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

Subversion Repositories mlite

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

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
int memcmp(const void *cs, const void *ct, unsigned long bytes);
59
void *memset(void *dst, int c, unsigned long bytes);
60
int abs(int n);
61
int rand(void);
62
void srand(unsigned int seed);
63
long strtol(const char *s, const char **end, int base);
64
int atoi(const char *s);
65
void itoa(char *dst, int num, int base, int width);
66
#ifndef NO_ELLIPSIS
67
int sprintf(char *s, const char *format, ...);
68
int sscanf(char *s, const char *format, ...);
69
#endif
70
 
71
/***************** Assembly **************/
72
#define OS_CriticalBegin() OS_AsmInterruptEnable(0)
73
#define OS_CriticalEnd(S) OS_AsmInterruptEnable(S)
74
typedef uint32 jmp_buf[20];
75
extern uint32 OS_AsmInterruptEnable(uint32 state);
76
extern void OS_AsmInterruptInit(void);
77
extern int setjmp(jmp_buf env);
78
extern void longjmp(jmp_buf env, int val);
79
extern uint32 OS_AsmMult(uint32 a, uint32 b, unsigned long *hi);
80
 
81
/***************** Heap ******************/
82
#define HEAP_SYSTEM  (void*)0
83
#define HEAP_GENERAL (void*)1
84
#define HEAP_SMALL   (void*)2
85
#define HEAP_UI      (void*)3
86
typedef struct OS_Heap_s OS_Heap_t;
87
OS_Heap_t *OS_HeapCreate(const char *Name, void *Memory, uint32 Size);
88
void OS_HeapDestroy(OS_Heap_t *Heap);
89
void *OS_HeapMalloc(OS_Heap_t *Heap, int Bytes);
90
void OS_HeapFree(void *Block);
91
void OS_HeapAlternate(OS_Heap_t *Heap, OS_Heap_t *Alternate);
92
void OS_HeapRegister(void *Index, OS_Heap_t *Heap);
93
 
94
/***************** Thread *****************/
95
#ifdef WIN32
96
#define STACK_SIZE_MINIMUM (1024*4)
97
#else
98
#define STACK_SIZE_MINIMUM (1024*1)
99
#endif
100
#define STACK_SIZE_DEFAULT 1024*2
101
#define THREAD_PRIORITY_IDLE 0
102
#define THREAD_PRIORITY_MAX 255
103
typedef void (*OS_FuncPtr_t)(void *Arg);
104
typedef struct OS_Thread_s OS_Thread_t;
105
OS_Thread_t *OS_ThreadCreate(const char *Name,
106
                             OS_FuncPtr_t FuncPtr,
107
                             void *Arg,
108
                             uint32 Priority,
109
                             uint32 StackSize);
110
void OS_ThreadExit(void);
111
OS_Thread_t *OS_ThreadSelf(void);
112
void OS_ThreadSleep(int Ticks);
113
uint32 OS_ThreadTime(void);
114
void OS_ThreadInfoSet(OS_Thread_t *Thread, void *Info);
115
void *OS_ThreadInfoGet(OS_Thread_t *Thread);
116
uint32 OS_ThreadPriorityGet(OS_Thread_t *Thread);
117
void OS_ThreadPrioritySet(OS_Thread_t *Thread, uint32 Priority);
118
void OS_ThreadTick(void *Arg);
119
 
120
/***************** Semaphore **************/
121
#define OS_SUCCESS 0
122
#define OS_ERROR  -1
123
#define OS_WAIT_FOREVER -1
124
#define OS_NO_WAIT 0
125
typedef struct OS_Semaphore_s OS_Semaphore_t;
126
OS_Semaphore_t *OS_SemaphoreCreate(const char *Name, uint32 Count);
127
void OS_SemaphoreDelete(OS_Semaphore_t *Semaphore);
128
int OS_SemaphorePend(OS_Semaphore_t *Semaphore, int Ticks); //tick ~= 10ms
129
void OS_SemaphorePost(OS_Semaphore_t *Semaphore);
130
 
