Skip to content

Commit

Permalink
Merge pull request #15 from kaizoku-oh/config
Browse files Browse the repository at this point in the history
Config
  • Loading branch information
kaizoku-oh authored Apr 15, 2021
2 parents 03cb900 + 6376f65 commit be4cc98
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 23 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RTC OS (Run To Completion Operating System)
# RTCOS (Run To Completion Operating System)

<p align="center">
<img src="https://github.com/kaizoku-oh/rtcos/blob/main/docs/image/logo.png">
Expand All @@ -12,14 +12,13 @@
![GitHub issues](https://img.shields.io/github/issues/kaizoku-oh/rtcos)
![GitHub top language](https://img.shields.io/github/languages/top/kaizoku-oh/rtcos)
![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)
![Twitter follow](https://img.shields.io/twitter/follow/kaizoku_ouh?style=social)

is an event-driven RTC (Run To Completion) scheduler dedicated to ultra constrained IoT devices.

RTC OS is written in pure C and doesn't need any thirdparty library or dependency to work.
RTCOS is written in pure C and doesn't need any thirdparty library or dependency to work.

Being hardware agnostic, RTC OS can work on any hardware platform that can provide a hardware timer tick and optionally an interface to enter and exit critical section.
Being hardware agnostic, RTCOS can work on any hardware platform that can provide a hardware timer tick and optionally an interface to enter and exit critical section.

## Acknowledgments
- This project is inspired from the work done by [Jon Norenberg](https://github.com/norenberg99) in [rtcOS](https://github.com/norenberg99/rtcOS) project.

![Twitter follow](https://img.shields.io/twitter/follow/kaizoku_ouh?style=social)
2 changes: 1 addition & 1 deletion docs/rtcos_doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = RTCOS
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.1.1
PROJECT_NUMBER = 1.2.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
5 changes: 4 additions & 1 deletion examples/arduino/include/RTCOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : RTCOSConfig.h
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : RTCOS user configuration example used to overrite os default configuration
*
Expand All @@ -21,6 +21,9 @@
/*-----------------------------------------------------------------------------------------------*/
/* Defines */
/*-----------------------------------------------------------------------------------------------*/
#define RTCOS_ENABLE_MESSAGES
#define RTCOS_ENABLE_TIMERS

#define RTCOS_MAX_TASKS_COUNT 2
#define RTCOS_MAX_FUTURE_EVENTS_COUNT 2
#define RTCOS_MAX_MESSAGES_COUNT 2
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ monitor_speed = 9600
build_flags = -I include
lib_deps =
paulstoffregen/TimerOne@^1.1
kaizoku-oh/RTCOS@^1.1.1
kaizoku-oh/RTCOS@^1.2.0
2 changes: 1 addition & 1 deletion examples/arduino/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : main.cpp
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : Arduino example sketch
*
Expand Down
5 changes: 4 additions & 1 deletion examples/linux/RTCOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : RTCOSConfig.h
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : RTCOS user configuration example used to overrite os default configuration
*
Expand All @@ -16,6 +16,9 @@
/*-----------------------------------------------------------------------------------------------*/
/* Defines */
/*-----------------------------------------------------------------------------------------------*/
#define RTCOS_ENABLE_MESSAGES
#define RTCOS_ENABLE_TIMERS

#define RTCOS_MAX_TASKS_COUNT 2
#define RTCOS_MAX_FUTURE_EVENTS_COUNT 2
#define RTCOS_MAX_MESSAGES_COUNT 2
Expand Down
2 changes: 1 addition & 1 deletion examples/linux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : main.c
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : Linux example program
*
Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : config.h
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : RTCOS default configuration file
*
Expand Down
22 changes: 21 additions & 1 deletion include/rtcos.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : rtcos.h
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : RTCOS header file
*
Expand All @@ -27,6 +27,17 @@
#ifndef RTCOS_H
#define RTCOS_H

/*-----------------------------------------------------------------------------------------------*/
/* Includes */
/*-----------------------------------------------------------------------------------------------*/
/** @defgroup rtcos_private_includes Private includes
* @{
*/
#include "config.h"
/**
* @}
*/

/*-----------------------------------------------------------------------------------------------*/
/* Defines */
/*-----------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -60,7 +71,9 @@ typedef signed long long _s64;

/** RTCOS related types */
typedef void (*pf_os_idle_handler_t)(void);
#ifdef RTCOS_ENABLE_TIMERS
typedef void (*pf_os_timer_cb_t)(void const *);
#endif /* RTCOS_ENABLE_TIMERS */
typedef _u32 (*pf_os_task_handler_t)(_u32, _u08, _u32);
typedef enum
{
Expand All @@ -76,11 +89,14 @@ typedef enum
RTCOS_ERR_MSG_EMPTY = -9,
RTCOS_ERR_ARG = -10,
}rtcos_status_t;

#ifdef RTCOS_ENABLE_TIMERS
typedef enum
{
RTCOS_TIMER_PERIODIC = 0,
RTCOS_TIMER_ONE_SHOT,
}rtcos_timer_type_t;
#endif /* RTCOS_ENABLE_TIMERS */
/**
* @}
*/
Expand All @@ -99,16 +115,20 @@ void rtcos_delay(_u32);
void rtcos_update_tick(void);
void rtcos_set_tick_count(_u32);
_u32 rtcos_get_tick_count(void);
#ifdef RTCOS_ENABLE_TIMERS
_s08 rtcos_create_timer(rtcos_timer_type_t, pf_os_timer_cb_t, void *);
_bool rtcos_timer_expired(_u08);
rtcos_status_t rtcos_start_timer(_u08, _u32);
rtcos_status_t rtcos_stop_timer(_u08);
#endif /* RTCOS_ENABLE_TIMERS */
rtcos_status_t rtcos_register_task_handler(pf_os_task_handler_t, _u08, _u32);
rtcos_status_t rtcos_register_idle_handler(pf_os_idle_handler_t);
rtcos_status_t rtcos_send_event(_u08, _u32, _u32, _bool);
rtcos_status_t rtcos_clear_event(_u08, _u32);
#ifdef RTCOS_ENABLE_MESSAGES
rtcos_status_t rtcos_send_message(_u08, void *);
rtcos_status_t rtcos_get_message(void **);
#endif /* RTCOS_ENABLE_MESSAGES */

#if defined(__cplusplus)
}
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RTCOS",
"version": "1.1.1",
"version": "1.2.0",
"description": "An event-driven RTC (Run To Completion) OS/scheduler dedicated to ultra constrained devices.",
"keywords": "cooperative, event, scheduler, os",
"repository":
Expand Down
44 changes: 35 additions & 9 deletions src/rtcos.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file : rtcos.c
* @author : Bayrem GHARSELLAOUI
* @version : 1.1.1
* @version : 1.2.0
* @date : April 2021
* @brief : RTCOS source file
*
Expand Down Expand Up @@ -31,6 +31,7 @@
/** @defgroup rtcos_private_types Private types
* @{
*/
#ifdef RTCOS_ENABLE_MESSAGES
/** Fifo structure used for storing messages */
typedef struct
{
Expand All @@ -39,6 +40,7 @@ typedef struct
_u08 u08Count; /**< Fifo current count */
void *tpvBuffer[RTCOS_MAX_MESSAGES_COUNT]; /**< Fifo buffer of pointers */
}rtcos_fifo_t;
#endif /* RTCOS_ENABLE_MESSAGES */

/** Future event structure representing information about each event */
typedef struct
Expand All @@ -50,37 +52,43 @@ typedef struct
volatile _bool bInUse; /**< Indicates if the event is still used */
}rtcos_future_event_t;

#ifdef RTCOS_ENABLE_TIMERS
/** Software os timer structure representing information about each timer */
typedef struct
{
volatile _bool bInUse; /**< Indicates if the timer is still used */
rtcos_timer_type_t ePeriodType; /**< Periodic or one shot timer */
volatile _u32 u32StartTickCount; /**< Start time of the timer */
_u32 u32TickDelay; /**< Period of the timer */
pf_os_timer_cb_t pfTimerCb; /**< Timer callback function */
pf_os_timer_cb_t pfTimerCb; /**< Timer callback function */
}rtcos_timer_t;
#endif /* RTCOS_ENABLE_TIMERS */

/** Task structure representing information about each task */
typedef struct
{
volatile _u32 u32EventFlags; /**< Event flags associated to this task */
pf_os_task_handler_t pfTaskHandlerCb; /**< Task handler function */
pf_os_task_handler_t pfTaskHandlerCb; /**< Task handler function */
_u32 u32TaskParam; /**< Task parameter */
#ifdef RTCOS_ENABLE_MESSAGES
rtcos_fifo_t stFifo; /**< Fifo associated to this task */
#endif /* RTCOS_ENABLE_MESSAGES */
}rtcos_task_t;

/** Context structure representing the main context of the OS */
typedef struct
{
_u08 u08TasksCount; /**< Number of the tasks present in the system */
_u08 u08CurrentTaskID; /**< Current task ID */
volatile _u32 u32SysTicksCount; /**< Current number of the system ticks */
pf_os_idle_handler_t pfIdleHandler; /**< Handler function when the system is Idle */
volatile _u32 u32SysTicksCount; /**< Current number of the system ticks */
pf_os_idle_handler_t pfIdleHandler; /**< Handler function when the system is Idle */
volatile _u08 u08FutureEventsCount; /**< Number of the events present in the system */
rtcos_future_event_t tstFutureEvents[RTCOS_MAX_FUTURE_EVENTS_COUNT]; /**< Array of events */
rtcos_task_t tstTasks[RTCOS_MAX_TASKS_COUNT]; /**< Array of tasks */
#ifdef RTCOS_ENABLE_TIMERS
rtcos_timer_t tstTimers[RTCOS_MAX_TIMERS_COUNT]; /**< Array of timers */
_u08 u08TimersCount; /**< Number of the timers present in the system */
#endif /* RTCOS_ENABLE_TIMERS */
}rtcos_ctx_t;
/**
* @}
Expand All @@ -103,6 +111,7 @@ static rtcos_ctx_t stRtcosCtx;
/** @defgroup rtcos_private_functions Private functions
* @{
*/
#ifdef RTCOS_ENABLE_MESSAGES
/** ***********************************************************************************************
* @brief Initialize the fifo that will hold a task's messages
* @param u08TaskID ID of the task using this fifo
Expand Down Expand Up @@ -204,6 +213,7 @@ static rtcos_status_t _rtcos_fifo_pop(_u08 u08TaskID, void **ppvMsg)
}
return eRetVal;
}
#endif /* RTCOS_ENABLE_MESSAGES */

/** ***********************************************************************************************
* @brief Find the highest priority task with an event or a message
Expand All @@ -218,8 +228,11 @@ static _bool _rtcos_find_ready_task(_u08 *pu08NewCurrTaskID)
bRetVal = FALSE;
for(u08Index = 0; u08Index < stRtcosCtx.u08TasksCount; ++u08Index)
{
if((0 != stRtcosCtx.tstTasks[u08Index].u32EventFlags) ||
(FALSE == _rtcos_fifo_empty(u08Index)))
if((0 != stRtcosCtx.tstTasks[u08Index].u32EventFlags)
#ifdef RTCOS_ENABLE_MESSAGES
|| (FALSE == _rtcos_fifo_empty(u08Index))
#endif /* RTCOS_ENABLE_MESSAGES */
)
{
*pu08NewCurrTaskID = u08Index;
bRetVal = TRUE;
Expand All @@ -246,7 +259,11 @@ static void _rtcos_run_ready_task(_u08 u08NewCurrTaskID)
RTCOS_EXIT_CRITICAL_SECTION();
u32UnhandledEvents = (stRtcosCtx.tstTasks[stRtcosCtx.u08CurrentTaskID].pfTaskHandlerCb)
(u32CurrentEvents,
#ifdef RTCOS_ENABLE_MESSAGES
_rtcos_fifo_count(stRtcosCtx.u08CurrentTaskID),
#else
0,
#endif /* RTCOS_ENABLE_MESSAGES */
stRtcosCtx.tstTasks[stRtcosCtx.u08CurrentTaskID].u32TaskParam);
RTCOS_ENTER_CRITICAL_SECTION();
stRtcosCtx.tstTasks[stRtcosCtx.u08CurrentTaskID].u32EventFlags |= u32UnhandledEvents;
Expand Down Expand Up @@ -428,7 +445,9 @@ void rtcos_init(void)
{
stRtcosCtx.tstTasks[u08Index].pfTaskHandlerCb = NIL;
stRtcosCtx.tstTasks[u08Index].u32EventFlags = 0;
#ifdef RTCOS_ENABLE_MESSAGES
_rtcos_fifo_init(u08Index);
#endif /* RTCOS_ENABLE_MESSAGES */
}
for(u08Index = 0; u08Index < RTCOS_MAX_FUTURE_EVENTS_COUNT; ++u08Index)
{
Expand All @@ -438,19 +457,20 @@ void rtcos_init(void)
stRtcosCtx.tstFutureEvents[u08Index].u32EventDelay = 0;
stRtcosCtx.tstFutureEvents[u08Index].u32ReloadDelay = 0;
}
#ifdef RTCOS_ENABLE_TIMERS
for(u08Index = 0; u08Index < RTCOS_MAX_TASKS_COUNT; ++u08Index)
{
stRtcosCtx.tstTimers[u08Index].u32StartTickCount = 0;
stRtcosCtx.tstTimers[u08Index].u32TickDelay = 0;
stRtcosCtx.tstTimers[u08Index].bInUse = FALSE;
stRtcosCtx.tstTimers[u08Index].pfTimerCb = NIL;
}
stRtcosCtx.u08TimersCount = 0;
#endif /* RTCOS_ENABLE_TIMERS */
stRtcosCtx.u08CurrentTaskID = 0;
stRtcosCtx.u32SysTicksCount = 0;
stRtcosCtx.u08TasksCount = 0;
stRtcosCtx.u08FutureEventsCount = 0;
stRtcosCtx.pfIdleHandler = NIL;
stRtcosCtx.u08TimersCount = 0;
}

/** ***********************************************************************************************
Expand Down Expand Up @@ -508,6 +528,7 @@ rtcos_status_t rtcos_register_idle_handler(pf_os_idle_handler_t pfIdleHandler)
return eRetVal;
}

#ifdef RTCOS_ENABLE_MESSAGES
/** ***********************************************************************************************
* @brief Send a message to a task
* @param u08TaskID ID of the task which will receive the message
Expand Down Expand Up @@ -552,7 +573,9 @@ rtcos_status_t rtcos_get_message(void **ppMsg)
}
return eRetVal;
}
#endif /* RTCOS_ENABLE_MESSAGES */

#ifdef RTCOS_ENABLE_TIMERS
/** ***********************************************************************************************
* @brief Create an os software timer
* @param ePeriodType timer type as defined in ::rtcos_timer_type_t
Expand Down Expand Up @@ -652,6 +675,7 @@ _bool rtcos_timer_expired(_u08 u08TimerID)
RTCOS_EXIT_CRITICAL_SECTION();
return bExpired;
}
#endif /* RTCOS_ENABLE_TIMERS */

/** ***********************************************************************************************
* @brief Set an event for a certain task
Expand Down Expand Up @@ -813,6 +837,7 @@ void rtcos_update_tick(void)
}
}
}
#ifdef RTCOS_ENABLE_TIMERS
if(stRtcosCtx.u08TimersCount > 0)
{
for(u08Index = 0; u08Index < stRtcosCtx.u08TimersCount; u08Index++)
Expand All @@ -831,6 +856,7 @@ void rtcos_update_tick(void)
}
}
}
#endif /* RTCOS_ENABLE_TIMERS */
RTCOS_EXIT_CRITICAL_SECTION();
}
/**
Expand Down

0 comments on commit be4cc98

Please sign in to comment.