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.
126 lines
3.4 KiB
C
126 lines
3.4 KiB
C
4 weeks ago
|
/*
|
||
|
* ModbusRTUTransceiver.h
|
||
|
*
|
||
|
* Author: Aleksey Gerasimenko
|
||
|
* gerasimenko.aleksey.n@gmail.com
|
||
|
*/
|
||
|
|
||
|
#include <math.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
|
||
|
#include <DSP28x_Project.h>
|
||
|
|
||
|
#include "DSP28335/GPIO.h"
|
||
|
#include "DSP28335/CPUTimers.h"
|
||
|
#include "DSP28335/MeasureTimeInterval.h"
|
||
|
#include "DSP28335/SCIA.h"
|
||
|
#include "DSP28335/SCIB.h"
|
||
|
#include "DSP28335/SCIBase.h"
|
||
|
#include "DSP28335/SCIC.h"
|
||
|
|
||
|
#include "MODBUSRTU/ModbusRTUTransceiverBase.h"
|
||
|
#include "MODBUSRTU/ModbusRTUCRC.h"
|
||
|
#include "MODBUSRTU/ModbusRTUDefines.h"
|
||
|
#include "MODBUSRTU/ModbusRTUVariant.h"
|
||
|
|
||
|
|
||
|
#ifndef MODBUSRTU_MODBUSRTUTRANSCEIVER_H_
|
||
|
#define MODBUSRTU_MODBUSRTUTRANSCEIVER_H_
|
||
|
|
||
|
namespace MODBUSRTU
|
||
|
{
|
||
|
|
||
|
|
||
|
class ModbusRTUTransceiver
|
||
|
{
|
||
|
private:
|
||
|
DSP28335::SCIBase& m_sci_port;
|
||
|
DSP28335::SCIConfiguration m_sci_config;
|
||
|
uint16_t m_node_id;
|
||
|
private:
|
||
|
MODBUSRTU::transceiver_state_machine_t m_state_machine;
|
||
|
MODBUSRTU::transceiver_event_t m_event;
|
||
|
private:
|
||
|
DSP28335::MeasureTimeInterval& m_interval_measure;
|
||
|
Uint32 m_interval_pause;
|
||
|
Uint32 m_interval_b5;
|
||
|
Uint32 m_interval_b75;
|
||
|
Uint32 m_interval_1b;
|
||
|
Uint32 m_interval_1b25;
|
||
|
Uint32 m_interval_1b5;
|
||
|
Uint32 m_interval_1b75;
|
||
|
Uint32 m_interval_3b5;
|
||
|
Uint32 m_interval_freeze;
|
||
|
Uint32 m_interval_current;
|
||
|
private:
|
||
|
uint16_t m_rx_buffer[256];
|
||
|
uint16_t m_tx_buffer[256];
|
||
|
uint16_t m_rx_count;
|
||
|
uint16_t m_tx_count;
|
||
|
uint16_t m_tx_length;
|
||
|
//
|
||
|
private:
|
||
|
uint16_t m_aux_rx_buf;
|
||
|
uint16_t m_aux_rx_count;
|
||
|
uint16_t m_aux_tx_buf;
|
||
|
uint16_t m_aux_tx_count;
|
||
|
private:
|
||
|
bool m_crc_status;
|
||
|
MODBUSRTU::ModbusRTUCRC& m_crc;
|
||
|
uint16_t m_crc_calculate;
|
||
|
uint16_t m_crc_rx_frame;
|
||
|
uint16_t m_crc_tx_frame;
|
||
|
private:
|
||
|
uint16_t *m_rx_external_buffer;
|
||
|
uint16_t *m_tx_external_buffer;
|
||
|
uint16_t *m_rx_messaage_length;
|
||
|
uint16_t *m_tx_message_length;
|
||
|
private:
|
||
|
uint16_t *m_destination;
|
||
|
uint16_t *m_source_start;
|
||
|
uint16_t *m_source_end;
|
||
|
uint16_t m_copy_length;
|
||
|
public:
|
||
|
ModbusRTUTransceiver(DSP28335::SCIBase& sciport, DSP28335::MeasureTimeInterval& interval_measure, MODBUSRTU::ModbusRTUCRC& crc);
|
||
|
void setup(ModbusRTUTransceiverSetup& setup);
|
||
|
void configure(ModbusRTUTransceiverConfiguration& config);
|
||
|
void port_reset();
|
||
|
bool compare_state(MODBUSRTU::transceiver_state_machine_t state_machine);
|
||
|
public:
|
||
|
void execute();
|
||
|
public:
|
||
|
void setRXBuffer(uint16_t *bufferStart, uint16_t *messageLen);
|
||
|
void setTXBuffer(uint16_t *bufferStart, uint16_t *messageLen);
|
||
|
private:
|
||
|
void _set_receive_node_id();
|
||
|
void _set_receive_function();
|
||
|
void _set_receive_data();
|
||
|
void _set_wait_response();
|
||
|
void _set_transmit_data();
|
||
|
void _set_break_condition();
|
||
|
private:
|
||
|
void (ModbusRTUTransceiver::*_execute)();
|
||
|
void (ModbusRTUTransceiver::*_frame_transceiver)();
|
||
|
void _execute_transceiver();
|
||
|
void _execute_break();
|
||
|
void _frame_receive_node_id();
|
||
|
void _frame_receive_function();
|
||
|
void _frame_receive_data();
|
||
|
void _frame_wait_response();
|
||
|
void _frame_transmit_data();
|
||
|
void _frame_break_condition();
|
||
|
private:
|
||
|
inline void _frame_copy();
|
||
|
inline void _frame_copy_erase();
|
||
|
void _frame_copy(uint16_t *source, uint16_t length, uint16_t *destination);
|
||
|
private:
|
||
|
void (*_re_de_setup)();
|
||
|
void (*_driver_enable)();
|
||
|
void (*_receiver_enable)();
|
||
|
};
|
||
|
|
||
|
} /* namespace MODBUSRTU */
|
||
|
|
||
|
#endif /* MODBUSRTU_MODBUSRTUTRANSCEIVER_H_ */
|