void SetCommand() { //copy the data for (int i = 0; i < 13; i++) { DeviceConfig[i] = input_data[i+1]; } //send the data to the peripherie Output_data(); //save the data to the eeprom, if wanted if ((DeviceConfig[12] & 0x01) == 0x01) { for (int i = 0; i < 12; i++) { uint8_t eeprom_addr = EEPROM_CONFIG_OFFSET + i; eeprom_update_byte((uint8_t*)eeprom_addr, DeviceConfig[i]); } } //enable or disable load_at_boot if ((DeviceConfig[12] & 0x10) == 0x10) { eeprom_update_byte((uint8_t*)EEPROM_BOOT_VALUES, 0x10); } else { eeprom_update_byte((uint8_t*)EEPROM_BOOT_VALUES, 0x00); } return; }
void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ USB_Init(); // http://avrbeginners.net/architecture/spi/spi.html SPI_Init(SPI_SPEED_FCPU_DIV_32 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_LEADING | SPI_ORDER_MSB_FIRST | SPI_MODE_MASTER); //initialize TWI-Bus TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000)); //check wether to load data at boot and do it if (eeprom_read_byte((uint8_t*)EEPROM_BOOT_VALUES) == 0x10 ) { for (int i = 0; i < ConfigSize; i++) { uint8_t eeprom_addr = EEPROM_CONFIG_OFFSET + i; DeviceConfig[i] = eeprom_read_byte((uint8_t*)eeprom_addr); } Output_data(); } }
//**************************************************************************** // Core() IS THE MAIN EXECUTION LOOP FUNCTION. // THE ONE AND ONLY BLOCKING CALL IN HERE SHALL BE THE StartReading function. //**************************************************************************** void MAPShokuyo::Core() { //There are no inputs to read from in this component. //Make sure you have one and only blocking function (Rest, Wait, MAPS::Sleep, select, whatever...) //inside Core(). // Start of user code Core processing with no inputs // Wait4Event(isDyingEvent); //Pause the current thread until shutdown. Output_data(MAPS::CurrentTime()) ; Rest(500000); // End of user code }