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
27{
28 t0Count = 0;
29 TL0 = (0x20 << TL0_TL0__SHIFT);
30 TCON_TR0 = true;
31 return;
32}
33
39{
40 TCON_TR0 = false;
41 TL0 = (0x20 << TL0_TL0__SHIFT);
42 t0Count = 0;
43 return;
44}
45
50{
51 XCVR_TX = true;
52 dir_tx = true;
53 return;
54}
55
60{
61 XCVR_TX = false;
62 dir_tx = false;
63 return;
64}
65
70{
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
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:
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
180{
181 // check if you can access this
182 if (Address > eMMW_HR_CFG &&
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/*
219pu8_t PetitPortInputRegRead(pu8_t Address, pu16_t* Data)
220{
221 return 1;
222}
223*/
224
235{
236 if (Address == 0)
237 {
238 *Data = sys_ok;
239 return 1;
240 }
241 return 0;
242}
243
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
bool sys_ok
bool pw_flag
cfg_t cfg
uint16_t pw
#define C_CMD_COMMIT
#define C_CMD_CANCEL
bool dir_tx
CfgSM_t cfgSmS
@ eCFG_Cache
New Configuration is Caching from Modbus.
@ eCFG_Commit
New Configuration is Committed (Active)
#define pu16_t
pb_t PetitPortCoilRead(pu16_t Address, pu8_t *Data)
void PetitPortTimerStart()
pb_t PetitPortCoilWrite(pu16_t Address, pu16_t Data)
pb_t PetitPortRegWrite(pu8_t Address, pu16_t Data)
pb_t PetitPortRegRead(pu8_t Address, pu16_t *Data)
#define pu8_t
void PetitPortTxBegin(pu8_t tx)
void PetitPortDirRx()
void PetitPortDirTx()
void PetitPortTimerStop()
#define pb_t
volatile sv_dev_sta_t sv_dev_sta
volatile uint8_t t0Count
@ eLR_Init
Initial State. No recorded reset.
@ eMMW_B_NUM
@ eMMW_HR_WDT
@ eMMW_HR_PW
@ eMMW_HR_CFG
@ eMMW_HR_MB
@ eMMW_HR_STA
bool mbWDTpet
#define C_WDT_DIS
#define C_WDT_PET
uint8_t MB_WD_TIMEOUT
bool mbWDTen
#define XCVR_TX
Definition hardware.h:50
uint16_t pw
uint8_t sid
uint8_t wdto
uint8_t baud
uint8_t b
byte access
LastRst_t lastRstS
struct sv_dev_sta_t::@0 v