diff --git a/RTE/_Target_1/RTE_Components.h b/RTE/_Target_1/RTE_Components.h
index c793458..702e9fb 100644
--- a/RTE/_Target_1/RTE_Components.h
+++ b/RTE/_Target_1/RTE_Components.h
@@ -28,6 +28,8 @@
#define RTE_Compiler_IO_STDOUT_ITM /* Compiler I/O: STDOUT ITM */
/* Keil::Device:STM32Cube Framework:Classic:1.2.7 */
#define RTE_DEVICE_FRAMEWORK_CLASSIC
+/* Keil::Device:STM32Cube HAL:CRC:1.2.7 */
+#define RTE_DEVICE_HAL_CRC
/* Keil::Device:STM32Cube HAL:Common:1.2.7 */
#define RTE_DEVICE_HAL_COMMON
/* Keil::Device:STM32Cube HAL:Cortex:1.2.7 */
diff --git a/lab04-queue.uvprojx b/lab04-queue.uvprojx
index 82caec7..0beed68 100644
--- a/lab04-queue.uvprojx
+++ b/lab04-queue.uvprojx
@@ -393,15 +393,15 @@
::CMSIS
+
+ ::Hesso pack
+
::Compiler
::Device
-
- ::Hesso pack
-
@@ -464,6 +464,12 @@
+
+
+
+
+
+
@@ -605,4 +611,13 @@
+
+
+
+ lab04-queue
+ 1
+
+
+
+
diff --git a/main.c b/main.c
index 05dbf50..961f13e 100644
--- a/main.c
+++ b/main.c
@@ -5,10 +5,6 @@
#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
#include
@@ -17,22 +13,33 @@
#include "EventRecorder.h"
#endif
+CRC_HandleTypeDef hcrc;
+static void MX_CRC_Init(void);
+
osThreadId_t thread1,thread2;
-osMessageQueueId_t msgQueue;
+osMessageQueueId_t pipe1, pipe2;
+osSemaphoreId_t mutexCRC;
const osThreadAttr_t thread1_attr = {
.stack_size = 1024, // Create the thread stack size
.priority = osPriorityNormal, //Set initial thread priority to high
- .name = "Producer",
+ .name = "Task2",
};
const osThreadAttr_t thread2_attr = {
.stack_size = 1024, // Create the thread stack size
.priority = osPriorityNormal, //Set initial thread priority to high
- .name = "Consumer",
+ .name = "Task2",
};
-const osMessageQueueAttr_t msgQueue_attr = {
- .name = "MsgQueue",
+const osMessageQueueAttr_t pipe1_attr = {
+ .name = "Pipe1",
+};
+
+const osMessageQueueAttr_t pipe2_attr = {
+ .name = "Pipe2",
+};
+const osSemaphoreAttr_t mutexCRC_attr = {
+ .name = "MTX_CRC", // name of the semaphore
};
@@ -69,45 +76,78 @@ void SystemClock_Config (void) {
-/*----------------------------------------------------------------------------
- * 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;
+static void MX_CRC_Init(void) {
+ __HAL_RCC_CRC_CLK_ENABLE();
+ hcrc.Instance = CRC;
+ hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
+ hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
+ hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
+ hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
+ hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_WORDS;
+ if (HAL_CRC_Init(&hcrc) != HAL_OK) //Error_Handler();
+ {
- do {
- statusQueue = osMessageQueueGet(*queue, &msg, NULL, 0);
- printf("Value is %d\r\n", msg);
- } while(statusQueue != osErrorResource);
- if(++counter > 10) counter = 1;
- osDelay(counter*100);
- }
+ }
}
+/*----------------------------------------------------------------------------
+ * Thread Task1
+ *---------------------------------------------------------------------------*/
+__NO_RETURN static void Task1(void *argument) {
+ uint32_t msg[]={1234,5678,41234,4356,122457,8562,45772,245735};
+
+ uint32_t crc;
+ osSemaphoreAcquire(mutexCRC, osWaitForever);
+ //MX_CRC_Init();
+ crc = HAL_CRC_Calculate(&hcrc, msg, 8); // TODO: CRC module init
+ osSemaphoreRelease(mutexCRC);
+
+ for (;;) {
+ // TODO: post 8 values and wait for the CRC back from Task 2
+ osStatus_t status;
+
+ while(1) {
+ for(uint8_t i = 0; i < 8;) {
+ status = osMessageQueuePut(pipe1, &(msg[i]), 1, 0);
+ if(status == osOK) i++;
+ osDelay(500);
+ }
+ uint32_t recData;
+ do {
+ status = osMessageQueueGet(pipe2, &recData, NULL, 0);
+ } while(status != osOK);
+ if(recData == crc) {
+ printf("CRC OK: %d\r\n", crc);
+ } else {
+ printf("Error ! crc = %d, and should be: %d\r\n", recData, crc);
+ }
+ }
+
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * Thread Task2
+ *---------------------------------------------------------------------------*/
+__NO_RETURN static void Task2(void *argument) {
+ uint32_t crc;
+ uint32_t recData;
+
+ for (;;) {
+ osSemaphoreAcquire(mutexCRC, osWaitForever);
+ MX_CRC_Init();
+ for(uint8_t i = 0; i < 8; i++) {
+ osMessageQueueGet(pipe1, &recData, NULL, osWaitForever);
+ crc = HAL_CRC_Accumulate(&hcrc, &recData, 1);
+ }
+ osSemaphoreRelease(mutexCRC);
+ osMessageQueuePut(pipe2, &crc, 1, osWaitForever);
+ }
+}
+
+
int main (void) {
// System Initialization
@@ -119,17 +159,22 @@ int main (void) {
EventRecorderInitialize(EventRecordAll, 1U);
#endif
+ MX_CRC_Init();
osKernelInitialize(); // Initialize CMSIS-RTOS
- msgQueue = osMessageQueueNew(8, 4, &msgQueue_attr);
- thread1 = osThreadNew(Thread_Producer, &msgQueue, &thread1_attr);
- thread2 = osThreadNew(Thread_Consumer, &msgQueue, &thread2_attr);
+ pipe1 = osMessageQueueNew(8, 4, &pipe1_attr);
+ pipe2 = osMessageQueueNew(8, 4, &pipe2_attr);
+ thread1 = osThreadNew(Task1, (void*)1, &thread1_attr);
+ thread2 = osThreadNew(Task2, (void*)2, &thread2_attr);
+ mutexCRC= osSemaphoreNew(1,1,&mutexCRC_attr);
//----------------------------------------------------------------------------------------------
// get names are placed for TraceAlyzer visualisation
//----------------------------------------------------------------------------------------------
osThreadGetName(thread1);
osThreadGetName(thread2);
- osMessageQueueGetName(msgQueue);
+ osMessageQueueGetName(pipe1);
+ osMessageQueueGetName(pipe2);
+ osSemaphoreGetName(mutexCRC);
osKernelStart(); // Start thread execution
for (;;) {}
}