Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic18Device::write_program_memory ( DataBuffer buf,
bool  verify 
) [protected, virtual]

Writes data to the program memory. The entire code space is written to take advantage of multi-panel writes.

buf The DataBuffer from which to retrieve the data to write.
verify A boolean value indicating if the written data should be read back and verified.
The progress_count is incremented by the number of words written to program memory. If verify is true then progress_count will have been incremented by two times the number of words written; once for the write and once for the verify.
runtime_error Contains a description of the error along with the address at which the error occurred.

Definition at line 135 of file Pic18Device.cxx.

References PicDevice::codesize, COMMAND_CORE_INSTRUCTION, COMMAND_TABLE_WRITE, load_write_buffer(), program_wait(), Device::progress(), read_memory(), set_tblptr(), THROW_ERROR, and write_command().

Referenced by program().

      unsigned int npanels, panel, offset;

      panel = 0;
      offset = 0;
      npanels = this->codesize/(PANELSIZE/2);
      try {
            /* Step 1: Enable multi-panel writes */
            write_command(COMMAND_TABLE_WRITE, 0x0040);

            /* Step 2: Direct access to code memory */
            /* BSF EECON1, EEPGD */
            write_command(COMMAND_CORE_INSTRUCTION, 0x8ea6);
            /* BCF EECON1, CFGS */
            write_command(COMMAND_CORE_INSTRUCTION, 0x9ca6);

            for(offset=0; offset < PANELSIZE; offset+=8) {
                  /* Step 3,4,5,6: Load write buffer for Panel 1,2,3,4 */
                  for(panel=0; panel<npanels-1; panel++) {
                        /* Give byte addresses to progress() to match datasheet. */
                        progress((panel << PANEL_SHIFT) + offset);
                        load_write_buffer(buf, panel, offset, false);
                  load_write_buffer(buf, panel, offset, true);


                  if(verify) {
                        /* Verify the memory just written */
                        for(unsigned int panel=0; panel<npanels; panel++) {
                              progress((panel << PANEL_SHIFT) + offset);
                              /* Verify the 4 words per panel */
                              read_memory(buf, (panel << PANEL_SHIFT) + offset, 4, true);
      } catch(std::exception& e) {
              "Couldn't write program memory at address 0x%06lx",
              (unsigned long)(panel << PANEL_SHIFT) + offset);

Generated by  Doxygen 1.6.0   Back to index