B15F Board 15 Famulus Edition

b15f.h
1 #ifndef B15F_H
2 #define B15F_H
3
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20
21 // wichtig für die Register-Zugriffe
22 #define _AVR_IO_H_ 1 // Erzwinge die Inklusion
23 #include "/usr/lib/avr/include/avr/sfr_defs.h"
24 #include "/usr/lib/avr/include/avr/iom1284p.h"
25
26 typedef std::function<void(std::exception&)> errorhandler_t;
27
28
31 class B15F
32 {
33 private:
34 // privater Konstruktor
35 B15F(void);
36 public:
37
38 /*************************************
39 * Grundfunktionen des B15F Treibers *
40 *************************************/
41
46 void reconnect(void);
47
52 void discard(void);
53
58 bool testConnection(void);
59
64 bool testIntConv(void);
65
70 std::vector<std::string> getBoardInfo(void);
71
76 void delay_ms(uint16_t ms);
77
82 void delay_us(uint16_t us);
83
88 static B15F& getInstance(void);
89
94 static std::string exec(std::string cmd);
95
100 static void abort(std::string msg);
101
106 static void abort(std::exception& ex);
107
112 static void setAbortHandler(errorhandler_t func);
113
114 /*************************************/
115
116
117
118 /*************************
119 * Steuerbefehle für B15 *
120 *************************/
121
127 bool activateSelfTestMode(void);
128
134 bool digitalWrite0(uint8_t);
135
141 bool digitalWrite1(uint8_t);
142
148 uint8_t digitalRead0(void);
149
155 uint8_t digitalRead1(void);
156
162 uint8_t readDipSwitch(void);
163
169 bool analogWrite0(uint16_t port);
170
176 bool analogWrite1(uint16_t port);
177
183 uint16_t analogRead(uint8_t channel);
184
200 void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
201
210 uint8_t pwmSetFrequency(uint32_t freq);
211
217 bool pwmSetValue(uint8_t value);
218
226 bool setRegister(volatile uint8_t* adr, uint8_t val);
227
233 uint8_t getRegister(volatile uint8_t* adr);
234
235 /*************************/
236
237
238 // CONSTANTS
239 const std::string PRE = "[B15F] ";
240 constexpr static uint8_t MSG_OK = 0xFF;
241 constexpr static uint8_t MSG_FAIL = 0xFE;
242 constexpr static uint16_t RECONNECT_TIMEOUT = 64;
243 constexpr static uint16_t WDT_TIMEOUT = 15;
244 constexpr static uint8_t RECONNECT_TRIES = 3;
245 constexpr static uint32_t BAUDRATE = 57600;
246
247 private:
248
253 void init(void);
254
255 USART usart;
256 static B15F* instance;
257 static errorhandler_t errorhandler;
258
259 // REQUESTS
260 constexpr static uint8_t RQ_DISC = 0;
261 constexpr static uint8_t RQ_TEST = 1;
262 constexpr static uint8_t RQ_INFO = 2;
263 constexpr static uint8_t RQ_INT = 3;
264 constexpr static uint8_t RQ_ST = 4;
265 constexpr static uint8_t RQ_BA0 = 5;
266 constexpr static uint8_t RQ_BA1 = 6;
267 constexpr static uint8_t RQ_BE0 = 7;
268 constexpr static uint8_t RQ_BE1 = 8;
269 constexpr static uint8_t RQ_DSW = 9;
270 constexpr static uint8_t RQ_AA0 = 10;
271 constexpr static uint8_t RQ_AA1 = 11;
272 constexpr static uint8_t RQ_ADC = 12;
273 constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
274 constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
275 constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
276 constexpr static uint8_t RQ_SET_REG = 16;
277 constexpr static uint8_t RQ_GET_REG = 17;
278 };
279
280 #endif // B15F_H
B15F::exec
static std::string exec(std::string cmd)
Definition: b15f.cpp:451
B15F::MSG_FAIL
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:239
B15F::delay_us
void delay_us(uint16_t us)
Definition: b15f.cpp:437
B15F::digitalRead0
uint8_t digitalRead0(void)
Definition: b15f.cpp:207
B15F::pwmSetFrequency
uint8_t pwmSetFrequency(uint32_t freq)
Definition: b15f.cpp:359
B15F::analogSequence
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:302
B15F::testConnection
bool testConnection(void)
Definition: b15f.cpp:95
B15F::readDipSwitch
uint8_t readDipSwitch(void)
Definition: b15f.cpp:235
B15F::getRegister
uint8_t getRegister(volatile uint8_t *adr)
Definition: b15f.cpp:414
B15F::delay_ms
void delay_ms(uint16_t ms)
Definition: b15f.cpp:432
B15F::getInstance
static B15F & getInstance(void)
Definition: b15f.cpp:442
B15F
Definition: b15f.h:31
B15F::abort
static void abort(std::string msg)
Definition: b15f.cpp:467
USART
Definition: usart.h:16
B15F::analogRead
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:279
B15F::digitalWrite0
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:179
B15F::PRE
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:237
B15F::activateSelfTestMode
bool activateSelfTestMode(void)
Definition: b15f.cpp:166
B15F::getBoardInfo
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:134
B15F::RECONNECT_TIMEOUT
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:240
B15F::analogWrite1
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:264
B15F::digitalWrite1
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:193
B15F::pwmSetValue
bool pwmSetValue(uint8_t value)
Definition: b15f.cpp:379
B15F::discard
void discard(void)
Definition: b15f.cpp:72
B15F::setRegister
bool setRegister(volatile uint8_t *adr, uint8_t val)
Definition: b15f.cpp:396
B15F::MSG_OK
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:238
B15F::digitalRead1
uint8_t digitalRead1(void)
Definition: b15f.cpp:221
B15F::WDT_TIMEOUT
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:241
B15F::reconnect
void reconnect(void)
Definition: b15f.cpp:57
B15F::BAUDRATE
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:243
B15F::setAbortHandler
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:485
B15F::analogWrite0
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:249
B15F::RECONNECT_TRIES
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:242
B15F::testIntConv
bool testIntConv(void)
Definition: b15f.cpp:114