monoZ docs
MZ_timer_example.c
Go to the documentation of this file.
1
8#include "MZ_sys_cmsis_os2.h"
9#include "MZ_timer_example.h"
10#include "MZ_timer.h"
11#include "MZ_print.h"
12#include "MZ_error_handler.h"
13
14#define START_AT_INIT (0)
15#define START_AT_THREAD (1)
16
17#define TIMER_EXAMPLE START_AT_THREAD
18
19#define TIMER_APP_STACK_SIZE (128)
20
22static StaticTask_t timer_cb_mem;
31static void timer_cb(TimerHandle_t xTimer)
32{
33 // Unlock the lock when timer expires
34 //mz_sem_release(&timer_sema_id);
35 mz_puts("Timer expires\r\n");
36}
37
43static void timer_app(void * arg)
44{
45 (void)arg;
46#if(TIMER_EXAMPLE == START_AT_THREAD)
47 // create the timer and start when the starts if main RTOS scheduler started
48 if(MZ_OK != mz_tm_create_start_recursive("My timer",
49 pdMS_TO_TICKS(5000),
50 timer_cb))
51 {
52 __NOP(); //No action
53 }
54 mz_puts("Timer Created and started at Application \r\n");
55#endif
56
57 while(1)
58 {
59// // Wait till the timer is unlocked to re-lock
60// if(SEMA_TIMEOUT != mz_sem_wait(&timer_sema_id,10))
61// {
62// // sample print
63// mz_puts("Timer expires");
64// }
65// else
66// {
67// __NOP();
68// }
69 }
70
71}
72
73/*
74 * @fn mz_error_t timer_app_init(void)
75 * @brief Initiate the Timer App and creates the thread for timer application
76 * @return _ret returns the status of app thread creation(MZ_OK/MZ_FAIL)
77 * @note semaphore is created for lock the process when multiple processes are in run status
78 */
80{
81 mz_error_t _ret = MZ_OK;
82
83 // Create the timer application threads
85 "Timer Scheduler",
87 NULL,
88 osPriorityNormal,
92 sizeof(timer_cb_mem)))
93 {
95 }
96
97 // Create lock with already locked
98 if(!mz_sem_create(&timer_sema_id,1U,1U))
99 {
100 _ret = MZ_SEMA_CREATE_FAIL;
101 }
102
103#if(TIMER_EXAMPLE == START_AT_INIT)
104 if(MZ_OK != mz_tm_create_start_recursive("My timer",
105 pdMS_TO_TICKS(5000),
106 timer_cb))
107 {
108 __NOP();
109 }
110
111 mz_puts("Timer Created and started at Initialization \r\n");
112#endif
113 return _ret;
114}
monoZ Error Handler
mz_error_t
Enumeration of monoZ Error Flags.
@ MZ_SEMA_CREATE_FAIL
@ MZ_THREAD_CREATE_FAIL
@ MZ_OK
monoZ Print
monoZ system CMSIS OS2 This is an abstraction layer and includes FreeRTOS configuration,...
osSemaphoreId_t mz_semaphore_t
mz_semaphore_t variable of type osSemaphoreId_t
osThreadId_t mz_thread_t
mz_thread_t variable of type osThreadId_t
This file contains APIs for create,delete,start and stop of timers. Maximum 5 timers can be created....
static StackType_t timer_stack[TIMER_APP_STACK_SIZE]
static mz_thread_t timer_thread_id
static StaticTask_t timer_cb_mem
#define TIMER_APP_STACK_SIZE
Defines the App stack size.
static void timer_app(void *arg)
create the timer and start when the starts if main RTOS scheduler started
static void timer_cb(TimerHandle_t xTimer)
timer callback function Unlock the lock when timer expires
mz_error_t timer_app_init(void)
Initiate the Timer App and creates the thread for timer application.
static mz_semaphore_t timer_sema_id
This is an example of how to use a timer and print in CLI using Application thread.
int mz_puts(void *__ch)
This function prints the given string.
uint8_t mz_sem_create(mz_semaphore_t *c, uint8_t cnt, uint8_t init)
This function is used to create and initialize the semaphore object Create and Initialize a Semaphore...
uint8_t mz_thread_create(mz_thread_t *t, const char *name, mz_fn thread_func, void *const arg, mz_thread_prio_t prio, StackType_t *stack_mem, size_t stack_size, StaticTask_t *cb_mem, uint32_t cb_size)
This function is used to check the message queue object validity Create a thread and add it to Active...
mz_error_t mz_tm_create_start_recursive(char *_name, TickType_t _tick, mz_tm_cb _cb)
Function to Create and Start One Shot Timers.