summaryrefslogtreecommitdiff
path: root/lib/visual_state_api/src/SMPInq.c
blob: 007b374bc9cfb4685d94ad9b49e4fbfbc44fda1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * Type:        Source Code File
 * 
 * Id:          SMPInq.c
 *
 * Function:    Contains the SMP_Inquiry, SMP_GetInput and SMP_GetInputAll
 *              SEM Library Expert version 4 functions.
 *
 * Portability: ANSI-C Compiler.
 *
 * Copyright (c) 1999-2006 IAR Systems. All rights reserved.
 */

/*
 * Version   ! Date   ! Status ! Changes
 *----------------------------------------------------------------------------
 * 4.0.0.5   ! 200199 ! Closed ! -
 * 4.0.4     ! 010799 ! Closed ! Minor update, there might be no changes to this particular file.
 * 4.0.4.1   ! 050799 ! Closed ! SMP_GetInput fixed.
 */

#include "SEMLibE.h"


unsigned char SMP_Inquiry (SEM_CONTEXT VS_TQ_CONTEXT *Context)
{
  if (!Context)
    return (SES_NOT_LOADED);
  Context->InqAct = VS_FALSE;
  if (Context->State != STATE_SEM_INITIALIZE)
    return (SES_ACTIVE);
  else
    return (SES_OKAY);
} 


unsigned char SMP_GetInput (SEM_CONTEXT VS_TQ_CONTEXT *Context, 
  SEM_EVENT_TYPE *EventNo, SEM_EVENT_TYPE *EventList)
{
  SEM_RULE_DATA_TYPE rd;
  SEM_RULE_TABLE_INDEX_TYPE iInqFirstR, iInqLastR;
  unsigned char i, InqIt, nPos;
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
  SEM_STATE_TYPE s;
  unsigned char nNeg;
#endif

  if (!Context)
    return (SES_NOT_LOADED);
  if (!Context->InqAct)
    Context->InqEventNo = 0;
  for(;;)
  {
    Context->InqAct = VS_FALSE;
    if (Context->InqEventNo >= Context->nNofEvents)
      break;
    if (EventList)
    {
      Context->InqFoundEventNo = EventList[Context->InqEventNo];
      if (Context->InqFoundEventNo == EVENT_TERMINATION_ID)
        break;
      if (Context->nNofEvents <= Context->InqFoundEventNo)
        return (SES_RANGE_ERR);
    }
    else
      Context->InqFoundEventNo = Context->InqEventNo;
    Context->InqEventNo++;
    Context->InqCurrentEventNo = Context->InqFoundEventNo;
    for (InqIt = 2; InqIt; InqIt--)
    {
#if (SEM_EVENT_GROUP_TABLE_INDEX) || defined VISUALSTATE_EXPERT_DLL
      if (InqIt == 2)
      {
        if (Context->EventGroupType == 2)
        {
          Context->iInqFirstEgi = Context->pEGTI[Context->InqCurrentEventNo];
          Context->iInqLastEgi = Context->pEGTI[Context->InqCurrentEventNo + 1];
        }
      }
#endif
      if (InqIt == 1)
      {
#if (SEM_EVENT_GROUP_INDEX) || defined VISUALSTATE_EXPERT_DLL
        if (Context->EventGroupType == 1)
        {
          Context->InqCurrentEventNo = (SEM_EVENT_TYPE) Context->pEGT[Context->InqCurrentEventNo];
          if (Context->InqCurrentEventNo == EVENT_UNDEFINED)
            break;
          Context->InqCurrentEventNo = (SEM_EVENT_TYPE)(Context->InqCurrentEventNo + Context->nNofEvents);
        }
#endif
#if (SEM_EVENT_GROUP_TABLE_INDEX) || defined VISUALSTATE_EXPERT_DLL
        if (Context->EventGroupType == 2)
        {
          if (Context->iInqFirstEgi == Context->iInqLastEgi)
            break;
          Context->InqCurrentEventNo = (SEM_EVENT_TYPE) Context->pEGT[Context->iInqFirstEgi++];
          Context->InqCurrentEventNo = (SEM_EVENT_TYPE)(Context->InqCurrentEventNo + Context->nNofEvents);
          InqIt++;
        }
#endif
      }
      iInqFirstR = Context->pRTI[Context->InqCurrentEventNo];
      iInqLastR = Context->pRTI[Context->InqCurrentEventNo + 1];
      while (iInqFirstR < iInqLastR)
      {
        Context->iInqRI = Context->pRI[iInqFirstR++];
#if (SEM_RD_WIDTH_8_BIT && SEM_RDHW_TYPE_1 && SEM_RDHW_WIDTH_16_BIT)
       	Context->iInqRI++;
        rd = Context->pRD[Context->iInqRI++];
        nPos = (unsigned char)(rd & 0x0F);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)(rd >> 4);
#endif
#endif
#if (SEM_RD_WIDTH_8_BIT && SEM_RDHW_TYPE_2 && SEM_RDHW_WIDTH_24_BIT)
        rd = Context->pRD[Context->iInqRI];
        Context->iInqRI += 3;
        nPos = (unsigned char)(rd & 0x0F);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)(rd >> 4);
#endif
#endif
#if (SEM_RD_WIDTH_8_BIT && SEM_RDHW_TYPE_1 && SEM_RDHW_WIDTH_32_BIT)
        Context->iInqRI += 2;
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)Context->pRD[Context->iInqRI++];
#else
        Context->iInqRI++;
#endif
        nPos = (unsigned char)Context->pRD[Context->iInqRI++];
#endif
#if (SEM_RD_WIDTH_8_BIT && SEM_RDHW_TYPE_2 && SEM_RDHW_WIDTH_48_BIT)
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)Context->pRD[Context->iInqRI++];
#else
        Context->iInqRI++;
