diff --git a/RTE/RTOS/FreeRTOSConfig.h b/RTE/RTOS/FreeRTOSConfig.h
index 1c67995..9c15fd7 100644
--- a/RTE/RTOS/FreeRTOSConfig.h
+++ b/RTE/RTOS/FreeRTOSConfig.h
@@ -76,7 +76,7 @@ extern uint32_t SystemCoreClock;
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_TRACE_FACILITY 1
-#define configUSE_TICKLESS_IDLE 1
+#define configUSE_TICKLESS_IDLE 0
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_NEWLIB_REENTRANT 0
#define configUSE_CO_ROUTINES 0
@@ -87,7 +87,7 @@ extern uint32_t SystemCoreClock;
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
/* Constants that define which hook (callback) functions should be used. */
-#define configUSE_IDLE_HOOK 0
+#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#define configUSE_MALLOC_FAILED_HOOK 1
diff --git a/Test_project_for_GD32107C-EVAL.uvoptx b/Test_project_for_GD32107C-EVAL.uvoptx
index 78f3dc8..77842dc 100644
--- a/Test_project_for_GD32107C-EVAL.uvoptx
+++ b/Test_project_for_GD32107C-EVAL.uvoptx
@@ -154,6 +154,13 @@
+
+
+ 0
+ 1
+ tickCounter
+
+
1
diff --git a/Test_project_for_GD32107C-EVAL.uvprojx b/Test_project_for_GD32107C-EVAL.uvprojx
index 70e9717..20269f1 100644
--- a/Test_project_for_GD32107C-EVAL.uvprojx
+++ b/Test_project_for_GD32107C-EVAL.uvprojx
@@ -334,7 +334,7 @@
5
1
1
- 1
+ 0
0
0
diff --git a/main.c b/main.c
index 58f28c6..7650b3f 100644
--- a/main.c
+++ b/main.c
@@ -4,9 +4,12 @@
#include "gd32f10x_gpio.h"
#include "stdio.h"
#define BUTTON_USER GPIO_PIN_14
+#define LED2_USER_PORT GPIOC
+#define LED5_TICK_PORT GPIOE
#define LED2_USER GPIO_PIN_0
#define LED5_TICK GPIO_PIN_1
-
+#define TASK_HELLO_WORLD_DELAY 500
+#define TASK_TOGGLE_LED_DELAY 125
void vTaskHelloWorld( void *pvParameters);
void vTaskToggleLed( void *pvParameters);
int stdout_putchar (int ch);
@@ -25,29 +28,29 @@ int stdin_getchar (void)
return usart_data_receive(EVAL_COM1);
}
-/*! \brief InitMCU
+/**! \brief vInitMCU
* Initial MCU configuration
*/
-static void InitMCU(void)
+static void vInitMCU(void)
{
SystemInit();
//gd_eval_led_init(LED2);
//gd_eval_led_on(LED2);
rcu_periph_clock_enable(RCU_GPIOC);
- gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED2_USER);
- gpio_bit_set(GPIOC, LED2_USER);
+ gpio_init(LED2_USER_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED2_USER);
+ gpio_bit_set(LED2_USER_PORT, LED2_USER);
rcu_periph_clock_enable(RCU_GPIOE);
- gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED5_TICK);
- gpio_bit_set(GPIOE, LED5_TICK);
+ gpio_init(LED5_TICK_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED5_TICK);
+ gpio_bit_set(LED5_TICK_PORT, LED5_TICK);
gd_eval_com_init(EVAL_COM1);
rcu_periph_clock_enable(RCU_GPIOB);
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ, BUTTON_USER);
}
-/*! \brief vTaskHelloWorld procedure
+/**! \brief vTaskHelloWorld procedure
*
* \param Not Used.
*/
@@ -60,11 +63,11 @@ void vTaskHelloWorld( void *pvParameters)
if (ButtonState)
{
printf("Hello world\n");
- vTaskDelay(500);
+ vTaskDelay(TASK_HELLO_WORLD_DELAY);
}
}
}
-/*! \brief vTaskToggleLed procedure
+/**! \brief vTaskToggleLed procedure
*
* \param Not Used.
*/
@@ -75,37 +78,33 @@ void vTaskToggleLed( void *pvParameters)
{
if (toggle)
{
- gpio_bit_reset(GPIOC, LED2_USER);
+ gpio_bit_reset(LED2_USER_PORT, LED2_USER);
}
else
{
- gpio_bit_set(GPIOC, LED2_USER);
+ gpio_bit_set(LED2_USER_PORT, LED2_USER);
}
toggle = !toggle;
- vTaskDelay(125);
+ vTaskDelay(TASK_TOGGLE_LED_DELAY);
}
}
int main(void)
{
- InitMCU();
+ vInitMCU();
xTaskCreate(vTaskToggleLed, "ToggleLed", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
xTaskCreate(vTaskHelloWorld, "HelloWorld", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
vTaskStartScheduler();
while(1);
}
-/**
- * task.h
- * @code{c}
- * void vApplicationMallocFailedHook( void )
- * @endcode
- *
- * This hook function is called when allocation failed.
+/**! \func void vApplicationMallocFailedHook( void )
+ * \brief This hook function is called when allocation failed.
*/
void vApplicationMallocFailedHook( void )
{
- #if defined (DEBUG)
+#if defined (DEBUG)
+ printf("Malloc Failed Hook\n");
__ASM("BKPT #0\n");
#endif
NVIC_SystemReset();
@@ -113,26 +112,49 @@ void vApplicationMallocFailedHook( void )
}
-/*! \func vApplicationTickHook( void )
+/**! \func vApplicationTickHook( void )
* \brief Toggles LED5_TICK to indicate RTOS running well
*/
void vApplicationTickHook( void )
{
- static uint16_t tickCounter = 0;
+ static uint16_t tickCounter = 0;
if(++tickCounter == configTICK_RATE_HZ)
{
- gpio_bit_reset(GPIOE, LED5_TICK);
+ gpio_bit_reset(LED5_TICK_PORT, LED5_TICK);
tickCounter = 0;
}
else if(tickCounter == configTICK_RATE_HZ/2)
{
- gpio_bit_set(GPIOE, LED5_TICK);
+ gpio_bit_set(LED5_TICK_PORT, LED5_TICK);
}
}
+/**! \func vApplicationIdleHook( void )
+ * \brief Idle task Hook
+ */
+void vApplicationIdleHook( void )
+{
+#if defined (DEBUG)
+ int32_t delta = (configTICK_RATE_HZ-(TASK_TOGGLE_LED_DELAY + TASK_HELLO_WORLD_DELAY)) % configTICK_RATE_HZ;
+ if (delta < 0) delta = -delta;
+
+ static uint32_t idleHookCounter = 0;
+ uint32_t currentTick = xTaskGetTickCount();
+ if(currentTick > idleHookCounter + delta)
+ {
+ printf("Idle Hook %d\n", idleHookCounter);//__ASM("BKPT #0\n");
+ }
+ idleHookCounter = currentTick;
+#endif
+}
+
+/**! \func vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
+ * \brief Stack overflow Hook
+ */
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
#if defined (DEBUG)
+ printf("Stack Overflow Hook\n");
__ASM("BKPT #0\n");
#endif
NVIC_SystemReset();
@@ -165,6 +187,7 @@ static volatile uint32_t psr;/* Program status register. */
pc = pulFaultStackAddress[ 6 ];
psr = pulFaultStackAddress[ 7 ];
#ifdef DEBUG
+ printf("Hard Fault Hook\n");
__asm volatile("BKPT #0\n") ;
#endif
NVIC_SystemReset();