Quality RTOS & Embedded Software

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


Semaphore doesn't seem to work

Posted by Torben on May 9, 2007

In my application I create a semaphore to control access to a global structure which holds the acual time, which is beeing read out a RTC in a task. In another task I create log entrys, including the time. In both tasks, the access to the structure is protected by the semaphore. I initialize the "time reading task" before the log task, so the time should be read out before any log entry is created. Even so the first log entrys contain a wrong time. How is this possible. As long as the time reading task holds the semaphore the log task should not be able to access the time keeping structure. Unfortunately my debugger (using IAR Embedded Workbench) is not able to debug this, I get a message stating "simulating illegal code condition". Now I am wondering how this is possible. Preemption is enabled and both tasks have the same priority. But this should not be important as I am using the semaphore. Has anyone an idea on this?


RE: Semaphore doesn't seem to work

Posted by Nobody/Anonymous on May 9, 2007
From the error it sounds like you are running it in the simulator. Is this the case. I don't think the IAR simulator simulated peripherals.

RE: Semaphore doesn't seem to work

Posted by Torben on May 9, 2007
No it runs on hardware with a SAM-ICE connected. The error is not the problem. I figured out so much: The RTC Read task is started before the Log Task. It runs beyond the take semaphore command and starts updating the clock structure. I then have to let it run, else I encounter the prior mentioned error. The Log task is entered thereafter (I have a breakpoint here). If I debug it, sometimes the time is correctly set prior to the first log entry and sometimes not. Is it possible that the tasks start in a casual order, so sometimes the log task has first access and sometimes not? I don't really think so but this would be an explanation. On the other hand: If the time is not correct, parts of the time are right, e.g. seconds and minutes, but not the hours, which is for me a hint that the RTC Task is being interrupted and the semaphore does not work. So far this only happens at startup. Before using a semaphore I had glitches in the displayed time several times, they are all gone with the introduction of the semaphore, only this startup problem is left.
I have firgured out a workaround which is reading the clock directly before staring the scheduler, nonetheless I would like to find the problem there.

I don't think my explanation is very good, but I hope you can still get the problem.

RE: Semaphore doesn't seem to work

Posted by Torben on May 9, 2007

I think I figured out the problem: It is not the semaphore it is the TWI which is use to read the RTC (I²C). Some or all Values seem to be read out wrong sometimes at startup, but not always. I thought the TWI routines work ok because they did till now. The errors seem only to occur at startup. So everything with the semaphores is fine!

[ 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.


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





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