diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h index f2e302f..9d0b014 100644 --- a/Core/Inc/navikit.h +++ b/Core/Inc/navikit.h @@ -93,6 +93,7 @@ enum Device_t{USB2_Port1=0x00,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_P SYS_FAN1=0x20,SYS_FAN2,SYS_FAN3, //Fan on Board SYS_RUN_LED,SYS_PWR_LED, //LED on Board + SYS_SRC_BUZZ, //Oscillation source internal buzzer SOM_PWR_EN=0x30,SOM_DFU,SOM_RESET,SOM_SLEEP, //SOM Control @@ -107,10 +108,10 @@ void NaviKit_var_init(); //power state machine switch function void enter_standby_state(uint16_t delay); void enter_isp_state(); -void enter_run_state(uint16_t delay); -void enter_idle_state(uint16_t delay); -void enter_sleep_state(uint16_t delay); -void enter_dfu_state(uint16_t delay); +void enter_run_state(uint16_t interval); +void enter_idle_state(uint16_t interval); +void enter_sleep_state(uint16_t interval); +void enter_dfu_state(uint16_t interval); void som_reboot(uint16_t delay); //non-blocking beep function with os delay void TaskBeep(uint32_t time_ms, uint8_t n); diff --git a/Core/Src/navikit.c b/Core/Src/navikit.c index e469eb4..dc4ce27 100644 --- a/Core/Src/navikit.c +++ b/Core/Src/navikit.c @@ -29,10 +29,12 @@ void NaviKit_var_init() void TaskBeep(uint32_t time_ms , uint8_t n) { for(uint8_t i=0;i>1);//equal "time divided by 2" - HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_SET); - osDelay(time_ms>>1);//equal "time divided by 2" + PWR_Enable_IRQ(SYS_SRC_BUZZ, true, time_ms>>1);//equal "time divided by 2" + PWR_Enable_IRQ(SYS_SRC_BUZZ, false, time_ms>>1);//equal "time divided by 2" +// HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_RESET); +// osDelay(time_ms>>1);//equal "time divided by 2" +// HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin, GPIO_PIN_SET); +// osDelay(time_ms>>1);//equal "time divided by 2" } } @@ -75,103 +77,103 @@ void enter_isp_state() } //timeout:the time of wait -void enter_idle_state(uint16_t delay){ +void enter_idle_state(uint16_t interval){ log_i("Enter to idle state."); TaskBeep(50,1); - PWR_Enable(SOM_SLEEP,true,delay); + PWR_Enable(SOM_SLEEP,true,interval); - PWR_Enable(USB3_Port4,false, delay); - PWR_Enable(USB3_Port3,false, delay); - PWR_Enable(USB3_Port2,false, delay); - PWR_Enable(USB3_Port1,false, delay); - PWR_Enable(USB3_Port6,false, delay); - PWR_Enable(USB3_Port5,false, delay); + PWR_Enable(USB3_Port4,false, interval); + PWR_Enable(USB3_Port3,false, interval); + PWR_Enable(USB3_Port2,false, interval); + PWR_Enable(USB3_Port1,false, interval); + PWR_Enable(USB3_Port6,false, interval); + PWR_Enable(USB3_Port5,false, interval); - PWR_Enable(USB2_Port6,false, delay); - PWR_Enable(USB2_Port5,false, delay); - PWR_Enable(USB2_Port4,false, delay); - PWR_Enable(USB2_Port3,false, delay); - PWR_Enable(USB2_Port2,false, delay); - PWR_Enable(USB2_Port1,false, delay); + PWR_Enable(USB2_Port6,false, interval); + PWR_Enable(USB2_Port5,false, interval); + PWR_Enable(USB2_Port4,false, interval); + PWR_Enable(USB2_Port3,false, interval); + PWR_Enable(USB2_Port2,false, interval); + PWR_Enable(USB2_Port1,false, interval); - PWR_Enable(SOC_USB3_HUB ,false, delay); - PWR_Enable(SOC_USB2_HUB ,false, delay); - PWR_Enable(SOC_USB3_HOST,false, delay); - PWR_Enable(SOC_USB3_GEC ,false, delay); - PWR_Enable(SOC_GE_SW ,false, delay); + PWR_Enable(SOC_USB3_HUB ,false, interval); + PWR_Enable(SOC_USB2_HUB ,false, interval); + PWR_Enable(SOC_USB3_HOST,false, interval); + PWR_Enable(SOC_USB3_GEC ,false, interval); + PWR_Enable(SOC_GE_SW ,false, interval); - PWR_Enable(SYS_FAN1 ,false , delay); - PWR_Enable(SYS_FAN2 ,false , delay); - PWR_Enable(SYS_FAN3 ,false , delay); + PWR_Enable(SYS_FAN1 ,false , interval); + PWR_Enable(SYS_FAN2 ,false , interval); + PWR_Enable(SYS_FAN3 ,false , interval); - PWR_Enable(SOM_PWR_EN ,false, delay); + PWR_Enable(SOM_PWR_EN ,false, interval); PWR_Enable(PMB_PS_ON ,false , 0); } -void enter_run_state(uint16_t delay) +void enter_run_state(uint16_t interval) { log_i("Enter to run state"); TaskBeep(200,1); - PWR_Enable(PMB_PS_ON ,true, delay); + PWR_Enable(PMB_PS_ON ,true, interval); PWR_Enable(SOM_DFU ,false, 0); //disable dfu pin PWR_Enable(SOM_RESET , false , 0); //disable reset pin - PWR_Enable(SYS_FAN1 ,true , delay); - PWR_Enable(SYS_FAN2 ,true , delay); - PWR_Enable(SYS_FAN3 ,true , delay); + PWR_Enable(SYS_FAN1 ,true , interval); + PWR_Enable(SYS_FAN2 ,true , interval); + PWR_Enable(SYS_FAN3 ,true , interval); - PWR_Enable(SOM_PWR_EN , true , delay); + PWR_Enable(SOM_PWR_EN , true , interval); - PWR_Enable(SOC_USB3_HUB ,true , delay); - PWR_Enable(SOC_USB2_HUB ,true , delay); - PWR_Enable(SOC_USB3_HOST,true , delay); - PWR_Enable(SOC_USB3_GEC ,true , delay); - PWR_Enable(SOC_GE_SW ,true , delay); + PWR_Enable(SOC_USB3_HUB ,true , interval); + PWR_Enable(SOC_USB2_HUB ,true , interval); + PWR_Enable(SOC_USB3_HOST,true , interval); + PWR_Enable(SOC_USB3_GEC ,true , interval); + PWR_Enable(SOC_GE_SW ,true , interval); - PWR_Enable(USB2_Port1,true , delay); - PWR_Enable(USB2_Port2,true , delay); - PWR_Enable(USB2_Port3,true , delay); - PWR_Enable(USB2_Port4,true , delay); - PWR_Enable(USB2_Port5,true , delay); - PWR_Enable(USB2_Port6,true , delay); + PWR_Enable(USB2_Port1,true , interval); + PWR_Enable(USB2_Port2,true , interval); + PWR_Enable(USB2_Port3,true , interval); + PWR_Enable(USB2_Port4,true , interval); + PWR_Enable(USB2_Port5,true , interval); + PWR_Enable(USB2_Port6,true , interval); - PWR_Enable(USB3_Port5,true , delay); - PWR_Enable(USB3_Port6,true , delay); - PWR_Enable(USB3_Port1,true , delay); - PWR_Enable(USB3_Port2,true , delay); - PWR_Enable(USB3_Port3,true , delay); - PWR_Enable(USB3_Port4,true , delay); + PWR_Enable(USB3_Port5,true , interval); + PWR_Enable(USB3_Port6,true , interval); + PWR_Enable(USB3_Port1,true , interval); + PWR_Enable(USB3_Port2,true , interval); + PWR_Enable(USB3_Port3,true , interval); + PWR_Enable(USB3_Port4,true , interval); } -void enter_sleep_state(uint16_t delay) +void enter_sleep_state(uint16_t interval) { log_i("Enter to sleep state."); TaskBeep(50,1); } -void enter_dfu_state(uint16_t delay) +void enter_dfu_state(uint16_t interval) { log_i("Enter to DFU state."); TaskBeep(500,3); - PWR_Enable(PMB_PS_ON , true , delay); + PWR_Enable(PMB_PS_ON , true , interval); PWR_Enable(SOM_DFU , true , 0); PWR_Enable(SOM_RESET , false , 0); //disable reset pin - PWR_Enable(SYS_FAN1 , true , delay); - PWR_Enable(SYS_FAN2 , true , delay); - PWR_Enable(SYS_FAN3 , true , delay); + PWR_Enable(SYS_FAN1 , true , interval); + PWR_Enable(SYS_FAN2 , true , interval); + PWR_Enable(SYS_FAN3 , true , interval); - PWR_Enable(SOM_PWR_EN , true , delay); + PWR_Enable(SOM_PWR_EN , true , interval); } -//para, delay:reset low level signal duration (ms) -void som_reboot(uint16_t delay){ +//para, interval:reset low level signal duration (ms) +void som_reboot(uint16_t interval){ log_i("Jetson Nano rebooting..."); PWR_Enable(SOM_RESET,true,0); TaskBeep(100,1); @@ -219,6 +221,7 @@ bool PWR_Enable_IRQ(enum Device_t device,bool en,uint16_t delay){ case SYS_FAN3: {HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port, SYS_FAN_CTL_3_Pin, en); }break; case SYS_RUN_LED: {HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port, SYS_RUN_LED_CTL_Pin, !en); }break; case SYS_PWR_LED: {HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port, SYS_POWER_LED_CTL_Pin, !en); }break; + case SYS_SRC_BUZZ: {HAL_GPIO_WritePin(SYS_BUZZ_CTL_GPIO_Port, SYS_BUZZ_CTL_Pin, !en); }break; case SOM_PWR_EN: {HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port, SOM_POWER_EN_Pin, en); }break; case SOM_DFU: {HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin, !en); }break; case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, !en); }break; @@ -256,6 +259,7 @@ bool PWR_Status(enum Device_t device){ case SYS_FAN3: {sta = HAL_GPIO_ReadPin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin); }break; case SYS_RUN_LED: {sta = !HAL_GPIO_ReadPin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin); }break; case SYS_PWR_LED: {sta = !HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin); }break; + case SYS_SRC_BUZZ :{sta = !HAL_GPIO_ReadPin(SYS_BUZZ_CTL_GPIO_Port,SYS_BUZZ_CTL_Pin); }break; case SOM_PWR_EN: {sta = HAL_GPIO_ReadPin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin); }break; case SOM_DFU: {sta = !HAL_GPIO_ReadPin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin); }break; case SOM_RESET: {sta = !HAL_GPIO_ReadPin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin); }break;