131
/***************** Mutex ******************/
132
typedef struct OS_Mutex_s OS_Mutex_t;
133
OS_Mutex_t *OS_MutexCreate(const char *Name);
134
void OS_MutexDelete(OS_Mutex_t *Semaphore);
135
void OS_MutexPend(OS_Mutex_t *Semaphore);
136
void OS_MutexPost(OS_Mutex_t *Semaphore);
137
 
138
/***************** MQueue *****************/
139
enum {
140
   MESSAGE_TYPE_USER = 0,
141
   MESSAGE_TYPE_TIMER = 5
142
};
143
typedef struct OS_MQueue_s OS_MQueue_t;
144
OS_MQueue_t *OS_MQueueCreate(const char *Name,
145
                             int MessageCount,
146
                             int MessageBytes);
147
void OS_MQueueDelete(OS_MQueue_t *MQueue);
148
int OS_MQueueSend(OS_MQueue_t *MQueue, void *Message);
149
int OS_MQueueGet(OS_MQueue_t *MQueue, void *Message, int Ticks);
150
 
151
/***************** Timer ******************/
152
typedef struct OS_Timer_s OS_Timer_t;
153
OS_Timer_t *OS_TimerCreate(const char *Name, OS_MQueue_t *MQueue, uint32 Info);
154
void OS_TimerDelete(OS_Timer_t *Timer);
155
void OS_TimerStart(OS_Timer_t *Timer, uint32 Ticks, uint32 TicksRestart);
156
void OS_TimerStop(OS_Timer_t *Timer);
157
 
158
/***************** ISR ********************/
159
void OS_InterruptServiceRoutine(uint32 Status);
160
void OS_InterruptRegister(uint32 Mask, OS_FuncPtr_t FuncPtr);
161
uint32 OS_InterruptStatus(void);
162
uint32 OS_InterruptMaskSet(uint32 Mask);
163
uint32 OS_InterruptMaskClear(uint32 Mask);
164
 
165
/***************** Init ******************/
166
void OS_Init(uint32 *HeapStorage, uint32 Bytes);
167
void OS_Start(void);
168
void OS_Assert(void);
169
void MainThread(void *Arg);
170
 
171
/***************** UART ******************/
172
void UartInit(void);
173
void UartWrite(int C);
174
uint8 UartRead(void);
175
void UartWriteData(uint8 *Data, int Length);
176
void UartReadData(uint8 *Data, int Length);
177
#ifndef NO_ELLIPSIS2
178
void UartPrintf(const char *format, ...);
179
void UartPrintfPoll(const char *format, ...);
180
void UartPrintfCritical(const char *format, ...);
181
void UartScanf(const char *format, ...);
182
#endif
183
int puts(const char *string);
184
int getch(void);
185
int kbhit(void);
186
void LogWrite(int a);
187
void LogDump(void);
188
 
189
/***************** Math ******************/
190
//IEEE single precision floating point math
191
#ifndef WIN32
192
#define FP_Neg     __negsf2
193
#define FP_Add     __addsf3
194
#define FP_Sub     __subsf3
195
#define FP_Mult    __mulsf3
196
#define FP_Div     __divsf3
197
#define FP_ToLong  __fixsfsi
198
#define FP_ToFloat __floatsisf
199
#define sqrt FP_Sqrt
200
#define cos  FP_Cos
201
#define sin  FP_Sin
202
#define atan FP_Atan
203
#define log  FP_Log
204
#define exp  FP_Exp
205
#endif
206
float FP_Neg(float a_fp);
207
float FP_Add(float a_fp, float b_fp);
208
float FP_Sub(float a_fp, float b_fp);
209
float FP_Mult(float a_fp, float b_fp);
210
float FP_Div(float a_fp, float b_fp);
211
long  FP_ToLong(float a_fp);
212
float FP_ToFloat(long af);
213
int   FP_Cmp(float a_fp, float b_fp);
214
float FP_Sqrt(float a);
215
float FP_Cos(float rad);
216
float FP_Sin(float rad);
217
float FP_Atan(float x);
218
float FP_Atan2(float y, float x);
219
float FP_Exp(float x);
220
float FP_Log(float x);
221
float FP_Pow(float x, float y);
222
 
223
#endif //__PLASMA_H__
224
 

powered by: WebSVN 2.1.0

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