OpenCores
URL https://opencores.org/ocsvn/mlite/mlite/trunk

Subversion Repositories mlite

[/] [mlite/] [trunk/] [kernel/] [rtos.h] - Blame information for rev 144

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 138 rhoads
/*--------------------------------------------------------------------
2
 * TITLE: Plasma Real Time Operating System
3
 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
 * DATE CREATED: 12/17/05
5
 * FILENAME: rtos.h
6
 * PROJECT: Plasma CPU core
7
 * COPYRIGHT: Software placed into the public domain by the author.
8
 *    Software 'as is' without warranty.  Author liable for nothing.
9
 * DESCRIPTION:
10
 *    Plasma Real Time Operating System
11
 *--------------------------------------------------------------------*/
12
#ifndef __RTOS_H__
13
#define __RTOS_H__
14
 
15
//#define printf     UartPrintf
16
#define printf     UartPrintfPoll
17
#define scanf      UartScanf
18
 
19
// Typedefs
20
typedef unsigned int   uint32;
21
typedef unsigned short uint16;
22
typedef unsigned char  uint8;
23
 
24
// Memory Access
25
#ifdef WIN32
26
uint32 MemoryRead(uint32 Address);
27
void MemoryWrite(uint32 Address, uint32 Value);
28
#else
29
#define MemoryRead(A) (*(volatile uint32*)(A))
30
#define MemoryWrite(A,V) *(volatile uint32*)(A)=(V)
31
#endif
32
 
33
/***************** LibC ******************/
34
#ifndef NULL
35
#define NULL (void*)0
36
#endif
37
 
38
#define assert(A) if((A)==0){OS_Assert();UartPrintfCritical("\r\nAssert %s:%d\r\n", __FILE__, __LINE__);}
39
 
40
#define isprint(c) (' '<=(c)&&(c)<='~')
41
#define isspace(c) ((c)==' '||(c)=='\t'||(c)=='\n'||(c)=='\r')
42
#define isdigit(c) ('0'<=(c)&&(c)<='9')
43
#define islower(c) ('a'<=(c)&&(c)<='z')
44
#define isupper(c) ('A'<=(c)&&(c)<='Z')
45
#define isalpha(c) (islower(c)||isupper(c))
46
#define isalnum(c) (isalpha(c)||isdigit(c))
47
#define min(a,b)   ((a)<(b)?(a):(b))
48
 
49
char *strcpy(char *dst, const char *src);
50
char *strncpy(char *dst, const char *src, int count);
51
char *strcat(char *dst, const char *src);
52
char *strncat(char *dst, const char *src, int count);
53
int strcmp(const char *string1, const char *string2);
54
int strncmp(const char *string1, const char *string2, int count);
55
char *strstr(char *string, char *find);
56
int strlen(const char *string);
57
void *memcpy(void *dst, const void *src, unsigned long bytes);
58 144 rhoads
void *memmove(void *dst, const void *src, unsigned long bytes);
59 138 rhoads
int memcmp(const void *cs, const void *ct, unsigned long bytes);
60
void *memset(void *dst, int c, unsigned long bytes);
61
int abs(int n);
62 144 rhoads
unsigned int rand(void);
63 138 rhoads
void srand(unsigned int seed);
64
long strtol(const char *s, const char **end, int base);
65
int atoi(const char *s);
66
void itoa(char *dst, int num, int base, int width);
67
#ifndef NO_ELLIPSIS
68
int sprintf(char *s, const char *format, ...);
69
int sscanf(char *s, const char *format, ...);
70
#endif
71
 
72
/***************** Assembly **************/
73
#define OS_CriticalBegin() OS_AsmInterruptEnable(0)
74
#define OS_CriticalEnd(S) OS_AsmInterruptEnable(S)
75
typedef uint32 jmp_buf[20];
76
extern uint32 OS_AsmInterruptEnable(uint32 state);
77
extern void OS_AsmInterruptInit(void);
78
extern int setjmp(jmp_buf env);
79
extern void longjmp(jmp_buf env, int val);
80
extern uint32 OS_AsmMult(uint32 a, uint32 b, unsigned long *hi);
81
 
82
/***************** Heap ******************/
83
#define HEAP_SYSTEM  (void*)0
84
#define HEAP_GENERAL (void*)1
85
#define HEAP_SMALL   (void*)2
86
#define HEAP_UI      (void*)3
87
typedef struct OS_Heap_s OS_Heap_t;
88
OS_Heap_t *OS_HeapCreate(const char *Name, void *Memory, uint32 Size);
89
void OS_HeapDestroy(OS_Heap_t *Heap);
90
void *OS_HeapMalloc(OS_Heap_t *Heap, int Bytes);
91
void OS_HeapFree(void *Block);
92
void OS_HeapAlternate(OS_Heap_t *Heap, OS_Heap_t *Alternate);
93
void OS_HeapRegister(void *Index, OS_Heap_t *Heap);
94
 
95
/***************** Thread *****************/
96
#ifdef WIN32
97
#define STACK_SIZE_MINIMUM (1024*4)
98
#else
99
#define STACK_SIZE_MINIMUM (1024*1)
100
#endif
101
#define STACK_SIZE_DEFAULT 1024*2
102
#define THREAD_PRIORITY_IDLE 0
103
#define THREAD_PRIORITY_MAX 255
104
typedef void (*OS_FuncPtr_t)(void *Arg);
105
typedef struct OS_Thread_s OS_Thread_t;
106
OS_Thread_t *OS_ThreadCreate(const char *Name,
107
                             OS_FuncPtr_t FuncPtr,
108
                             void *Arg,
109
                             uint32 Priority,
110
                             uint32 StackSize);
