dev_common_freertos.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2021 VERISILICON
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (C) 2014 - 2021 VERISILICON
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program; if not, write to the Free Software Foundation,
  43. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  44. *
  45. *****************************************************************************
  46. *
  47. * Note: This software is released under dual MIT and GPL licenses. A
  48. * recipient may use this file under the terms of either the MIT license or
  49. * GPL License. If you wish to use only one license not the other, you can
  50. * indicate your decision by deleting one of the above license notices in your
  51. * version of this file.
  52. *
  53. *****************************************************************************/
  54. #ifndef _DEV_COMMON_FREERTOS_H_
  55. #define _DEV_COMMON_FREERTOS_H_
  56. /**********Driver for FreeRTOS based on the method of Linux's calling**********/
  57. #define __u8 u8
  58. #define __i8 i8
  59. #define __u32 u32
  60. #define __i32 i32
  61. #define sema_init(s,v) sem_init(s,0,v)
  62. //PCIE
  63. #define pci_get_device(a,b,c) (void *)0
  64. #define pci_enable_device(a) 0
  65. #define pci_disable_device(a) 0
  66. #define pci_resource_start(a,b) 0
  67. #define pci_resource_len(a,b) 0
  68. /*--------------------------------*/
  69. /* IO */
  70. //#define O_RDONLY (1)
  71. //#define O_WRONLY (1 << 1)
  72. //#define O_RDWR (O_RDONLY | O_WRONLY)
  73. //#define O_SYNC (1 << 2)
  74. #undef MAP_FAILED
  75. #define MAP_FAILED NULL
  76. #undef NULL
  77. #define NULL ((void *)0)
  78. #define getpagesize() (1)
  79. #define ioremap_nocache(addr,size) (addr)
  80. #define iounmap(addr)
  81. #define mmap(va, size, access, flag, fd, pa) DirectMemoryMap(pa, size)
  82. #define munmap(pRegs, size)
  83. #define vmalloc(a) pvPortMalloc(a) //malloc(a);
  84. #define vfree(a) vPortFree(a) //free(a);
  85. #define probe(a) Platform_init(a)
  86. #define open(name,flag) freertos_open(name,flag)
  87. #define ioctl(fd,cmd,arg) freertos_ioctl(fd,cmd,arg)
  88. #define close(fd) freertos_close(fd)
  89. #define KERN_INFO
  90. #define KERN_ERR
  91. #define KERN_WARNING
  92. #define KERN_DEBUG
  93. #define printk PDEBUG
  94. #define access_ok(a,b,c) (1)
  95. #define __init
  96. #define __exit
  97. #define msleep(s) osal_usleep(s*1000)
  98. /*
  99. * Let any architecture override either of the following before
  100. * including this file.
  101. */
  102. #ifndef _IOC_SIZEBITS
  103. # define _IOC_SIZEBITS 14
  104. #endif
  105. #ifndef _IOC_DIRBITS
  106. # define _IOC_DIRBITS 2
  107. #endif
  108. #define _IOC_NRBITS 8
  109. #define _IOC_TYPEBITS 8
  110. #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
  111. #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
  112. #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
  113. #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
  114. #define _IOC_NRSHIFT 0
  115. #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
  116. #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
  117. #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
  118. /*
  119. * Direction bits, which any architecture can choose to override
  120. * before including this file.
  121. */
  122. #ifndef _IOC_NONE
  123. # define _IOC_NONE 0U
  124. #endif
  125. #ifndef _IOC_WRITE
  126. # define _IOC_WRITE 1U
  127. #endif
  128. #ifndef _IOC_READ
  129. # define _IOC_READ 2U
  130. #endif
  131. #define _IOC(dir,type,nr,size) \
  132. (((dir) << _IOC_DIRSHIFT) | \
  133. ((type) << _IOC_TYPESHIFT) | \
  134. ((nr) << _IOC_NRSHIFT) | \
  135. ((size) << _IOC_SIZESHIFT))
  136. #define _IOC_TYPECHECK(t) (sizeof(t))
  137. /* used to create numbers */
  138. #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
  139. #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
  140. #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
  141. #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
  142. #define _IOR_BAD(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
  143. #define _IOW_BAD(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
  144. /* used to decode ioctl numbers.. */
  145. #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
  146. #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
  147. #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
  148. #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
  149. /* ...and for the drivers/sound files... */
  150. #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
  151. #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
  152. #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
  153. #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT)
  154. #define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
  155. #define DECLARE_WAIT_QUEUE_HEAD(a)
  156. /* Kernel/User space */
  157. #define copy_from_user(des,src,size) (memcpy(des,src,size),0)
  158. #define copy_to_user(des,src,size) (memcpy(des,src,size),0)
  159. #define raw_copy_from_user(des,src,size) (memcpy(des,src,size),0)
  160. #define raw_copy_to_user(des,src,size) (memcpy(des,src,size),0)
  161. #define __put_user(val,user) (*(user) = (val))
  162. #define __get_user(val,user) ((val) = *user)
  163. /* Interrupt */
  164. /*********************request_irq, disable_irq, enable_irq need to be provided by customer*********************/
  165. #define request_irq(i,isr,flag,name,data) RegisterIRQ(i, isr, flag, name, data)
  166. #define disable_irq(i) IntDisableIRQ(i)
  167. #define enable_irq(i) IntEnableIRQ(i)
  168. #define free_irq(i,data)
  169. #define irqreturn_t void
  170. #define down_interruptible(a) pthread_mutex_lock(a)
  171. #define up(a) pthread_mutex_unlock(a)
  172. #define wait_event_interruptible(a,b) sem_wait(&a)
  173. #define wake_up_interruptible_all(a) sem_post(a)
  174. #define IRQ_RETVAL(a) //(a)
  175. #define IRQ_HANDLED //1
  176. #define IRQ_NONE //0
  177. #define register_chrdev(m,name,op) (0)
  178. #define unregister_chrdev(m,name)
  179. #define IRQF_SHARED 1
  180. #define IRQF_DISABLED 0x00000020
  181. #define request_mem_region(addr,size,name) (1)
  182. #define release_mem_region(addr,size)
  183. #define kill_fasync(queue,sig,flag)
  184. //Timer
  185. //typedef TimerHandle_t struct timer_list; //For FreeRTOS
  186. #define ERR_OS_FAIL (0xffff)
  187. #define ERESTARTSYS ERR_OS_FAIL
  188. #ifdef EFAULT
  189. #undef EFAULT
  190. #endif
  191. #define EFAULT ERR_OS_FAIL
  192. #ifdef ENOTTY
  193. #undef ENOTTY
  194. #endif
  195. #define ENOTTY ERR_OS_FAIL
  196. #ifdef EINVAL
  197. #undef EINVAL
  198. #endif
  199. #define EINVAL ERR_OS_FAIL
  200. #ifdef EBUSY
  201. #undef EBUSY
  202. #endif
  203. #define EBUSY ERR_OS_FAIL
  204. /* kernel sync objects */
  205. /**********the atomic operations need to be provided by customer**********/
  206. //#define atomic_t __attribute__((section("cpu_dram"), aligned(4))) xmp_atomic_int_t//i32
  207. //#define ATOMIC_INIT(a) XMP_ATOMIC_INT_INITIALIZER(a)//a
  208. //#define atomic_inc(a) xmp_atomic_int_increment(a,1)//((*(a))++)
  209. //#define atomic_read(a) xmp_atomic_int_value(a)//(a)
  210. #define atomic_t i32
  211. #define ATOMIC_INIT(a) a
  212. #define atomic_inc(a) ((*(a))++)
  213. #define atomic_read(a) (a)
  214. typedef int sig_atomic_t;
  215. //typedef int sigset_t;
  216. #define sigemptyset(set)
  217. #define sigaddset(set, sig)
  218. #define sigsuspend(set)
  219. #define sigwait(set, signo)
  220. #define spinlock_t pthread_mutex_t
  221. #define spin_lock_init(a) (*a = PTHREAD_MUTEX_INITIALIZER)
  222. #define isr_spin_lock_irqsave(a,b)
  223. #define isr_spin_unlock_irqrestore(a,b)
  224. #define spin_lock_irqsave(a,b) {pthread_mutex_lock(a); \
  225. b = ioread32((void *)SYS_REG_INT_EN) & g_vc8000_int_enable_mask; \
  226. *((volatile uint32_t *)SYS_REG_INT_EN) &= ~(b);}
  227. #define spin_unlock_irqrestore(a,b) {*((volatile uint32_t *)SYS_REG_INT_EN) = \
  228. ioread32((void *)SYS_REG_INT_EN) | (b); \
  229. pthread_mutex_unlock(a); }
  230. #define spin_lock(a) pthread_mutex_lock(a)
  231. #define spin_unlock(a) pthread_mutex_unlock(a)
  232. #define getpid() (int)pthread_self()
  233. #endif /* _DEV_COMMON_FREERTOS_H_ */