rtthread_service.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #ifndef _FREERTOS_SERVICE_H_
  2. #define _FREERTOS_SERVICE_H_
  3. //----- ------------------------------------------------------------------
  4. // Include Files
  5. //----- ------------------------------------------------------------------
  6. //#include "wireless.h"
  7. #include "dlist.h"
  8. // --------------------------------------------
  9. // Platform dependent include file
  10. // --------------------------------------------
  11. #if defined(CONFIG_PLATFORM_8195A)
  12. #include "platform/platform_stdlib.h"
  13. extern VOID RtlUdelayOS(u32 us);
  14. #elif defined(CONFIG_PLATFORM_8711B)
  15. #include "platform/platform_stdlib.h"
  16. #else
  17. // other MCU may use standard library
  18. #include <string.h>
  19. #endif
  20. #if (defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI) || defined(CONFIG_LX_HCI)
  21. /* For SPI interface transfer and us delay implementation */
  22. #if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
  23. #include <rtwlan_bsp.h>
  24. #endif
  25. #endif
  26. // --------------------------------------------
  27. // Platform dependent type define
  28. // --------------------------------------------
  29. #if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
  30. typedef unsigned char u8;
  31. typedef unsigned short u16;
  32. typedef unsigned int u32;
  33. typedef signed char s8;
  34. typedef signed short s16;
  35. typedef signed int s32;
  36. typedef signed long long s64;
  37. typedef unsigned long long u64;
  38. typedef unsigned int uint;
  39. typedef signed int sint;
  40. #ifndef bool
  41. typedef int bool;
  42. #define true 1
  43. #define false 0
  44. #endif
  45. #define IN
  46. #define OUT
  47. #define VOID void
  48. #define NDIS_OID uint
  49. #define NDIS_STATUS uint
  50. #ifndef PVOID
  51. typedef void * PVOID;
  52. #endif
  53. typedef unsigned int __kernel_size_t;
  54. typedef int __kernel_ssize_t;
  55. typedef __kernel_size_t SIZE_T;
  56. typedef __kernel_ssize_t SSIZE_T;
  57. #endif //CONFIG_PLATFORM_8195A
  58. #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
  59. // os types
  60. typedef char osdepCHAR;
  61. typedef float osdepFLOAT;
  62. typedef double osdepDOUBLE;
  63. typedef long osdepLONG;
  64. typedef short osdepSHORT;
  65. typedef unsigned long osdepSTACK_TYPE;
  66. typedef long osdepBASE_TYPE;
  67. typedef unsigned long osdepTickType;
  68. typedef void* _timerHandle;
  69. typedef void* _sema;
  70. typedef void* _mutex;
  71. typedef void* _lock;
  72. typedef void* _queueHandle;
  73. typedef void* _xqueue;
  74. typedef struct timer_list _timer;
  75. typedef struct sk_buff _pkt;
  76. typedef unsigned char _buffer;
  77. #ifndef __LIST_H
  78. #warning "DLIST_NOT_DEFINE!!!!!!"
  79. struct list_head {
  80. struct list_head *next, *prev;
  81. };
  82. #endif
  83. struct __queue {
  84. struct list_head queue;
  85. _lock lock;
  86. };
  87. typedef struct __queue _queue;
  88. typedef struct list_head _list;
  89. typedef unsigned long _irqL;
  90. typedef void* _thread_hdl_;
  91. typedef void thread_return;
  92. typedef void* thread_context;
  93. #define ATOMIC_T atomic_t
  94. #define HZ configTICK_RATE_HZ
  95. #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
  96. /* emulate a modern version */
  97. #define LINUX_VERSION_CODE KERNEL_VERSION(2, 6, 17)
  98. static __inline _list *get_next(_list *list)
  99. {
  100. return list->next;
  101. }
  102. static __inline _list *get_list_head(_queue *queue)
  103. {
  104. return (&(queue->queue));
  105. }
  106. #define LIST_CONTAINOR(ptr, type, member) \
  107. ((type *)((char *)(ptr)-(SIZE_T)((char *)&((type *)ptr)->member - (char *)ptr)))
  108. //#define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
  109. #define container_of(ptr, type, member) \
  110. ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
  111. #define TASK_PRORITY_LOW 1
  112. #define TASK_PRORITY_MIDDLE 2
  113. #define TASK_PRORITY_HIGH 3
  114. #define TASK_PRORITY_SUPER 4
  115. #define TIMER_MAX_DELAY 0xFFFFFFFF
  116. void save_and_cli(void);
  117. void restore_flags(void);
  118. void cli(void);
  119. #ifndef mdelay
  120. #define mdelay(t) ((t/portTICK_RATE_MS)>0)?(vTaskDelay(t/portTICK_RATE_MS)):(vTaskDelay(1))
  121. #endif
  122. #ifndef udelay
  123. #define udelay(t) ((t/(portTICK_RATE_MS*1000))>0)?vTaskDelay(t/(portTICK_RATE_MS*1000)):(vTaskDelay(1))
  124. #endif
  125. //----- ------------------------------------------------------------------
  126. // Common Definition
  127. //----- ------------------------------------------------------------------
  128. #define __init
  129. #define __exit
  130. #define __devinit
  131. #define __devexit
  132. #define KERN_ERR
  133. #define KERN_INFO
  134. #define KERN_NOTICE
  135. #undef GFP_KERNEL
  136. #define GFP_KERNEL 1
  137. #define GFP_ATOMIC 1
  138. #define SET_MODULE_OWNER(some_struct) do { } while (0)
  139. #define SET_NETDEV_DEV(dev, obj) do { } while (0)
  140. #define register_netdev(dev) (0)
  141. #define unregister_netdev(dev) do { } while (0)
  142. #define netif_queue_stopped(dev) (0)
  143. #define netif_wake_queue(dev) do { } while (0)
  144. #define printk printf
  145. #define DBG_ERR(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args)
  146. #if WLAN_INTF_DBG
  147. #define DBG_TRACE(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args)
  148. #define DBG_INFO(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args)
  149. #else
  150. #define DBG_TRACE(fmt, args...)
  151. #define DBG_INFO(fmt, args...)
  152. #endif
  153. #define HALT() do { cli(); for(;;);} while(0)
  154. #undef ASSERT
  155. #define ASSERT(x) do { \
  156. if((x) == 0) \
  157. printf("\n\rAssert(" #x ") failed on line %d in file %s", __LINE__, __FILE__); \
  158. HALT(); \
  159. } while(0)
  160. #undef DBG_ASSERT
  161. #define DBG_ASSERT(x, msg) do { \
  162. if((x) == 0) \
  163. printf("\n\r%s, Assert(" #x ") failed on line %d in file %s", msg, __LINE__, __FILE__); \
  164. } while(0)
  165. //----- ------------------------------------------------------------------
  166. // Atomic Operation
  167. //----- ------------------------------------------------------------------
  168. #if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) // for 8195A, it is defined in ..system../basic_types.h
  169. typedef struct { volatile int counter; } atomic_t;
  170. #endif
  171. /*
  172. * atomic_read - read atomic variable
  173. * @v: pointer of type atomic_t
  174. *
  175. * Atomically reads the value of @v. Note that the guaranteed
  176. * useful range of an atomic_t is only 24 bits.
  177. */
  178. #undef atomic_read
  179. #define atomic_read(v) ((v)->counter)
  180. /*
  181. * atomic_set - set atomic variable
  182. * @v: pointer of type atomic_t
  183. * @i: required value
  184. *
  185. * Atomically sets the value of @v to @i. Note that the guaranteed
  186. * useful range of an atomic_t is only 24 bits.
  187. */
  188. #undef atomic_set
  189. #define atomic_set(v,i) ((v)->counter = (i))
  190. /*
  191. * These inlines deal with timer wrapping correctly. You are
  192. * strongly encouraged to use them
  193. * 1. Because people otherwise forget
  194. * 2. Because if the timer wrap changes in future you wont have to
  195. * alter your driver code.
  196. *
  197. * time_after(a,b) returns true if the time a is after time b.
  198. *
  199. * Do this with "<0" and ">=0" to only test the sign of the result. A
  200. * good compiler would generate better code (and a really good compiler
  201. * wouldn't care). Gcc is currently neither.
  202. */
  203. #define time_after(a,b) ((long)(b) - (long)(a) < 0)
  204. #define time_before(a,b) time_after(b,a)
  205. #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
  206. #define time_before_eq(a,b) time_after_eq(b,a)
  207. extern void rtw_init_listhead(_list *list);
  208. extern u32 rtw_is_list_empty(_list *phead);
  209. extern void rtw_list_insert_head(_list *plist, _list *phead);
  210. extern void rtw_list_insert_tail(_list *plist, _list *phead);
  211. extern void rtw_list_delete(_list *plist);
  212. #if CONFIG_PLATFORM_8711B
  213. extern u32 random_seed;
  214. #endif
  215. #endif /* _FREERTOS_SERVICE_H_ */