maintenance.c
Go to the documentation of this file.
1 #include <asf.h>
2 #include "misc/rtos.h"
3 #include "maintenance.h"
4 #include "d_flash.h"
5 #include "bootloaderApp.h"
6 #include "globals.h"
7 
8 
9 
10 void led_maintenance(void)
11 {
12  if( g_nvmFlashCfg->sysCfgBits & SYS_CFG_BITS_DISABLE_LEDS )
13  {
14  LEDS_ALL_OFF();
15  return;
16  }
17 
18  int solStatus = INS_STATUS_SOLUTION(g_insStatus);
19 
20 #if LED_SCHEME==LED_SCHEME_BLINK
21  // System Slow Blink Flash
23 
24  // Red LED
25  switch( g_sc.calState )
26  {
27  // Calibration in Progress
28  default:
29  LED_ON(LED_RED);
30  break;
31 
32  // GPS Status
33  case SC_RUNTIME:
34  case SC_TCAL_DONE:
35  // end LED Flash
36  if( g_gpsTimeOfWeekMs >= g_led.gps_timeMs )
37  LED_OFF(LED_GPS_STATUS);
38  break;
39  }
40 
41 // if( g_led.heartbeat_cnt > 50 ) // incremented in solution task
42 // {
43 // g_led.heartbeat_cnt = 0;
44 // LED_TOGGLE(LED_SYS_HEALTH);
45 // }
46 #elif LED_SCHEME==LED_SCHEME_HEARTBEAT
47  // System Heart Beat Flash
49  vTaskDelay( mainLED_FLASH_RATE );
50  // End LED Flash
51  if( g_gpsTimeOfWeekMs >= g_led.gps_timeMs )
52  LED_OFF(LED_GPS_STATUS);
53 
54  // System LED Heartbeat
55 #define HEARTBEAT_RAMP_RATE (500/mainLED_FLASH_RATE)
56 #define HEARTBEAT_WAIT (100/mainLED_FLASH_RATE)
57  switch(g_led.heartbeat_state)
58  {
59  default: // ramp up
60  g_led.heartbeat_duty += HEARTBEAT_RAMP_RATE;
61 
62  if( g_led.heartbeat_duty >= 100 )
63  {
64  g_led.heartbeat_duty = 100;
65  g_led.heartbeat_cnt = 0;
66  g_led.heartbeat_state = 1;
67  }
68  set_LED_PWM(g_led.heartbeat_duty);
69  break;
70 
71  case 1: // Wait
72  if( ++g_led.heartbeat_cnt >= HEARTBEAT_WAIT )
73  g_led.heartbeat_state++;
74  break;
75 
76  case 2: // Ramp down
77  g_led.heartbeat_duty -= HEARTBEAT_RAMP_RATE;
78 
79  if( g_led.heartbeat_duty <= 0 )
80  {
81  g_led.heartbeat_duty = 0;
82  g_led.heartbeat_cnt = 0;
83  g_led.heartbeat_state++;
84  }
85  set_LED_PWM(g_led.heartbeat_duty);
86  break;
87 
88  case 3: // Wait
89  if( ++g_led.heartbeat_cnt >= HEARTBEAT_WAIT )
90  g_led.heartbeat_state++;
91  break;
92  }
93 
94 #elif LED_SCHEME==LED_SCHEME_SOLID
95  // Solid LED Scheme:
96  // Red - general fault, unhanded interrupt, calibrating
97  // Orange - unaligned
98  // Blue - aligned w/o GPS lock
99  // Green - aligned w GPS lock and sync (blip Red)
100  // White Purple - On boot
101  // Purple - boot loader
102  // Cyan (green/blue) -
103 
104  if( g_sc.calState != SC_RUNTIME )
105  {
106  switch(g_sc.calState)
107  {
108  default:
109  case SC_ORTH_SAMPLE_INIT:
110  LED_COLOR_RED();
111  break;
112 
113  case SC_ACCEL_ALIGN_CHECK:
114  if( g_sc.status == SC_STATUS_ALIGNED )
115  {
116  LED_COLOR_GREEN();
117  }
118  else
119  {
121  }
122  break;
123 
124  case SC_ORTH_SAMPLE_MEAN:
125  LED_COLOR_CYAN();
126  break;
127 
128  case SC_DONE:
129 // LED_COLOR_WHITE();
130  LED_COLOR_RED(); // Red
131  break;
132  }
133  }
134  else
135  {
136  // Allow for GPS red pulse
137  if( g_gpsTimeOfWeekMs < g_led.gps_timeMs )
138  return;
139 
140  // Mag is recalibrating
141  if( g_insStatus & INS_STATUS_MAG_RECALIBRATING )
142  {
144  return;
145  }
146 
147  // Normal Operation
148  switch( solStatus )
149  {
151  //LEDS_ALL_OFF();
153  break;
154 
156  LED_COLOR_WHITE();
157  break;
158 
163  break;
164 
166  LED_COLOR_GREEN();
167  break;
168 
170  LED_COLOR_BLUE();
171  break;
172  }
173  }
174 #endif
175 }
176 
177 
179 {
180 #if LED_SCHEME==LED_SCHEME_BLINK
181  // Pulse LED status
182  if( ++g_led.heartbeat_cnt >= 100 )
183  {
184  g_led.heartbeat_cnt = 0;
185  g_led.heartbeat_state = 1;
186  LED_ON(LED_SYS_HEALTH);
187  }
188  // Keep LED on for 100ms
189  if( g_led.heartbeat_state && g_led.heartbeat_cnt >= g_led.heartbeat_duty )
190  {
191  g_led.heartbeat_state = 0;
192  LED_OFF(LED_SYS_HEALTH);
193  }
194 #else
195  // Breathing LED status
196 #endif
197 }
198 
199 
201 {
202  // Observe state of RTOS
203  if (g_enRtosStats)
204  {
206  }
207 
208  // Check if task runtime has gone over the allotted period
209  for (size_t i = TASK_SAMPLE; i < TASK_MAINTENANCE; i++)
210  {
212  {
214  }
215  }
216 }
217 
218 
220 {
221  for(int port=0; port<NUM_COM_PORTS; port++)
222  {
223  // Copy RMC
224  g_nvmInternalFlashCfg->startupRmc[port] = g_rmci[port];
225 
226  // Copy ASCII
227  g_nvmInternalFlashCfg->startupAsciiPeriod[port] = g_asciiPeriod[port];
228  }
229  // Copy CAN
230  g_nvmInternalFlashCfg->startupCAN = g_CAN;
231 
232  nvr_flash_config_write_needed_enable();
233 }
#define LED_ON(led)
Definition: user_board.h:236
#define LEDS_ALL_OFF()
Definition: user_board.h:273
#define LED_OFF(led)
Definition: user_board.h:235
#define LED_COLOR_BLUE()
Definition: user_board.h:253
#define LED_COLOR_YELLOW()
Definition: user_board.h:255
evb_rtos_info_t g_rtos
Definition: globals.c:27
#define LED_COLOR_RED()
Definition: user_board.h:251
bool g_enRtosStats
Definition: globals.c:35
rtos_task_t task[UINS_RTOS_NUM_TASKS]
Definition: data_sets.h:3335
void led_maintenance(void)
Definition: maintenance.c:10
#define NUM_COM_PORTS
Definition: data_sets.h:1199
#define LED_COLOR_GREEN()
Definition: user_board.h:252
void save_persistent_messages(void)
Definition: maintenance.c:219
void rtos_monitor(int numRtosTasks)
Definition: rtos.c:64
#define INS_STATUS_SOLUTION(insStatus)
Definition: data_sets.h:213
#define LED_COLOR_WHITE()
Definition: user_board.h:257
uint32_t maxRunTimeUs
Definition: data_sets.h:3307
uint32_t periodMs
Definition: data_sets.h:3301
#define LED_COLOR_PURPLE()
Definition: user_board.h:256
void vTaskDelay(const TickType_t xTicksToDelay) PRIVILEGED_FUNCTION
Autogenerated API include file for the Atmel Software Framework (ASF)
void rtos_maintenance(void)
Definition: maintenance.c:200
#define RTOS_NUM_TASKS
Definition: rtos.h:29
#define LED_COLOR_CYAN()
Definition: user_board.h:254
void led_sys_heartbeat(void)
Definition: maintenance.c:178


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04