The timer is part of the kernel in Ti-rtos, so you want to know how to use it or read bios_user_guide.pdf.
The main use of such a few APIs, bold font more definitions can be in the. View in \packages\ti\sysbios\knl\clock.
#define CLOCK_CONSTRUCT Ti_sysbios_knl_clock_construct
#define Clock_create Ti_sysbios_knl_clock_create
#define Clock_handle Ti_sysbios_knl_clock_handle
#define CLOCK_STRUCT Ti_sysbios_knl_clock_struct
#define Clock_handle_label Ti_sysbios_knl_clock_handle_label
#define CLOCK_HANDLE_NAME Ti_sysbios_knl_clock_handle_name
#define CLOCK_INSTANCE_INIT Ti_sysbios_knl_clock_instance_init
#define Clock_object_count Ti_sysbios_knl_clock_object_count
#define Clock_object_get Ti_sysbios_knl_clock_object_get
#define Clock_object_first Ti_sysbios_knl_clock_object_first
#define Clock_object_next Ti_sysbios_knl_clock_object_next
#define CLOCK_OBJECT_SIZEOF ti_sysbios_knl_clock_object_sizeof
#define CLOCK_PARAMS_COPY Ti_sysbios_knl_clock_params_copy
#define CLOCK_PARAMS_INIT Ti_sysbios_knl_clock_params_init
Operating mode is a single overflow, or can be repeated overflow. Clock_create () The second parameter is used to specify the time of the first overflow, the unit should be 10US, if you want to repeat the event, you want to specify the period in the third parameter, assign a value. Period is 0, which indicates a single time, and a value other than 0 produces a periodic event. Once an overflow occurs, an overflow function is executed, which is the function pointed to by the first parameter of Clock_create. It works as follows:
Well, let's go through the same ritual and demonstrate its application. Here the timer is used to control the light, and the 500ms state changes once. The entire code is as follows:
/**************************************************************************************************
Filename:timerdemotask.c
Editor:tome @ newbit
Revised: $Date: 2016-8-10 11:20:02 +0800 $
Revision: $Revision: 00001 $
Description: Understand the use of Ti-rtos, Timer
History:
Notes: To understand this part of the interface, you can read the TI document
1. Ti-rtos 2.20 User ' s Guide.pdf
2. Bios User Guide.pdf
Hardware platform Cc1130_launchpad Rev1.3
**************************************************************************************************/
/**************************************************************************************************
Includes
**************************************************************************************************/
/* Xdctools Header Files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>//new Plus
/* BIOS Header Files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>//new Plus
/* Ti-rtos Header Files */
#include <ti/drivers/PIN.h>
#include "Board.h"
/**************************************************************************************************
TYPEDEF
**************************************************************************************************/
/**************************************************************************************************
CONSTANTS
**************************************************************************************************/
#define TASKSTACKSIZE 768
/**************************************************************************************************
LOCAL veriable
**************************************************************************************************/
Task_struct timerdemotaskstruct;
Char Timerdemotaskstack[taskstacksize]; Stack space for this task, static assignment
Pin_handle Ledpinhandle; Take the LED action handle as a global variable
/* Global memory storage for a pin_config table */
Static Pin_state ledpinstate;
/*
* Application Timerdemo pin configuration table:
*-All Timerdemos board Timerdemos is off.
*/
Pin_config ledpintable[] = {
board_led1 | Pin_gpio_output_en | Pin_gpio_low | Pin_pushpull | Pin_drvstr_max,
Board_led2 | Pin_gpio_output_en | Pin_gpio_low | Pin_pushpull | Pin_drvstr_max,
Pin_terminate
};
/**************************************************************************************************
FUNCTIONS decleration
**************************************************************************************************/
Void timerdemofxn (Uarg arg0, Uarg arg1);
void MyHandler (Xdc_uarg arg0);
/**************************************************************************************************
FUNCTIONS
**************************************************************************************************/
/**************************************************************************************************
* @fn Timerdemotaskadd
*
* @brief
*
* @param void
*
* @return void
**************************************************************************************************/
void Timerdemotaskadd (void)
{
Task_params Taskparams;
/* Construct BIOS Objects */
Task_params_init (&taskparams); The parameters that are required to create the task are set to the default values
Taskparams.stacksize = taskstacksize; Stack space
Taskparams.stack = &timerDemoTaskStack; Stack Address
To pass parameters to the BIOS and set up a control light task
Task_construct (&timerdemotaskstruct, (task_funcptr) timerdemofxn, &taskparams, NULL);
}
Tasks for demonstrating timers
Void timerdemofxn (Uarg arg0, Uarg arg1)
{
This is not to initialize, but to get the handle of the operation (handle)
Function Description: Allocate One or more pins for a driver or an application.
Ledpinhandle = Pin_open (&ledpinstate, ledpintable);
if (!ledpinhandle) {
System_abort ("Error Initializing Board LED pins\n");
}
Light the first LED light.
Pin_setoutputvalue (Ledpinhandle, board_led1, 1);
Start initializing a Timer
Clock_params Clockparams;
Clock_handle Myclock;
Error_block EB;
Error_init (&EB);
Clock_params_init (&clockparams);
Clockparams.period = 100 * 500; 500MS, Flash light frequency is 1hz
Clockparams.startflag = TRUE;
Clockparams.arg = (uarg) 0x5555;
Myclock = Clock_create (MyHandler, 5, &clockparams, &eb);
if (Myclock = = NULL)
{
System_abort ("Clock create failed\n");
}
Timer Configuration End
The subject of the task is dormant only
while (1)
{
Task hibernation 1 seconds, 1000000US, the following function is the unit 10US
Task_sleep (100000);
}
}
/**************************************************************************************************
* @fn myhanlder
*
* execute function
*
when @brief timer overflow * @param xdc_uarg arg0
*
* @return void
************************ /
void MyHandler (Xdc_uarg arg0)
{
uint_t ledstate;
//Read the status of LED lights, and then set to the opposite state
ledstate = Pin_getoutputvalue (BOARD_LED2);
ledstate =!ledstate;
//Set operation requires handle
Pin_setoutputvalue (Ledpinhandle, Board_led2, ledstate );
}
/**************************************************************************************************
Copyright newbit Studio. All rights reserved.
**************************************************************************************************/
Use of the Ti-rtos timer