uint64_t eep_read_ieee_address(void) { /* Union used to convert from byte read EEPROM address to number. */ union { uint64_t nmbr; uint8_t array[sizeof(uint64_t)]; } address_conv; address_conv.nmbr = 0; if (EEP_SOURCE_EXTERNAL == eep_source) { (bool)at24cxx_read_byte(EE_MAC_ADR + 0, &(address_conv.array[7])); (bool)at24cxx_read_byte(EE_MAC_ADR + 1, &(address_conv.array[6])); (bool)at24cxx_read_byte(EE_MAC_ADR + 2, &(address_conv.array[5])); (bool)at24cxx_read_byte(EE_MAC_ADR + 3, &(address_conv.array[4])); (bool)at24cxx_read_byte(EE_MAC_ADR + 4, &(address_conv.array[3])); (bool)at24cxx_read_byte(EE_MAC_ADR + 5, &(address_conv.array[2])); (bool)at24cxx_read_byte(EE_MAC_ADR + 6, &(address_conv.array[1])); (bool)at24cxx_read_byte(EE_MAC_ADR + 7, &(address_conv.array[0])); } else if (EEP_SOURCE_INTERNAL == eep_source) { EEGET((address_conv.array[7]), EE_MAC_ADR + 0); EEGET((address_conv.array[6]), EE_MAC_ADR + 1); EEGET((address_conv.array[5]), EE_MAC_ADR + 2); EEGET((address_conv.array[4]), EE_MAC_ADR + 3); EEGET((address_conv.array[3]), EE_MAC_ADR + 4); EEGET((address_conv.array[2]), EE_MAC_ADR + 5); EEGET((address_conv.array[1]), EE_MAC_ADR + 6); EEGET((address_conv.array[0]), EE_MAC_ADR + 7); } else { /* Function has been called without one of the supported EEPROM locations * being valid. */ } return address_conv.nmbr; }
/** * @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; }
/** * @brief Get data from persistence storage * * @param[in] ps_type Persistence storage type * @param[in] start_addr Start offset within EEPROM * @param[in] length Number of bytes to read from EEPROM * @param[out] value Data from persistence storage * * @return MAC_SUCCESS if everything went OK else FAILURE */ retval_t pal_ps_get(ps_type_t ps_type, uint16_t start_addr, uint16_t length, void *value) { #if (EXTERN_EEPROM_AVAILABLE == 1) if (ps_type == EXTERN_EEPROM) { return extern_eeprom_get(start_addr, length, value); } else #endif if (ps_type == INTERN_EEPROM) { uint16_t index; uint8_t *data_ptr; if ((start_addr + length) > (E2END + 1)) { return FAILURE; } data_ptr = (uint8_t *)(value); for (index = 0; index < length; index++) { EEGET(*data_ptr, start_addr); start_addr++; data_ptr++; } } else // no internal eeprom and no external eeprom available { return MAC_INVALID_PARAMETER; } return MAC_SUCCESS; }
bool eep_init(void) { /* Initialize the external TWI EEPROM, and see if it is possible to read-back * the magic. */ if(true != at24cxx_init()) { at24cxx_deinit(); return false; } /* Read internal and external EEPROM magic. */ uint8_t int_magic = 0xFF; EEGET(int_magic, EE_MAGIC_ADR); uint8_t ext_magic = 0xFF; (bool)at24cxx_read_byte(EE_MAGIC_ADR, &ext_magic); bool init_status = false; if (EE_MAGIC == ext_magic) { eep_source = EEP_SOURCE_EXTERNAL; init_status = true; } else if (EE_MAGIC == int_magic) { /* Save power by turning the TWI module off. */ at24cxx_deinit(); eep_source = EEP_SOURCE_INTERNAL; init_status = true; } else { /* Save power by turning the TWI module off. */ at24cxx_deinit(); /* No magic found. The init failed. */ eep_source = EEP_SOURCE_UNSUPPORTED; } return init_status; }
uint16_t eep_read_1v1(void) { /* Union used to convert from byte read EEPROM address to number. */ union { uint16_t nmbr; uint8_t array[sizeof(uint16_t)]; } v_conv; v_conv.nmbr = 0; if (EEP_SOURCE_EXTERNAL == eep_source) { (bool)at24cxx_read_byte(EE_1V1_CAL_VALUE_ADR + 1, &(v_conv.array[0])); (bool)at24cxx_read_byte(EE_1V1_CAL_VALUE_ADR + 0, &(v_conv.array[1])); } else if (EEP_SOURCE_INTERNAL == eep_source) { EEGET((v_conv.array[0]), EE_1V1_CAL_VALUE_ADR + 1); EEGET((v_conv.array[1]), EE_1V1_CAL_VALUE_ADR + 0); } else { /* Function has been called without one of the supported EEPROM locations * being valid. */ } return v_conv.nmbr; }
uint8_t eep_read_production_day(void) { uint8_t prod_day = 0xFF; if (EEP_SOURCE_EXTERNAL == eep_source) { (bool)at24cxx_read_byte(EE_PRODDAY_ADR, &prod_day); } else if (EEP_SOURCE_INTERNAL == eep_source) { EEGET(prod_day, EE_PRODDAY_ADR); } else { /* Function has been called without one of the supported EEPROM locations * being valid. */ } return prod_day; }
uint8_t eep_read_hw_revision(void) { uint8_t hw_rev = 0xFF; if (EEP_SOURCE_EXTERNAL == eep_source) { (bool)at24cxx_read_byte(EE_HWREV_ADR, &hw_rev); } else if (EEP_SOURCE_INTERNAL == eep_source) { EEGET(hw_rev, EE_HWREV_ADR); } else { /* Function has been called without one of the supported EEPROM locations * being valid. */ } return hw_rev; }
uint8_t eep_read_cap_array(void) { uint8_t cap_array_setting = 0xFF; if (EEP_SOURCE_EXTERNAL == eep_source) { (bool)at24cxx_read_byte(EE_CAPARRAY_ADR, &cap_array_setting); } else if (EEP_SOURCE_INTERNAL == eep_source) { EEGET(cap_array_setting, EE_CAPARRAY_ADR); } else { /* Function has been called without one of the supported EEPROM locations * being valid. */ } return cap_array_setting; }
bool eep_read(eep_address_t eeprom_address, 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_read_continuous(eeprom_address, length, data_buffer_ptr); } else { do { EEGET(*data_buffer_ptr, eeprom_address); 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(); } }