Logo Search packages:      
Sourcecode: odyssey version File versions

void Pic16f6xxDevice::bulk_erase ( void   )  [protected, virtual]

Bulk erase the program and data memory of a flash device.

Precondition:
The device has flash memory.

Code protection on the device is verified to be completely off.

The device is turned completely off.

Postcondition:
The device is turned completely off.
Exceptions:
runtime_error Contains a description of the error.

Reimplemented from Pic16Device.

Definition at line 35 of file Pic16f6xx.cxx.

References PicDevice::COMMAND_BEGIN_PROG, PicDevice::COMMAND_ERASE_DATA_MEM, PicDevice::COMMAND_ERASE_PROG_MEM, PicDevice::COMMAND_INC_ADDRESS, PicDevice::COMMAND_LOAD_CONFIG, PicDevice::erase_time, PicDevice::flags, Device::io, PIC_FEATURE_EEPROM, PicDevice::pic_off(), PicDevice::program_time, PicDevice::set_program_mode(), IO::shift_bits_out(), IO::usleep(), PicDevice::write_command(), Pic16Device::write_ee_data(), and PicDevice::write_prog_data().

Referenced by disable_codeprotect().

                                     {
      try {
            this->set_program_mode();

            /* This clears the config word. XXX: TESTME */
            this->write_command(COMMAND_LOAD_CONFIG);
            this->io->shift_bits_out(0x7ffe, 16, 1);
            this->io->usleep(1);
            for(int i=0; i<7; i++)
                  this->write_command(COMMAND_INC_ADDRESS);
            this->write_command(0x01);    /* Bulk Erase Setup1 */
            this->write_command(0x07);    /* Bulk Erase Setup2 */
            this->write_command(COMMAND_BEGIN_PROG);
            this->io->usleep(this->erase_time + this->program_time);
            this->write_command(0x01);
            this->write_command(0x07);

            /* This should erase the ID & program memory */
            this->write_prog_data(0x3fff);
            this->write_command(COMMAND_ERASE_PROG_MEM);
            this->write_command(COMMAND_BEGIN_PROG);
            this->io->usleep(this->erase_time);

            if(this->flags & PIC_FEATURE_EEPROM) {
                  /* This clears the data EEPROM */
                  this->write_ee_data(0x3fff);
                  this->write_command(COMMAND_ERASE_DATA_MEM);
                  this->write_command(COMMAND_BEGIN_PROG);
                  this->io->usleep(this->erase_time);
            }

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


Generated by  Doxygen 1.6.0   Back to index