| 1 | /**************************************************************************** |
|---|
| 2 | DHL_OSAL_Impl.c - private header |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | ****************************************************************************/ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #ifndef __DHL_OSAL_IMPL_H__ |
|---|
| 11 | #define __DHL_OSAL_IMPL_H__ |
|---|
| 12 | |
|---|
| 13 | #ifdef _cplusplus |
|---|
| 14 | extern "C" { |
|---|
| 15 | #endif |
|---|
| 16 | |
|---|
| 17 | #include "bos.h" |
|---|
| 18 | #include "ucos_ii.h" |
|---|
| 19 | #include "ministd.h" |
|---|
| 20 | #include "string.h" |
|---|
| 21 | //#include "libc.h" |
|---|
| 22 | #include "bkni.h" |
|---|
| 23 | |
|---|
| 24 | /* platform dependent settings */ |
|---|
| 25 | typedef UINT32 os_task_id; |
|---|
| 26 | typedef void *os_semaphore_id; |
|---|
| 27 | typedef void *os_messagequeue_id; |
|---|
| 28 | typedef void (*os_taskfunction)(void *); |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | SemaphoreÀÇ option. |
|---|
| 33 | |
|---|
| 34 | °¢Á¾ CreateXXXSemaphoreÀÇ optionÀ¸·Î »ç¿ëµÈ´Ù. |
|---|
| 35 | ÀϹÝÀûÀ¸·Î´Â priority ¹æ½ÄÀ¸·Î »ç¿ëÇÏ¸é µÈ´Ù. |
|---|
| 36 | --> uCOS-II¿¡¼´Â µ¿ÀÏÇÑ priority¸¦ °¡Áø task´Â ¾øÀ½. »ç¿ëÇÏÁö ¾Ê´Â ¿É¼Ç |
|---|
| 37 | */ |
|---|
| 38 | enum { |
|---|
| 39 | OS_SEM_PRIO=0x0, ///< ´ë±âÁßÀÎ taskÁß¿¡¼ highest priority task°¡ ¸ÕÀú ±ú¾î³². |
|---|
| 40 | OS_SEM_FIFO=0x1, ///< ¸Ç ¸ÕÀú suspend µÈ task°¡ ¸ÕÀú ±ú¾î³² |
|---|
| 41 | }; |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | #ifdef BCM_DEBUG |
|---|
| 45 | // because we use broadcom heap debug function, |
|---|
| 46 | // OSAL heap code depends on broadcom make flag. |
|---|
| 47 | #define OSAL_HEAP_DEBUG 1 |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | typedef struct |
|---|
| 52 | { |
|---|
| 53 | UINT32 size_heap; // size of entire heap |
|---|
| 54 | |
|---|
| 55 | UINT32 num_alloc_chunk; // number of alloc chunk |
|---|
| 56 | UINT32 size_alloc; // total byte size alloc chunk |
|---|
| 57 | |
|---|
| 58 | UINT32 num_free_chunk; // number of free chunk |
|---|
| 59 | UINT32 size_free; // total byte size free chunk |
|---|
| 60 | |
|---|
| 61 | } dhl_heap_status; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | #if OSAL_HEAP_DEBUG // heap debugging |
|---|
| 65 | |
|---|
| 66 | void *os_dbg_malloc(int size, char *file, int line); |
|---|
| 67 | void *os_dbg_calloc(int n, int m, char *file, int line); |
|---|
| 68 | void os_dbg_free(void *ptr, char *file, int line); |
|---|
| 69 | |
|---|
| 70 | // we need file/line info of the caller. |
|---|
| 71 | #define OS_Malloc(n) os_dbg_malloc((n), __FILE__, __LINE__) |
|---|
| 72 | #define OS_Calloc(n,m) os_dbg_calloc((n),(m), __FILE__, __LINE__) |
|---|
| 73 | #define OS_Free(p) os_dbg_free((p), __FILE__, __LINE__) |
|---|
| 74 | |
|---|
| 75 | #else |
|---|
| 76 | // this is normal function. |
|---|
| 77 | void *OS_Malloc(int size); |
|---|
| 78 | void *OS_Calloc(int n, int m); |
|---|
| 79 | void OS_Free(void *pp); |
|---|
| 80 | void OS_FreeDirect(void *ptr); |
|---|
| 81 | #endif |
|---|
| 82 | |
|---|
| 83 | void os_heap_status(dhl_heap_status *pstat); |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | int osi_dbgprint(char *fmt, ...); |
|---|
| 88 | |
|---|
| 89 | UINT32 osi_gettickcount(); |
|---|
| 90 | UINT32 osi_gettickspersecond(); |
|---|
| 91 | void osi_delay(UINT32 millisec); |
|---|
| 92 | |
|---|
| 93 | BOOL osi_in_interrupt(void); |
|---|
| 94 | |
|---|
| 95 | UINT32 osi_disableint(); |
|---|
| 96 | void osi_enableint(UINT32 mask); |
|---|
| 97 | |
|---|
| 98 | BOOL osi_in_tasklock(void); |
|---|
| 99 | |
|---|
| 100 | UINT32 osi_locktask(); |
|---|
| 101 | void osi_unlocktask(UINT32 mask); |
|---|
| 102 | char *osi_taskname(os_task_id tid); |
|---|
| 103 | int osi_taskpriority(); |
|---|
| 104 | os_task_id osi_taskid(); |
|---|
| 105 | os_task_id osi_taskidfromname(char *tname); |
|---|
| 106 | void osi_changetaskpriority(os_task_id tid, UINT32 newPrio, UINT32 *oldPrioPtr); |
|---|
| 107 | void osi_deletetask(os_task_id tid); |
|---|
| 108 | void osi_selfdeletetask(void); |
|---|
| 109 | |
|---|
| 110 | os_task_id osi_spawntask(os_taskfunction func, const char *name, int priority, UINT32 stackSize, |
|---|
| 111 | UINT32 arg1); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | int osi_takesemaphore(os_semaphore_id sid); |
|---|
| 115 | int osi_takesemaphore_wait(os_semaphore_id sid, int ticks); |
|---|
| 116 | int osi_takesemaphore_nowait(os_semaphore_id sid); |
|---|
| 117 | int osi_givesemaphore(os_semaphore_id sid); |
|---|
| 118 | int osi_flushsemaphore(os_semaphore_id sid); |
|---|
| 119 | void osi_deletesemaphore(os_semaphore_id sid); |
|---|
| 120 | int osi_takemutexsemaphore_wait(os_semaphore_id sid, int ticks); |
|---|
| 121 | void osi_givemutexsemaphore(os_semaphore_id sid); |
|---|
| 122 | void osi_deletemutexsemaphore(os_semaphore_id sid); |
|---|
| 123 | os_semaphore_id osi_createcountingsemaphore(const char *name, UINT32 options, UINT32 count); |
|---|
| 124 | os_semaphore_id osi_createbinarysemaphore(const char *name, UINT32 options, BOOL flag); |
|---|
| 125 | os_semaphore_id osi_createmutexsemaphore(const char *name); |
|---|
| 126 | |
|---|
| 127 | int osi_free_reuse_sem_count(void); |
|---|
| 128 | os_semaphore_id osi_create_reuse_semaphore(char *name, int count); |
|---|
| 129 | void osi_delete_reuse_semaphore(os_semaphore_id sid); |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | void osi_deletemessagequeue(os_messagequeue_id qid); |
|---|
| 133 | os_messagequeue_id osi_createmessagequeue(const char *name, UINT32 options, |
|---|
| 134 | UINT32 maxMessages, UINT32 maxMessageLength); |
|---|
| 135 | int osi_sendmessage(os_messagequeue_id qid, void *buffer, int nBytes); |
|---|
| 136 | int osi_receivemessage(os_messagequeue_id qid, void *msgBuf); |
|---|
| 137 | int osi_receivemessage_wait(os_messagequeue_id qid, void *msgBuf, int ticks); |
|---|
| 138 | int osi_receivemessage_nowait(os_messagequeue_id qid, void *msgBuf); |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | void osi_show_taskinfo(int level); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | #ifdef _cplusplus |
|---|
| 145 | extern } /* extern "C" */ |
|---|
| 146 | #endif |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | #endif /* __DHL_OSAL_IMPL_H__ */ |
|---|
| 151 | |
|---|
| 152 | /* end of file */ |
|---|