Two or more Tasks

Could you please give me an example of a real world application that requires two or more threads / Task’s?

This will help me to get the idea

I hope this can help?

I worked in access control for many years. A typical example is a card reader that must perform several tasks concurrently:

  • monitor the radio field for badge presentations and process those
  • communicate with a host (typically over a serial line)
  • maintain timers (eg to be able to time out cards)
  • serve peripherals such as LEDs

The crucial point here is that all of those tasks have some degree of independence of each other. If the control flow was static, unidirectional and deterministic, a single strand of execuition would suffice.

For a long time, such a device would be programmed without an RTOS, typically as some kind of big message pump or state machine. Anyone who has ever seen such a code base will agree that an RTOS makes life much much much easier.

2 Likes

One of my best examples is a system with a motor controller and a command interface.

The motor control part of the system needs to do its work at very tightly controlled times, between when we get feedback from the system and when we need to update the control loop in response to that feedback. This will be done in a “High” priority task.

The command interface takes in various inputs and adjusts the overall goals of the control loop. This can be done in a “Low” priority task, as a millisecond delay in processing isn’t important.

This low priority task will be interrupted every time new motor information comes in and the high priority task does its work, and then resumed.

To try and do this with a single task means the command processor needs to frequently stop what it is doing and see if the control loop will need to run soon. This makes the command processor very messy and the system fragile, as if you miss a section that takes too long, your control loop breaks or degrades.

2 Likes

I have no idea how your access control system work. I’ve seen a door lock access control system that has a reader on the front of the door.
To enter the room, the user has to scan the card in front of the reader, if there is a valid card, the door opens for a few seconds(5 seconds) and closes automatically. If the user wants to come out of the room, he presses the switch on the door, then the door opens for 5 seconds and closes automatically. An office has many such doors which are controlled by an access control system.

If freeRTOS is applicable for my use case then how many threads need to be created ?

You need to distingush between readers and AC terminals. A terminal normally controls a number of entrances, that is, readers, door input contacts, relays and so on, and it (the terminal) frequently has a host (network) communication to a remote server from which it downloads the credential and permission database (with reliable internet, the access decisions may be made in the cloud altogehter these days). The readers provide the credentials which the terminals use to make the access decision.

Sometimes readers serve as semi terminals, ie have the information to make local access decisions, but that is very rare. Normally readers are either transparent (ie tunnel all communication between the card/badge and the terminal) or do some very rudimentary check on the card credentials and otherwise just pass them on to the terminal. Sometimes readers have on board peripherals (relay for a door latch, feeback contacts etc) which are then driven by the terminal, sometimes not. Some readers take up intelligence to write offline permissions to cards. Most readers have red/green/yellow LEDs that can be driven asynchronously by the terminal.

For a “dumb” reader, you can budget in something around a half dozen tasks. For a full blown AC terminal serving 32 doors there may easily be 50 up to a hundred (third party middleware generally takes up a good number as well).

1 Like

I’m changing my use case to better understand what you said.

There is an access control system that has an inbuilt reader to scan the tag and microcontroller to read tag and compare the data and it also control door using realy. There are two sensors IN sensor confirm that the user has entered into the room and the out sensor confirms that the user has come out of the room.

Each access control system is installed on a door, and all these access systems are connected to a centralized server.

In the above use cases I want to understand how the tasks of the whole system are divided into OS tasks.

Into how many tasks have you or will you divide the task of the system?
RAc
@AWS