Quality RTOS & Embedded Software

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


Loading

freertos with endless loop in main instead of tasks

Posted by kafna on January 6, 2018

Hi, I'm working on a port of freertos to raspberry pi , I want to eventually port it to pi3 on 64 bit.

The code of pxPortInitialiseStack , portRESTORE_CONTEXT and portSAVE_CONTEXT is identical to the port for GCC/ARM7_AT91FR40008

I added uart driver with an intrrupt handler that works , and I want to start by porting only the uart driver. So I don't want to enable the timer interrupt and the scheduler, instead I want to run an endless loop in main function.

I wrote a function xInitPxCurrentTCB
which initialize pxCurrentTCB since it is used to save the sp register in context switch.

The main function initializes the uart, then calls xInitPxCurrentTCB and then enables the interrupts. It also initialize the spsr register to 0x1f as this is the initial value set in the function pxPortInitialiseStack

it then enters an endless loop where it turn the green led on and off.

The code for main.

I have two bugs that I couldn't figure them out:

  1. If I don't initialize the spsr register, then upon sending rx to the uart, the main function then starts from it's beginning after the interrupt handler returns instead of continuing from somewhere in the endless loop where the interrupt fired.
  2. If do initalize the spsr in the main function with:

~~~ _asm volatile("nop"); __asm volatile ("push {r0}"); __asm volatile ("mov r0, #31"); __asm volatile ("msr spsrcxsf, r0"); __asm volatile ("pop {r0}"); ~~~

Then it seems that there is a contraption , as the green led stop blinking.


freertos with endless loop in main instead of tasks

Posted by richard_damon on January 6, 2018

Many of the FreeRTOS API functions aren't supposed to be used (especially the 'FromISR ones) until after the schedule has been started, so you are going to be fighting FreeRTOS all the way with this plan.

Rather than trying to make things work with an endless loop in main, create a single task, and put the endless loop in that. Run it at task priority 0 so the Idle task will get time (not so important now, but later when you split off other functions, it may be needed), and then you won't have any of these sort of issues.


[ 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