You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
6.4 KiB
C
258 lines
6.4 KiB
C
4 weeks ago
|
/*
|
||
|
* ModbusRTUDefines.h
|
||
|
*
|
||
|
* Author: Aleksey Gerasimenko
|
||
|
* gerasimenko.aleksey.n@gmail.com
|
||
|
*/
|
||
|
|
||
|
#include <math.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include "F28335/DSP28x_Project.h"
|
||
|
#include "F28335/DSP2833x_Examples.h"
|
||
|
|
||
|
#include "DSP28335/GPIO.h"
|
||
|
#include "DSP28335/SCIBase.h"
|
||
|
|
||
|
#include "MODBUSRTU/ModbusRTUVariant.h"
|
||
|
|
||
|
|
||
|
#ifndef SCIRS485_BAUDRATE_DEFAULT
|
||
|
//#define SCIRS485_BAUDRATE_DEFAULT (DSP28335::BR2400)
|
||
|
//#define SCIRS485_BAUDRATE_DEFAULT (DSP28335::BR4800)
|
||
|
#define SCIRS485_BAUDRATE_DEFAULT (DSP28335::BR9600)
|
||
|
//#define SCIRS485_BAUDRATE_DEFAULT (DSP28335::BR14400)
|
||
|
//#define SCIRS485_BAUDRATE_DEFAULT (DSP28335::BR19200)
|
||
|
//#define SCIRS485_BAUDRATE_DEFAULT (DSP28335::BR38400)
|
||
|
#endif
|
||
|
|
||
|
#ifndef SCIRS485_PARITY_DEFAULT
|
||
|
#define SCIRS485_PARITY_DEFAULT (DSP28335::NO)
|
||
|
//#define SCIRS485_PARITY_DEFAULT (MODBUSRTU::ODD)
|
||
|
//#define SCIRS485_PARITY_DEFAULT (MODBUSRTU::EVEN)
|
||
|
#endif
|
||
|
|
||
|
#ifndef SCIRS485_STOPBITS_DEFAULT
|
||
|
#define SCIRS485_STOPBITS_DEFAULT (DSP28335::ONE)
|
||
|
//#define SCIRS485_STOPBITS_DEFAULT (DSP28335::ODD)
|
||
|
//#define SCIRS485_STOPBITS_DEFAULT (DSP28335::EVEN)
|
||
|
#endif
|
||
|
|
||
|
#ifndef SCIRS485_LENGHT_DEFAULT
|
||
|
#define SCIRS485_LENGHT_DEFAULT (DSP28335::LEN8)
|
||
|
#endif
|
||
|
|
||
|
#ifndef SCIRS485_GPIO_SETUP_DEFAULT
|
||
|
#define SCIRS485_GPIO_SETUP_DEFAULT (&DSP28335::GPIO::gpio_scib_setup)
|
||
|
#endif
|
||
|
|
||
|
#ifndef SCIRS485_GPIO_DE_DEFAULT
|
||
|
#define SCIRS485_GPIO_DE_DEFAULT (&DSP28335::GPIO::gpio_scib_re_de_set)
|
||
|
#endif
|
||
|
|
||
|
#ifndef SCIRS485_GPIO_RE_DEFAULT
|
||
|
#define SCIRS485_GPIO_RE_DEFAULT (&DSP28335::GPIO::gpio_scib_re_de_clear)
|
||
|
#endif
|
||
|
|
||
|
|
||
|
#ifndef NOP
|
||
|
#define NOP asm(" NOP")
|
||
|
#endif
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_BROADCAST
|
||
|
#define MODBUSRTU_FUNCTION_BROADCAST (uint16_t) 00
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_READ_COIL_STATUS
|
||
|
#define MODBUSRTU_FUNCTION_READ_COIL_STATUS (uint16_t) 01
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_READ_INPUT_STATUS
|
||
|
#define MODBUSRTU_FUNCTION_READ_INPUT_STATUS (uint16_t) 02
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_READ_HOLDING_REGISTERS
|
||
|
#define MODBUSRTU_FUNCTION_READ_HOLDING_REGISTERS (uint16_t) 03
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_READ_INPUT_REGISTERS
|
||
|
#define MODBUSRTU_FUNCTION_READ_INPUT_REGISTERS (uint16_t) 04
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_FORCE_SINGLE_COIL
|
||
|
#define MODBUSRTU_FUNCTION_FORCE_SINGLE_COIL (uint16_t) 05
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_PRESET_SINGLE_REGISTER
|
||
|
#define MODBUSRTU_FUNCTION_PRESET_SINGLE_REGISTER (uint16_t) 06
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_FORCE_MULTIPLE_COILS
|
||
|
#define MODBUSRTU_FUNCTION_FORCE_MULTIPLE_COILS (uint16_t) 15
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_FUNCTION_PRESET_MULTIPLE_REGISTERS
|
||
|
#define MODBUSRTU_FUNCTION_PRESET_MULTIPLE_REGISTERS (uint16_t) 16
|
||
|
#endif
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#ifndef DEFAULT_MODBUSRTU_INPUT_REGISTERS_SIZE
|
||
|
#define DEFAULT_MODBUSRTU_INPUT_REGISTERS_SIZE (uint16_t)10
|
||
|
#endif
|
||
|
|
||
|
#ifndef DEFAULT_MODBUSRTU_OUTPUT_REGISTERS_SIZE
|
||
|
#define DEFAULT_MODBUSRTU_OUTPUT_REGISTERS_SIZE (uint16_t)10
|
||
|
#endif
|
||
|
|
||
|
#ifndef DEFAULT_MODBUSRTU_INPUT_COILS_SIZE
|
||
|
#define DEFAULT_MODBUSRTU_INPUT_COILS_SIZE (uint16_t)10
|
||
|
#endif
|
||
|
|
||
|
#ifndef DEFAULT_MODBUSRTU_OUTPUT_COILS_SIZE
|
||
|
#define DEFAULT_MODBUSRTU_OUTPUT_COILS_SIZE (uint16_t)10
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_INPUT_REGISTERS_SIZE
|
||
|
#define MODBUSRTU_INPUT_REGISTERS_SIZE DEFAULT_MODBUSRTU_INPUT_REGISTERS_SIZE
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_OUTPUT_REGISTERS_SIZE
|
||
|
#define MODBUSRTU_OUTPUT_REGISTERS_SIZE DEFAULT_MODBUSRTU_OUTPUT_REGISTERS_SIZE
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_INPUT_COILS_SIZE
|
||
|
#define MODBUSRTU_INPUT_COILS_SIZE DEFAULT_MODBUSRTU_INPUT_COILS_SIZE
|
||
|
#endif
|
||
|
|
||
|
#ifndef MODBUSRTU_OUTPUT_COILS_SIZE
|
||
|
#define MODBUSRTU_OUTPUT_COILS_SIZE DEFAULT_MODBUSRTU_OUTPUT_COILS_SIZE
|
||
|
#endif
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#ifndef MODBUSRTU_MODBUSRTUDEFINES_H_
|
||
|
#define MODBUSRTU_MODBUSRTUDEFINES_H_
|
||
|
|
||
|
|
||
|
namespace MODBUSRTU
|
||
|
{
|
||
|
|
||
|
enum buffer_type_t {OUTPUTCOILS, INPUTCOILS, OUTPUTREGISTERS, INPUTREGISTERS};
|
||
|
enum transceiver_state_machine_t {SCAN, RECEIVE, WAIT_RESPONSE, TRANSMIT, BREAK};
|
||
|
enum transceiver_event_t {ENTRY, RXREADY, TXREADY, TXWAIT};
|
||
|
|
||
|
enum modbusrtu_register_16_bit_t { REG16_BIT0,
|
||
|
REG16_BIT1,
|
||
|
REG16_BIT2,
|
||
|
REG16_BIT3,
|
||
|
REG16_BIT4,
|
||
|
REG16_BIT5,
|
||
|
REG16_BIT6,
|
||
|
REG16_BIT7,
|
||
|
REG16_BIT8,
|
||
|
REG16_BIT9,
|
||
|
REG16_BIT10,
|
||
|
REG16_BIT11,
|
||
|
REG16_BIT12,
|
||
|
REG16_BIT13,
|
||
|
REG16_BIT14,
|
||
|
REG16_BIT15};
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//struct ModbusRTUDataByteField
|
||
|
//{
|
||
|
// uint16_t low :8;
|
||
|
// uint16_t high :8;
|
||
|
//};//ModbusRTUDataByteField
|
||
|
|
||
|
//union ModbusRTUDataRegister
|
||
|
//{
|
||
|
// uint16_t all;
|
||
|
// ModbusRTUDataByteField byte;
|
||
|
// ModbusRTUDataRegister():
|
||
|
// all(0)
|
||
|
// {}
|
||
|
//};//ModbusRTUDataRegister
|
||
|
|
||
|
|
||
|
//enum ModbusRTUEventRS
|
||
|
//{
|
||
|
// ENTRY, // state entry event
|
||
|
// EXIT, // state exit event
|
||
|
// TIMEOUT3_5CHAR, // All datagram have been received
|
||
|
// TIMEOUT1_5CHAR, // Interval time of each byte in datagram. Not used
|
||
|
// RX_READY, // SCIRXST.bit.RXRDY. Serial port received a serial data (one byte)
|
||
|
// TX_READY, // All datagram have been sent
|
||
|
// TX_WAIT // Wait for the datagram to be sent
|
||
|
//};//
|
||
|
|
||
|
/*
|
||
|
enum ModbusRTUReceiveEvent
|
||
|
{
|
||
|
ENTRY,
|
||
|
RECEIVE,
|
||
|
EXIT,
|
||
|
TIMEOUT355CHAR,
|
||
|
TIMEOUT155CHAR,
|
||
|
FRAMEREADY,
|
||
|
WAIT
|
||
|
};//
|
||
|
*/
|
||
|
|
||
|
|
||
|
//struct ModbusRTUTimerStateBitField
|
||
|
//{
|
||
|
// uint16_t time_over_1_5_char :1;
|
||
|
// uint16_t time_over_3_5_char :1;
|
||
|
//};//ModbusRTUTimerStateBitField
|
||
|
|
||
|
//union ModbusRTUTimerState
|
||
|
//{
|
||
|
// uint16_t all;
|
||
|
// ModbusRTUTimerStateBitField bit;
|
||
|
// ModbusRTUTimerState():
|
||
|
// all((uint16_t)0)
|
||
|
// {}
|
||
|
//};//ModbusRTUTimerState
|
||
|
|
||
|
|
||
|
//struct ModbusRTUTimer
|
||
|
//{
|
||
|
// uint32_t counter;
|
||
|
// uint32_t start;
|
||
|
// uint32_t interval;
|
||
|
// uint32_t period_1_5_char;
|
||
|
// uint32_t period_3_5_char;
|
||
|
// ModbusRTUTimerState flag;
|
||
|
// ModbusRTUTimer():
|
||
|
// counter((uint32_t)0),
|
||
|
// start((uint32_t)0),
|
||
|
// interval((uint32_t)0),
|
||
|
// period_1_5_char((uint32_t)0),
|
||
|
// period_3_5_char((uint32_t)0),
|
||
|
// flag()
|
||
|
// {}
|
||
|
//};//
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
} /* namespace MODBUSRTU */
|
||
|
|
||
|
#endif /* MODBUSRTU_MODBUSRTUDEFINES_H_ */
|