Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic18Device::write_config_memory ( DataBuffer buf,
unsigned long  addr,
bool  verify 
) [protected, virtual]

Writes the configuration words

Parameters:
buf The DataBuffer from which data is read.
addr The byte address of the configuration words in the PIC address space.
verify A boolean value indicating if the written data should be read back and verified.
Postcondition:
The progress_count is incremented by the number of configuration words written. 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.
Exceptions:
runtime_error Contains a description of the error along with the configuration word number where the error occurred.

Definition at line 304 of file Pic18Device.cxx.

References COMMAND_CORE_INSTRUCTION, COMMAND_TABLE_WRITE_START, program_wait(), Device::progress(), Device::progress_count, read_config_memory(), set_tblptr(), THROW_ERROR, and write_command().

Referenced by program().

               {
      int i;

      i = 0;
      try {
            /* Step 1: Direct access to config memory */
            /* BSF EECON1, EEPGD */
            write_command(COMMAND_CORE_INSTRUCTION, 0x8ea6);
            /* BSF EECON1, CFGS */
            write_command(COMMAND_CORE_INSTRUCTION, 0x8ca6);

            /* Step 2: Position the program counter */
            /* GOTO 100000h */
            write_command(COMMAND_CORE_INSTRUCTION, 0xef00);
            write_command(COMMAND_CORE_INSTRUCTION, 0xf800);

            for(i=0; i<7; i++) {
                  /* Give byte addresses to the callback to match datasheet. */
                  progress(addr);

                  /* Step 3: Set Table Pointer for config byte to be written. Write
                   * even/odd addresses */
                  set_tblptr(addr);
                  write_command(COMMAND_TABLE_WRITE_START, buf[(addr/2)] & 0xff);
                  program_wait();

                  write_command(COMMAND_CORE_INSTRUCTION, 0x2af6); /* INCF TBLPTR */
                  write_command(COMMAND_TABLE_WRITE_START, buf[(addr/2)] & 0xff00);
                  program_wait();

                  this->progress_count++;
                  if(verify) {
                        /* Verify the config word just written */
                        read_config_memory(buf, addr, 1, true);
                  }
                  addr += 2;
            }
      } catch(std::exception& e) {
            THROW_ERROR(runtime_error,
              "Couldn't write configuration word #%d", i);
      }
}


Generated by  Doxygen 1.6.0   Back to index