Revision 85e62aaf

View differences:

core/src/aos_main.cpp
125 125
static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags)
126 126
{
127 127
#if (AMIROOS_CFG_DBG == true)
128
  aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
128
    aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
129 129
#else
130
  (void)(mask);
131
  (void)(flags);
130
    (void)(mask);
131
    (void)(flags);
132 132
#endif
133
  return;
133
    return;
134 134
}
135 135

  
136 136

  
......
142 142
 */
143 143
static void _ssspTimerCallback(void* par)
144 144
{
145
  aosDbgCheck(par != NULL);
145
    aosDbgCheck(par != NULL);
146 146

  
147
  chSysLockFromISR();
148
  chEvtBroadcastI((event_source_t*)par);
149
  chSysUnlockFromISR();
147
    chSysLockFromISR();
148
    chEvtBroadcastI((event_source_t*)par);
149
    chSysUnlockFromISR();
150 150

  
151
  return;
151
    return;
152 152
}
153 153
#endif
154 154
/**
......
160 160
 */
161 161
inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n)
162 162
{
163
  aosDbgCheck(dst != NULL);
164
  aosDbgCheck(n > 0 && n <= 8);
163
    aosDbgCheck(dst != NULL);
164
    aosDbgCheck(n > 0 && n <= 8);
165 165

  
166
  for (uint8_t byte = 0; byte < n; ++byte) {
167
    dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF);
168
  }
166
    for (uint8_t byte = 0; byte < n; ++byte) {
167
        dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF);
168
    }
169 169

  
170
  return;
170
    return;
171 171
}
172 172

  
173 173
/**
......
180 180
 */
181 181
inline uint64_t _deserialize(uint8_t* src, const uint8_t n)
182 182
{
183
  aosDbgCheck(src != NULL);
184
  aosDbgCheck(n > 0 && n <= 8);
183
    aosDbgCheck(src != NULL);
184
    aosDbgCheck(n > 0 && n <= 8);
185 185

  
186
  uint64_t result = 0;
187
  for (uint8_t byte = 0; byte < n; ++byte) {
188
    result |= ((uint64_t)src[byte]) << (byte * 8);
189
  }
186
    uint64_t result = 0;
187
    for (uint8_t byte = 0; byte < n; ++byte) {
188
        result |= ((uint64_t)src[byte]) << (byte * 8);
189
    }
190 190

  
191
  return result;
191
    return result;
192 192
}
193 193

  
194 194
/**
......
210 210
 */
211 211
inline uint64_t _TM2U64(struct tm* src)
212 212
{
213
  aosDbgCheck(src != NULL);
214

  
215
  return (((uint64_t)(src->tm_sec  & 0x0000003F) << (0))               |
216
          ((uint64_t)(src->tm_min  & 0x0000003F) << (6))               |
217
          ((uint64_t)(src->tm_hour & 0x0000001F) << (12))              |
218
          ((uint64_t)(src->tm_mday & 0x0000001F) << (17))              |
219
          ((uint64_t)(src->tm_mon  & 0x0000000F) << (22))              |
220
          ((uint64_t)(src->tm_year & 0x00FFFFFF) << (26))              |
221
          ((uint64_t)(src->tm_wday & 0x00000007) << (50))              |
222
          ((uint64_t)(src->tm_yday & 0x000001FF) << (53))              |
223
          ((uint64_t)((src->tm_isdst == 0) ? 0 : (src->tm_isdst > 0) ? 1 : 2) << (62)));
213
    aosDbgCheck(src != NULL);
214

  
215
    return (((uint64_t)(src->tm_sec  & 0x0000003F) << (0))               |
216
            ((uint64_t)(src->tm_min  & 0x0000003F) << (6))               |
217
            ((uint64_t)(src->tm_hour & 0x0000001F) << (12))              |
218
            ((uint64_t)(src->tm_mday & 0x0000001F) << (17))              |
219
            ((uint64_t)(src->tm_mon  & 0x0000000F) << (22))              |
220
            ((uint64_t)(src->tm_year & 0x00FFFFFF) << (26))              |
221
            ((uint64_t)(src->tm_wday & 0x00000007) << (50))              |
222
            ((uint64_t)(src->tm_yday & 0x000001FF) << (53))              |
223
            ((uint64_t)((src->tm_isdst == 0) ? 0 : (src->tm_isdst > 0) ? 1 : 2) << (62)));
224 224
}
225 225

  
226 226
/**
......
233 233
 */
234 234
inline void _U642TM(struct tm* dst, const uint64_t src)
235 235
{
236
  aosDbgCheck(dst != NULL);
237

  
238
  dst->tm_sec  = (src >> 0)  & 0x0000003F;
239
  dst->tm_min  = (src >> 6)  & 0x0000003F;
240
  dst->tm_hour = (src >> 12) & 0x0000001F;
241
  dst->tm_mday = (src >> 17) & 0x0000001F;
242
  dst->tm_mon  = (src >> 22) & 0x0000000F;
243
  dst->tm_year = (src >> 26) & 0x00FFFFFF;
244
  dst->tm_wday = (src >> 50) & 0x00000007;
245
  dst->tm_yday = (src >> 53) & 0x000001FF;
246
  dst->tm_isdst = (((src >> 62) & 0x03) == 0) ? 0 : (((src >> 62) & 0x03) > 0) ? 1 : -1;
247

  
248
  return;
236
    aosDbgCheck(dst != NULL);
237

  
238
    dst->tm_sec  = (src >> 0)  & 0x0000003F;
239
    dst->tm_min  = (src >> 6)  & 0x0000003F;
240
    dst->tm_hour = (src >> 12) & 0x0000001F;
241
    dst->tm_mday = (src >> 17) & 0x0000001F;
242
    dst->tm_mon  = (src >> 22) & 0x0000000F;
243
    dst->tm_year = (src >> 26) & 0x00FFFFFF;
244
    dst->tm_wday = (src >> 50) & 0x00000007;
245
    dst->tm_yday = (src >> 53) & 0x000001FF;
246
    dst->tm_isdst = (((src >> 62) & 0x03) == 0) ? 0 : (((src >> 62) & 0x03) > 0) ? 1 : -1;
247

  
248
    return;
249 249
}
250 250
#if (AMIROOS_CFG_SSSP_ENABLE == true)
251 251
/**
......
257 257
 */
258 258
aos_shutdown_t _ssspModuleStackInitialization(void)
259 259
{
260
  // local types
261
  /**
260
    // local types
261
    /**
262 262
   * @brief   States for the internal state machine to implement SSSP startup stage 3.
263 263
   */
264
  typedef enum {
265
    STAGE_3_1,                  /**< Initiation of SSSP startup stage 3. */
266
    STAGE_3_2,                  /**< Starting the sequence and broadcasting the first ID. */
267
    STAGE_3_3_WAITFORFIRSTID,   /**< Waiting for first ID after initiation. */
268
    STAGE_3_3_WAITFORIDORSIG,   /**< Waiting for next ID or activation of neighbor signal. */
269
    STAGE_3_3_WAITFORID,        /**< Waiting for next ID (after the module has set its own ID). */
270
    STAGE_3_4_FINISH,           /**< Successful finish of stage 3. */
271
    STAGE_3_4_ABORT_ACTIVE,     /**< Aborting stage 3 (active). */
272
    STAGE_3_4_ABORT,            /**< Aborting stage 3 (passive). */
273
  } sssp_modulestackinitstage_t;
274

  
275
  typedef struct {
276
    bool loop     : 1;
277
    bool wfe      : 1;
278
    bool wfe_next : 1;
279
  } flags_t;
280

  
281
  // local variables
282
  aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
283
  sssp_modulestackinitstage_t stage = STAGE_3_1;
284
  eventmask_t eventmask = 0;
285
  eventflags_t ioflags;
286
  event_source_t eventSourceTimeout;
287
  event_source_t eventSourceDelay;
288
  event_listener_t eventListenerTimeout;
289
  event_listener_t eventListenerDelay;
290
  event_listener_t eventListenerCan;
291
  virtual_timer_t timerTimeout;
292
  virtual_timer_t timerDelay;
293
  CANTxFrame canTxFrame;
294
  CANRxFrame canRxFrame;
264
    typedef enum {
265
        STAGE_3_1,                  /**< Initiation of SSSP startup stage 3. */
266
        STAGE_3_2,                  /**< Starting the sequence and broadcasting the first ID. */
267
        STAGE_3_3_WAITFORFIRSTID,   /**< Waiting for first ID after initiation. */
268
        STAGE_3_3_WAITFORIDORSIG,   /**< Waiting for next ID or activation of neighbor signal. */
269
        STAGE_3_3_WAITFORID,        /**< Waiting for next ID (after the module has set its own ID). */
270
        STAGE_3_4_FINISH,           /**< Successful finish of stage 3. */
271
        STAGE_3_4_ABORT_ACTIVE,     /**< Aborting stage 3 (active). */
272
        STAGE_3_4_ABORT,            /**< Aborting stage 3 (passive). */
273
    } sssp_modulestackinitstage_t;
274

  
275
    typedef struct {
276
        bool loop     : 1;
277
        bool wfe      : 1;
278
        bool wfe_next : 1;
279
    } flags_t;
280

  
281
    // local variables
282
    aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
283
    sssp_modulestackinitstage_t stage = STAGE_3_1;
284
    eventmask_t eventmask = 0;
285
    eventflags_t ioflags;
286
    event_source_t eventSourceTimeout;
287
    event_source_t eventSourceDelay;
288
    event_listener_t eventListenerTimeout;
289
    event_listener_t eventListenerDelay;
290
    event_listener_t eventListenerCan;
291
    virtual_timer_t timerTimeout;
292
    virtual_timer_t timerDelay;
293
    CANTxFrame canTxFrame;
294
    CANRxFrame canRxFrame;
295 295
#if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true)
296
  aos_ssspmoduleid_t lastid = 0;
297
#endif
298
  flags_t flags;
299

  
300
  // initialize local varibles
301
  chEvtObjectInit(&eventSourceTimeout);
302
  chEvtObjectInit(&eventSourceDelay);
303
  chVTObjectInit(&timerTimeout);
304
  chVTObjectInit(&timerDelay);
305
  canTxFrame.RTR = CAN_RTR_DATA;
306
  canTxFrame.IDE = CAN_IDE_STD;
307
  flags.loop = true;
308
  flags.wfe = false; // do not wait for events in the initial iteration of the FSM loop
309
  flags.wfe_next = true;
310

  
311
  // initialize system variables
312
  aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
313
  aos.sssp.moduleId = 0;
314

  
315
  // listen to events (timout, delay, CAN receive)
316
  chEvtRegisterMask(&eventSourceTimeout, &eventListenerTimeout, TIMEOUTEVENT_MASK);
317
  chEvtRegisterMask(&eventSourceDelay, &eventListenerDelay, DELAYEVENT_MASK);
318
  chEvtRegisterMask(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan, CANEVENT_MASK);
319

  
320
  /*
296
    aos_ssspmoduleid_t lastid = 0;
297
#endif
298
    flags_t flags;
299

  
300
    // initialize local varibles
301
    chEvtObjectInit(&eventSourceTimeout);
302
    chEvtObjectInit(&eventSourceDelay);
303
    chVTObjectInit(&timerTimeout);
304
    chVTObjectInit(&timerDelay);
305
    canTxFrame.RTR = CAN_RTR_DATA;
306
    canTxFrame.IDE = CAN_IDE_STD;
307
    flags.loop = true;
308
    flags.wfe = false; // do not wait for events in the initial iteration of the FSM loop
309
    flags.wfe_next = true;
310

  
311
    // initialize system variables
312
    aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
313
    aos.sssp.moduleId = 0;
314

  
315
    // listen to events (timout, delay, CAN receive)
316
    chEvtRegisterMask(&eventSourceTimeout, &eventListenerTimeout, TIMEOUTEVENT_MASK);
317
    chEvtRegisterMask(&eventSourceDelay, &eventListenerDelay, DELAYEVENT_MASK);
318
    chEvtRegisterMask(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan, CANEVENT_MASK);
319

  
320
    /*
321 321
   * FSM in a loop.
322 322
   *
323 323
   * This is a fully event-based FSM for the module stack initialization
......
344 344
   *  delays:     Depending on the current state, delays are required by SSSP
345 345
   *              for timing of the sequential activation of signals.
346 346
   */
347
  aosDbgPrintf("SSSP stack initialization sequence:\n");
348
  while (flags.loop) {
347
    aosDbgPrintf("SSSP stack initialization sequence:\n");
348
    while (flags.loop) {
349 349
#if (AMIROOS_CFG_DBG == true)
350
    switch (stage) {
351
      case STAGE_3_1:
352
        aosDbgPrintf(">>> 3-1\n");
353
        break;
354
      case STAGE_3_2:
355
        aosDbgPrintf(">>> 3-2\n");
356
        break;
357
      case STAGE_3_3_WAITFORFIRSTID:
358
        aosDbgPrintf(">>> 3-3 (1st ID)\n");
359
        break;
360
      case STAGE_3_3_WAITFORIDORSIG:
361
        aosDbgPrintf(">>> 3-3 (ID/sig)\n");
362
        break;
363
      case STAGE_3_3_WAITFORID:
364
        aosDbgPrintf(">>> 3-3 (ID)\n");
365
        break;
366
      case STAGE_3_4_FINISH:
367
        aosDbgPrintf(">>> 3-4 (finish)\n");
368
        break;
369
      case STAGE_3_4_ABORT_ACTIVE:
370
        aosDbgPrintf(">>> 3-4 (active abort)\n");
371
        break;
372
      case STAGE_3_4_ABORT:
373
        aosDbgPrintf(">>> 3-4 (abort)\n");
374
        break;
375
    }
350
        switch (stage) {
351
        case STAGE_3_1:
352
            aosDbgPrintf(">>> 3-1\n");
353
            break;
354
        case STAGE_3_2:
355
            aosDbgPrintf(">>> 3-2\n");
356
            break;
357
        case STAGE_3_3_WAITFORFIRSTID:
358
            aosDbgPrintf(">>> 3-3 (1st ID)\n");
359
            break;
360
        case STAGE_3_3_WAITFORIDORSIG:
361
            aosDbgPrintf(">>> 3-3 (ID/sig)\n");
362
            break;
363
        case STAGE_3_3_WAITFORID:
364
            aosDbgPrintf(">>> 3-3 (ID)\n");
365
            break;
366
        case STAGE_3_4_FINISH:
367
            aosDbgPrintf(">>> 3-4 (finish)\n");
368
            break;
369
        case STAGE_3_4_ABORT_ACTIVE:
370
            aosDbgPrintf(">>> 3-4 (active abort)\n");
371
            break;
372
        case STAGE_3_4_ABORT:
373
            aosDbgPrintf(">>> 3-4 (abort)\n");
374
            break;
375
        }
376 376
#endif
377 377

  
378
    // reset wfe flag for the next iteration
379
    flags.wfe_next = true;
378
        // reset wfe flag for the next iteration
379
        flags.wfe_next = true;
380 380

  
381
    // waiting for events may be skipped
382
    if (flags.wfe) {
383
      // wait for any event to occur
384
      aosDbgPrintf("WFE...");
385
      eventmask = chEvtWaitAnyTimeout(ALL_EVENTS, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT));
386
      aosDbgPrintf("\t0x%08X", eventmask);
387
    } else {
388
      aosDbgPrintf("WFE skipped");
389
    }
390
    aos_timestamp_t uptime;
391
    aosSysGetUptime(&uptime);
392
    aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / 1000));
381
        // waiting for events may be skipped
382
        if (flags.wfe) {
383
            // wait for any event to occur
384
            aosDbgPrintf("WFE...");
385
            eventmask = chEvtWaitAnyTimeout(ALL_EVENTS, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT));
386
            aosDbgPrintf("\t0x%08X", eventmask);
387
        } else {
388
            aosDbgPrintf("WFE skipped");
389
        }
390
        aos_timestamp_t uptime;
391
        aosSysGetUptime(&uptime);
392
        aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / 1000));
393 393

  
394
    /*
394
        /*
395 395
     * execute some general tasks and high priority events
396 396
     */
397
    // no event occurred at all
398
    if ((flags.wfe) && (eventmask == 0)) {
399
      aosDbgPrintf("ERR: no evt\n");
400
      // enforce timeout event
401
      chEvtBroadcast(&eventSourceTimeout);
402
      continue;
403
    }
404
    // if an IO event occurred
405
    if (eventmask & _eventListenerIO.events) {
406
      ioflags = chEvtGetAndClearFlags(&_eventListenerIO);
407
      aosDbgPrintf("INFO: IO evt (0x%08X)\n", ioflags);
408
      // a power-down event occurred
409
      if (ioflags & MODULE_SSSP_EVENTFLAGS_PD) {
410
        aosDbgPrintf("PD evt\n");
411
        // deactivate S and UP
412
        apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
413
  #if (AMIROOS_CFG_SSSP_STACK_END != true)
414
        apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
415
  #endif
416
        // set shutdown flag and exit the loop
417
        shutdown = AOS_SHUTDOWN_PASSIVE;
418
        break;
419
      }
420
      // the S signal was deactivated
421
      if (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC) {
422
        apalControlGpioState_t sstate;
423
        apalControlGpioGet(&moduleSsspGpioSync, &sstate);
424
        if (sstate == APAL_GPIO_OFF) {
425
          aosDbgPrintf("-S evt\n");
426
          // either finish or abort
427
          if ((stage == STAGE_3_3_WAITFORID) && (aos.sssp.moduleId != 0)) {
428
            stage = STAGE_3_4_FINISH;
429
          } else if (stage != STAGE_3_4_ABORT) {
430
            stage = STAGE_3_4_ABORT_ACTIVE;
431
          }
397
        // no event occurred at all
398
        if ((flags.wfe) && (eventmask == 0)) {
399
            aosDbgPrintf("ERR: no evt\n");
400
            // enforce timeout event
401
            chEvtBroadcast(&eventSourceTimeout);
402
            continue;
432 403
        }
433
      }
434
    }
435
    // an OS event occurred
436
    if (eventmask & _eventListenerOS.events) {
437
      aosDbgPrintf("WARN: OS evt\n");
438
      // get the flags
439
      eventflags_t oseventflags = chEvtGetAndClearFlags(&_eventListenerOS);
440
      // there should be no OS events at this point
404
        // if an IO event occurred
405
        if (eventmask & _eventListenerIO.events) {
406
            ioflags = chEvtGetAndClearFlags(&_eventListenerIO);
407
            aosDbgPrintf("INFO: IO evt (0x%08X)\n", ioflags);
408
            // a power-down event occurred
409
            if (ioflags & MODULE_SSSP_EVENTFLAGS_PD) {
410
                aosDbgPrintf("PD evt\n");
411
                // deactivate S and UP
412
                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
413
#if (AMIROOS_CFG_SSSP_STACK_END != true)
414
                apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
415
#endif
416
                // set shutdown flag and exit the loop
417
                shutdown = AOS_SHUTDOWN_PASSIVE;
418
                break;
419
            }
420
            // the S signal was deactivated
421
            if (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC) {
422
                apalControlGpioState_t sstate;
423
                apalControlGpioGet(&moduleSsspGpioSync, &sstate);
424
                if (sstate == APAL_GPIO_OFF) {
425
                    aosDbgPrintf("-S evt\n");
426
                    // either finish or abort
427
                    if ((stage == STAGE_3_3_WAITFORID) && (aos.sssp.moduleId != 0)) {
428
                        stage = STAGE_3_4_FINISH;
429
                    } else if (stage != STAGE_3_4_ABORT) {
430
                        stage = STAGE_3_4_ABORT_ACTIVE;
431
                    }
432
                }
433
            }
434
        }
435
        // an OS event occurred
436
        if (eventmask & _eventListenerOS.events) {
437
            aosDbgPrintf("WARN: OS evt\n");
438
            // get the flags
439
            eventflags_t oseventflags = chEvtGetAndClearFlags(&_eventListenerOS);
440
            // there should be no OS events at this point
441 441
#ifdef MODULE_SSSP_STARTUP_3_OSEVENT_HOOK
442
      MODULE_SSSP_STARTUP_3_OSEVENT_HOOK(eventmask, eventflags);
442
            MODULE_SSSP_STARTUP_3_OSEVENT_HOOK(eventmask, eventflags);
443 443
#else
444
      _unexpectedEventError(eventmask, oseventflags);
444
            _unexpectedEventError(eventmask, oseventflags);
445 445
#endif
446
    }
447
    // if a CAN event occurred
448
    if ((eventmask & eventListenerCan.events)) {
449
      // fetch message
450
      if (flags.wfe) {
451
        canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE);
452
        aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
453
      }
454
      // identify and handle abort messgaes
455
      if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
456
        stage = STAGE_3_4_ABORT;
457
      }
458
      // warn if a unexpected message was received
459
      else if ((canRxFrame.SID != SSSP_STACKINIT_CANMSGID_INIT) &&
460
               (canRxFrame.SID != SSSP_STACKINIT_CANMSGID_MODULEID)) {
461
        aosDbgPrintf("WARN: unknown msg\n");
462
      }
463
      // any further pending messages are fetched at the end of the loop
464
    }
465
    // if a timeout event occurred
466
    if (eventmask & eventListenerTimeout.events) {
467
      // is handled at the end of the loop (or must be cleared by FSM)
468
    }
469
    // if a delay event occurred
470
    if (eventmask & eventListenerDelay.events) {
471
      // is handled by FSM
472
    }
446
        }
447
        // if a CAN event occurred
448
        if ((eventmask & eventListenerCan.events)) {
449
            // fetch message
450
            if (flags.wfe) {
451
                canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE);
452
                aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
453
            }
454
            // identify and handle abort messgaes
455
            if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
456
                stage = STAGE_3_4_ABORT;
457
            }
458
            // warn if a unexpected message was received
459
            else if ((canRxFrame.SID != SSSP_STACKINIT_CANMSGID_INIT) &&
460
                     (canRxFrame.SID != SSSP_STACKINIT_CANMSGID_MODULEID)) {
461
                aosDbgPrintf("WARN: unknown msg\n");
462
            }
463
            // any further pending messages are fetched at the end of the loop
464
        }
465
        // if a timeout event occurred
466
        if (eventmask & eventListenerTimeout.events) {
467
            // is handled at the end of the loop (or must be cleared by FSM)
468
        }
469
        // if a delay event occurred
470
        if (eventmask & eventListenerDelay.events) {
471
            // is handled by FSM
472
        }
473 473

  
474
    /*
474
        /*
475 475
     * this is the actual FSM
476 476
     */
