I using Keil compiler and the port RVDS from GitHub for my project on LPC2368. FreeRTOS works well as long as it doesn’t use critical section.
If I use this block
vTaskSuspendAll ();
....
xTaskResumeAll ();
everything is ok, but if I type acording documentation:
vTaskSuspendAll ();
....
if (!xTaskResumeAll ()) taskYIELD ();
programm will stoped somewere in taskYIELD
Someone know why it should be happened?
Other question: when program spends too much time in critical section, then program stopped somewhere in ‘xTaskResumeAll’, I think, that it the same error, in xTaskResumeAll FreeRTOS runs taskYIELD.
How can I spend as much time as it takes in critical section? But I think, than answer on first question must decide this problem too.
My FreeRTOSConfig.h:
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 72000000 ) /* =12.0MHz xtal multiplied by 4 using the PLL. */
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 2 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 90 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) 6 * 1024 )//( ( size_t ) 13 * 1024 )
#define configMAX_TASK_NAME_LEN ( 8 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configQUEUE_REGISTRY_SIZE 0
//#define configSUPPORT_STATIC_ALLOCATION 1
//#define configSUPPORT_DYNAMIC_ALLOCATION 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
// HOOKs
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MALLOC_FAILED_HOOK 1
Example code:
void testTask (void *p);
void testTask3 (void *p);
int main (void) {
Init ();
dbgmsg ("start FreeRTOS\n");
BaseType_t ret;
ret = xTaskCreate(testTask, (signed char *)"testTask", configMINIMAL_STACK_SIZE, 0, 0, 0);
if (ret != pdPASS) {
errmsg ("xTaskCreate: COULD_NOT_ALLOCATE_REQUIRED_MEMORY");
goto rtosError;
}
ret = xTaskCreate(testTask3, (signed char *)"testTask3", configMINIMAL_STACK_SIZE, 0, 0, 0);
if (ret != pdPASS) {
errmsg ("xTaskCreate: COULD_NOT_ALLOCATE_REQUIRED_MEMORY");
goto rtosError;
}
vTaskStartScheduler();
rtosError:
while (9)
{
RED_LED_ON;
GREEN_LED_OFF;
Delay (1000, 0);
RED_LED_OFF;
GREEN_LED_ON;
Delay (1000, 0);
}
return 0;
}
// HOOKs
void
vApplicationStackOverflowHook( TaskHandle_t xTask, char * pcTaskName ) {
//taskENTER_CRITICAL();
//vTaskSuspendAll ();
while (true)
{
dbgmsg ("vApplicationStackOverflowHook at '%s'\n", pcTaskName);
}
//xTaskResumeAll();
//taskEXIT_CRITICAL();
}
void
vApplicationMallocFailedHook() {
//vTaskSuspendAll ();
while (true)
{
dbgmsg ("vApplicationMallocFailedHook\n");
}
//if (!xTaskResumeAll ()) taskYIELD ();
}
#include "Defports.h"
extern void rtosSleep(uint32_t ms);
extern volatile bool mainTaskIinitialized ();
void
testTask3 (void *p) {
Delay (500, 0);
while (9)
{
dbgmsg ("3");
vTaskSuspendAll ();
RED_LED_ON;
GREEN_LED_OFF;
xTaskResumeAll ();
//if (!xTaskResumeAll ()) taskYIELD ();
Delay (1000, 0);
//rtosSleep (1000);
}
}
void testTask (void *p) {
while (1) {
dbgmsg ("1");
vTaskSuspendAll ();
RED_LED_OFF;
GREEN_LED_ON;
//xTaskResumeAll ();
if (!xTaskResumeAll ()) taskYIELD ();
Delay (1000, 0);
}
}