practical work N°1 finish
We measure that switching context time is around: - 20us without optimization, with EventRecorder - 6us without optimization, without EventRecorder - 2us with optimization (o2), without EventRecorder
This commit is contained in:
parent
26880f9bb8
commit
eeff72a57b
@ -64,7 +64,7 @@
|
||||
// <i> Defines how many ticks a thread will execute before a thread switch.
|
||||
// <i> Default: 5
|
||||
#ifndef OS_ROBIN_TIMEOUT
|
||||
#define OS_ROBIN_TIMEOUT 5
|
||||
#define OS_ROBIN_TIMEOUT 1
|
||||
#endif
|
||||
|
||||
// </e>
|
||||
|
@ -20,15 +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:STDIN:User:1.2.0 */
|
||||
#define RTE_Compiler_IO_STDIN /* Compiler I/O: STDIN */
|
||||
#define RTE_Compiler_IO_STDIN_User /* Compiler I/O: STDIN User */
|
||||
/* Keil.ARM Compiler::Compiler:I/O:STDOUT:User:1.2.0 */
|
||||
/* 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_User /* Compiler I/O: STDOUT User */
|
||||
#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 */
|
||||
|
@ -313,7 +313,7 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>1</Optim>
|
||||
<Optim>3</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
@ -446,19 +446,7 @@
|
||||
<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="STDIN" Cvariant="User" Cvendor="Keil" Cversion="1.2.0" condition="ARMCC Cortex-M">
|
||||
<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="User" Cvendor="Keil" Cversion="1.2.0" condition="ARMCC Cortex-M">
|
||||
<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>
|
||||
<targetInfo name="Target 1"/>
|
||||
@ -543,12 +531,10 @@
|
||||
</targetInfos>
|
||||
</file>
|
||||
<file attr="config" category="header" name="Config\EventRecorderConf.h" version="1.1.0">
|
||||
<instance index="0">RTE\Compiler\EventRecorderConf.h</instance>
|
||||
<instance index="0" removed="1">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>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
<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>
|
||||
|
152
main.c
Normal file
152
main.c
Normal file
@ -0,0 +1,152 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS 'main' function template
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "RTE_Components.h"
|
||||
#include CMSIS_device_header
|
||||
#include "cmsis_os2.h"
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
#include "ext_uart.h"
|
||||
|
||||
#ifdef RTE_Compiler_EventRecorder
|
||||
#include "EventRecorder.h"
|
||||
#endif
|
||||
|
||||
#define NBR_COUNTER 4
|
||||
|
||||
osThreadId_t idTask1, idTask2, idTask3, idTask4, idTask5;
|
||||
osMutexId_t mutexCounter[NBR_COUNTER];
|
||||
|
||||
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",
|
||||
};
|
||||
|
||||
uint32_t counter[NBR_COUNTER];
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread Task counter
|
||||
*---------------------------------------------------------------------------*/
|
||||
__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);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup system clock to 216MHz
|
||||
//------------------------------------------------------------------------------
|
||||
void SystemClock_Config (void) {
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
|
||||
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 25;
|
||||
RCC_OscInitStruct.PLL.PLLN = 432;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 9;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/* Activate the OverDrive to reach the 216 MHz Frequency */
|
||||
HAL_PWREx_EnableOverDrive();
|
||||
|
||||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
|
||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
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();
|
||||
#ifdef RTE_Compiler_EventRecorder
|
||||
// Initialize and start Event Recorder
|
||||
// Ext_UART_Init(9600);
|
||||
EventRecorderInitialize(EventRecordAll, 1U);
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// get names are placed for TraceAlyzer visualisation
|
||||
//----------------------------------------------------------------------------------------------
|
||||
osThreadGetName(idTask1);
|
||||
osThreadGetName(idTask2);
|
||||
osThreadGetName(idTask3);
|
||||
osThreadGetName(idTask4);
|
||||
osThreadGetName(idTask5);
|
||||
|
||||
|
||||
osKernelStart();
|
||||
// Start thread execution
|
||||
for (;;) {
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user