MTK timer Summary
There are many types of MTK tiemr, from the underlying KAL to MMI, there are timer figures.
KAL timer
KAL timer is a very underlying timer. Its implementation is to directly encapsulate the timer of mtk rtos (nuleus). The implementation method is HISR,
Therefore, this timer has a high priority, that is, when this timer times out, it will trigger an HISR (Advanced interrupt), this interrupt
Callback registers the function. Therefore, when using this timer, be careful. It has a high priority. When the callback function is running, other events are
Not handled. The related API functions are as follows:
kal_timerid kal_create_timer(kal_char * timer_name_ptr);
Create a timer. The parameter is the name of the timer.
void kal_set_timer(kal_timerid timer_id, kal_timer_func_ptr handler_func_ptr,void *
handler_param_ptr,kal_uint32 delay,kal_uint32 reschedule_time);
Set the timer timeout time. timer_id is the return value of the kal_create_timer function, handler_func_ptr is the callback function, and handler_param_ptr
Is the parameter returned by the callback function, and delay is the timeout time. Note that the unit of this parameter is ticks rather than ms. Reschedule_time indicates whether timer is used cyclically, 0
Indicates that timer is stopped after one timeout, and 1 indicates that timer is automatically started cyclically.
STACK TIMER
The biggest difference between this timer and KAL timer is that after the stack timer times out, a timeout message is sent to the Message Queue of the corresponding task, which is sent by the message queue of the task.
Handle this message. Unlike KAL timer, the function is directly registered in the interrupt status callback. From the perspective of time accuracy, stack timer may not be precise with KAL timer (send messages,
Task Switching takes time), but the stack is more secure (processing the message in the task) and improves concurrency (only one message is sent after the stack timer expires.
Not processed ). Related API functions:
void stack_init_timer(stack_timer_struct *stack_timer, kal_char *timer_name,module_type
module_id);
// Function: Initialize stack timer
Parameter Parsing: stack_timer --- pointer to stack_timer_struct type, fill in timer-related information
Timer_name --- name of kal_timer
Module_type --- MOD_ID of the message received when kal_timer times out
kal_bool stack_is_time_out_valid(stack_timer_struct *stack_timer);
// Function: determines whether the message continues to be valid, that is, whether it needs to be processed (when the stack timer times out
The timer is canceled at this time, but the message has not been sent and processed.
, Special processing is required, although the probability of such a situation is very small ).
Void stack_process_time_out (stack_timer_struct * stack_timer); // this function is used in pairs with the above function
Void stack_start_timer (stack_timer_struct * stack_timer, kal_uint16 timer_index, kal_uint32 init_time );
Function: start the timer.
Parameter Parsing: stack_timer ---- pointing to the struct variable installed in the timer-related information
Timer_index ----- timer Index
Init_time ----- time-out period of time
The two types of timer, KAL timer and stack timer are mentioned above.
KAL timer is usually used to manage a group of timer when the time requirement for driver development is particularly accurate.
Stack timer and event schedmer.
In MMI development, the commonly used timer is composed of stack timer + event schedmer. Its functions
The interfaces are starttimer and stoptimer. The following describes how to use it.
Step 1: First add a timer ID in mmi_timer_ids of timerevents. H, such as test_id,
After this ID is added, we can use the timer function to perform some scheduled events.
Step 2: Create a timer, void starttimer (2010timerid, u32 delay, funcptr)
Timerid ---- the ID number defined in the table, test_id,
Delay ---- delay time, in ms
FuncPtr ---- the callback function when the timeout occurs
StartTimer (TEST_ID, 10*1000, TestTimeout); in this way, when the scheduled time is reached, the callback will be made.
This function.
Step 3: If you do not want the timeout to occur, you can use StopTimer (2010timerid ).