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