IoT Supervisor
0.0
Loading...
Searching...
No Matches
PetitModbusPort.c
Go to the documentation of this file.
1
14
// Necessary Petit Modbus Includes
15
#include "PetitModbusPort.h"
16
// User Includes
17
#include <SI_EFM8BB1_Register_Enums.h>
18
#include "
hardware.h
"
19
#include "
IoT_Supervisor.h
"
20
#include "
ModbusMiddleWare.h
"
21
22
26
void
PetitPortTimerStart
()
27
{
28
t0Count
= 0;
29
TL0 = (0x20 << TL0_TL0__SHIFT);
30
TCON_TR0 =
true
;
31
return
;
32
}
33
38
void
PetitPortTimerStop
()
39
{
40
TCON_TR0 =
false
;
41
TL0 = (0x20 << TL0_TL0__SHIFT);
42
t0Count
= 0;
43
return
;
44
}
45
49
void
PetitPortDirTx
()
50
{
51
XCVR_TX
=
true
;
52
dir_tx
=
true
;
53
return
;
54
}
55
59
void
PetitPortDirRx
()
60
{
61
XCVR_TX
=
false
;
62
dir_tx
=
false
;
63
return
;
64
}
65
69
void
PetitPortTxBegin
(
pu8_t
tx)
70
{
71
PetitPortDirTx
();
72
// no need to check here, this function should only be called by
73
// petitmodbus on the first character anyway
74
SBUF0 = tx;
75
return
;
76
}
77
87
pb_t
PetitPortRegWrite
(
pu8_t
Address,
pu16_t
Data)
88
{
89
// check if you can write to this
90
if
(Address >
eMMW_HR_CFG
&&
cfgSmS
!=
eCFG_Cache
)
91
{
92
return
0;
93
}
94
// the status register only accepts a few values, and petting the watchdog
95
// automatically enables the watchdog
96
// the reset source can be reset to 0 by writing 0 to this register
97
if
(Address ==
eMMW_HR_STA
)
98
{
99
switch
(Data)
100
{
101
case
0:
102
sv_dev_sta
.
v
.
lastRstS
=
eLR_Init
;
103
break
;
104
case
C_WDT_PET
:
105
mbWDTpet
=
true
;
106
mbWDTen
=
true
;
107
break
;
108
case
C_WDT_DIS
:
109
mbWDTen
=
false
;
110
break
;
111
default
:
112
return
0;
113
}
114
}
115
// you can enter whatever password you want
116
if
(Address ==
eMMW_HR_CFG
)
117
{
118
pw
= Data;
119
pw_flag
=
true
;
120
}
121
// it's perfectly valid to enter 0 for this since none of the bytewise
122
// changes will be applied
123
if
(Address ==
eMMW_HR_MB
)
124
{
125
if
((Data & 0xFF) > 0)
126
{
127
// but if you enter an SID that is too large, you will get an error
128
if
((Data & 0xFF) < 248)
129
{
130
cfg
.
sid
= Data & 0xFF;
131
}
132
else
133
{
134
return
0;
135
}
136
}
137
if
(Data >> 8 > 0)
138
{
139
if
(Data >> 8 <
eMMW_B_NUM
)
140
{
141
cfg
.
baud
= Data >> 8;
142
}
143
}
144
}
145
// the WDT timeout must be at least one minute.
146
if
(Address ==
eMMW_HR_WDT
)
147
{
148
if
(Data > 0)
149
{
150
cfg
.
wdto
= Data;
151
}
152
else
153
{
154
return
0;
155
}
156
}
157
// the new password must be valid
158
if
(Address ==
eMMW_HR_PW
)
159
{
160
if
(Data != 0 && Data !=
C_CMD_COMMIT
&& Data !=
C_CMD_CANCEL
)
161
{
162
cfg
.
pw
= Data;
163
}
164
else
165
{
166
return
0;
167
}
168
}
169
170
return
1;
171
}
172
179
pb_t
PetitPortRegRead
(
pu8_t
Address,
pu16_t
* Data)
180
{
181
// check if you can access this
182
if
(Address >
eMMW_HR_CFG
&&
183
(
cfgSmS
!=
eCFG_Cache
&&
cfgSmS
!=
eCFG_Commit
))
184
{
185
return
0;
186
}
187
if
(Address ==
eMMW_HR_STA
)
188
{
189
*Data =
sv_dev_sta
.
b
;
190
}
191
if
(Address ==
eMMW_HR_CFG
)
192
{
193
*Data =
cfgSmS
;
194
}
195
if
(Address ==
eMMW_HR_MB
)
196
{
197
*Data =
cfg
.
baud
<< 8 |
cfg
.
sid
;
198
}
199
if
(Address ==
eMMW_HR_WDT
)
200
{
201
*Data =
MB_WD_TIMEOUT
;
202
}
203
if
(Address ==
eMMW_HR_PW
)
204
{
205
*Data =
cfg
.
pw
;
206
}
207
return
1;
208
}
209
217
// this function is basically here as an example, it is not used.
218
/*
219
pu8_t PetitPortInputRegRead(pu8_t Address, pu16_t* Data)
220
{
221
return 1;
222
}
223
*/
224
234
pb_t
PetitPortCoilRead
(
pu16_t
Address,
pu8_t
* Data)
235
{
236
if
(Address == 0)
237
{
238
*Data =
sys_ok
;
239
return
1;
240
}
241
return
0;
242
}
243
253
pb_t
PetitPortCoilWrite
(
pu16_t
Address,
pu16_t
Data)
254
{
255
if
(Address == 0)
256
{
257
if
(Data)
258
sys_ok
=
true
;
259
else
260
sys_ok
=
false
;
261
return
1;
262
}
263
return
0;
264
}
265
266
// group IoT Supervisor EFM8BB1LCK Petit Modbus Port
IoT_Supervisor.h
ModbusMiddleWare.h
sys_ok
bool sys_ok
Definition
IoT Supervisor_main.c:108
pw_flag
bool pw_flag
Definition
IoT Supervisor_main.c:456
cfg
cfg_t cfg
Definition
IoT Supervisor_main.c:460
pw
uint16_t pw
Definition
IoT Supervisor_main.c:459
C_CMD_COMMIT
#define C_CMD_COMMIT
Definition
IoT_Supervisor.h:28
C_CMD_CANCEL
#define C_CMD_CANCEL
Definition
IoT_Supervisor.h:29
dir_tx
bool dir_tx
Definition
IoT Supervisor_main.c:457
cfgSmS
CfgSM_t cfgSmS
Definition
IoT Supervisor_main.c:455
eCFG_Cache
@ eCFG_Cache
New Configuration is Caching from Modbus.
Definition
IoT_Supervisor.h:126
eCFG_Commit
@ eCFG_Commit
New Configuration is Committed (Active)
Definition
IoT_Supervisor.h:127
pu16_t
#define pu16_t
Definition
PetitModbusUserPort.h:76
PetitPortCoilRead
pb_t PetitPortCoilRead(pu16_t Address, pu8_t *Data)
Definition
PetitModbusPort.c:234
PetitPortTimerStart
void PetitPortTimerStart()
Definition
PetitModbusPort.c:26
PetitPortCoilWrite
pb_t PetitPortCoilWrite(pu16_t Address, pu16_t Data)
Definition
PetitModbusPort.c:253
PetitPortRegWrite
pb_t PetitPortRegWrite(pu8_t Address, pu16_t Data)
Definition
PetitModbusPort.c:87
PetitPortRegRead
pb_t PetitPortRegRead(pu8_t Address, pu16_t *Data)
Definition
PetitModbusPort.c:179
pu8_t
#define pu8_t
Definition
PetitModbusUserPort.h:74
PetitPortTxBegin
void PetitPortTxBegin(pu8_t tx)
Definition
PetitModbusPort.c:69
PetitPortDirRx
void PetitPortDirRx()
Definition
PetitModbusPort.c:59
PetitPortDirTx
void PetitPortDirTx()
Definition
PetitModbusPort.c:49
PetitPortTimerStop
void PetitPortTimerStop()
Definition
PetitModbusPort.c:38
pb_t
#define pb_t
Definition
PetitModbusUserPort.h:72
sv_dev_sta
volatile sv_dev_sta_t sv_dev_sta
Definition
IoT Supervisor_main.c:47
t0Count
volatile uint8_t t0Count
Definition
IoT Supervisor_main.c:53
eLR_Init
@ eLR_Init
Initial State. No recorded reset.
Definition
IoT_Supervisor.h:89
eMMW_B_NUM
@ eMMW_B_NUM
Definition
ModbusMiddleWare.h:37
eMMW_HR_WDT
@ eMMW_HR_WDT
Definition
ModbusMiddleWare.h:88
eMMW_HR_PW
@ eMMW_HR_PW
Definition
ModbusMiddleWare.h:89
eMMW_HR_CFG
@ eMMW_HR_CFG
Definition
ModbusMiddleWare.h:86
eMMW_HR_MB
@ eMMW_HR_MB
Definition
ModbusMiddleWare.h:87
eMMW_HR_STA
@ eMMW_HR_STA
Definition
ModbusMiddleWare.h:85
mbWDTpet
bool mbWDTpet
Definition
IoT Supervisor_main.c:300
C_WDT_DIS
#define C_WDT_DIS
Definition
IoT_Supervisor.h:23
C_WDT_PET
#define C_WDT_PET
Definition
IoT_Supervisor.h:22
MB_WD_TIMEOUT
uint8_t MB_WD_TIMEOUT
Definition
IoT Supervisor_main.c:298
mbWDTen
bool mbWDTen
Definition
IoT Supervisor_main.c:299
hardware.h
XCVR_TX
#define XCVR_TX
Definition
hardware.h:50
cfg_t::pw
uint16_t pw
Definition
IoT_Supervisor.h:138
cfg_t::sid
uint8_t sid
Definition
IoT_Supervisor.h:135
cfg_t::wdto
uint8_t wdto
Definition
IoT_Supervisor.h:137
cfg_t::baud
uint8_t baud
Definition
IoT_Supervisor.h:136
sv_dev_sta_t::b
uint8_t b
byte access
Definition
IoT_Supervisor.h:165
sv_dev_sta_t::lastRstS
LastRst_t lastRstS
Definition
IoT_Supervisor.h:161
sv_dev_sta_t::v
struct sv_dev_sta_t::@0 v
src
PetitModbusPort.c
Generated by
1.9.8