#endif
        nPos = (unsigned char)Context->pRD[Context->iInqRI];
        Context->iInqRI += 5;
#endif
#if (SEM_RD_WIDTH_16_BIT && SEM_RDHW_TYPE_1 && SEM_RDHW_WIDTH_16_BIT)
        rd = Context->pRD[Context->iInqRI++];
        nPos = (unsigned char)(rd & 0x0F);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)((rd >> 4) & 0x0F);
#endif
#endif
#if (SEM_RD_WIDTH_16_BIT && SEM_RDHW_TYPE_3 && SEM_RDHW_WIDTH_32_BIT)
        rd = Context->pRD[Context->iInqRI++];
        nPos = (unsigned char)(rd & 0x0F);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)((rd >> 4) & 0x0F);
#endif
        Context->iInqRI += 1;
#endif
#if (SEM_RD_WIDTH_16_BIT && SEM_RDHW_TYPE_1 && SEM_RDHW_WIDTH_32_BIT)
        Context->iInqRI++;
        rd = Context->pRD[Context->iInqRI++];
        nPos = (unsigned char)(rd & 0x0FF);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)(rd >> 8);
#endif
#endif
#if (SEM_RD_WIDTH_16_BIT && SEM_RDHW_TYPE_2 && SEM_RDHW_WIDTH_48_BIT)
        rd = Context->pRD[Context->iInqRI];
        Context->iInqRI += 3;
        nPos = (unsigned char)(rd & 0x0FF);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)(rd >> 8);
#endif
#endif
#if (SEM_RD_WIDTH_32_BIT && SEM_RDHW_TYPE_1 && SEM_RDHW_WIDTH_32_BIT)
        rd = Context->pRD[Context->iInqRI++];
        nPos = (unsigned char)(rd & 0X0FF);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)((rd >> 8) & 0X0FF);
#endif
#endif
#if (SEM_RD_WIDTH_32_BIT && SEM_RDHW_TYPE_3 && SEM_RDHW_WIDTH_64_BIT)
        rd = Context->pRD[Context->iInqRI++];
        nPos = (unsigned char)(rd & 0x0FF);
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        nNeg = (unsigned char)((rd >> 8) & 0x0FF);
#endif
        Context->iInqRI++;
#endif
        for (i = 0; i < nPos; i++)
        {
          rd = Context->pRD[Context->iInqRI++];
          if (rd != Context->pCSV[Context->pSMI[rd]])
            goto NextRule;
        }
#if (SEM_RMN_NEGATIVE_STATE_SYNCS || defined VISUALSTATE_EXPERT_DLL)
        for (i = 0; i < nNeg; i++)
        {
          rd = Context->pRD[Context->iInqRI++];
          s = Context->pCSV[Context->pSMI[rd]];
          if ((s == STATE_UNDEFINED) || (s == (SEM_STATE_TYPE) rd))
            goto NextRule;
        }
#endif
        Context->InqAct = VS_TRUE;
        *EventNo = Context->InqFoundEventNo;
        return (SES_FOUND);
NextRule :
        ;
      }
    }
  }
  return (SES_OKAY);
} 


#if defined SEM_GET_INPUT_ALL || defined VISUALSTATE_EXPERT_DLL
unsigned char SMP_GetInputAll (SEM_CONTEXT VS_TQ_CONTEXT *Context, 
  SEM_EVENT_TYPE *EventVector, SEM_EVENT_TYPE *EventList, 
  SEM_EVENT_TYPE MaxSize)
{
  SEM_EVENT_TYPE i;
  unsigned char CC;

  if (!Context)
    return (SES_NOT_LOADED);

  for (i = 0; ((CC = SMP_GetInput (Context, &EventVector[i], EventList)) == SES_FOUND) 
    && i < MaxSize - 1; i++);

  if (CC == SES_OKAY)
  {
    EventVector[i] = EVENT_TERMINATION_ID;
    return (SES_OKAY);
  }
  if (CC == SES_FOUND)
    return (SES_BUFFER_OVERFLOW);
  return (CC);
} 
#endif