drv_api.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef CYGONCE_HAL_DRV_API_H
  2. #define CYGONCE_HAL_DRV_API_H
  3. /*==========================================================================
  4. //
  5. // drv_api.h
  6. //
  7. // Native API for Kernel
  8. //
  9. //==========================================================================
  10. // ####ECOSGPLCOPYRIGHTBEGIN####
  11. // -------------------------------------------
  12. // This file is part of eCos, the Embedded Configurable Operating System.
  13. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
  14. //
  15. // eCos is free software; you can redistribute it and/or modify it under
  16. // the terms of the GNU General Public License as published by the Free
  17. // Software Foundation; either version 2 or (at your option) any later
  18. // version.
  19. //
  20. // eCos is distributed in the hope that it will be useful, but WITHOUT
  21. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  22. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  23. // for more details.
  24. //
  25. // You should have received a copy of the GNU General Public License
  26. // along with eCos; if not, write to the Free Software Foundation, Inc.,
  27. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  28. //
  29. // As a special exception, if other files instantiate templates or use
  30. // macros or inline functions from this file, or you compile this file
  31. // and link it with other works to produce a work based on this file,
  32. // this file does not by itself cause the resulting work to be covered by
  33. // the GNU General Public License. However the source code for this file
  34. // must still be made available in accordance with section (3) of the GNU
  35. // General Public License v2.
  36. //
  37. // This exception does not invalidate any other reasons why a work based
  38. // on this file might be covered by the GNU General Public License.
  39. // -------------------------------------------
  40. // ####ECOSGPLCOPYRIGHTEND####
  41. //==========================================================================
  42. //#####DESCRIPTIONBEGIN####
  43. //
  44. // Author(s): nickg
  45. // Date: 1999-02-24
  46. // Purpose: Driver API
  47. // Description: This file defines the API used by device drivers to access
  48. // system services. When the kernel is present it maps directly
  49. // to the Kernel C API. When the kernel is absent, it is provided
  50. // by a set of HAL functions.
  51. //
  52. // Usage: #include <cyg/kernel/kapi.h>
  53. //
  54. //####DESCRIPTIONEND####
  55. //
  56. //========================================================================*/
  57. //#include <pkgconf/hal.h> //mod by prife
  58. #include <cyg/infra/cyg_type.h>
  59. #ifdef CYGPKG_KERNEL
  60. /*------------------------------------------------------------------------*/
  61. /* Kernel co-resident version of API */
  62. #include <pkgconf/kernel.h>
  63. #ifndef CYGFUN_KERNEL_API_C
  64. #error Driver API requres Kernel API to be present
  65. #endif
  66. #include <cyg/kernel/kapi.h>
  67. #define cyg_drv_isr_lock cyg_interrupt_disable
  68. #define cyg_drv_isr_unlock cyg_interrupt_enable
  69. #define cyg_drv_dsr_lock cyg_scheduler_lock
  70. #define cyg_drv_dsr_unlock cyg_scheduler_unlock
  71. #define cyg_drv_mutex_t cyg_mutex_t
  72. #define cyg_drv_mutex_init cyg_mutex_init
  73. #define cyg_drv_mutex_destroy cyg_mutex_destroy
  74. #define cyg_drv_mutex_lock cyg_mutex_lock
  75. #define cyg_drv_mutex_trylock cyg_mutex_trylock
  76. #define cyg_drv_mutex_unlock cyg_mutex_unlock
  77. #define cyg_drv_mutex_release cyg_mutex_release
  78. #define cyg_drv_cond_t cyg_cond_t
  79. #define cyg_drv_cond_init cyg_cond_init
  80. #define cyg_drv_cond_destroy cyg_cond_destroy
  81. #define cyg_drv_cond_wait cyg_cond_wait
  82. #define cyg_drv_cond_signal cyg_cond_signal
  83. #define cyg_drv_cond_broadcast cyg_cond_broadcast
  84. #define cyg_drv_interrupt_create cyg_interrupt_create
  85. #define cyg_drv_interrupt_delete cyg_interrupt_delete
  86. #define cyg_drv_interrupt_attach cyg_interrupt_attach
  87. #define cyg_drv_interrupt_detach cyg_interrupt_detach
  88. #define cyg_drv_interrupt_mask cyg_interrupt_mask
  89. #define cyg_drv_interrupt_unmask cyg_interrupt_unmask
  90. #define cyg_drv_interrupt_mask_intunsafe cyg_interrupt_mask_intunsafe
  91. #define cyg_drv_interrupt_unmask_intunsafe cyg_interrupt_unmask_intunsafe
  92. #define cyg_drv_interrupt_acknowledge cyg_interrupt_acknowledge
  93. #define cyg_drv_interrupt_configure cyg_interrupt_configure
  94. #define cyg_drv_interrupt_level cyg_interrupt_level
  95. #define cyg_drv_interrupt_set_cpu cyg_interrupt_set_cpu
  96. #define cyg_drv_interrupt_get_cpu cyg_interrupt_get_cpu
  97. #define cyg_drv_spinlock_t cyg_spinlock_t
  98. #define cyg_drv_spinlock_init cyg_spinlock_init
  99. #define cyg_drv_spinlock_spin cyg_spinlock_spin
  100. #define cyg_drv_spinlock_clear cyg_spinlock_clear
  101. #define cyg_drv_spinlock_try cyg_spinlock_try
  102. #define cyg_drv_spinlock_test cyg_spinlock_test
  103. #define cyg_drv_spinlock_spin_intsave cyg_spinlock_spin_intsave
  104. #define cyg_drv_spinlock_clear_intsave cyg_spinlock_clear_intsave
  105. #else /* CYGPKG_KERNEL */
  106. /*------------------------------------------------------------------------*/
  107. /* Non-kernel version of API */
  108. typedef CYG_ADDRWORD cyg_addrword_t; /* May hold pointer or word */
  109. typedef cyg_addrword_t cyg_handle_t; /* Object handle */
  110. typedef cyg_uint32 cyg_priority_t; /* type for priorities */
  111. typedef cyg_uint32 cyg_vector_t; /* Interrupt vector id */
  112. typedef cyg_uint32 cyg_cpu_t; /* CPU id */
  113. typedef int cyg_bool_t;
  114. typedef cyg_int32 cyg_code_t; /* type for various codes */
  115. typedef cyg_uint32 cyg_ISR_t( cyg_vector_t vector, cyg_addrword_t data);
  116. typedef void cyg_DSR_t(cyg_vector_t vector,
  117. cyg_ucount32 count,
  118. cyg_addrword_t data);
  119. externC void cyg_drv_isr_lock(void);
  120. externC void cyg_drv_isr_unlock(void);
  121. externC void cyg_drv_dsr_lock(void);
  122. externC void cyg_drv_dsr_unlock(void);
  123. typedef struct
  124. {
  125. cyg_atomic lock;
  126. } cyg_drv_mutex_t;
  127. externC void cyg_drv_mutex_init( cyg_drv_mutex_t *mutex );
  128. externC void cyg_drv_mutex_destroy( cyg_drv_mutex_t *mutex );
  129. externC cyg_bool_t cyg_drv_mutex_lock( cyg_drv_mutex_t *mutex );
  130. externC cyg_bool_t cyg_drv_mutex_trylock( cyg_drv_mutex_t *mutex );
  131. externC void cyg_drv_mutex_unlock( cyg_drv_mutex_t *mutex );
  132. externC void cyg_drv_mutex_release( cyg_drv_mutex_t *mutex );
  133. typedef struct
  134. {
  135. cyg_atomic wait;
  136. cyg_drv_mutex_t *mutex;
  137. } cyg_drv_cond_t;
  138. externC void cyg_drv_cond_init( cyg_drv_cond_t *cond, cyg_drv_mutex_t *mutex );
  139. externC void cyg_drv_cond_destroy( cyg_drv_cond_t *cond );
  140. externC cyg_bool_t cyg_drv_cond_wait( cyg_drv_cond_t *cond );
  141. externC void cyg_drv_cond_signal( cyg_drv_cond_t *cond );
  142. externC void cyg_drv_cond_broadcast( cyg_drv_cond_t *cond );
  143. typedef struct cyg_interrupt
  144. {
  145. cyg_vector_t vector;
  146. cyg_priority_t priority;
  147. cyg_ISR_t *isr;
  148. cyg_DSR_t *dsr;
  149. CYG_ADDRWORD data;
  150. struct cyg_interrupt* volatile next_dsr;
  151. volatile cyg_int32 dsr_count;
  152. #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN
  153. struct cyg_interrupt *next;
  154. #endif
  155. } cyg_interrupt;
  156. externC void cyg_drv_interrupt_create(
  157. cyg_vector_t vector,
  158. cyg_priority_t priority,
  159. cyg_addrword_t data,
  160. cyg_ISR_t *isr,
  161. cyg_DSR_t *dsr,
  162. cyg_handle_t *handle,
  163. cyg_interrupt *intr
  164. );
  165. externC void cyg_drv_interrupt_delete( cyg_handle_t interrupt );
  166. externC void cyg_drv_interrupt_attach( cyg_handle_t interrupt );
  167. externC void cyg_drv_interrupt_detach( cyg_handle_t interrupt );
  168. externC void cyg_drv_interrupt_mask( cyg_vector_t vector );
  169. externC void cyg_drv_interrupt_mask_intunsafe( cyg_vector_t vector );
  170. externC void cyg_drv_interrupt_unmask( cyg_vector_t vector );
  171. externC void cyg_drv_interrupt_unmask_intunsafe( cyg_vector_t vector );
  172. externC void cyg_drv_interrupt_acknowledge( cyg_vector_t vector );
  173. externC void cyg_drv_interrupt_configure(
  174. cyg_vector_t vector,
  175. cyg_bool_t level,
  176. cyg_bool_t up
  177. );
  178. externC void cyg_drv_interrupt_level( cyg_vector_t vector, cyg_priority_t level );
  179. externC void cyg_drv_interrupt_set_cpu( cyg_vector_t vector, cyg_cpu_t cpu );
  180. externC cyg_cpu_t cyg_drv_interrupt_get_cpu( cyg_vector_t vector );
  181. enum cyg_ISR_results
  182. {
  183. CYG_ISR_HANDLED = 1, /* Interrupt was handled */
  184. CYG_ISR_CALL_DSR = 2 /* Schedule DSR */
  185. };
  186. typedef struct
  187. {
  188. cyg_atomic lock;
  189. } cyg_drv_spinlock_t;
  190. void cyg_drv_spinlock_init(
  191. cyg_drv_spinlock_t *lock, /* spinlock to initialize */
  192. cyg_bool_t locked /* init locked or unlocked */
  193. );
  194. void cyg_drv_spinlock_destroy( cyg_drv_spinlock_t *lock );
  195. void cyg_drv_spinlock_spin( cyg_drv_spinlock_t *lock );
  196. void cyg_drv_spinlock_clear( cyg_drv_spinlock_t *lock );
  197. cyg_bool_t cyg_drv_spinlock_try( cyg_drv_spinlock_t *lock );
  198. cyg_bool_t cyg_drv_spinlock_test( cyg_drv_spinlock_t *lock );
  199. void cyg_drv_spinlock_spin_intsave( cyg_drv_spinlock_t *lock,
  200. cyg_addrword_t *istate );
  201. void cyg_drv_spinlock_clear_intsave( cyg_drv_spinlock_t *lock,
  202. cyg_addrword_t istate );
  203. #endif /* CYGPKG_KERNEL */
  204. /*------------------------------------------------------------------------*/
  205. /* EOF drv_api.h */
  206. #endif // CYGONCE_HAL_DRV_API_H