/** * @brief Write data to persistence storage * * @param[in] start_addr Start address offset within EEPROM * @param[in] length Number of bytes to be written to EEPROM * @param[in] value Data to persistence storage * * @return MAC_SUCCESS if everything went OK else FAILURE */ retval_t pal_ps_set(uint16_t start_addr, uint16_t length, void *value) { uint8_t *data_ptr; uint16_t i; uint8_t read_data; if ((start_addr + length) > (E2END + 1)) { return FAILURE; } data_ptr = (uint8_t *)(value); for (i = 0; i < length; i++) { EEGET(read_data, start_addr); if (read_data != *data_ptr) { EEPUT(start_addr, *data_ptr); } data_ptr++; start_addr++; } return MAC_SUCCESS; }
bool eep_write(eep_address_t eeprom_address, const uint8_t *data_buffer_ptr, eep_length_t length) { /* Perform sanity checks. */ if (EEP_SOURCE_UNSUPPORTED == eep_source) { return false; } if (NULL == data_buffer_ptr) { return false; } if (0 == length) { return false; } if (EEP_SOURCE_EXTERNAL == eep_source) { return at24cxx_write_continuous(eeprom_address, length, data_buffer_ptr); } else { do { EEPUT(eeprom_address, *data_buffer_ptr); data_buffer_ptr++; eeprom_address++; length--; } while (0 != length); return true; } }
void main(void) { #else int main(void) { #endif /* Ensure that the watchdog is not running. */ wdt_disable(); /* Initialize AVR peripheral modules. */ (bool)avr_init(); /* Check if the RX and TX pins are shorted. If they are shorted, the RZUSBSTICK * shall start the bootloader. If not, continue to verify if the application * requested to enter the bootloader. */ /* Check if the application has requested to enter the bootloader. */ if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) { /* Check that RX goes high when TX is pulled high. */ BOOT_PORT |= (1 << BOOT_TX); nop(); nop(); nop(); nop(); if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) { start_application(); } } else { /* Check if the application has requested to enter the bootloader. */ uint8_t volatile magic_value = 0xAA; EEGET(magic_value, EE_BOOT_MAGIC_ADR); if (EE_BOOT_MAGIC_VALUE != magic_value) { start_application(); } else { EEPUT(EE_BOOT_MAGIC_ADR, 0xFF); } } /* Set the interrupt vectors to the bootloader, initialize the LEDs and the * VRT kernel. */ ENTER_CRITICAL_REGION(); uint8_t temp_mcucr = MCUCR; MCUCR = (1 << IVCE); MCUCR = (1 << IVSEL); MCUCR = temp_mcucr; LEAVE_CRITICAL_REGION(); LED_INIT(); vrt_init(); if (true != eep_init()) { error_handler(); } else if (true != cmd_if_init()) { error_handler(); } LED_ORANGE_ON(); /* Enable Interrupts. */ sei(); /* Enter the endless application loop. */ for (;;) { vrt_dispatch_event(); usb_task(); } }