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

IAR 78K0R port: random reboots

Posted by justdanpo on March 5, 2015

I've just fixed a bug very hard to find. IAR 78K0R port uses configMEMORYMODE to detect if ES register should be saved/restored on a context switch. The problem occurs when a project has near data model and far code model with a code placed in several 64K pages. As data model is near, configMEMORYMODE should be set to 0. But a function exit code generated by IAR uses far data pointers. These pointers are used to retrieve how much function arguments should be removed from a stack. When some task goes to a background inside a function exit code and another task or interrupt handler changes ES register, stack pointer of the first task becomes invalid. To fix this issue portSAVECONTEXT and portRESTORECONTEXT in addition to configMEMORY_MODE should check the code model. But I'd rather always save ES register even when both code and data models are near.


IAR 78K0R port: random reboots

Posted by rtel on March 5, 2015

Thanks for taking the time to report this. I would be grateful if you could attach the updated port layer file so we can ensure we understand the fix correctly.

Regards.


IAR 78K0R port: random reboots

Posted by justdanpo on March 6, 2015

FreeRTOSSourceportableIAR78K0RISR_Support.h

portSAVE_CONTEXT macro

Original code:

~~~~~~

if configMEMORY_MODE == 1
MOV       A, CS                 ; Save CS register.
XCH       A, X
MOV       A, ES                 ; Save ES register.
PUSH      AX
else
MOV       A, CS                 ; Save CS register.
PUSH      AX
endif

~~~~~~

For those who count each instruction cycle:

~~~~~

if defined(FAR_MODEL) || (configMEMORY_MODE == 1)
MOV       A, CS                 ; Save CS register.
XCH       A, X
MOV       A, ES                 ; Save ES register.
PUSH      AX
else
MOV       A, CS                 ; Save CS register.
PUSH      AX
endif

~~~~~

__FARMODEL_ is a macro defined in assembler preprocessor options (just like __NEARMODEL_ in original demo project FreeRTOSDemoNEC78K0RIAR). Also the condition (configMEMORYMODE == 1) may be replaced by defined(_FARDATAMODEL__).

The code I use at this moment:

~~~~~ MOV A, CS ; Save CS register. XCH A, X MOV A, ES ; Save ES register. PUSH AX ~~~~~

I don't care about 2 extra instructions for each save/restore context. Also some of my projects, which use NEAR code and data models, use far pointers (to access flash memory for example) so conditional compilation may also cause a bug.

portRESTORE_CONTEXT macro should be changed by the same way.


IAR 78K0R port: random reboots

Posted by justdanpo on October 1, 2015

OK, here is the file

Attachments

ISR_Support.h (5397 bytes)


[ 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