Task state and transition

“freertos/RTOS-task-states”

I am reading the information given in the link many times but i’m having a hard time understanding the concept.

I am looking for examples to clarify the definition.

There are four rooms in one office and one reader is fixed at the door of each room.
When a person holding a valid card, scan his card in front of the reader, the door opens for 3 seconds and he can enter into the room, After this the gate will automatically close .
If the person wants to come out of the room then he has to press the button on the gate which will open the door for 3 seconds and he can come out. After this the gate will automatically close.
The whole system consists of a microcontroller that has four UARTs, all they are connected to four RFID readers. When the card is scanned in front of the RFID reader, the microcontroller receives 12 characters from the reader over UART. 9600 baud UART. The system has four switches and an four electronic door lock system

Note i can’t post link because i am new user

Hi and welcome Kittu,

it is not clear what you are asking for, I believe that you are looking for advice on how to translate your problem to a (Free)RTOS execution model.

I have worked in access control systems on RTOS based platforms for 25+ years, so I could tell you a lot about how to do that right, but that would probably not help you a whole lot.

May I suggest that you reduce your sample problem in complexity - eg only model a room with a single access point. Trust me, that is challenging enough for a beginning. A good starting point is to figure out which things need to happen concurrently (set aside threads of execution for those) and on the other hand which events require serialized execution (those generally, but necessarily go into a single thread of execution).

Once you have that laid out in a coarse model graphic, a good idea is to start (pseudo) coding for your desired platform. A lot of questions will have answered themselves at this point.

In this forum, you can expect very down-to-the-point and competent answers for down-to-the-point questions, but rarely will architectures be discussed or peer-developed here.

1 Like

Nice to hear that you already have work experience with access control systems. I was having a lot of difficulty in understanding how to convert system Tasks into rtos Tasks so I have taken this example

There’s a one room and a reader is fixed at the door. When the reader scans a valid card, the door opens for 3 seconds and then closes automatically… The door automatically opens and closes for 3 seconds when the user presses and releases the button.

The complexity is how to access the door because there are two ways to access it through the card and through the switch

if I got it right you just have to open a door for 3 sec if either a RFID telegram or a button event is detected. So it could be sufficient to have a task to control the door which is waiting for a open door message from a message queue sent from the UART ISR (after reception of the RFID telegram) or the button/GPIO ISR. Then you could open the door and start a one-shot FreeRTOS timer with the 3 sec duration. If another open door event occurs within the 3 sec just restart the timer on reception of the corresponding open door message.
In the timer callback (invoked on expiration) just send a close door message to the door task.
If open/close message contains the door ID (should be easy to do because you know from which UART you received the RFID telegram resp. which button was pressed) one door task along with 4 FreeRTOS timers could easily handle all 4 doors.
Alternatively and probably sufficient to cover all doors you could use task notifications

See also

well yes. But. How do you know that the person who presented the card actually DID enter the room? How do you know he or she even bothered to press the door knob? Maybe he or she remembered he or she had forgotton something and went back to the office instead of entering the room? What happens if the person does in fact push the knob and open the door but keeps it jammed open?

A “door” can have up to three inputs; one that signals that the knob has been pushed, one that signals that the door has indeed been opened, and one that indicated that the room has truly been entered (normally a laser bridge a few inches away from the actual entrance). Any given door may or may not have any subsets of thoser inputs. Consequently, monitoring the STATE a “door” is one (unlocked, opened, passed through, vandalized) is far from being trivial in the first place. Trust me. Just believing that if a card has been presented means that the corresponding card owner is in the room is naive in the best case.

And that is where it only begins. There are arbitrary policies defined by companies that make it even the more complex. For example , for certain security relevant doors, there are stipulations that at least x verified badges MUST have been presented before the door really opens and at most y people are in the room at any given time.

Again, if you are new to RTOS architecturing, pick simple things to model. Trust me. ONE door is far from being trivial. You will learn enough from it to keep you busy for months.

I think one key point is most of this discussion relates to the DATA model of the system, not the task structure model, and has nothing to the “Task State” model of FreeRTOS.

From everything I have heard, it sounds like it could be done with a single user-defined task getting event inputs from the various sensors, and time-out events from software timers triggered by these events, and the user-defined task initiates and terminates the door-open commands.

I have taken the example only and only to understand the task state of free RTOS. The link I posted only gives the definition.
It would have been better if the definition had explained these facts with a real world example.

Just to be clear… you did not post any link (possibly a new user permission problem)

i was talking about this link

1 Like

Examples are being given all over the place in the Demo section: FreeRTOS/FreeRTOS/Demo at main · FreeRTOS/FreeRTOS · GitHub
and here:
FreeRTOS/FreeRTOS-Plus/Demo at main · FreeRTOS/FreeRTOS · GitHub
Also in code comments in task.h