Execution only in last created task

I am beginner in RTOS here i tried to execute four tasks simultaneously(with same priority). But the program execution is only in Task4 and never exit the loop.Using pic24fj256ga106 and FreeRTOS7.5.3 ,  I set break point in task4 as shown  below when execution reaches at break point the values are a=0,b=0,c=0,d=0 and xTickCount =0. if i run one time it again reach the break point and values would be a=0,b=0,c=0,d=1 and xTickCount =94, 2nd time a=0,b=0,c=0,d=2 and xTickCount =188 and so on , it never exit task4. Please help me what could be the reason how can i run all simultaneously. please.. unsigned int a=0,b=0,c=0,d=0;
int main( void )
{
        prvSetupHardware();
        xTaskCreate( vTask1, “Task 1”, 200, NULL, 1, NULL );
        
        xTaskCreate( vTask2, “Task 2”, 200, NULL, 1, NULL );         xTaskCreate( vTask3, “Task 2”, 200, NULL, 1, NULL );         xTaskCreate( vTask4, “Task 2”, 200, NULL, 1, NULL );
vTaskStartScheduler(); /* If all is well then main() will never reach here as the scheduler will
now be running the tasks. If main() does reach here then it is likely that
there was insufficient heap memory available for the idle task to be created.
CHAPTER 5 provides more information on memory management. */
for( ;; );
} void vTask1( void *pvParameters )
{
    volatile unsigned long ul;
for( ;; )
    {
     
            PORTF = 0x0004;
            a++;
    }    } void vTask2( void *pvParameters )
{
    volatile unsigned long ul;
for( ;; )
    {
     
            PORTF = 0x0008;
            b++;
    }    } void vTask3( void *pvParameters )
{
    volatile unsigned long ul;
for( ;; )
    {
     
            PORTF = 0x0008;
            c++;
    }    } void vTask4( void *pvParameters )
{
    volatile unsigned long ul;     for( ;; )
    {
            PORTF = 0x0008;    // set break point here
            d++;
            for( ul = 0; ul < 50000; ul++ )
            {
              ;
            }             PORTF = 0x0004;
             for( ul = 0; ul < 50000; ul++ )
     {
                ;
     }     }
}

Execution only in last created task

The fact that the tick count is increasing shows the tick interrupt is executing, and each task has the same priority, so I’m not sure why they are not time slicing.  From your code you would expect a, b and c to increment a lot faster than d as those tasks don’t contain the loop.  I just executed your exact code (unmodified) in the Windows simulator and the behaviour was as expected.  I don’t have the PIC24 hardware with me at the moment to try it on that. One thing comes to mind.  Do you have configUSE_PREEMPTION set to 1 in FreeRTOSConfig.h?  If it is set to 0 then a task switch will only happen if you call taskYIELD() in the implementation of the task. Regards.

Execution only in last created task

