PIC33: Problem with taskschedule

hi everyone, this is my first time working with FreeRTOS and i hope u guys could help me. First: I´m using MPLABv8.30 and the C30v3.12 compiler. I´m working with the dsPIC33FJ256GP710 uC and the Microchip PICkit2 Programmer. I´m using the FreeRTOS demo project (.FreeRTOSV8.1.2FreeRTOSDemodsPIC_MPLAB). Problem: I was just playing with tasks but the tasks arent context switching – Programm remains in the first created task. Configuration:
//default values of the demo project
#define configUSE_PREEMPTION            1
#define configUSE_TIME_SLICING          1 
#define configUSE_IDLE_HOOK         1
#define configUSE_TICK_HOOK         0
#define configTICK_RATE_HZ          ( ( TickType_t ) 1000 )
#define configCPU_CLOCK_HZ          ( ( unsigned long ) 25000000 )  /* Fosc / 2 */
#define configMAX_PRIORITIES        ( 4 )
#define configMINIMAL_STACK_SIZE        ( 105 )
#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
main:
//both tasks with same priority
xTaskCreate(first_task,"f", 1024, NULL, 1, NULL);
xTaskCreate(secound_task,"s", 1024, NULL, 1, NULL);
vTaskStartScheduler();
tasks:
void first_task(void *p){
    while(1){
        function_one();
    }
}



void secound_task(void *p){
    while(1){
        function_two();
    }
}
tick Interrupt:
void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void )
{
    /* Clear the timer interrupt. */
    IFS0bits.T1IF = 0;

    if( xTaskIncrementTick() != pdFALSE )
    {
        portYIELD();
    }
}
The tick-Interrupt occurs but the function “xTaskIncrementTick()” returns always pdFALSE – I never reach “portYIELD()”. I really dont know why this is happening but I hope someone out there knows whats wrong.

PIC33: Problem with taskschedule

Is the tick interrupt executing? Try putting a break point in it, or viewing the tick count (xTickCount) in the debugger. If you add taskYIELD() calls into the tasks, do they switch between each other then? void firsttask(void *p){ while(1){ functionone(); taskYIELD(); } } I’m assuming functionone() and functiontwo() are not doing anything that may cause a problem?

PIC33: Problem with taskschedule

Hello,
  • I tried to use the taskYIELD() but it didnt worked.
  • functionone() and functiontwo() are putting some strings on the LCD-Display. The display shows the text from functionone(). If I put a break point in functiontwo() the debugger doesnt reach it. If I create the secondtask before the firsttask then the text from functiontwo() is shown on the display – functionone() doesnt execute.
  • tick interrupt is executing. Tomorrow I will view the tick count (xTickCount).
  • I should add that I removed most of the demo tasks because I thought that I wont need them. I havent touched the header files but I removed the following source files:
ParTest.c, timertest.c, BlockQ.c, blocktim.c, comtest.c, crflash.c and integer.c My whole main-function: LCD, LED and the buttons are working perfectly fine.
int main(void) {
    // Init
    config_osc();
    Init_LCD();
    Init_LED();
    Init_Buttons();
    Init_ADC();

    xTaskCreate(first_task,"f", 1024, NULL, 1, NULL);
    xTaskCreate(secound_task,"s", 1024, NULL, 1, NULL);
    vTaskStartScheduler();

return 0;
}

PIC33: Problem with taskschedule

I tried to use the taskYIELD() but it didnt worked.
So neither the tick interrupt or a yield is causing a task switch. Are you sure both tasks were created? Did you check the return value of xTaskCreate(), as your stack sizes are very big and it might just be that only one task is ever created.
function_one() and function_two() are putting some strings on the
LCD-Display. The display shows the text from function_one(). If I
put a break point in function_two() the debugger doesnt reach it.
If I create the second_task before the first_task then the text from
function_two() is shown on the display - function_one() doesnt execute.
Try replacing the call to functionone and functiontwo with a simple variable increment. For example, define the two variables: volatile uint32_t ul1 = 0, ul2 = 0; Then replace the call to functionone() with ul1++, and replace the call to functiontwo() with ul2++. Leave the call to taskYIELD() in there too. You should be able to simple step through the taskYIELD() code then to see what happens.
I should add that I removed most of the demo tasks because I thought
that I wont need them. I havent touched the header files but I
removed the following source files:
Probably best to also set configUSEIDLEHOOK to 0 as well as that demo schedules co-routines in the idle hook. Regards.

PIC33: Problem with taskschedule

