Quality RTOS & Embedded Software

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


Loading

Giving a semaphore from the main function

Posted by sarahaka on February 24, 2019

Hello,

I want to acheive the following: 1. Once the main starts, check for the type of reset of the microcontroller. This can be a user reset, software reset etc.. 2. Based on the type of reset, give a semaphore to a specific task.

The problem is, techincially I am giving a smaphore to a task that is not yet created because I am checking for the type of reset in the begining of the main function. Initially I have several tasks, I only want the reset_task to run incase of a specific reset, while the other tasks will not run. The code looks like this: ~~~ int main(){

check for type of reset;
if (type of reset == software reset){
    Give a semaphore to task 3;
    (Or in other words, task 3 should run first and keepi running)
    (all other tasks will stay blocked)
}
create task 1;
create task 2;
create task 3;

} ~~~

Main function is not a task, but I need to check for resets at this point. This is the contradiction. Thus my question is, how do I make sure that task 3 is the first task to run and keep running. Task 3 is initially blocking on a semaphore.

I know that I may give the semaphore from task 1 or 2, but that mean I need to use a flag to store the state and it also means I need to copy paste the same peice of code into both tasks. Is there any better wat to do this?

Thank you


Giving a semaphore from the main function

Posted by hs2sf on February 24, 2019

What about using a flag checked by 'root' task 3 and let task 3 then create 'child' task 1 and 2 ?


Giving a semaphore from the main function

Posted by richarddamon on February 24, 2019

First, you can't give a flag to a specific task, but only raise or lower a given semaphore and let each task have their own.

What I would do is change your order a bit, First check for the type of reset and save that value, Next, create all of tasks/semaphores/queue/etc needed in the system (or at least all that can be created prescheduler) Finally, based on the saved flag value, ajust things to get the state you want.

You could have each of the task begin with taking a semaphore that is specific for that task, and only give the semaphore when that task is ready to run. Or you coul after creating each of the tasks suspend it, and then issue a resume when things are ready for it to run.


Giving a semaphore from the main function

Posted by richarddamon on February 24, 2019

First, you can't give a flag to a specific task, but only raise or lower a given semaphore and let each task have their own.

What I would do is change your order a bit, First check for the type of reset and save that value, Next, create all of tasks/semaphores/queue/etc needed in the system (or at least all that can be created prescheduler) Finally, based on the saved flag value, ajust things to get the state you want.

You could have each of the task begin with taking a semaphore that is specific for that task, and only give the semaphore when that task is ready to run. Or you coul after creating each of the tasks suspend it, and then issue a resume when things are ready for it to run.


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


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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

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

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

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Mediatek

Renesas

RISC-V

SiFIve RISC-V

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