RainbowBS Manual: RainbowBS.h File Reference

RainbowBS

RainbowBS Manual  v0.1.0
Written by QWQ([email protected])
RainbowBS.h File Reference
#include <stddef.h> #include <windows.h>
#include "RainbowBSConf.h"
#include "pt.h"
#include "pt-sem.h"
#include <stdio.h>
#include <string.h>
Include dependency graph for RainbowBS.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  tTime
 Time structure. More...
 
struct  process_struct
 Process structure(one process consists one protothread). More...
 
struct  etime_struct
 Event timer structure. More...
 

Macros

#define RBS_VERSION   "0.1.0"
 
#define RBS_VERNUM   0x0100
 
#define RBS_VER_MAJOR   0
 
#define RBS_VER_MINOR   1
 
#define RBS_VER_REVISION   0
 
#define RBS_VER_SUBREVISION   0
 
#define FALSE   0u
 
#define TRUE   1u
 
#define USE_PARA(para)   (para = (para))
 
#define MIN(v0, v1)   (((v0) > (v1)) ? (v1) : (v0))
 
#define MAX(v0, v1)   (((v0) > (v1)) ? (v0) : (v1))
 
#define ABS(v)   (((v) >= 0) ? (v) : (-(v)))
 
#define SWAP(a, b)   (a = (a) + (b),b = (a) - (b),a = (a) - (b))
 
#define COUNT_OF(a)   (sizeof(a)/sizeof(a[0]))
 
#define _STR(a)   #a
 
#define STR(a)   _STR(a)
 
#define _CONS(a, b)   a##b
 
#define CONS(a, b)   _CONS(a,b)
 
#define ALIGN_F(pointer, power2)   (((IPTRDIFF)(pointer) + ((IPTRDIFF)((power2) - 1))) & (~((IPTRDIFF)((power2) - 1))))
 
#define ALIGN_B(pointer, power2)   ((IPTRDIFF)(pointer) & (~((IPTRDIFF)((power2) - 1))))
 
#define HDMM_NULL   NULL
 
#define HBLOCK_NULL   NULL
 
#define HMEM_NULL   NULL
 
#define PROCESS_NONE   NULL
 
#define PROCESS_BROADCAST   NULL
 
#define PROCESS_NAME_STRING(process)   ((NULL == (process)) ? "No Name" : (process)->name)
 
predefined event type
#define PROCESS_EVENT_NONE   0x80
 
#define PROCESS_EVENT_INIT   0x81
 
#define PROCESS_EVENT_POLL   0x82
 
#define PROCESS_EVENT_EXIT   0x83
 
#define PROCESS_EVENT_SERVICE_REMOVED   0x84
 
#define PROCESS_EVENT_CONTINUE   0x85
 
#define PROCESS_EVENT_MSG   0x86
 
#define PROCESS_EVENT_EXITED   0x87
 
#define PROCESS_EVENT_TIMER   0x88
 
#define PROCESS_EVENT_COM   0x89
 
#define PROCESS_EVENT_MAX   0x8a
 
process declaration and definition
#define PROCESS_THREAD(name, ev, data)
 Define the body of a process. More...
 
#define PROCESS_NAME(name)   extern tPROCESS name
 Declare the name of a process. More...
 
#define PROCESS(name, strname)
 Define a process. More...
 
semaphore declaration and definition
#define SEM_NAME(name)   extern struct pt_sem sem_##name
 Declare the name of a semaphore. More...
 
#define SEM(name, count)
 Define a semaphore. More...
 
process protothread functions
#define PROCESS_BEGIN()
 Define the beginning of a process. More...
 
#define PROCESS_END()
 Define the end of a process. More...
 
#define PROCESS_WAIT_EVENT()
 Wait for an event to be posted to the process. More...
 
#define PROCESS_WAIT_EVENT_UNTIL(c)
 Wait for an event to be posted to the process, with an extra condition. More...
 
#define PROCESS_YIELD()
 Yield the currently running process.
 
#define PROCESS_YIELD_UNTIL(c)
 Yield the currently running process until a condition occurs. More...
 
#define PROCESS_WAIT_UNTIL(c)
 Wait for a condition to occur. More...
 
#define PROCESS_WAIT_WHILE(c)
 Wait for a condition not occur. More...
 
#define PROCESS_EXIT()
 Exit the currently running process.
 
#define PROCESS_PT_SPAWN(pt, thread)
 Spawn a protothread from the process. More...
 
#define PROCESS_PAUSE()
 Yield the process for a short while. More...
 
#define PROCESS_WAIT_SEM(name)
 
#define PROCESS_SIGNAL_SEM(name)
 
poll and exit handlers
#define PROCESS_POLLHANDLER(handler)   if(ev == PROCESS_EVENT_POLL) { handler; }
 Specify an action when a process is polled. More...
 
#define PROCESS_EXITHANDLER(handler)   if(ev == PROCESS_EVENT_EXIT) { handler; }
 Specify an action when a process exits. More...
 
statement macros

statement macros for debug

