Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner