static void reflash_led_blinker(void *parameters) { (void)parameters; while(!end_led) { led_set_red(0); led_set_green(1); vTaskDelay(100/portTICK_RATE_MS); led_set_red(1); led_set_green(0); vTaskDelay(100/portTICK_RATE_MS); } led_set_red(0); led_set_green(1); while(1) { vTaskDelay(1000/portTICK_RATE_MS); } }
////////////////////////////////////////////////////////////////////////////// /// Inizialization. This function is called once before entering /// main loop. /// ////////////////////////////////////////////////////////////////////////////// void init() { VMC_INT_16 motorID; init_aisc167b(); init_asccom(); init_cycletime_counter(); i2c_init(); init_bioport(); if (can_init(CAN_BAUD, 0)) while(1){led_swap_green();} led_set_green(0); led_set_red(0); ledseq_init(); ais_system_init(); //init_Thermic(); init_error(); init_calculatestate(); init_motorcontrol(); init_controller(); init_current_limiter(); mpwr_init(); set_default_configuration(); for (motorID = 0; motorID < 3; motorID++) { // init_Limiter(i, 100); init_encoder(motorID); } }
/* Reflash the controller flash if all of the following conditions are satisfied: * + We have new flash content in eink_flash_content * + The flash identification indicates our custom built controller and not the stock Epson one * + The first 4 bytes of the existing flash content do not match eink_flash_content * * If this function returns a positive value then the controller was reset and the application * should wait 5ms before proceeding; if the function returns 0, no change was done; if the * function returns a negative value it is an error code */ int eink_flash_conditional_reflash(void) { if(sizeof(eink_flash_content) == 0) return 0; int r = eink_flash_acquire(); if(r>=0) { unsigned int ident = eink_flash_read_identification(); xTaskHandle led_task_handle; #ifdef DEBUG_REFLASH printf("Device identification: %06X\n", ident); #endif if( ident != 0x202016 ) { /* Only for our own flash, not the pre-assembled */ goto out_done; } eink_flash_read(0, flash_tmpbuf, sizeof(flash_tmpbuf)); #ifdef DEBUG_REFLASH printf("%02X %02X %02X %02X\n", flash_tmpbuf[0], flash_tmpbuf[1], flash_tmpbuf[2], flash_tmpbuf[3]); #endif if(memcmp(flash_tmpbuf, eink_flash_content, sizeof(flash_tmpbuf)) != 0) { printf("Flash content not correct, starting reflash cycle\nDO NOT POWER OFF\n"); xTaskCreate( reflash_led_blinker, (signed char*)"LED BLINKER", 128, NULL, tskIDLE_PRIORITY+1, &led_task_handle); printf("Starting bulk erase\n"); eink_flash_write_enable(); eink_flash_bulk_erase(); printf("Done bulk erase\n"); printf("Starting programming (%i bytes)\n", sizeof(eink_flash_content)); eink_flash_program(eink_flash_content, sizeof(eink_flash_content)); printf("Done\n"); end_led = 1; vTaskDelay(150/portTICK_RATE_MS); vTaskDelete(led_task_handle); led_set_red(0); led_set_green(1); } } else { return r; } out_done: eink_flash_release(); return 1; }
void show_color(unsigned char dig){ switch(dig){ case 0: led_set_yellow(POWER); led_set_black(); led_set_black(); led_set_black(); led_set_black(); sound_start(dig); break; case 1: led_set_black(); led_set_red(POWER); led_set_black(); led_set_black(); led_set_black(); sound_start(dig); break; case 2: led_set_black(); led_set_black(); led_set_green(POWER); led_set_black(); led_set_black(); sound_start(dig); break; case 3: led_set_black(); led_set_black(); led_set_black(); led_set_blue(POWER); led_set_black(); sound_start(dig); break; } }