[97] | 1 | /*
|
---|
| 2 | ** Copyright 2012 by Kvaser AB, Mölndal, Sweden
|
---|
| 3 | ** http://www.kvaser.com
|
---|
| 4 | **
|
---|
| 5 | ** This software is dual licensed under the following two licenses:
|
---|
| 6 | ** BSD-new and GPLv2. You may use either one. See the included
|
---|
| 7 | ** COPYING file for details.
|
---|
| 8 | **
|
---|
| 9 | ** License: BSD-new
|
---|
| 10 | ** ===============================================================================
|
---|
| 11 | ** Redistribution and use in source and binary forms, with or without
|
---|
| 12 | ** modification, are permitted provided that the following conditions are met:
|
---|
| 13 | ** * Redistributions of source code must retain the above copyright
|
---|
| 14 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 15 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer in the
|
---|
| 17 | ** documentation and/or other materials provided with the distribution.
|
---|
| 18 | ** * Neither the name of the <organization> nor the
|
---|
| 19 | ** names of its contributors may be used to endorse or promote products
|
---|
| 20 | ** derived from this software without specific prior written permission.
|
---|
| 21 | **
|
---|
| 22 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
| 23 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
| 24 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 25 | ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
---|
| 26 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
| 27 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
| 28 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 29 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 30 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 31 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 32 | **
|
---|
| 33 | **
|
---|
| 34 | ** License: GPLv2
|
---|
| 35 | ** ===============================================================================
|
---|
| 36 | ** This program is free software; you can redistribute it and/or
|
---|
| 37 | ** modify it under the terms of the GNU General Public License
|
---|
| 38 | ** as published by the Free Software Foundation; either version 2
|
---|
| 39 | ** of the License, or (at your option) any later version.
|
---|
| 40 | **
|
---|
| 41 | ** This program is distributed in the hope that it will be useful,
|
---|
| 42 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 43 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 44 | ** GNU General Public License for more details.
|
---|
| 45 | **
|
---|
| 46 | ** You should have received a copy of the GNU General Public License
|
---|
| 47 | ** along with this program; if not, write to the Free Software
|
---|
| 48 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
| 49 | **
|
---|
| 50 | ** ---------------------------------------------------------------------------
|
---|
| 51 | **/
|
---|
| 52 |
|
---|
| 53 | #ifndef OSIF_FUNCTIONS_KERNEL_H_
|
---|
| 54 | #define OSIF_FUNCTIONS_KERNEL_H_
|
---|
| 55 |
|
---|
| 56 | #include "osif_kernel.h"
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | //////////////////////////////////////////////////////////////////////
|
---|
| 60 | //
|
---|
| 61 | #define os_if_wait_event_interruptible_timeout(wq, condition, timeout) \
|
---|
| 62 | wait_event_interruptible_timeout(wq, condition, msecs_to_jiffies(timeout) + 1)
|
---|
| 63 |
|
---|
| 64 | //////////////////////////////////////////////////////////////////////
|
---|
| 65 | //
|
---|
| 66 | void os_if_write_port(unsigned regist, unsigned portAddr);
|
---|
| 67 |
|
---|
| 68 | //////////////////////////////////////////////////////////////////////
|
---|
| 69 | //
|
---|
| 70 | unsigned int os_if_read_port(unsigned portAddr);
|
---|
| 71 |
|
---|
| 72 | //////////////////////////////////////////////////////////////////////
|
---|
| 73 | //
|
---|
| 74 | int os_if_queue_task(OS_IF_TASK_QUEUE_HANDLE *hnd);
|
---|
| 75 |
|
---|
| 76 | //////////////////////////////////////////////////////////////////////
|
---|
| 77 | //
|
---|
| 78 | int os_if_queue_task_not_default_queue(OS_IF_WQUEUE *wq,
|
---|
| 79 | OS_IF_TASK_QUEUE_HANDLE *hnd);
|
---|
| 80 |
|
---|
| 81 | //////////////////////////////////////////////////////////////////////
|
---|
| 82 | //
|
---|
| 83 | void os_if_init_waitqueue_head(OS_IF_WAITQUEUE_HEAD *handle);
|
---|
| 84 |
|
---|
| 85 | //////////////////////////////////////////////////////////////////////
|
---|
| 86 | //
|
---|
| 87 | void os_if_init_named_waitqueue_head(OS_IF_WAITQUEUE_HEAD *handle, char *name);
|
---|
| 88 |
|
---|
| 89 | //////////////////////////////////////////////////////////////////////
|
---|
| 90 | //
|
---|
| 91 | void os_if_delete_waitqueue_head(OS_IF_WAITQUEUE_HEAD *handle);
|
---|
| 92 |
|
---|
| 93 | //////////////////////////////////////////////////////////////////////
|
---|
| 94 | //
|
---|
| 95 | void os_if_init_waitqueue_entry(OS_IF_WAITQUEUE *wait);
|
---|
| 96 |
|
---|
| 97 | //////////////////////////////////////////////////////////////////////
|
---|
| 98 | //
|
---|
| 99 | void os_if_add_wait_queue(OS_IF_WAITQUEUE_HEAD *waitQ,
|
---|
| 100 | OS_IF_WAITQUEUE *wait);
|
---|
| 101 |
|
---|
| 102 | //////////////////////////////////////////////////////////////////////
|
---|
| 103 | //
|
---|
| 104 | void os_if_remove_wait_queue(OS_IF_WAITQUEUE_HEAD *waitQ,
|
---|
| 105 | OS_IF_WAITQUEUE *wait);
|
---|
| 106 |
|
---|
| 107 | //////////////////////////////////////////////////////////////////////
|
---|
| 108 | //
|
---|
| 109 | signed long os_if_wait_for_event_timeout(signed long timeout,
|
---|
| 110 | OS_IF_WAITQUEUE *handle);
|
---|
| 111 |
|
---|
| 112 | //////////////////////////////////////////////////////////////////////
|
---|
| 113 | //
|
---|
| 114 | signed long os_if_wait_for_event_timeout_simple(signed long timeout);
|
---|
| 115 |
|
---|
| 116 | //////////////////////////////////////////////////////////////////////
|
---|
| 117 | //
|
---|
| 118 | void os_if_wait_for_event(OS_IF_WAITQUEUE_HEAD *handle);
|
---|
| 119 |
|
---|
| 120 | //////////////////////////////////////////////////////////////////////
|
---|
| 121 | //
|
---|
| 122 | //long os_if_wait_event_interruptible_timeout(OS_IF_WAITQUEUE_HEAD handle,
|
---|
| 123 | // unsigned long *cond, long time);
|
---|
| 124 |
|
---|
| 125 | //////////////////////////////////////////////////////////////////////
|
---|
| 126 | //
|
---|
| 127 | void os_if_wake_up_interruptible(OS_IF_WAITQUEUE_HEAD *handle);
|
---|
| 128 |
|
---|
| 129 | //////////////////////////////////////////////////////////////////////
|
---|
| 130 | //
|
---|
| 131 |
|
---|
| 132 | //////////////////////////////////////////////////////////////////////
|
---|
| 133 | //
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | //////////////////////////////////////////////////////////////////////
|
---|
| 137 | //
|
---|
| 138 | void os_if_up_sema(OS_IF_SEMAPHORE *var);
|
---|
| 139 |
|
---|
| 140 | //////////////////////////////////////////////////////////////////////
|
---|
| 141 | //
|
---|
| 142 | void os_if_down_sema(OS_IF_SEMAPHORE *var);
|
---|
| 143 |
|
---|
| 144 | //////////////////////////////////////////////////////////////////////
|
---|
| 145 | //
|
---|
| 146 | int os_if_down_sema_time(OS_IF_SEMAPHORE *var, int timeout);
|
---|
| 147 |
|
---|
| 148 | //////////////////////////////////////////////////////////////////////
|
---|
| 149 | //
|
---|
| 150 | void os_if_init_sema(OS_IF_SEMAPHORE *var);
|
---|
| 151 |
|
---|
| 152 | //////////////////////////////////////////////////////////////////////
|
---|
| 153 | //
|
---|
| 154 | void os_if_delete_sema(OS_IF_SEMAPHORE *var);
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | //////////////////////////////////////////////////////////////////////
|
---|
| 158 | //
|
---|
| 159 | void os_if_set_task_interruptible(void);
|
---|
| 160 |
|
---|
| 161 | //////////////////////////////////////////////////////////////////////
|
---|
| 162 | //
|
---|
| 163 | void os_if_set_task_uninterruptible(void);
|
---|
| 164 |
|
---|
| 165 | //////////////////////////////////////////////////////////////////////
|
---|
| 166 | //
|
---|
| 167 | void os_if_set_task_running(void);
|
---|
| 168 |
|
---|
| 169 | //////////////////////////////////////////////////////////////////////
|
---|
| 170 | //
|
---|
| 171 | unsigned long os_if_get_timeout_time(void);
|
---|
| 172 |
|
---|
| 173 | //////////////////////////////////////////////////////////////////////
|
---|
| 174 | //
|
---|
| 175 | void os_if_do_get_time_of_day(OS_IF_TIME_VAL *tv);
|
---|
| 176 |
|
---|
| 177 | //////////////////////////////////////////////////////////////////////
|
---|
| 178 | //
|
---|
| 179 | int os_if_is_rec_busy(int nr, volatile unsigned long *addr);
|
---|
| 180 |
|
---|
| 181 | //////////////////////////////////////////////////////////////////////
|
---|
| 182 | //
|
---|
| 183 | void os_if_rec_not_busy(int nr, volatile unsigned long *addr);
|
---|
| 184 |
|
---|
| 185 | //////////////////////////////////////////////////////////////////////
|
---|
| 186 | //
|
---|
| 187 | # define os_if_spin_lock_init(lock) spin_lock_init(lock)
|
---|
| 188 |
|
---|
| 189 | //////////////////////////////////////////////////////////////////////
|
---|
| 190 | //
|
---|
| 191 | void os_if_spin_lock(OS_IF_LOCK *lock);
|
---|
| 192 |
|
---|
| 193 | //////////////////////////////////////////////////////////////////////
|
---|
| 194 | //
|
---|
| 195 | void os_if_spin_unlock(OS_IF_LOCK *lock);
|
---|
| 196 |
|
---|
| 197 | //////////////////////////////////////////////////////////////////////
|
---|
| 198 | //
|
---|
| 199 | void os_if_spin_lock_remove(OS_IF_LOCK *lock);
|
---|
| 200 |
|
---|
| 201 | //////////////////////////////////////////////////////////////////////
|
---|
| 202 | //
|
---|
| 203 | void os_if_irq_disable(OS_IF_LOCK *lock);
|
---|
| 204 |
|
---|
| 205 | //////////////////////////////////////////////////////////////////////
|
---|
| 206 | //
|
---|
| 207 | void os_if_irq_enable(OS_IF_LOCK *lock);
|
---|
| 208 |
|
---|
| 209 | //////////////////////////////////////////////////////////////////////
|
---|
| 210 | //
|
---|
| 211 | void os_if_irq_save(OS_IF_LOCK *lock, unsigned long *flags);
|
---|
| 212 |
|
---|
| 213 | //////////////////////////////////////////////////////////////////////
|
---|
| 214 | //
|
---|
| 215 | void os_if_irq_restore(OS_IF_LOCK *lock, unsigned long flags);
|
---|
| 216 |
|
---|
| 217 | //////////////////////////////////////////////////////////////////////
|
---|
| 218 | //
|
---|
| 219 | void os_if_spin_lock_irqsave(OS_IF_LOCK *lock, unsigned long *flags);
|
---|
| 220 |
|
---|
| 221 | //////////////////////////////////////////////////////////////////////
|
---|
| 222 | //
|
---|
| 223 | void os_if_spin_unlock_irqrestore(OS_IF_LOCK *lock, unsigned long flags);
|
---|
| 224 |
|
---|
| 225 | //////////////////////////////////////////////////////////////////////
|
---|
| 226 | //
|
---|
| 227 | void os_if_spin_lock_softirq(OS_IF_LOCK *lock);
|
---|
| 228 |
|
---|
| 229 | //////////////////////////////////////////////////////////////////////
|
---|
| 230 | //
|
---|
| 231 | void os_if_spin_unlock_softirq(OS_IF_LOCK *lock);
|
---|
| 232 |
|
---|
| 233 | //////////////////////////////////////////////////////////////////////
|
---|
| 234 | //
|
---|
| 235 | int os_if_get_user_data(void *to, const void *from, OS_IF_SIZE n);
|
---|
| 236 |
|
---|
| 237 | //////////////////////////////////////////////////////////////////////
|
---|
| 238 | //
|
---|
| 239 | int os_if_set_user_data(void *to, const void *from, OS_IF_SIZE n);
|
---|
| 240 |
|
---|
| 241 | //////////////////////////////////////////////////////////////////////
|
---|
| 242 | //
|
---|
| 243 | int os_if_set_int(int val, int *dest);
|
---|
| 244 |
|
---|
| 245 | //////////////////////////////////////////////////////////////////////
|
---|
| 246 | //
|
---|
| 247 | int os_if_get_int(int *val, int *src);
|
---|
| 248 |
|
---|
| 249 | //////////////////////////////////////////////////////////////////////
|
---|
| 250 | //
|
---|
| 251 | int os_if_get_long(long *val, long *src);
|
---|
| 252 |
|
---|
| 253 | //////////////////////////////////////////////////////////////////////
|
---|
| 254 | //
|
---|
| 255 | OS_IF_WQUEUE* os_if_declare_task(char *name, OS_IF_TASK_QUEUE_HANDLE *taskQ);
|
---|
| 256 |
|
---|
| 257 | //////////////////////////////////////////////////////////////////////
|
---|
| 258 | //
|
---|
| 259 | OS_IF_WQUEUE* os_if_declare_rt_task(char *name, OS_IF_TASK_QUEUE_HANDLE *taskQ);
|
---|
| 260 |
|
---|
| 261 | //////////////////////////////////////////////////////////////////////
|
---|
| 262 | //
|
---|
| 263 | void os_if_destroy_task(OS_IF_WQUEUE *wQueue);
|
---|
| 264 |
|
---|
| 265 | //////////////////////////////////////////////////////////////////////
|
---|
| 266 | //
|
---|
| 267 | void os_if_init_task(OS_IF_TASK_QUEUE_HANDLE *taskQ, void *function, void *data);
|
---|
| 268 |
|
---|
| 269 | //////////////////////////////////////////////////////////////////////
|
---|
| 270 | //
|
---|
| 271 | void os_if_rwlock_init(rwlock_t *lock);
|
---|
| 272 |
|
---|
| 273 | //////////////////////////////////////////////////////////////////////
|
---|
| 274 | //
|
---|
| 275 | void os_if_read_lock_irqsave(rwlock_t *rw_lock, unsigned long *flags);
|
---|
| 276 |
|
---|
| 277 | //////////////////////////////////////////////////////////////////////
|
---|
| 278 | //
|
---|
| 279 | void os_if_read_unlock_irqrestore(rwlock_t *rw_lock, unsigned long flags);
|
---|
| 280 |
|
---|
| 281 | //////////////////////////////////////////////////////////////////////
|
---|
| 282 | //
|
---|
| 283 | void os_if_write_lock_irqsave(rwlock_t *rw_lock, unsigned long *flags);
|
---|
| 284 |
|
---|
| 285 | //////////////////////////////////////////////////////////////////////
|
---|
| 286 | //
|
---|
| 287 | void os_if_write_unlock_irqrestore(rwlock_t *rw_lock, unsigned long flags);
|
---|
| 288 |
|
---|
| 289 | //////////////////////////////////////////////////////////////////////
|
---|
| 290 | //
|
---|
| 291 | void os_if_rwlock_remove(rwlock_t *lock);
|
---|
| 292 |
|
---|
| 293 | //////////////////////////////////////////////////////////////////////
|
---|
| 294 | //
|
---|
| 295 | int os_if_signal_pending(void);
|
---|
| 296 |
|
---|
| 297 | //////////////////////////////////////////////////////////////////////
|
---|
| 298 | //
|
---|
| 299 | void* os_if_kernel_malloc(size_t buffer_size);
|
---|
| 300 |
|
---|
| 301 | //////////////////////////////////////////////////////////////////////
|
---|
| 302 | //
|
---|
| 303 | void os_if_kernel_free(void *mem_ptr);
|
---|
| 304 |
|
---|
| 305 | //////////////////////////////////////////////////////////////////////
|
---|
| 306 | //
|
---|
| 307 | OS_IF_THREAD os_if_kernel_thread(int (*thread)(void *context), void *context);
|
---|
| 308 |
|
---|
| 309 | //////////////////////////////////////////////////////////////////////
|
---|
| 310 | //
|
---|
| 311 | void os_if_exit_thread(int result);
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 | typedef unsigned long AtomicBit;
|
---|
| 315 | typedef AtomicBit OS_IF_ATOMIC_BIT;
|
---|
| 316 |
|
---|
| 317 | void os_if_init_atomic_bit(OS_IF_ATOMIC_BIT *ab);
|
---|
| 318 | void os_if_remove_atomic_bit(OS_IF_ATOMIC_BIT *ab);
|
---|
| 319 |
|
---|
| 320 | #endif //OSIF_FUNCTIONS_KERNEL_H_
|
---|