LCOV - code coverage report
Current view: top level - backend/devices/parallel - sram.cpp (source / functions) Hit Total Coverage
Test: "6f9243f" Lines: 45 47 95.7 %
Date: 2024-02-24 14:58:06 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // ---------------------------------------------------------------------------
       2             : // USB EPROM/Flash Programmer
       3             : //
       4             : // Copyright (2023) 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/sram.cpp
      12             :  * @brief Implementation of a Parallel SRAM.
      13             :  *
      14             :  * @author Robson Martins (https://www.robsonmartins.com)
      15             :  */
      16             : // ---------------------------------------------------------------------------
      17             : 
      18             : #include <QByteArray>
      19             : #include <QRandomGenerator>
      20             : #include <QLoggingCategory>
      21             : 
      22             : #include "sram.hpp"
      23             : 
      24             : // ---------------------------------------------------------------------------
      25             : // Logging
      26             : 
      27          18 : Q_LOGGING_CATEGORY(deviceParSram, "device.parallel.sram")
      28             : 
      29             : #define DEBUG qCDebug(deviceParSram)
      30             : #define INFO qCInfo(deviceParSram)
      31             : #define WARNING qCWarning(deviceParSram)
      32             : #define CRITICAL qCCritical(deviceParSram)
      33             : #define FATAL qCFatal(deviceParSram)
      34             : 
      35             : // ---------------------------------------------------------------------------
      36             : 
      37           1 : SRAM::SRAM(QObject *parent) : ParDevice(parent) {
      38           1 :     info_.name = "SRAM";
      39           1 :     info_.capability.hasProgram = true;
      40           1 :     info_.capability.hasVDD = true;
      41           1 :     twp_ = 1;
      42           1 :     twc_ = 1;
      43           1 :     vddRd_ = 5.0f;
      44           1 :     vddWr_ = 5.0f;
      45           1 :     size_ = 2048;
      46           1 :     algo_ = kCmdDeviceAlgorithmSRAM;
      47           2 :     DEBUG << info_.toString();
      48           1 : }
      49             : 
      50           2 : SRAM::~SRAM() {}
      51             : 
      52           4 : bool SRAM::program(const QByteArray &buffer, bool verify) {
      53             :     (void)buffer;
      54             :     (void)verify;
      55           8 :     INFO << "Testing device...";
      56           4 :     canceling_ = false;
      57           4 :     uint32_t current = 0, total = size_;
      58           4 :     if (!initDevice(kDeviceOpRead)) {
      59           2 :         WARNING << "Error testing device";
      60           1 :         return false;
      61             :     }
      62           3 :     bool error = false;
      63           3 :     if (!doPatternTest_() || !doRandomTest_()) error = true;
      64           3 :     if (!error && runner_.hasError()) {
      65           0 :         return finalizeDevice(total, total, true, false);
      66             :     }
      67           3 :     if (!error) emit onProgress(total, total, true);
      68           3 :     finalizeDevice();
      69           3 :     if (error) {
      70           0 :         WARNING << "Error testing device";
      71             :     } else {
      72           6 :         INFO << "Testing device OK";
      73             :     }
      74           3 :     return !error;
      75             : }
      76             : 
      77           3 : bool SRAM::doPatternTest_() {
      78           3 :     QByteArray buffer = generatePatternData_();
      79           3 :     runner_.addrClr();
      80           3 :     if (!programDevice(buffer)) return false;
      81           3 :     runner_.addrClr();
      82           3 :     if (!verifyDevice(buffer)) return false;
      83           3 :     return !runner_.hasError();
      84           3 : }
      85             : 
      86           3 : bool SRAM::doRandomTest_() {
      87           3 :     QByteArray buffer = generateRandomData_();
      88           3 :     runner_.addrClr();
      89           3 :     if (!programDevice(buffer)) return false;
      90           3 :     runner_.addrClr();
      91           3 :     if (!verifyDevice(buffer)) return false;
      92           3 :     return !runner_.hasError();
      93           3 : }

Generated by: LCOV version 1.14