|
2
|
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 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
28 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //========================================================================== |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
|
35 // Author(s): nickg |
|
|
36 // Date: 1999-02-24 |
|
|
37 // Purpose: Driver API |
|
|
38 // Description: This file defines the API used by device drivers to access |
|
|
39 // system services. When the kernel is present it maps directly |
|
|
40 // to the Kernel C API. When the kernel is absent, it is provided |
|
|
41 // by a set of HAL functions. |
|
|
42 // |
|
|
43 // Usage: #include <cyg/kernel/kapi.h> |
|
|
44 // |
|
|
45 //####DESCRIPTIONEND#### |
|
|
46 // |
|
|
47 //========================================================================*/ |
|
|
48 |
|
|
49 #include <pkgconf/hal.h> |
|
|
50 #include <cyg/infra/cyg_type.h> |
|
|
51 |
|
|
52 #ifdef CYGPKG_KERNEL |
|
|
53 |
|
|
54 /*------------------------------------------------------------------------*/ |
|
|
55 /* Kernel co-resident version of API */ |
|
|
56 |
|
|
57 #include <pkgconf/kernel.h> |
|
|
58 |
|
|
59 #ifndef CYGFUN_KERNEL_API_C |
|
|
60 #error Driver API requres Kernel API to be present |
|
|
61 #endif |
|
|
62 |
|
|
63 #include <cyg/kernel/kapi.h> |
|
|
64 |
|
|
65 #define cyg_drv_isr_lock cyg_interrupt_disable |
|
|
66 #define cyg_drv_isr_unlock cyg_interrupt_enable |
|
|
67 |
|
|
68 #define cyg_drv_dsr_lock cyg_scheduler_lock |
|
|
69 #define cyg_drv_dsr_unlock cyg_scheduler_unlock |
|
|
70 |
|
|
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 |
|
|
79 #define cyg_drv_cond_t cyg_cond_t |
|
|
80 #define cyg_drv_cond_init cyg_cond_init |
|
|
81 #define cyg_drv_cond_destroy cyg_cond_destroy |
|
|
82 #define cyg_drv_cond_wait cyg_cond_wait |
|
|
83 #define cyg_drv_cond_signal cyg_cond_signal |
|
|
84 #define cyg_drv_cond_broadcast cyg_cond_broadcast |
|
|
85 |
|
|
86 #define cyg_drv_interrupt_create cyg_interrupt_create |
|
|
87 #define cyg_drv_interrupt_delete cyg_interrupt_delete |
|
|
88 #define cyg_drv_interrupt_attach cyg_interrupt_attach |
|
|
89 #define cyg_drv_interrupt_detach cyg_interrupt_detach |
|
|
90 #define cyg_drv_interrupt_mask cyg_interrupt_mask |
|
|
91 #define cyg_drv_interrupt_unmask cyg_interrupt_unmask |
|
|
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 |
|
|
96 #else /* CYGPKG_KERNEL */ |
|
|
97 |
|
|
98 /*------------------------------------------------------------------------*/ |
|
|
99 /* Non-kernel version of API */ |
|
|
100 |
|
|
101 typedef CYG_ADDRWORD cyg_addrword_t; /* May hold pointer or word */ |
|
|
102 typedef cyg_addrword_t cyg_handle_t; /* Object handle */ |
|
|
103 typedef cyg_uint32 cyg_priority_t; /* type for priorities */ |
|
|
104 typedef cyg_uint32 cyg_vector_t; /* Interrupt vector id */ |
|
|
105 typedef int cyg_bool_t; |
|
|
106 |
|
|
107 typedef cyg_uint32 cyg_ISR_t( cyg_vector_t vector, cyg_addrword_t data); |
|
|
108 typedef void cyg_DSR_t(cyg_vector_t vector, |
|
|
109 cyg_ucount32 count, |
|
|
110 cyg_addrword_t data); |
|
|
111 |
|
|
112 |
|
|
113 externC void cyg_drv_isr_lock(void); |
|
|
114 externC void cyg_drv_isr_unlock(void); |
|
|
115 |
|
|
116 externC void cyg_drv_dsr_lock(void); |
|
|
117 externC void cyg_drv_dsr_unlock(void); |
|
|
118 |
|
|
119 typedef struct |
|
|
120 { |
|
|
121 cyg_atomic lock; |
|
|
122 } cyg_drv_mutex_t; |
|
|
123 |
|
|
124 externC void cyg_drv_mutex_init( cyg_drv_mutex_t *mutex ); |
|
|
125 externC void cyg_drv_mutex_destroy( cyg_drv_mutex_t *mutex ); |
|
|
126 externC cyg_bool_t cyg_drv_mutex_lock( cyg_drv_mutex_t *mutex ); |
|
|
127 externC cyg_bool_t cyg_drv_mutex_trylock( cyg_drv_mutex_t *mutex ); |
|
|
128 externC void cyg_drv_mutex_unlock( cyg_drv_mutex_t *mutex ); |
|
|
129 externC void cyg_drv_mutex_release( cyg_drv_mutex_t *mutex ); |
|
|
130 |
|
|
131 typedef struct |
|
|
132 { |
|
|
133 cyg_atomic wait; |
|
|
134 cyg_drv_mutex_t *mutex; |
|
|
135 } cyg_drv_cond_t; |
|
|
136 |
|
|
137 externC void cyg_drv_cond_init( cyg_drv_cond_t *cond, cyg_drv_mutex_t *mutex ); |
|
|
138 externC void cyg_drv_cond_destroy( cyg_drv_cond_t *cond ); |
|
|
139 externC void cyg_drv_cond_wait( cyg_drv_cond_t *cond ); |
|
|
140 externC void cyg_drv_cond_signal( cyg_drv_cond_t *cond ); |
|
|
141 externC void cyg_drv_cond_broadcast( cyg_drv_cond_t *cond ); |
|
|
142 |
|
|
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 |
|
|
151 volatile struct cyg_interrupt *next_dsr; |
|
|
152 cyg_int32 dsr_count; |
|
|
153 |
|
|
154 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN |
|
|
155 struct cyg_interrupt *next; |
|
|
156 #endif |
|
|
157 |
|
|
158 } cyg_interrupt; |
|
|
159 |
|
|
160 externC void cyg_drv_interrupt_create( |
|
|
161 cyg_vector_t vector, |
|
|
162 cyg_priority_t priority, |
|
|
163 cyg_addrword_t data, |
|
|
164 cyg_ISR_t *isr, |
|
|
165 cyg_DSR_t *dsr, |
|
|
166 cyg_handle_t *handle, |
|
|
167 cyg_interrupt *intr |
|
|
168 ); |
|
|
169 externC void cyg_drv_interrupt_delete( cyg_handle_t interrupt ); |
|
|
170 externC void cyg_drv_interrupt_attach( cyg_handle_t interrupt ); |
|
|
171 externC void cyg_drv_interrupt_detach( cyg_handle_t interrupt ); |
|
|
172 |
|
|
173 externC void cyg_drv_interrupt_mask( cyg_vector_t vector ); |
|
|
174 externC void cyg_drv_interrupt_unmask( cyg_vector_t vector ); |
|
|
175 externC void cyg_drv_interrupt_acknowledge( cyg_vector_t vector ); |
|
|
176 externC void cyg_drv_interrupt_configure( |
|
|
177 cyg_vector_t vector, |
|
|
178 cyg_bool_t level, |
|
|
179 cyg_bool_t up |
|
|
180 ); |
|
|
181 externC void cyg_drv_interrupt_level( cyg_vector_t vector, cyg_priority_t level ); |
|
|
182 |
|
|
183 |
|
|
184 enum cyg_ISR_results |
|
|
185 { |
|
|
186 CYG_ISR_HANDLED = 1, /* Interrupt was handled */ |
|
|
187 CYG_ISR_CALL_DSR = 2 /* Schedule DSR */ |
|
|
188 }; |
|
|
189 |
|
|
190 #endif /* CYGPKG_KERNEL */ |
|
|
191 |
|
|
192 /*------------------------------------------------------------------------*/ |
|
|
193 /* EOF drv_api.h */ |
|
|
194 #endif // CYGONCE_HAL_DRV_API_H |