monoZ docs
MZ_uart_example.c
Go to the documentation of this file.
1/*
2 * Objectives covered in this Example :
3 * 1. Demonstrate how to create a simple recursive Timer using MonoZ_Lib
4 * 2. Demonstrate how to create a Application Thread using MonoZ_Lib
5 * 3. Demonstrate how to send data in UART using MonoZ_Lib.
6 * 4. Demonstrate how to create a semaphore using MonoZ_Lib.
7 *
8 * NOTE : This is an empty example.
9 *
10 * Sources for this example :
11 * MZ_uart_example.c - Main Application file
12 * MZ_uart_example.h
13 * MZ_uart3_instance.c - UART driver file
14 * MZ_uart3_instance.h
15 */
16
17
26#include "MZ_sys_cmsis_os2.h"
27#include "MZ_uart_example.h"
28#include "MZ_timer.h"
29#include "MZ_print.h"
30#include "MZ_uart3_instance.h"
31#include "MZ_error_handler.h"
32#include "MZ_uart.h"
33
34/* Application related MACRO - START */
35#define UART_APP_STACK_SIZE (128)
36#define UART_TX_TIME (pdMS_TO_TICKS(60000))
37#define UART_TX_SIZE (10)
38/* Application related MACRO - END */
39
40/* Application related variables - START */
42static StaticTask_t uart_cb_mem;
43static StackType_t uart_stack[UART_APP_STACK_SIZE];
45static uint8_t send_data[UART_TX_SIZE];
46/* Application related variables - END */
47
53/*
54 * UART transmission timer callback - START
55 *
56 * This Timer callback will be called after the UART transmission timer is
57 * expired.
58 * The timer value is set as UART_TX_TIME
59 */
60static void timer_cb(TimerHandle_t xTimer)
61{
62 mz_puts("Timer expires\r\n");
64 (uint8_t *)&send_data,
65 sizeof(send_data));
66}
67/* UART transmission timer callback - END */
68
69
75/*
76 * UART Application thread API. - START
77 *
78 * 1. It Create and start UART transmission timer
79 * 2. Process other actions on the thread loop
80 */
81static void uart_app(void * arg)
82{
83 (void)arg;
84
85 /*
86 * create the UART transmission timer.
87 * As per requirement, We are creating a recursive timer using
88 * mz_tm_create_start_recursive() API.
89 * In-case of other type of timer, please refer MZ_timer.h
90 * The expire time for this timer set to UART_TX_TIME.
91 * "timer_cb" is passed as an argument.
92 * When the timer expires, the "timer_cb" API will be processed.
93 */
94 if(MZ_OK != mz_tm_create_start_recursive("UART transmission timer",
96 timer_cb))
97 {
98 /* Timer create and start failed. */
99 __NOP(); /* Dummy No operation statement */
100 }
101
102 /*
103 * This is the infinite loop for this thread - the thread will execute this
104 * loop forever and not come outside of this loop
105 */
106 while(1)
107 {
108 /* Need to write the periodic executing logic in this loop block */
109 __NOP(); /* Dummy No operation statement */
110
111 /* Add a delay for Non-blocking */
112 HAL_Delay(1);
113
114 }//End of while(1) - Do not place any code after this.
115
116}
117/* UART Application thread API. - END */
118
125/*
126 * UART Application initialization API. - START
127 *
128 * 1. It Initialize UART interface
129 * 2. It create the main UART application
130 * 3. It create a semaphore, that can be used in application
131 */
133{
134 mz_error_t _ret = MZ_OK;
135
136 /* Initialize UART 3 */
138
139 /* Create the UART application threads */
141 "UART Scheduler",
142 uart_app,
143 NULL,
144 osPriorityNormal,
148 sizeof(uart_cb_mem)))
149 {
151 }
152
153 /* Create lock with already locked */
154 if(!mz_sem_create(&uart_sema_id,1U,1U))
155 {
156 _ret = MZ_SEMA_CREATE_FAIL;
157 }
158
159 return _ret;
160}
161/* UART Application initialization API. - END */
162
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....
mz_error_t UART3_init(void)
UART initialize.
Create UART instance.
#define MZ_UART_INSTANCE
Define UART Instance.
This file includes monoZ Uart Related APIs.
static void uart_app(void *arg)
create the timer and start when the starts if main RTOS scheduler started
static StaticTask_t uart_cb_mem
static uint8_t send_data[UART_TX_SIZE]
static mz_thread_t uart_thread_id
#define UART_TX_SIZE
mz_error_t uart_app_init(void)
Initialize UART App and creates the uart application thread By default it will initialize the uart3.
static void timer_cb(TimerHandle_t xTimer)
timer callback function notifies when timer expires
static StackType_t uart_stack[UART_APP_STACK_SIZE]
#define UART_TX_TIME
#define UART_APP_STACK_SIZE
static mz_semaphore_t uart_sema_id
Monoz UART example This example app can be used when there is a requirement for different uart specif...
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.
mz_error_t MZ_UART_Transmit_IT(uint8_t uart_no, uint8_t *pData, uint16_t Size)
This function is used to transmit data using UART in interrupt mode.