Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Cant get context switching to function

Posted by Kyle on August 31, 2011
I am running freertos on a dspic33f and am having trouble to get context switching to function properly.
I have verified that the interrupt is happening and that the vTaskIncrementTick() function is being called.

I have created 2 different task as follows:

xTaskCreate( vIrrigationTask, ( signed char * ) "Irrigation", 100, NULL, tskIDLE_PRIORITY + 3, NULL );
xTaskCreate( vModuleEmulatorTask, ( signed char * ) "Module", 100, NULL, tskIDLE_PRIORITY + 2, NULL );

My problem is that which ever task has the highest priority always runs (wont give any time to the other task), or if I set both priorities to be the same (2 for example) then the vModuleEmulatorTask task will only run. I am unsure why this is occurring or what I can do to fix this problem.

If you need more information please ask, as I am completely lost and don't even know what might be useful information to post.



RE: Cant get context switching to function

Posted by Richard Damon on August 31, 2011
If you are sure the tic is running, one other possibility is that you haven't configured the system to be preemptive (in FreeRTOSconfig.h, #define configUSE_PREEMPTION 1)

RE: Cant get context switching to function

Posted by Kyle on August 31, 2011
Thanks for your reply. I do have configUSE_PREEMPTION set to 1.

I am pretty sure that the tick is running. When I place a breakpoint in the vTaskIncrementTick() function, the program gets halted, and it will keep getting re-halted every-time the function is called without the processor resetting.


Here is my current configuration settings:
#define configUSE_PREEMPTION1
#define configUSE_IDLE_HOOK0 // original value was 1
#define configUSE_TICK_HOOK0
#define configTICK_RATE_HZ( ( portTickType ) 1000 )
#define configCPU_CLOCK_HZ( ( unsigned long ) 16000000 ) /* Fosc / 2 */
#define configMAX_PRIORITIES( ( unsigned portBASE_TYPE ) 4 )
#define configMINIMAL_STACK_SIZE( 115 )
#define configTOTAL_HEAP_SIZE( ( size_t ) 5120 )
#define configMAX_TASK_NAME_LEN( 16 )
#define configUSE_TRACE_FACILITY0
#define configUSE_16_BIT_TICKS1
#define configIDLE_SHOULD_YIELD1

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 1
#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_vTaskPrioritySet1
#define INCLUDE_uxTaskPriorityGet0
#define INCLUDE_vTaskDelete0
#define INCLUDE_vTaskCleanUpResources0
#define INCLUDE_vTaskSuspend1
#define INCLUDE_vTaskDelayUntil1
#define INCLUDE_vTaskDelay1


#define configKERNEL_INTERRUPT_PRIORITY0x01


Any other ideas?

RE: Cant get context switching to function

Posted by Richard on August 31, 2011
Are you sure both tasks are created? Check the return value of xTaskCreate().

Do you have a malloc failed hook defined? That could also catch a task not being created.

In the case where one task has a higher priority than the other task, the higher priority task should always run as long as it is able to. For the lower priority task to run the higher priority task must be in the Blocked state (delaying, or blocking on a queue/semaphore, etc.), or Suspended state.

Regards.

RE: Cant get context switching to function

Posted by Kyle on September 2, 2011
I am creating both tasks with a priority of 2 now and am ensuring that they are created properly. The tasks are being created as follows:

if(xTaskCreate( vIrrigationTask, ( signed char * ) "Irrigation", 100, NULL, tskIDLE_PRIORITY + 2, NULL ) != pdPASS)
{
while(1){};
}
if(xTaskCreate( vModuleEmulatorTask, ( signed char * ) "Module", 100, NULL, tskIDLE_PRIORITY + 2, NULL ) != pdPASS)
{
while(1){};
}


Only the module task is running when they both have a priority of 2.

I created a malloc failed hook, and it is not being called. I also added a delay call to the module task to ensure that it is not blocking.

Here is the code (very simple) inside of my module task:

for( ;; )
{
LATGbits.LATG14 = 1; // red led
vTaskDelay( 100 / portTICK_RATE_MS );
}


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS