25
25
*/
26
26
27
27
#include <openbeacon.h>
28
+ #include <uart.h>
28
29
#include <acc.h>
29
30
#include <flash.h>
30
31
#include <radio.h>
@@ -38,6 +39,7 @@ uint8_t hibernate = 0;
38
39
uint16_t status_flags = 0 ;
39
40
uint8_t boot_count ;
40
41
uint32_t reset_reason ;
42
+ uint8_t uart_enabled = 0 ;
41
43
42
44
43
45
void blink (uint8_t times )
@@ -99,10 +101,14 @@ void main_entry(void)
99
101
reset_reason = NRF_POWER -> RESETREAS ;
100
102
NRF_POWER -> RESETREAS = 0 ;
101
103
102
- /* if reset was externally triggered, boot into hibernation mode */
104
+ /* if reset was externally triggered,
105
+ boot into hibernation mode and enable serial port */
103
106
if ( (reset_reason & POWER_RESETREAS_RESETPIN_Msk ) ||
104
107
(reset_reason & POWER_RESETREAS_SREQ_Msk ) )
108
+ {
105
109
hibernate = 1 ;
110
+ uart_enabled = 1 ;
111
+ }
106
112
107
113
/* get/update boot counter -- register is retained
108
114
across resets as long as the device is powered */
@@ -121,7 +127,6 @@ void main_entry(void)
121
127
122
128
/* initialize UART */
123
129
uart_init ();
124
- uart_enable (1 );
125
130
126
131
/* start timer */
127
132
timer_init ();
@@ -142,13 +147,12 @@ void main_entry(void)
142
147
halt (3 );
143
148
144
149
/* start radio */
145
- debug_printf ("\n\rInitializing Tag[%08X] v" PROGRAM_VERSION " @24%02iMHz ...\n\r" ,
150
+ if (uart_enabled )
151
+ debug_printf ("\n\rInitializing Tag[%08X] v" PROGRAM_VERSION " @24%02iMHz ...\n\r" ,
146
152
tag_id ,
147
153
CONFIG_TRACKER_CHANNEL );
148
154
radio_init (tag_id );
149
155
150
- uart_enable (0 );
151
-
152
156
/* enter main loop */
153
157
blink_fast (5 );
154
158
@@ -172,16 +176,14 @@ void main_entry(void)
172
176
keypress_duration = blink_wait_release ();
173
177
174
178
/* long key press while tag is hibernating triggers log dump */
175
- if (hibernate && (keypress_duration > 2000 ))
179
+ if (hibernate && uart_enabled && (keypress_duration > 2000 ))
176
180
{
177
181
#if CONFIG_FLASH_LOGGING
178
182
blink_fast (10 );
179
183
180
184
/* dump log data & status to serial */
181
- uart_enable (1 );
182
185
flash_log_dump ();
183
186
flash_log_status ();
184
- uart_enable (0 );
185
187
#endif /* CONFIG_FLASH_LOGGING */
186
188
} else if (keypress_duration > 500 )
187
189
{
@@ -195,9 +197,8 @@ void main_entry(void)
195
197
#endif /* CONFIG_FLASH_LOGGING */
196
198
197
199
blink_fast (hibernate ? 3 : 6 );
198
- uart_enable (1 );
199
- debug_printf ("\n\rhibernate -> %i" , hibernate );
200
- uart_enable (0 );
200
+ if (uart_enabled )
201
+ debug_printf ("\n\rhibernate -> %i" , hibernate );
201
202
}
202
203
}
203
204
0 commit comments