#define configUSE_TICKLESS_IDLE 0

This commit is contained in:
Alexei 2023-01-23 01:05:20 +07:00
parent 35635fe2ea
commit 9ddbad2373
4 changed files with 59 additions and 29 deletions

View File

@ -76,7 +76,7 @@ extern uint32_t SystemCoreClock;
#define configUSE_QUEUE_SETS 1 #define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1 #define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_TRACE_FACILITY 1 #define configUSE_TRACE_FACILITY 1
#define configUSE_TICKLESS_IDLE 1 #define configUSE_TICKLESS_IDLE 0
#define configUSE_APPLICATION_TASK_TAG 0 #define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_NEWLIB_REENTRANT 0 #define configUSE_NEWLIB_REENTRANT 0
#define configUSE_CO_ROUTINES 0 #define configUSE_CO_ROUTINES 0
@ -87,7 +87,7 @@ extern uint32_t SystemCoreClock;
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
/* Constants that define which hook (callback) functions should be used. */ /* 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_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 #define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#define configUSE_MALLOC_FAILED_HOOK 1 #define configUSE_MALLOC_FAILED_HOOK 1

View File

@ -154,6 +154,13 @@
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>tickCounter</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1> <MemoryWindow1>
<Mm> <Mm>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>

View File

@ -334,7 +334,7 @@
<v6LangP>5</v6LangP> <v6LangP>5</v6LangP>
<vShortEn>1</vShortEn> <vShortEn>1</vShortEn>
<vShortWch>1</vShortWch> <vShortWch>1</vShortWch>
<v6Lto>1</v6Lto> <v6Lto>0</v6Lto>
<v6WtE>0</v6WtE> <v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti> <v6Rtti>0</v6Rtti>
<VariousControls> <VariousControls>

75
main.c
View File

@ -4,9 +4,12 @@
#include "gd32f10x_gpio.h" #include "gd32f10x_gpio.h"
#include "stdio.h" #include "stdio.h"
#define BUTTON_USER GPIO_PIN_14 #define BUTTON_USER GPIO_PIN_14
#define LED2_USER_PORT GPIOC
#define LED5_TICK_PORT GPIOE
#define LED2_USER GPIO_PIN_0 #define LED2_USER GPIO_PIN_0
#define LED5_TICK GPIO_PIN_1 #define LED5_TICK GPIO_PIN_1
#define TASK_HELLO_WORLD_DELAY 500
#define TASK_TOGGLE_LED_DELAY 125
void vTaskHelloWorld( void *pvParameters); void vTaskHelloWorld( void *pvParameters);
void vTaskToggleLed( void *pvParameters); void vTaskToggleLed( void *pvParameters);
int stdout_putchar (int ch); int stdout_putchar (int ch);
@ -25,29 +28,29 @@ int stdin_getchar (void)
return usart_data_receive(EVAL_COM1); return usart_data_receive(EVAL_COM1);
} }
/*! \brief InitMCU /**! \brief vInitMCU
* Initial MCU configuration * Initial MCU configuration
*/ */
static void InitMCU(void) static void vInitMCU(void)
{ {
SystemInit(); SystemInit();
//gd_eval_led_init(LED2); //gd_eval_led_init(LED2);
//gd_eval_led_on(LED2); //gd_eval_led_on(LED2);
rcu_periph_clock_enable(RCU_GPIOC); rcu_periph_clock_enable(RCU_GPIOC);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED2_USER); gpio_init(LED2_USER_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED2_USER);
gpio_bit_set(GPIOC, LED2_USER); gpio_bit_set(LED2_USER_PORT, LED2_USER);
rcu_periph_clock_enable(RCU_GPIOE); rcu_periph_clock_enable(RCU_GPIOE);
gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED5_TICK); gpio_init(LED5_TICK_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_2MHZ, LED5_TICK);
gpio_bit_set(GPIOE, LED5_TICK); gpio_bit_set(LED5_TICK_PORT, LED5_TICK);
gd_eval_com_init(EVAL_COM1); gd_eval_com_init(EVAL_COM1);
rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOB);
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ, BUTTON_USER); gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_2MHZ, BUTTON_USER);
} }
/*! \brief vTaskHelloWorld procedure /**! \brief vTaskHelloWorld procedure
* *
* \param Not Used. * \param Not Used.
*/ */
@ -60,11 +63,11 @@ void vTaskHelloWorld( void *pvParameters)
if (ButtonState) if (ButtonState)
{ {
printf("Hello world\n"); printf("Hello world\n");
vTaskDelay(500); vTaskDelay(TASK_HELLO_WORLD_DELAY);
} }
} }
} }
/*! \brief vTaskToggleLed procedure /**! \brief vTaskToggleLed procedure
* *
* \param Not Used. * \param Not Used.
*/ */
@ -75,37 +78,33 @@ void vTaskToggleLed( void *pvParameters)
{ {
if (toggle) if (toggle)
{ {
gpio_bit_reset(GPIOC, LED2_USER); gpio_bit_reset(LED2_USER_PORT, LED2_USER);
} }
else else
{ {
gpio_bit_set(GPIOC, LED2_USER); gpio_bit_set(LED2_USER_PORT, LED2_USER);
} }
toggle = !toggle; toggle = !toggle;
vTaskDelay(125); vTaskDelay(TASK_TOGGLE_LED_DELAY);
} }
} }
int main(void) int main(void)
{ {
InitMCU(); vInitMCU();
xTaskCreate(vTaskToggleLed, "ToggleLed", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL); xTaskCreate(vTaskToggleLed, "ToggleLed", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
xTaskCreate(vTaskHelloWorld, "HelloWorld", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL); xTaskCreate(vTaskHelloWorld, "HelloWorld", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
vTaskStartScheduler(); vTaskStartScheduler();
while(1); while(1);
} }
/** /**! \func void vApplicationMallocFailedHook( void )
* task.h * \brief This hook function is called when allocation failed.
* @code{c}
* void vApplicationMallocFailedHook( void )
* @endcode
*
* This hook function is called when allocation failed.
*/ */
void vApplicationMallocFailedHook( void ) void vApplicationMallocFailedHook( void )
{ {
#if defined (DEBUG) #if defined (DEBUG)
printf("Malloc Failed Hook\n");
__ASM("BKPT #0\n"); __ASM("BKPT #0\n");
#endif #endif
NVIC_SystemReset(); NVIC_SystemReset();
@ -113,26 +112,49 @@ void vApplicationMallocFailedHook( void )
} }
/*! \func vApplicationTickHook( void ) /**! \func vApplicationTickHook( void )
* \brief Toggles LED5_TICK to indicate RTOS running well * \brief Toggles LED5_TICK to indicate RTOS running well
*/ */
void vApplicationTickHook( void ) void vApplicationTickHook( void )
{ {
static uint16_t tickCounter = 0; static uint16_t tickCounter = 0;
if(++tickCounter == configTICK_RATE_HZ) if(++tickCounter == configTICK_RATE_HZ)
{ {
gpio_bit_reset(GPIOE, LED5_TICK); gpio_bit_reset(LED5_TICK_PORT, LED5_TICK);
tickCounter = 0; tickCounter = 0;
} }
else if(tickCounter == configTICK_RATE_HZ/2) 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 ) void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{ {
#if defined (DEBUG) #if defined (DEBUG)
printf("Stack Overflow Hook\n");
__ASM("BKPT #0\n"); __ASM("BKPT #0\n");
#endif #endif
NVIC_SystemReset(); NVIC_SystemReset();
@ -165,6 +187,7 @@ static volatile uint32_t psr;/* Program status register. */
pc = pulFaultStackAddress[ 6 ]; pc = pulFaultStackAddress[ 6 ];
psr = pulFaultStackAddress[ 7 ]; psr = pulFaultStackAddress[ 7 ];
#ifdef DEBUG #ifdef DEBUG
printf("Hard Fault Hook\n");
__asm volatile("BKPT #0\n") ; __asm volatile("BKPT #0\n") ;
#endif #endif
NVIC_SystemReset(); NVIC_SystemReset();