fork download
  1. #ifndef __DTYPE_H__
  2. #define __DTYPE_H__
  3.  
  4. #define ACTIVATED 1<<0
  5. #define PERIODIC 1<<1
  6.  
  7. #define OK 0
  8. #define ERROR -1
  9. #define TRUE (1==1)
  10. #define FALSE (0==1)
  11. #define N 0
  12. #define BLOCKHEAD_SIGNATURE 0x0000F00D
  13. #define NAME_MAXLEN 20
  14. #define NULL 0
  15. #define MAX_PRIO 32
  16. #define MAX_TASK_NUM 256
  17. #define TASK_STACK_SIZE 0x1000
  18.  
  19.  
  20. /*general device commands*/
  21. #define DEVICE_SET_RESUME 0x01 //resume device
  22. #define DEVICE_SET_SUSPEND 0x02 //suspend device
  23.  
  24. //flags[0:3]: device mode
  25. //device mode
  26. #define DEVICE_RDONLY 1<<0
  27. #define DEVICE_WRONLY 1<<1
  28. #define DEVICE_RDWR DEVICE_RDONLY | DEVICE_WRONLY
  29. #define DEVICE_STANDALONERDLONLY 1<<2
  30.  
  31. //flags[4:7]:active or suspend
  32. //active or suspend
  33. #define DEVICE_ACTIVATED 1<<4
  34. #define DEVICE_SUSPENDED 1<<5
  35.  
  36.  
  37. //flags[8:11]:Tx and Rx flag
  38. //TX_RX mode
  39. #define DEVICE_RX_INT_MODE 1<<8 //INT mode on Rx
  40. #define DEVICE_RX_DMA_MODE 1<<9 //DMA mode on Rx
  41. #define DEVICE_TX_INT_MODE 1<<10 //INT mode on Tx
  42. #define DEVICE_TX_DMA_MODE 1<<11 //DMA mode on Tx
  43.  
  44. //flags[12:15]:device Open flag
  45. //OPEN flag
  46. #define DEVICE_OFLAG_RDONLY 1<<12
  47. #define DEVICE_OFLAG_WRONLY 1<<13
  48. #define DEVICE_OFLAG_RDWR DEVICE_OFLAG_RDONLY | DEVICE_OFLAG_WRONLY
  49. #define DEVICE_OFLAG_CLOSE 1<<14
  50. #define DEVICE_OFLAG_OPEN 1<<15
  51.  
  52.  
  53. typedef unsigned int u32int;
  54. typedef int s32int;
  55. typedef unsigned short u16int;
  56. typedef short s16int;
  57. typedef unsigned char u8int;
  58. typedef char s8int;
  59. //typedef void device_t;
  60.  
  61.  
  62.  
  63.  
  64. /**********************************************************
  65. for node&list structures
  66. ***********************************************************/
  67. struct node{
  68. struct node *next;
  69. struct node *prev;
  70. };
  71. typedef struct node node_t;
  72.  
  73. struct list{
  74. node_t head;
  75. node_t tail;
  76. };
  77. typedef struct list list_t;
  78.  
  79.  
  80.  
  81. //I/O device structure
  82. typedef enum {
  83. Char_Device = 0, //character device
  84. Block_Device, //block device
  85. NetIf_Device, //net interface
  86. Sound_Device, //Sound device
  87. Unknown_Device //unkenown device
  88. } device_type;
  89.  
  90.  
  91. /*********************************************************
  92. for device
  93. *********************************************************/
  94. struct device{
  95. node_t node; //the node of timer list
  96. char name[NAME_MAXLEN];
  97. device_type type;
  98.  
  99. //4bits: oflag, 4bits:TX_RX_flag, 4bits: active or suspend, 4bits: mode
  100. u16int flags;
  101.  
  102.  
  103.  
  104.  
  105.  
  106. //device interface
  107. s8int (*init)(device_t* dev);
  108. s8int (*close)(device_t* dev);
  109. s8int (*open) (device_t* dev, u16int oflag);
  110. u32int (*read) (device_t* dev, u32int pos, u32int size, void* buffer);
  111. u32int (*write) (device_t* dev, u32int pos, u32int size, const void* buffer);
  112. s8int (*ctrl) (device_t* dev, u8int cmd, void *args);
  113.  
  114. //device callback
  115. s8int (*rx)(device_t* dev, u32int size);
  116. s8int (*tx)(device_t* dev, void* buffer);
  117.  
  118. };
  119. typedef struct device device_t;
  120.  
  121.  
  122.  
  123.  
  124. /**********************************************************
  125. task definition
  126. **********************************************************/
  127. /*state of task*/
  128. typedef enum{
  129. READY=0,
  130. RUNNING,
  131. BLOCK,
  132. CLOSE
  133. } TASK_STATE;
  134.  
  135. /**********************************************************
  136. for Timer Structure
  137. ***********************************************************/
  138. struct timer{
  139. node_t node;
  140. char name[NAME_MAXLEN];
  141. u8int flag; /* 0 bit:actived, 1 bit:type*/
  142. void (*timeout_func)(void* parameter);
  143. void *parameter;
  144. u32int init_tick; /*timer timeout tick.*/
  145. u32int timeout_tick; /*timeout tick.*/
  146. };
  147. typedef struct timer timer_t;
  148.  
  149.  
  150. /*structure of task*/
  151. struct task {
  152. node_t node;
  153.  
  154. /*stack point and entry*/
  155. void* sp;
  156. void* entry;
  157. void* parameter;
  158. void* stack_addr;
  159. u16int stack_size;
  160.  
  161. u8int priority;
  162.  
  163. u32int init_tick;
  164. u32int remaining_tick;
  165.  
  166. u32int task_id;
  167. TASK_STATE state;
  168. char name[NAME_MAXLEN];
  169.  
  170. timer_t* timer;
  171. };
  172. typedef struct task task_t;
  173.  
  174. typedef enum{
  175. WAITING_NO = 0,
  176. WAITING,
  177. WAITING_FOREVER
  178. } SEM_WAITING_TYPE;
  179.  
  180. typedef enum{
  181. FIFO = 0,
  182. PRIO
  183. } SEM_FLAG_TYPE;
  184.  
  185. /**********************************************************
  186. for mailbox
  187. ***********************************************************/
  188. struct mailbox {
  189. char name[NAME_MAXLEN];
  190. u32int *msg_pool;
  191. SEM_FLAG_TYPE flag;
  192. u16int size;
  193. u16int entry;
  194. u16int input_offset;
  195. u16int output_offset;
  196. list_t waiting_list;
  197. };
  198. typedef struct mailbox mailbox_t;
  199.  
  200. /*********************************************************
  201. for semaphore
  202. **********************************************************/
  203. /*
  204.  * semaphore
  205.  *
  206.  */
  207. struct semaphore{
  208. char name[NAME_MAXLEN];
  209. u16int value;
  210. SEM_FLAG_TYPE flag;
  211. list_t waiting_list;
  212. };
  213. typedef struct semaphore sem_t;
  214.  
  215.  
  216. /**********************************************************
  217. for schedule
  218. ***********************************************************/
  219. typedef enum{
  220. SCHED_TIME_EXPIRE=0,
  221. SCHED_TASK_REQUEST
  222. } SCHED_TYPE;
  223.  
  224.  
  225.  
  226. typedef enum{
  227. SET_TIME=0,
  228. GET_TIME,
  229. SET_ONESHOT,
  230. SET_PERIODIC
  231. } TIMER_CMD_TYPE;
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. /**********************************************************
  239. for Memory Block Structure
  240. ***********************************************************/
  241. typedef struct blockHead{
  242. u32int signature;
  243. u8int allocated;
  244. u32int size;
  245. struct blockHead *next;
  246. struct blockHead *prev;
  247. }blockHead_t;
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. /**********************************************************
  255. for descript table
  256. ***********************************************************/
  257. // This structure contains the value of one GDT entry.
  258. // We use the attribute 'packed' to tell GCC not to change
  259. // any of the alignment in the structure.
  260. struct gdt_entry_struct
  261. {
  262. u16int limit_low; // The lower 16 bits of the limit.
  263. u16int base_low; // The lower 16 bits of the base.
  264. u8int base_middle; // The next 8 bits of the base.
  265. u8int access; // Access flags, determine what ring this segment can be used in.
  266. u8int granularity;
  267. u8int base_high; // The last 8 bits of the base.
  268. } __attribute__((packed));
  269.  
  270. typedef struct gdt_entry_struct gdt_entry_t;
  271.  
  272. // This struct describes a GDT pointer. It points to the start of
  273. // our array of GDT entries, and is in the format required by the
  274. // lgdt instruction.
  275. struct gdt_ptr_struct
  276. {
  277. u16int limit; // The upper 16 bits of all selector limits.
  278. u32int base; // The address of the first gdt_entry_t struct.
  279. } __attribute__((packed));
  280.  
  281. typedef struct gdt_ptr_struct gdt_ptr_t;
  282.  
  283. // A struct describing an interrupt gate.
  284. struct idt_entry_struct
  285. {
  286. u16int base_lo; // The lower 16 bits of the address to jump to when this interrupt fires.
  287. u16int sel; // Kernel segment selector.
  288. u8int always0; // This must always be zero.
  289. u8int flags; // More flags. See documentation.
  290. u16int base_hi; // The upper 16 bits of the address to jump to.
  291. } __attribute__((packed));
  292.  
  293. typedef struct idt_entry_struct idt_entry_t;
  294.  
  295. // A struct describing a pointer to an array of interrupt handlers.
  296. // This is in a format suitable for giving to 'lidt'.
  297. struct idt_ptr_struct
  298. {
  299. u16int limit;
  300. u32int base; // The address of the first element in our idt_entry_t array.
  301. } __attribute__((packed));
  302.  
  303. typedef struct idt_ptr_struct idt_ptr_t;
  304.  
  305.  
  306. /************************************************************************************/
  307. /************************************************************************
  308. for regs
  309. ************************************************************************/
  310. /* This defines what the stack looks like after an ISR was running */
  311. struct regs
  312. {
  313. unsigned int gs, fs, es, ds;
  314. unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
  315. unsigned int int_no, err_code;
  316. unsigned int eip, cs, eflags, useresp, ss;
  317. };
  318.  
  319. //;typedef struct registers
  320. //;{
  321. //; unsigned int ds; // Data segment selector
  322. //; unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
  323. //; unsigned int int_no, err_code; // Interrupt number and error code (if applicable)
  324. //; unsigned int eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
  325. //;} __attribute__ ((packed)) registers_t;
  326.  
  327. typedef struct regs registers_t;
  328.  
  329. /************************************************************************************/
  330.  
  331.  
  332.  
  333. #endif
  334.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:107: error: expected ‘)’ before ‘*’ token
prog.c:108: error: expected ‘;’ before ‘s8int’
stdout
Standard output is empty