Thank you for reply. I am expecting the result like a=1,b=1,c=1,d=1 in a single cycle of process.     configUSE_PREEMPTION is 1  in FreeRTOSConfig.h.  I am doing in MPLABX  linux, and here some more things i observed   if i delete two delay  for() loop in task4 the  xTickCount  won’t increment it remains 0, d would increment by 1. If i put delay it would increment as i said before.  I executed code step by step first execution will enter void vTaskStartScheduler( void ) then xReturn = xTaskCreate( prvIdleTask, ( signed char * ) “IDLE”, tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL ); then if( xReturn == pdPASS )
{
/* Interrupts are turned off here, to ensure a tick does not occur
before or during the call to xPortStartScheduler().  The stacks of
the created tasks contain a status word with interrupts switched on
so interrupts will automatically get re-enabled when the first task
starts to run. STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE
DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */
portDISABLE_INTERRUPTS(); xSchedulerRunning = pdTRUE;
xTickCount = ( portTickType ) 0U; /* If configGENERATE_RUN_TIME_STATS is defined then the following
macro must be defined to configure the timer/counter used to generate
the run time counter time base. */
portCONFIGURE_TIMER_FOR_RUN_TIME_STATS(); /* Setting up the timer tick is hardware specific and thus in the
portable interface. */
if( xPortStartScheduler() != pdFALSE ) after this line enters directly to Task4. why this happening ?  if i delete Task4, Task 3 behaves like, if delete task3 Task 2 only work.  Execution is only in the Task which i created last. void vTaskStartScheduler( void )
{
portBASE_TYPE xReturn; /* Add the idle task at the lowest priority. */
#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
{
/* Create the idle task, storing its handle in xIdleTaskHandle so it can
be returned by the xTaskGetIdleTaskHandle() function. */
xReturn = xTaskCreate( prvIdleTask, ( signed char * ) “IDLE”, tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */
}
#else
{
/* Create the idle task without storing its handle. */
xReturn = xTaskCreate( prvIdleTask, ( signed char * ) “IDLE”, tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL );  /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */
}
#endif /* INCLUDE_xTaskGetIdleTaskHandle */ #if ( configUSE_TIMERS == 1 )
{
if( xReturn == pdPASS )
{
xReturn = xTimerCreateTimerTask();
}
}
#endif /* configUSE_TIMERS */ if( xReturn == pdPASS )
{
/* Interrupts are turned off here, to ensure a tick does not occur
before or during the call to xPortStartScheduler().  The stacks of
the created tasks contain a status word with interrupts switched on
so interrupts will automatically get re-enabled when the first task
starts to run. STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE
DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */
portDISABLE_INTERRUPTS(); xSchedulerRunning = pdTRUE;
xTickCount = ( portTickType ) 0U; /* If configGENERATE_RUN_TIME_STATS is defined then the following
macro must be defined to configure the timer/counter used to generate
the run time counter time base. */
portCONFIGURE_TIMER_FOR_RUN_TIME_STATS(); /* Setting up the timer tick is hardware specific and thus in the
portable interface. */
if( xPortStartScheduler() != pdFALSE )
{
/* Should not reach here as if the scheduler is running the
function will not return. */
                    Nop();
}
else
{
Nop();/* Should only reach here if a task calls xTaskEndScheduler(). */
}
}
else
{
/* This line will only be reached if the kernel could not be started,
because there was not enough FreeRTOS heap to create the idle task
or the timer task. */
configASSERT( xReturn );
}
}

Execution only in last created task

I have just tried: 1) Taking the PIC24 MPLAB X project in the FreeRTOS download.
2) Replaced main() in the project with your main().
3) Added in your four task definitions, and the a, b, c and d variables (cut and paste from your post).
4) Changed the project to use the simulator instead of the real hardware.
5) Built and executed the project. All the variables are being incremented – a, b and c are incremented very quickly, d is incremented much more slowly, as expected. Regards.

Execution only in last created task

