LCOV - code coverage report
Current view: top level - backend/devices/parallel - eeprom.cpp (source / functions) Hit Total Coverage
Test: "6f9243f" Lines: 64 72 88.9 %
Date: 2024-02-24 14:58:06 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // ---------------------------------------------------------------------------
       2             : // USB EPROM/Flash Programmer
       3             : //
       4             : // Copyright (2024) Robson Martins
       5             : //
       6             : // This work is licensed under a Creative Commons Attribution-NonCommercial-
       7             : // ShareAlike 4.0 International License.
       8             : // ---------------------------------------------------------------------------
       9             : /**
      10             :  * @ingroup Software
      11             :  * @file backend/devices/parallel/eeprom.cpp
      12             :  * @brief Implementation of the Parallel EEPROM.
      13             :  *
      14             :  * @author Robson Martins (https://www.robsonmartins.com)
      15             :  */
      16             : // ---------------------------------------------------------------------------
      17             : 
      18             : #include <QLoggingCategory>
      19             : #include "eeprom.hpp"
      20             : 
      21             : // ---------------------------------------------------------------------------
      22             : // Logging
      23             : 
      24          70 : Q_LOGGING_CATEGORY(deviceParEEprom, "device.parallel.eeprom")
      25             : 
      26             : #define DEBUG qCDebug(deviceParEEprom)
      27             : #define INFO qCInfo(deviceParEEprom)
      28             : #define WARNING qCWarning(deviceParEEprom)
      29             : #define CRITICAL qCCritical(deviceParEEprom)
      30             : #define FATAL qCFatal(deviceParEEprom)
      31             : 
      32             : // ---------------------------------------------------------------------------
      33             : 
      34           2 : EEPROM::EEPROM(QObject *parent) : ParDevice(parent) {
      35           2 :     info_.name = "EEPROM";
      36           2 :     info_.capability.hasRead = true;
      37           2 :     info_.capability.hasProgram = true;
      38           2 :     info_.capability.hasVerify = true;
      39           2 :     info_.capability.hasBlankCheck = true;
      40           2 :     info_.capability.hasVDD = true;
      41           2 :     info_.capability.hasErase = true;
      42           2 :     vddRd_ = 5.0f;
      43           2 :     vddWr_ = 5.0f;
      44           2 :     vpp_ = 12.0f;
      45           2 :     vee_ = 12.0f;
      46           2 :     size_ = 2048;
      47           2 :     twp_ = 2;
      48           2 :     twc_ = 10000;
      49           2 :     algo_ = kCmdDeviceAlgorithmEEPROM28C64;
      50           2 :     maxAttemptsProg_ = 3;
      51           4 :     DEBUG << info_.toString();
      52           2 : }
      53             : 
      54           2 : EEPROM::~EEPROM() {}
      55             : 
      56           6 : void EEPROM::setSize(uint32_t value) {
      57           6 :     ParDevice::setSize(value);
      58           6 :     algo_ = (size_ <= 0x2000) ? kCmdDeviceAlgorithmEEPROM28C64
      59             :                               : kCmdDeviceAlgorithmEEPROM28C256;
      60           6 :     bool oldValue = info_.capability.hasUnprotect;
      61           6 :     bool newValue = (size_ >= 0x2000);  // >= 8KB
      62           6 :     if (oldValue != newValue) {
      63           2 :         info_.capability.hasUnprotect = newValue;
      64           2 :         info_.capability.hasProtect = newValue;
      65           4 :         DEBUG << info_.toString();
      66             :     }
      67           6 : }
      68             : 
      69          14 : bool EEPROM::eraseDevice() {
      70          28 :     DEBUG << "Erasing data...";
      71             :     // Create a blank (0xFF) buffer
      72          14 :     QByteArray data = QByteArray(size_, (char)0xFF);
      73          14 :     if (!programDevice(data)) {
      74           0 :         WARNING << "Erase error";
      75           0 :         return false;
      76             :     }
      77          28 :     DEBUG << "Erase OK";
      78          14 :     return true;
      79          14 : }
      80             : 
      81             : // ---------------------------------------------------------------------------
      82             : 
      83           1 : EEPROM28C::EEPROM28C(QObject *parent) : EEPROM(parent) {
      84           1 :     info_.name = "EEPROM 28C/X28";
      85           2 :     DEBUG << info_.toString();
      86           1 : }
      87             : 
      88           2 : EEPROM28C::~EEPROM28C() {}
      89             : 
      90             : // ---------------------------------------------------------------------------
      91             : 
      92           1 : EEPROM28AT::EEPROM28AT(QObject *parent) : EEPROM(parent) {
      93           1 :     info_.name = "EEPROM AT28C";
      94           2 :     DEBUG << info_.toString();
      95           1 : }
      96             : 
      97           2 : EEPROM28AT::~EEPROM28AT() {}
      98             : 
      99           3 : void EEPROM28AT::setSize(uint32_t value) {
     100           3 :     EEPROM::setSize(value);
     101           3 :     switch (size_) {
     102           2 :         case 0x02000:  //   8KB
     103             :         case 0x04000:  //  16KB
     104             :         case 0x08000:  //  32KB
     105           2 :             sectorSize_ = 64;
     106           2 :             break;
     107           0 :         case 0x10000:  //  64KB
     108             :         case 0x20000:  // 128KB
     109           0 :             sectorSize_ = 128;
     110           0 :             break;
     111           0 :         case 0x40000:  // 256KB
     112           0 :             sectorSize_ = 256;
     113           0 :             break;
     114           1 :         default:
     115           1 :             if (size_ < 0x02000) sectorSize_ = 0;
     116           1 :             if (size_ > 0x40000) sectorSize_ = 256;
     117           1 :             break;
     118             :     }
     119           3 :     bool oldValue = info_.capability.hasSectorSize;
     120           3 :     bool newValue = (size_ >= 0x2000);  // >= 8KB
     121           3 :     if (oldValue != newValue) {
     122           1 :         info_.capability.hasSectorSize = newValue;
     123           2 :         DEBUG << info_.toString();
     124             :     }
     125           3 : }

Generated by: LCOV version 1.14