support restart multiple ports at once, support execute log return

master
ThinkPad-T460P 2021-02-07 11:11:26 +08:00
parent b71014583e
commit 7df0667bde
3 changed files with 36 additions and 14 deletions

View File

@ -57,7 +57,7 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
extern uint8_t port_restart;
extern bool flag_restart;
extern uint8_t number_restart;
//Timer
osTimerId_t PwrBtnLongPressTimerHandle;
const osTimerAttr_t PwrBtnLongPressTimer_attributes = {
@ -661,16 +661,38 @@ void StartEventDetect(void *argument)
/* USER CODE BEGIN Application */
void StartCdcMonitorTask(void *argument){
uint8_t port_restart_temp[64]={0};
uint32_t number_restart_temp =0;
bool beep_flag = false;
for(;;){
if(flag_restart && port_restart<12){
flag_restart = false;
uint8_t port_restart_temp = port_restart;
Log(info,sys,"Port%d restart",port_restart_temp);
PWR_Enable(port_restart_temp, false,400);
TaskBeep(50,1);
PWR_Enable(port_restart_temp, true,0);
if(number_restart){
number_restart_temp = number_restart;
memcpy(port_restart_temp,&port_restart,number_restart_temp<=12 ? number_restart_temp : 12);
number_restart = 0;
// turn off usb port device
for(uint8_t i=0;i<number_restart_temp;i++){
if(port_restart_temp[i]<12){
PWR_Enable(port_restart_temp[i], false,200);
Log(info,sys,"USB Port%d power off",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
}
osDelay(200);
}
//turn on usb port device
beep_flag = false;
for(uint8_t i=0;i<number_restart_temp;i++){
if(port_restart_temp[i]<12){
PWR_Enable(port_restart_temp[i], true,200);
Log(info,sys,"USB Port%d power on",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
beep_flag = true;
}
}
if(beep_flag){
beep_flag = false;
TaskBeep(50, 1);
}
}
osDelay(100);
}
}
void StartLogtoUartTask(void *argument){

View File

@ -68,5 +68,6 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>

View File

@ -100,8 +100,8 @@ uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
/* USER CODE BEGIN PRIVATE_VARIABLES */
extern uint8_t port_restart = 0;
extern bool flag_restart = false;
extern uint8_t port_restart[64] = {0};
extern uint32_t number_restart = 0;
/* USER CODE END PRIVATE_VARIABLES */
/**
@ -269,10 +269,9 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
port_restart = Buf[0];
flag_restart = true;
memcpy(port_restart,Buf,*Len<=64 ? *Len : 64);
number_restart = *Len<=64 ? *Len : 64;
Log(info,sys,"cdc receive %d",port_restart);
return (USBD_OK);
/* USER CODE END 6 */
}