Quality RTOS & Embedded Software

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




Loading

PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Pistole Gun on March 28, 2011
Hallo Everyone,

I am new in FreeRTOS (version 5.1.0). I used PIC32 starter kit (PIC32MX360F512L)
C32 Compiler v 1.05. I compile it directly using JTAG in PIC32 Starter kit.

On my first, I made 2 simple tasks to turn on 2 LEDs with different vTaskDelay. and it works.
then I try to utilize vApplicationIdleHook.. but until now my program never go to this function.

I have made
#define configUSE_IDLE_HOOK1

I also have declared this in my main function
void vApplicationTickHook( void );

my function is just simple which only turn on the third LED when it is in idle
void vApplicationTickHook( void )
{
for( ;; )
{
mPORTDSetBits(BIT_0);
}
}

I also have looked on RTOS viewer in MPLAB IDE v8.60, that Idle Task is running
However, The program never go to vApplicationIdleHook function ( I used breakdown point there)
I am really confused.

Any help figuring this out will be appreciated.
Thanks in advance guys :)

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by woops_ on March 28, 2011
Do you want an idle hook or a tick hook? You set configUSE_IDLE_HOOK 1, but define a tick hook function. Idle hook functions are called vApplicationIdleHook()

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Pistole Gun on March 28, 2011
Hallo woops_

Thanks for your reply.
Sorry I make mistake during write in this forum.
Actually, on my program I use idle hook.
void vApplicationIdleHook( void );

void vApplicationIdleHook( void )
{
for( ;; )
{
mPORTDSetBits(BIT_0);
}
}

Yes I have set configUSE_IDLE_HOOK 1
and it never goes to the void vApplicationIdleHook( void ) function

Do you have any idea?

thanks woops_

Best regards

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Richard on March 28, 2011
Can you show the structure of your LED tasks please?

Also, how do you know it is not entering the idle hook function? I presume because you have put a break point in the function?

Try removing the for( ;; ) loop in the idle hook function so the hook function is continuously entered and exited. That would make it easier to see if the break point is hit, especially if optimisation is on.

Regards.

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Pistole Gun on March 28, 2011
Thanks for your reply.

Here is the program to set up hardware

static void prvSetupHardware( void );

static void prvSetupHardware( void )
{
//Used for Initialization of IO pins
mPORTDClearBits(BIT_0);
mPORTDSetPinsDigitalOut(BIT_0);
mPORTDClearBits(BIT_1);
mPORTDSetPinsDigitalOut(BIT_1);
mPORTDClearBits(BIT_2);
mPORTDSetPinsDigitalOut(BIT_2);
/* Set the system and peripheral bus speeds and enable the program cache*/
SYSTEMConfigPerformance( configCPU_CLOCK_HZ - 1 );
mOSCSetPBDIV( OSC_PB_DIV_2 );

/* Setup to use the external interrupt controller. */
INTEnableSystemMultiVectoredInt();

portDISABLE_INTERRUPTS();
}

Here are the Tasks

xTaskCreate( prvTestTask1, "Blink RD0", configMINIMAL_STACK_SIZE, NULL, 2, NULL );
xTaskCreate( prvTestTask2, "Blink RD1", configMINIMAL_STACK_SIZE, NULL, 2, NULL );

static void prvTestTask1( void *pvParameters )
{
for( ;; )
{
mPORTDToggleBits(BIT_2);
vTaskDelay( smallDelay );
}
}

static void prvTestTask2( void *pvParameters )
{
for( ;; )
{
mPORTDToggleBits(BIT_1);
vTaskDelay( mediumDelay );

}
}

void vApplicationIdleHook( void )
{
mPORTDSetBits(BIT_0);
}

The connection pin to LED is simple. just pin into anode of LED and resistor 330 Ohm then ground.

Yes, I used Breakpoint to know whether it is executed vApplicationIdleHook.

I also have tried to remove for loop in vApplicationIdleHook, but it is still not working.
It never goes to the fuction.

Thank you very much for your kindness richardbarry. :)

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Richard on March 28, 2011
Well it looks ok, so its a matter of ascertaining why its not working.

Is it possible that smallDelay and/or mediumDelay could be zero? If so then the idle task would not run. Are the LEDs visibly toggling at the rate you expect?

