Add V3 implementation (not tested)
This commit is contained in:
parent
dce33b5b89
commit
33672839e9
@ -129,6 +129,10 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
|
||||
header file. */
|
||||
/* USER CODE BEGIN 1 */
|
||||
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
|
||||
#include "usage.h"
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 1
|
||||
#define traceTASK_SWITCHED_IN() Usage_TaskSwitchedIn()
|
||||
#define traceTASK_SWITCHED_OUT() Usage_TaskSwitchedOut()
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
|
||||
|
||||
@ -61,14 +61,11 @@ unsigned long getRunTimeCounterValue(void);
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
|
||||
__weak void configureTimerForRunTimeStats(void)
|
||||
#include "usage.h"
|
||||
void configureTimerForRunTimeStats(void) { }
|
||||
unsigned long getRunTimeCounterValue(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
__weak unsigned long getRunTimeCounterValue(void)
|
||||
{
|
||||
return 0;
|
||||
return Usage_GetTicks();
|
||||
}
|
||||
/* USER CODE END 1 */
|
||||
|
||||
|
||||
@ -35,15 +35,21 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
// gpio pin assignment
|
||||
#define LED_RED_GPIO_PORT GPIOA
|
||||
#define LED_RED_GPIO_PIN GPIO_PIN_7
|
||||
|
||||
#define LED_GREEN_GPIO_PORT GPIOB
|
||||
#define LED_GREEN_GPIO_PIN GPIO_PIN_1
|
||||
|
||||
#define LED_BLUE_GPIO_PORT GPIOA
|
||||
#define LED_BLUE_GPIO_PIN GPIO_PIN_5
|
||||
|
||||
#define BUTTON_GPIO_PORT GPIOA
|
||||
#define BUTTON_GPIO_PIN GPIO_PIN_0
|
||||
|
||||
// touch controller constants
|
||||
#define TOUCH_EVENT_IS_PRESSED 8
|
||||
#define TOUCH_EVENT_NOT_PRESSED 4
|
||||
#define TOUCH_EVENT_JUST_PRESSED 0
|
||||
@ -124,6 +130,95 @@ void drawButton(bool isPressed){
|
||||
}
|
||||
|
||||
|
||||
//==========================
|
||||
//==== Task definitions ====
|
||||
//==========================
|
||||
void Task1_blinkGreenLed(void *){
|
||||
while(1){
|
||||
HAL_GPIO_TogglePin(LED_GREEN_GPIO_PORT, LED_GREEN_GPIO_PIN);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
//HAL_Delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
void Task2_blinkBlueLed(void *){
|
||||
while(1){
|
||||
HAL_GPIO_TogglePin(LED_BLUE_GPIO_PORT, LED_BLUE_GPIO_PIN);
|
||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||
//HAL_Delay(1500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SemaphoreHandle_t Mutex_redLed = NULL;
|
||||
void Task3_4_blinkRedLed(void * param_uint32_blinkDelay){
|
||||
uint32_t blinkDelayMs = (uint32_t)param_uint32_blinkDelay;
|
||||
while(1){
|
||||
xSemaphoreTake(Mutex_redLed, portMAX_DELAY);
|
||||
|
||||
for (int i=0; i<2; i++){
|
||||
HAL_GPIO_WritePin(LED_RED_GPIO_PORT, LED_RED_GPIO_PIN, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(blinkDelayMs));
|
||||
HAL_GPIO_WritePin(LED_RED_GPIO_PORT, LED_RED_GPIO_PIN, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(blinkDelayMs));
|
||||
}
|
||||
|
||||
xSemaphoreGive(Mutex_redLed);
|
||||
vTaskDelay(pdMS_TO_TICKS(75));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SemaphoreHandle_t Semphr_buttonPressEvent = NULL;
|
||||
QueueHandle_t Queue_buttonEvents;
|
||||
void Task5_readButton(void *){
|
||||
bool buttonIsPressed, buttonIsPressedLast = false;
|
||||
while(1){
|
||||
buttonIsPressedLast = buttonIsPressed;
|
||||
buttonIsPressed = HAL_GPIO_ReadPin(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN) == GPIO_PIN_SET;
|
||||
|
||||
if (buttonIsPressed && !buttonIsPressedLast) { //rising edge, pressed event
|
||||
// free semaphore (notifies Task6)
|
||||
xSemaphoreGive(Semphr_buttonPressEvent);
|
||||
// send event to queue (used in Task7)
|
||||
bool queueElement = true;
|
||||
xQueueSendToBack(Queue_buttonEvents, &queueElement, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
else if (!buttonIsPressed && buttonIsPressedLast){ //falling edge, released event
|
||||
// send event to queue (used in Task7)
|
||||
bool queueElement = false;
|
||||
xQueueSendToBack(Queue_buttonEvents, &queueElement, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(25));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Task6_countButtonPresses(void *){
|
||||
uint16_t y = 0;
|
||||
while(1){
|
||||
if (xSemaphoreTake(Semphr_buttonPressEvent, pdMS_TO_TICKS(1000))){
|
||||
y++;
|
||||
printf("Task6: received Semaphore, current count = %d", y);
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
}
|
||||
printf("### Task 6 Loop ###");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Task7_receiveQueueEvents(void *){
|
||||
bool receivedEvent;
|
||||
while(1){
|
||||
if (xQueueReceive(Queue_buttonEvents, &receivedEvent, portMAX_DELAY)){
|
||||
printf("Task 7: %s", receivedEvent ? "pressed" : "released");
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -160,6 +255,8 @@ int main(void)
|
||||
MX_I2C3_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
Usage_Init();
|
||||
|
||||
Display_Init();
|
||||
// local variables
|
||||
uint32_t timestamp_lastCounted = HAL_GetTick();
|
||||
@ -169,20 +266,19 @@ int main(void)
|
||||
uint8_t Eventflag = TOUCH_EVENT_NOT_PRESSED, EventflagLast = TOUCH_EVENT_NOT_PRESSED;
|
||||
uint16_t xRaw, yRaw;
|
||||
int32_t xTouch, yTouch;
|
||||
bool buttonIsPressed;
|
||||
|
||||
|
||||
|
||||
drawButton(false);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* USER CODE BEGIN RTOS_MUTEX */
|
||||
/* add mutexes, ... */
|
||||
Mutex_redLed = xSemaphoreCreateMutex();
|
||||
/* USER CODE END RTOS_MUTEX */
|
||||
|
||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||
/* add semaphores, ... */
|
||||
Semphr_buttonPressEvent = xSemaphoreCreateBinary();
|
||||
/* USER CODE END RTOS_SEMAPHORES */
|
||||
|
||||
/* USER CODE BEGIN RTOS_TIMERS */
|
||||
@ -191,6 +287,7 @@ int main(void)
|
||||
|
||||
/* USER CODE BEGIN RTOS_QUEUES */
|
||||
/* add queues, ... */
|
||||
Queue_buttonEvents = xQueueCreate(10, sizeof(bool));
|
||||
/* USER CODE END RTOS_QUEUES */
|
||||
|
||||
/* Create the thread(s) */
|
||||
@ -198,6 +295,21 @@ int main(void)
|
||||
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 256);
|
||||
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||
|
||||
xTaskCreate(Task1_blinkGreenLed, "Task1_green-led", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task2_blinkBlueLed, "Task2_blue-led", 256, NULL, 0, NULL);
|
||||
|
||||
uint32_t delay1 = 150;
|
||||
xTaskCreate(Task3_4_blinkRedLed, "Task3_red-led-150", 256, (void *)&delay1, 0, NULL);
|
||||
uint32_t delay2 = 600;
|
||||
xTaskCreate(Task3_4_blinkRedLed, "Task4_red-led-600", 256, (void *)&delay2, 0, NULL);
|
||||
|
||||
xTaskCreate(Task5_readButton, "Task5_read-button", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task6_countButtonPresses, "Task6_countButtonPresses", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task7_receiveQueueEvents, "Task7_receiveQueueEvents", 256, NULL, 0, NULL);
|
||||
|
||||
|
||||
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
@ -211,68 +323,9 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
// display 100 count down
|
||||
if (time_msPassedSince(timestamp_lastCounted) >= 100) {
|
||||
timestamp_lastCounted = HAL_GetTick();
|
||||
Display_Printf( 0, 10,
|
||||
LCD_COLOR_WHITE, LCD_COLOR_BLACK,
|
||||
&FontBig,
|
||||
"Zahl %d", i
|
||||
);
|
||||
if (i == 0) i = 100;
|
||||
else i--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// every 20ms: read touch, print values, convert values, draw pixel, handle button
|
||||
if (time_msPassedSince(timestamp_lastTouchRead) >= 20) { // run this block every 20ms
|
||||
timestamp_lastTouchRead = HAL_GetTick();
|
||||
// read touch register
|
||||
HAL_I2C_Mem_Read(I2C3, 112, 3, I2C_MEMADD_SIZE_8BIT, DataRx, 4, 1000);
|
||||
|
||||
// interpret received data
|
||||
EventflagLast = Eventflag;
|
||||
Eventflag = (uint8_t)(DataRx[0] >> 4);
|
||||
yRaw = (uint16_t)((DataRx[0] & 0b00001111) << 8) | (uint16_t)DataRx[1];
|
||||
xRaw = (uint16_t)((DataRx[2] & 0b00001111) << 8) | (uint16_t)DataRx[3];
|
||||
|
||||
// show pos values on display
|
||||
if (Eventflag == TOUCH_EVENT_IS_PRESSED) printf("is pressed \n");
|
||||
Display_Printf( 0, 30,
|
||||
LCD_COLOR_WHITE, LCD_COLOR_BLACK,
|
||||
&FontBig,
|
||||
"x=%d y=%d", xRaw, yRaw
|
||||
);
|
||||
|
||||
//scale to display size
|
||||
xTouch = 239 * ((int32_t)xRaw - CAL_TOUCH_TOP_LEFT_X) / ((int32_t)CAL_TOUCH_BOT_RIGHT_X - CAL_TOUCH_TOP_LEFT_X);
|
||||
yTouch = 239 * ((int32_t)yRaw - CAL_TOUCH_TOP_LEFT_Y) / ((int32_t)CAL_TOUCH_BOT_RIGHT_Y - CAL_TOUCH_TOP_LEFT_Y);
|
||||
xTouch = clamp_i16(xTouch, 0, 239);
|
||||
yTouch = clamp_i16(yTouch, 0, 239);
|
||||
|
||||
|
||||
// draw position when pressed
|
||||
if (Eventflag == TOUCH_EVENT_IS_PRESSED){
|
||||
Display_DrawPixel( (uint16_t)xTouch, (uint16_t)yTouch, LCD_COLOR_WHITE );
|
||||
}
|
||||
|
||||
|
||||
// determine button pressed condition
|
||||
bool isInsideButtonArea = xTouch > 75 && xTouch < (75+100) && yTouch > 130 && yTouch < (130+100);
|
||||
bool touchIsPressed = Eventflag == TOUCH_EVENT_IS_PRESSED;
|
||||
|
||||
bool buttonIsPressedLast = buttonIsPressed;
|
||||
buttonIsPressed = isInsideButtonArea && touchIsPressed;
|
||||
|
||||
// just got pressed -> draw pressed button
|
||||
if (buttonIsPressed && !buttonIsPressedLast) drawButton(true);
|
||||
// just got released -> draw released button
|
||||
if (!buttonIsPressed && buttonIsPressedLast) drawButton(false);
|
||||
|
||||
} // end "run every 20ms"
|
||||
|
||||
|
||||
// print processor statistics
|
||||
Usage_PrintStats();
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
../Core/Src/freertos.c:64:13:configureTimerForRunTimeStats 1
|
||||
../Core/Src/freertos.c:69:22:getRunTimeCounterValue 1
|
||||
../Core/Src/freertos.c:79:6:vApplicationGetIdleTaskMemory 1
|
||||
../Core/Src/freertos.c:65:6:configureTimerForRunTimeStats 1
|
||||
../Core/Src/freertos.c:66:15:getRunTimeCounterValue 1
|
||||
../Core/Src/freertos.c:76:6:vApplicationGetIdleTaskMemory 1
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
../Core/Src/freertos.c:64:13:configureTimerForRunTimeStats 4 static
|
||||
../Core/Src/freertos.c:69:22:getRunTimeCounterValue 4 static
|
||||
../Core/Src/freertos.c:79:6:vApplicationGetIdleTaskMemory 24 static
|
||||
../Core/Src/freertos.c:65:6:configureTimerForRunTimeStats 4 static
|
||||
../Core/Src/freertos.c:66:15:getRunTimeCounterValue 8 static
|
||||
../Core/Src/freertos.c:76:6:vApplicationGetIdleTaskMemory 24 static
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
../Core/Src/main.c:92:5:_write 1
|
||||
../Core/Src/main.c:99:10:time_msPassedSince 1
|
||||
../Core/Src/main.c:106:23:clamp_i16 3
|
||||
../Core/Src/main.c:114:6:drawButton 2
|
||||
../Core/Src/main.c:133:5:main 16
|
||||
../Core/Src/main.c:287:6:SystemClock_Config 4
|
||||
../Core/Src/main.c:344:13:MX_I2C3_Init 4
|
||||
../Core/Src/main.c:392:13:MX_USART6_UART_Init 2
|
||||
../Core/Src/main.c:423:13:MX_FMC_Init 2
|
||||
../Core/Src/main.c:481:13:MX_GPIO_Init 1
|
||||
../Core/Src/main.c:858:6:StartDefaultTask 1
|
||||
../Core/Src/main.c:877:6:HAL_TIM_PeriodElapsedCallback 2
|
||||
../Core/Src/main.c:895:6:Error_Handler 1
|
||||
../Core/Src/main.c:98:5:_write 1
|
||||
../Core/Src/main.c:105:10:time_msPassedSince 1
|
||||
../Core/Src/main.c:120:6:drawButton 2
|
||||
../Core/Src/main.c:136:6:Task1_blinkGreenLed 1
|
||||
../Core/Src/main.c:144:6:Task2_blinkBlueLed 1
|
||||
../Core/Src/main.c:154:6:Task3_4_blinkRedLed 2
|
||||
../Core/Src/main.c:174:6:Task5_readButton 5
|
||||
../Core/Src/main.c:197:6:Task6_countButtonPresses 2
|
||||
../Core/Src/main.c:210:6:Task7_receiveQueueEvents 3
|
||||
../Core/Src/main.c:228:5:main 1
|
||||
../Core/Src/main.c:340:6:SystemClock_Config 4
|
||||
../Core/Src/main.c:397:13:MX_I2C3_Init 4
|
||||
../Core/Src/main.c:445:13:MX_USART6_UART_Init 2
|
||||
../Core/Src/main.c:476:13:MX_FMC_Init 2
|
||||
../Core/Src/main.c:534:13:MX_GPIO_Init 1
|
||||
../Core/Src/main.c:911:6:StartDefaultTask 1
|
||||
../Core/Src/main.c:930:6:HAL_TIM_PeriodElapsedCallback 2
|
||||
../Core/Src/main.c:948:6:Error_Handler 1
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
../Core/Src/main.c:92:5:_write 24 static
|
||||
../Core/Src/main.c:99:10:time_msPassedSince 16 static
|
||||
../Core/Src/main.c:106:23:clamp_i16 24 static
|
||||
../Core/Src/main.c:114:6:drawButton 24 static
|
||||
../Core/Src/main.c:133:5:main 96 static
|
||||
../Core/Src/main.c:287:6:SystemClock_Config 88 static
|
||||
../Core/Src/main.c:344:13:MX_I2C3_Init 8 static
|
||||
../Core/Src/main.c:392:13:MX_USART6_UART_Init 8 static
|
||||
../Core/Src/main.c:423:13:MX_FMC_Init 40 static
|
||||
../Core/Src/main.c:481:13:MX_GPIO_Init 64 static
|
||||
../Core/Src/main.c:858:6:StartDefaultTask 16 static
|
||||
../Core/Src/main.c:877:6:HAL_TIM_PeriodElapsedCallback 16 static
|
||||
../Core/Src/main.c:895:6:Error_Handler 4 static,ignoring_inline_asm
|
||||
../Core/Src/main.c:98:5:_write 24 static
|
||||
../Core/Src/main.c:105:10:time_msPassedSince 16 static
|
||||
../Core/Src/main.c:120:6:drawButton 24 static
|
||||
../Core/Src/main.c:136:6:Task1_blinkGreenLed 16 static
|
||||
../Core/Src/main.c:144:6:Task2_blinkBlueLed 16 static
|
||||
../Core/Src/main.c:154:6:Task3_4_blinkRedLed 24 static
|
||||
../Core/Src/main.c:174:6:Task5_readButton 24 static
|
||||
../Core/Src/main.c:197:6:Task6_countButtonPresses 24 static
|
||||
../Core/Src/main.c:210:6:Task7_receiveQueueEvents 24 static
|
||||
../Core/Src/main.c:228:5:main 80 static
|
||||
../Core/Src/main.c:340:6:SystemClock_Config 88 static
|
||||
../Core/Src/main.c:397:13:MX_I2C3_Init 8 static
|
||||
../Core/Src/main.c:445:13:MX_USART6_UART_Init 8 static
|
||||
../Core/Src/main.c:476:13:MX_FMC_Init 40 static
|
||||
../Core/Src/main.c:534:13:MX_GPIO_Init 64 static
|
||||
../Core/Src/main.c:911:6:StartDefaultTask 16 static
|
||||
../Core/Src/main.c:930:6:HAL_TIM_PeriodElapsedCallback 16 static
|
||||
../Core/Src/main.c:948:6:Error_Handler 4 static,ignoring_inline_asm
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2330:13:uxTaskGetNumberOfTasks 1
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2338:7:pcTaskGetName 3
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2485:14:uxTaskGetSystemState 4
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2559:15:xTaskGetIdleTaskHandle 2
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2665:12:xTaskIncrementTick 11
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2947:6:vTaskSwitchContext 5
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:3020:6:vTaskPlaceOnEventList 2
|
||||
@ -54,4 +55,5 @@
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:4828:13:xTaskGenericNotifyFromISR 15
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:4957:7:vTaskNotifyGiveFromISR 7
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:5044:13:xTaskNotifyStateClear 3
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:5074:13:xTaskGetIdleRunTimeCounter 1
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:5081:13:prvAddCurrentTaskToDelayedList 6
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2330:13:uxTaskGetNumberOfTasks 4 static
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2338:7:pcTaskGetName 24 static,ignoring_inline_asm
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2485:14:uxTaskGetSystemState 32 static
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2559:15:xTaskGetIdleTaskHandle 16 static,ignoring_inline_asm
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2665:12:xTaskIncrementTick 32 static,ignoring_inline_asm
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:2947:6:vTaskSwitchContext 32 static,ignoring_inline_asm
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:3020:6:vTaskPlaceOnEventList 24 static,ignoring_inline_asm
|
||||
@ -54,4 +55,5 @@
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:4828:13:xTaskGenericNotifyFromISR 64 static,ignoring_inline_asm
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:4957:7:vTaskNotifyGiveFromISR 48 static,ignoring_inline_asm
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:5044:13:xTaskNotifyStateClear 24 static
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:5074:13:xTaskGetIdleRunTimeCounter 4 static
|
||||
../Middlewares/Third_Party/FreeRTOS/Source/tasks.c:5081:13:prvAddCurrentTaskToDelayedList 24 static
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user