monoZ docs
MZ_gpio_example.c
Go to the documentation of this file.
1/*
2 * MZ_gpio_example.c
3 *
4 * Created on: 16-Mar-2022
5 * Author: Mahendra
6 */
7/*
8 * Objectives covered in this Example :
9 * 1. Demonstrate how to create a simple recursive Timer using MonoZ_Lib
10 * 2. Demonstrate how to create a Application Thread using MonoZ_Lib
11 * 3. Demonstrate how to send data in GPIO using MonoZ_Lib.
12 * 4. Demonstrate how to create a semaphore using MonoZ_Lib.
13 *
14 * NOTE : This is an empty example.
15 *
16 * Sources for this example :
17 * MZ_gpio_example.c - Main Application file
18 * MZ_gpio_example.h
19 * MZ_gpio_instance.c - GPIO driver file
20 * MZ_gpio_instance.h
21 */
22
23
32#include "MZ_sys_cmsis_os2.h"
33#include "MZ_gpio_example.h"
34#include "MZ_timer.h"
35#include "MZ_print.h"
36#include "MZ_gpio_instance.h"
37#include "MZ_error_handler.h"
38#include "MZ_gpio.h"
39#include "MZ_gpio_instance.h"
40
41/* Application related MACRO - START */
42#define GPIO_APP_STACK_SIZE (128)
43#define GPIO_TX_TIME (pdMS_TO_TICKS(5000))
44#define GPIO_TX_SIZE (10)
45/* Application related MACRO - END */
46
47/* Application related variables - START */
49static StaticTask_t gpio_cb_mem;
50static StackType_t gpio_stack[GPIO_APP_STACK_SIZE];
52//static uint8_t send_data[GPIO_TX_SIZE]; /*!< GPIO transmission buffer */
53/* Application related variables - END */
54
60/*
61 * GPIO transmission timer callback - START
62 *
63 * This Timer callback will be called after the GPIO transmission timer is
64 * expired.
65 * The timer value is set as GPIO_TX_TIME
66 */
67static void timer_cb(TimerHandle_t xTimer)
68{
69 mz_puts("Timer expires\r\n");
70// MZ_GPIO_Transmit_IT(MZ_GPIO_INSTANCE,
71// (uint8_t *)&send_data,
72// sizeof(send_data));
74
75}
76/* GPIO transmission timer callback - END */
77
78
84/*
85 * GPIO Application thread API. - START
86 *
87 * 1. It Create and start GPIO transmission timer
88 * 2. Process other actions on the thread loop
89 */
90static void gpio_app(void * arg)
91{
92 (void)arg;
93
94 /*
95 * create the GPIO transmission timer.
96 * As per requirement, We are creating a recursive timer using
97 * mz_tm_create_start_recursive() API.
98 * In-case of other type of timer, please refer MZ_timer.h
99 * The expire time for this timer set to GPIO_TX_TIME.
100 * "timer_cb" is passed as an argument.
101 * When the timer expires, the "timer_cb" API will be processed.
102 */
103
105 /* Initialize GPIO */
106// if(MZ_OK != gpio_init()){
107// Error_Handler();
108// }
109
110 if(MZ_OK != mz_tm_create_start_recursive("GPIO transmission timer",
112 timer_cb))
113 {
114 /* Timer create and start failed. */
115 __NOP(); /* Dummy No operation statement */
116 }
117
118 /*
119 * This is the infinite loop for this thread - the thread will execute this
120 * loop forever and not come outside of this loop
121 */
122 /*
123 * Use GPIO Configure API as output(GPIO_PIN_RESET) or input (GPIO_PIN_SET)
124 */
125// MZ_GPIO_INIT_ST gpio_instance = {0};
126
127// MZ_GPIO_WritePin(MZ_PORT_GPIOF, MZ_GPIO_PIN_3, GPIO_PIN_SET);
128// /* Initialize GPIO */
129// if(MZ_OK != gpio_init()){
130// Error_Handler();
131// }
132
133 while(1)
134 {
135 /* Need to write the periodic executing logic in this loop block */
136 __NOP(); /* Dummy No operation statement */
137//
138// MZ_GPIO_TogglePin(MZ_PORT_GPIOF,MZ_GPIO_PIN_3);
139//
140// /* Add a delay for Non-blocking */
141// HAL_Delay(5000);
142
143 }//End of while(1) - Do not place any code after this.
144
145}
146/* GPIO Application thread API. - END */
147
154/*
155 * GPIO Application initialization API. - START
156 *
157 * 1. It Initialize GPIO interface
158 * 2. It create the main GPIO application
159 * 3. It create a semaphore, that can be used in application
160 */
162{
163 mz_error_t _ret = MZ_OK;
164 /* Create the GPIO application threads */
166 "GPIO Scheduler",
167 gpio_app,
168 NULL,
169 osPriorityNormal,
173 sizeof(gpio_cb_mem)))
174 {
176 }
177
178 /* Create lock with already locked */
179 if(!mz_sem_create(&gpio_sema_id,1U,1U))
180 {
181 _ret = MZ_SEMA_CREATE_FAIL;
182 }
183
184 return _ret;
185}
186/* GPIO Application initialization API. - END */
187
monoZ Error Handler
mz_error_t
Enumeration of monoZ Error Flags.
@ MZ_SEMA_CREATE_FAIL
@ MZ_THREAD_CREATE_FAIL
@ MZ_OK
This file includes Monoz GPIO Related APIs.
mz_error_t gpio_app_init(void)
Initialize GPIO App and creates the gpio application thread By default it will initialize the gpio3.
static mz_semaphore_t gpio_sema_id
#define GPIO_APP_STACK_SIZE
static StaticTask_t gpio_cb_mem
static void timer_cb(TimerHandle_t xTimer)
timer callback function notifies when timer expires
static mz_thread_t gpio_thread_id
static void gpio_app(void *arg)
create the timer and start when the starts if main RTOS scheduler started
#define GPIO_TX_TIME
static StackType_t gpio_stack[GPIO_APP_STACK_SIZE]
#define MZ_PORT_GPIO1
#define MZ_GPIO_PIN1
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 MZ_GPIO_TogglePin(MZ_GPIOX_BTYPE_PTR GPIOx, uint16_t GPIO_Pin)
This function is used to Set the toggling to the specific pin.
mz_error_t MZ_GPIO_WritePin(MZ_GPIOX_BTYPE_PTR GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
This function is used to Set the input/output to the specific pin.
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.