void chrono_end_match (uint8_t block) { vect_t v = { 0, 0 }; /* Stop beacon system. */ if (AC_AI_TWI_MASTER_BEACON) { beacon_on (0); beacon_send_position (&v); } /* Make the bot stop moving */ asserv_stop_motor (); /* Wait until complete */ while (!twi_master_sync ()) timer_wait (); /* Wait, then release motors. */ utils_delay_ms (CHRONO_WAIT_BEFORE_FREE_MS); asserv_free_motor (); /* Wait until complete */ while (!twi_master_sync ()) timer_wait (); /* Block indefinitely */ while (block) utils_delay_ms (1000); }
int main (void) { system_init (); led_init (); /* TODO: Initialise timer/counter1. */ TCCR1A = 0x00; TCCR1B = 0x05; TCCR1C = 0x00; TCNT1 = 0; while (1) { /* Turn LED on. */ led_set (LED1, 1); /* TODO: wait for 500 milliseconds. */ timer_wait(40); /* Turn LED off. */ led_set (LED1, 0); //timer_wait(3900); timer_wait(40); /* TODO: wait for 500 milliseconds. */ } }
/*----------------------------------------------------------------------------*/ void blink_error(int count) { while(count>0) { gpio_toggle(ERROR_LED); timer_wait(TIMER_S/2); gpio_toggle(ERROR_LED); timer_wait(TIMER_S/2); count--; } }
void blink(uint8_t times) { while(times--) { nrf_gpio_pin_set(CONFIG_LED_PIN); timer_wait(MILLISECONDS(10)); nrf_gpio_pin_clear(CONFIG_LED_PIN); timer_wait(MILLISECONDS(490)); } }
void beep(unsigned int wait_time,unsigned int times ) { unsigned char tempA =inb(0x61); unsigned char tempB = (inb(0x61) & 0xFC); unsigned int count; for(count = 0; count < times; count++) { if(tempA != (tempA | 3)) { outb(0x61, tempA | 3); } timer_wait(wait_time); outb(0x61, tempB); timer_wait(1); } }
/** * Generates a manual field rotation to give an initial impulse to the * motor. */ int8_t bldc_start() { unsigned long timer = START_MAX, i; unsigned char maintain = START_MAINTAIN; bldc_phase = 0; DISABLE_BEMF_INT(); bldc_set_pwm(PWM_START); bldc_set_comm(); while (1) { for (i = 0; i < timer; i++) { timer_wait(100); } timer -= START_DEC(timer); if (timer < START_MIN) { if (maintain) { timer = START_MIN; maintain--; } else { return 1; } } bldc_set_comm(); bldc_phase++; bldc_phase %= 6; if (BEMF) { LED_GREEN_TOGGLE(); } } return 0; }
/** Main initialisation. */ static void main_init (void) { #ifndef HOST /* Disable watchdog (enabled in bootloader). */ MCUSR &= ~(1 << WDRF); wdt_disable (); #endif /* Serial port */ uart0_init (); /* Enable interrupts */ sei (); /* Main timer */ timer_init (); timer_wait (); /* TWI communications */ asserv_init (); mimot_init (); twi_master_init (); /* IO modules. */ pwm_init (); contact_init (); codebar_init (); usdist_init (); /* AI modules. */ clamp_init (); logistic_init (); path_init (); /* Initialization done. */ proto_send0 ('z'); }
bool BIKPlayer::next_frame() { if (timer_last_sec) { timer_wait(); } if(frameCount>=header.framecount) { return false; } binkframe frame = frames[frameCount++]; str->Seek(frame.pos, GEM_STREAM_START); ieDword audframesize; str->ReadDword(&audframesize); frame.size = str->Read( inbuff, frame.size - 4 ); if (DecodeAudioFrame(inbuff, audframesize)) { //buggy frame, we stop immediately //return false; } if (DecodeVideoFrame(inbuff+audframesize, frame.size-audframesize)) { //buggy frame, we stop immediately return false; } if (!timer_last_sec) { timer_start(); } return true; }
uint16_t acc_magnitude(int8_t* angle) { int16_t acc[3], a, alpha; /* briefly turn on accelerometer */ acc_write(ACC_REG_CTRL_REG1, 0x97); timer_wait(MILLISECONDS(2)); acc_read(ACC_REG_OUT_X, sizeof(acc), (uint8_t*)&acc); acc_write(ACC_REG_CTRL_REG1, 0x00); /* get acceleration vector magnitude */ a = sqrt32( ((int)acc[0])*acc[0] + ((int)acc[1])*acc[1] + ((int)acc[2])*acc[2] )/64; /* calculate tag angle */ if(angle) { if(!a) alpha = 127; else { alpha = (acc[2]*2)/a; if(alpha>127) alpha=127; else if(alpha<-127) alpha=-127; } *angle = asin7deg(alpha); } return a; }
int arm_main() { int cmdl; int flags, shift_buffer, pass; /* Initialize the AICA part of the SPU */ aica_init(); /* Observe channel 0 */ SNDREG8(0x280d) = 0; /* Wait for a command */ while(1) { /* Check for a command */ cmdl = *cmd; if (cmdl & AICA_CMD_KICK) { *cmd = 0; process_cmd(cmdl & ~AICA_CMD_KICK); } /* Update position counters */ chans[0].pos = SNDREG32(0x2814); /* Little delay to prevent memory lock */ timer_wait(10); } }
void halt(uint8_t times) { while(TRUE) { blink(times); timer_wait(SECONDS(3)); } }
void timer_set(uint16_t time) { timer_wait(); RTC.COMP = (time+3+RTC.CNT)%65536; if((RTC.INTFLAGS & 0x02) != 0) RTC.INTFLAGS = 0x02; RTC.CTRL = RTC_PRESCALER_DIV2_gc; }
void timer_reset(void ) { timer_wait(); RTC.CTRL = 0; RTC.COMP = 0; RTC.CNT = 0; if((RTC.INTFLAGS & 0x02) != 0) RTC.INTFLAGS = 0x02; }
void func1() { int x=0; while(1) { timer_wait(6); //putch('A'); putch('\n'); printInt(x++); } }
void ext2_flush_dirty(uint32_t ent_no) { // write out to the disk for (uint32_t i = 0; i < BLOCKSIZE / SECTORSIZE; ++i) { ide_write_sector(DISK_PORT, 0, btos(DC[ent_no].block_no) + i, (uint8_t *)((uint32_t)&DC[ent_no].block + SECTORSIZE * i)); //XXX: a hack? how about making ide_write_sector() blocking? // XXX: ^ ide_write_sector() IS blocking, we don't get notified properly of finishes to write calls timer_wait(10); } DC[ent_no].dirty = 0; }
void testprogram() { putch('\n'); while(1) { putch('\n'); puts("Hi"); timer_wait(6); } }
/** Main loop. */ static void main_loop (void) { main_timer[3] = timer_read (); /* Compute absolute position. */ aux_pos_update (); main_timer[4] = timer_read (); /* Compute trajectory. */ aux_traj_update (); /* Prepare control system. */ cs_update_prepare (); main_timer[5] = timer_read (); /* Wait for next cycle. */ timer_wait (); /* Encoder update. */ encoder_update (); main_timer[0] = timer_read (); /* Control system update. */ cs_update (); main_timer[1] = timer_read (); /* Pwm setup. */ output_update (); main_timer[2] = timer_read (); /* Sequences. */ seq_update (&seq_aux[0], &cs_aux[0].state); seq_update (&seq_aux[1], &cs_aux[1].state); /* Stats. */ if (main_sequence_ack && (seq_aux[0].ack != seq_aux[0].finish || seq_aux[1].ack != seq_aux[1].finish) && !--main_sequence_ack_cpt) { //XXX here proto_send2b ('A', seq_aux[0].finish, seq_aux[1].finish); main_sequence_ack_cpt = main_sequence_ack; } if (main_stat_counter && !--main_stat_counter_cpt) { proto_send2w ('C', encoder_aux[0].cur, encoder_aux[1].cur); main_stat_counter_cpt = main_stat_counter; } if (main_stat_aux_pos && !--main_stat_aux_pos_cpt) { proto_send2w ('Y', aux[0].pos, aux[1].pos); main_stat_aux_pos_cpt = main_stat_aux_pos; } if (main_stat_speed && !--main_stat_speed_cpt) { proto_send2w ('S', cs_aux[0].speed.cur_f >> 8, cs_aux[1].speed.cur_f >> 8); main_stat_speed_cpt = main_stat_speed; }
void proccmd(char * cmd) { if (strcmp(cmd, "clear") == 0) { clrscr(); gotoxy(0, -1); /* csr_y = -1 because of "\n" in prompt */ } else if (strcmp(cmd, "minios") == 0) about(); else if (strcmp(cmd, "reboot") == 0) { printk("\nrebooting...\n"); timer_wait(10); printk("\n[NOW]"); timer_wait(5); reboot(); } else if (strcmp(cmd, "help") == 0) help(); else if (strcmp(cmd, "date") == 0) { struct time t; kernel_mktime(&t); printk("\n%02d/%02d\t%02d:%02d:%02d IST\t%04d\n", t.month, t.day, t.hour, t.min, t.sec, t.year); } else printk("\nMINI shell : %s : command not found\n", cmd); }
void kernel_stop() { clear(); println("** Kernel Panic **\n"); print("Kernel Information > "); print(_KERNEL_BUILD_TIME_); print("::"); print(_KERNEL_BUILD_DATE_); __asm__ volatile ("hlt"); timer_wait(5); reboot(); }
/** * \brief LIN Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { /* Output example information */ console_example_info("LIN Example"); /* Configure Console interrupts */ printf("Initializing console interrupts\r\n"); console_set_rx_handler(_console_handler); console_enable_rx_interrupt(); /* Configure Timer/Counter */ _configure_tc(); /* Configure com port */ _init_com_master(); _init_com_slave(); /* main LIN program */ _display_menu(); do { switch (key) { case 'P': case 'p': case 'S': case 's': case 'I': case 'i': tc_stop(TC0, TC_CHANNEL); _process_button_evt(); _display_menu(); if (key == 'I' || key == 'i') tc_stop(TC0, 0); else tc_start(TC0, TC_CHANNEL); key = 0; break; default: break; } } while (key != 'q' && key != 'Q'); tc_stop(TC0, TC_CHANNEL); timer_wait(500); printf("\n\rEnd of demo\n\r"); while (1); }
int kbd_test_leds(unsigned short n, unsigned short *toggle) { unsigned short led_status = 0; kbd_subscribe_int(); unsigned int i = 0; for (i = 0; i < n; i++) { if (kbd_toggle_led(toggle[i], &led_status) != 0) { printf("kbd_test_leds()::led number %d doesn't exist\n", toggle[i]); continue; } printf("kbd_test_leds()::0x0%X ", led_status); printf("(caps lock = %s, scroll lock = %s, num lock = %s)\n", led_status & CAPS_LOCK ? "o" : " ", led_status & SCROLL_LOCK ? "o" : " ", led_status & NUM_LOCK ? "o" : " "); timer_wait(12 /* 12/60 = 200ms */); } kbd_unsubscribe_int(); return 0; }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog sys_init(); // See 'sys_init.c' timer_init(); // See 'timer_init.c' reset_lcd(); // See 'lcd_driver.c' timer_wait(100); // See 'timer_init.c' init_ILI9340C(); // See 'lcd_config.c' RGB_test_lcd(); // See 'lcd_driver.c' P1OUT &= ~BIT6; // Turn off green LED P1OUT |= BIT0; // Turn on green LED _BIS_SR(CPUOFF); // MSP430 shutdown }
void kernel_main() { gdt_install(); idt_install(); isrs_install(); irq_install(); terminal_initialize(); memory_manager_init(); enable_interrupts(); timer_install(); keyboard_install(); shell_init(); terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Here is some text in a new line\n"); terminal_writestring("Here is some more text\n"); terminal_writestring("Here is a new line\n"); terminal_writestring("Here is some text after terminal scroll\n"); char str[] = "A string"; char ch = 'c'; int integer = 45; printf("This is a test for printf.\nThis is a char %c and this a string %s\n", ch, str); printf("This is an int %d. This is the same in hex %x\n", integer, integer); for (size_t i = 0; i < 5; i++) { printf("This is line number %d\n", i); } puts("waiting for 2 sec\n"); timer_wait(2); puts("waiting complete\n"); char buffer[200]; gets(buffer); printf("%s\n", buffer); while(1) { shell(); } }
void* thread_run(void* arg) { thread_t* thread = arg; void* result = 0; pthread_cleanup_push(thread_cleanup, thread); #ifdef HAVE_LIBGCC_S pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0); #else pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); #endif thread_condition_lock(&thread->condition); thread->state = thread_state_running; thread_condition_signal(&thread->condition); thread_condition_unlock(&thread->condition); timer_start(&thread->start_time); if (thread->frequency > 0.0) { while (!thread_test_exit(thread)) { double timestamp; timer_start(×tamp); result = thread->routine(thread->arg); timer_wait(timestamp, thread->frequency); } } else result = thread->routine(thread->arg); pthread_cleanup_pop(1); return result; }
void sleep_ms(unsigned int n) { timer_wait(n * MICROSEC_TO_MILLSEC); }
void sleep(unsigned int n) { timer_wait(n * MICROSEC_TO_SEC); }
/** * Initializes the DBGU and ISO7816 driver, and starts some tests. * \return Unused (ANSI-C compatibility) */ extern int main( void ) { uint8_t Atr[MAX_ATR_SIZE] ; uint8_t size ; /* Disable watchdog */ wdt_disable(); /* Disable all PIO interrupts */ pio_reset_all_it(); /* Configure console */ board_cfg_console(); console_clear_screen(); console_reset_cursor(); /* Configure PIT. Must be always ON, used for delay */ printf("Configure PIT \n\r"); timer_configure(BLINK_PERIOD); printf( "-- USART ISO7816 Example %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; #ifdef CONFIG_HAVE_PMIC_ACT8945A pio_configure(act8945a_pins, ARRAY_SIZE(act8945a_pins)); if (act8945a_configure(&act8945a, &act8945a_twid)) { act8945a_set_regulator_voltage(&act8945a, 6, 2500); act8945a_enable_regulator(&act8945a, 6, true); } else { printf("--E-- Error initializing ACT8945A PMIC\n\r"); } #endif /* PIO configuration for LEDs */ printf("Configure LED PIOs.\n\r"); _configure_leds(); led_set(LED_BLUE); timer_wait(500); led_clear(LED_BLUE); led_status[LED_BLUE] = 1; /* PIO configuration for Button, use to simulate card detection. */ printf("Configure buttons with debouncing.\n\r"); _configure_buttons(); /* Configure Pios usart*/ pio_configure(&pins_com2[0], ARRAY_SIZE(pins_com2)); /* Init ISO7816 interface */ iso7816_init(&iso7816_desc, &iso7816_opt); /* Warm reset */ iso7816_warm_reset(&iso7816_desc); /* Read ATR */ memset( Atr, 0, sizeof(Atr) ) ; iso7816_get_data_block_ATR(&iso7816_desc, Atr, &size ); /* Decode ATR */ iso7816_decode_ATR(Atr); /* Allow user to send some commands */ _send_receive_commands(&iso7816_desc); printf("\n\r Exit App \n\r"); while (1) ; }
int main (void) { uint8_t i; #ifndef HOST uint8_t read_old = 0; uint8_t old_ind = 0; const int total = 5000; #endif timer_init (); for (i = 0; i < AC_ENCODER_EXT_NB; i++) encoder_init (i, &encoder[i]); encoder_corrector_init (&encoder_corrector_right); uart0_init (); proto_send0 ('z'); sei (); while (1) { timer_wait (); if (count) { encoder_update (); encoder_corrector_update (&encoder_corrector_right, &encoder[1]); } #ifndef HOST if (read && !--read_cpt) { uint8_t r0, r1, r2, r3; r0 = encoder_ext_read (0); r1 = encoder_ext_read (1); r2 = encoder_ext_read (2); r3 = encoder_ext_read (3); if (read_mode == 0 || (read_mode == 1 && r3 != read_old) || (read_mode == 2 && (r0 == 0 || r1 == 0 || r2 == 0 || r3 == 0))) { proto_send4b ('r', r0, r1, r2, r3); read_old = r3; } read_cpt = read; } if (ind && !--ind_cpt) { i = encoder_ext_read (3); if (!ind_init && i != old_ind) { uint8_t eip = old_ind + total; uint8_t eim = old_ind - total; proto_send7b ('i', old_ind, i, eip, eim, i - eip, i - eim, i == eip || i == eim); } old_ind = i; ind_init = 0; ind_cpt = ind; } #endif if (count && !--count_cpt) { proto_send4w ('C', encoder[0].cur, encoder[1].cur, encoder[2].cur, encoder[3].cur); count_cpt = count; } while (uart0_poll ()) proto_accept (uart0_getc ()); } }
/*----------------------------------------------------------------------------*/ void main(void) { char temp[16]; fb_t* display; /** initialize gpio */ gpio_init(); gpio_config(ERROR_LED,GPIO_OUTPUT); timer_init(); /** initialize video stuff - mailbox before that! */ mailbox_init(); do { blink_error(2); timer_wait(TIMER_S); display = video_init(VIDEO_RES_VGA); } while (!display); video_set_bgcolor(COLOR_BLUE); video_clear(); /** write something */ video_text_char('H'); video_text_char('E'); video_text_char('L'); video_text_char('L'); video_text_char('O'); video_text_char('!'); video_text_string("\nHAHA!"); video_text_cursor(3,1); video_text_string("Welcome!"); /* display info */ video_text_newline(); video_text_string("DISPX: "); int2str(temp,display->screen.xres); video_text_string(temp); video_text_string(", "); video_text_string("DISPY: "); int2str(temp,display->screen.yres); video_text_string(temp); video_text_string(", "); video_text_string("VDISPX: "); int2str(temp,display->screen.xout); video_text_string(temp); video_text_string(", "); video_text_string("VDISPY: "); int2str(temp,display->screen.yout); video_text_string(temp); video_text_char('\n'); video_text_string("OFFX: "); int2str(temp,display->screen.xoff); video_text_string(temp); video_text_string(", "); video_text_string("OFFY: "); int2str(temp,display->screen.yoff); video_text_string(temp); video_text_string(", "); video_text_string("XMAX: "); int2str(temp,display->cursor.xmax); video_text_string(temp); video_text_string(", "); video_text_string("YMAX: "); int2str(temp,display->cursor.ymax); video_text_string(temp); video_text_char('\n'); video_text_string("PITCH: "); int2str(temp,display->screen.pskip); video_text_string(temp); video_text_string(", "); video_text_string("DEPTH: "); int2str(temp,display->screen.depth); video_text_string(temp); /* test col overflow */ video_text_cursor(display->cursor.y+1,display->cursor.xmax-5); video_text_string("Continue next line!"); /* test line drawing */ video_draw_line(100,100,200,100); video_draw_line(200,100,100,200); video_draw_line(100,200,100,100); video_text_string("\nWait for it..."); blink_error(3); /* test row overflow */ video_text_cursor(display->cursor.ymax-1,display->cursor.xmax-5); video_text_string("Scroll this!"); /** sticking around */ while(1); }
void delay_ms(int delay){ //timer_wait(TICKS); timer_wait(39); }