From 6f27bb7d81b56f9b697b71f0552d89b4256157ca Mon Sep 17 00:00:00 2001 From: Dmitry Maylarov Date: Wed, 10 Jul 2019 16:30:28 +0300 Subject: [PATCH] trying to make it work --- Core/Inc/FreeRTOSConfig.h | 2 +- Core/Inc/main.h | 22 ++++++++++++ Core/Src/game.c | 3 ++ Core/Src/lcd.c | 4 +++ Core/Src/main.c | 73 +++++++++++++++------------------------ Makefile | 7 +++- 6 files changed, 63 insertions(+), 48 deletions(-) diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 4f11b74..6b95a77 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -73,7 +73,7 @@ #define configUSE_TICKLESS_IDLE 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ CLOCK +#define configCPU_CLOCK_HZ 24000000 #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMAX_PRIORITIES 5 #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 ) diff --git a/Core/Inc/main.h b/Core/Inc/main.h index accd48f..a44f75c 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -32,6 +32,13 @@ extern "C" { /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include +#include "lcd.h" +#include "game.h" +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "timers.h" /* USER CODE END Includes */ @@ -56,7 +63,22 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); void Error_Handler(void); /* USER CODE BEGIN EFP */ +void vTaskLed(void *parameter); +void vTaskButton(void *parameter); +void vTaskDisplay(void *parameter); +void vTaskBeep(void *parameter); +void vTaskOvertime(void *parameter); + +void vTaskStateMachine(void *parameter); + +void vTaskPlayerSetup(void *parameter); +void vTaskConfig(void *parameter); +void vTaskTimerSetup(void *parameter); +void vTaskTurn(void *parameter); +void vTaskTurnEnd(void *parameter); + +void vTimerCallback(TimerHandle_t xTimer); /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ diff --git a/Core/Src/game.c b/Core/Src/game.c index 0f7b42a..205f091 100644 --- a/Core/Src/game.c +++ b/Core/Src/game.c @@ -1,3 +1,5 @@ +#ifndef __GAME_H +#define __GAME_H #include "game.h" void InitGameEngine() { @@ -59,3 +61,4 @@ void NextPlayer() { game.currentPlayer = (game.currentPlayer + 1) % game.activePlayers; ResetTurnTimer(); } +#endif \ No newline at end of file diff --git a/Core/Src/lcd.c b/Core/Src/lcd.c index 5e321cd..d52d2a6 100644 --- a/Core/Src/lcd.c +++ b/Core/Src/lcd.c @@ -1,3 +1,5 @@ +#ifndef __LCD_H +#define __LCD_H #include "lcd.h" #define LCD_COLS 20 @@ -117,3 +119,5 @@ void LCD_SendString(LCD_HandleTypeDef *lcd, char *str) { str++; } } + +#endif \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index cd02400..d406986 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -24,13 +24,6 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include -#include "lcd.h" -#include "game.h" -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "timers.h" /* USER CODE END Includes */ @@ -71,6 +64,11 @@ LCD_HandleTypeDef hlcd = { LCD_ROWS, LCD_COLS }; +bool plusButton = false; +bool minusButton = false; +bool bigButton = false; + +static TimerHandle_t secondsTimerHandle = NULL; /* USER CODE END PV */ @@ -129,6 +127,9 @@ int main(void) /* USER CODE BEGIN 2 */ LCD_Init(&hlcd); InitGameEngine(); + + xTaskCreate(vTaskPlayerSetup, "Player", configMINIMAL_STACK_SIZE, NULL, 1, NULL); + vTaskStartScheduler(); /* USER CODE END 2 */ /* Infinite loop */ @@ -430,41 +431,21 @@ static void MX_GPIO_Init(void) } /* USER CODE BEGIN 4 */ -void logic() -{ - led1.SetHigh(); - usart.Send(); - xTaskCreate(vTaskLed, "LED", configMINIMAL_STACK_SIZE, NULL, 1, NULL); -// xTaskCreate(vTaskStateMachine, "FSM", configMINIMAL_STACK_SIZE, NULL, 1, NULL); - xTaskCreate(vTaskPlayerSetup, "Player", configMINIMAL_STACK_SIZE, NULL, 1, NULL); - vTaskStartScheduler(); - - while(1) { - - }; -} void vTaskPlayerSetup(void *parameter) { while (1) { - if (plusButton.PressedDebounced()) + if (plusButton) { - game.AddPlayer(); + AddPlayer(); } - if (minusButton.PressedDebounced()) + if (minusButton) { - game.RemovePlayer(); + RemovePlayer(); } -#ifdef DEBUG - for (auto i = 0; i < game.maxPlayers; i++) - buffer[i] = game.playerScore[i]; - usart.Send(); -#endif // DEBUG - - - if (game.activePlayers > 1 && bigButton.PressedDebounced()) + if (game.activePlayers > 1 && bigButton) break; vTaskDelay(5); @@ -476,17 +457,17 @@ void vTaskPlayerSetup(void *parameter) void vTaskTimerSetup(void *parameter) { while (1) { - if (plusButton.PressedDebounced()) + if (plusButton) { - game.IncrementTurnTime(); + IncrementTurnTime(); } - else if (minusButton.PressedDebounced()) + else if (minusButton) { - game.DecrementTurnTime(); + DecrementTurnTime(); } else vTaskDelay(10); - if (bigButton.PressedDebounced()) { + if (bigButton) { break; } vTaskDelay(10); @@ -514,12 +495,12 @@ void vTaskTimerSetup(void *parameter) { void vTaskConfig(void *parameter) { while (1) { - if (plusButton.PressedDebounced()) + if (plusButton) game.countScores = !game.countScores; - if (minusButton.PressedDebounced()) + if (minusButton) // show round number or change the way it counts game.countScores = !game.countScores; - if (bigButton.PressedDebounced()) { + if (bigButton) { break; } vTaskDelay(10); @@ -537,15 +518,15 @@ void vTaskTurn(void *parameter) { while (1) { - if (plusButton.PressedDebounced()) { + if (plusButton) { xTaskCreate(vTaskTimerSetup, "TaskTimerSetup", configMINIMAL_STACK_SIZE, NULL, 1, NULL); break; } - else if (minusButton.PressedDebounced()) { + else if (minusButton) { xTaskCreate(vTaskConfig, "Config", configMINIMAL_STACK_SIZE, NULL, 1, NULL); break; } - else if (bigButton.PressedDebounced()) { + else if (bigButton) { xTaskCreate(vTaskTurnEnd, "TaskTurnEnd", configMINIMAL_STACK_SIZE, NULL, 1, NULL); break; } @@ -583,15 +564,15 @@ void vTaskTurnEnd(void *parameter) { if (game.countScores) { int32_t delta = 0; while (1) { - if (bigButton.PressedDebounced()) { + if (bigButton) { game.ChangeScore(delta); break; } - else if (plusButton.PressedDebounced()) + else if (plusButton) { delta++; } - else if (minusButton.PressedDebounced()) + else if (minusButton) { delta--; } diff --git a/Makefile b/Makefile index 8fc81e9..395fdae 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,11 @@ BUILD_DIR = build # C sources C_SOURCES = \ Middlewares/FreeRTOS/Src/tasks.c \ +Middlewares/FreeRTOS/Src/list.c \ +Middlewares/FreeRTOS/Src/port.c \ +Middlewares/FreeRTOS/Src/event_groups.c \ +Middlewares/FreeRTOS/Src/stream_buffer.c \ +Middlewares/FreeRTOS/Src/heap_4.c \ Middlewares/FreeRTOS/Src/croutine.c \ Middlewares/FreeRTOS/Src/queue.c \ Middlewares/FreeRTOS/Src/timers.c \ @@ -134,11 +139,11 @@ C_INCLUDES = \ -ICore/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ --IMiddlewares/FreeRTOS/Inc \ -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \ -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \ -IDrivers/CMSIS/Device/ST/STM32F1xx/Include \ -IDrivers/CMSIS/Include \ +-IMiddlewares/FreeRTOS/Inc \ -IDrivers/CMSIS/Include