evb_tasks.cpp
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright 2014-2019 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT, IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include "evb_tasks.h"
14 #include "../../../hw-libs/drivers/d_i2c.h"
15 
16 
17 is_comm_instance_t& evbTaskCommInit(void *pvParameters)
18 {
19  UNUSED(pvParameters);
20  static uint8_t comm_buffer[PKT_BUF_SIZE];
21  is_comm_init(&g_commTx, comm_buffer, PKT_BUF_SIZE);
22 
23 #ifdef CONF_BOARD_CAN_TEST
24  //if(/*g_can_test == CAN_TEST_MASTER - or something like that*/ 1)
25  //mcan_test_master();
26  if(/*g_can_test == CAN_TEST_SLAVE - or something like that*/ 1)
28 #endif
29 
30  // Start USB CDC after everything is running
31 #ifdef USB_PORT_NUM
32  serInit(USB_PORT_NUM, 0, NULL, 0);
33 #endif
34 
35  vTaskDelay(200);
37 
38  return g_commTx;
39 }
40 
41 
43 {
44  vTaskDelay(task.periodMs);
45 
47 
48 #ifdef ENABLE_WDT
49  // Feed Watchdog to prevent reset
51 #endif
52 
53  // Turn off communications LEDs - first thing after vTaskDelay()
56 
57  // Forward data between communications ports
58  step_com_bridge(comm);
59  velocity_control(comm);
60 
61  // Read buttons and update LEDs
63 }
64 
65 
67 {
68  UNUSED(pvParameters);
69  static is_comm_instance_t comm;
70  static uint8_t comm_buffer[PKT_BUF_SIZE];
71  is_comm_init(&comm, comm_buffer, PKT_BUF_SIZE);
72 
73  vTaskDelay(200);
74  LED_LOG_OFF();
75  vTaskDelay(800);
76 
77 #if STREAM_INS_FOR_TIME_SYNC // Stream INS message on startup. Necessary to update EVB RTC for correct data log date and time.
78  //uINS_stream_stop_all(comm);
79  //uINS_stream_enable_std(comm);
80 #endif
81 
82  return comm;
83 }
84 
85 
87 {
88  static cISLogger logger = {};
89 
90  vTaskDelay(task.periodMs);
91 
92  step_logger_control(logger, comm);
93 
94  // Ready uINS data from com task. Log to file.
95  log_uINS_data(logger, comm);
96 
97  // Mount/unmount SD card
99 
101 }
102 
103 
104 void evbTaskMaintInit(void *pvParameters)
105 {
106  UNUSED(pvParameters);
107 }
108 
109 
111 {
112  static uint32_t m2sPeriodMs = 0;
113 
114  vTaskDelay(task.periodMs);
115 
117  // Fast Maintenance - 10ms period
120 
122  // Slow Maintenance - 1000ms period
124  {
125  m2sPeriodMs = 0;
126 
127  // Sync local time from uINS
129 
130  // Update RTOS stats
131  if (g_enRtosStats)
132  {
134  }
135 
137  { // uINS bootloader mode enabled
139  { // Automatically disable uINS after 3 minutes
141  }
142  }
143 
144  return 1;
145  }
146 
147  return 0;
148 }
149 
150 
151 void evbMainInit(void)
152 {
153  //XDMAC channel interrupt enables do not get cleared by a software reset. Clear them before they cause issues.
154  XDMAC->XDMAC_GID = 0xFFFFFFFF;
155  for(int i=0;i<XDMACCHID_NUMBER;i++)
156  {
157  XDMAC->XDMAC_CHID[i].XDMAC_CID = 0xFFFFFFFF;
158  }
159 
160  // Force USB to disconnect. Helps to make sure the USB port starts up correctly when debugging.
161  udc_stop();
162 
163  // Initialize the SAM system
164  board_init();
165 
166  // Init globals and flash parameters
167  globals_init();
168  nvr_init();
169 
170  // Hold config while resetting
172  {
174  }
175 
176  board_IO_config();
177 
178  // Setup user interface buttons and leds
179  evbUiDefaults();
180 }
181 
182 void evbMainInitHdw(void)
183 {
184  // Init hardware I/O, SD card logger, and communications
187 
188 #ifdef CONF_BOARD_ADC
190  {
191  adc_init();
192  }
193 #endif
194 }
195 
196 void evbMainInitRTOS(pdTASK_CODE pxTaskComm,
197  pdTASK_CODE pxTaskLogg,
198  pdTASK_CODE pxTaskWifi,
199  pdTASK_CODE pxTaskMant )
200 {
201  // Create RTOS tasks
204 #ifdef CONF_BOARD_SPI_ATWINC_WIFI // ATWINC WIFI
206 #endif
208  strncpy(g_rtos.task[EVB_TASK_IDLE].name, "IDLE", MAX_TASK_NAME_LEN);
209  strncpy(g_rtos.task[EVB_TASK_TIMER].name, "TIMER", MAX_TASK_NAME_LEN);
211 
212 #ifdef ENABLE_WDT
213  // Setup Watchdog
214  uint32_t timeout_value = wdt_get_timeout_value(1000000, BOARD_FREQ_SLCK_XTAL); //Timeout in us, configured for 1 second.
215  wdt_init(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT, timeout_value, timeout_value);
216 #endif
217 }
218 
219 
220 int evbMain(void)
221 {
222  // Start the scheduler
223  printf("Starting FreeRTOS\n\r");
225 
226  // Will only get here if there was insufficient memory to create the idle task.
227  return 0;
228 }
229 
230 
231 
232 
uint32_t bits
Definition: data_sets.h:3154
is_comm_instance_t g_commTx
void vTaskStartScheduler(TaskHandle_t *idleTaskHandle, TaskHandle_t *timerTaskHandle) PRIVILEGED_FUNCTION
Definition: tasks.c:1901
is_comm_instance_t & evbTaskLoggerInit(void *pvParameters)
Definition: evb_tasks.cpp:66
void wdt_restart(Wdt *p_wdt)
Restart the watchdog timer.
Definition: wdt.c:129
#define LED_LOG_OFF()
Definition: user_board.h:270
#define LED_OFF(led)
Definition: user_board.h:235
uint32_t time_msec(void)
Definition: d_time.c:95
#define UNUSED(v)
Marking v as a unused parameter or value.
Definition: compiler.h:86
void board_init(void)
This function initializes the board target resources.
Definition: init.c:573
void sd_card_maintenance(void)
void evbMainInitHdw(void)
Definition: evb_tasks.cpp:182
void evbTaskComm(rtos_task_t &task, is_comm_instance_t &comm)
Definition: evb_tasks.cpp:42
#define TASK_LOGGER_STACK_SIZE
Definition: evb_tasks.h:27
int serInit(int serialNum, uint32_t baudRate, sam_usart_opt_t *options, uint32_t *overrunStatus)
Initialize serial port with specific USART/UART and DMA settings. If not NULL, the overrun status wil...
Definition: d_usartDMA.c:1560
evb_rtos_info_t g_rtos
Definition: globals.c:27
#define TASK_WIFI_STACK_SIZE
Definition: evb_tasks.h:28
void globals_init(void)
Definition: globals.c:38
is_comm_instance_t & evbTaskCommInit(void *pvParameters)
Definition: evb_tasks.cpp:17
#define XDMAC
(XDMAC ) Base Address
Definition: same70j19.h:520
int evbTaskMaint(rtos_task_t &task)
Definition: evb_tasks.cpp:110
bool g_enRtosStats
Definition: globals.c:35
#define PKT_BUF_SIZE
Definition: ISComm.h:98
void mcan_test_slave(void)
Definition: CAN.cpp:215
uint32_t wdt_get_timeout_value(uint32_t ul_us, uint32_t ul_sclk)
Get counter value or permitted range value of watchdog timer from the desired timeout period (in us)...
Definition: wdt.c:88
rtos_task_t task[UINS_RTOS_NUM_TASKS]
Definition: data_sets.h:3457
#define NULL
Definition: nm_bsp.h:52
void evbUiRefreshLedCfg()
#define TASK_COMM_PRIORITY
Definition: evb_tasks.h:30
#define LED_INS_TXD_PIN
Definition: user_board.h:280
void udc_stop(void)
Stop the USB Device stack.
Definition: udc.c:358
void evbUiRefreshLedLog()
void communications_init(void)
int adc_init(void)
Definition: d_adc.c:4
#define TASK_MAINT_STACK_SIZE
Definition: evb_tasks.h:25
#define WDT
(WDT ) Base Address
Definition: same70j19.h:535
void velocity_control(is_comm_instance_t &comm)
Definition: control_law.cpp:31
uint32_t handle
Definition: data_sets.h:3441
static bool ioport_get_pin_level(ioport_pin_t pin)
Get current value of an IOPORT pin, which has been configured as an input.
Definition: ioport.h:301
void evbTaskMaintInit(void *pvParameters)
Definition: evb_tasks.cpp:104
#define EVB2_CB_PRESET_DEFAULT
Definition: data_sets.h:3236
#define TASK_MAINT_SLOW_SEC_PERIOD_MS
Definition: evb_tasks.h:21
void evbTaskLogger(rtos_task_t &task, is_comm_instance_t &comm)
Definition: evb_tasks.cpp:86
#define printf(...)
Definition: evb_tasks.h:36
void nvr_init(void)
Definition: globals.c:300
#define TASK_COMM_PERIOD_MS
Definition: evb_tasks.h:17
uint8_t cbPreset
Definition: data_sets.h:3142
uint32_t g_uInsBootloaderEnableTimeMs
Definition: globals.c:34
#define WDT_MR_WDDBGHLT
(WDT_MR) Watchdog Debug Halt
uint32_t g_comm_time_ms
Definition: globals.c:32
void * TaskHandle_t
Definition: task.h:62
#define TASK_WIFI_PERIOD_MS
Definition: evb_tasks.h:19
#define BUTTON_CFG_PIN
Definition: user_board.h:289
#define TASK_WIFI_PRIORITY
Definition: evb_tasks.h:32
void rtos_monitor(int numRtosTasks)
Definition: rtos.c:64
#define TASK_LOGGER_PERIOD_MS
Definition: evb_tasks.h:18
#define USB_PORT_NUM
Definition: user_board.h:192
void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
Definition: ISComm.c:185
#define MAX_TASK_NAME_LEN
Definition: data_sets.h:3408
uint32_t periodMs
Definition: data_sets.h:3423
#define TASK_MAINT_PERIOD_MS
Definition: evb_tasks.h:20
evb_flash_cfg_t * g_flashCfg
Definition: globals.c:22
#define LED_INS_RXD_PIN
Definition: user_board.h:279
#define TASK_COMM_STACK_SIZE
Definition: evb_tasks.h:24
void step_logger_control(cISLogger &logger, is_comm_instance_t &comm)
void sd_card_logger_init(void)
bool g_loggerEnabled
Definition: globals.c:33
void evbMainInitRTOS(pdTASK_CODE pxTaskComm, pdTASK_CODE pxTaskLogg, pdTASK_CODE pxTaskWifi, pdTASK_CODE pxTaskMant)
Definition: evb_tasks.cpp:196
#define TASK_LOGGER_PRIORITY
Definition: evb_tasks.h:31
void step_com_bridge(is_comm_instance_t &comm)
void step_user_interface(uint32_t time_ms)
int evbMain(void)
Definition: evb_tasks.cpp:220
#define XDMACCHID_NUMBER
Xdmac hardware registers.
#define pdTASK_CODE
Definition: FreeRTOS.h:922
void vTaskDelay(const TickType_t xTicksToDelay) PRIVILEGED_FUNCTION
void time_sync_from_uINS(void)
void board_IO_config(void)
Definition: init.c:376
void evbUiDefaults()
void wdt_init(Wdt *p_wdt, uint32_t ul_mode, uint16_t us_counter, uint16_t us_delta)
Initialize watchdog timer with the given mode.
Definition: wdt.c:110
#define WDT_MR_WDRSTEN
(WDT_MR) Watchdog Reset Enable
char name[MAX_TASK_NAME_LEN]
Definition: data_sets.h:3414
#define TASK_MAINT_PRIORITY
Definition: evb_tasks.h:33
#define BOARD_FREQ_SLCK_XTAL
Definition: same70/osc.h:57
int createTask(int index, pdTASK_CODE pxTaskCode, const char *const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, portTickType xTimeIncrement)
Definition: rtos.c:30
void log_uINS_data(cISLogger &logger, is_comm_instance_t &comm)
void evbMainInit(void)
Definition: evb_tasks.cpp:151


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57