Logo Search packages:      
Sourcecode: odyssey version File versions

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

Reads a portion of the PIC memory.

Parameters:
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 PIC's memory to begin the read. Since the PIC's memory is byte-oriented and the DataBuffer is 16-bit word oriented, the offset into the DataBuffer will be 1/2 the PIC memory address.
len The number of 16-bit words to read into the DataBuffer.
verify Boolean flag which indicates a verify operation against buf.
Postcondition:
The progress_count is incremented by the number of program memory words read/verified.
Exceptions:
runtime_error Contains a description of the error along with the address at which the error occurred.

Definition at line 349 of file Pic18Device.cxx.

References COMMAND_TABLE_READ_POSTINC, Device::progress(), Device::progress_count, set_tblptr(), THROW_ERROR, and write_command_read_data().

Referenced by read(), write_id_memory(), and write_program_memory().

                                  {
      unsigned int data;

      try {
            addr >>= 1;             /* Shift to word addresses */
            set_tblptr(2*addr);
            while(len > 0) {
                  /* Give byte addresses to progress() to match datasheet. */
                  progress(addr*2);

                  /* Read memory a byte at a time (little endian format) */
                  data = write_command_read_data(COMMAND_TABLE_READ_POSTINC);
                  data |= (write_command_read_data(COMMAND_TABLE_READ_POSTINC) << 8);
                  if(verify) {
                        if(data != buf[addr])
                              throw runtime_error("");
                  } else {
                        buf[addr] = data;
                  }
                  addr++;
                  len--;
                  this->progress_count++;
            }
      } catch(std::exception& e) {
            THROW_ERROR(runtime_error, "%s at address 0x%06lx",
              verify ? "Verification failed" : "Couldn't read memory",
              2*addr);
      }
}


Generated by  Doxygen 1.6.0   Back to index