Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
b7fe6a153d |
@ -28,6 +28,8 @@
|
|||||||
#define RTE_Compiler_IO_STDOUT_ITM /* Compiler I/O: STDOUT ITM */
|
#define RTE_Compiler_IO_STDOUT_ITM /* Compiler I/O: STDOUT ITM */
|
||||||
/* Keil::Device:STM32Cube Framework:Classic:1.2.7 */
|
/* Keil::Device:STM32Cube Framework:Classic:1.2.7 */
|
||||||
#define RTE_DEVICE_FRAMEWORK_CLASSIC
|
#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 */
|
/* Keil::Device:STM32Cube HAL:Common:1.2.7 */
|
||||||
#define RTE_DEVICE_HAL_COMMON
|
#define RTE_DEVICE_HAL_COMMON
|
||||||
/* Keil::Device:STM32Cube HAL:Cortex:1.2.7 */
|
/* Keil::Device:STM32Cube HAL:Cortex:1.2.7 */
|
||||||
|
@ -393,15 +393,15 @@
|
|||||||
<Group>
|
<Group>
|
||||||
<GroupName>::CMSIS</GroupName>
|
<GroupName>::CMSIS</GroupName>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Group>
|
||||||
|
<GroupName>::Hesso pack</GroupName>
|
||||||
|
</Group>
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>::Compiler</GroupName>
|
<GroupName>::Compiler</GroupName>
|
||||||
</Group>
|
</Group>
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>::Device</GroupName>
|
<GroupName>::Device</GroupName>
|
||||||
</Group>
|
</Group>
|
||||||
<Group>
|
|
||||||
<GroupName>::Hesso pack</GroupName>
|
|
||||||
</Group>
|
|
||||||
</Groups>
|
</Groups>
|
||||||
</Target>
|
</Target>
|
||||||
</Targets>
|
</Targets>
|
||||||
@ -464,6 +464,12 @@
|
|||||||
<targetInfo name="Target 1"/>
|
<targetInfo name="Target 1"/>
|
||||||
</targetInfos>
|
</targetInfos>
|
||||||
</component>
|
</component>
|
||||||
|
<component Cclass="Device" Cgroup="STM32Cube HAL" Csub="CRC" Cvendor="Keil" Cversion="1.2.7" condition="STM32F7 HAL">
|
||||||
|
<package name="STM32F7xx_DFP" schemaVersion="1.6.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.12.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</component>
|
||||||
<component Cclass="Device" Cgroup="STM32Cube HAL" Csub="Common" Cvendor="Keil" Cversion="1.2.7" condition="STM32F7 HAL Common">
|
<component Cclass="Device" Cgroup="STM32Cube HAL" Csub="Common" Cvendor="Keil" Cversion="1.2.7" condition="STM32F7 HAL Common">
|
||||||
<package name="STM32F7xx_DFP" schemaVersion="1.6.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.12.0"/>
|
<package name="STM32F7xx_DFP" schemaVersion="1.6.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.12.0"/>
|
||||||
<targetInfos>
|
<targetInfos>
|
||||||
@ -605,4 +611,13 @@
|
|||||||
</files>
|
</files>
|
||||||
</RTE>
|
</RTE>
|
||||||
|
|
||||||
|
<LayerInfo>
|
||||||
|
<Layers>
|
||||||
|
<Layer>
|
||||||
|
<LayName>lab04-queue</LayName>
|
||||||
|
<LayPrjMark>1</LayPrjMark>
|
||||||
|
</Layer>
|
||||||
|
</Layers>
|
||||||
|
</LayerInfo>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
125
main.c
125
main.c
@ -5,10 +5,6 @@
|
|||||||
#include "RTE_Components.h"
|
#include "RTE_Components.h"
|
||||||
#include CMSIS_device_header
|
#include CMSIS_device_header
|
||||||
#include "cmsis_os2.h"
|
#include "cmsis_os2.h"
|
||||||
#include "ext_led.h"
|
|
||||||
#include "ext_uart.h"
|
|
||||||
#include "ext_buttons.h"
|
|
||||||
#include "ext_keyboard.h"
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -17,22 +13,33 @@
|
|||||||
#include "EventRecorder.h"
|
#include "EventRecorder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
|
||||||
osThreadId_t thread1,thread2;
|
osThreadId_t thread1,thread2;
|
||||||
osMessageQueueId_t msgQueue;
|
osMessageQueueId_t pipe1, pipe2;
|
||||||
|
osSemaphoreId_t mutexCRC;
|
||||||
|
|
||||||
const osThreadAttr_t thread1_attr = {
|
const osThreadAttr_t thread1_attr = {
|
||||||
.stack_size = 1024, // Create the thread stack size
|
.stack_size = 1024, // Create the thread stack size
|
||||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||||
.name = "Producer",
|
.name = "Task2",
|
||||||
};
|
};
|
||||||
const osThreadAttr_t thread2_attr = {
|
const osThreadAttr_t thread2_attr = {
|
||||||
.stack_size = 1024, // Create the thread stack size
|
.stack_size = 1024, // Create the thread stack size
|
||||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||||
.name = "Consumer",
|
.name = "Task2",
|
||||||
};
|
};
|
||||||
|
|
||||||
const osMessageQueueAttr_t msgQueue_attr = {
|
const osMessageQueueAttr_t pipe1_attr = {
|
||||||
.name = "MsgQueue",
|
.name = "Pipe1",
|
||||||
|
};
|
||||||
|
|
||||||
|
const osMessageQueueAttr_t pipe2_attr = {
|
||||||
|
.name = "Pipe2",
|
||||||
|
};
|
||||||
|
const osSemaphoreAttr_t mutexCRC_attr = {
|
||||||
|
.name = "MTX_CRC", // name of the semaphore
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -69,41 +76,74 @@ 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(;;) {
|
static void MX_CRC_Init(void) {
|
||||||
osStatus_t statusQueue = osMessageQueuePut(*queue, &counter, 1, 0);
|
__HAL_RCC_CRC_CLK_ENABLE();
|
||||||
if(statusQueue != osOK) {
|
hcrc.Instance = CRC;
|
||||||
// TODO generate error
|
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();
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
counter++;
|
}
|
||||||
osDelay(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 Consumer
|
* Thread Task2
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
__NO_RETURN static void Thread_Consumer (void *argument) {
|
__NO_RETURN static void Task2(void *argument) {
|
||||||
osMessageQueueId_t* queue = (osMessageQueueId_t*)argument;
|
uint32_t crc;
|
||||||
uint8_t counter = 1;
|
uint32_t recData;
|
||||||
|
|
||||||
for(;;) {
|
for (;;) {
|
||||||
uint32_t msg;
|
osSemaphoreAcquire(mutexCRC, osWaitForever);
|
||||||
osStatus_t statusQueue;
|
MX_CRC_Init();
|
||||||
|
for(uint8_t i = 0; i < 8; i++) {
|
||||||
do {
|
osMessageQueueGet(pipe1, &recData, NULL, osWaitForever);
|
||||||
statusQueue = osMessageQueueGet(*queue, &msg, NULL, 0);
|
crc = HAL_CRC_Accumulate(&hcrc, &recData, 1);
|
||||||
printf("Value is %d\r\n", msg);
|
}
|
||||||
} while(statusQueue != osErrorResource);
|
osSemaphoreRelease(mutexCRC);
|
||||||
if(++counter > 10) counter = 1;
|
osMessageQueuePut(pipe2, &crc, 1, osWaitForever);
|
||||||
osDelay(counter*100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,17 +159,22 @@ int main (void) {
|
|||||||
EventRecorderInitialize(EventRecordAll, 1U);
|
EventRecorderInitialize(EventRecordAll, 1U);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
MX_CRC_Init();
|
||||||
osKernelInitialize(); // Initialize CMSIS-RTOS
|
osKernelInitialize(); // Initialize CMSIS-RTOS
|
||||||
msgQueue = osMessageQueueNew(8, 4, &msgQueue_attr);
|
pipe1 = osMessageQueueNew(8, 4, &pipe1_attr);
|
||||||
thread1 = osThreadNew(Thread_Producer, &msgQueue, &thread1_attr);
|
pipe2 = osMessageQueueNew(8, 4, &pipe2_attr);
|
||||||
thread2 = osThreadNew(Thread_Consumer, &msgQueue, &thread2_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
|
// get names are placed for TraceAlyzer visualisation
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
osThreadGetName(thread1);
|
osThreadGetName(thread1);
|
||||||
osThreadGetName(thread2);
|
osThreadGetName(thread2);
|
||||||
osMessageQueueGetName(msgQueue);
|
osMessageQueueGetName(pipe1);
|
||||||
|
osMessageQueueGetName(pipe2);
|
||||||
|
osSemaphoreGetName(mutexCRC);
|
||||||
osKernelStart(); // Start thread execution
|
osKernelStart(); // Start thread execution
|
||||||
for (;;) {}
|
for (;;) {}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user