477
    switch (stage) {
478
      case STAGE_3_1:
479
      {
480
        aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
477
        switch (stage) {
478
        case STAGE_3_1:
479
        {
480
            aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
481 481

  
482
        // there was no event at all (skipped wfe)
483
        if (eventmask == 0 && flags.wfe == false) {
482
            // there was no event at all (skipped wfe)
483
            if (eventmask == 0 && flags.wfe == false) {
484 484
#if (AMIROOS_CFG_SSSP_MASTER == true)
485
          // initialize the stage by transmitting an according CAN message
486
          aosDbgPrintf("CAN -> init\n");
487
          canTxFrame.DLC = 0;
488
          canTxFrame.SID = SSSP_STACKINIT_CANMSGID_INIT;
489
          if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
490
            chEvtBroadcast(&eventSourceTimeout);
491
            break;
492
          }
493
          // activate S
494
          aosDbgPrintf("S+\n");
495
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
485
                // initialize the stage by transmitting an according CAN message
486
                aosDbgPrintf("CAN -> init\n");
487
                canTxFrame.DLC = 0;
488
                canTxFrame.SID = SSSP_STACKINIT_CANMSGID_INIT;
489
                if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
490
                    chEvtBroadcast(&eventSourceTimeout);
491
                    break;
492
                }
493
                // activate S
494
                aosDbgPrintf("S+\n");
495
                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
496 496
#if (AMIROOS_CFG_SSSP_STACK_START == true)
497
          // proceed immediately
498
          stage = STAGE_3_2;
499
          flags.wfe_next = false;
497
                // proceed immediately
498
                stage = STAGE_3_2;
499
                flags.wfe_next = false;
500 500
#else
501
          // set the timeout timer
502
          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
503
          // proceed
504
          stage = STAGE_3_3_WAITFORFIRSTID;
501
                // set the timeout timer
502
                chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
503
                // proceed
504
                stage = STAGE_3_3_WAITFORFIRSTID;
505 505
#endif
506 506
#else
507
          // set the timeout timer
508
          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
507
                // set the timeout timer
508
                chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
509 509
#endif
510
        }
510
            }
511 511

  
512 512
#if (AMIROOS_CFG_SSSP_MASTER != true)
513
        // a CAN message was received
514
        else if (eventmask & eventListenerCan.events) {
515
          // if an initiation message was received
516
          if (canRxFrame.DLC == 0 &&
517
              canRxFrame.RTR == CAN_RTR_DATA &&
518
              canRxFrame.IDE == CAN_IDE_STD &&
519
              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_INIT) {
520
            aosDbgPrintf("init msg\n");
521
            // reset the timeout timer and clear pending flags
522
            chVTReset(&timerTimeout);
523
            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
524
            eventmask &= ~(eventListenerTimeout.events);
525
            // activate S
526
            aosDbgPrintf("S+\n");
527
            apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
513
            // a CAN message was received
514
            else if (eventmask & eventListenerCan.events) {
515
                // if an initiation message was received
516
                if (canRxFrame.DLC == 0 &&
517
                        canRxFrame.RTR == CAN_RTR_DATA &&
518
                        canRxFrame.IDE == CAN_IDE_STD &&
519
                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_INIT) {
520
                    aosDbgPrintf("init msg\n");
521
                    // reset the timeout timer and clear pending flags
522
                    chVTReset(&timerTimeout);
523
                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
524
                    eventmask &= ~(eventListenerTimeout.events);
525
                    // activate S
526
                    aosDbgPrintf("S+\n");
527
                    apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
528 528
#if (AMIROOS_CFG_SSSP_STACK_START == true)
529
            // proceed
530
            stage = STAGE_3_2;
531
            flags.wfe_next = false;
529
                    // proceed
530
                    stage = STAGE_3_2;
531
                    flags.wfe_next = false;
532 532
#else
533
            // set the timeout timer
534
            chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
535
            // proceed
536
            stage = STAGE_3_3_WAITFORFIRSTID;
533
                    // set the timeout timer
534
                    chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
535
                    // proceed
536
                    stage = STAGE_3_3_WAITFORFIRSTID;
537 537
#endif
538
          }
539
        }
538
                }
539
            }
540 540
#endif
541 541

  
542
        break;
543
      } /* end of STAGE_3_1 */
542
            break;
543
        } /* end of STAGE_3_1 */
544 544

  
545
      case STAGE_3_2:
546
      {
545
        case STAGE_3_2:
546
        {
547 547
#if (AMIROOS_CFG_SSSP_STACK_START == true)
548
        aos.sssp.stage = AOS_SSSP_STARTUP_3_2;
549

  
550
        // if this stage was just entered
551
        if (flags.wfe == false) {
552
          // set the module ID
553
          aos.sssp.moduleId = 1;
554
          // broadcast module ID
555
          aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
556
          canTxFrame.DLC = 4;
557
          canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
558
          _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
559
          if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
560
            chEvtBroadcast(&eventSourceTimeout);
561
            break;
562
          }
548
            aos.sssp.stage = AOS_SSSP_STARTUP_3_2;
549

  
550
            // if this stage was just entered
551
            if (flags.wfe == false) {
552
                // set the module ID
553
                aos.sssp.moduleId = 1;
554
                // broadcast module ID
555
                aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
556
                canTxFrame.DLC = 4;
557
                canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
558
                _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
559
                if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
560
                    chEvtBroadcast(&eventSourceTimeout);
561
                    break;
562
                }
563 563
#if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true)
564
          lastid = aos.sssp.moduleId;
564
                lastid = aos.sssp.moduleId;
565 565
#endif
566 566
#if (AMIROOS_CFG_SSSP_STACK_END == true)
567
          // sequence is already over
568
          // deactivate S
569
          aosDbgPrintf("S-\n");
570
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
571
          // proceed
572
          stage = STAGE_3_3_WAITFORID;
567
                // sequence is already over
568
                // deactivate S
569
                aosDbgPrintf("S-\n");
570
                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
571
                // proceed
572
                stage = STAGE_3_3_WAITFORID;
573 573
#else
574
          // set the delay timer so the UP signal is activated later
575
          chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
574
                // set the delay timer so the UP signal is activated later
575
                chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
576 576
#endif
577
        }
577
            }
578 578

  
579
        // if a delay event occurred
580
        if (eventmask & eventListenerDelay.events) {
581
          // activate UP
582
          aosDbgPrintf("UP+\n");
583
          apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
584
          // deactivate S
585
          aosDbgPrintf("S-\n");
586
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
587
          // explicitely clear timeout event flag
588
          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
589
          eventmask &= ~(eventListenerTimeout.events);
590
          // proceed
591
          stage = STAGE_3_3_WAITFORID;
592
        }
579
            // if a delay event occurred
580
            if (eventmask & eventListenerDelay.events) {
581
                // activate UP
582
                aosDbgPrintf("UP+\n");
583
                apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
584
                // deactivate S
585
                aosDbgPrintf("S-\n");
586
                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
587
                // explicitely clear timeout event flag
588
                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
589
                eventmask &= ~(eventListenerTimeout.events);
590
                // proceed
591
                stage = STAGE_3_3_WAITFORID;
592
            }
593 593
#endif
594 594

  
595
        break;
596
      } /* end of STAGE_3_2 */
595
            break;
596
        } /* end of STAGE_3_2 */
597 597

  
598
      case STAGE_3_3_WAITFORFIRSTID:
599
      {
598
        case STAGE_3_3_WAITFORFIRSTID:
599
        {
600 600
#if (AMIROOS_CFG_SSSP_STACK_START != true)
601
        aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
602

  
603
        // a CAN message was received
604
        if (eventmask & eventListenerCan.events) {
605
          // if an ID message was received
606
          if (canRxFrame.DLC == 4 &&
607
              canRxFrame.RTR == CAN_RTR_DATA &&
608
              canRxFrame.IDE == CAN_IDE_STD &&
609
              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
610
            aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
611
            // validate received ID
612
            if (lastid < _deserialize(canRxFrame.data8, 4)) {
613
              // store received ID
614
              lastid = _deserialize(canRxFrame.data8, 4);
615
              // restart timeout timer
616
              chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
617
              // proceed
618
              stage = STAGE_3_3_WAITFORIDORSIG;
619
            } else {
620
              aosDbgPrintf("ERR: invalid ID\n");
621
              // abort
622
              stage = STAGE_3_4_ABORT_ACTIVE;
623
              flags.wfe_next = false;
601
            aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
602

  
603
            // a CAN message was received
604
            if (eventmask & eventListenerCan.events) {
605
                // if an ID message was received
606
                if (canRxFrame.DLC == 4 &&
607
                        canRxFrame.RTR == CAN_RTR_DATA &&
608
                        canRxFrame.IDE == CAN_IDE_STD &&
609
                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
610
                    aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
611
                    // validate received ID
612
                    if (lastid < _deserialize(canRxFrame.data8, 4)) {
613
                        // store received ID
614
                        lastid = _deserialize(canRxFrame.data8, 4);
615
                        // restart timeout timer
616
                        chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
617
                        // proceed
618
                        stage = STAGE_3_3_WAITFORIDORSIG;
619
                    } else {
620
                        aosDbgPrintf("ERR: invalid ID\n");
621
                        // abort
622
                        stage = STAGE_3_4_ABORT_ACTIVE;
623
                        flags.wfe_next = false;
624
                    }
625
                    // explicitely clear timeout event flag
626
                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
627
                    eventmask &= ~(eventListenerTimeout.events);
628
                }
624 629
            }
625
            // explicitely clear timeout event flag
626
            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
627
            eventmask &= ~(eventListenerTimeout.events);
628
          }
629
        }
630 630
#endif
631
        break;
632
      } /* end of STAGE_3_3_WAITFORFIRSTID */
631
            break;
632
        } /* end of STAGE_3_3_WAITFORFIRSTID */
633 633

  
634
      case STAGE_3_3_WAITFORIDORSIG:
635
      {
634
        case STAGE_3_3_WAITFORIDORSIG:
635
        {
636 636
#if (AMIROOS_CFG_SSSP_STACK_START != true)
637
        aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
638

  
639
        // a CAN message was received
640
        if (eventmask & eventListenerCan.events) {
641
          // if an ID message was received
642
          if (canRxFrame.DLC == 4 &&
643
              canRxFrame.RTR == CAN_RTR_DATA &&
644
              canRxFrame.IDE == CAN_IDE_STD &&
645
              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
646
            aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
647
            // validate received ID
648
            if (lastid < _deserialize(canRxFrame.data8, 4)) {
649
              // store received ID
650
              lastid = _deserialize(canRxFrame.data8, 4);
651
              // restart timeout timer
652
              chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
653
            } else {
654
              aosDbgPrintf("ERR: invalid ID\n");
655
              // abort
656
              stage = STAGE_3_4_ABORT_ACTIVE;
657
              flags.wfe_next = false;
637
            aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
638

  
639
            // a CAN message was received
640
            if (eventmask & eventListenerCan.events) {
641
                // if an ID message was received
642
                if (canRxFrame.DLC == 4 &&
643
                        canRxFrame.RTR == CAN_RTR_DATA &&
644
                        canRxFrame.IDE == CAN_IDE_STD &&
645
                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
646
                    aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
647
                    // validate received ID
648
                    if (lastid < _deserialize(canRxFrame.data8, 4)) {
649
                        // store received ID
650
                        lastid = _deserialize(canRxFrame.data8, 4);
651
                        // restart timeout timer
652
                        chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
653
                    } else {
654
                        aosDbgPrintf("ERR: invalid ID\n");
655
                        // abort
656
                        stage = STAGE_3_4_ABORT_ACTIVE;
657
                        flags.wfe_next = false;
658
                    }
659
                    // explicitely clear timeout event flag
660
                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
661
                    eventmask &= ~(eventListenerTimeout.events);
662
                }
658 663
            }
659
            // explicitely clear timeout event flag
660
            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
661
            eventmask &= ~(eventListenerTimeout.events);
662
          }
663
        }
664 664

  
665
        // if an IO event was received (DN signal)
666
        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_DN)) {
667
          aosDbgPrintf("DN <-\n");
668
          // reset timeout timer
669
          chVTReset(&timerTimeout);
670
          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
671
          eventmask &= ~(eventListenerTimeout.events);
672
          // increment and broadcast ID
673
          aos.sssp.moduleId = lastid + 1;
674
          aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
675
          canTxFrame.DLC = 4;
676
          canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
677
          _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
678
          if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
679
            chEvtBroadcast(&eventSourceTimeout);
680
            break;
681
          }
682
          // set delay timer
683
          chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
684
        }
665
            // if an IO event was received (DN signal)
666
            if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_DN)) {
667
                aosDbgPrintf("DN <-\n");
668
                // reset timeout timer
669
                chVTReset(&timerTimeout);
670
                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
671
                eventmask &= ~(eventListenerTimeout.events);
672
                // increment and broadcast ID
673
                aos.sssp.moduleId = lastid + 1;
674
                aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
675
                canTxFrame.DLC = 4;
676
                canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
677
                _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
678
                if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
679
                    chEvtBroadcast(&eventSourceTimeout);
680
                    break;
681
                }
682
                // set delay timer
683
                chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
684
            }
685 685

  
686
        // if a delay event occurred
687
        if (eventmask & eventListenerDelay.events) {
686
            // if a delay event occurred
687
            if (eventmask & eventListenerDelay.events) {
688 688
#if (AMIROOS_CFG_SSSP_STACK_END != true)
689
          // activate UP
690
          aosDbgPrintf("UP+\n");
691
          apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
692
#endif
693
          // deactivate S
694
          aosDbgPrintf("S-\n");
695
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
696
          // reset the timeout timer
697
          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
698
          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
699
          eventmask &= ~(eventListenerTimeout.events);
700
          // proceed
701
          stage = STAGE_3_3_WAITFORID;
702
        }
689
                // activate UP
690
                aosDbgPrintf("UP+\n");
691
                apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
692
#endif
693
                // deactivate S
694
                aosDbgPrintf("S-\n");
695
                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
696
                // reset the timeout timer
697
                chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
698
                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
699
                eventmask &= ~(eventListenerTimeout.events);
700
                // proceed
701
                stage = STAGE_3_3_WAITFORID;
702
            }
703 703
#endif
704 704

  
705
        break;
706
      } /* end of STAGE_3_3_WAITFORIDORSIG */
705
            break;
706
        } /* end of STAGE_3_3_WAITFORIDORSIG */
707 707

  
708
      case STAGE_3_3_WAITFORID:
709
      {
710
        aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
708
        case STAGE_3_3_WAITFORID:
709
        {
710
            aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
711 711

  
712 712
#if (AMIROOS_CFG_SSSP_STACK_END != true)
713
        // a CAN message was received
714
        if (eventmask & eventListenerCan.events) {
715
          // if an ID message was received
716
          if (canRxFrame.DLC == 4 &&
717
              canRxFrame.RTR == CAN_RTR_DATA &&
718
              canRxFrame.IDE == CAN_IDE_STD &&
719
              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
713
            // a CAN message was received
714
            if (eventmask & eventListenerCan.events) {
715
                // if an ID message was received
716
                if (canRxFrame.DLC == 4 &&
717
                        canRxFrame.RTR == CAN_RTR_DATA &&
718
                        canRxFrame.IDE == CAN_IDE_STD &&
719
                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
720 720
#if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true)
721
            // Plausibility of the received ID is not checked at this point but is done by other modules still in a previous stage.
722
            lastid = _deserialize(canRxFrame.data8, 4);
723
            aosDbgPrintf("ID (%u)\n", lastid);
724
#endif
725
            // restart timeout timer
726
            chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
727
            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
728
            eventmask &= ~(eventListenerTimeout.events);
729
          }
730
        }
721
                    // Plausibility of the received ID is not checked at this point but is done by other modules still in a previous stage.
722
                    lastid = _deserialize(canRxFrame.data8, 4);
723
                    aosDbgPrintf("ID (%u)\n", lastid);
724
#endif
725
                    // restart timeout timer
726
                    chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
727
                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
728
                    eventmask &= ~(eventListenerTimeout.events);
729
                }
730
            }
731 731
#endif
732 732

  
733
        break;
734
      } /* end of STAGE_3_3_WAITFORID */
733
            break;
734
        } /* end of STAGE_3_3_WAITFORID */
735

  
736
        case STAGE_3_4_FINISH:
737
        {
738
            aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
739

  
740
            // if an IO event was received (S signal)
741
            if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
742
                // reset the timeout timer
743
                chVTReset(&timerTimeout);
744
                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
745
                eventmask &= ~(eventListenerTimeout.events);
746
                //set the delay timer
747
                chVTSet(&timerDelay, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceDelay);
748
            }
735 749

  
736
      case STAGE_3_4_FINISH:
737
      {
738
        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
750
            // if a CAN event was received
751
            if (eventmask & eventListenerCan.events) {
752
                // if an abort message was received
753
                if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
754
                    aosDbgPrintf("abort msg\n");
755
                    // reset the delay timer
756
                    chVTReset(&timerDelay);
757
                    chEvtWaitAnyTimeout(eventListenerDelay.events, TIME_IMMEDIATE);
758
                    eventmask &= ~(eventListenerDelay.events);
759
                    // proceed
760
                    stage = STAGE_3_4_ABORT;
761
                }
762
            }
739 763

  
740
        // if an IO event was received (S signal)
741
        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
742
          // reset the timeout timer
743
          chVTReset(&timerTimeout);
744
          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
745
          eventmask &= ~(eventListenerTimeout.events);
746
          //set the delay timer
747
          chVTSet(&timerDelay, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceDelay);
748
        }
764
            // if a delay timer event occurred
765
            if (eventmask & eventListenerDelay.events) {
766
                aosDbgPrintf("sequence sucessful\n");
767
                // sequence finished sucessfully
768
                flags.loop = false;
769
            }
749 770

  
750
        // if a CAN event was received
751
        if (eventmask & eventListenerCan.events) {
752
          // if an abort message was received
753
          if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
754
            aosDbgPrintf("abort msg\n");
755
            // reset the delay timer
756
            chVTReset(&timerDelay);
757
            chEvtWaitAnyTimeout(eventListenerDelay.events, TIME_IMMEDIATE);
758
            eventmask &= ~(eventListenerDelay.events);
759
            // proceed
771
            break;
772
        } /* end of STAGE_3_4_FINISH */
773

  
774
        case STAGE_3_4_ABORT_ACTIVE:
775
        {
776
            aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
777

  
778
            // emit abort message
779
            canTxFrame.DLC = 0;
780
            canTxFrame.SID = SSSP_STACKINIT_CANMSGID_ABORT;
781
            canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_INFINITE);
782
            aosDbgPrintf("CAN -> abort\n");
783
            // clear timeout flag
784
            eventmask &= ~(eventListenerTimeout.events);
785
            // proceed immediately
760 786
            stage = STAGE_3_4_ABORT;
761
          }
762
        }
787
            flags.wfe_next = false;
788
            break;
789
        } /* end of STAGE_3_4_ABORT_ACTIVE */
790

  
791
        case STAGE_3_4_ABORT:
792
        {
793
            aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
794

  
795
            // deactivate S
796
            aosDbgPrintf("S-\n");
797
            apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
798
            // invalidate module ID
799
            aos.sssp.moduleId = 0;
800

  
801
            // if an IO event was received (S signal)
802
            if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
803
                aosDbgPrintf("sequence aborted\n");
804
                // exit the sequence
805
                flags.loop = false;
806
            }
763 807

  
764
        // if a delay timer event occurred
765
        if (eventmask & eventListenerDelay.events) {
766
          aosDbgPrintf("sequence sucessful\n");
767
          // sequence finished sucessfully
768
          flags.loop = false;
808
            break;
809
        } /* end of STAGE_3_4_ABORT */
769 810
        }
770 811

  
771
        break;
772
      } /* end of STAGE_3_4_FINISH */
773

  
774
      case STAGE_3_4_ABORT_ACTIVE:
775
      {
776
        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
777

  
778
        // emit abort message
779
        canTxFrame.DLC = 0;
780
        canTxFrame.SID = SSSP_STACKINIT_CANMSGID_ABORT;
781
        canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_INFINITE);
782
        aosDbgPrintf("CAN -> abort\n");
783
        // clear timeout flag
784
        eventmask &= ~(eventListenerTimeout.events);
785
        // proceed immediately
786
        stage = STAGE_3_4_ABORT;
787
        flags.wfe_next = false;
788
        break;
789
      } /* end of STAGE_3_4_ABORT_ACTIVE */
790

  
791
      case STAGE_3_4_ABORT:
792
      {
793
        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
794

  
795
        // deactivate S
796
        aosDbgPrintf("S-\n");
797
        apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
798
        // invalidate module ID
799
        aos.sssp.moduleId = 0;
800

  
801
        // if an IO event was received (S signal)
802
        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
803
          aosDbgPrintf("sequence aborted\n");
804
          // exit the sequence
805
          flags.loop = false;
812
        // fetch pending CAN message (if any)
813
        if ((eventmask & eventListenerCan.events) && (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE) == MSG_OK)) {
814
            aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
815
            flags.wfe_next = false;
806 816
        }
807 817

  
808
        break;
809
      } /* end of STAGE_3_4_ABORT */
810
    }
811

  
812
    // fetch pending CAN message (if any)
813
    if ((eventmask & eventListenerCan.events) && (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE) == MSG_OK)) {
814
      aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
815
      flags.wfe_next = false;
816
    }
817

  
818
    // handle unhandled timeout events
819
    if (eventmask & eventListenerTimeout.events) {
820
      aosDbgPrintf("ERR: timeout evt\n");
821
      // abort
822
      flags.wfe_next = false;
823
      stage = STAGE_3_4_ABORT_ACTIVE;
824
    }
818
        // handle unhandled timeout events
819
        if (eventmask & eventListenerTimeout.events) {
820
            aosDbgPrintf("ERR: timeout evt\n");
821
            // abort
822
            flags.wfe_next = false;
823
            stage = STAGE_3_4_ABORT_ACTIVE;
824
        }
825 825

  
826
    // apply wfe value for next iteration
827
    flags.wfe = flags.wfe_next;
828
  } /* end of FSM loop */
829
  aosDbgPrintf("\n");
826
        // apply wfe value for next iteration
827
        flags.wfe = flags.wfe_next;
828
    } /* end of FSM loop */
829
    aosDbgPrintf("\n");
830 830

  
831
  // unregister all events (timeout, delay, CAN receive)
832
  chEvtUnregister(&eventSourceTimeout, &eventListenerTimeout);
833
  chEvtUnregister(&eventSourceDelay, &eventListenerDelay);
834
  chEvtUnregister(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan);
835
  // clear any pending events (timeout, delay, CAN receive)
836
  chEvtWaitAllTimeout(TIMEOUTEVENT_MASK | DELAYEVENT_MASK | CANEVENT_MASK, TIME_IMMEDIATE);
831
    // unregister all events (timeout, delay, CAN receive)
832
    chEvtUnregister(&eventSourceTimeout, &eventListenerTimeout);
833
    chEvtUnregister(&eventSourceDelay, &eventListenerDelay);
834
    chEvtUnregister(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan);
835
    // clear any pending events (timeout, delay, CAN receive)
836
    chEvtWaitAllTimeout(TIMEOUTEVENT_MASK | DELAYEVENT_MASK | CANEVENT_MASK, TIME_IMMEDIATE);
837 837

  
838
  // reset all control signals
838
    // reset all control signals
839 839
#if (AMIROOS_CFG_SSSP_STACK_END != true)
840
  apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
840
    apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
841 841
#endif
842
  apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
842
    apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
843 843

  
844
  return shutdown;
844
    return shutdown;
845 845
}
846 846
#endif
847 847
/**
......
849 849
 */
850 850
int main(void)
851 851
{
852
  // local variables
853
  eventmask_t eventmask = 0;
854
  eventflags_t eventflags = 0;
855
  aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
852
    // local variables
853
    eventmask_t eventmask = 0;
854
    eventflags_t eventflags = 0;
855
    aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
856 856
#if defined(AMIROOS_CFG_MAIN_EXTRA_THREAD_VARIABLES)
857
  AMIROOS_CFG_MAIN_EXTRA_THREAD_VARIABLES
858
#endif
859

  
860
  /*
861
   * ##########################################################################
862
   * # system initialization                                                  #
863
   * ##########################################################################
864
   */
865

  
866
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0)
867
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS)
868
  AMIROOS_CFG_MAIN_INIT_HOOK_0(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS);
857
    AMIROOS_CFG_MAIN_EXTRA_THREAD_VARIABLES
858
        #endif
859

  
860
            /*
861
           * ##########################################################################
862
           * # system initialization                                                  #
863
           * ##########################################################################
864
           */
865

  
866
        #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0)
867
        #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS)
868
            AMIROOS_CFG_MAIN_INIT_HOOK_0(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS);
869 869
#else
870
  AMIROOS_CFG_MAIN_INIT_HOOK_0();
870
            AMIROOS_CFG_MAIN_INIT_HOOK_0();
871 871
#endif
872 872
#endif
873 873

  
874
  /* hardware, kernel, and operating system initialization */
875
  // ChibiOS/HAL and custom hal additions (if any)
876
  halInit();
874
    /* hardware, kernel, and operating system initialization */
875
    // ChibiOS/HAL and custom hal additions (if any)
876
    halInit();
877 877
#ifdef MODULE_INIT_HAL_EXTRA
878
  MODULE_INIT_HAL_EXTRA();
878
    MODULE_INIT_HAL_EXTRA();
879 879
#endif
880 880

  
881 881
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_1)
882 882
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_1_ARGS)
883
  AMIROOS_CFG_MAIN_INIT_HOOK_1(AMIROOS_CFG_MAIN_INIT_HOOK_1_ARGS);
883
    AMIROOS_CFG_MAIN_INIT_HOOK_1(AMIROOS_CFG_MAIN_INIT_HOOK_1_ARGS);
884 884
#else
885
  AMIROOS_CFG_MAIN_INIT_HOOK_1();
885
    AMIROOS_CFG_MAIN_INIT_HOOK_1();
886 886
#endif
887 887
#endif
888 888

  
889
  // ChibiOS/RT kernel and custom kernel additions (if any)
890
  chSysInit();
889
    // ChibiOS/RT kernel and custom kernel additions (if any)
890
    chSysInit();
891 891
#ifdef MODULE_INIT_KERNEL_EXTRA
892
  MODULE_INIT_KERNEL_EXTRA();
892
    MODULE_INIT_KERNEL_EXTRA();
893 893
#endif
894 894

  
895 895
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_2)
896 896
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_2_ARGS)
897
  AMIROOS_CFG_MAIN_INIT_HOOK_2(AMIROOS_CFG_MAIN_INIT_HOOK_2_ARGS);
897
    AMIROOS_CFG_MAIN_INIT_HOOK_2(AMIROOS_CFG_MAIN_INIT_HOOK_2_ARGS);
898 898
#else
899
  AMIROOS_CFG_MAIN_INIT_HOOK_2();
899
    AMIROOS_CFG_MAIN_INIT_HOOK_2();
900 900
#endif
901 901
#endif
902 902

  
903
  // AMiRo-OS and custom OS additions (if any)
903
    // AMiRo-OS and custom OS additions (if any)
904 904
#if (AMIROOS_CFG_SHELL_ENABLE == true)
905
  aosSysInit(moduleShellPrompt);
905
    aosSysInit(moduleShellPrompt);
906 906
#else
907
  aosSysInit();
907
    aosSysInit();
908 908
#endif
909 909
#ifdef MODULE_INIT_OS_EXTRA
910
  MODULE_INIT_OS_EXTRA();
910
    MODULE_INIT_OS_EXTRA();
911 911
#endif
912 912

  
913 913
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_3)
914 914
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_3_ARGS)
915
  AMIROOS_CFG_MAIN_INIT_HOOK_3(AMIROOS_CFG_MAIN_INIT_HOOK_3_ARGS);
915
    AMIROOS_CFG_MAIN_INIT_HOOK_3(AMIROOS_CFG_MAIN_INIT_HOOK_3_ARGS);
916 916
#else
917
  AMIROOS_CFG_MAIN_INIT_HOOK_3();
917
    AMIROOS_CFG_MAIN_INIT_HOOK_3();
918 918
#endif
919 919
#endif
920 920

  
921 921
#if (AMIROOS_CFG_TESTS_ENABLE == true)
922 922
#if defined(MODULE_INIT_TESTS)
923
  MODULE_INIT_TESTS();
923
    MODULE_INIT_TESTS();
924 924
#else
925
  #warning "MODULE_INIT_TESTS not defined"
925
#warning "MODULE_INIT_TESTS not defined"
926 926
#endif
927 927
#endif
928 928

  
929 929
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_4)
930 930
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_4_ARGS)
931
  AMIROOS_CFG_MAIN_INIT_HOOK_4(AMIROOS_CFG_MAIN_INIT_HOOK_4_ARGS);
931
    AMIROOS_CFG_MAIN_INIT_HOOK_4(AMIROOS_CFG_MAIN_INIT_HOOK_4_ARGS);
932 932
#else
933
  AMIROOS_CFG_MAIN_INIT_HOOK_4();
933
    AMIROOS_CFG_MAIN_INIT_HOOK_4();
934 934
#endif
935 935
#endif
936 936

  
937 937
#if (AMIROOS_CFG_SSSP_ENABLE == true)
938
  /* event associations */
938
    /* event associations */
939 939
#if (AMIROOS_CFG_SSSP_STACK_START == true) && (AMIROOS_CFG_SSSP_STACK_END == true)
940
  chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC);
940
    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC);
941 941
#elif (AMIROOS_CFG_SSSP_STACK_START == true)
942
  chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_UP);
942
    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_UP);
943 943
#elif (AMIROOS_CFG_SSSP_STACK_END == true)
944
  chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN);
944
    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN);
945 945
#else
946
  chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN | MODULE_SSSP_EVENTFLAGS_UP);
946
    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN | MODULE_SSSP_EVENTFLAGS_UP);
947 947
#endif
948 948
#endif // end of AMIROOS_CFG_SSSP_ENABLE condition
949
  chEvtRegisterMask(&aos.events.os, &_eventListenerOS, OSEVENT_MASK);
949
    chEvtRegisterMask(&aos.events.os, &_eventListenerOS, OSEVENT_MASK);
950 950

  
951 951
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_5)
952 952
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_5_ARGS)
953
  AMIROOS_CFG_MAIN_INIT_HOOK_5(AMIROOS_CFG_MAIN_INIT_HOOK_5_ARGS);
953
    AMIROOS_CFG_MAIN_INIT_HOOK_5(AMIROOS_CFG_MAIN_INIT_HOOK_5_ARGS);
954 954
#else
955
  AMIROOS_CFG_MAIN_INIT_HOOK_5();
955
    AMIROOS_CFG_MAIN_INIT_HOOK_5();
956 956
#endif
957 957
#endif
958 958

  
959
  /* periphery communication initialization */
960
  // CAN (mandatory)
961
  canStart(&MODULE_HAL_CAN, &moduleHalCanConfig);
959
    /* periphery communication initialization */
960
    // CAN (mandatory)
961
    canStart(&MODULE_HAL_CAN, &moduleHalCanConfig);
962 962

  
963
  // module specific initialization (if any)
963
    // module specific initialization (if any)
964 964
#ifdef MODULE_INIT_PERIPHERY_COMM
965
  MODULE_INIT_PERIPHERY_COMM();
965
    MODULE_INIT_PERIPHERY_COMM();
966 966
#endif
967
  // user interface (if any)
967
    // user interface (if any)
968 968
#ifdef MODULE_HAL_PROGIF
969
  aosIOChannelInit(&_stdiochannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
970
  aosIOChannelOutputEnable(&_stdiochannel);
971
  aosIOStreamAddChannel(&aos.iostream, &_stdiochannel);
969
    aosIOChannelInit(&_stdiochannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
970
    aosIOChannelOutputEnable(&_stdiochannel);
971
    aosIOStreamAddChannel(&aos.iostream, &_stdiochannel);
972 972
#if (AMIROOS_CFG_SHELL_ENABLE == true)
973
  aosShellChannelInit(&_stdshellchannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
974
  aosShellChannelInputEnable(&_stdshellchannel);
975
  aosShellChannelOutputEnable(&_stdshellchannel);
976
  aosShellStreamAddChannel(&aos.shell.stream, &_stdshellchannel);
973
    aosShellChannelInit(&_stdshellchannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
974
    aosShellChannelInputEnable(&_stdshellchannel);
975
    aosShellChannelOutputEnable(&_stdshellchannel);
976
    aosShellStreamAddChannel(&aos.shell.stream, &_stdshellchannel);
977 977
#endif
978 978
#endif
979 979

  
980 980
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_6)
981 981
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_6_ARGS)
982
  AMIROOS_CFG_MAIN_INIT_HOOK_6(AMIROOS_CFG_MAIN_INIT_HOOK_6_ARGS);
982
    AMIROOS_CFG_MAIN_INIT_HOOK_6(AMIROOS_CFG_MAIN_INIT_HOOK_6_ARGS);
983 983
#else
984
  AMIROOS_CFG_MAIN_INIT_HOOK_6();
985
#endif
986
#endif
987
  for (unsigned int hase = 0; hase < 10; ++hase) {
988
      //toggle LED
989
      palClearLine(LINE_LED_GREEN);
990
      chThdSleepMilliseconds(1500);
991
      palSetLine(LINE_LED_GREEN);
992
      chThdSleepMilliseconds(500);
993
  }
994
  chprintf((BaseSequentialStream*)&SD2, "Hallo Welt!\n");
995

  
996
  /* module is ready -> print welcome prompt */
997
  aosprintf("\n");
998
  aosprintf("######################################################################\n");
999
  aosprintf("# AMiRo-OS is an operating system designed for the Autonomous Mini   #\n");
1000
  aosprintf("# Robot (AMiRo) platform.                                            #\n");
1001
  aosprintf("# Copyright (C) 2016..2018  Thomas Schöpping et al.                  #\n");
1002
  aosprintf("#                                                                    #\n");
1003
  aosprintf("# This is free software; see the source for copying conditions.      #\n");
1004
  aosprintf("# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n");
1005
  aosprintf("# A PARTICULAR PURPOSE.                                              #\n");
1006
  aosprintf("# The development of this software was supported by the Excellence   #\n");
1007
  aosprintf("# Cluster EXC 227 Cognitive Interaction Technology. The Excellence   #\n");
1008
  aosprintf("# Cluster EXC 227 is a grant of the Deutsche Forschungsgemeinschaft  #\n");
1009
  aosprintf("# (DFG) in the context of the German Excellence Initiative.          #\n");
1010
  aosprintf("######################################################################\n");
1011
  aosprintf("\n");
984
    AMIROOS_CFG_MAIN_INIT_HOOK_6();
985
#endif
986
#endif
987
    //  for (unsigned int hase = 0; hase < 10; ++hase) {
988
    //      //toggle LED
989
    //      palClearLine(LINE_LED_GREEN);
990
    //      chThdSleepMilliseconds(1500);
991
    //      palSetLine(LINE_LED_GREEN);
992
    //      chThdSleepMilliseconds(500);
993
    //  }
994
    //  chprintf((BaseSequentialStream*)&SD2, "Hallo Welt!\n");
995

  
996
    /* module is ready -> print welcome prompt */
997
    aosprintf("\n");
998
    aosprintf("######################################################################\n");
999
    aosprintf("# AMiRo-OS is an operating system designed for the Autonomous Mini   #\n");
1000
    aosprintf("# Robot (AMiRo) platform.                                            #\n");
1001
    aosprintf("# Copyright (C) 2016..2018  Thomas Schöpping et al.                  #\n");
1002
    aosprintf("#                                                                    #\n");
1003
    aosprintf("# This is free software; see the source for copying conditions.      #\n");
1004
    aosprintf("# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n");
1005
    aosprintf("# A PARTICULAR PURPOSE.                                              #\n");
1006
    aosprintf("# The development of this software was supported by the Excellence   #\n");
1007
    aosprintf("# Cluster EXC 227 Cognitive Interaction Technology. The Excellence   #\n");
1008
    aosprintf("# Cluster EXC 227 is a grant of the Deutsche Forschungsgemeinschaft  #\n");
1009
    aosprintf("# (DFG) in the context of the German Excellence Initiative.          #\n");
1010
    aosprintf("######################################################################\n");
1011
    aosprintf("\n");
1012 1012

  
1013 1013
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_7)
1014 1014
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS)
1015
  AMIROOS_CFG_MAIN_INIT_HOOK_7(AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS);
1015
    AMIROOS_CFG_MAIN_INIT_HOOK_7(AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS);
1016 1016
#else
1017
  AMIROOS_CFG_MAIN_INIT_HOOK_7();
1018
#endif
1019
#endif
1017
    AMIROOS_CFG_MAIN_INIT_HOOK_7();
1018
#endif //AMIROOS_CFG_MAIN_INIT_HOOK_7
1019
#endif //AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS
1020 1020

  
1021 1021
#if (AMIROOS_CFG_SSSP_ENABLE == true)
1022
  /* SSSP startup OS synchronization phase (end of startup stage 2) */
1023
  while ((shutdown == AOS_SHUTDOWN_NONE) && (eventmask = aosSysSsspStartupOsInitSyncCheck(&_eventListenerIO)) != 0) {
1024
    /*
1022
    /* SSSP startup OS synchronization phase (end of startup stage 2) */
1023
    while ((shutdown == AOS_SHUTDOWN_NONE) && (eventmask = aosSysSsspStartupOsInitSyncCheck(&_eventListenerIO)) != 0) {
1024
        /*
1025 1025
     * This code is executed if the received event was not about the SYS_SYNC control signal.
1026 1026
     * The returned event could be caused by any listener (not only the argument).
1027 1027
     */
1028
    // IO event
1029
    if (eventmask & _eventListenerIO.events) {
1030
      eventflags = chEvtGetAndClearFlags(&_eventListenerIO);
1031
      // PD event
1032
      if (eventflags & MODULE_SSSP_EVENTFLAGS_PD) {
1033
        shutdown = AOS_SHUTDOWN_PASSIVE;
1034
      } else {
1028
        // IO event
1029
        if (eventmask & _eventListenerIO.events) {
1030
            eventflags = chEvtGetAndClearFlags(&_eventListenerIO);
1031
            // PD event
1032
            if (eventflags & MODULE_SSSP_EVENTFLAGS_PD) {
1033
                shutdown = AOS_SHUTDOWN_PASSIVE;
1034
            } else {
1035 1035
#ifdef MODULE_SSSP_STARTUP_2_2_IOEVENT_HOOK
1036
        MODULE_SSSP_STARTUP_2_2_IOEVENT_HOOK(eventmask, eventflags);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff