void busywait_us(long long int us) { long long int threshold; timer0_update_value_write(1); threshold = timer0_value_read() - us*CONFIG_CLOCK_FREQUENCY/1000000LL; while(timer0_value_read() > threshold) timer0_update_value_write(1); }
static int test_user_abort(void) { char c; printf("Automatic boot in 2 seconds...\n"); printf("Q/ESC: abort boot\n"); printf("F7: boot from serial\n"); #ifdef MINIMAC_BASE printf("F8: boot from network\n"); #endif timer0_en_write(0); timer0_reload_write(0); timer0_load_write(identifier_frequency_read()*2); timer0_en_write(1); timer0_update_value_write(1); while(timer0_value_read()) { if(readchar_nonblock()) { c = readchar(); if((c == 'Q')||(c == '\e')) { puts("Aborted"); return 0; } if(c == 0x06) { serialboot(); return 0; } #ifdef MINIMAC_BASE if(c == 0x07) { netboot(); return 0; } #endif } timer0_update_value_write(1); }
static int check_ack(void) { int recognized; static const char str[SFL_MAGIC_LEN] = SFL_MAGIC_ACK; timer0_en_write(0); timer0_reload_write(0); timer0_load_write(identifier_frequency_read()/4); timer0_en_write(1); timer0_update_value_write(1); recognized = 0; while(timer0_value_read()) { if(uart_read_nonblock()) { char c; c = uart_read(); if(c == str[recognized]) { recognized++; if(recognized == SFL_MAGIC_LEN) return 1; } else { if(c == str[0]) recognized = 1; else recognized = 0; } } timer0_update_value_write(1); } return 0; }
long long int clock_get_ms(void) { long long int clock_sys; long long int clock_ms; timer0_update_value_write(1); clock_sys = 0x7fffffffffffffffLL - timer0_value_read(); clock_ms = clock_sys/(CONFIG_CLOCK_FREQUENCY/1000); return clock_ms; }
unsigned int timer_get(void) { return timer0_value_read(); }