Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic16Device::read_program_memory ( DataBuffer buf,
long  base = 0,
bool  verify = false 
) [protected, virtual, inherited]

Read the entire contents of program memory from the PIC device.

Parameters:
buf A DataBuffer in which to store the read data.
base The offset within the data buffer to start storing data. If this parameter isn't specified, it defaults to 0.
verify If this flag is true, don't store the data in the DataBuffer but verify the contents of it.
Precondition:
The PIC should have it's program counter set to the beginning of program memory.
Postcondition:
The program counter is pointing to the address immediatly after the last program memory address.
Exceptions:
runtime_error Contains a description of the error along with the address at which the error occurred.

Definition at line 328 of file Pic16Device.cxx.

References PicDevice::codesize, PicDevice::COMMAND_INC_ADDRESS, PicDevice::flags, PIC_HAS_OSCAL, Device::progress(), Device::progress_count, PicDevice::read_prog_data(), THROW_ERROR, and PicDevice::write_command().

Referenced by Pic16Device::read().

                                                                             {
      unsigned int offset;

      try {
            for(offset=0; offset < this->codesize; offset++) {
                  progress(base+offset);

                  if(verify) {
                        /* Don't verify the OSCAL location. */
                        if(! ((this->flags & PIC_HAS_OSCAL) &&
                          (offset == this->codesize-1))) {
                              if((uint32_t)buf[base+offset] != this->read_prog_data())
                                    throw runtime_error("");
                        }
                  } else {
                        buf[base+offset] = this->read_prog_data();
                  }
                  this->write_command(COMMAND_INC_ADDRESS);
                  this->progress_count++;
            }
      } catch(std::exception& e) {
            THROW_ERROR(runtime_error, "%s at address 0x%04lx",
              verify ? "Verification failed" : "Couldn't read program memory",
              base+offset);
      }
}


Generated by  Doxygen 1.6.0   Back to index