Quality RTOS & Embedded Software

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


Loading

understanding portable code

Posted by kafna on December 9, 2017

Hi, I don't have a lot of background in RT , I want to understand few things.

  1. regarding the function pxPortInitialiseStack, it is wrriten Initialise the stack of a task to look exactly as if a call to portSAVE_CONTEXT had been called. So does it mean that pxPortInitialiseStack and portSAVE_CONTEXT are identical ? If I want to implement a new port, I should just make sure that those functions and also portRESTORE_CONTEXT are consistent with each other? For example, I can decide the order for which to push the registers values to the stack as long as it's the same order for the pxPortInitialiseStack and portSAVE_CONTEXT functions?

  2. Is the function portRESTORE_CONTEXT equivalent to the function __switch_to in the linux kernel ?

  3. I want to add a new port to dragonboard410c, which is arm64 cortext A53, which I see a directory in freertos portable/GCC/ARM_CA53_64_BIT is already implemented. Can I use the code there as is or there is a possibilty that I might need to adjust things ?

Thanks


understanding portable code

Posted by rtel on December 11, 2017
regarding the function |pxPortInitialiseStack|, it is wrriten
|Initialise the stack of a task to look exactly as if a call to
portSAVE_CONTEXT had been called|. So does it mean that
|pxPortInitialiseStack| and |portSAVE_CONTEXT| are identical ? 

No - perhaps too obviously if you look at the code, so maybe you don't mean literally - one is a function that sets the initial stack frame for a new task, and the other is [normally, but depends on port] a macro that saves the CPU context to the stack of a task.

So portSAVECONTEXT saves the CPU context onto the stack of the task, and portRESTORECONTEXT restores the CPU context from the stack of the task. It is the job of pxPortInitialiseStack() to create a stack frame that is identical to the one created by portSAVECONTEXT so when portRESTORECONTEXT is called to run a newly created task for the first time everything works as expected.

If I want to implement a new port, I should just make sure that those functions and also |portRESTORE_CONTEXT| are consistent with each other?

Yes.

For example, I can decide the order for which to push the registers
values to the stack as long as it's the same order for the
|pxPortInitialiseStack| and |portSAVE_CONTEXT| functions?

Almost - you also have to take into account the way the compiler uses the stack. For example, a parameter can be passed into a task so you need to know where the code generated by the compiler expects to find that parameter - be it in a particular register (r0 in the case of most ARM MCUs), or on the stack.

2.

Is the function |portRESTORE_CONTEXT| equivalent to the function
|__switch_to| in the linux kernel ?

Sorry, don't know :o)

3.

I want to add a new port to dragonboard410c
<https://developer.qualcomm.com/hardware/dragonboard-410c>, which is
arm64 cortext A53, which I see a directory in freertos
|portable/GCC/ARM_CA53_64_BIT| is already implemented. Can I use the
code there as is or there is a possibilty that I might need to
adjust things ?

No doubt the port in that directory will be a good starting point, and maybe everything you need. It mainly depends on the interrupt controller used. The port was written for the Zynq Ultrascale, which (I think) uses the standard ARM interrupt controller. If your port uses the same interrupt controller then you may not need to change anything (or maybe just a few register addresses).


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


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

Webinar

"OTA Update Security and Reliability" webinar presented by TI and AWS. Register here.


Careers

FreeRTOS and other embedded software careers at AWS.


Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.


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

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