/** * Function signaling that error have occured through LED on board. */ void errorSTOP() { TCM_disable(); USBTCM_error=1; possibleFile=0; while (USBTCM_error==1 && possibleFile==0) // TCM operation failed { LED_ClrVal(NULL); WAIT_Waitms(400); LED_SetVal(NULL); WAIT_Waitms(400); } }
void checkBusytoHigh() { uint8_t i = 0; while (1) { if (Busy_GetVal(NULL)) { break; } else if (i == 40) // Gives timeout about 4s { errorSTOP(); } WAIT_Waitms(200); i++; } }
int main() { /* Perform processor initialization */ sysinit(); printf("\nRunning the SolderTermo_v2 project.\r\n"); initTime(); initNVRAM(); readNVRAM(); printf("Version %hd\tCRC %hd\r\n", nvram.Version, nvram.nvramCrc); initDisplay(); //initMAX31855(); initThermocoupleADC(); initPowerPWM(); initHMI(); initButtons(); initStateMachine(); int fastLog = 0; while(1) { if (fastLog) printf("%hd\t%hd\r\n", vram.ADCVal, vram.CurrTemp); else printf("%hd\t%hd\t%hd\t%hd\t%hd\t%hd\r\n", vram.CurrTemp / 10, nvram.Tsp, vram.PWM_Sp, nvram.Kp, nvram.Ki, nvram.Kd); if ( UART_CharPresent(UART2) ) { uint8_t c; uint8_t charNo = 0; memset(uartBuff, 0, UART_MAX_BUFF); printf("Finish your input by ENTER\r\n"); printf("\r\n"); do { c = uartBuff[charNo++] = UART_GetChar(UART2); // wait for char to come UART_PutChar(UART2, c); WAIT_Waitms(50); } while ( c != '\r' && charNo < UART_MAX_BUFF ); switch(uartBuff[0]) { case 'f': fastLog = 1; break; // fast logging case 's': fastLog = 0; break; // slow logging case 'p': nvram.Kp = atoi(uartBuff + 1); break; // fast logging case 'i': nvram.Ki = atoi(uartBuff + 1); break; // slow logging case 'd': nvram.Kd = atoi(uartBuff + 1); break; // slow logging } } WAIT_Waitms(fastLog ? 20 : 200); } return 0; // should never come here }
/** * @brief Read and send EPD response * @return Status-response */ LDD_TError readAndSendEPD() { TCM_enable(); PE_low_level_init(); // Pointer to part of an image. uint32 ii = 0; uint32 a = 0; uint32 nr_block_flash = 0; LDD_TError Result = -1; uint32_t ImageDatatoSend = 0; uint32_t image_shift = 0; uint8_t fileDetected = 0; uint32_t imageStart = 0x7000; uint32_t controlFileStartAddress = 0; fileDetected = findFileStartAddress(&imageStart, &controlFileStartAddress); if(controlFileStartAddress) { EM_ReadData((uint8_t*) &upload_image2, controlFileStartAddress, 16); uint32_t len = upload_image2[0]; if(len > 0) { tcm_drivescheme = upload_image2[1]; } if(len > 1) { tcm_framebuffer_slot = upload_image2[2]; } } else { tcm_drivescheme = 0x24; tcm_framebuffer_slot = 0; } display_update[0] = tcm_drivescheme; upload_image[2] = tcm_framebuffer_slot; display_update[2] = tcm_framebuffer_slot; if (fileDetected == 1) { EM_ReadData((uint8_t*) &upload_image2, imageStart, 400); uint16_t res_x, res_y, color_bit; res_x = upload_image2[1] * 256 + upload_image2[2]; res_y = upload_image2[3] * 256 + upload_image2[4]; color_bit = upload_image2[5]; ImageDatatoSend = res_x * res_y / 8; if(color_bit) { ImageDatatoSend *= color_bit; } ImageDatatoSend += 16; //image header if (ImageDatatoSend < EM_SETUP_MEMORY_SIZE_BYTES) { LED_ClrVal(NULL); nr_block_flash=0; while(ImageDatatoSend>0) { EM_ReadData((uint8_t*) &upload_image2,imageStart - image_shift + (nr_block_flash * 400), 400); for (ii = 0; ii < 4; ii++) { // Copying part of image. for (a = 0; a < 100; a++) { upload_image[a + 4] = upload_image2[100 * ii + a]; } // Sending image to TCM. if(ImageDatatoSend>=100) { upload_image[3] = 100; tcm_receive=TCM_ImageUpload(upload_image, 104); ImageDatatoSend-=100; } else { upload_image[3] = ImageDatatoSend; tcm_receive=TCM_ImageUpload(upload_image, ImageDatatoSend+4); ImageDatatoSend=0; } if(tcm_receive != 0x90) { if((ii != 0)||(nr_block_flash != 0)) { errorSTOP(); return Result; } } if(ImageDatatoSend==0) { break; } } nr_block_flash++; } } } else { //if there was no upload then give time for the TCM to start-up (upload is starting with a delay) WAIT_Waitms(20); } if((USBTCM_error == 0) && (fileDetected || controlFileStartAddress)) { WAIT_Waitms(1); //The period of this WAIT is different ~(x 0.5) tcm_receive=TCM_DisplayUpdate(); if(tcm_receive != 0x90 && fileDetected) //check response for upload command { errorSTOP(); return Result; } WAIT_Waitms(1); checkBusy(); // Check Busy pin to low if(USBTCM_error!=0) { return Result; } checkBusytoHigh(); // Check Busy pin to if(USBTCM_error!=0) { return Result; } WAIT_Waitms(2); tcm_receive=TCM_GetAnswer(); if(tcm_receive != 0x90) { errorSTOP(); return Result; } } possibleFile = 0; TCM_disable(); return Result; }