Statistics
| Branch: | Tag: | Revision:

amiro-blt / Target / Modules / DiWheelDrive_1-2 / Boot / main.c @ c1f21a71

History | View | Annotate | Download (35.287 KB)

1
/************************************************************************************//**
2
* \file         Demo\ARMCM3_STM32_Olimex_STM32P103_GCC\Boot\main.c
3
* \brief        Bootloader application source file.
4
* \ingroup      Boot_ARMCM3_STM32_Olimex_STM32P103_GCC
5
* \internal
6
*----------------------------------------------------------------------------------------
7
*                          C O P Y R I G H T
8
*----------------------------------------------------------------------------------------
9
*   Copyright (c) 2012  by Feaser    http://www.feaser.com    All rights reserved
10
*
11
*----------------------------------------------------------------------------------------
12
*                            L I C E N S E
13
*----------------------------------------------------------------------------------------
14
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License as published by the Free
16
* Software Foundation, either version 3 of the License, or (at your option) any later
17
* version.
18
*
19
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21
* PURPOSE. See the GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License along with OpenBLT.
24
* If not, see <http://www.gnu.org/licenses/>.
25
*
26
* A special exception to the GPL is included to allow you to distribute a combined work
27
* that includes OpenBLT without being obliged to provide the source code for any
28
* proprietary components. The exception text is included at the bottom of the license
29
* file <license.html>.
30
*
31
* \endinternal
32
****************************************************************************************/
33

    
34
/****************************************************************************************
35
* Include files
36
****************************************************************************************/
37
#include "boot.h"                                /* bootloader generic header          */
38
#include "timer.h"
39
#include "ARMCM3_STM32/types.h"
40
#include "AMiRo/amiroblt.h"
41
#include "helper.h"
42
#include "iodef.h"
43

    
44
/****************************************************************************************
45
* Defines
46
****************************************************************************************/
47
#define RESET_TIMEOUT_MS    100
48

    
49
/****************************************************************************************
50
* Function prototypes
51
****************************************************************************************/
52
static void Init(void);
53

    
54
static void initGpio();
55
static void initExti();
56
void configGpioForShutdown();
57

    
58
ErrorStatus handleColdReset();
59
ErrorStatus handleUartWakeup();
60
ErrorStatus handleImuWakeup();
61

    
62
ErrorStatus shutdownDisambiguationProcedure(const uint8_t type);
63
void shutdownToTransportation(const blt_bool exec_disambiguation);
64
void shutdownToDeepsleep(const blt_bool exec_disambiguation);
65
void shutdownToHibernate(const blt_bool exec_disambiguation);
66
void shutdownAndRestart(const blt_bool exec_disambiguation);
67

    
68
volatile blBackupRegister_t backup_reg;
69

    
70
/****************************************************************************************
71
* Callback configuration
72
****************************************************************************************/
73
void blCallbackShutdownTransportation(void);
74
void blCallbackShutdownDeepsleep(void);
75
void blCallbackShutdownHibernate(void);
76
void blCallbackShutdownRestart(void);
77
void blCallbackHandleShutdownRequest(void);
78

    
79
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
80
  .magicNumber = BL_MAGIC_NUMBER,
81
  .vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
82
  .vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
83
  .vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__},  // currently only GCC is supported
84
  .cbShutdownHibernate = blCallbackShutdownHibernate,
85
  .cbShutdownDeepsleep = blCallbackShutdownDeepsleep,
86
  .cbShutdownTransportation = blCallbackShutdownTransportation,
87
  .cbShutdownRestart = blCallbackShutdownRestart,
88
  .cbHandleShutdownRequest = blCallbackHandleShutdownRequest,
89
  .cb5 = (void*)0,
90
  .cb6 = (void*)0,
91
  .cb7 = (void*)0,
92
  .cb8 = (void*)0,
93
  .cb9 = (void*)0,
94
  .cb10 = (void*)0,
95
  .cb11 = (void*)0
96
};
97

    
98
/************************************************************************************//**
99
** \brief     This is the entry point for the bootloader application and is called
100
**            by the reset interrupt vector after the C-startup routines executed.
101
** \return    Program return code.
102
**
103
****************************************************************************************/
104
int main(void)
105
{
106
  /* initialize the microcontroller */
107
  Init();
108

    
109
  /* activate some required clocks */
110
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
111
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
112

    
113
  /* initialize GPIOs and EXTI lines */
114
  initGpio();
115
  setLed(BLT_TRUE);
116
  initExti();
117

    
118
  /* initialize the timer */
119
  TimerInit();
120

    
121
  /* detect the primary reason for this wakeup/restart */
122
  backup_reg.wakeup_pri_reason =
123
      ((RCC_GetFlagStatus(RCC_FLAG_LPWRRST) == SET) ? BL_WAKEUP_PRI_RSN_LPWRRST : 0) |
124
      ((RCC_GetFlagStatus(RCC_FLAG_WWDGRST) == SET) ? BL_WAKEUP_PRI_RSN_WWDGRST : 0) |
125
      ((RCC_GetFlagStatus(RCC_FLAG_IWDGRST) == SET) ? BL_WAKEUP_PRI_RSN_IWDGRST : 0) |
126
      ((RCC_GetFlagStatus(RCC_FLAG_SFTRST) == SET) ? BL_WAKEUP_PRI_RSN_SFTRST : 0)   |
127
      ((RCC_GetFlagStatus(RCC_FLAG_PORRST) == SET) ? BL_WAKEUP_PRI_RSN_PORRST : 0)   |
128
      ((RCC_GetFlagStatus(RCC_FLAG_PINRST) == SET) ? BL_WAKEUP_PRI_RSN_PINRST : 0)   |
129
      ((PWR_GetFlagStatus(PWR_FLAG_WU) == SET) ? BL_WAKEUP_PRI_RSN_WKUP : 0);
130

    
131
  /* when woken from standby mode, detect the secondary reason for thiswakeup/reset */
132
  if ( (backup_reg.wakeup_pri_reason & BL_WAKEUP_PRI_RSN_WKUP) && (PWR_GetFlagStatus(PWR_FLAG_SB) == SET) ) {
133
    if (GPIO_ReadInputDataBit(SYS_UART_UP_GPIO, SYS_UART_UP_PIN) == Bit_SET) {
134
      backup_reg.wakeup_sec_reason = BL_WAKEUP_SEC_RSN_UART;
135
    } else {
136
      backup_reg.wakeup_sec_reason = BL_WAKEUP_SEC_RSN_IMU;
137
    }
138
  } else {
139
    backup_reg.wakeup_sec_reason = BL_WAKEUP_SEC_RSN_UNKNOWN;
140
  }
141

    
142
  /* clear the flags */
143
  RCC_ClearFlag();
144
  PWR_ClearFlag(PWR_FLAG_WU);
145

    
146
  setLed(BLT_FALSE);
147

    
148
  /* wait 1ms for all signals to become stable */
149
  msleep(1);
150

    
151
  /* handle different wakeup/reset reasons */
152
  ErrorStatus status = ERROR;
153
  if (backup_reg.wakeup_pri_reason & BL_WAKEUP_PRI_RSN_WKUP) {
154
    /* the system was woken via WKUP pin */
155
    /* differenciate between two wakeup types */
156
    switch (backup_reg.wakeup_sec_reason) {
157
      case BL_WAKEUP_SEC_RSN_UART:
158
        status = handleUartWakeup();
159
        break;
160
      case BL_WAKEUP_SEC_RSN_IMU:
161
        status = handleImuWakeup();
162
        break;
163
      default:
164
        status = ERROR;
165
        break;
166
    }
167
  } else if (backup_reg.wakeup_pri_reason & BL_WAKEUP_PRI_RSN_PINRST) {
168
    /* system was woken via NRST pin */
169
    status = handleColdReset();
170
  } else {
171
    /* system was woken/reset for an unexpected reason */
172
    blinkSOS(1);
173
    status = handleColdReset();
174
  }
175

    
176
  /* if something went wrong, signal this failure */
177
  if (status != SUCCESS) {
178
    blinkSOSinf();
179
  }
180

    
181
  return 0;
182
} /*** end of main ***/
183

    
184

    
185
/************************************************************************************//**
186
** \brief     Initializes the microcontroller.
187
** \return    none.
188
**
189
****************************************************************************************/
190
static void Init(void)
191
{
192
  volatile blt_int32u StartUpCounter = 0, HSEStatus = 0;
193
  blt_int32u pll_multiplier;
194
#if (BOOT_FILE_LOGGING_ENABLE > 0) && (BOOT_COM_UART_ENABLE == 0)
195
  GPIO_InitTypeDef  GPIO_InitStruct;
196
  USART_InitTypeDef USART_InitStruct;
197
#endif
198

    
199
  /* reset the RCC clock configuration to the default reset state (for debug purpose) */
200
  /* set HSION bit */
201
  RCC->CR |= (blt_int32u)0x00000001;
202
  /* reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
203
  RCC->CFGR &= (blt_int32u)0xF8FF0000;
204
  /* reset HSEON, CSSON and PLLON bits */
205
  RCC->CR &= (blt_int32u)0xFEF6FFFF;
206
  /* reset HSEBYP bit */
207
  RCC->CR &= (blt_int32u)0xFFFBFFFF;
208
  /* reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
209
  RCC->CFGR &= (blt_int32u)0xFF80FFFF;
210
  /* disable all interrupts and clear pending bits  */
211
  RCC->CIR = 0x009F0000;
212
  /* enable HSE */
213
  RCC->CR |= ((blt_int32u)RCC_CR_HSEON);
214
  /* wait till HSE is ready and if Time out is reached exit */
215
  do
216
  {
217
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
218
    StartUpCounter++;
219
  }
220
  while((HSEStatus == 0) && (StartUpCounter != 1500));
221
  /* check if time out was reached */
222
  if ((RCC->CR & RCC_CR_HSERDY) == RESET)
223
  {
224
    /* cannot continue when HSE is not ready */
225
    ASSERT_RT(BLT_FALSE);
226
  }
227
  /* enable flash prefetch buffer */
228
  FLASH->ACR |= FLASH_ACR_PRFTBE;
229
  /* reset flash wait state configuration to default 0 wait states */
230
  FLASH->ACR &= (blt_int32u)((blt_int32u)~FLASH_ACR_LATENCY);
231
#if (BOOT_CPU_SYSTEM_SPEED_KHZ > 48000)
232
  /* configure 2 flash wait states */
233
  FLASH->ACR |= (blt_int32u)FLASH_ACR_LATENCY_2;
234
#elif (BOOT_CPU_SYSTEM_SPEED_KHZ > 24000)
235
  /* configure 1 flash wait states */
236
  FLASH->ACR |= (blt_int32u)FLASH_ACR_LATENCY_1;
237
#endif
238
  /* HCLK = SYSCLK */
239
  RCC->CFGR |= (blt_int32u)RCC_CFGR_HPRE_DIV1;
240
  /* PCLK2 = HCLK/2 */
241
  RCC->CFGR |= (blt_int32u)RCC_CFGR_PPRE2_DIV2;
242
  /* PCLK1 = HCLK/2 */
243
  RCC->CFGR |= (blt_int32u)RCC_CFGR_PPRE1_DIV2;
244
  /* reset PLL configuration */
245
  RCC->CFGR &= (blt_int32u)((blt_int32u)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | \
246
                                          RCC_CFGR_PLLMULL));
247
  /* assert that the pll_multiplier is between 2 and 16 */
248
  ASSERT_CT((BOOT_CPU_SYSTEM_SPEED_KHZ/BOOT_CPU_XTAL_SPEED_KHZ) >= 2);
249
  ASSERT_CT((BOOT_CPU_SYSTEM_SPEED_KHZ/BOOT_CPU_XTAL_SPEED_KHZ) <= 16);
250
  /* calculate multiplier value */
251
  pll_multiplier = BOOT_CPU_SYSTEM_SPEED_KHZ/BOOT_CPU_XTAL_SPEED_KHZ;
252
  /* convert to register value */
253
  pll_multiplier = (blt_int32u)((pll_multiplier - 2) << 18);
254
  /* set the PLL multiplier and clock source */
255
  RCC->CFGR |= (blt_int32u)(RCC_CFGR_PLLSRC_HSE | pll_multiplier);
256
  /* enable PLL */
257
  RCC->CR |= RCC_CR_PLLON;
258
  /* wait till PLL is ready */
259
  while((RCC->CR & RCC_CR_PLLRDY) == 0)
260
  {
261
  }
262
  /* select PLL as system clock source */
263
  RCC->CFGR &= (blt_int32u)((blt_int32u)~(RCC_CFGR_SW));
264
  RCC->CFGR |= (blt_int32u)RCC_CFGR_SW_PLL;
265
  /* wait till PLL is used as system clock source */
266
  while ((RCC->CFGR & (blt_int32u)RCC_CFGR_SWS) != (blt_int32u)0x08)
267
  {
268
  }
269

    
270
  /* remap JTAG pins */
271
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
272
  AFIO->MAPR &= ~(blt_int32u)((blt_int32u)0x7 << 24);
273
  AFIO->MAPR |=  (blt_int32u)((blt_int32u)0x2 << 24);
274
  /* all input */
275

    
276
#if (BOOT_COM_CAN_ENABLE > 0 || BOOT_GATE_CAN_ENABLE > 0)
277
  /* enable clocks for CAN transmitter and receiver pins (GPIOB and AFIO) */
278
  RCC->APB2ENR |= (blt_int32u)(0x00000004 | 0x00000001);
279
  /* configure CAN Rx (GPIOA11) as alternate function input */
280
  /* first reset the configuration */
281
  GPIOA->CRH &= ~(blt_int32u)((blt_int32u)0xf << 12);
282
  /* CNF8[1:0] = %01 and MODE8[1:0] = %00 */
283
  GPIOA->CRH |= (blt_int32u)((blt_int32u)0x4 << 12);
284
  /* configure CAN Tx (GPIOA12) as alternate function push-pull */
285
  /* first reset the configuration */
286
  GPIOA->CRH &= ~(blt_int32u)((blt_int32u)0xf << 16);
287
  /* CNF9[1:0] = %11 and MODE9[1:0] = %11 */
288
  GPIOA->CRH |= (blt_int32u)((blt_int32u)0xb << 16);
289

    
290
  /* remap CAN1 pins to PortA */
291
  AFIO->MAPR &= ~(blt_int32u)((blt_int32u)0x3 << 13);
292
  AFIO->MAPR |=  (blt_int32u)((blt_int32u)0x0 << 13);
293
#endif
294

    
295
#if (BOOT_COM_UART_ENABLE > 0 || BOOT_GATE_UART_ENABLE > 0)
296
  /* enable clocks for USART1 peripheral, transmitter and receiver pins (GPIOA and AFIO) */
297
  RCC->APB2ENR |= (blt_int32u)(0x00004000 | 0x00000004 | 0x00000001);
298
  /* configure USART1 Tx (GPIOA9) as alternate function push-pull */
299
  /* first reset the configuration */
300
  GPIOA->CRH &= ~(blt_int32u)((blt_int32u)0xf << 4);
301
  /* CNF2[1:0] = %10 and MODE2[1:0] = %11 */
302
  GPIOA->CRH |= (blt_int32u)((blt_int32u)0xb << 4);
303
  /* configure USART1 Rx (GPIOA10) as alternate function input floating */
304
  /* first reset the configuration */
305
  GPIOA->CRH &= ~(blt_int32u)((blt_int32u)0xf << 8);
306
  /* CNF2[1:0] = %01 and MODE2[1:0] = %00 */
307
  GPIOA->CRH |= (blt_int32u)((blt_int32u)0x4 << 8);
308
#endif
309

    
310
} /*** end of Init ***/
311

    
312
/*
313
 * Initializes all GPIO used by the bootloader
314
 */
315
static void initGpio() {
316
  GPIO_InitTypeDef gpio_init;
317

    
318
  /*
319
   * OUTPUTS
320
   */
321

    
322
  /* initialize LED and push it up (inactive) */
323
  GPIO_SetBits(LED_GPIO, LED_PIN);
324
  gpio_init.GPIO_Pin    = LED_PIN;
325
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_PP;
326
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
327
  GPIO_Init(LED_GPIO, &gpio_init);
328

    
329
  /* initialize SYS_PD_N and let it go (inactive) */
330
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
331
  gpio_init.GPIO_Pin    = SYS_PD_N_PIN;
332
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_OD;
333
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
334
  GPIO_Init(SYS_PD_N_GPIO, &gpio_init);
335

    
336
  /* initialize SYS_SYNC_N and pull it down (active) */
337
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
338
  gpio_init.GPIO_Pin    = SYS_SYNC_N_PIN;
339
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_OD;
340
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
341
  GPIO_Init(SYS_SYNC_N_GPIO, &gpio_init);
342

    
343
  /* initialize SYS_WARMST_N and let it go (active) */
344
  GPIO_SetBits(SYS_WARMRST_N_GPIO, SYS_WARMRST_N_PIN);
345
  gpio_init.GPIO_Pin    = SYS_WARMRST_N_PIN;
346
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_OD;
347
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
348
  GPIO_Init(SYS_WARMRST_N_GPIO, &gpio_init);
349

    
350
  /* initialize SYS_UART_UP and let it go (inactive) */
351
  GPIO_SetBits(SYS_UART_UP_GPIO, SYS_UART_UP_PIN);
352
  gpio_init.GPIO_Pin    = SYS_UART_UP_PIN;
353
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_OD;
354
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
355
  GPIO_Init(SYS_UART_UP_GPIO, &gpio_init);
356

    
357
  /* initialize PATH_DCEN and pull it down (inactive) */
358
  GPIO_ResetBits(PATH_DCEN_GPIO, PATH_DCEN_PIN);
359
  gpio_init.GPIO_Pin    = PATH_DCEN_PIN;
360
  gpio_init.GPIO_Mode   = GPIO_Mode_Out_PP;
361
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
362
  GPIO_Init(PATH_DCEN_GPIO, &gpio_init);
363

    
364
  /*
365
   * INPUTS
366
   */
367

    
368
  /* initialize the input IMU_INT */
369
  gpio_init.GPIO_Pin    = IMU_INT_PIN;
370
  gpio_init.GPIO_Mode   = GPIO_Mode_IN_FLOATING;
371
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
372
  GPIO_Init(IMU_INT_GPIO, &gpio_init);
373

    
374
  return;
375
} /*** end of initGpio ***/
376

    
377
/*
378
 * Initialize all EXTI lines
379
 */
380
static void initExti() {
381
  /* configure EXTI lines */
382
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource1); // SYS_SYNC_N
383
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource2); // SYS_WARMRST_N
384
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource3); // PATH_DCSTAT
385
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource8); // SYS_PD_N
386
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource9); // SYS_REG_EN
387
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12); // IR_INT
388
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource14); // SYS_UART_UP
389
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource15); // IMU_INT
390

    
391
  return;
392
} /*** end of initExti ***/
393

    
394
/*
395
 * Signals, which type of low-power mode the system shall enter after the shutdown sequence.
396
 */
397
ErrorStatus shutdownDisambiguationProcedure(const uint8_t type) {
398
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
399
  ErrorStatus ret_val = ERROR;
400

    
401
  switch (type) {
402
    case BL_SHUTDOWN_PRI_RSN_UNKNOWN:
403
    case BL_SHUTDOWN_PRI_RSN_HIBERNATE:
404
    case BL_SHUTDOWN_PRI_RSN_DEEPSLEEP:
405
    case BL_SHUTDOWN_PRI_RSN_TRANSPORT:
406
    {
407
      // broadcast a number of pulses, depending on the argument
408
      uint8_t pulse_counter = 0;
409
      for (pulse_counter = 0; pulse_counter < type; ++pulse_counter) {
410
        msleep(1);
411
        GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
412
        msleep(1);
413
        GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
414
      }
415
      // wait for timeout
416
      msleep(10);
417
      ret_val = SUCCESS;
418
      break;
419
    }
420
    case BL_SHUTDOWN_PRI_RSN_RESTART:
421
    {
422
      // since there is no ambiguity for restart requests, no pulses are generated
423
      msleep(10);
424
      ret_val = SUCCESS;
425
      break;
426
    }
427
    default:
428
      ret_val = ERROR;
429
      break;
430
  }
431

    
432
  return ret_val;
433
} /*** end of shutdownDisambiguationProcedure ***/
434

    
435
/*
436
 * Final shutdown of the system to enter transportation mode.
437
 */
438
void shutdownToTransportation(const blt_bool exec_disambiguation) {
439
  /* configure some criticpal GPIOs as input
440
   * This is required, because otherwise some hardware might be powered through these signals */
441
  configGpioForShutdown();
442

    
443
  /* turn off the motors */
444
  GPIO_ResetBits(POWER_EN_GPIO, POWER_EN_PIN);
445

    
446
  /* deactivate the WKUP pin */
447
  PWR_WakeUpPinCmd(DISABLE);
448

    
449
  /* deactivate any RTC related events */
450
  RTC_ITConfig(RTC_IT_ALR | RTC_IT_OW | RTC_IT_SEC, DISABLE);
451
  RTC_ClearFlag(~0);
452

    
453
  /* disable the IWDG */
454
  IWDG_ReloadCounter();
455

    
456
  /* wait for all boards to be ready for shutdown */
457
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
458
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
459
    // this must skipped if the pullup voltage (VIO3.3) is not active
460
    setLed(BLT_TRUE);
461
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
462
    setLed(BLT_FALSE);
463
  }
464

    
465
  if (exec_disambiguation == BLT_TRUE) {
466
    /* execute disambiguation procedure and signal all modules to enter transportation mode */
467
    if (shutdownDisambiguationProcedure(BL_SHUTDOWN_PRI_RSN_TRANSPORT) != SUCCESS) {
468
      blinkSOS(1);
469
      msleep(10);
470
    }
471
  }
472

    
473
  /* morse 'OK' via the LED to signal that shutdown was successful */
474
  blinkOK(1);
475

    
476
  /* enter standby mode */
477
  PWR_EnterSTANDBYMode();
478

    
479
  return;
480
} /*** end of shutdownToTransportation ***/
481

    
482
/*
483
 * Final shutdown of the system to enter deepsleep mode.
484
 */
485
void shutdownToDeepsleep(const blt_bool exec_disambiguation) {
486
  /* configure some criticpal GPIOs as input
487
   * This is required, because otherwise some hardware might be powered through these signals */
488
  configGpioForShutdown();
489

    
490
  /* turn off the motors */
491
  GPIO_ResetBits(POWER_EN_GPIO, POWER_EN_PIN);
492

    
493
  /* deactivate the WKUP pin */
494
  PWR_WakeUpPinCmd(ENABLE);
495

    
496
  /*
497
   * Configuration of RTC and IWDG belongs to the OS.
498
   */
499

    
500
  /* wait for all boards to be ready for shutdown */
501
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
502
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
503
    // this must skipped if the pullup voltage (VIO3.3) is not active
504
    setLed(BLT_TRUE);
505
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
506
    setLed(BLT_FALSE);
507
  }
508

    
509
  if (exec_disambiguation == BLT_TRUE) {
510
    /* execute disambiguation procedure and signal all modules to enter deepsleep mode */
511
    if (shutdownDisambiguationProcedure(BL_SHUTDOWN_PRI_RSN_DEEPSLEEP) != SUCCESS) {
512
      blinkSOS(1);
513
      msleep(10);
514
    }
515
  }
516

    
517
  /* morse 'OK' via the LED to signal that shutdown was successful */
518
  blinkOK(1);
519

    
520
  /* enter standby mode */
521
  PWR_EnterSTANDBYMode();
522

    
523
  return;
524
} /*** end of shutdownToDeepsleep ***/
525

    
526
/*
527
 * Final shutdown of the system to enter hibernate mode.
528
 */
529
void shutdownToHibernate(const blt_bool exec_disambiguation) {
530
  /* configure some criticpal GPIOs as input
531
   * This is required, because otherwise some hardware might be powered through these signals */
532
  configGpioForShutdown();
533

    
534
  /* turn off the motors */
535
  GPIO_ResetBits(POWER_EN_GPIO, POWER_EN_PIN);
536

    
537
  /* deactivate the WKUP pin */
538
  PWR_WakeUpPinCmd(ENABLE);
539

    
540
  /*
541
   * Configuration of RTC and IWDG belongs to the OS.
542
   */
543

    
544
  /* wait for all boards to be ready for shutdown */
545
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
546
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
547
    // this must skipped if the pullup voltage (VIO3.3) is not active
548
    setLed(BLT_TRUE);
549
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
550
    setLed(BLT_FALSE);
551
  }
552

    
553
  if (exec_disambiguation == BLT_TRUE) {
554
    /* execute disambiguation procedure and signal all modules to enter deepsleep mode */
555
    if (shutdownDisambiguationProcedure(BL_SHUTDOWN_PRI_RSN_HIBERNATE) != SUCCESS) {
556
      blinkSOS(1);
557
      msleep(10);
558
    }
559
  }
560

    
561
  /* morse 'OK' via the LED to signal that shutdown was successful */
562
  blinkOK(1);
563

    
564
  /* enter standby mode */
565
  PWR_EnterSTANDBYMode();
566

    
567
  return;
568
} /* end of shutdownToHibernate ***/
569

    
570
/*
571
 * Final shutdown of the system and restart.
572
 */
573
void shutdownAndRestart(const blt_bool exec_disambiguation) {
574
  /* configure some criticpal GPIOs as input
575
   * This is required, because otherwise some hardware might be powered through these signals */
576
  configGpioForShutdown();
577

    
578
  /* turn off the motors */
579
  GPIO_ResetBits(POWER_EN_GPIO, POWER_EN_PIN);
580

    
581
  /* prepare for low-power mode */
582
  PWR_WakeUpPinCmd(DISABLE); // disable WKUP pin
583
  RTC_ITConfig(RTC_IT_ALR | RTC_IT_OW | RTC_IT_SEC, DISABLE); // unset RTC events
584
  RTC_ClearFlag(~0); // clear pending RTC events
585
  IWDG_ReloadCounter(); // disable IWDG
586

    
587
  /* wait for all boards to be ready for shutdown */
588
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
589
  if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
590
    // this must skipped if the pullup voltage (VIO3.3) is not active
591
    setLed(BLT_TRUE);
592
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
593
    setLed(BLT_FALSE);
594
  }
595

    
596
  if (exec_disambiguation == BLT_TRUE) {
597
    /* execute disambiguation procedure and signal all modules to restart in default mode */
598
    if (shutdownDisambiguationProcedure(BL_SHUTDOWN_PRI_RSN_RESTART) != SUCCESS) {
599
      blinkSOS(1);
600
      msleep(10);
601
    }
602
  }
603

    
604
  /* morse 'OK' via the LED to signal that shutdown was successful */
605
  blinkOK(1);
606

    
607
  /* enter standby mode */
608
  PWR_EnterSTANDBYMode();
609

    
610
  /*
611
   * Even though this module will not restart the system by its own, the PowerManagement will reset the system.
612
   */
613

    
614
  return;
615
} /*** end of shutdownAndRestart***/
616

    
617
/*
618
 * Configures some GPIO pins as inputs for safety reasons.
619
 * Under certain circumstances, these pins might power hardware that is supposed to be shut down.
620
 */
621
void configGpioForShutdown() {
622
  /* setup the configuration */
623
  GPIO_InitTypeDef gpio_init;
624
  gpio_init.GPIO_Mode   = GPIO_Mode_IN_FLOATING;
625
  gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
626

    
627
  /* configure SYS_UART_TX */
628
  gpio_init.GPIO_Pin = SYS_UART_TX_PIN;
629
  GPIO_Init(SYS_UART_TX_GPIO, &gpio_init);
630

    
631
  /* configure CAN_TX */
632
  gpio_init.GPIO_Pin = CAN_TX_PIN;
633
  GPIO_Init(CAN_TX_GPIO, &gpio_init);
634

    
635
  return;
636
} /*** end of configGpioForShutdown ***/
637

    
638
/*
639
 * System was reset via the NRST pin or the reason could not be detected.
640
 * In this case, there are three possibilities how to act:
641
 * 1) When the SYS_WARMRST_N signal becomes inactive, flashing mode is entered and the system will try to load the OS.
642
 * 2) When the SYS_UART_UP signal becomes active (low), the system will enter hibernate mode to enable charging via the pins.
643
 * 3) If none of both happens and a timeout occurs, the system enters deepsleep mode.
644
 */
645
ErrorStatus handleColdReset() {
646
  /* wait until either the SYS_WARMRST_N signal goes up, or SYS_UART_UP goes down */
647
  enum CRST_SIG {CRST_SIG_SYS_WARMRST_N,
648
                 CRST_SIG_SYS_UART_UP,
649
                 CRST_SIG_TIMEOUT
650
                } sig;
651
  uint32_t loopStartTime = 0;
652
  saTimerUpdate(&loopStartTime);
653
  uint32_t currentTime = loopStartTime;
654
  setLed(BLT_TRUE);
655
  while (1) {
656
    /* read the input signals */
657
    if (GPIO_ReadInputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET &&
658
        GPIO_ReadInputDataBit(SYS_WARMRST_N_GPIO, SYS_WARMRST_N_PIN) == Bit_SET) {
659
      sig = CRST_SIG_SYS_WARMRST_N;
660
      break;
661
    }
662
    if (GPIO_ReadInputDataBit(SYS_UART_UP_GPIO, SYS_UART_UP_PIN) == Bit_RESET) {
663
      sig = CRST_SIG_SYS_UART_UP;
664
      break;
665
    }
666

    
667
    /* check for a timeout */
668
    saTimerUpdate(&currentTime);
669
    if (currentTime > loopStartTime + RESET_TIMEOUT_MS) {
670
      sig = CRST_SIG_TIMEOUT;
671
      break;
672
    }
673
  }
674
  setLed(BLT_FALSE);
675

    
676
  /* depending on the signal, react accordingly */
677
  switch (sig) {
678
    /* activation of the slave modules signales to boot the OS */
679
    case CRST_SIG_SYS_WARMRST_N:
680
    {
681
      /* enable CAN clock */
682
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
683

    
684
      /* initialize the bootloader */
685
      BootInit();
686

    
687
      /* start the infinite program loop */
688
      uint32_t loopStartTime = 0;
689
      saTimerUpdate(&loopStartTime);
690
      uint32_t currentTime = loopStartTime;
691
      while (1)
692
      {
693
//        /* make the LED "double-blink" */
694
//        saTimerUpdate(&currentTime);
695
//        if (currentTime < loopStartTime + 50) {
696
//          setLed(BLT_TRUE);
697
//        } else if (currentTime < loopStartTime + 50+100) {
698
//          setLed(BLT_FALSE);
699
//        } else if (currentTime < loopStartTime + 50+100+50) {
700
//          setLed(BLT_TRUE);
701
//        } else if ( currentTime < loopStartTime + 50+100+50+300) {
702
//          setLed(BLT_FALSE);
703
//        } else {
704
//          loopStartTime = currentTime;
705
//        }
706

    
707
        /* run the bootloader task */
708
        BootTask();
709

    
710
        /* check the SYS_PD_N signal */
711
        if (GPIO_ReadInputDataBit(SYS_PD_N_GPIO, SYS_PD_N_PIN) == Bit_RESET) {
712
          blCallbackHandleShutdownRequest();
713
          return SUCCESS;
714
        }
715
      }
716

    
717
      break;
718
    }
719
    /* activation of the UART_UP signal indicates that this module shall enter hibernate mode */
720
    case CRST_SIG_SYS_UART_UP:
721
    {
722
      /* indicate that the MCU is busy */
723
      GPIO_ResetBits(SYS_UART_UP_GPIO, SYS_UART_UP_PIN);
724

    
725
      /* enable the charging pins */
726
      GPIO_SetBits(PATH_DCEN_GPIO, PATH_DCEN_PIN);
727

    
728
      /* wait some time so the systen voltage (VSYS) is stable if it is supplied via the pins */
729
      msleep(10);
730

    
731
      /* indicate that the MCU is not busy anymore */
732
      GPIO_SetBits(SYS_UART_UP_GPIO, SYS_UART_UP_PIN);
733

    
734
      /* configure the IMU external interrupt as event */
735
      EXTI_InitTypeDef exti;
736
      exti.EXTI_Line = EXTI_Line15;
737
      exti.EXTI_Mode = EXTI_Mode_Event;
738
      exti.EXTI_Trigger = EXTI_Trigger_Falling;
739
      exti.EXTI_LineCmd = ENABLE;
740
      EXTI_Init(&exti);
741

    
742
      /* sleep until something happens */
743
      __WFE();
744

    
745
      /* clear all pending EXTI events */
746
      EXTI_DeInit();
747
      EXTI_ClearFlag(EXTI_Line15);
748

    
749
      /* handle IMU wakeup
750
       * note: In fact, the only events that will occur at this point are an interrupt event from the IMU, or a
751
       * system reset from the PowerManagement via the NRST pin. Thus, if the following code is reached, it must have
752
       * been the IMU.
753
       */
754

    
755
      /* as as after a normal wakeup from the IMU */
756
      return handleImuWakeup();
757

    
758
      break;
759
    }
760
    /* if a timeout occurred, the system enters deepsleep mode */
761
    case CRST_SIG_TIMEOUT:
762
    {
763
      /* reconfigure the LED_GPIO as input so it will not light up (and thus save energy) */
764
      GPIO_InitTypeDef gpio_init;
765
      gpio_init.GPIO_Pin    = LED_PIN;
766
      gpio_init.GPIO_Mode   = GPIO_Mode_IN_FLOATING;
767
      gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
768
      GPIO_Init(LED_GPIO, &gpio_init);
769

    
770
      /* reconfigure SYS_PD_N as input so the callback will not indicate a shutdown */
771
      gpio_init.GPIO_Pin    = SYS_PD_N_PIN;
772
      gpio_init.GPIO_Mode   = GPIO_Mode_IN_FLOATING;
773
      gpio_init.GPIO_Speed  = GPIO_Speed_50MHz;
774
      GPIO_Init(SYS_PD_N_GPIO, &gpio_init);
775

    
776
      blCallbackShutdownDeepsleep();
777
      break;
778
    }
779
    default:
780
      break;
781
  }
782

    
783
  return ERROR;
784
} /*** end of handleColdReset ***/
785

    
786
/*
787
 * System was woken up via the WKUP pin and the SYS_UART_UP signal was found to be responsible.
788
 * In this case, the system starts as after a cold reset.
789
 */
790
ErrorStatus handleUartWakeup() {
791
  return handleColdReset();
792
} /*** end of handleUartWakeup ***/
793

    
794
/*
795
 * System was woken up via the WKUP pin and the IMU_INT signal was found to be responsible.
796
 * The SYS_UART_UP signal is used to wake the PowerManagement before a normal cold reset is performed.
797
 */
798
ErrorStatus handleImuWakeup() {
799
  /* wakeup the PowerManegement (ensure that the pulse is detected) */
800
  GPIO_ResetBits(SYS_UART_UP_GPIO, SYS_UART_UP_PIN);
801
  msleep(1);
802
  GPIO_SetBits(SYS_UART_UP_GPIO, SYS_UART_UP_PIN);
803

    
804
  return handleColdReset();
805
} /*** end of handleImuWakeu ***/
806

    
807
/*
808
 * Callback function that handles the system shutdown and enters transportation mode.
809
 * When called from a multithreaded environment, it must be ensured that no other thread will preempt this function.
810
 * In transportation low-power mode the system can only be woken up by pulling down the NRST signal.
811
 * Furthermore, the system can not be charged when in transportation mode.
812
 */
813
void blCallbackShutdownTransportation(void) {
814
  /* make sure that the required clocks are activated */
815
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
816
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
817

    
818
  /* set/keep the SYS_SYNC and SYS_PD signals active */
819
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
820
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
821

    
822
  setLed(BLT_TRUE);
823
  saTimerInit();
824

    
825
  shutdownToTransportation(BLT_TRUE);
826

    
827
  return;
828
} /*** end of blCallbackShutdownTransportation ***/
829

    
830
/*
831
 * Callback function that handles the system shutdown and enters deepsleep mode.
832
 * When called from a multithreaded environment, it must be ensured that no other thread will preempt this function.
833
 * In deepsleep low-power mode the system can only be woken up via the NRST or the WKUP signal, or the RTC or IWDG, if configured.
834
 */
835
void blCallbackShutdownDeepsleep(void) {
836
  /* make sure that the required clocks are activated */
837
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
838
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
839

    
840
  /* set/keep the SYS_SYNC and SYS_PD signals active */
841
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
842
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
843

    
844
  saTimerInit();
845

    
846
  shutdownToDeepsleep(BLT_TRUE);
847

    
848
  return;
849
} /*** end of blCallbackShutdownDeepsleep ***/
850

    
851
/*
852
 * Callback function that handles the system shutdown and enters hibernate mode.
853
 * When called from a multithreaded environment, it must be ensured that no other thread will preempt this function.
854
 */
855
void blCallbackShutdownHibernate(void) {
856
  /* make sure that the required clocks are activated */
857
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
858
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
859

    
860
  /* set/keep the SYS_SYNC and SYS_PD signals active */
861
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
862
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
863

    
864
  saTimerInit();
865

    
866
  shutdownToHibernate(BLT_TRUE);
867

    
868
  return;
869
} /*** end of blCallbackShutdownHibernate ***/
870

    
871
/*
872
 * Callback function that handles the system shutdown and initializes a restart.
873
 * When called from a multithreaded environment, it must be ensured that no other thread will preempt this function.
874
 */
875
void blCallbackShutdownRestart(void) {
876
  /* make sure that the required clocks are activated */
877
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
878
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
879

    
880
  /* set/keep the SYS_SYNC and SYS_PD signal active */
881
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
882
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
883

    
884
  /* ensure that all modules had a chance to detect the pulse on SYS_PD_N */
885
  saTimerInit();
886
  msleep(1);
887
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
888
  msleep(1);
889

    
890
  shutdownAndRestart(BLT_TRUE);
891

    
892
  return;
893
} /*** end of blCallbackRestart ***/
894

    
895
/*
896
 * Callback function that handles a system shutdown/restart request from another module.
897
 * Depending on the result of the disambiguation procedure, the module will enter the according low-power mode or restart.
898
 * When called from a multithreaded environment, it must be ensured that no other thread will preempt this function.
899
 */
900
void blCallbackHandleShutdownRequest(void) {
901
  /* make sure that the required clocks are activated */
902
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
903
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
904

    
905
  /* set/keep the SYS_SYNC and SYS_PD signal active */
906
  GPIO_ResetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
907
  GPIO_ResetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
908

    
909
  /* initialized the standalone timer */
910
  saTimerInit();
911

    
912
  setLed(BLT_TRUE);
913

    
914
  /* deactivate SYS_PD_N and ensure that all modules had a chance to detect the falling edge */
915
  msleep(1);
916
  GPIO_SetBits(SYS_PD_N_GPIO, SYS_PD_N_PIN);
917
  msleep(1);
918

    
919
  /* wait for all boards to be ready for shutdown */
920
  GPIO_SetBits(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN);
921
  if (GPIO_ReadOutputDataBit(SYS_REG_EN_GPIO, SYS_REG_EN_PIN) == Bit_SET) {
922
    // this must skipped if the pullup voltage (VIO3.3) is not active
923
    setLed(BLT_TRUE);
924
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
925
    setLed(BLT_FALSE);
926
  }
927

    
928
  /* check ths SYS_PD_N signal, whether the system shall shutdown or restart */
929
  blt_bool shutdown_nrestart = (GPIO_ReadInputDataBit(SYS_PD_N_GPIO, SYS_PD_N_PIN) == Bit_RESET) ? BLT_TRUE : BLT_FALSE;
930

    
931
  /* disambiguation procedure (passive) */
932
  uint32_t pulse_counter = 0;
933
  while (waitForSignalTimeout(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_RESET, 10)) {
934
    waitForSignal(SYS_SYNC_N_GPIO, SYS_SYNC_N_PIN, Bit_SET);
935
    ++pulse_counter;
936
  }
937

    
938
  /* evaluate and hanlde disambiguation result */
939
  if (shutdown_nrestart == BLT_TRUE) {
940
    /* shutdown request */
941

    
942
    /* handle special cases */
943
    if (pulse_counter == BL_SHUTDOWN_PRI_RSN_UNKNOWN) {
944
      /* no pulse at all was received */
945
      pulse_counter = BL_SHUTDOWN_PRI_RSN_DEFAULT;
946
    } else if (pulse_counter != BL_SHUTDOWN_PRI_RSN_HIBERNATE &&
947
               pulse_counter != BL_SHUTDOWN_PRI_RSN_DEEPSLEEP &&
948
               pulse_counter != BL_SHUTDOWN_PRI_RSN_TRANSPORT) {
949
      /* invalid number of pulses received */
950
      blinkSOS(1);
951
      pulse_counter = BL_SHUTDOWN_PRI_RSN_DEFAULT;
952
    }
953

    
954
    switch (pulse_counter) {
955
      case BL_SHUTDOWN_PRI_RSN_HIBERNATE:
956
        shutdownToHibernate(BLT_FALSE);
957
        break;
958
      case BL_SHUTDOWN_PRI_RSN_DEEPSLEEP:
959
        shutdownToDeepsleep(BLT_FALSE);
960
        break;
961
      case BL_SHUTDOWN_PRI_RSN_TRANSPORT:
962
        shutdownToTransportation(BLT_FALSE);
963
        break;
964
    }
965
  } else {
966
    /* restart request */
967

    
968
    /* there is no ambiguity for restart, so it is ignored */
969
    shutdownAndRestart(BLT_FALSE);
970
  }
971

    
972
  /* if this code is reached, the system did neither shut down, nor restart.
973
   * This must never be the case!
974
   */
975
  blinkSOSinf();
976
  return;
977
} /*** end of blCallbackHandleShutdownRequest ***/
978

    
979
/*********************************** end of main.c *************************************/