2024-03-18 12:47:07 +00:00
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* CMSIS-RTOS 'main' function template
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include "stm32f7xx_hal.h"
|
|
|
|
#include "RTE_Components.h"
|
|
|
|
#include CMSIS_device_header
|
|
|
|
#include "cmsis_os2.h"
|
|
|
|
#include "ext_led.h"
|
|
|
|
#include "ext_uart.h"
|
|
|
|
#include "ext_buttons.h"
|
|
|
|
#include "ext_keyboard.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef RTE_Compiler_EventRecorder
|
|
|
|
#include "EventRecorder.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
osThreadId_t thread1,thread2;
|
|
|
|
osMessageQueueId_t msgQueue;
|
|
|
|
|
|
|
|
const osThreadAttr_t thread1_attr = {
|
|
|
|
.stack_size = 1024, // Create the thread stack size
|
|
|
|
.priority = osPriorityNormal, //Set initial thread priority to high
|
|
|
|
.name = "Producer",
|
|
|
|
};
|
|
|
|
const osThreadAttr_t thread2_attr = {
|
|
|
|
.stack_size = 1024, // Create the thread stack size
|
|
|
|
.priority = osPriorityNormal, //Set initial thread priority to high
|
|
|
|
.name = "Consumer",
|
|
|
|
};
|
|
|
|
|
|
|
|
const osMessageQueueAttr_t msgQueue_attr = {
|
|
|
|
.name = "MsgQueue",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Thread Producer
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
__NO_RETURN static void Thread_Producer (void *argument) {
|
|
|
|
osMessageQueueId_t* queue = (osMessageQueueId_t*)argument;
|
|
|
|
uint32_t counter = 0;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
osStatus_t statusQueue = osMessageQueuePut(*queue, &counter, 1, 0);
|
|
|
|
if(statusQueue != osOK) {
|
|
|
|
// TODO generate error
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
osDelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Thread Consumer
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
__NO_RETURN static void Thread_Consumer (void *argument) {
|
|
|
|
osMessageQueueId_t* queue = (osMessageQueueId_t*)argument;
|
|
|
|
uint8_t counter = 1;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
uint32_t msg;
|
|
|
|
osStatus_t statusQueue;
|
|
|
|
|
|
|
|
do {
|
|
|
|
statusQueue = osMessageQueueGet(*queue, &msg, NULL, 0);
|
2024-03-18 12:59:32 +00:00
|
|
|
if(statusQueue == osOK) printf("Value is %d\r\n", msg);
|
2024-03-18 12:47:07 +00:00
|
|
|
} while(statusQueue != osErrorResource);
|
|
|
|
if(++counter > 10) counter = 1;
|
|
|
|
osDelay(counter*100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main (void) {
|
|
|
|
|
|
|
|
// System Initialization
|
|
|
|
SystemClock_Config();
|
|
|
|
SystemCoreClockUpdate();
|
|
|
|
#ifdef RTE_Compiler_EventRecorder
|
|
|
|
// Initialize and start Event Recorder
|
|
|
|
// Ext_UART_Init(9600);
|
|
|
|
EventRecorderInitialize(EventRecordAll, 1U);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
osKernelInitialize(); // Initialize CMSIS-RTOS
|
|
|
|
msgQueue = osMessageQueueNew(8, 4, &msgQueue_attr);
|
|
|
|
thread1 = osThreadNew(Thread_Producer, &msgQueue, &thread1_attr);
|
|
|
|
thread2 = osThreadNew(Thread_Consumer, &msgQueue, &thread2_attr);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
// get names are placed for TraceAlyzer visualisation
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
osThreadGetName(thread1);
|
|
|
|
osThreadGetName(thread2);
|
|
|
|
osMessageQueueGetName(msgQueue);
|
|
|
|
osKernelStart(); // Start thread execution
|
|
|
|
for (;;) {}
|
|
|
|
}
|