#define RBS_DEBUG_STA(sta)   sta
 C statement sta is compiled if enable debug. More...
 
#define RBS_DEBUG_IF(exp, sta)   if (exp) { sta
 C statement if is compiled if enable debug. More...
 
#define RBS_DEBUG_ELSIF(sta1, exp, sta2)   sta1;} else if (exp) { sta2
 C statement else if is compiled if enable debug. More...
 
#define RBS_DEBUG_ENDIF(sta)   sta;}
 C statement } for if is compiled if enable debug. More...
 
error macro function

error macros for debug output

#define RBS_DEBUG_ERROR(exp, s, sta)
 Output error information. More...
 
#define RBS_DEBUG_ERROR_FORMAT(exp, format, sta, ...)
 Output format error information conditionally. More...
 
warning macro function

warning macros for debug output

#define RBS_DEBUG_WARN(exp, s)
 Output warning information conditionally. More...
 
#define RBS_DEBUG_WARN_FORMAT(exp, format, ...)
 Output format warning information conditionally. More...
 
log macro function

log macros for debug output

#define RBS_DEBUG_LOG(s)
 Output format log information. More...
 
#define RBS_DEBUG_LOG_FORMAT(format, ...)
 Output format log information. More...
 

Typedefs

typedef uint8_t BOOL
 
typedef int8_t I8
 
typedef uint8_t U8
 
typedef int16_t I16
 
typedef uint16_t U16
 
typedef int32_t I32
 
typedef uint32_t U32
 
typedef int64_t I64
 
typedef uint64_t U64
 
typedef size_t USIZE
 
typedef ptrdiff_t IPTRDIFF
 
typedef U64 TICK
 
typedef void * hDMM
 
typedef void * hBLOCK
 
typedef void * hMEM
 
typedef U8 process_event_t
 
typedef void * process_data_t
 
typedef struct process_struct tPROCESS
 Process structure(one process consists one protothread). More...
 
typedef struct etime_struct tETIME
 Event timer structure. More...
 

Functions

BOOL RBS_Init (void)
 Initialize RainbowBS. More...
 
U8 RBS_GetCPUBits (void)
 CPU word-width. More...
 
BOOL RBS_IsCPULittleEndian (void)
 Check if CPU is little-endian. More...
 
BOOL RBS_IsStackGrowDown (void)
 Check if stack grows down. More...
 
void RBS_MemSet8 (U8 *pDes, U8 fill, USIZE num)
 Set memory by byte unit. More...
 
void RBS_MemSet16 (U16 *pDes, U16 fill, USIZE num)
 Set memory by two-bytes unit. More...
 
void RBS_MemSet32 (U32 *pDes, U32 fill, USIZE num)
 Set memory by four-bytes unit. More...
 
void RBS_MemCpy8 (U8 *pDes, const U8 *pSrc, USIZE num)
 Copy memory by byte unit. More...
 
U16 RBS_Read16L (const U8 **ppData)
 Read a 16-bits entity in little-endian. More...
 
U32 RBS_Read32L (const U8 **ppData)
 Read a 32-bits entity in little-endian. More...
 
void RBS_Write16L (U8 **ppData, U16 data)
 Write a 16-bits entity in little-endian. More...
 
void RBS_Write32L (U8 **ppData, U32 data)
 Write a 32-bits entity in little-endian. More...
 
U16 RBS_Read16B (const U8 **ppData)
 Read a 16-bits entity in big-endian. More...
 
U32 RBS_Read32B (const U8 **ppData)
 Read a 32-bits entity in big-endian. More...
 
void RBS_Write16B (U8 **ppData, U16 data)
 Write a 16-bits entity in big-endian. More...
 
void RBS_Write32B (U8 **ppData, U32 data)
 Write a 32-bits entity in big-endian. More...
 
hDMM RBS_DMM_RegisterBlock (char *pName, void *pDM, USIZE size, USIZE block_size, HMUTEX hMutex)
 Register the memory area as a dynamic block memory area. More...
 
hBLOCK RBS_DMM_AllocZeroBlock (hDMM hDmm)
 Allocate a free block with zero initialization from the dynamic block memory area. More...
 
hBLOCK RBS_DMM_AllocBlock (hDMM hDmm)
 Allocate a free block from the dynamic block memory area. More...
 
BOOL RBS_DMM_FreeBlock (hBLOCK hBlock)
 Free the allocated block. More...
 
void * RBS_DMM_UseHBlock (hBLOCK hBlock)
 Get the allocated block pointer. More...
 
BOOL RBS_DMM_UnuseHBlock (hBLOCK hBlock)
 Unuse the allocated block area. More...
 
hDMM RBS_DMM_RegisterPool (char *pName, void *pDM, USIZE size, BOOL bAntiFrag, U16 handle_count, HMUTEX hMutex)
 Register the memory area as a dynamic pool memory area. More...
 
hMEM RBS_DMM_AllocZeroMem (hDMM hDmm, USIZE size)
 Allocate a free memory with zero initialization from the dynamic memory area. More...
 
