versadac  1
versadac - Scalable Recorder Firmware
os.h
1 /*---------------------------------------------------------------------------*/
2 /* Copyright (C) 2006 Woodhead Software & Electonics. All rights reserved. */
3 /*---------------------------------------------------------------------------*/
4 /* This program is protected by international copyright. */
5 /* */
6 /* The use of this software including but not limited to its Source Code */
7 /* is subject to restrictions as agreed in the license agreement between */
8 /* you and Woodhead. */
9 /* Copying or distribution is not allowed unless expressly permitted */
10 /* according to your license agreement with Woodhead. */
11 /*---------------------------------------------------------------------------*/
12 /* */
13 /* Project : STACK PROFINET Controller */
14 /* Component : Hardware Interface */
15 /* $Workfile:: os.h $*/
16 /* $Revision:: 2 $*/
17 /* $Date:: 15/06/10 16:34 $*/
18 /* */
19 /*---------------------------------------------------------------------------*/
20 /* */
21 /* D e s c r i p t i o n : */
22 /* Network Abstraction Layer */
23 /* */
24 /*---------------------------------------------------------------------------*/
25 #ifndef _OS_H
26 #define _OS_H
27 
28 #define _CRTDBG_MAP_ALLOC
29 
30 #include <vxWorks.h>
31 #include <semLib.h>
32 #include <taskLib.h>
33 #include <intLib.h>
34 #include <timers.h>
35 #include <tickLib.h>
36 #include <sysLib.h>
37 #include "sockLib.h"
38 #include "inetLib.h"
39 #include "hostLib.h"
40 #include "stdio.h"
41 
42 
43 #include "string.h"
44 #include "types.h"
45 #include "platform.h"
46 
47 #define INFINITE -1
48 
49 
50 
51 
52 
53 //#ifdef OS_VXWORKS
54 
55 #define THREAD_PRIORITY_NORMAL 100
56 #define THREAD_PRIORITY_HIGHEST 100
57 #define THREAD_PRIORITY_TIME_CRITICAL 100
58 
59 #define TASK_RPC_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
60 #define TASK_MSG_ASYNC_PRIO THREAD_PRIORITY_TIME_CRITICAL
61 #define TASK_ERROR_PRIO THREAD_PRIORITY_TIME_CRITICAL
62 #define TASK_CPM_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
63 #define TASK_LMPM_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
64 #define TASK_PPM_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
65 #define TASK_ASE_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
66 #define TASK_ALM_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
67 #define TASK_RPC_MSSER_PRIO THREAD_PRIORITY_TIME_CRITICAL
68 #define TASK_FSPM_RUNTIME_PRIO THREAD_PRIORITY_TIME_CRITICAL
69 #define TASK_SCHEDULE_RUNTIME_PRIO 51
70 #define TASK_ADDIN_RUNTIME_PRIO 60
71 //#endif
72 
73 
74 
75 #define OS_MEMCOPY memcpy
76 #define OS_MEMSET memset
77 #define OS_MEMCMP memcmp
78 #define OS_SPRINTF sprintf
79 #define OS_SSCANF sscanf
80 #define OS_STRCPY strcpy
81 #define OS_STRCAT strcat
82 #define OS_STRNCAT strncat
83 
84 #define OS_FOPEN fopen
85 #define OS_FCLOSE fclose
86 #define OS_FREAD fread
87 #define OS_FWRITE fwrite
88 
89 #ifdef ACTIVATE_LOG_EVENT
90 
91  void logAssert(APP_DWORD dwLine);
92 
93  #ifdef OS_DEBUG
94  #define OS_ASSERT(a) if(!(a)){OsDebugPrint("assert %s - %d \n",__FILE__,__LINE__); logAssert(__LINE__);__asm {int 3}}
95  #else
96  #define OS_ASSERT(a) if(!(a)){printf("assert %s - %d \n",__FILE__,__LINE__);logAssert(__LINE__);}
97  #endif
98 
99 #endif
100 #ifndef ACTIVATE_LOG_EVENT
101 
102  #ifdef OS_DEBUG
103  #define OS_ASSERT(a) if(!(a)){OsDebugPrint("assert %s - %d \n",__FILE__,__LINE__); __asm {int 3}}
104  #else
105  #define OS_ASSERT(a)
106  #endif
107 
108 #endif
109 
110 
111 /* NETWORK CONVERSION MACROs*/
112 #undef HTONS
113 #define HTONS htons
114 #undef HTONL
115 #define HTONL htonl
116 
117 
118 
119 /* STRING MACROs*/
120 #define OS_STRNCPY strncpy
121 #define OS_STRLEN strlen
122 #define OS_STRCMP strcmp
123 
124 /*Use buzzer for user alarm*/
125 #ifdef __NO_BEEP
126  #define OS_BEEP(x,y)
127 #else
128  #define OS_BEEP(x,y) Beep((x),(y));
129 #endif
130 
131 /* GENERAL MACROs */
132 #ifdef OS_DEBUG
133 
134 APP_VOID OsPndTestHeader(char * lpszFormat);
135 #define PN_TEST_FAILED printf ("------- ######################################## --------\n");printf("####### -------------- TEST FAILED -------------- #######\n");printf("\n");printf
136 #define PN_TEST_SUCCEED printf
137 #define osPndTestFinish(testName) printf("\n \n \n");\
138  printf("------------------------------------------------------------\n"); \
139  printf("- *** Test Finish :%s ***\n",testName); \
140  printf("------------------------------------------------------------\n \n \n");
141 #else
142 
143 #define PN_TEST_FAILED
144 #define PN_TEST_SUCCEED
145 
146 #endif
147 
148 /*---------------------------- Init function -----------------------*/
149 APP_WORD OsInit (void);
150 APP_WORD OsExit( APP_VOID );
151 
152 /*---------------------------- memory management -------------------*/
153 APP_WORD _OsAlloc (APP_LPVOID* ppMem,APP_BYTE byValue,APP_DWORD dwLength);
154 APP_WORD _OsFree (APP_LPVOID* ppMem);
155 APP_WORD _OsAllocDebug (APP_LPVOID* ppMem,APP_BYTE byValue,APP_DWORD dwLength,APP_LPCHAR szFile,APP_DWORD dwLine);
156 APP_WORD _OsFreeDebug(APP_LPVOID *pMemchar,APP_LPCHAR szFile,APP_DWORD dwLine);
157 /*---------------------------- time management ---------------------*/
158 APP_VOID OsWait_ms (APP_DWORD PauseTime_ms);
159 APP_DWORD OsGetTime_us (APP_VOID);
160 APP_DWORD OsGetTime_ms (APP_VOID);
161 APP_DWORD OsGetUnixTime (APP_VOID); /* Return a date from ....*/
162 
163 /*---------------------------- timer management --------------------*/
164 APP_WORD OsAllocTimer (APP_VOID);
165 APP_WORD OsStartTimer (APP_WORD wDelay);
166 APP_WORD OsStopTimer (APP_WORD wTimerId);
167 APP_WORD OsWaitForTimer ( APP_VOID );
168 
169 /*---------------------------- thread handling ---------------------*/
170 APP_DWORD OsGetCurrentThreadId (void);
171 APP_HANDLE OsGetCurrentThreadHandle(void);
172 /*---------------------------- mutex -------------------------------*/
173 APP_HANDLE OsCreateMutex (APP_LPCHAR szName);
174 APP_VOID OsCloseMutex (APP_HANDLE hMutext);
175 APP_WORD OsReleaseMutex (APP_HANDLE hMutext);
176 
177 APP_HANDLE OsCreateEvent(APP_BOOL ManualReset,APP_BOOL InitialState,APP_LPCHAR szName);
178 APP_BOOL OsSetEvent(APP_HANDLE hEvent);
179 APP_DWORD OsCloseEvent(APP_HANDLE hEvent);
180 APP_BOOL OsResetEvent(APP_HANDLE hEvent);
181 APP_DWORD OsWaitForEvent(APP_HANDLE hEvent,APP_DWORD dwDelay);
182 APP_DWORD OsWaitForMutex(APP_HANDLE hEvent,APP_DWORD dwDelay);
183 APP_VOID OsDestroyCriticalSection (APP_LPHANDLE lphSection);
184 APP_VOID OsLeaveCriticalSection (APP_LPHANDLE lphSection);
185 APP_VOID OsInitializeCriticalSection(APP_LPHANDLE lphSection);
186 APP_VOID OsEnterCriticalSection (APP_LPHANDLE lphSection);
187 
188 void * OsCreateThread (
189  APP_WORD (*TaskEntry)(APP_LPVOID pArg),
190  APP_DWORD TaskPrio,
191  APP_LPVOID pArg,
192  APP_LPDWORD pThreadId,
193  APP_LPCHAR szTaskName );
194 
195 APP_WORD OsResumeThread (APP_HANDLE hThread);
196 
197 typedef struct
198 {
199  APP_VOID (*callback_timeout) (APP_VOID);
200  SEM_ID hTimer;
201  APP_DWORD dwThread;
202  APP_WORD wTimerID;
203  APP_BOOL bRunning;
205 
206 #define _DEBUG_MAX_ALLOC_ 3000
207 
208 #define NB_MAX_DEVICE 30
209 
210 #endif
211 
Definition: os.h:197