static void periphInit() { USART_Config(BT_USART, BT_BaudRate); FileManager_Init(); PWM_Init(HEATER_PWM_FREQ); Move_Init(); Extruder_Init(); HeatBed_Init(); USBDevice_Config(); Command_Init(); HostCtrl_Init(); }
int main(void) { int Temp_Che; int File_fd; unsigned int n; unsigned char *Buf; SetforI2C(); GPIOInit(); //PB3 = 0; force M4 to Update.when done ,it need to change //PB4 = 0; Rest M4; //PB4 = 1; before this step,need think whether there is a delay(usleep) Program_Size = Get_file_size(File_Path); if(Program_Size == -1) { printf("Get_file_size failed\n"); //need other handle } Buf = (unsigned char *)malloc(Program_Size); Command_Init(); if((File_fd = open(File_Path, O_RDONLY)) < 0 ) { printf("file open failed\n"); } if(read(File_fd, Buf, Program_Size) < 0) { printf("file read failed\n"); } Temp_Che = -1; while(Temp_Che == -1 ) { Temp_Che = Send_Command(command_ping, 1); } Temp_Che = -1; while(Temp_Che == -1) { Temp_Che = Send_Command(command_download, 9); } n = Program_Size / 100; while(n--) { strncpy(command_send_data + 1, Buf, 100); Temp_Che = -1; while(Temp_Che == -1) { Temp_Che = Send_Command(command_send_data, 101); } Buf = Buf + 100; } Temp_Che = -1; strncpy(command_send_data + 1, Buf + n * 100, Program_Size - n * 100); while(Temp_Che == -1) { Temp_Che = Send_Command(command_send_data, (Program_Size - n * 100) + 1); } free(Buf); close(File_fd); return 0; }