void env_init() { clrscr(); move_cursor(0,0); setup_hw(); puts("Ben OS v"BOS_VERSION" starting...\n"); puts(msg_boot32ok); check_memory(); floppy = get_floppy_info(); }
int main(void) { setup_hw(); delay(6000); process_lamp_job(LJ_FADE_IN); for (;;) { //soft_uart_rx_test(); //adc_test(1); // shows ADCH on the 8 LEDs. timer1 should be OFF (or it blinks like mad --> headache) TOGGLE_LED; // make the lamps visible in the darkness kitchen_lights(1); } }
int main(void) { setup_charlie_struct(); setup_hw(); //for(uint16_t a=0;a<=buffer_length;a++) buffer[a]=0; //clear buffer // Initialize AVR for use with mirf mirf_init(); // Wait for mirf to come up _delay_ms(50); // Activate interrupts sei(); // Configure mirf mirf_config(); // Test communication int i = 0; sei(); //global interrupt enable roll_charlie(); while(1) { /* for(uint8_t i=0;i<10;i++) { mirf_send(&i,1); _delay_ms(1000); } */ uint8_t status = mirf_data_ready(); while (!status); LED_PATTERN=status; //mirf_get_data(*buffer); //set_charlie(buffer[i]); //i++; } }
int main(void) { setup_hw(); for (;;) { switch( PINB & 0x06 ) // only get PB2 and PB1 { case 0x02: // something on PB1 if(OCR0A < 255) { OCR0A++; } break; case 0x04: // something on PB2 if(OCR0A > 0) { OCR0A--; } break; default: break; } delay(5); } }
int main(void) { setup_hw(); static uint8_t button_press_just_happened = 0; static uint8_t not_the_first_time_pressed = 0; #ifdef USE_PWM uint8_t lamp_state = 0; uint8_t OCR1B_tmp = 0; #endif while(1) { int8_t counts = encoder_get(ENC_COUNTS); int16_t velocity = encoder_get(ENC_VELOCITY); if( counts > 0 ) { #ifdef AUTO_COARSE_FINE if( velocity > COARSE_FINE_THRESHOLD ) { soft_uart_send(PSTR("+"),4); } else { soft_uart_send(PSTR("+"),1); } #else soft_uart_send(PSTR("+"),1); #endif #ifdef USE_PWM if(OCR1B < 255) { OCR1B++; } else { #ifdef SHOW_PWM_MAX LED_on; // signal that the maximum has been reached delay(200); LED_off; LED_idle; #endif } lamp_state = 1; #endif } if( counts < 0 ) { #ifdef AUTO_COARSE_FINE if( velocity < -COARSE_FINE_THRESHOLD ) { soft_uart_send(PSTR("-"),4); } else { soft_uart_send(PSTR("-"),1); } #else soft_uart_send(PSTR("-"),1); #endif #ifdef USE_PWM if(OCR1B > 0) { OCR1B--; } else { lamp_state = 0; } #endif } if( encoder_get(BUTTON_WAS_PRESSED) ) { soft_uart_send(PSTR("/"),1); button_press_just_happened = 1; #ifdef USE_PWM if( lamp_state == 1 ) { OCR1B_tmp = OCR1B; // save PWM value lamp_state = 0; // lamp is off OCR1B = 0; // turn PWM off } else { OCR1B = OCR1B_tmp; // restore PWM value lamp_state = 1; // lamp is on } #endif } if( encoder_get(BUTTON_WAS_RELEASED) ) { soft_uart_send(PSTR("\\"),1); not_the_first_time_pressed = 0; } if( encoder_get(BUTTON_STATE) && ( (button_press_just_happened == 1) || (not_the_first_time_pressed == 1) ) ) { // "¯" is an unicode character! It will be sent as 2 bytes ( 0xC2 0xAF ) soft_uart_send(PSTR("¯"),1); button_press_just_happened = 0; not_the_first_time_pressed = 1; delay(50); } else { //soft_uart_send(PSTR("_"),1); } } return 0; }
static void extract_e820(void) { int id = fw_cfg_file_id("etc/e820"); uint32_t size; int nr_map; int i; if (id == -1) panic(); size = fw_cfg_file_size(id); nr_map = size / sizeof(e820->map[0]) + 4; fw_cfg_file_select(id); e820 = malloc(offsetof(struct e820map, map[nr_map])); e820->nr_map = nr_map; e820->map[0] = (struct e820entry) { .addr = 0, .size = 639 * 1024, .type = E820_RAM }; /* low RAM */ e820->map[1] = (struct e820entry) { .addr = 639 * 1024, .size = 1024, .type = E820_RESERVED }; /* EBDA */ e820->map[2] = (struct e820entry) { .addr = 0xd0000, .size = 128 * 1024, .type = E820_NVS }; /* ACPI tables */ e820->map[3] = (struct e820entry) { .addr = 0xf0000, .size = 64 * 1024, .type = E820_RESERVED }; /* firmware */ fw_cfg_read(&e820->map[4], size); for (i = 4; i < e820->nr_map; i++) if (e820->map[i].addr == 0) { lowmem = e820->map[i].size; e820->map[i].addr = 1024 * 1024; e820->map[i].size -= 1024 * 1024; break; } e820_seg = ((uintptr_t) e820) >> 4; } static bool detect_cbfs_and_boot(void) { size_t sz; void *base = pflash_base(1, &sz); if (!base) return false; return boot_from_cbfs(base, sz); } int main(void) { setup_hw(); // Now go to the F-segment: we need to move away from flash area // in order to probe CBFS! asm("ljmp $0x8, $1f; 1:"); setup_pci(); setup_idt(); fw_cfg_setup(); extract_acpi(); extract_e820(); // extract_smbios(); if (!detect_cbfs_and_boot()) boot_from_fwcfg(); panic(); }
int main(void) { setup_hw(); uint32_t fan_timeout = 0; uint8_t state = 0; uint32_t high_time = 0; uint32_t low_time = 0; uint32_t half_period = 0; int32_t adc_val = 0; uint32_t pot_poll_timeout = 0; while (1) { if ((millis() - pot_poll_timeout) > 1000) { uint16_t tmp1 = adc_read(); if (tmp1 > 512) { adc_val = (176 * (int32_t)(tmp1) - 80288) * ( MEASURE_INTERVAL / 10 ); } else { adc_val = ( MEASURE_INTERVAL * 1000000 ) / (- 176 * (int32_t)(tmp1) + 100112 ) * 10; } pot_poll_timeout = millis(); } if ((millis() - fan_timeout) > 2000) { flag = 1; edges = 2; } if (flag == 1) { half_period = (uint32_t) (adc_val / (edges-1)); flag = 0; fan_timeout = millis(); } switch (state) { case 0: if ((micros() - low_time) > half_period) { DDRB &= ~_BV(PB4); // set as input (pull-up off) PORTB |= _BV(PB1); // LED off high_time = micros(); state = 1; } break; case 1: if ((micros() - high_time) > half_period) { DDRB |= _BV(PB4); // set as output PORTB &= ~_BV(PB4); // pull low PORTB &= ~_BV(PB1); // LED on low_time = micros(); state = 0; } break; default: break; } } }