monoZ docs
MZ_spi_example.c
Go to the documentation of this file.
1
9/*
10 * Objectives covered in this Example :
11 * 1. Demonstrate how to create a simple recursive Timer using MonoZ_Lib
12 * 2. Demonstrate how to create a Application Thread using MonoZ_Lib
13 * 3. Demonstrate how to send data in SPI using MonoZ_Lib.
14 * 4. Demonstrate how to create a semaphore using MonoZ_Lib.
15 *
16 * NOTE : This is an empty example.
17 *
18 * Sources for this example :
19 * MZ_spi_example.c - Main Application file
20 * MZ_spi_example.h
21 * MZ_spi1_instance.c - SPI driver file
22 * MZ_spi1_instance.h
23 */
24
25/* Include Header Files - START */
26#include "MZ_sys_cmsis_os2.h"
27#include "MZ_spi_example.h"
28#include "MZ_timer.h"
29#include "MZ_print.h"
30#include "MZ_spi2_instance.h"
31#include "MZ_error_handler.h"
32#include "MZ_spi.h"
33#include <stdio.h>
34#include <math.h>
35#include<stdlib.h>
36#include "stm32l4xx_hal_spi.h"
37/* Include Header Files - END */
38
39/* Application related MACRO - START */
40#define SPI_APP_STACK_SIZE (1024)
41#define SPI_TX_TIME (pdMS_TO_TICKS(60000))
42#define SPI_TX_SIZE (10)
43
45static StaticTask_t spi_cb_mem;
46static StackType_t spi_stack[SPI_APP_STACK_SIZE];
49/* Application related variables - END */
50
56static void timer_cb(TimerHandle_t xTimer)
57{
58 mz_puts("Timer expires\r\n");
60}
61
69static void spi_app(void * arg)
70{
71 (void)arg;
72
73 /*
74 * create the SPI transmission timer.
75 * As per requirement, We are creating a recursive timer using
76 * mz_tm_create_start_recursive() API.
77 * In-case of other type of timer, please refer MZ_timer.h
78 * The expire time for this timer set to SPI_TX_TIME.
79 * "timer_cb" is passed as an argument.
80 * When the timer expires, the "timer_cb" API will be processed.
81 */
83 {
84 /* Timer create and start failed. */
85 __NOP(); /* Dummy No operation statement */
86 }
87 /*
88 * This is the infinite loop for this thread - the thread will execute this
89 * loop forever and not come outside of this loop
90 */
91 while(1)
92 {
93 /* Need to write the periodic executing logic in this loop block */
94 __NOP(); /* Dummy No operation statement */
95
96 /* Add a delay for Non-blocking */
97 HAL_Delay(1);
98
99 }//End of while(1) - Do not place any code after this.
100
101}
102/* SPI Application thread API. - END */
103
104/*
105 * @fn mz_error_t spi_app_init(void)
106 * @brief creates the App thread and semaphore
107 * @return MZ_OK/MZ_FAIL
108 */
109/* SPI Application initialization API. - START
110 *
111 * 1. It Initialize SPI interface
112 * 2. It create the main SPI application
113 * 3. It create a semaphore, that can be used in application
114 */
116{
117 mz_error_t _ret = MZ_OK;
118
119 // Initialize SPI 1
120 if(MZ_OK != SPI1_init())
121 return MZ_FAIL;
122
123 // Create the SPI application threads
125 "SPI Scheduler",
126 spi_app,
127 NULL,
128 osPriorityNormal,
129 spi_stack,
131 &spi_cb_mem,
132 sizeof(spi_cb_mem)))
133 {
135 }
136
137 // Create lock with already locked
138 if(!mz_sem_create(&spi_sema_id,1U,1U))
139 {
140 _ret = MZ_SEMA_CREATE_FAIL;
141 }
142
143 return _ret;
144}
145/* SPI Application initialization API. - END */
unsigned char mzUint8
1 Byte data type
Definition: MZ_common.h:57
monoZ Error Handler
mz_error_t
Enumeration of monoZ Error Flags.
@ MZ_SEMA_CREATE_FAIL
@ MZ_THREAD_CREATE_FAIL
@ MZ_OK
@ MZ_FAIL
monoZ Print
#define MZ_SPI_INSTANCE
This file contains all the functionalities for SPI protocol.
static mz_thread_t spi_thread_id
#define SPI_TX_TIME
static StaticTask_t spi_cb_mem
#define SPI_APP_STACK_SIZE
static mz_semaphore_t spi_sema_id
static void spi_app(void *arg)
create the timer and starts if main RTOS scheduler started
static mzUint8 send_data[SPI_TX_SIZE]
static void timer_cb(TimerHandle_t xTimer)
Timer callback function for transmission of the data.
#define SPI_TX_SIZE
static StackType_t spi_stack[SPI_APP_STACK_SIZE]
mz_error_t spi_app_init(void)
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....
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...
mz_error_t MZ_SPI_Transmit_IT(uint8_t spi_no, uint8_t *pData, uint16_t Size)
This function is used to transmit data using SPI in interrupt mode.
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.