Ho!!. .. Let me know what simulator you are using? Here what could be the cause of error , can you  guess or any suggestion please?? i tried every known possibilities.  :-(.  I tried with taskYIELD(),  vTaskDelete( NULL ), vTaskDelay( 2) etc.. No change.

Execution only in last created task

Let me know what simulator you are using?
The one in MPLAB X.
what could be the cause of error
I really don’t know.  As I said, the tick interrupt is evidently running so it should not be a problem.  You might want to double check that the tick interrupt really is running by placing a break point in configTICK_INTERRUPT_HANDLER(), which is in FreeRTOS/Source/portable/MPLAB/PIC24_dsPIC/port.c.  You can also step through the function, which should call portYIELD(), which is itself a function you can step through. Regards.

Execution only in last created task

xTickCount is not incrementing (when watch xTickCount  in debugging mode) if i delete delay loops for( ul = 0; ul < 50000; ul++ ) { ; }  in Task4 . If the error is in tick interrup how can i fix it.  in

Execution only in last created task

Are you using the default tick interrupt handler provided in port.c, or providing your own?
Are you using the same chip as used in the demo, or have you retargeted the demo to a different chip? Most likely the source of the issue will be in the configuration bits, especially if you have changed the target chip in the project options.  Take a look using the Windows->PIC Memory Views->Configuration Bits menu option in MPLAB X. Regards.

Execution only in last created task

I didnt  make any change in the downloaded code FreeRTOS7.5.3  only added four tasks in the main.  I am using pic24fj256GA106, and configuaration settings /******************************************************************************
* Configuration bits for  processor   *
******************************************************************************/ // PIC24FJ256GA106 Configuration Bit Settings #include <xc.h> // CONFIG3
#pragma config WPFP = WPFP5             // Write Protection Flash Page Segment Boundary (Page 5 (0x1400))
#pragma config WPDIS = WPDIS            // Segment Write Protection Disable bit (Segmented code protection disabled)
#pragma config WPCFG = WPCFGDIS         // Configuration Word Code Page Protection Select bit (Last page(at the top of program memory) and Flash configuration words are not protected)
#pragma config WPEND = WPSTARTMEM       // Segment Write Protection End Page Select bit (Write Protect from page 0 to WPFP) // CONFIG2
#pragma config POSCMOD = NONE           // Primary Oscillator Select (Primary oscillator disabled)
#pragma config IOL1WAY = ON             // IOLOCK One-Way Set Enable bit (Write RP Registers Once)
#pragma config OSCIOFNC = OFF           // Primary Oscillator Output Function (OSCO functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor (Both Clock Switching and Fail-safe Clock Monitor are disabled)
#pragma config FNOSC = FRC              // Oscillator Select (Fast RC Oscillator (FRC))
#pragma config IESO = ON                // Internal External Switch Over Mode (IESO mode (Two-speed start-up) enabled) // CONFIG1
#pragma config WDTPS = PS32768          // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = OFF             // Watchdog Timer Window (Standard Watchdog Timer is enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx2               // Comm Channel Select (Emulator functions are shared with PGEC2/PGED2)
#pragma config GWRP = OFF               // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF                // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG port is disabled)

Execution only in last created task

Are these bits generated by the settings in the IDE? I can see a few differences in the settings you posted compared to the settings in the IDE window opened using the menu item I mentioned above – for CONFIG1 anyway.  I can’t see any settings for CONFIG2. Regards.

Execution only in last created task

Yes, iam using MPLAB X IDE v1.80, with XC16 compiler. will you please post the setting which you have? it may another version of  MPLAB .

Execution only in last created task

It is not easy to post an image here, but if you take a clean FreeRTOS distribution, open the project, and then view the configuration bits window you will see what they are set to.  This is all assuming the project is somehow configured to use the bits that are defined by the settings in that window. Regards.

Execution only in last created task

i coudnt find anything wrong in configuration bits, let me ask you something here i checked Task1 void vTask1( void *pvParameters )
{
     volatile unsigned long ul;
     
    for( ;; )
    {
   
         PORTF = 0x0004;     //set break point here
         a++;
            for( ul = 0; ul < 1000; ul++ )
           { /* This loop is just a very crude delay implementation. There is
nothing to do in here. Later examples will replace this crude
loop with a proper delay/sleep function. */
}
            } } when i execute one time in the Task1 loop a =1, XTickCount=1, 2nt time a =2, XTickCount=2 and so on.  If i replace  for( ul = 0; ul < 1000; ul++ ) {}  with    vTaskDelay(200);   XTick Count starts counting when a=63, XTick Count  would be 2 in next 63. i tried with  vTaskDelay(20000); ,vTaskDelay(200000);  ,vTaskDelay(2); but no change in this relation XTick Count starts counting only when a=63,.  when it switch to another task(  XTickCount  value?) ///////////FreeRTOSConfig///////// #ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H #include <p24FJ256GA106.h> /*—————————————
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE ‘CONFIGURATION’ SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*—————————————*/ #define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configTICK_RATE_HZ ( ( portTickType ) 10000 )
#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 ( 4 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1 /* 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_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1 #define configKERNEL_INTERRUPT_PRIORITY 0x01 #endif /* FREERTOS_CONFIG_H */

Execution only in last created task

You have configTICK_RATE_HZ set to 10KHz, which is extremely fast, probably to fast by a factor of about 100 at least.  I suspect most of your CPU time will be spend servicing interrupts.  Try setting it to 100. You also have configUSE_16_BIT_TICKS, which means the maximum number of ticks you can block for is 0xffff.  With a tick frequency of 10KHz the tick count will overflow every 6 seconds (which doesn’t matter to FreeRTOS). When you replace the loop with vTaskDelay(200); I would expect there to be a minimum of 200 ticks between each increment of a, and I would not expect a to increment more than once before the tick count reached 200 minimum.  If I were to set up a test here again I’m sure that is what I would find as when I replicated your tests yesterday I found everything function as expected, and I could not replicate your results.  Sorry – I don’t know what is wrong with your project, but obviously something quite fundamental.  Maybe it is related to the extremely fast tick you have configured. Maybe as an aside, if you have configTICK_RATE_HZ set above 1000 then you cannot use the portTICK_RATE_MS constant. Regards.

Execution only in last created task

Thank you so much for all your support and valuable time. Its working now, actually i got FreeRTOS code (which i worked so far)  from my friend not downloaded from here, I have downloaded new and checked, everything is fine. Thanks again for all your help!  :-)