Sun, 25 Oct 2020 17:02:53 +0100
Update the custom target HP34970_FP_303RD
update the platformio.ini:
remove unused flags, and configure so it uses includes from the project's root
directory (in TARGET_HP34970_FP_F303RD) so these .h/.c files do not conflict
when compiling for other targets.
Add a TARGET_HP34970_FR_F303RD/ for target specific headers/linker files.
Add a src/TARGET_HP34970_FR_F303RD/ for c files (protected by '#if defined'
statments).
5 | 1 | #ifndef HP34COMM_H |
2 | #define HP34COMM_H | |
3 | ||
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
4 | #include <mbed.h> |
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
5 | #include <CircularBuffer.h> |
5 | 6 | |
7 | /***** HP 34970A communication class ***/ | |
8 | ||
9 | #define MAX_ERRS 10 | |
8 | 10 | #define MAX_BUFF 16 |
11 | #define BUF_SIZE 16 | |
5 | 12 | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
13 | |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
14 | |
5 | 15 | class HPSerial { |
16 | ||
17 | public: | |
18 | typedef struct _CMD | |
19 | { | |
20 | uint8_t cmd; | |
21 | uint8_t size; | |
22 | char value[MAX_BUFF+1]; | |
23 | unsigned long id; | |
24 | } CMD; | |
21 | 25 | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
26 | HPSerial(PinName tx, PinName rx); |
19 | 27 | |
5 | 28 | bool cmd_available(void); |
29 | bool pop(CMD& cmd); | |
30 | bool cmd_buf_full(void); | |
31 | unsigned int nerrors(uint8_t errorno); | |
21 | 32 | |
19 | 33 | void startup(void); |
34 | void send(const uint8_t *buf, uint8_t size); | |
35 | void sendkey(uint8_t keycode); | |
21 | 36 | |
5 | 37 | private: |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
38 | void pushCmd(uint8_t cmd, uint8_t size, char *payload); |
5 | 39 | void rxIrq(void); |
40 | void timeout(void); | |
19 | 41 | void set_timer(float v=0.0) { |
42 | timeouter.detach(); | |
43 | if (v > 0.0) | |
44 | timeouter.attach(callback(this, &HPSerial::timeout), v); | |
45 | } | |
5 | 46 | |
47 | private: | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
48 | UnbufferedSerial serial; |
5 | 49 | uint8_t buf[BUF_SIZE]; |
50 | uint8_t head; | |
51 | CircularBuffer<CMD, 32> cmdbuf; | |
52 | unsigned long ncmd; | |
53 | unsigned int errs[MAX_ERRS]; | |
54 | Ticker timeouter; | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
55 | |
19 | 56 | public: |
57 | // global state machine | |
58 | typedef enum { | |
59 | GSTATE_STARTING, | |
60 | GSTATE_IDLE, | |
61 | GSTATE_TX, | |
62 | GSTATE_RX, | |
63 | NUM_GSTATES} gstate_t; | |
64 | gstate_t gstate() {return cur_gstate;}; | |
65 | /* gstate_t do_start(); */ | |
66 | /* gstate_t do_send(); */ | |
67 | /* gstate_t do_receive(); */ | |
21 | 68 | |
19 | 69 | /* typedef gstate_t(HPSerial::*gstatemethod)(); */ |
70 | /* statemethod const gstate_table[NUM_GSTATES] = { */ | |
71 | /* &HPSerial::do_start, */ | |
72 | /* &HPSerial::do_send, */ | |
73 | /* &HPSerial::do_receive, */ | |
74 | /* }; */ | |
21 | 75 | |
19 | 76 | /* gstate_t run_gstate(gstate_t cur_state); */ |
77 | private: | |
78 | gstate_t cur_gstate; | |
21 | 79 | |
19 | 80 | public: |
81 | // transmission state machine | |
82 | typedef enum { | |
83 | STATE_IDLE, | |
84 | STATE_COMMAND, | |
85 | STATE_PAYLOAD_SIZE, | |
86 | STATE_PAYLOAD, | |
87 | STATE_SENDING, | |
88 | STATE_EOT, | |
89 | NUM_STATES} state_t; | |
90 | state_t state() {return cur_state;}; | |
21 | 91 | |
19 | 92 | private: |
93 | typedef struct state_data { | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
94 | uint8_t cmd; |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
95 | uint8_t size; |
19 | 96 | uint8_t pos; |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
97 | char payload[MAX_BUFF]; |
19 | 98 | } state_data_t; |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
99 | |
19 | 100 | void _startup(void); |
101 | state_t do_state_initial(uint8_t c=0x00); | |
102 | state_t do_state_command(uint8_t c); | |
103 | state_t do_state_payload_size(uint8_t c); | |
104 | state_t do_state_payload(uint8_t c); | |
105 | state_t do_state_sending(uint8_t c=0x00); | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
21
diff
changeset
|
106 | state_t do_state_eot(uint8_t c=0x55); |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
107 | |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
108 | void send_ack(uint8_t c); |
21 | 109 | |
19 | 110 | typedef state_t(HPSerial::*statemethod)(uint8_t c); |
21 | 111 | static statemethod state_table[NUM_STATES]; |
19 | 112 | state_t run_state(state_t cur_state, uint8_t c); |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
113 | |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
10
diff
changeset
|
114 | state_t cur_state; |
19 | 115 | state_data_t tr_data; |
5 | 116 | }; |
117 | ||
19 | 118 | |
5 | 119 | #endif |