// This file has been prepared for Doxygen automatic documentation generation. /*! \file ******************************************************************** * * Atmel Corporation * * \li File: eeprom.c * \li Compiler: IAR EWAAVR 3.10c * \li Support mail: avr@atmel.com * * \li Supported devices: All devices with split EEPROM erase/write * capabilities can be used. * The example is written for ATmega48. * * \li AppNote: AVR103 - Using the EEPROM Programming Modes. * * \li Description: Example on how to use the split EEPROM erase/write * capabilities in e.g. ATmega48. All EEPROM * programming modes are tested, i.e. Erase+Write, * Erase-only and Write-only. * * $Revision: 1.6 $ * $Date: Friday, February 11, 2005 07:16:44 UTC $ ****************************************************************************/ //#include //#include // ecmc added #include #include #include #define EEPROM_DUMMY_FILE "./ecmc_grbl_eeprom.txt" #define EEPROM_MEM_SIZE 1024 char buffer[EEPROM_MEM_SIZE]; /* These EEPROM bits have different names on different devices. */ //#ifndef EEPE // #define EEPE EEWE //!< EEPROM program/write enable. // #define EEMPE EEMWE //!< EEPROM master program/write enable. //#endif /* These two are unfortunately not defined in the device include files. */ //#define EEPM1 5 //!< EEPROM Programming Mode Bit 1. //#define EEPM0 4 //!< EEPROM Programming Mode Bit 0. /* Define to reduce code size. */ //#define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling. //unsigned char ecmc_mem_to_file(); // Init file void ecmc_init_file() { printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); memset(&buffer[0],0,EEPROM_MEM_SIZE); //ecmc_mem_to_file(); } // Read file to buffer[] //unsigned char ecmc_file_to_mem() //{ // //printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); // // FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd"); // // if (fh == NULL) // { // printf("something went wrong and file could not be opened"); // return 1; // } // unsigned char c = 0; // for (int i = 0; i < EEPROM_MEM_SIZE ; i++) { // // Get the characters // buffer[i] = fgetc(fh); // } // // fclose(fh); // return 0; //} // Write buffer[] to file //unsigned char ecmc_mem_to_file() //{ //// printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); // // FILE* fh = fopen(EEPROM_DUMMY_FILE, "w"); // // if (fh == NULL) // { // printf("something went wrong and file could not be opened"); // return 1; // } // for (int i = 0; i < EEPROM_MEM_SIZE ; i++) { // // Get the characters // fputc (buffer[i], fh); // } // // fclose(fh); // return 0; //} /*! \brief Read byte from EEPROM. * * This function reads one byte from a given EEPROM address. * * \note The CPU is halted for 4 clock cycles during EEPROM read. * * \param addr EEPROM address to read from. * \return The byte read from the EEPROM address. */ unsigned char eeprom_get_char( unsigned int addr ) { //ecmc_file_to_mem(); //printf("%s:%s:%d addr: %ud, value %d..\n",__FILE__,__FUNCTION__,__LINE__,addr,buffer[addr]); return buffer[addr]; //do {} while( EECR & (1< 0; size--) { checksum = (checksum << 1) || (checksum >> 7); checksum += *source; eeprom_put_char(destination++, *(source++)); } eeprom_put_char(destination, checksum); } int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) { printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); unsigned char data, checksum = 0; for(; size > 0; size--) { data = eeprom_get_char(source++); checksum = (checksum << 1) || (checksum >> 7); checksum += data; *(destination++) = data; } return(checksum == eeprom_get_char(source)); } // end of file