增加空闲时关闭电机功能,防止异常发热

This commit is contained in:
Yu Xifeng 2024-08-18 17:25:01 +08:00
parent c300183b37
commit 6ffa8a56ef
3 changed files with 95 additions and 38 deletions

View File

@ -266,8 +266,9 @@ gptimer_config_t timer_config = {
extern uint8_t Motor_GO(uint8_t DIR);
static bool IRAM_ATTR SysTick_callback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data)
{
static portBASE_TYPE xHigherPriorityTaskWoken;
xSemaphoreGiveFromISR(SysTick_queue,xHigherPriorityTaskWoken);
// static portBASE_TYPE xHigherPriorityTaskWoken;
// xSemaphoreGiveFromISR(SysTick_queue,xHigherPriorityTaskWoken);
Timer_State_machine_cb(1);
return true;
}

View File

@ -26,10 +26,11 @@ Receive_data_t Rev_USB_data = {
typedef struct _Heat_page_t{
char* Heat_Page_buff;
char Heat_block_buff[80][TH_ACTUAL_WIDTH];
char* Heat_block_buff;
uint8_t Heat_line_buf[TH_WIDTH];
uint32_t Heat_Read;
uint32_t Heat_Write;
uint32_t Max_hight;
uint16_t Heat_Initial_time;
uint16_t Heat_Line_time;
@ -47,51 +48,58 @@ Heat_page_t Heat58MM = {
EXT_RAM_BSS_ATTR uint8_t Heat_Page_buff[800][TH_WIDTH];
EXT_RAM_BSS_ATTR uint8_t LineBuffer[480][TH_WIDTH]; //行打印buffer
EXT_RAM_BSS_ATTR uint8_t PrnHeatProp[TH_WIDTH]; //打印头点行buffer
EXT_RAM_BSS_ATTR uint8_t PrnDotBuf[DOTMAPLINE][TH_WIDTH];
uint32_t StepCount = 0; //步进计数
uint32_t FeedPhase = 0; //马达相位
uint32_t StepCount,AcceCount,AcceMax,AccMaxInit;
uint16_t PrnDotWr,PrnDotRd;
bool Printer_direction = true; //打印方向 true:正方向
EventGroupHandle_t Printer_group;
SemaphoreHandle_t Spi_send_end;
SemaphoreHandle_t Motor_is_Running;
extern const char Font24x24ASCII[];
void Sys_heap_Init(void)
{
memset(&LineBuffer[0],0,480*(TH_WIDTH));
memset(&PrnHeatProp[0],0,TH_WIDTH);
memset(&PrnDotBuf[0],0,DOTMAPLINE*(TH_WIDTH));
}
}
void Fill_block2Page_Buff(uint16_t SetPosY,uint16_t hight,uint8_t* block_buff)
{
uint32_t Total_height = SetPosY + hight;
memset(&Heat58MM.Heat_Page_buff[0],0xff,TH_ACTUAL_WIDTH*3);
for(int i=SetPosY;i<(SetPosY+hight);i++)
{
memcpy(&Heat58MM.Heat_Page_buff[i*TH_ACTUAL_WIDTH],&block_buff[(i - SetPosY)*TH_ACTUAL_WIDTH],TH_ACTUAL_WIDTH);
}
if(Total_height > Heat58MM.Max_hight)
{
Heat58MM.Max_hight = Total_height;
}
Heat58MM.Heat_Write = Heat58MM.Max_hight;
}
void Fill_Page_Buff(char ch)
{
int i=0,j=0;
uint8_t Rebuff[72];
memcpy(&Rebuff[0],&Font24x24ASCII[ch*72],72);
memset(&Heat58MM.Heat_block_buff[0],0x00,TH_ACTUAL_WIDTH*24);
// ESP_LOGI(TAG, "Font24x24ASCII[%d]: %X %X %X",0x41,)
for(i=0;i<24;i++)
{
for(j=0;j<16;j++)
{
memcpy(&Rebuff[0],&Font24x24ASCII[(ch+j)*72],72);
memcpy(&Heat58MM.Heat_block_buff[i][j*3],&Rebuff[i*3],3);
}
// memcpy(&Heat58MM.Heat_block_buff[i][0],&Rebuff[i*3],3);
}
for(i=0;i<80;i++)
{
memcpy(&Heat58MM.Heat_Page_buff[i*TH_ACTUAL_WIDTH],&Heat58MM.Heat_block_buff[i][0],TH_ACTUAL_WIDTH);
memcpy(&Heat58MM.Heat_block_buff[i*TH_ACTUAL_WIDTH+j*3],&Rebuff[i*3],3);
}
}
Fill_block2Page_Buff(50,24*50,(uint8_t*)&Heat58MM.Heat_block_buff[0]);
}
const char *button_event_table[] = {
"BUTTON_PRESS_DOWN",
@ -142,26 +150,55 @@ void Sys_Key_motion_cb(void *arg, void *data)
}
}
void Timer_State_machine_cb(uint16_t time_ms)
{
static uint16_t counts = 0;
counts+=time_ms;
// if(counts >=10)
{
static portBASE_TYPE xHigherPriorityTaskWoken;
xSemaphoreGiveFromISR(SysTick_queue,xHigherPriorityTaskWoken);
counts = 0;
}
}
void Printer_Run_task(void *pvParameter)
{
uint8_t execute = 0;
uint16_t counts = 0;
char ch = 0;
Spi_send_end = xSemaphoreCreateBinary();
while (1)
{
if(execute != 0)
if(xSemaphoreTake(SysTick_queue, portMAX_DELAY ) == pdTRUE )
{
if(execute > 100)
if(counts%1000 == 0)
{
vTaskDelay(10/ portTICK_PERIOD_MS);
execute = 0;
if(counts%5000 == 0)
{
if (xSemaphoreTake(Motor_is_Running, 10 / portTICK_PERIOD_MS) == pdTRUE)
{
xEventGroupSetBits(Printer_group,EVENT_Motor_Sleep);
xSemaphoreGive(Motor_is_Running);//解锁
}
continue;
counts = 0;
}
vTaskDelay(20/ portTICK_PERIOD_MS);
}
if(counts%100 == 0)
{
}
if(counts%10 == 0)
{
}
if(1)
{
}
counts+=1;
}
}
}
@ -170,13 +207,13 @@ void Printer_Run_task(void *pvParameter)
static void Printer_start(uint8_t Heat_Step)
static uint16_t Printer_start(uint8_t Heat_Step)
{
if(Heat58MM.Heat_Page_buff == NULL || Heat58MM.Heat_Read == Heat58MM.Heat_Write)
{
Heat58MM.Heat_Write = 0;
Heat58MM.Heat_Read = 0;
return;
return 0;
}
if(Heat_Step == 0)
@ -187,26 +224,38 @@ static void Printer_start(uint8_t Heat_Step)
}else{
xEventGroupSetBits(Printer_group,EVENT_Heat_Begin);
}
return (Heat58MM.Heat_Write - Heat58MM.Heat_Read);
}
void Printer_Heat_task(void *pvParameter)
{
static uint8_t Ongoing_state = 0;
static uint8_t Heat_Step = 0;
EventBits_t bits;
ESP_LOGI(TAG,"Printer_Heat_task init");
while (1)
{
bits = xEventGroupWaitBits(Printer_group,EVENT_Motor_Test | EVENT_Heat_Begin | EVENT_Heat_Done | EVENT_SPI_SEND_Begin| Heat_END_EVENT | EVENT_SPI_SEND_Done,pdFALSE,pdFALSE,portMAX_DELAY);
bits = xEventGroupWaitBits(Printer_group,EVENT_Motor_Test | EVENT_Heat_Begin | EVENT_Heat_Done | EVENT_SPI_SEND_Begin
| EVENT_Motor_Sleep | Heat_END_EVENT | EVENT_SPI_SEND_Done,pdFALSE,pdFALSE,portMAX_DELAY);
switch (bits)
{
case EVENT_Motor_Test:
// ESP_LOGI(TAG,"Event Motor_Test");
// Fill_Page_Buff('A');
Heat58MM.Heat_Write = 80;
Printer_start(Heat_Step);
if (xSemaphoreTake(Motor_is_Running, 0) == pdTRUE)//上锁,电机运行中
{
Ongoing_state = 1;
}else if(Ongoing_state == 0){
ESP_LOGI(TAG,"Event Motor_is_Running");
xEventGroupClearBits(Printer_group,EVENT_Motor_Test);
break;
}
if(Printer_start(Heat_Step) == 0)
{
Ongoing_state = 0;
xSemaphoreGive(Motor_is_Running);//解锁
}
// Set_heat_timer_value(1000*1000*5);
xEventGroupClearBits(Printer_group,EVENT_Motor_Test);
break;
@ -262,6 +311,7 @@ void Printer_Heat_task(void *pvParameter)
xEventGroupClearBits(Printer_group,EVENT_SPI_SEND_Done);
break;
case EVENT_Motor_Sleep:
ESP_LOGI(TAG,"EVENT_Motor_Sleep");
Motor_GO(0xff);
xEventGroupClearBits(Printer_group,EVENT_Motor_Sleep);
break;
@ -273,8 +323,12 @@ void Printer_Heat_task(void *pvParameter)
void Printer_run_init()
{
Motor_is_Running = xSemaphoreCreateMutex();
Sys_heap_Init();
Heat58MM.Heat_Page_buff = malloc(58*1600);
Heat58MM.Heat_Page_buff = malloc(TH_ACTUAL_WIDTH*500*8);
Heat58MM.Heat_block_buff = malloc(TH_ACTUAL_WIDTH*100*8);
memset(&Heat58MM.Heat_Page_buff[0],0x00,TH_ACTUAL_WIDTH*500*8);
memset(&Heat58MM.Heat_block_buff[0],0x00,TH_ACTUAL_WIDTH*100*8);
xTaskCreatePinnedToCore(Printer_Heat_task, "Printer_Heat_task", 1024 * 10, NULL, 20, NULL, 1);//核心1
xTaskCreatePinnedToCore(Printer_Run_task, "Printer_Run_task", 1024 * 100, NULL, 12, NULL, 0);//核心1
}

View File

@ -79,6 +79,7 @@ extern gpio_state_t LAT;
extern gpio_state_t STB;
extern EventGroupHandle_t Printer_group;
extern spi_device_handle_t Printer_spi;
extern SemaphoreHandle_t SysTick_queue;
extern void BSP_GPIO_Init(void);
extern uint8_t Motor_GO(uint8_t DIR);
@ -89,4 +90,5 @@ extern void spi_printer_data_send(spi_device_handle_t handle, uint8_t* pBuffer);
extern void button_init(void);
extern void Feed_Key_motion_cb(void *arg, void *data);
extern void Sys_Key_motion_cb(void *arg, void *data);
extern void Timer_State_machine_cb(uint16_t time_ms);
#endif