Motion_EC_Stm32_archived/App/Src/th_cdc.c

59 lines
1.4 KiB
C
Raw Normal View History

2021-03-09 18:17:28 +08:00
#define LOG_TAG "TH-CDC"
#include <th_cdc.h>
#include "main.h"
#include "usbd_cdc_if.h"
#include "navikit.h"
//global variable
extern uint8_t port_restart[];
extern uint32_t number_restart;
//task attributes
const osThreadAttr_t cdcMonitorTask_attributes = {
.name = "cdcMonitorTask",
2021-03-12 13:38:28 +08:00
.priority = (osPriority_t) osPriorityBelowNormal7,
2021-03-14 23:24:59 +08:00
.stack_size = 256 * 4
2021-03-09 18:17:28 +08:00
};
//task instance
2021-03-15 19:26:10 +08:00
void CdcMonitorTask(void *argument){
2021-03-09 18:17:28 +08:00
uint8_t port_restart_temp[64]={0};
uint32_t number_restart_temp =0;
bool beep_flag = false;
2021-03-12 13:38:28 +08:00
log_d("Start CDC Monitor Task");
2021-03-09 18:17:28 +08:00
for(;;){
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_i("USB Port%d power off",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
}
}
//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_i("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);
}
}