|
|
@@ -82,6 +82,7 @@ typedef StaticTask_t osStaticThreadDef_t;
|
|
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
ADC_HandleTypeDef hadc1;
|
|
|
+ADC_HandleTypeDef hadc2;
|
|
|
|
|
|
FDCAN_HandleTypeDef hfdcan1;
|
|
|
|
|
|
@@ -105,7 +106,7 @@ SRAM_HandleTypeDef hsram4;
|
|
|
|
|
|
/* Definitions for taskEPS */
|
|
|
osThreadId_t taskEPSHandle;
|
|
|
-uint32_t taskEPSBuffer[ 128 ];
|
|
|
+uint32_t taskEPSBuffer[ 256 ];
|
|
|
osStaticThreadDef_t taskEPSControlBlock;
|
|
|
const osThreadAttr_t taskEPS_attributes = {
|
|
|
.name = "taskEPS",
|
|
|
@@ -125,7 +126,7 @@ const osThreadAttr_t taskSnap_attributes = {
|
|
|
.stack_size = sizeof(taskSnapBuffer),
|
|
|
.cb_mem = &taskSnapControlBlock,
|
|
|
.cb_size = sizeof(taskSnapControlBlock),
|
|
|
- .priority = (osPriority_t) osPriorityNormal,
|
|
|
+ .priority = (osPriority_t) osPriorityRealtime,
|
|
|
};
|
|
|
/* Definitions for taskAI */
|
|
|
osThreadId_t taskAIHandle;
|
|
|
@@ -161,12 +162,12 @@ static void MX_USART2_UART_Init(void);
|
|
|
static void MX_USART3_UART_Init(void);
|
|
|
static void MX_ICACHE_Init(void);
|
|
|
static void MX_GTZC_Init(void);
|
|
|
+static void MX_ADC2_Init(void);
|
|
|
void taskEPSRunner(void *argument);
|
|
|
void taskSnapRunner(void *argument);
|
|
|
void taskAIRunner(void *argument);
|
|
|
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
-
|
|
|
/* USER CODE END PFP */
|
|
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
|
@@ -176,7 +177,7 @@ extern "C" int _write(int32_t file, uint8_t *ptr, int32_t len) {
|
|
|
#else
|
|
|
int _write(int32_t file, uint8_t *ptr, int32_t len) {
|
|
|
#endif
|
|
|
- if( HAL_UART_Transmit(&huart1, ptr, len, len) == HAL_OK ) return len;
|
|
|
+ if( HAL_UART_Transmit(&UART_HANDLER_SBC, ptr, len, len) == HAL_OK ) return len;
|
|
|
else return 0;
|
|
|
}
|
|
|
|
|
|
@@ -251,16 +252,17 @@ int main(void)
|
|
|
MX_USART3_UART_Init();
|
|
|
MX_ICACHE_Init();
|
|
|
MX_USB_Device_Init();
|
|
|
+ MX_ADC2_Init();
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
printf("\r\n\r\n\r\n");
|
|
|
printf("**************************\r\n");
|
|
|
printf("** TEST APP INFORMATION **\r\n");
|
|
|
- printf(" - SBC M33 freeRTOS, truztzone, CAM, EPS\r\n");
|
|
|
- printf(" - 2023. 7. 13. 12:00\r\n");
|
|
|
+ printf(" - SBC M33 freeRTOS, truztzone, ADC test\r\n");
|
|
|
+ printf(" - 2023.10.20. 10:00\r\n");
|
|
|
printf("**************************\r\n");
|
|
|
printf("\r\n\r\n\r\n");
|
|
|
/* after SBC boot-up, sbc power gpio pin should be ON */
|
|
|
- imc_sbc_power_on(0); // delay(param) should be 0ms
|
|
|
+ imc_sbc_power_on(); // delay(param) should be 0ms
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
@@ -303,6 +305,7 @@ int main(void)
|
|
|
|
|
|
/* Start scheduler */
|
|
|
osKernelStart();
|
|
|
+
|
|
|
/* We should never get here as control is now taken by the scheduler */
|
|
|
/* Infinite loop */
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
@@ -470,6 +473,64 @@ static void MX_ADC1_Init(void)
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief ADC2 Initialization Function
|
|
|
+ * @param None
|
|
|
+ * @retval None
|
|
|
+ */
|
|
|
+static void MX_ADC2_Init(void)
|
|
|
+{
|
|
|
+
|
|
|
+ /* USER CODE BEGIN ADC2_Init 0 */
|
|
|
+
|
|
|
+ /* USER CODE END ADC2_Init 0 */
|
|
|
+
|
|
|
+ ADC_ChannelConfTypeDef sConfig = {0};
|
|
|
+
|
|
|
+ /* USER CODE BEGIN ADC2_Init 1 */
|
|
|
+
|
|
|
+ /* USER CODE END ADC2_Init 1 */
|
|
|
+
|
|
|
+ /** Common config
|
|
|
+ */
|
|
|
+ hadc2.Instance = ADC2;
|
|
|
+ hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
|
|
+ hadc2.Init.Resolution = ADC_RESOLUTION_12B;
|
|
|
+ hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
|
|
+ hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
|
|
+ hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
|
|
+ hadc2.Init.LowPowerAutoWait = DISABLE;
|
|
|
+ hadc2.Init.ContinuousConvMode = DISABLE;
|
|
|
+ hadc2.Init.NbrOfConversion = 1;
|
|
|
+ hadc2.Init.DiscontinuousConvMode = DISABLE;
|
|
|
+ hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
|
|
+ hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
|
|
+ hadc2.Init.DMAContinuousRequests = DISABLE;
|
|
|
+ hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
|
|
+ hadc2.Init.OversamplingMode = DISABLE;
|
|
|
+ if (HAL_ADC_Init(&hadc2) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Configure Regular Channel
|
|
|
+ */
|
|
|
+ sConfig.Channel = ADC_CHANNEL_2;
|
|
|
+ sConfig.Rank = ADC_REGULAR_RANK_1;
|
|
|
+ sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
|
|
+ sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
|
|
+ sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
|
|
+ sConfig.Offset = 0;
|
|
|
+ if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ /* USER CODE BEGIN ADC2_Init 2 */
|
|
|
+
|
|
|
+ /* USER CODE END ADC2_Init 2 */
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief FDCAN1 Initialization Function
|
|
|
* @param None
|
|
|
@@ -940,18 +1001,14 @@ static void MX_USART3_UART_Init(void)
|
|
|
/*
|
|
|
* use below code if code is re-generated by .ioc modification
|
|
|
#if CAM_CHANGE_BAUDRATE
|
|
|
- huart3.Init.BaudRate = 38400;
|
|
|
+ UART_HANDLER_CAM.Init.BaudRate = 38400;
|
|
|
#else
|
|
|
- huart3.Init.BaudRate = 115200;
|
|
|
+ UART_HANDLER_CAM.Init.BaudRate = 115200;
|
|
|
#endif
|
|
|
*/
|
|
|
/* USER CODE END USART3_Init 1 */
|
|
|
huart3.Instance = USART3;
|
|
|
-#if CAM_CHANGE_BAUDRATE
|
|
|
- huart3.Init.BaudRate = 38400;
|
|
|
-#else
|
|
|
huart3.Init.BaudRate = 115200;
|
|
|
-#endif
|
|
|
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
|
|
huart3.Init.StopBits = UART_STOPBITS_1;
|
|
|
huart3.Init.Parity = UART_PARITY_NONE;
|
|
|
@@ -1282,11 +1339,35 @@ static void MX_GPIO_Init(void)
|
|
|
void taskEPSRunner(void *argument)
|
|
|
{
|
|
|
/* USER CODE BEGIN 5 */
|
|
|
+#if (EPS_CAP_VOLT_ADC)
|
|
|
+ int capacitor_voltage0 = 0;
|
|
|
+ //int capacitor_voltage1 = 0;
|
|
|
+
|
|
|
/* Infinite loop */
|
|
|
+ for(;;)
|
|
|
+ {
|
|
|
+ capacitor_voltage0 = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
|
|
|
+ //capacitor_voltage1 = measure_voltage(ADC_HANDLER_CAM, EPS_CAP_ID_CAM);
|
|
|
+
|
|
|
+ //printf("\t\t\t\t\t\t[EPS] CAP VOLT: %d.%03d, %d.%03d\r\n", capacitor_voltage0/1000, capacitor_voltage0%1000, capacitor_voltage1/1000, capacitor_voltage1%1000);
|
|
|
+
|
|
|
+ if (capacitor_voltage0 < EPS_CAP_VOLT_LOW_THRESHOLD_SBC)
|
|
|
+ {
|
|
|
+ printf("[EPS] CAP#%d < %dmV (TODO JIT CHECKPOINT)\r\n", EPS_CAP_ID_SBC, EPS_CAP_VOLT_LOW_THRESHOLD_SBC);
|
|
|
+ // TODO: JIT CHECKPOINT
|
|
|
+ imc_sbc_power_off();
|
|
|
+ }
|
|
|
+
|
|
|
+ osDelay(DELAY_AFTER_WORK);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+#if (EPS_CAP_VOLT_GPIO)
|
|
|
/* energy_level: 1~7, and SBC power off when the level is 1 */
|
|
|
uint8_t energy_level_prev = 8;
|
|
|
uint8_t energy_level_curr = 8;
|
|
|
|
|
|
+ /* Infinite loop */
|
|
|
for(;;)
|
|
|
{
|
|
|
energy_level_curr = imc_get_energy_level();
|
|
|
@@ -1298,7 +1379,7 @@ void taskEPSRunner(void *argument)
|
|
|
|
|
|
if (energy_level_curr <= EPS_SBC_OFF_LEVEL)
|
|
|
{
|
|
|
- imc_sbc_power_off(0);
|
|
|
+ imc_sbc_power_off();
|
|
|
}
|
|
|
|
|
|
energy_level_prev = energy_level_curr;
|
|
|
@@ -1306,6 +1387,7 @@ void taskEPSRunner(void *argument)
|
|
|
|
|
|
osDelay(DELAY_AFTER_WORK);
|
|
|
}
|
|
|
+#endif
|
|
|
/* USER CODE END 5 */
|
|
|
}
|
|
|
|
|
|
@@ -1322,26 +1404,36 @@ void taskSnapRunner(void *argument)
|
|
|
{
|
|
|
/* USER CODE BEGIN taskSnapRunner */
|
|
|
sc03mpd_ifx_t ifx = {
|
|
|
- .context = (void*)&huart3,
|
|
|
+ .context = (void*)&UART_HANDLER_CAM,
|
|
|
.sendif = hal_uart_ifx_send,
|
|
|
.recvif = hal_uart_ifx_recv,
|
|
|
};
|
|
|
|
|
|
+ uint8_t error_count = 0;
|
|
|
+
|
|
|
/* Infinite loop */
|
|
|
while (1)
|
|
|
{
|
|
|
+ printf ("\r\n\r\n\r\n#%ld\r\n\r\n", trial);
|
|
|
+ trial++;
|
|
|
+
|
|
|
// osSemaphoreWait(empty, osWaitForever);
|
|
|
|
|
|
+#if EPS_CAP_VOLT_ADC
|
|
|
+ SC03MPD_ASSERT(imc_sc03mpd_cap_check (ADC_HANDLER_CAM), "[CAM] FAILED CAP volt", ERROR)
|
|
|
+#endif
|
|
|
+
|
|
|
/*
|
|
|
* 2022. 11. 10. TEST for EPS-SBC-CAM; SBC controls CAM ON/OFF; KETI EPS does NOT wait 2.5s for CAM init.
|
|
|
*/
|
|
|
- printf ("\r\n\r\n#%lu\r\n\r\n", trial);
|
|
|
- trial++;
|
|
|
+ imc_cam_power_on();
|
|
|
|
|
|
- imc_cam_power_on(0);
|
|
|
+ // (M33) moved from imc_sc03mpd_init
|
|
|
+ printf("[CAM] wait %dms for boot-up\r\n", DELAY_AFTER_POWERUP);
|
|
|
+ osDelay (DELAY_AFTER_POWERUP);
|
|
|
+ MX_USART3_UART_Init();
|
|
|
+ // (M33) moved from imc_sc03mpd_init
|
|
|
|
|
|
- /* camera init */
|
|
|
- MX_USART3_UART_Init(); // (M33) moved from imc_sc03mpd_init
|
|
|
SC03MPD_ASSERT(imc_sc03mpd_init(&ifx), "[CAM] FAILED init", ERROR)
|
|
|
|
|
|
/* execute once when change CAM default baudrate */
|
|
|
@@ -1373,7 +1465,10 @@ void taskSnapRunner(void *argument)
|
|
|
/*
|
|
|
* 2022. 11. 10. TEST for EPS-SBC-CAM
|
|
|
*/
|
|
|
- imc_cam_power_off(0);
|
|
|
+ imc_cam_power_off();
|
|
|
+
|
|
|
+ // error_count reset
|
|
|
+ error_count = 0;
|
|
|
|
|
|
/* DO SOMETHING */
|
|
|
#if 0
|
|
|
@@ -1383,8 +1478,8 @@ void taskSnapRunner(void *argument)
|
|
|
|
|
|
// osSemaphoreRelease(full);
|
|
|
#else
|
|
|
- printf ("[SBC] wait %dms for next job\r\n", DELAY_AFTER_WORK);
|
|
|
- osDelay(DELAY_AFTER_WORK);
|
|
|
+ printf ("[SBC] wait %dms for DO SOMETHING\r\n", DELAY_DO_SOMETHING);
|
|
|
+ osDelay(DELAY_DO_SOMETHING);
|
|
|
#endif
|
|
|
|
|
|
continue;
|
|
|
@@ -1395,20 +1490,27 @@ ERROR:
|
|
|
* 2022. 8. 25. add USART3 init. and reset fn.; download or capture failure --> normal
|
|
|
* 2022. 8. 25. after SC03MPD power off/on, works well after few failures
|
|
|
* 2022. 11. 11. start of this while loop, CAM init is called
|
|
|
+ * 2023. 10. 20. add error_count for handling successive errors
|
|
|
*/
|
|
|
-#if 1
|
|
|
+ error_count++;
|
|
|
+
|
|
|
printf("[CAM] ERROR HANDLING; CAM OFF > %dms delay > CAM ON\r\n", DELAY_BEFORE_ERR_HANDLING);
|
|
|
- imc_cam_power_off(0);
|
|
|
+ imc_cam_power_off();
|
|
|
// osSemaphoreRelease(empty);
|
|
|
|
|
|
- osDelay(DELAY_BEFORE_ERR_HANDLING);
|
|
|
+ osDelay(DELAY_BEFORE_ERR_HANDLING); //imc_sbc_power_off();
|
|
|
|
|
|
- continue;
|
|
|
-#else
|
|
|
- osDelay(DELAY_BEFORE_ERR_HANDLING);
|
|
|
+ // ERROR 3 times -> SBC reboot
|
|
|
+ if (error_count >= CAM_ERROR_COUNT_MAX) {
|
|
|
+ error_count = 0;
|
|
|
|
|
|
- SC03MPD_ASSERT(imc_sc03mpd_init(&ifx), "[CAM] FAILED ERROR HANDLING; init", ERROR)
|
|
|
-#endif
|
|
|
+ printf("[CAM] %d ERRORs continue and SBC OFF\r\n", CAM_ERROR_COUNT_MAX);
|
|
|
+ imc_sbc_power_off();
|
|
|
+
|
|
|
+ osDelay(DELAY_DO_SOMETHING);
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
}
|
|
|
#if 0
|
|
|
EXIT:
|