OpenEL  3.0.0
openEL.c
Go to the documentation of this file.
1 
12 /*
13 
14 Copyright (c) 2017,2018 Japan Embedded Systems Technology Association(JASA)
15 All rights reserved.
16 
17 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
18 
19  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
20  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
21  Neither the name of the Association nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 
26 /* Includes */
27 /*---------------------------------------------------------------------------*/
28 
29 #define OPENEL_SW_SURFACE_FRIEND 1
30 #include "openEL.h"
31 
32 #include "stdio.h"
33 
34 /* Macro (module scope) */
35 /*---------------------------------------------------------------------------*/
36 
37 
38 /* Variable (global scope) */
39 /*---------------------------------------------------------------------------*/
40 
41 /* Variable (friend scope) */
42 /*---------------------------------------------------------------------------*/
43 
45 
46 static int32_t elPortMst = 0;
48 /* Variable (module scope) */
49 /*---------------------------------------------------------------------------*/
50 
51 /* Function prototype (module scope) */
52 /*---------------------------------------------------------------------------*/
53 
54 static int32_t elInit_old(uint32_t handle,EL_CMN_FNC_TBL_T fncTbl,uint32_t compoIndex);
55 static int32_t elGetNewHandle(void);
56 static EL_CMN_FNC_TBL_T elGetComponent(int32_t vendorID, int32_t compoID);
57 
58 /* Functions */
59 /*---------------------------------------------------------------------------*/
75 enum ReturnCode HalInit(HALCOMPONENT_T *halComponent) {
76  int32_t retVal;
77  EL_CMN_FNC_TBL_T pFncTbl;
78  int32_t hn;
79  printf("HalInit():%x,%x,%x\n", halComponent->halComponent_core.halId.vendorId, halComponent->halComponent_core.halId.productId, halComponent->halComponent_core.halId.instanceId);
80 
81  pFncTbl = elGetComponent(halComponent->halComponent_core.halId.vendorId, halComponent->halComponent_core.halId.productId);
82 
83  if ( (hn = elGetNewHandle()) < 0 ) {
84  return HAL_ERROR;
85  }
86  printf("hn = %d\n", hn);
87  retVal = elInit_old(hn,pFncTbl,halComponent->halComponent_core.halId.instanceId);
88  if (retVal < 0 ) {
89  return HAL_ERROR;
90  } else {
91  halComponent->halComponent_core.handle = hn;
92  }
93 
94  return HAL_OK;
95 }
96 /*---------------------------------------------------------------------------*/
104 int32_t elInit_old(uint32_t handle,EL_CMN_FNC_TBL_T fncTbl,uint32_t compoIndex) {
105  if ( (handle > EL_PORT_ID_MAX) || (0 != elPortTbl[handle].physicalPortID) ) {
106  return HAL_ERROR;
107  }
108  elPortTbl[handle].physicalPortID = compoIndex;
109  elPortTbl[handle].fncTbl = fncTbl;
110  return elPortTbl[handle].fncTbl.pGeneral->pFncInit(elPortTbl[handle].physicalPortID,handle);
111 }
112 /*---------------------------------------------------------------------------*/
114 enum ReturnCode HalReInit(HALCOMPONENT_T *halComponent) {
115  int32_t rVal;
116 #if 1 == EL_SW_FAST
117  uint32_t physicalhandle = elPortTbl[*halComponent->halComponent_core.handle].physicalhandle;
118 #else
119  uint32_t physicalhandle;
120  if ( 0 == (physicalhandle = elGetPhyicalPortID(halComponent->halComponent_core.handle,0)) ) {
121  return HAL_ERROR;
122  }
123 #endif
124  rVal = elPortTbl[halComponent->halComponent_core.handle].fncTbl.pGeneral->pFncReInit(physicalhandle);
125  return rVal;
126 }
127 
128 /*---------------------------------------------------------------------------*/
130 enum ReturnCode HalFinalize(HALCOMPONENT_T *halComponent) {
131  int32_t rVal;
132 #if 1 == EL_SW_FAST
133  uint32_t physicalhandle = elPortTbl[halComponent->halComponent_core.handle].physicalhandle;
134 #else
135  uint32_t physicalhandle;
136  if ( 0 == (physicalhandle = elGetPhyicalPortID(halComponent->halComponent_core.handle,0)) ) {
137  return HAL_ERROR;
138  }
139 #endif
140 
141  rVal = elPortTbl[halComponent->halComponent_core.handle].fncTbl.pGeneral->pFncFinalize(physicalhandle);
142  elPortTbl[halComponent->halComponent_core.handle].physicalPortID = 0; /* Clear physicalPortID */
143  return rVal;
144 }
145 
146 enum ReturnCode HalAddObserver(HALCOMPONENT_T *halComponent, HALOBSERVER_T *halObserver) {
147  printf("HalAddObserver\n");
148  halComponent->halComponent_core.observerList[0] = *halObserver;
149  return HAL_OK;
150 }
151 
152 enum ReturnCode HalRemoveObserver(HALCOMPONENT_T *halComponent, HALOBSERVER_T *halObserver) {
153  printf("HalRemoveObserver\n");
154  return HAL_OK;
155 }
156 
157 enum ReturnCode HalGetProperty(HALCOMPONENT_T *halComponent, PROPERTY_T *property) {
158  printf("HalGetProperty\n");
159  return HAL_OK;
160 }
161 
162 enum ReturnCode HalGetTime(HALCOMPONENT_T *halComponent, int32_t *time) {
163  printf("HalGetTime\n");
164  return HAL_OK;
165 }
166 
168  printf("HalEventTimerStartTimer\n");
169  eventTimer->observerList[0].notify_timer(eventTimer);
170  return HAL_OK;
171 }
172 
174  printf("HalEventTimerStopTimer\n");
175  return HAL_OK;
176 }
177 
178 enum ReturnCode HalEventTimerSetEventPeriod(EVENTTIMER_T *eventTimer, int32_t eventPeriod) {
179  printf("HalEventTimerSetEventPeriod\n");
180  return HAL_OK;
181 }
182 
184  printf("HalEventTimerAddObserver\n");
185  eventTimer->observerList[0] = *timerObserver;
186  return HAL_OK;
187 }
188 
190  printf("HalEventTimerRemoveObserver\n");
191  return HAL_OK;
192 }
193 
194 /*---------------------------------------------------------------------------*/
196 int32_t elGetPhyicalPortID(uint32_t handle,uint32_t profileID) {
197  uint32_t phyID;
198  if ( handle <= EL_PORT_ID_MAX ) {
199  phyID = elPortTbl[handle].physicalPortID;
200 // printf("OK:phyID=%d\n", phyID);
201  } else {
202 // printf("NG:phyID=0\n");
203  phyID = 0;
204  }
205 
206  return phyID;
207 }
208 
209 /*---------------------------------------------------------------------------*/
214 static int32_t elGetNewHandle(void) {
215  if ( elPortMst < EL_PORT_ID_MAX ) {
216  elPortMst++;
217  } else {
218  elPortMst = -1;
219  }
220 
221  return elPortMst;
222 }
223 
224 /*---------------------------------------------------------------------------*/
226 EL_CMN_FNC_TBL_T elGetComponent(int32_t vendorID, int32_t compoID) {
227  const EL_CMN_FNC_TBL_T noCompo = { (void *)0};
228  struct elCompoTbl_st *pCompo = (struct elCompoTbl_st *)elCompoTbl;
229  uint32_t idx = 0;
230 
231  while (idx++ < elSzCompoTbl ) {
232  if ( (pCompo->vendorID == vendorID) && (pCompo->componentID == compoID) ) {
233  return *(pCompo->pFncTbl);
234  }
235  pCompo++;
236  }
237  return noCompo;
238 }
239 
240 /*---------------------------------------------------------------------------*/
struct elPort_st elPortTbl[EL_PORT_ID_MAX]
Definition: openEL.c:44
enum ReturnCode HalAddObserver(HALCOMPONENT_T *halComponent, HALOBSERVER_T *halObserver)
Definition: openEL.c:146
enum ReturnCode HalEventTimerStopTimer(EVENTTIMER_T *eventTimer)
Definition: openEL.c:173
const struct elCompoTbl_st elCompoTbl[]
enum ReturnCode(* pFncInit)()
Definition: openEL.h:176
OpenEL Common Header File 3.0.0.
HALCOMPONENT_CORE_T halComponent_core
Definition: openEL.h:163
EL_CMN_FNC_TBL_T fncTbl
Definition: openEL.h:226
enum ReturnCode HalGetProperty(HALCOMPONENT_T *halComponent, PROPERTY_T *property)
Definition: openEL.c:157
EL_GENERAL_FNC_TBL_T * pGeneral
Definition: openEL.h:215
enum ReturnCode HalGetTime(HALCOMPONENT_T *halComponent, int32_t *time)
Definition: openEL.c:162
ReturnCode
Definition: openEL.h:44
uint32_t physicalPortID
Definition: openEL.h:225
enum ReturnCode HalFinalize(HALCOMPONENT_T *halComponent)
Definition: openEL.c:130
#define EL_PORT_ID_MAX
Definition: openEL.h:237
uint32_t vendorID
Definition: openEL.h:231
enum ReturnCode HalEventTimerAddObserver(EVENTTIMER_T *eventTimer, TIMEROBSERVER_T *timerObserver)
Definition: openEL.c:183
EL_CMN_FNC_TBL_T * pFncTbl
Definition: openEL.h:233
enum ReturnCode(* pFncReInit)()
Definition: openEL.h:177
void(* notify_timer)(EVENTTIMER_T *eventTimer)
Definition: openEL.h:102
enum ReturnCode HalRemoveObserver(HALCOMPONENT_T *halComponent, HALOBSERVER_T *halObserver)
Definition: openEL.c:152
enum ReturnCode HalReInit(HALCOMPONENT_T *halComponent)
Definition: openEL.c:114
enum ReturnCode HalEventTimerSetEventPeriod(EVENTTIMER_T *eventTimer, int32_t eventPeriod)
Definition: openEL.c:178
enum ReturnCode HalInit(HALCOMPONENT_T *halComponent)
Definition: openEL.c:75
uint32_t componentID
Definition: openEL.h:232
Definition: openEL.h:45
const uint32_t elSzCompoTbl
TIMEROBSERVER_T observerList[8]
Definition: openEL.h:106
enum ReturnCode HalEventTimerStartTimer(EVENTTIMER_T *eventTimer)
Definition: openEL.c:167
enum ReturnCode HalEventTimerRemoveObserver(EVENTTIMER_T *eventTimer, TIMEROBSERVER_T *timerObserver)
Definition: openEL.c:189
enum ReturnCode(* pFncFinalize)()
Definition: openEL.h:178
int32_t elGetPhyicalPortID(uint32_t handle, uint32_t profileID)
Definition: openEL.c:196