versadac  1
versadac - Scalable Recorder Firmware
stk_thd.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 : Thread manager */
15 /* $Workfile:: stk_thd.h $*/
16 /* $Revision:: 3 $*/
17 /* $Date:: 27/04/10 11:27 $*/
18 /* */
19 /*---------------------------------------------------------------------------*/
20 /* */
21 /* D e s c r i p t i o n : */
22 /* abstraction layer for thread */
23 /* */
24 /*---------------------------------------------------------------------------*/
25 
26 #ifndef __STK_THD_H__
27 #define __STK_THD_H__
28 
29 
30 /*-----------------------------------------------------------------------*/
31 /* system */
32 /*-----------------------------------------------------------------------*/
33 
34 #define MAXNUM_OF_TASKS_SYSTEM 14 /* Number of task or thread (Thread 0 / Queue 0 = Error Queue)*/
35 
36 #define MAXNUM_OF_QUEUE_SYSTEM ID_QUEUE_MAX /* Normaly 1 Queue = 1 Task or Thread
37  But to be able in the future to cut some Task/Thread
38  Some QueueID could redirect to the same Thread
39  */
40 
41 #define MAXNUM_OF_TASK_APPLICATE (5+MAX_DEVICE) /* Normaly 1 Queue = 1 Task or Thread
42  But to be able in the future to cut some Task/Thread
43  Some QueueID could redirect to the same Thread
44  */
45 
46 #define MAXNUM_OF_QUEUE (MAXNUM_OF_QUEUE_SYSTEM + MAXNUM_OF_TASK_APPLICATE)
47 #define MAXNUM_OF_TASKS (MAXNUM_OF_TASKS_SYSTEM + MAXNUM_OF_TASK_APPLICATE)
48 
49 #define TASK_BLOCKED 0
50 #define TASK_ENABLED 1
51 #define TASK_OPERATING 2
52 
53 #define INVALID_TASK_ID 0
54 
55 #define MAX_TASK_NAME_SIZE 32
56 typedef struct _task_prop
57 {
58  APP_DWORD volatile dwState; /* Task state (BLOCKED/ENABLED/OPERATING)*/
59  ST_POOL stPool;
60  APP_HANDLE hSection; /* Use to protect queue*/
61  APP_HANDLE hEvent; /* Use to block read in queue if no message*/
62  APP_DWORD dwIdThread;
63  APP_HANDLE hThread;
64  APP_CHAR szTaskName[MAX_TASK_NAME_SIZE]; /* Nom du thread*/
65  APP_DWORD dwLastTime;
66  APP_DWORD dwCycle;
67  APP_DWORD dwCycleMin;
68  APP_DWORD dwCycleMax;
69  APP_DWORD dwNbMsg;
70  APP_BOOL bOccupied; /* valid, if value = 1, 0: invalid*/
72 
73 
74 APP_DWORD StackGetThreadId (void);
75 APP_WORD StackDestroyThread(APP_DWORD TaskId);
76 
77 APP_VOID StackInitializeCriticalSectionThread(APP_LONG lTaskId);
78 APP_VOID StackDestroyCriticalSectionThread(APP_LONG lTaskId);
79 APP_VOID StackEnterCriticalSectionThread(APP_LONG lTaskId);
80 APP_VOID StackLeaveCriticalSectionThread(APP_LONG lTaskId);
81 APP_BOOL CreateEventThread(APP_LONG lTaskId,APP_BOOL ManualReset,APP_BOOL InitialState,APP_LPCHAR szName);
82 APP_DWORD CloseEventThread(APP_LONG lTaskId);
83 APP_BOOL SetEventThread(APP_LONG lTaskId);
84 APP_BOOL ResetEventThread(APP_LONG lTaskId);
85 APP_DWORD StackGetTaskState(APP_LONG lTaskId);
86 APP_VOID StackSetTaskState(APP_LONG lTaskId, APP_DWORD dwState);
87 LPST_POOL GetQueueThread(APP_LONG lTaskId);
88 APP_HANDLE GetEventThread(APP_LONG lTaskId);
89 
90 APP_DWORD WaitForEventThread(APP_LONG lTaskId,APP_DWORD dwDelay);
91 
92 #ifdef OS_DEBUG
93 APP_VOID StackIncNbMsgThread (APP_DWORD dwThreadId);
94 APP_VOID StackDecNbMsgThread (APP_DWORD dwThreadId);
95 APP_VOID StackResetNbMsgThread(APP_DWORD dwThreadId);
96 #endif
97 
98 APP_VOID Monitor_Init_Task_cycle(APP_LONG lTaskId);
99 APP_VOID Monitor_Set_Task_cycle(APP_LONG lTaskId);
100 
101 APP_WORD StackStartThread ( APP_DWORD dwThreadId);
102 
103 APP_VOID StackInitManagmentThread();
104 
105 
106 APP_BOOL StackIsFreeThread(APP_LONG lTaskId);
107 APP_VOID StackSetOccupiedThread(APP_LONG lTaskId,APP_BOOL bState);
108 
109 APP_WORD StackCreateThread (
110  APP_WORD (*TaskEntry)(APP_LPVOID pArg), /* [in ]pointer to task handler */
111  APP_DWORD TaskPrio, /* [in ]task priority */
112  APP_LPVOID pArg,
113  APP_DWORD* pTaskId, /* [out] pointer to Task ID */
114  APP_LPCHAR szTaskName );
115 
116 APP_WORD StackWaitOnEnableThread();
117 APP_WORD StackWaitOnDisableThread();
118 APP_BOOL StackThreadIsDisable(APP_LONG lTaskId);
119 
120 #endif
121 
Definition: stk_thd.h:56