MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderboard_stm32h7b3i_dk_annunciator.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderboard_stm32h7b3i_dk_annunciator.c
4
5Function:
6 Annunciator (LED flashing) functions for STM32H7B3I_DK boards
7
8Copyright and License:
9 This file copyright (C) 2021 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 ChaeHee Won, MCCI Corporation June 2021
19
20*/
21
23
24#include "mcci_bootloader.h"
25
26/****************************************************************************\
27|
28| Manifest constants & typedefs.
29|
30\****************************************************************************/
31
32typedef struct Stm32h7b3iDk_Annunciator_s Stm32h7b3iDk_Annunciator_t;
33
34typedef enum
35 {
36 stNoChange = -1, ///< internal: don't change state.
37 stInitial, ///< not initialized
38 stIdle, ///< not displaying
39 stLedOn, ///< light is on
40 stBitGap, ///< displaying bit gap
41 stByteGap, ///< displaying byte gap
43
44struct Stm32h7b3iDk_Annunciator_s
45 {
46 uint32_t tick;
47 uint32_t display;
48 uint32_t value;
49 uint32_t bittime;
50 uint32_t timer;
51 McciBootloaderState_t bootState;
52 AnnunciatorBitState_t bitState;
53 };
54
55/****************************************************************************\
56|
57| Read-only data.
58|
59\****************************************************************************/
60
61
62
63/****************************************************************************\
64|
65| Variables.
66|
67\****************************************************************************/
68
69static Stm32h7b3iDk_Annunciator_t annunciator;
70
71void
73 void
74 )
75 {
76 /// enable interrupts
77 McciArm_setPRIMASK(0);
78 annunciator.bittime = 100; // 100 ms per bit.
79 annunciator.bitState = stIdle;
80 }
81
82void
85 )
86 {
87 if (state != 0)
88 {
89 uint32_t display = ((uint32_t)state << 1) | 1;
90 unsigned nBits;
91 // always put at least 2 bits
92 for (nBits = 31; nBits > 2; --nBits)
93 {
94 if (display & (UINT32_C(1) << nBits))
95 break;
96 }
97
98 // if display is 2^k-1, then add a bit, so we have
99 // a time contrast on long pulses.
100 if (((display + 1) & display) == 0)
101 ++nBits;
102
103 annunciator.display = (uint32_t)display << (31 - nBits);
104 }
105 else
106 annunciator.display = 0;
107 }
108
109static bool
111 {
112 bool fNextBit = !!(annunciator.value & UINT32_C(0x80000000));
113 annunciator.value <<= 1;
114 if (annunciator.value == 0)
115 return false;
116
118 annunciator.timer = annunciator.tick + annunciator.bittime * (1 + 2 * fNextBit);
119 return true;
120 }
121
122void
124 void
125 )
126 {
127 const uint32_t now = annunciator.tick + 1;
128 annunciator.tick = now;
130
131 switch (annunciator.bitState)
132 {
133 default:
134 case stInitial:
135 nextState = stInitial;
136 annunciator.bitState = stInitial;
137 return;
138
139 case stIdle:
140 if (annunciator.display != 0)
141 {
142 annunciator.value = annunciator.display;
143 nextBit();
144 nextState = stLedOn;
145 }
146 break;
147
148 case stLedOn:
149 if ((int32_t)(now - annunciator.timer) >= 0)
150 {
152 annunciator.timer = now + annunciator.bittime;
153 nextState = stBitGap;
154 }
155 break;
156
157 case stBitGap:
158 if ((int32_t)(now - annunciator.timer) >= 0)
159 {
160 if (nextBit())
161 nextState = stLedOn;
162 else
163 {
164 nextState = stByteGap;
165 annunciator.timer = now + 2 * annunciator.bittime;
166 }
167 }
168 break;
169
170 case stByteGap:
171 if ((int32_t)(now - annunciator.timer) >= 0)
172 {
173 annunciator.value = annunciator.display;
174 if (nextBit())
175 nextState = stLedOn;
176 else
177 {
178 nextState = stIdle;
179 }
180 }
181 break;
182 }
183
184 if (nextState != stNoChange)
185 annunciator.bitState = nextState;
186 }
187
188/**** end of mccibootloaderboard_stm32h7b3i_dk_annunciator.c ****/
void McciBootloaderBoard_Stm32h7b3iDk_setLed(void)
McciBootloaderPlatform_AnnunciatorIndicateStateFn_t McciBootloaderBoard_Stm32h7b3iDk_annunciatorIndicateState
void McciBootloaderBoard_Stm32h7b3iDk_clearLed(void)
uint32_t McciBootloaderState_t
Current boot system state.
void McciBootloaderBoard_Stm32h7b3iDk_annunciatorInit(void)
static Stm32h7b3iDk_Annunciator_t annunciator
@ stByteGap
displaying byte gap
@ stNoChange
internal: don't change state.
@ stBitGap
displaying bit gap
void McciBootloaderBoard_Stm32h7b3iDk_handleSysTick(void)