Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | |
| 3 | (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29 |
| 4 | www.systec-electronic.com |
| 5 | |
| 6 | Project: openPOWERLINK |
| 7 | |
| 8 | Description: source file for Statusu-Module |
| 9 | |
| 10 | License: |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions |
| 14 | are met: |
| 15 | |
| 16 | 1. Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | |
| 19 | 2. Redistributions in binary form must reproduce the above copyright |
| 20 | notice, this list of conditions and the following disclaimer in the |
| 21 | documentation and/or other materials provided with the distribution. |
| 22 | |
| 23 | 3. Neither the name of SYSTEC electronic GmbH nor the names of its |
| 24 | contributors may be used to endorse or promote products derived |
| 25 | from this software without prior written permission. For written |
| 26 | permission, please contact info@systec-electronic.com. |
| 27 | |
| 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 31 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 32 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 33 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 34 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 35 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 36 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 37 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 38 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 39 | POSSIBILITY OF SUCH DAMAGE. |
| 40 | |
| 41 | Severability Clause: |
| 42 | |
| 43 | If a provision of this License is or becomes illegal, invalid or |
| 44 | unenforceable in any jurisdiction, that shall not affect: |
| 45 | 1. the validity or enforceability in that jurisdiction of any other |
| 46 | provision of this License; or |
| 47 | 2. the validity or enforceability in other jurisdictions of that or |
| 48 | any other provision of this License. |
| 49 | |
| 50 | ------------------------------------------------------------------------- |
| 51 | |
| 52 | $RCSfile: EplStatusu.c,v $ |
| 53 | |
| 54 | $Author: D.Krueger $ |
| 55 | |
| 56 | $Revision: 1.5 $ $Date: 2008/10/17 15:32:32 $ |
| 57 | |
| 58 | $State: Exp $ |
| 59 | |
| 60 | Build Environment: |
| 61 | GCC V3.4 |
| 62 | |
| 63 | ------------------------------------------------------------------------- |
| 64 | |
| 65 | Revision History: |
| 66 | |
| 67 | 2006/11/15 d.k.: start of the implementation |
| 68 | |
| 69 | ****************************************************************************/ |
| 70 | |
| 71 | #include "user/EplStatusu.h" |
| 72 | #include "user/EplDlluCal.h" |
| 73 | |
| 74 | /***************************************************************************/ |
| 75 | /* */ |
| 76 | /* */ |
| 77 | /* G L O B A L D E F I N I T I O N S */ |
| 78 | /* */ |
| 79 | /* */ |
| 80 | /***************************************************************************/ |
| 81 | |
| 82 | //--------------------------------------------------------------------------- |
| 83 | // const defines |
| 84 | //--------------------------------------------------------------------------- |
| 85 | |
| 86 | //--------------------------------------------------------------------------- |
| 87 | // local types |
| 88 | //--------------------------------------------------------------------------- |
| 89 | |
| 90 | //--------------------------------------------------------------------------- |
| 91 | // modul globale vars |
| 92 | //--------------------------------------------------------------------------- |
| 93 | |
| 94 | //--------------------------------------------------------------------------- |
| 95 | // local function prototypes |
| 96 | //--------------------------------------------------------------------------- |
| 97 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 98 | /***************************************************************************/ |
| 99 | /* */ |
| 100 | /* */ |
| 101 | /* C L A S S <xxxxx> */ |
| 102 | /* */ |
| 103 | /* */ |
| 104 | /***************************************************************************/ |
| 105 | // |
| 106 | // Description: |
| 107 | // |
| 108 | // |
| 109 | /***************************************************************************/ |
| 110 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 111 | //=========================================================================// |
| 112 | // // |
| 113 | // P R I V A T E D E F I N I T I O N S // |
| 114 | // // |
| 115 | //=========================================================================// |
| 116 | |
| 117 | //--------------------------------------------------------------------------- |
| 118 | // const defines |
| 119 | //--------------------------------------------------------------------------- |
| 120 | |
| 121 | //--------------------------------------------------------------------------- |
| 122 | // local types |
| 123 | //--------------------------------------------------------------------------- |
| 124 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 125 | typedef struct { |
| 126 | tEplStatusuCbResponse m_apfnCbResponse[254]; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 127 | |
| 128 | } tEplStatusuInstance; |
| 129 | |
| 130 | //--------------------------------------------------------------------------- |
| 131 | // local vars |
| 132 | //--------------------------------------------------------------------------- |
| 133 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 134 | static tEplStatusuInstance EplStatusuInstance_g; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 135 | |
| 136 | //--------------------------------------------------------------------------- |
| 137 | // local function prototypes |
| 138 | //--------------------------------------------------------------------------- |
| 139 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 140 | static tEplKernel EplStatusuCbStatusResponse(tEplFrameInfo *pFrameInfo_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 141 | |
| 142 | //=========================================================================// |
| 143 | // // |
| 144 | // P U B L I C F U N C T I O N S // |
| 145 | // // |
| 146 | //=========================================================================// |
| 147 | |
| 148 | //--------------------------------------------------------------------------- |
| 149 | // |
| 150 | // Function: EplStatusuInit |
| 151 | // |
| 152 | // Description: init first instance of the module |
| 153 | // |
| 154 | // |
| 155 | // |
| 156 | // Parameters: |
| 157 | // |
| 158 | // |
| 159 | // Returns: tEplKernel = errorcode |
| 160 | // |
| 161 | // |
| 162 | // State: |
| 163 | // |
| 164 | //--------------------------------------------------------------------------- |
| 165 | |
Greg Kroah-Hartman | d9068d6 | 2009-03-23 13:26:29 -0700 | [diff] [blame] | 166 | tEplKernel EplStatusuInit(void) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 167 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 168 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 169 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 170 | Ret = EplStatusuAddInstance(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 171 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 172 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 175 | //--------------------------------------------------------------------------- |
| 176 | // |
| 177 | // Function: EplStatusuAddInstance |
| 178 | // |
| 179 | // Description: init other instances of the module |
| 180 | // |
| 181 | // |
| 182 | // |
| 183 | // Parameters: |
| 184 | // |
| 185 | // |
| 186 | // Returns: tEplKernel = errorcode |
| 187 | // |
| 188 | // |
| 189 | // State: |
| 190 | // |
| 191 | //--------------------------------------------------------------------------- |
| 192 | |
Greg Kroah-Hartman | d9068d6 | 2009-03-23 13:26:29 -0700 | [diff] [blame] | 193 | tEplKernel EplStatusuAddInstance(void) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 194 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 195 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 196 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 197 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 198 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 199 | // reset instance structure |
| 200 | EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof(EplStatusuInstance_g)); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 201 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 202 | // register StatusResponse callback function |
| 203 | Ret = |
| 204 | EplDlluCalRegAsndService(kEplDllAsndStatusResponse, |
| 205 | EplStatusuCbStatusResponse, |
| 206 | kEplDllAsndFilterAny); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 207 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 208 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 209 | |
| 210 | } |
| 211 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 212 | //--------------------------------------------------------------------------- |
| 213 | // |
| 214 | // Function: EplStatusuDelInstance |
| 215 | // |
| 216 | // Description: delete instance |
| 217 | // |
| 218 | // |
| 219 | // |
| 220 | // Parameters: |
| 221 | // |
| 222 | // |
| 223 | // Returns: tEplKernel = errorcode |
| 224 | // |
| 225 | // |
| 226 | // State: |
| 227 | // |
| 228 | //--------------------------------------------------------------------------- |
| 229 | |
Greg Kroah-Hartman | d9068d6 | 2009-03-23 13:26:29 -0700 | [diff] [blame] | 230 | tEplKernel EplStatusuDelInstance(void) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 231 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 232 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 233 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 234 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 235 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 236 | // deregister StatusResponse callback function |
| 237 | Ret = |
| 238 | EplDlluCalRegAsndService(kEplDllAsndStatusResponse, NULL, |
| 239 | kEplDllAsndFilterNone); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 240 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 241 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 242 | |
| 243 | } |
| 244 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 245 | //--------------------------------------------------------------------------- |
| 246 | // |
| 247 | // Function: EplStatusuReset |
| 248 | // |
| 249 | // Description: resets this instance |
| 250 | // |
| 251 | // Parameters: |
| 252 | // |
| 253 | // Returns: tEplKernel = errorcode |
| 254 | // |
| 255 | // |
| 256 | // State: |
| 257 | // |
| 258 | //--------------------------------------------------------------------------- |
| 259 | |
Greg Kroah-Hartman | d9068d6 | 2009-03-23 13:26:29 -0700 | [diff] [blame] | 260 | tEplKernel EplStatusuReset(void) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 261 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 262 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 263 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 264 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 265 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 266 | // reset instance structure |
| 267 | EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof(EplStatusuInstance_g)); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 268 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 269 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 270 | |
| 271 | } |
| 272 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 273 | //--------------------------------------------------------------------------- |
| 274 | // |
| 275 | // Function: EplStatusuRequestStatusResponse |
| 276 | // |
| 277 | // Description: returns the StatusResponse for the specified node. |
| 278 | // |
| 279 | // Parameters: uiNodeId_p = IN: node ID |
| 280 | // pfnCbResponse_p = IN: function pointer to callback function |
| 281 | // which will be called if StatusResponse is received |
| 282 | // |
| 283 | // Return: tEplKernel = error code |
| 284 | // |
| 285 | // State: not tested |
| 286 | // |
| 287 | //--------------------------------------------------------------------------- |
| 288 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 289 | tEplKernel EplStatusuRequestStatusResponse(unsigned int uiNodeId_p, |
| 290 | tEplStatusuCbResponse pfnCbResponse_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 291 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 292 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 293 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 294 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 295 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 296 | // decrement node ID, because array is zero based |
| 297 | uiNodeId_p--; |
| 298 | if (uiNodeId_p < tabentries(EplStatusuInstance_g.m_apfnCbResponse)) { |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 299 | #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0) |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 300 | if (EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL) { // request already issued (maybe by someone else) |
| 301 | Ret = kEplInvalidOperation; |
| 302 | } else { |
| 303 | EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] = |
| 304 | pfnCbResponse_p; |
| 305 | Ret = |
| 306 | EplDlluCalIssueRequest(kEplDllReqServiceStatus, |
| 307 | (uiNodeId_p + 1), 0xFF); |
| 308 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 309 | #else |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 310 | Ret = kEplInvalidOperation; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 311 | #endif |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 312 | } else { // invalid node ID specified |
| 313 | Ret = kEplInvalidNodeId; |
| 314 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 315 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 316 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 317 | |
| 318 | } |
| 319 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 320 | //=========================================================================// |
| 321 | // // |
| 322 | // P R I V A T E F U N C T I O N S // |
| 323 | // // |
| 324 | //=========================================================================// |
| 325 | |
| 326 | //--------------------------------------------------------------------------- |
| 327 | // |
| 328 | // Function: EplStatusuCbStatusResponse |
| 329 | // |
| 330 | // Description: callback funktion for StatusResponse |
| 331 | // |
| 332 | // |
| 333 | // |
| 334 | // Parameters: pFrameInfo_p = Frame with the StatusResponse |
| 335 | // |
| 336 | // |
| 337 | // Returns: tEplKernel = error code |
| 338 | // |
| 339 | // |
| 340 | // State: |
| 341 | // |
| 342 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 343 | static tEplKernel EplStatusuCbStatusResponse(tEplFrameInfo *pFrameInfo_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 344 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 345 | tEplKernel Ret = kEplSuccessful; |
| 346 | unsigned int uiNodeId; |
| 347 | unsigned int uiIndex; |
| 348 | tEplStatusuCbResponse pfnCbResponse; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 349 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 350 | uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 351 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 352 | uiIndex = uiNodeId - 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 353 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 354 | if (uiIndex < tabentries(EplStatusuInstance_g.m_apfnCbResponse)) { |
| 355 | // memorize pointer to callback function |
| 356 | pfnCbResponse = EplStatusuInstance_g.m_apfnCbResponse[uiIndex]; |
| 357 | if (pfnCbResponse == NULL) { // response was not requested |
| 358 | goto Exit; |
| 359 | } |
| 360 | // reset callback function pointer so that caller may issue next request |
| 361 | EplStatusuInstance_g.m_apfnCbResponse[uiIndex] = NULL; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 362 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 363 | if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_STATUSRES) { // StatusResponse not received or it has invalid size |
| 364 | Ret = pfnCbResponse(uiNodeId, NULL); |
| 365 | } else { // StatusResponse received |
| 366 | Ret = |
| 367 | pfnCbResponse(uiNodeId, |
| 368 | &pFrameInfo_p->m_pFrame->m_Data. |
| 369 | m_Asnd.m_Payload.m_StatusResponse); |
| 370 | } |
| 371 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 372 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 373 | Exit: |
| 374 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // EOF |