Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic16f87xADevice::write_program_memory ( DataBuffer buf,
long  base = 0 
) [protected, virtual]

Program the entire contents of program memory to the PIC device.

Parameters:
buf A DataBuffer containing the data to program.
base The offset within the data buffer to start retrieving data. If this parameter isn't specified, it defaults to 0.
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.

Reimplemented from Pic16Device.

Definition at line 62 of file Pic16f87xADevice.cxx.

References PicDevice::codesize, PicDevice::COMMAND_BEGIN_PROG, COMMAND_END_PROG, PicDevice::COMMAND_INC_ADDRESS, PicDevice::flags, Device::io, PIC_REQUIRE_EPROG, PicDevice::program_time, Device::progress(), Device::progress_count, THROW_ERROR, IO::usleep(), PicDevice::write_command(), and PicDevice::write_prog_data().

                                                                      {
      unsigned int offset;

      if((base % 8) != 0) {
            THROW_ERROR(runtime_error,
              "Base address doesn't fall on 3-bit boundary, 0x%04lx", base);
      }

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

                  this->write_prog_data((uint32_t)buf[base+offset]);
                  /* 8 words loaded, now program it. */
                  if(((offset+base) % 8) == 7) {
                        this->write_command(COMMAND_BEGIN_PROG);
                        this->io->usleep(this->program_time);
                        if(this->flags & PIC_REQUIRE_EPROG)
                              this->write_command(COMMAND_END_PROG);
                  }

                  this->write_command(COMMAND_INC_ADDRESS);
                  this->progress_count++;
            }
            if(offset < this->codesize) throw runtime_error("");
      } catch(std::exception& e) {
            THROW_ERROR(runtime_error,
              "Couldn't write program memory at address 0x%04lx", base+offset);
      }
}


Generated by  Doxygen 1.6.0   Back to index