hMEM RBS_DMM_AllocMem (hDMM hDmm, USIZE size)
 Allocate a free memory from the dynamic memory area. More...
 
hMEM RBS_DMM_ReallocMem (hMEM hMem, USIZE size)
 Reallocate a free memory from the same dynamic memory area. More...
 
BOOL RBS_DMM_FreeMem (hMEM hMem)
 Free the allocated memory. More...
 
void * RBS_DMM_UseHMem (hMEM hMem)
 Get the allocated memory pointer. More...
 
BOOL RBS_DMM_UnuseHMem (hMEM hMem)
 Unuse the allocated memory area. More...
 
USIZE RBS_DMM_GetHMemSize (hMEM hMem)
 Get the allocated memory size. More...
 
system information
const char * RBS_GetVersionString (void)
 Get RainbowBS version string. More...
 
const char * RBS_GetSysInfo (void)
 Get system description string. More...
 
process functions called from device drivers.
BOOL process_poll (tPROCESS *ptProcess)
 Request a process to be polled. More...
 
functions called by the system and boot-up code
U16 process_run (void)
 Run the system once - call poll handlers and process one event. More...
 
BOOL process_is_running (tPROCESS *ptProcess)
 Check if a process is running. More...
 
U16 process_nevents (void)
 Number of events waiting to be processed. More...
 
etimer functions called from application programs
void etimer_set (tETIME *ptEtime, TICK interval)
 Set an event timer. More...
 
void etimer_reset (tETIME *ptEtime)
 Reset an event timer with the same interval as was previously set. More...
 
void etimer_restart (tETIME *ptEtime)
 Restart an event timer from the current point in time. More...
 
void etimer_adjust (tETIME *ptEtime, int timediff)
 Adjust the expiration time for an event timer. More...
 
TICK etimer_expiration_time (tETIME *ptEtime)
 Get the expiration time for the event timer. More...
 
TICK etimer_start_time (tETIME *ptEtime)
 Get the start time for the event timer. More...
 
BOOL etimer_expired (tETIME *ptEtime)
 Check if an event timer has expired. More...
 
void etimer_stop (tETIME *ptEtime)
 Stop a pending event timer. More...
 
etimer functions called from timer interrupts,by the system
void etimer_request_poll (void)
 Make the event timer aware that the clock has changed. More...
 
BOOL etimer_pending (void)
 Check if there are any non-expired event timers. More...
 

time releated

#define RBS_TICK_MS   (1000u/RBS_CFG_TICK_RATE)
 
TICK RBS_GetTickCount (void)
 Get system tick. More...
 
U64 RBS_GetRunTime (void)
 Get system running time(ms). More...
 
void RBS_GetLocalTime (tTime *ptTime)
 Get system local time. More...
 
void RBS_Delay (U32 milliseconds)
 Delay some milliseconds. More...
 

convert digit to string

enum  ePOW { SHEX, SBINARY, SDECIMAL }
 Specific hex,binary or decimal. More...
 
U8 RBS_Number2String (U32 value, ePOW ePow, U8 length, char *pText)
 Convert unsigned digit to ASCII string. More...
 

trigonometric releted

#define ANG_45DEG   1024
 
#define ANG_90DEG   (2*ANG_45DEG)
 
#define ANG_135DEG   (3*ANG_45DEG)
 
#define ANG_180DEG   (4*ANG_45DEG)
 
#define ANG_225DEG   (5*ANG_45DEG)
 
#define ANG_270DEG   (6*ANG_45DEG)
 
#define ANG_315DEG   (7*ANG_45DEG)
 
#define ANG_360DEG   (8*ANG_45DEG)
 
int RBS_sin (int angle)
 Calculate sine. More...
 
int RBS_cos (int angle)
 Calculate cosine. More...
 
int RBS_tan (int angle)
 Calculate tangent. More...
 
int RBS_ctan (int angle)
 Calculate cotangent. More...
 

process functions called from application programs

#define PROCESS_CURRENT()   process_current
 Get a pointer to the currently running process. More...
 
#define PROCESS_CONTEXT_BEGIN(ptProcess)   { tPROCESS *tmp_current = PROCESS_CURRENT();process_current = ptProcess
 Switch context to another process. More...
 
#define PROCESS_CONTEXT_END(ptProcess)   process_current = tmp_current; }
 End a context switch. More...
 
tPROCESSprocess_current
 
BOOL process_start (tPROCESS *ptProcess, process_data_t arg)
 Start a process. More...
 
BOOL process_post (tPROCESS *ptProcess, process_event_t ev, void *data)
 Post an asynchronous event to one or all processes. More...
 
void process_send (tPROCESS *ptProcess, process_event_t ev, void *data)
 Send a synchronous event to a process. More...
 
void process_exit (tPROCESS *ptProcess)
 Cause a process to exit. More...
 
process_event_t process_alloc_event (void)
 Allocate a global event number. More...
 

Detailed Description

Generated by   doxygen 1.8.9.1