I use dsPIC33F processor with FreeRTOS and they work very well.. 1) I would suggest that you start with the supported demo… if your using an explorer 16 board, it will just run if your using your own hardware, make change for the LED and serial port in the standard demo… The standard demo is a good test to make sure your hardware is stable.. 2) If you can, move up to MPLABX and the XC compiler… and FreeRTOS 8.xx as a starting base 3) add the FreeRTOS callback functions to see if your having a stack or memory issue… ( you will also need to enable them in FreeRTOSConfig.h) 4) what FreeRTOS heap are you using heap_1.c, 2, 3 or 4?? 5) change your FreeRTOS task size to a bigger value by 2X or 3X /* *********** FreeRTOS callback functions *********** */ /*
* * vApplicationIdleHook * *
*/ void vApplicationIdleHook( void ) { /* Schedule the co-routines from within the idle task hook. */ } /*
* * vApplicationTickHook * *
*/ void vApplicationTickHook( void ) { /* This function will be called by each tick interrupt if configUSETICKHOOK is set to 1 in FreeRTOSConfig.h. User code can be added here, but the tick hook is called from an interrupt context, so code must not attempt to block, and only the interrupt safe FreeRTOS API functions can be used (those that end in FromISR()). */ } /*
* * vApplicationStackOverflowHook * *
*/ void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ) { taskDISABLE_INTERRUPTS();
while(1) ;             // we will hang here if we have stack overflow
} /*
* * vApplicationMallocFailedHook * *
*/ void vApplicationMallocFailedHook( void ) { /* vApplicationMallocFailedHook() will only be called if configUSEMALLOCFAILEDHOOK is set to 1 in FreeRTOSConfig.h. It is a hook function that will get called if a call to pvPortMalloc() fails. pvPortMalloc() is called internally by the kernel whenever a task, queue, timer or semaphore is created. It is also called by various parts of the demo application. If heap1.c or heap2.c are used, then the size of the heap available to pvPortMalloc() is defined by configTOTALHEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used to query the size of free heap space that remains (although it does not provide information on how the remaining heap might be fragmented). */
taskDISABLE_INTERRUPTS();


while(1) ;                     // we will hang here if we have stack
overflow } On Mon, Jan 19, 2015 at 10:00 AM, Patrick patricknew@users.sf.net wrote:
hi everyone, this is my first time working with FreeRTOS and i hope u guys could help me. First: I´m using MPLABv8.30 and the C30v3.12 compiler. I´m working with the dsPIC33FJ256GP710 uC and the Microchip PICkit2 Programmer. I´m using the FreeRTOS demo project (.FreeRTOSV8.1.2FreeRTOSDemodsPIC_MPLAB). Problem: I was just playing with tasks but the tasks arent context switching – Programm remains in the first created task. Configuration: //default values of the demo project#define configUSEPREEMPTION 1#define configUSETIMESLICING 1 #define configUSEIDLEHOOK 1#define configUSETICKHOOK 0#define configTICKRATEHZ ( ( TickTypet ) 1000 )#define configCPUCLOCKHZ ( ( unsigned long ) 25000000 ) /* Fosc / 2 */#define configMAX_PRIORITIES ( 4 )#define configMINIMAL_STACK_SIZE ( 105 )#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 main: //both tasks with same priorityxTaskCreate(firsttask,”f”, 1024, NULL, 1, NULL);xTaskCreate(secoundtask,”s”, 1024, NULL, 1, NULL);vTaskStartScheduler(); tasks: void firsttask(void *p){ while(1){ functionone(); }} void secoundtask(void *p){ while(1){ functiontwo(); }} tick Interrupt: void attribute((interrupt, autopsv)) configTICKINTERRUPT_HANDLER( void ){ /* Clear the timer interrupt. */ IFS0bits.T1IF = 0;
if( xTaskIncrementTick() != pdFALSE )
{
    portYIELD();
}}
The tick-Interrupt occurs but the function “xTaskIncrementTick()” returns always pdFALSE – I never reach “portYIELD()”. I really dont know why this is happening but I hope someone out there

knows whats wrong.

PIC33: Problem with taskschedule

https://sourceforge.net/p/freertos/discussion/382005/thread/4ff5d22b/?limit=25#6e48

Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/ To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
— ~~ _/) ~~~~ _/) ~~~~ _/) ~~~~ _/) ~~ Tom Lafleur

PIC33: Problem with taskschedule

Hi, after I did some stack and memory managment everything is wokring fine. Thanks for helping!