Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic16Device::read ( DataBuffer buf,
bool  verify = false 
) [virtual, inherited]

Read the contents of a device into the DataBuffer.

Parameters:
buf The DataBuffer to store the read data.
verify If this flag is true, don't store the data in the DataBuffer but verify the contents of it.
Precondition:
set_iodevice() must have been called with a valid IO object.
Exceptions:
runtime_error Contains a textual description of the error.

Implements Device.

Definition at line 208 of file Pic16Device.cxx.

References PicDevice::codesize, PicDevice::COMMAND_INC_ADDRESS, PicDevice::COMMAND_LOAD_CONFIG, PicDevice::eesize, PicDevice::flags, Device::io, PIC_FEATURE_BKBUG, PIC_FEATURE_EEPROM, PicDevice::pic_off(), Device::progress(), Device::progress_count, Device::progress_total, Pic16Device::read_config_word(), Pic16Device::read_data_memory(), Pic16Device::read_id_memory(), PicDevice::read_prog_data(), Pic16Device::read_program_memory(), PicDevice::set_program_mode(), IO::shift_bits_out(), IO::usleep(), and PicDevice::write_command().

                                                   {
      this->progress_total = this->codesize + this->eesize + 4;
      this->progress_count = 0;

      try {
            this->set_program_mode();

            /* Read the program memory */
            this->read_program_memory(buf, 0, verify);

            /* Read the data EEPROM if this PIC has one */
            if(this->flags & PIC_FEATURE_EEPROM)
                  this->read_data_memory(buf, 0x2100, verify);

            /* Read the ID locations */
            this->write_command(COMMAND_LOAD_CONFIG);
            this->io->shift_bits_out(0x7ffe, 16, 1);  /* Dummy write of all 1's */
            this->io->usleep(1);
            this->read_id_memory(buf, 0x2000, verify);

            /* Read the debugger interrupt location if this PIC has one */
            if(this->flags & PIC_FEATURE_BKBUG) {
                  if(verify) {
                        if((uint32_t)buf[0x2004] != this->read_prog_data())
                              throw runtime_error("Verification failed at address 0x2004");
                  } else {
                        buf[0x2004] = this->read_prog_data();
                  }
            }

            /* Skip past the next 3 addresses */
            for(int i=4; i < 7; i++)
                  this->write_command(COMMAND_INC_ADDRESS);

            progress(0x2007);
            if(verify) {
                  this->read_config_word(true, buf[0x2007]);
            } else {
                  buf[0x2007] = this->read_config_word();
            }
            this->progress_count++;

            this->pic_off();
      } catch(std::exception& e) {
            this->pic_off();
            throw;
      }
}


Generated by  Doxygen 1.6.0   Back to index