TOP Contributors

  1. MIKROE (2653 codes)
  2. Alcides Ramos (352 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (136715 times)
  2. FAT32 Library (69925 times)
  3. Network Ethernet Library (55938 times)
  4. USB Device Library (46261 times)
  5. Network WiFi Library (41884 times)
  6. FT800 Library (41150 times)
  7. GSM click (28979 times)
  8. PID Library (26412 times)
  9. mikroSDK (26355 times)
  10. microSD click (25353 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Library

C RTOS for mP and mB (P18 and P24)

Rating:

10

Author: dany

Last Updated: 2016-02-18

Package Version: 3.0.0.0

Category: Other Codes

Downloaded: 5008 times

Followed by: 2 users

License: MIT license  

CRTOS stands for Cooperative Real Time Operating System; designed for and written specifically in mP/mB from mikroElektronika. The system uses cooperative as opposed to pre-emptive scheduling which means that the application code you write has to voluntarily release back to the operating system at appropriate times.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "C RTOS for mP and mB (P18 and P24)" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "C RTOS for mP and mB (P18 and P24)" changes.

Do you want to report abuse regarding "C RTOS for mP and mB (P18 and P24)".

  • Information
  • Comments (2)

Library Blog

CRTOS Library (Cooperative Real Time Operating System). Documentation. The P24 mP version was tested on P24FJ64GA002 and on MMB for P24EF. The P24 mB version was tested on a P24FJ64GA002 (limited test). The P18 version is tested on a P18F2620.


IMPORTANT: Since the projects using CRTOS will include *.inc files and at least one *.pld file it is necessary to have the "Always build all files in the project” compiler option (IDE menu: Tools, Options, Output settings ) ON.


Attention for package (.mpkg) users:
After installing the package please copy all "*.inc" files from the directory " C:\Users\Public\Documents\Mikroelektronika\mikroPascal PRO for dsPIC\Packages\CRTOS_PIC24\examples\CRTOS include files" to the directory "C:\Users\Public\Documents\Mikroelektronika\mikroPascal PRO for dsPIC\Packages\CRTOS_PIC24\Uses" (P24 version, windows 7 example given).


This RTOS is a Cooperative Real Time Operating System designed for and written specifically in mikroPascal from mikroElektronika. The system uses cooperative as opposed to pre-emptive scheduling which means that the application code you write has to voluntarily release back to the operating system at appropriate times.

Writing code for a RTOS requires a different mindset from that used when writing a single threaded
application. However, once you have come to terms with this approach you will find that quite complex real time systems can be developed quickly using the services of the operating system.

A cooperative operating system is the simplest one imaginable. The tasks running under this type of RTOS are not interrupted by the RTOS to give execution time to another task (as with the preemptive Real Time OS), instead, tasks always have to hand back control to the operating system (i.e.“yield” to the operating system) before the CRTOS gives execution to another task.

So, simple enough. This means however that each single task must yield to the OS in an acceptable time. If a task is too time consuming then it has to be split up in several subtasks, each with an acceptable yield time. Hence the term cooperative: the tasks have to cooperate to make things work well.

The whole library is targeted at the P18, P24 and P24E series of MPUs. It is written in mikroPascal (with a small part - context saving and restoring - in assembler), so changes should be rather easy to implement.

CRTOS supports the following features:

  • Task priorities
  • Tasks can have local variables (only for P24) of which the values has to be preserved between task invocations. In the P18 version the value of any local variables can be lost between task invocations.
  • Unconditional yielding to the CRTOS Scheduler
  • Timed yielding to the CRTOS Scheduler (i.e. “delay” performed by the Scheduler)
  • Binary semaphores
  • Counting semaphores
  • Waiting for semaphores with or without timeout
  • Clearing semaphores
  • Starting and stopping tasks
  • Starting tasks with an initial delay
  • Signaling semaphores from within an Interrupt Service Routine
  • An "Always" procedure in every scheduler loop (optionally, only for P24)

Have fun!


Usage Examples:
Uart receive / send example with a critical resource
CRTOS Counting Semaphore example
CRTOS Counting Semaphore signaled from ISR example
Example for the mikro Media Board (P24EP)


  Acknowledgement: The specification of CRTOS is derived from PRTOS which was written by John Barrat in PDS Basic. Also some parts of text in the documentation are extracted (and are sometimes adapted) from the document “PRTOS, Real Time Operating System for Proton Development System” written by John Barrat. John also contributed a lot to the development of the library, test projects and examples. Thanks John!      

 

Task switching mechanism

Task switching mechanism

As can be seen, the scheduler does not “call” the tasks, the tasks “call” the scheduler. The scheduler simply chooses the task to which it “returns” to.

View full image

Version 1.1: corrected an error in "OS_CreateCountingSemaphore". Sorry for the inconvenience.


2013-06-27: Updated the documentation CRTOS.pdf


2013-06-29: New version: the .mpkg file (package) was not installable: an .mpkg file should have a library (.mcl files) included, this was not the case.


30-06-2013: version 1.2.
Made selection of the next task faster,
Optimized the timer interrupt procedure for speed,
Optimized the time interrupts are disabled.


2013-07-01: added the mikroBasic for PIC24 version.


2013-07-03: Added the "Always" procedure to the documentation now (was implemented in version 1.2). This is a procedure that is called (optionally) in every CRTOS scheduler loop.


2013-07-04: Updated the documentation. My thanks to John Barrat for his advice.


2012-07-05: new version: v1.3.
Added some functionalities:

  • OS_StartTask_Delay (starting a task with an initial delay)
  • OS_ClearSemaphore (clearing binary and counting semaphores)

2013-07-09: version 1.4: Moved the CRTOS configuration out of CRTOS.mpas to 2 project files: CRTOS_Defines.pld and CRTOS_Sizes.inc. The user does not have to adapt the library code itself to his needs, this is now done in the 2 extra project files. See the Documentation for details.


New version 2.0 (2013-09-02): Extended the context of the tasks. The saved context per task is now: W0..W14, PSVPAG, TBLPAG, RCOUNT, PCH and PCL, according the suggestions of the mE developers (thanks mE!).


2013-09-03: - corrected a small error in "CRTOS_Select_and Run_Task.inc". Nothing fatal. :-) - made the assembler code in the .inc files more simple. The functionality is unchanged.


 Version 3.0 (2013-09-11): - Made the PIC24 versions more code size efficient (one extra file: "CRTOS_P24E.inc"). - Added the P18 versions (mP and mB)


2013-12-12: Added the following text to the helpfile regarding the compiler options to use: IMPORTANT: Since the projects using CRTOS will include *.inc files and at least one *.pld file it is necessary to have the "Always build all files in the project” compiler option (IDE menu: Tools, Options, Output settings ) ON.


2014-03-13: The mikroBasic files and zip files have been updated. All mB sources are present now (not tested if compilable though).


2015-01-26: Replaced the mB files: all mB files are compilable now (which e.g. means that all "with" statements are dealt with). I could however not link and test the libraries (no mB licence).


2015-05-09: Corrected the P24 version for problems with non preservation of local variable values. Also a problem with accessing constants (which blocked the code) has been solved. Sorry for any inconveniences caused by these issues!


2015-05-11: Both P18 and P24: Small change in OS_CreateTask and Restore_Context, no functionality changes...

ALSO FROM THIS AUTHOR

Article: The DS18(S)20, DS18B20, DS1820 Lib and OW_Utilities Lib usage

3

The DS18(S)20, DS18B20 device usage plus the DS1820 Lib and OW_Utilities Lib usage. Also some errors in the mE example (compiler help) are stated.

[Learn More]

Schedulers

11

Scheduler (in a broad sense) related libs:
"Timebase"
"Timers"
"COS"
"COS_TimedOnly"
"StateMachine"
"StateMachine_2"

[Learn More]

Tool: mikroPascal to mikroBasic convertor

10

Simple mikroPascal for PIC to mikroBasic for PIC source code convertor. The tool can convert complete mP units to mB modules and complete mP programs to mB programs. It can be used both in interactive and batchmode.

[Learn More]