This is a port of the mruby/c tutorial Chapter 03 to the mbed environment.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rrt0.h Source File

rrt0.h

Go to the documentation of this file.
00001 /*! @file
00002   @brief
00003   Realtime multitask monitor for mruby/c
00004 
00005   <pre>
00006   Copyright (C) 2016 Kyushu Institute of Technology.
00007   Copyright (C) 2016 Shimane IT Open-Innovation Center.
00008 
00009   This file is distributed under BSD 3-Clause License.
00010   </pre>
00011 */
00012 
00013 #ifndef MRBC_SRC_RRT0_H_
00014 #define MRBC_SRC_RRT0_H_
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019 
00020 /***** Feature test switches ************************************************/
00021 /***** System headers *******************************************************/
00022 #include <stdint.h>
00023 
00024 /***** Local headers ********************************************************/
00025 /***** Constant values ******************************************************/
00026 
00027 //================================================
00028 /*!@brief
00029   Task state
00030 */
00031 enum MrbcTaskState {
00032   TASKSTATE_DOMANT    = 0x00,
00033   TASKSTATE_READY     = 0x01,
00034   TASKSTATE_RUNNING   = 0x03,
00035   TASKSTATE_WAITING   = 0x04,
00036   TASKSTATE_SUSPENDED = 0x08,
00037 };
00038 
00039 
00040 /***** Macros ***************************************************************/
00041 /***** Typedefs *************************************************************/
00042 
00043 //================================================
00044 /*!@brief
00045   Task control block
00046 */
00047 struct VM;
00048 typedef volatile struct st_MrbcTcb {
00049   volatile struct st_MrbcTcb *next;
00050   struct VM               *vm;
00051   uint8_t                  priority;
00052   uint8_t                  priority_preemption;
00053   uint8_t                  timeslice;
00054   uint8_t                  state; //!< enum MrbcTaskState
00055   union {
00056     uint32_t wakeup_tick;
00057   };
00058 } MrbcTcb;
00059 
00060 #define MRBC_TCB_INITIALIZER { 0, 0, 128, 128, 0, TASKSTATE_READY }
00061 
00062 
00063 /***** Global variables *****************************************************/
00064 /***** Function prototypes **************************************************/
00065 void mrbc_tick (void);
00066 void mrbc_init (void);
00067 MrbcTcb *mrbc_create_task (const uint8_t *vm_code, MrbcTcb *tcb);
00068 int mrbc_run (void);
00069 void mrbc_sleep_ms (MrbcTcb *tcb, uint32_t ms);
00070 void mrbc_relinquish (MrbcTcb *tcb);
00071 void mrbc_change_priority (MrbcTcb *tcb, int priority);
00072 void mrbc_suspend_task (MrbcTcb *tcb);
00073 void mrbc_resume_task (MrbcTcb *tcb);
00074 
00075 
00076 /***** Inline functions *****************************************************/
00077 
00078 
00079 #ifdef __cplusplus
00080 }
00081 #endif
00082 #endif // ifndef MRBC_RRT0_H_
00083