Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic18Device::read_data_memory ( DataBuffer buf,
unsigned long  addr,
bool  verify 
) [protected, virtual]

Reads the entire PIC data EEPROM. The bytes are packed into the DataBuffer as 1 byte per 16-bit word.

buf The DataBuffer to store the read data. On a verify, this data is compared with the data on the PIC.
addr The byte address in the DataBuffer to store the EEPROM data. Since the DataBuffer consists of 16-bit words, the DataBuffer offset will be 1/2 this.
verify Boolean flag which indicates a verify operation against buf.
The progress_count is incremented by the number of bytes read/verified from the data memory.
runtime_error Contains a description of the error along with the data memory location at which the error occured.

Definition at line 415 of file Pic18Device.cxx.

References COMMAND_CORE_INSTRUCTION, COMMAND_SHIFT_OUT_TABLAT, PicDevice::eesize, Device::progress(), Device::progress_count, THROW_ERROR, write_command(), and write_command_read_data().

Referenced by read().

      uint32_t ins;
      unsigned int offset, data;

      offset = 0;
      try {
            /* Direct address to data EEPROM */
            write_command(COMMAND_CORE_INSTRUCTION, 0x9ea6);/* bcf EECON1, EEPGD */
            write_command(COMMAND_CORE_INSTRUCTION, 0x9ca6);/* bcf EECON1, CPGS */

            for(offset=0; offset<this->eesize; offset++) {
                  /* Give byte addresses to progress() to match datasheet. */

                  /* Set the data EEPROM address pointer */
                  ins = 0x0e00 | (offset & 0xff);                       /* movlw <addr> */
                  write_command(COMMAND_CORE_INSTRUCTION, ins);
                  write_command(COMMAND_CORE_INSTRUCTION, 0x6ea9);/* movwf EEADR */

                  /* Initiate a memory read */
                  /* bsf EECON1, RD */
                  write_command(COMMAND_CORE_INSTRUCTION, 0x80a6);

                  /* Load data into the serial data holding register */
                  /* movf EEDATA, W, 0 */
                  write_command(COMMAND_CORE_INSTRUCTION, 0x50a8);
                  /* movwf TABLAT */
                  write_command(COMMAND_CORE_INSTRUCTION, 0x6ef5);

                  /* Shift out data */
                  data = write_command_read_data(COMMAND_SHIFT_OUT_TABLAT);
                  if(verify) {
                        if(data != (buf[(addr/2)+offset] & 0xff))
                              throw runtime_error("");
                  } else {
                        buf[(addr/2)+offset] = data;
      } catch(std::exception& e) {
            THROW_ERROR(runtime_error, "%s at location %d",
              verify ? "Data memory verification failed" :
              "Couldn't read data memory", offset);

Generated by  Doxygen 1.6.0   Back to index