...
This function is called by MB_Exit()
to close all serial interfaces used by µC/Modbus. Your application DOES NOT need to call this function. The pseudo-code for this function is shown below:
Code Block |
---|
|
void MB_CommExit (void)
{
/* Disable all uC/Modbus Rx interrupts */
/* Disable all uC/Modbus Tx interrupts */
/* Remove interrupt vectors (if needed) */
} |
BSP, MB_CommPortCfg()
This function is called by MB_CfgCh()
to configure the UART communication settings for a channel. MB_CommPortCfg()
must NOT be called by your application. The function prototype is shown below:
Code Block |
---|
|
void MB_CommPortCfg (MODBUS_CH *pch,
CPU_INT08U port_nbr,
CPU_INT32U baud,
CPU_INT08U bits,
CPU_INT08U parity,
CPU_INT08U stops); |
pch
is a pointer to the communication channel to configure. This pointer is returned to your application when you call MB_CfgCh()
.
...
Most UARTs allow you to generate an interrupt when either a byte is received or when a byte has been sent. If your UART generates an interrupt when either a byte is received or when one has been sent then, you would need to write a function that determines whether the interrupt was caused by a received by or by a byte sent. In this case, you would write a function called MBS_CommRxTxISR_x_Handler()
where the ‘x’ indicates the physical UART (example 1, 2, 3 …). The pseudo-code for this function is shown below. The code in RED is code that you have to write. You should COPY all the other code as is.
Code Block |
---|
|
void MB_CommRxTxISR_x_Handler (void)
{
CPU_INT08U c;
CPU_INT08U ch;
MODBUS_CH *pch;
pch = &MB_ChTbl[0];
for (ch = 0; ch < MODBUS_MAX_CH; ch++) {
if (pch->PortNbr == port_nbr) {
if (Rx Interrupt) {
c = Read byte from UART;
Clear Rx Interrupt;
pch->RxCtr++;
MB_RxByte(pch, c); // Pass byte to Modbus to process
}
if (Tx Interrupt) {
pch->TxCtr++;
MB_TxByte(pch); // Send next byte in response
Clear Tx Interrupt;
} break;
} else {
pch++;
}
}
Clear spurious interrupts;
} |
BSP, MB_CommRxIntEn()
This function is called by µC/Modbus to enable Rx interrupts from a UART.
Code Block |
---|
|
void MB_CommRxIntEn (MODBUS_CH * pch)
{
switch (pch->PortNbr) {
/* Enable Rx interrupts for specified UART */
}
} |
BSP, MB_CommRxIntDis()
This function is called by µC/Modbus to disable Rx interrupts from a UART.
Code Block |
---|
|
void MB_CommRxIntDis(MODBUS_CH * pch)
{
switch (pch->PortNbr) {
/* Disable Rx interrupts for specified UART */
}
} |
BSP, MB_CommTx1()
This function is called by µC/Modbusto send a SINGLE byte to the UART associated with the µC/Modbuschannel.
Code Block |
---|
|
void MB_CommTx1 (MODBUS_CH * pch,
CPU_INT08U c)
{
switch (pch->PortNbr) {
/* Write byte 'c' to specified UART */
}
} |
BSP, MB_CommTxIntEn()
This function is called by µC/Modbusto enable Tx interrupts from a UART.
Code Block |
---|
|
void MB_CommTxIntEn(MODBUS_CH * pch)
{
switch (pch->PortNbr) {
/* Enable Tx interrupts from specified UART */
}
} |
BSP, MB_CommTxIntDis()
This function is called by µC/Modbusto disable Tx interrupts from a UART.
Code Block |
---|
|
void MB_CommTxIntDis(MODBUS_CH * pch)
{
switch (pch->PortNbr) {
/* Disable Tx interrupts from specified UART */
}
} |
BSP, MB_RTU_TmrInit()
This function is called by MB_Init()
to initialize the RTU timer. freq
specifies the frequency used for the RTU timer interrupts.
Code Block |
---|
|
void MB_RTU_TmrInit(CPU_INT32U freq); |
BSP, MB_RTU_TmrExit()
This function is called by MB_Exit()
to stop RTU timer interrupts.
Code Block |
---|
|
void MB_RTU_TmrExit(void); |
BSP, MB_RTU_TmrISR_Handler()
This function is the ISR handler for RTU timer interrupts. The pseudo-code for this function is shown below:
Code Block |
---|
|
void MB_RTU_TmrISR_Handler (void)
{
Clear the RTU timer interrupt source;
MB_RTU_TmrCtr++; // Indicate that we had activities on this interrupt
MB_RTU_TmrUpdate(); // Check for RTU timers that have expired
} |