111
void OS_ThreadExit(void);
112
OS_Thread_t *OS_ThreadSelf(void);
113
void OS_ThreadSleep(int Ticks);
114
uint32 OS_ThreadTime(void);
115
void OS_ThreadInfoSet(OS_Thread_t *Thread, void *Info);
116
void *OS_ThreadInfoGet(OS_Thread_t *Thread);
117
uint32 OS_ThreadPriorityGet(OS_Thread_t *Thread);
118
void OS_ThreadPrioritySet(OS_Thread_t *Thread, uint32 Priority);
119
void OS_ThreadTick(void *Arg);
120
 
121
/***************** Semaphore **************/
122
#define OS_SUCCESS 0
123
#define OS_ERROR  -1
124
#define OS_WAIT_FOREVER -1
125
#define OS_NO_WAIT 0
126
typedef struct OS_Semaphore_s OS_Semaphore_t;
127
OS_Semaphore_t *OS_SemaphoreCreate(const char *Name, uint32 Count);
128
void OS_SemaphoreDelete(OS_Semaphore_t *Semaphore);
129
int OS_SemaphorePend(OS_Semaphore_t *Semaphore, int Ticks); //tick ~= 10ms
130
void OS_SemaphorePost(OS_Semaphore_t *Semaphore);
131
 
132
/***************** Mutex ******************/
133
typedef struct OS_Mutex_s OS_Mutex_t;
134
OS_Mutex_t *OS_MutexCreate(const char *Name);
135
void OS_MutexDelete(OS_Mutex_t *Semaphore);
136
void OS_MutexPend(OS_Mutex_t *Semaphore);
137
void OS_MutexPost(OS_Mutex_t *Semaphore);
138
 
139
/***************** MQueue *****************/
140
enum {
141
   MESSAGE_TYPE_USER = 0,
142
   MESSAGE_TYPE_TIMER = 5
143
};
144
typedef struct OS_MQueue_s OS_MQueue_t;
145
OS_MQueue_t *OS_MQueueCreate(const char *Name,
146
                             int MessageCount,
147
                             int MessageBytes);
148
void OS_MQueueDelete(OS_MQueue_t *MQueue);
149
int OS_MQueueSend(OS_MQueue_t *MQueue, void *Message);
150
int OS_MQueueGet(OS_MQueue_t *MQueue, void *Message, int Ticks);
151
 
152
/***************** Timer ******************/
153
typedef struct OS_Timer_s OS_Timer_t;
154
OS_Timer_t *OS_TimerCreate(const char *Name, OS_MQueue_t *MQueue, uint32 Info);
155
void OS_TimerDelete(OS_Timer_t *Timer);
156
void OS_TimerStart(OS_Timer_t *Timer, uint32 Ticks, uint32 TicksRestart);
157
void OS_TimerStop(OS_Timer_t *Timer);
158
 
159
/***************** ISR ********************/
160
void OS_InterruptServiceRoutine(uint32 Status);
161
void OS_InterruptRegister(uint32 Mask, OS_FuncPtr_t FuncPtr);
162
uint32 OS_InterruptStatus(void);
163
uint32 OS_InterruptMaskSet(uint32 Mask);
164
uint32 OS_InterruptMaskClear(uint32 Mask);
165
 
166
/***************** Init ******************/
167
void OS_Init(uint32 *HeapStorage, uint32 Bytes);
168
void OS_Start(void);
169
void OS_Assert(void);
170
void MainThread(void *Arg);
171
 
172
/***************** UART ******************/
173
void UartInit(void);
174
void UartWrite(int C);
175
uint8 UartRead(void);
176
void UartWriteData(uint8 *Data, int Length);
177
void UartReadData(uint8 *Data, int Length);
178
#ifndef NO_ELLIPSIS2
179
void UartPrintf(const char *format, ...);
180
void UartPrintfPoll(const char *format, ...);
181
void UartPrintfCritical(const char *format, ...);
182
void UartScanf(const char *format, ...);
183
#endif
184
int puts(const char *string);
185
int getch(void);
186
int kbhit(void);
187
void LogWrite(int a);
188
void LogDump(void);
189
 
190
/***************** Math ******************/
191
//IEEE single precision floating point math
192
#ifndef WIN32
193
#define FP_Neg     __negsf2
194
#define FP_Add     __addsf3
195
#define FP_Sub     __subsf3
196
#define FP_Mult    __mulsf3
197
#define FP_Div     __divsf3
198
#define FP_ToLong  __fixsfsi
199
#define FP_ToFloat __floatsisf
200
#define sqrt FP_Sqrt
201
#define cos  FP_Cos
202
#define sin  FP_Sin
203
#define atan FP_Atan
204
#define log  FP_Log
205
#define exp  FP_Exp
206
#endif
207
float FP_Neg(float a_fp);
208
float FP_Add(float a_fp, float b_fp);
209
float FP_Sub(float a_fp, float b_fp);
210
float FP_Mult(float a_fp, float b_fp);
211
float FP_Div(float a_fp, float b_fp);
212
long  FP_ToLong(float a_fp);
213
float FP_ToFloat(long af);
214
int   FP_Cmp(float a_fp, float b_fp);
215
float FP_Sqrt(float a);
216
float FP_Cos(float rad);
217
float FP_Sin(float rad);
218
float FP_Atan(float x);
219
float FP_Atan2(float y, float x);
220
float FP_Exp(float x);
221
float FP_Log(float x);
222
float FP_Pow(float x, float y);
223
 
224
#endif //__PLASMA_H__
225
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.