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


"Broadcast" semaphores and watchdog timers

Posted by philpem on February 25, 2016


I've designed a system which uses the idle task to reset (kick/poke/whatever) the watchdog timer. Effectively this means that if the system is stuck in a tight loop for an extended period of time, it will reboot.

Unfortunately, sometimes there are long-running tasks which need to be handled, but the watchdog still needs to be dealt with too. Without yielding some time to the WDT, these long-running tasks will cause spurious watchdog resets. So as an extension to this design, the idle task gives a semaphore after the WDT is reset, which can then be taken by long-running tasks.

This raises the question: what can I do if I have two long-running tasks which want to yield? One watchdog reset is as good as any other, and if I have two tasks waiting, I should be able to wake both of them up. Is it possible to have a semaphore wake two tasks?

One solution I thought of was to have a queue which tracked the task handles of the tasks waiting for the watchdog to update.

When a task wants to wait, it puts its handle in the queue, then calls vTaskSuspend().

When the idle task has finished updating the watchdog, it looks in the queue and calls vTaskResume against all the task handles in the queue.

But this seems a little over-engineered. Can anyone suggest a better way to do this?

Thanks, Phil.

"Broadcast" semaphores and watchdog timers

Posted by davedoors on February 25, 2016

Brainstorm -

Use an event group instead of a semaphore?

Use a trace macro or tick hook to count the number of times each task executes, then check the counts on every 'n' ticks and clear the watchdog if the counts match expectation?

"Broadcast" semaphores and watchdog timers

Posted by philpem on February 26, 2016

That looks like a nice way to do it -- I hadn't even looked at Event Groups before. I'm now doing this:

  • Tasks use EventGroupSync with no bits to set and one "watchdog done" bit specified to wait for
  • Watchdog idle hook sets "watchdog done" event group bit when it's finished resetting the watchdog

Which beats my queue implementation by... well, not wasting memory on a queue. If another task needs to wait for a watchdog update, it simply ends up joining the end of the line and is resumed at the same time as the first one.

The timeout on the EventGroupSync call is only 10 ticks, so in practice not many tasks will end up waiting... but it would seem to guarantee that if multiple long-running tasks end up running, they can at least yield a small slice of CPU time back to the watchdog :)

How elegant!

Thanks, Phil.

[ 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