The other thing to do would be to place a break point in the idle task directly. To do that, open up FreeRTOS/source/tasks.c, and search for "static portTASK_FUNCTION( prvIdleTask, pvParameters )" to find the idle task definition. Put a break point on the call to prvCheckTasksWaitingTermination(); at the top of the idle talk loop. When you run the code, is it ever hit? If so then the idle task is getting some CPU time and you can step through it in the debugger to see why the idle hook is not called. In fact, in the same function, at the bottom of the idle task loop, you can see the call to vApplicationIdleHook() - if you cannot put a break point on that line (with zero optimisation) then it is not getting built in.

Regards.

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Pistole Gun on March 28, 2011
Thanks Mr. Richardbarry.

No the delay is not zero, and the LEDs toggling rate is ok.
smallDelay = 2000 ms
mediumDelay = 12000ms.

I have tried it.
it can hit to prvCheckTasksWaitingTermination();

and then I run the debug using Step into, but it never go to vApplicationIdleHook()
It only go to if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( unsigned portBASE_TYPE ) 1 )
then go back again to prvCheckTasksWaitingTermination();

I also cannot put breakpoint to vApplicationIdleHook()

Do you know why it is happened ?
Why is it not getting built in ?

Thank you very much for your kindness. :)

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Richard on March 28, 2011
It sounds like it is not seeing the definition of configUSE_IDLE_HOOK.

Where have you defined configUSE_IDLE_HOOK? It must be in FreeRTOSConfig.h.

Can you check the spelling of configUSE_IDLE_HOOK to make sure it is correct?

Regards.

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Pistole Gun on March 28, 2011
#define configUSE_IDLE_HOOK1
It is in FreeRTOSConfig.h

the spelling is also correct.

static portTASK_FUNCTION( prvIdleTask, pvParameters )
{
/* Stop warnings. */
( void ) pvParameters;

for( ;; )
{
/* See if any tasks have been deleted. */
prvCheckTasksWaitingTermination();

#if ( configUSE_PREEMPTION == 0 )
{
/* If we are not using preemption we keep forcing a task switch to
see if any other task has become available. If we are using
preemption we don't need to do this as any task becoming available
will automatically get the processor anyway. */
taskYIELD();
}
#endif

#if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) )
{
/* When using preemption tasks of equal priority will be
timesliced. If a task that is sharing the idle priority is ready
to run then the idle task should yield before the end of the
timeslice.

A critical region is not required here as we are just reading from
the list, and an occasional incorrect value will not matter. If
the ready list at the idle priority contains more than one task
then a task other than the idle task is ready to execute.
*/
if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( unsigned portBASE_TYPE ) 1 )
{
taskYIELD();
}
}
#endif

#if ( configUSE_IDLE_HOOK == 1 )
{
extern void vApplicationIdleHook( void );

/* Call the user defined function from within the idle task. This
allows the application designer to add background functionality
without the overhead of a separate task.
NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,
CALL A FUNCTION THAT MIGHT BLOCK. */
vApplicationIdleHook();
}
#endif
}
} /*lint !e715 pvParameters is not accessed but all task functions require the same prototype. */

That is the function in tasks.c.
In tasks.c , there is include FreeRTOS.h. and inside FreeRTOS.h there is include FreeRTOSConfig.h

Thank you very much for your kindness. :)

RE: PIC32Starter kit_IdleHook_v5.1.0_Newbie

Posted by Pistole Gun on March 29, 2011
Hallo Richardbarry

Now I can use vApplicationIdleHook. but it looks very strange.
my previous program is just the same. I only copy the whole file to a new folder.
then change the name of .mcp
on the first, there is warning like below :
WARNING: Boot Flash Write Protect and/or Primary Oscillator Configuration set to safe defaults.

I do not know what happened,
then I closed it and reopened again.
debugger PIC32Starter kit, buid all, and there is no such warning again.
hmm.. strange..
and it can go to vApplicationIdleHook.

then I try my previous program again.
There is also same Warning,
I closed, reopened, do the same like before.
There is no such warning anymore.
but It cannot go to vApplicationIdleHook. like before.

I do not get any reasons, still confused. However my new folder with same code works.

Thanks for your help richardbarry :)


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists