MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderboard_catenaabz_annunciator.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderboard_catenaabz_annunciator.c
4
5Function:
6 Annunciator (LED flashing) functions for ABZ-based Catena 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 Terry Moore, MCCI Corporation March 2021
19
20*/
21
23
24#include "mcci_bootloader.h"
25
26/****************************************************************************\
27|
28| Manifest constants & typedefs.
29|
30\****************************************************************************/
31
32typedef struct CatenaAbz_Annuciator_s CatenaAbz_Annuciator_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 CatenaAbz_Annuciator_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 CatenaAbz_Annuciator_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
169 case stByteGap:
170 if ((int32_t)(now - annunciator.timer) >= 0)
171 {
172 annunciator.value = annunciator.display;
173 if (nextBit())
174 nextState = stLedOn;
175 else
176 {
177 nextState = stIdle;
178 }
179 }
180 break;
181 }
182
183 if (nextState != stNoChange)
184 annunciator.bitState = nextState;
185 }
186
187/**** end of mccibootloaderboard_catenaabz_annunciator.c ****/
McciBootloaderPlatform_AnnunciatorIndicateStateFn_t McciBootloaderBoard_CatenaAbz_annunciatorIndicateState
void McciBootloaderBoard_CatenaAbz_clearLed(void)
void McciBootloaderBoard_CatenaAbz_setLed(void)
uint32_t McciBootloaderState_t
Current boot system state.
static bool nextBit(void)
static CatenaAbz_Annuciator_t annunciator
@ stByteGap
displaying byte gap
@ stNoChange
internal: don't change state.
@ stBitGap
displaying bit gap
@ stInitial
not initialized
void McciBootloaderBoard_CatenaAbz_annunciatorInit(void)
void McciBootloaderBoard_CatenaAbz_handleSysTick(void)