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

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.
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.
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. */

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

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

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

Generated by  Doxygen 1.6.0   Back to index