Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic16Device::program ( DataBuffer buf  )  [virtual, inherited]

Program the contents of the DataBuffer to the device. This performs no erasure or blank check.

Parameters:
buf The DataBuffer containing the data to program.
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 152 of file Pic16Device.cxx.

References PicDevice::codesize, PicDevice::COMMAND_INC_ADDRESS, PicDevice::COMMAND_LOAD_CONFIG, PicDevice::eesize, PicDevice::flags, Device::io, PicDevice::memtype, Pic16Device::persistent_config_mask, PIC_FEATURE_BKBUG, PIC_FEATURE_EEPROM, PicDevice::pic_off(), Pic16Device::program_one_location(), Device::progress(), Device::progress_count, Device::progress_total, Pic16Device::read_config_word(), PicDevice::set_program_mode(), IO::shift_bits_out(), IO::usleep(), PicDevice::write_command(), Pic16Device::write_config_word(), Pic16Device::write_data_memory(), Pic16Device::write_id_memory(), and Pic16Device::write_program_memory().

                                         {
      uint32_t data;

      switch(this->memtype) {
      case MEMTYPE_EPROM:
      case MEMTYPE_FLASH:
            break;
      default:
            throw runtime_error("Unsupported memory type in device");
      }

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

      try {
            this->set_program_mode();

            /* Write the program memory */
            this->write_program_memory(buf);

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

            /* Write the ID locations */
            this->write_command(COMMAND_LOAD_CONFIG);
            this->io->shift_bits_out(0x7ffe, 16, 1);
            this->io->usleep(1);
            this->write_id_memory(buf, 0x2000);

            /* Write the debugger interrupt location if this PIC has one */
            if(this->flags & PIC_FEATURE_BKBUG) {
                  if(!program_one_location((uint32_t)buf[0x2004]))
                        throw runtime_error("Couldn't write the debugger " \
                          "interrupt vector at address 0x2004.");
            }

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

            /* Program the config word, keeping the persistent bits. */
            progress(0x2007);
            data = buf[0x2007] & ~this->persistent_config_mask;
            data |= (read_config_word() & this->persistent_config_mask);
            this->write_config_word(data);
            this->progress_count++;

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


Generated by  Doxygen 1.6.0   Back to index