start practical work N°2
just add the event and measure the time of it
This commit is contained in:
108
main.c
108
main.c
@@ -2,81 +2,68 @@
|
||||
* CMSIS-RTOS 'main' function template
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "stm32f7xx_hal_conf.h"
|
||||
#include "RTE_Components.h"
|
||||
#include CMSIS_device_header
|
||||
#include "cmsis_os2.h"
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
#include "ext_uart.h"
|
||||
#include "ext_buttons.h"
|
||||
#include "ext_26pin.h"
|
||||
|
||||
|
||||
#ifdef RTE_Compiler_EventRecorder
|
||||
#include "EventRecorder.h"
|
||||
#endif
|
||||
|
||||
#define NBR_COUNTER 4
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
osThreadId_t idTask1, idTask2, idTask3, idTask4, idTask5;
|
||||
osMutexId_t mutexCounter[NBR_COUNTER];
|
||||
osThreadId_t idTask1;
|
||||
osEventFlagsId_t evt_id;
|
||||
|
||||
const osThreadAttr_t AttrTask1 = {
|
||||
.stack_size = 512, // Create the thread stack size
|
||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||
.name = "Task 1"
|
||||
};
|
||||
const osThreadAttr_t AttrTask2 = {
|
||||
.stack_size = 512, // Create the thread stack size
|
||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||
.name = "Task 2"
|
||||
};
|
||||
const osThreadAttr_t AttrTask3 = {
|
||||
.stack_size = 512, // Create the thread stack size
|
||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||
.name = "Task 3"
|
||||
};
|
||||
const osThreadAttr_t AttrTask4 = {
|
||||
.stack_size = 512, // Create the thread stack size
|
||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||
.name = "Task 4"
|
||||
};
|
||||
|
||||
void init_button(void)
|
||||
{
|
||||
/* Configure GPIO pin: PI2 (BTN_0) as interrupt */
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
HAL_NVIC_SetPriority(EXTI2_IRQn,5,5);
|
||||
HAL_NVIC_EnableIRQ(EXTI2_IRQn);
|
||||
}
|
||||
|
||||
const osThreadAttr_t AttrTask5 = {
|
||||
.stack_size = 1024, // Create the thread stack size
|
||||
.priority = osPriorityHigh, //Set initial thread priority to high
|
||||
.name = "Task 5",
|
||||
};
|
||||
|
||||
uint32_t counter[NBR_COUNTER];
|
||||
void EXTI2_IRQHandler(void)
|
||||
{
|
||||
EventRecord2(0x000,0,0);
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
|
||||
EventRecord2(0x100,0,0);
|
||||
}
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_PIN)
|
||||
{
|
||||
//button interrupt
|
||||
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_9);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread Task counter
|
||||
* Thread 1
|
||||
*---------------------------------------------------------------------------*/
|
||||
__NO_RETURN static void taskCounter(void *argument) {
|
||||
uint8_t idCounter = (uint8_t) *((uint8_t* )argument);
|
||||
for (;;) {
|
||||
osMutexAcquire(mutexCounter[idCounter], osWaitForever);
|
||||
counter[idCounter]++;
|
||||
osMutexRelease(mutexCounter[idCounter]);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread Task 5
|
||||
*---------------------------------------------------------------------------*/
|
||||
__NO_RETURN static void task5(void *argument) {
|
||||
uint32_t freq = osKernelGetTickFreq();
|
||||
uint32_t countTick = freq*5;
|
||||
|
||||
for (;;) {
|
||||
uint32_t sum = 0;
|
||||
for(uint8_t i = 0; i < NBR_COUNTER; i++)
|
||||
{
|
||||
osMutexAcquire(mutexCounter[i], osWaitForever);
|
||||
sum += counter[i];
|
||||
printf("[%d] ", counter[i]);
|
||||
osMutexRelease(mutexCounter[i]);
|
||||
}
|
||||
printf("\r\nSum = %u\r\n", sum);
|
||||
osDelay(countTick);
|
||||
osEventFlagsWait(evt_id);
|
||||
osEventFlagsClear(evt_id, );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,16 +98,16 @@ void SystemClock_Config (void) {
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
|
||||
}
|
||||
|
||||
|
||||
int main (void) {
|
||||
|
||||
uint8_t task1_parameter = 0;
|
||||
uint8_t task2_parameter = 1;
|
||||
uint8_t task3_parameter = 2;
|
||||
uint8_t task4_parameter = 3;
|
||||
|
||||
// System Initialization
|
||||
SystemCoreClockUpdate();
|
||||
SystemClock_Config();
|
||||
|
||||
Ext_Debug_Init();//initialize pin pf9 as output
|
||||
init_button();
|
||||
|
||||
#ifdef RTE_Compiler_EventRecorder
|
||||
// Initialize and start Event Recorder
|
||||
// Ext_UART_Init(9600);
|
||||
@@ -129,20 +116,15 @@ int main (void) {
|
||||
|
||||
osKernelInitialize(); // Initialize CMSIS-RTOS
|
||||
|
||||
idTask1 = osThreadNew(taskCounter, &task1_parameter, &AttrTask1);
|
||||
idTask2 = osThreadNew(taskCounter, &task2_parameter, &AttrTask2);
|
||||
idTask3 = osThreadNew(taskCounter, &task3_parameter, &AttrTask3);
|
||||
idTask4 = osThreadNew(taskCounter, &task4_parameter, &AttrTask4);
|
||||
idTask5 = osThreadNew(task5, NULL, &AttrTask5);
|
||||
|
||||
idTask1 = osThreadNew(taskCounter, NULL, &AttrTask1);
|
||||
|
||||
//events
|
||||
evt_id = osEventFlagsNew(NULL);
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// get names are placed for TraceAlyzer visualisation
|
||||
//----------------------------------------------------------------------------------------------
|
||||
osThreadGetName(idTask1);
|
||||
osThreadGetName(idTask2);
|
||||
osThreadGetName(idTask3);
|
||||
osThreadGetName(idTask4);
|
||||
osThreadGetName(idTask5);
|
||||
|
||||
|
||||
osKernelStart();
|
||||
|
||||
Reference in New Issue
Block a user