在线时间36 小时
UID423505
注册时间2013-3-27
NXP金币0
该用户从未签到
高级会员

- 积分
- 651
- 最后登录
- 2020-9-4
|
/*FUNCTION*------------------------------------------------------
*
* Function Name : LED_on
* Returned Value : none
* Comments :
* This timer function prints out "ON"
*END*-----------------------------------------------------------*/
static void LED_on
(
_timer_id id,
pointer data_ptr,
MQX_TICK_STRUCT_PTR tick_ptr
)
{
printf("ON\n");
}
/*FUNCTION*------------------------------------------------------
*
* Function Name : LED_off
* Returned Value : none
* Comments :
* This timer function prints out "OFF"
*END*-----------------------------------------------------------*/
static void LED_off
(
_timer_id id,
pointer data_ptr,
MQX_TICK_STRUCT_PTR tick_ptr
)
{
printf("OFF\n");
}
/*TASK*----------------------------------------------------------
*
* Task Name : main_task
* Comments :
* This task creates two timers, each of a period of 2 seconds,
* the second timer offset by 1 second from the first.
*END*-----------------------------------------------------------*/
void main_task
(
uint_32 initial_data
)
{
MQX_TICK_STRUCT ticks;
MQX_TICK_STRUCT dticks;
_timer_id on_timer;
_timer_id off_timer;
uint_8 time = 6; // time in seconds
printf("\n\nTwo timers are created, each of a period of 2 seconds,\nthe second timer offset by 1 second from the first.\n");
printf("Task runs for %d seconds,\nthen timers are closed and task finishes.\n\n", time);
/*
** Create the timer component with more stack than the default
** in order to handle printf() requirements:
*/
_timer_create_component(TIMER_TASK_PRIORITY, TIMER_STACK_SIZE);
_time_init_ticks(&dticks, 0);
_time_add_sec_to_ticks(&dticks, 2);
_time_get_elapsed_ticks(&ticks);
_time_add_sec_to_ticks(&ticks, 1);
on_timer = _timer_start_periodic_at_ticks(LED_on, 0,
TIMER_ELAPSED_TIME_MODE, &ticks, &dticks);
_time_add_sec_to_ticks(&ticks, 1);
off_timer = _timer_start_periodic_at_ticks(LED_off, 0,
TIMER_ELAPSED_TIME_MODE, &ticks, &dticks);
_time_delay(time * 1000); // wait 6 seconds
printf("\nThe task is finished!");
_timer_cancel(on_timer);
_timer_cancel(off_timer);
_task_block();
}
|
|