Init
This commit is contained in:
commit
3e5a18ff2e
|
|
@ -0,0 +1,194 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 25.03.24.
|
||||||
|
//
|
||||||
|
#include "SerialPorts.h"
|
||||||
|
#include "at32f435_437.h"
|
||||||
|
|
||||||
|
tSerialPorts SERIAL_PORTS;
|
||||||
|
|
||||||
|
|
||||||
|
///начало-----------------------------------------Rs485-----------------------------------------------------------------
|
||||||
|
uint8_t buf_UART7_DMA[256];
|
||||||
|
|
||||||
|
// IDLE прерывание
|
||||||
|
void UART7_IRQHandler() {
|
||||||
|
SerialPort_IrqProcessing_UartIdle(&SERIAL_PORTS.Rs485);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RX
|
||||||
|
void DMA1_Channel1_IRQHandler(void) {
|
||||||
|
SerialPort_IrqProcessing_DmaRxLoop(&SERIAL_PORTS.Rs485);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TX
|
||||||
|
void DMA1_Channel2_IRQHandler(void) {
|
||||||
|
SerialPort_IrqProcessing_DmaTx(&SERIAL_PORTS.Rs485);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vSerialPort_InitUART7(tSerialPortArtery *env){
|
||||||
|
gpio_init_type GPIO_InitStruct;
|
||||||
|
|
||||||
|
gpio_default_para_init(&GPIO_InitStruct);
|
||||||
|
|
||||||
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_3;
|
||||||
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_4;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE3, GPIO_MUX_8);
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE4, GPIO_MUX_8);
|
||||||
|
|
||||||
|
vSerialPortInitDmaWithNameAndSniffer(
|
||||||
|
env,
|
||||||
|
UART7, 115200,
|
||||||
|
1, 1, 1, 2,
|
||||||
|
false,
|
||||||
|
0x58,
|
||||||
|
buf_UART7_DMA, sizeof(buf_UART7_DMA),
|
||||||
|
256, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
///начало-----------------------------------------Модем-----------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t buf_USART3_DMA[1024*2];
|
||||||
|
|
||||||
|
// IDLE прерывание
|
||||||
|
void USART3_IRQHandler() {
|
||||||
|
SerialPort_IrqProcessing_UartIdle(&SERIAL_PORTS.Modem);
|
||||||
|
// SerialPort_IrqProcessingFilter_UartIdle(&SERIAL_PORTS.Modem, &SERIAL_PORTS.gnssVirtualInIo,
|
||||||
|
// &counterBufFilterStr, BufFilterStr, sizeof(BufFilterStr),
|
||||||
|
// FilterStr, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RX
|
||||||
|
void DMA1_Channel3_IRQHandler(void) {
|
||||||
|
SerialPort_IrqProcessing_DmaRxLoop(&SERIAL_PORTS.Modem);
|
||||||
|
// SerialPort_IrqProcessingFilter_DmaRxLoop(&SERIAL_PORTS.Modem, &SERIAL_PORTS.gnssVirtualInIo,
|
||||||
|
// &counterBufFilterStr, BufFilterStr, sizeof(BufFilterStr),
|
||||||
|
// FilterStr, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TX
|
||||||
|
void DMA1_Channel4_IRQHandler(void) {
|
||||||
|
|
||||||
|
SerialPort_IrqProcessing_DmaTx(&SERIAL_PORTS.Modem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройка порта
|
||||||
|
static void vSerialPort_InitUSART3(tSerialPortArtery *env) {
|
||||||
|
gpio_init_type GPIO_InitStruct;
|
||||||
|
|
||||||
|
gpio_default_para_init(&GPIO_InitStruct);
|
||||||
|
|
||||||
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_10;
|
||||||
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_11;
|
||||||
|
gpio_init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE10, GPIO_MUX_7);
|
||||||
|
gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE11, GPIO_MUX_7);
|
||||||
|
|
||||||
|
vSerialPortInitDmaWithNameAndSniffer(
|
||||||
|
env,
|
||||||
|
USART3, 115200,
|
||||||
|
1, 3, 1, 4,
|
||||||
|
false,
|
||||||
|
0x56,
|
||||||
|
buf_USART3_DMA, sizeof(buf_USART3_DMA),
|
||||||
|
1024 * 6, 2048
|
||||||
|
);
|
||||||
|
}
|
||||||
|
///конец------------------------------------------Модем-----------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
uint8_t buf_USART2_DMA[256];
|
||||||
|
|
||||||
|
// IDLE прерывание
|
||||||
|
void USART2_IRQHandler() {
|
||||||
|
SerialPort_IrqProcessing_UartIdle(&SERIAL_PORTS.Debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RX
|
||||||
|
void DMA1_Channel5_IRQHandler(void) {
|
||||||
|
SerialPort_IrqProcessing_DmaRxLoop(&SERIAL_PORTS.Debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TX
|
||||||
|
void DMA1_Channel6_IRQHandler(void) {
|
||||||
|
SerialPort_IrqProcessing_DmaTx(&SERIAL_PORTS.Debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройка порта радиомодуля
|
||||||
|
static void vSerialPort_InitUSART2(tSerialPortArtery *env) {
|
||||||
|
gpio_init_type GPIO_InitStruct;
|
||||||
|
|
||||||
|
gpio_default_para_init(&GPIO_InitStruct);
|
||||||
|
|
||||||
|
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
|
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
|
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_5;
|
||||||
|
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
|
||||||
|
gpio_init(GPIOD, &GPIO_InitStruct);
|
||||||
|
GPIO_InitStruct.gpio_pins = GPIO_PINS_6;
|
||||||
|
gpio_init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
gpio_pin_mux_config(GPIOD, GPIO_PINS_SOURCE5, GPIO_MUX_7);
|
||||||
|
gpio_pin_mux_config(GPIOD, GPIO_PINS_SOURCE6, GPIO_MUX_7);
|
||||||
|
|
||||||
|
vSerialPortInitDmaWithNameAndSniffer(
|
||||||
|
env,
|
||||||
|
USART2, 115200,
|
||||||
|
1, 5, 1, 6,
|
||||||
|
false,
|
||||||
|
0x59,
|
||||||
|
buf_USART2_DMA, sizeof(buf_USART2_DMA),
|
||||||
|
256, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
///конец---------------------------------------Debug_Usart--------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
void SerialPorts_Init(tRs485DirectionPins *directionPins) {
|
||||||
|
|
||||||
|
tSerialPorts *env = &SERIAL_PORTS;
|
||||||
|
// Usart1 Rs485
|
||||||
|
vSerialPort_InitUART7(&env->Rs485);
|
||||||
|
SERIAL_PORTS.Rs485_IO = vSerialPortGetIo(&SERIAL_PORTS.Rs485);
|
||||||
|
SERIAL_PORTS.Rs485_HalfDuplex = vSerialPortHalfDuplexInit(&SERIAL_PORTS.Rs485_IO,
|
||||||
|
&directionPins->transmit,
|
||||||
|
&directionPins->receive);
|
||||||
|
SERIAL_PORTS.Rs485_HalfDuplexIo = vSerialPortHalfDuplexGetIo(&SERIAL_PORTS.Rs485_HalfDuplex);
|
||||||
|
//// Usart3 Модем
|
||||||
|
vSerialPort_InitUSART3(&env->Modem);
|
||||||
|
SERIAL_PORTS.Modem_IO = vSerialPortGetIo(&SERIAL_PORTS.Modem);
|
||||||
|
SERIAL_PORTS.Modem_snif_IO = vSerialPortGetSnifferIo(&SERIAL_PORTS.Modem);
|
||||||
|
|
||||||
|
//// Usart2 Debug-usart
|
||||||
|
// vSerialPort_InitUSART2(&env->Debug);
|
||||||
|
// SERIAL_PORTS.Debug_IO = vSerialPortGetIo(&env->Debug);
|
||||||
|
|
||||||
|
//// Виртуальный сериал порт
|
||||||
|
SerialPortP2p_Init(&env->cliVirtualPort, 3 * 1024, 1024);
|
||||||
|
env->cliVirtualInIo = SerialPortP2p_GetIoFirst(&env->cliVirtualPort);
|
||||||
|
env->cliVirtualOutIo = SerialPortP2p_GetIoSecond(&env->cliVirtualPort);
|
||||||
|
|
||||||
|
SerialPortP2p_Init(&env->gnssVirtualPort, 256, 256);
|
||||||
|
env->gnssVirtualInIo = SerialPortP2p_GetIoFirst(&env->gnssVirtualPort);
|
||||||
|
env->gnssVirtualOutIo = SerialPortP2p_GetIoSecond(&env->gnssVirtualPort);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 25.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SMART_COMPONENTS_SERIALPORTS_H
|
||||||
|
#define SMART_COMPONENTS_SERIALPORTS_H
|
||||||
|
|
||||||
|
#include "SerialPortArtery.h"
|
||||||
|
#include "SerialPortP2p.h"
|
||||||
|
#include "SerialPortHalfDuplexIO.h"
|
||||||
|
|
||||||
|
//Пины RS485
|
||||||
|
typedef struct {
|
||||||
|
tGpioPin receive;
|
||||||
|
tGpioPin transmit;
|
||||||
|
} tRs485DirectionPins;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
//Usart Debug
|
||||||
|
// tSerialPortArtery Debug;
|
||||||
|
// tSerialPortIO Debug_IO;
|
||||||
|
//Usart модема
|
||||||
|
tSerialPortArtery Modem;
|
||||||
|
tSerialPortIO Modem_IO;
|
||||||
|
tSerialPortIO Modem_snif_IO;
|
||||||
|
//Usart-RS485
|
||||||
|
tSerialPortArtery Rs485;
|
||||||
|
tSerialPortIO Rs485_IO;
|
||||||
|
|
||||||
|
tSerialPortHalfDuplex Rs485_HalfDuplex;
|
||||||
|
tSerialPortIO Rs485_HalfDuplexIo;
|
||||||
|
|
||||||
|
tSerialPortP2p cliVirtualPort;
|
||||||
|
tSerialPortIO cliVirtualInIo;
|
||||||
|
tSerialPortIO cliVirtualOutIo;
|
||||||
|
|
||||||
|
tSerialPortP2p gnssVirtualPort;
|
||||||
|
tSerialPortIO gnssVirtualInIo;
|
||||||
|
tSerialPortIO gnssVirtualOutIo;
|
||||||
|
|
||||||
|
} tSerialPorts;
|
||||||
|
|
||||||
|
extern tSerialPorts SERIAL_PORTS;
|
||||||
|
|
||||||
|
void SerialPorts_Init(tRs485DirectionPins *directionPins);
|
||||||
|
|
||||||
|
#endif //SMART_COMPONENTS_SERIALPORTS_H
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"./**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue