GCC Code Coverage Report


Directory: ./
File: firmware/libfirmware/pt2001/include/rusefi/pt2001.h
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 0.0% 0 0 8
Functions: 0.0% 0 0 3
Branches: -% 0 0 0
Decisions: -% 0 - 0

Line Branch Decision Exec Source
1 /*
2 * @file mc33816.h
3 *
4 * @date May 3, 2019
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8 #pragma once
9
10 #include <cstddef>
11 #include <cstdint>
12
13 #include "pt2001_memory_map.h"
14
15 void initMc33816();
16
17 enum class McFault : uint8_t
18 {
19 None = 0,
20 NoFlash = 1,
21 UnderVoltageAfter = 2,
22 NoComm = 3,
23 flag0 = 4,
24 UnderVoltage5 = 5,
25 Driven = 6,
26 UnderVoltage7 = 7,
27 };
28
29 const char * mcFaultToString(McFault fault);
30
31 class Pt2001Base {
32 public:
33 // Reinitialize the PT2001 chip, returns true if successful
34 bool restart();
35
36 // Disable the PT2001 chip.
37 void shutdown();
38
39 void onError(McFault p_fault) {
40 fault = p_fault;
41 }
42
43 private:
44 // method not public since does not acquire/release bus yet!
45 // Re-read timing configuration and reconfigure the chip. This is safe to call while operating.
46 void setTimings();
47
48 // method not public since does not acquire/release bus yet!
49 // Set the boost voltage target. This is safe to call while operating.
50 void setBoostVoltage(float volts);
51
52 public:
53 McFault fault = McFault::None;
54 uint16_t status = 0;
55
56 void periodicCallback();
57 uint16_t readStatus(int reg);
58
59 private:
60 // SPI tx/rx helpers
61 void send(uint16_t tx) {
62 sendRecv(tx);
63 }
64
65 uint16_t recv() {
66 return sendRecv(0xFFFF);
67 }
68
69 // Chip init logic
70 void setupSpi();
71 uint16_t readId();
72
73 void enableFlash();
74 bool checkFlash();
75
76 void downloadRam(int target);
77 void downloadRegister(int target);
78
79 // Chip IO helpers
80 uint16_t readDram(MC33816Mem addr);
81 void writeDram(MC33816Mem addr, uint16_t data);
82 uint16_t readDriverStatus();
83 void clearDriverStatus();
84
85 protected:
86 // The consuming app must implement these functions!
87 virtual void acquireBus() = 0;
88 virtual void select() = 0;
89 virtual void deselect() = 0;
90 virtual void releaseBus() = 0;
91 virtual uint16_t sendRecv(uint16_t tx) = 0;
92 // Send `count` number of 16 bit words from `data`
93 virtual void sendLarge(const uint16_t* data, size_t count) = 0;
94
95 // GPIO reset and enable pins
96 virtual void setResetB(bool state) = 0;
97 virtual void setDriveEN(bool state) = 0;
98
99 // GPIO inputs for various pins we need
100 virtual bool readFlag0() const = 0;
101
102 // Get battery voltage - only try to init chip when powered
103 virtual float getVbatt() const = 0;
104
105 // CONFIGURATIONS: currents, timings, voltages
106 virtual float getBoostVoltage() const = 0;
107
108 // Currents in amps
109 virtual float getBoostCurrent() const = 0;
110 virtual float getPeakCurrent() const = 0;
111 virtual float getHoldCurrent() const = 0;
112
113 virtual float getPumpPeakCurrent() const = 0;
114 virtual float getPumpHoldCurrent() const = 0;
115
116 // Timings in microseconds
117 virtual uint16_t getTpeakOff() const = 0;
118 virtual uint16_t getTpeakTot() const = 0;
119 virtual uint16_t getTbypass() const = 0;
120 virtual uint16_t getTholdOff() const = 0;
121 virtual uint16_t getTHoldTot() const = 0;
122 virtual uint16_t getTBoostMin() const = 0;
123 virtual uint16_t getTBoostMax() const = 0;
124
125 virtual uint16_t getPumpTholdOff() const = 0;
126 virtual uint16_t getPumpTholdTot() const = 0;
127
128 // Print out an error message
129 virtual void onError(const char* why) = 0;
130 // useful for poorly designed boards or when short of IO
131 virtual bool errorOnUnexpectedFlag() = 0;
132
133 // Sleep for some number of milliseconds
134 virtual void sleepMs(size_t ms) = 0;
135 };
136