IoT Supervisor 0.0
Loading...
Searching...
No Matches
ModbusMiddleWare.c
Go to the documentation of this file.
1#include "ModbusMiddleWare.h"
2#include "IoT_Supervisor.h"
3#include <stdint.h>
4#include <SI_EFM8BB1_Register_Enums.h>
5
25code const uint8_t mmw_ct[eMMW_B_NUM][eMMW_CL_NUM] =
26{
27 {0, 0xEC, 0, 0},
28 {0, 0xD8, 0, 0},
29 {0, 0xB0, 1, 0},
30 {0, 0x60, 4, 1},
31 {1, 0xE5, 10, 3},
32 {1, 0xCB, 22, 7}
33};
34
37
38// Functions
47void mmw_init(uint8_t sid, uint8_t baud)
48{
50 if (baud == 0)
51 {
52 return;
53 }
54
55 // stop UART
56 SCON0 &= ~SCON0_REN__BMASK & ~SCON0_MCE__BMASK;
57 // stop timer 1
58 TMOD = (TMOD & ~TMOD_T1M__FMASK) | TMOD_T1M__MODE3;
59
60 // decode T1 clock source
61 if (mmw_ct[baud - 1][eMMW_CL_T1_PRE] == 1)
62 {
63 // prescaler
64 CKCON0 = (CKCON0 & ~CKCON0_T1M__BMASK) | CKCON0_T1M__PRESCALE;
65 }
66 else
67 {
68 // system clock
69 CKCON0 = (CKCON0 & ~CKCON0_T1M__BMASK) | CKCON0_T1M__SYSCLK;
70 }
71
72 // set timer 1 mode to mode 2 (8-bit counter/timer with auto-reload)
73 TMOD = (TMOD & ~TMOD_T1M__FMASK) | TMOD_T1M__MODE2;
74
75 // set timer 1 current value and reload value
76 TH1 = (mmw_ct[baud - 1][eMMW_CL_TH1] << TH1_TH1__SHIFT);
77 TL1 = (mmw_ct[baud - 1][eMMW_CL_TH1] << TL1_TL1__SHIFT);
78
79 // maybe this code will support parity values in the future, but the
80 // efm8bb1 does not support parity.
81
82 // enable UART, interestingly enough the MCE bit is just for
83 // normal interrupts
84 SCON0 |= SCON0_REN__RECEIVE_ENABLED | SCON0_MCE__MULTI_ENABLED;
85
86 // software counter values
88 T0C_TOP = mmw_ct[baud - 1][eMMW_CL_TL0_TOP];
89}
90
// group Modbus_MiddleWare
uint8_t T0C_TOP
void mmw_init(uint8_t sid, uint8_t baud)
uint8_t PETITMODBUS_SLAVE_ADDRESS
code const uint8_t mmw_ct[eMMW_B_NUM][eMMW_CL_NUM]
uint8_t PETITMODBUS_DLY_TOP
@ eMMW_B_NUM
@ eMMW_CL_TH1
@ eMMW_CL_PETIT_TOP
@ eMMW_CL_T1_PRE
@ eMMW_CL_TL0_TOP
@ eMMW_CL_NUM