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

Get task running in error trap and terminate

Posted by https://www.google.com/accounts on June 10, 2012
My dsPIC processor supports error trap interrupts such as divide by zero, memory access violation, etc.

If one of these occurs then it is likely the task currently running has caused it. I would like to avoid a complete processor reset and just end the appropriate task. So, I will need to get the task pointer of the currently running task and terminate it. So, the code would look something like this:


void div_zero_exception()
{
xTaskHandle tp = xTaskGetCurrentTaskHandle();
_debug_msg("[****] Task terminated: %s due to zero division", pcTaskGetTaskName(tp));
vTaskSuspend(tp);
}


This will run from the task that is being terminated - would this cause any problems? This also only suspends the task - ideally, it would be completely terminated and all memory related to the task would be freed.

RE: Get task running in error trap and terminate

Posted by Richard Damon on June 11, 2012
One concern I would have is that you don't know for sure that the exception is coming from a task, it could also be coming from an interrupt handler. You also need to be careful about is killing a task at an unknown point, as you have no Idea on the status of the resources it uses.

I would also be very nervous about using a "printf" like function at the exception level. Note that in the exception handler, ALL interrupts are disabled.

RE: Get task running in error trap and terminate

Posted by Richard on June 11, 2012
As per richard_damon's reply, plus:

In this case, the exception is equivalent to an interrupt, so only FreeRTOS API functions that end if "FromISR" should be called. I can't remember the exact details of the PIC24 port, so you might get away with it, but keep in mind that you will be using the API outside of its intended scope.

Suspending the currently executing task will probably result in a reschedule, so your exception may never be concluded correctly (you may never clear the exception if another task starts running, and the stacks might be left in an inconsistent state). You also have to consider how you are going to exit from the exception, if you have deleted or suspended the task that caused the exception does not cause another task to execute - what are you going to return to?

Regards.


[ 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