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

Subversion Repositories mlite

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

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

powered by: WebSVN 2.1.0

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