start practical work N°2

just add the event and measure the time of it
This commit is contained in:
Rémi Heredero 2024-04-08 16:11:43 +02:00
parent eeff72a57b
commit 8ad28e5e39
7 changed files with 381 additions and 65 deletions

135
RTE/Hesso_pack/ext_26pin.c Normal file
View File

@ -0,0 +1,135 @@
#include "stm32f7xx_hal.h"
#include "ext_26pin.h"
SPI_HandleTypeDef hspi2;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int32_t Ext_Debug_Init (void) {
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOF_CLK_ENABLE();
/* Configure GPIO pin: PF9 (GPIO_DEBUG) */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int32_t Ext_FreqGen_Init (void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
/*Configure GPIO pin : nCS_FREQ_GEN_Pin */
GPIO_InitStruct.Pin = nCS_FREQ_GEN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(nCS_FREQ_GEN_GPIO_Port, &GPIO_InitStruct);
__HAL_RCC_SPI2_CLK_ENABLE();
/**SPI2 GPIO Configuration
PI1 ------> SPI2_SCK
PB15 ------> SPI2_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
return -1;
Ext_FreqGen_Set(20,SQUARE);
Ext_FreqGen_Set(20,SQUARE);
return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void Ext_FreqGen_Set(uint32_t frequency,f_mode mode)
{
uint8_t data[2];
float calcDivisor;
uint32_t divisorInt;
calcDivisor = ((float)frequency * 268435456L) / 16000000L;
divisorInt = (uint32_t)calcDivisor + 1;
//----------------------------------------------------------------------------
// reset generator
data[0] = 0x21;
data[1] = 0x00;
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi2,data,2,10);
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
//----------------------------------------------------------------------------
// set frequency LSB (14 bits)
data[0] = ((divisorInt & 0x3FFF) | 0x4000) >> 8;
data[1] = ((divisorInt & 0x3FFF) | 0x4000) >> 0;
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi2,data,2,10);
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
//----------------------------------------------------------------------------
// set frequency MSB (14 bits)
data[0] = (((divisorInt>>14) & 0x3FFF) | 0x4000) >> 8;
data[1] = (((divisorInt>>14) & 0x3FFF) | 0x4000) >> 0;
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi2,data,2,10);
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
//----------------------------------------------------------------------------
// set output signal
data[0] = 0x20; // unreset
switch(mode)
{
case SINUS:
data[1] = 0x00;
break;
case TRIANGLE:
data[1] = 0x02;
break;
case SQUARE:
data[1] = 0x28;
break;
}
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi2,data,2,10);
HAL_GPIO_WritePin(nCS_FREQ_GEN_GPIO_Port, nCS_FREQ_GEN_Pin, GPIO_PIN_SET);
}

View File

@ -0,0 +1,47 @@
/************************************************************************//**
* \file ext_keyboard.h
* \brief Function to use the extension keyboard
* \author pascal (dot) sartoretti (at) hevs (dot) ch
***************************************************************************/
#ifndef __EXT_26PIN_H
#define __EXT_26PIN_H
#include <stdint.h>
#include "stm32f7xx_hal.h"
#define nCS_FREQ_GEN_Pin GPIO_PIN_6
#define nCS_FREQ_GEN_GPIO_Port GPIOF
typedef enum
{
SINUS,
TRIANGLE,
SQUARE
}f_mode;
/************************************************************************//**
* \brief Inits the Sparkfun frequency generator connected to SPI
* port on the 26 pin connector pins below:
* SCK = pin 3
* MOSI = pin 2
* nCS = pin 4
***************************************************************************/
int32_t Ext_FreqGen_Init (void);
/************************************************************************//**
* \brief Sets a frequency on Sparfun generator output
* \param frequency The frequency in hertz (below 20 Hz signal is bad)
* \param mode The signal mode (SINUS,TRIANGLE,SQUARE)
*
* The signal is centered at about 1.61 volt +/- 0.53 volts
***************************************************************************/
void Ext_FreqGen_Set(uint32_t frequency,f_mode mode);
/************************************************************************//**
* \brief Inits the debug pin PF9
***************************************************************************/
int32_t Ext_Debug_Init(void);
#endif /* __BOARD_LED_H */

View File

@ -0,0 +1,58 @@
#include "stm32f7xx_hal.h"
#include "ext_buttons.h"
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int32_t Ext_Buttons_Init (void) {
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
/* Configure GPIO pin: PI2 (BTN_0) */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
/* Configure GPIO pin: PI3 (BTN_1) */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
/* Configure GPIO pin: PG7 (BTN_2) */
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
/* Configure GPIO pin: PG6 (BTN_3) */
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint32_t Ext_Buttons_GetState (void) {
uint32_t val = 0;
if (HAL_GPIO_ReadPin(GPIOI, GPIO_PIN_2) == GPIO_PIN_RESET) {
val |= 1;
}
if (HAL_GPIO_ReadPin(GPIOI, GPIO_PIN_3) == GPIO_PIN_RESET) {
val |= 2;
}
if (HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_7) == GPIO_PIN_RESET) {
val |= 4;
}
if (HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_6) == GPIO_PIN_RESET) {
val |= 8;
}
return val;
}

View File

@ -0,0 +1,23 @@
/************************************************************************//**
* \file ext_buttons.h
* \brief Function to use the extension uart
* \author pascal (dot) sartoretti (at) hevs (dot) ch
***************************************************************************/
#ifndef __EXT_BUTTONS_H
#define __EXT_BUTTONS_H
#include <stdint.h>
/************************************************************************//**
* \brief Inits the external buttons usage.
* \return Always #0
***************************************************************************/
extern int32_t Ext_Buttons_Init(void);
/************************************************************************//**
* \brief Reads the buttons status
* \return The binary state of the buttons (example 4 for button 2 pressed).
***************************************************************************/
extern uint32_t Ext_Buttons_GetState(void);
#endif /* __BOARD_BUTTONS_H */

View File

@ -20,6 +20,9 @@
#define RTE_CMSIS_RTOS2 /* CMSIS-RTOS2 */
#define RTE_CMSIS_RTOS2_RTX5 /* CMSIS-RTOS2 Keil RTX5 */
#define RTE_CMSIS_RTOS2_RTX5_SOURCE /* CMSIS-RTOS2 Keil RTX5 Source */
/* Keil.ARM Compiler::Compiler:Event Recorder:DAP:1.5.1 */
#define RTE_Compiler_EventRecorder
#define RTE_Compiler_EventRecorder_DAP
/* Keil.ARM Compiler::Compiler:I/O:STDOUT:ITM:1.2.0 */
#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */
#define RTE_Compiler_IO_STDOUT_ITM /* Compiler I/O: STDOUT ITM */
@ -33,12 +36,16 @@
#define RTE_DEVICE_HAL_CORTEX
/* Keil::Device:STM32Cube HAL:DMA:1.2.7 */
#define RTE_DEVICE_HAL_DMA
/* Keil::Device:STM32Cube HAL:EXTI:1.2.7 */
#define RTE_DEVICE_HAL_EXTI
/* Keil::Device:STM32Cube HAL:GPIO:1.2.7 */
#define RTE_DEVICE_HAL_GPIO
/* Keil::Device:STM32Cube HAL:PWR:1.2.7 */
#define RTE_DEVICE_HAL_PWR
/* Keil::Device:STM32Cube HAL:RCC:1.2.7 */
#define RTE_DEVICE_HAL_RCC
/* Keil::Device:STM32Cube HAL:SPI:1.2.7 */
#define RTE_DEVICE_HAL_SPI
/* Keil::Device:STM32Cube HAL:UART:1.2.7 */
#define RTE_DEVICE_HAL_UART
/* Keil::Device:Startup:1.2.4 */

View File

@ -434,6 +434,18 @@
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="26_PIN" Cvendor="HessoValais" Cversion="1.2.0" condition="any">
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="Buttons" Cvendor="HessoValais" Cversion="1.0.0" condition="any">
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="LEDs" Cvendor="HessoValais" Cversion="1.0.0" condition="any">
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
@ -446,6 +458,12 @@
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cbundle="ARM Compiler" Cclass="Compiler" Cgroup="Event Recorder" Cvariant="DAP" Cvendor="Keil" Cversion="1.5.1" condition="Cortex-M Device">
<package name="ARM_Compiler" schemaVersion="1.7.7" url="https://www.keil.com/pack/" vendor="Keil" version="1.7.2"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cbundle="ARM Compiler" Cclass="Compiler" Cgroup="I/O" Csub="STDOUT" Cvariant="ITM" Cvendor="Keil" Cversion="1.2.0" condition="ARMCC Cortex-M with ITM">
<package name="ARM_Compiler" schemaVersion="1.7.7" url="https://www.keil.com/pack/" vendor="Keil" version="1.7.2"/>
<targetInfos>
@ -482,6 +500,12 @@
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Device" Cgroup="STM32Cube HAL" Csub="EXTI" 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="GPIO" 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>
@ -500,6 +524,12 @@
<targetInfo name="Target 1"/>
</targetInfos>
</component>
<component Cclass="Device" Cgroup="STM32Cube HAL" Csub="SPI" Cvendor="Keil" Cversion="1.2.7" condition="STM32F7 HAL DMA">
<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="UART" Cvendor="Keil" Cversion="1.2.7" condition="STM32F7 HAL DMA">
<package name="STM32F7xx_DFP" schemaVersion="1.6.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.12.0"/>
<targetInfos>
@ -531,10 +561,12 @@
</targetInfos>
</file>
<file attr="config" category="header" name="Config\EventRecorderConf.h" version="1.1.0">
<instance index="0" removed="1">RTE\Compiler\EventRecorderConf.h</instance>
<instance index="0">RTE\Compiler\EventRecorderConf.h</instance>
<component Cbundle="ARM Compiler" Cclass="Compiler" Cgroup="Event Recorder" Cvariant="DAP" Cvendor="Keil" Cversion="1.5.1" condition="Cortex-M Device"/>
<package name="ARM_Compiler" schemaVersion="1.7.7" url="https://www.keil.com/pack/" vendor="Keil" version="1.7.2"/>
<targetInfos/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="header" name="CMSIS\Driver\Config\RTE_Device.h" version="1.5.1">
<instance index="0">RTE\Device\STM32F746NGHx\RTE_Device.h</instance>
@ -568,6 +600,38 @@
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="source" name="extension_board\ext_26pin.c" version="1.2.0">
<instance index="0">RTE\Hesso_pack\ext_26pin.c</instance>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="26_PIN" Cvendor="HessoValais" Cversion="1.2.0" condition="any"/>
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="header" name="extension_board\ext_26pin.h" version="1.2.0">
<instance index="0">RTE\Hesso_pack\ext_26pin.h</instance>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="26_PIN" Cvendor="HessoValais" Cversion="1.2.0" condition="any"/>
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="source" name="extension_board\ext_buttons.c" version="1.0.0">
<instance index="0">RTE\Hesso_pack\ext_buttons.c</instance>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="Buttons" Cvendor="HessoValais" Cversion="1.0.0" condition="any"/>
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="header" name="extension_board\ext_buttons.h" version="1.0.0">
<instance index="0">RTE\Hesso_pack\ext_buttons.h</instance>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="Buttons" Cvendor="HessoValais" Cversion="1.0.0" condition="any"/>
<package name="Extension_board" schemaVersion="1.2" url="http://kpacks.hevs.ch/HessoValais.Extension_board.pdsc" vendor="HessoValais" version="1.2.0"/>
<targetInfos>
<targetInfo name="Target 1"/>
</targetInfos>
</file>
<file attr="config" category="source" name="extension_board\ext_led.c" version="1.0.0">
<instance index="0">RTE\Hesso_pack\ext_led.c</instance>
<component Cclass="Hesso pack" Cgroup="Extension Board" Csub="LEDs" Cvendor="HessoValais" Cversion="1.0.0" condition="any"/>

106
main.c
View File

@ -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"
};
const osThreadAttr_t AttrTask5 = {
.stack_size = 1024, // Create the thread stack size
.priority = osPriorityHigh, //Set initial thread priority to high
.name = "Task 5",
};
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);
}
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;
int main (void) {
// 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();