Добавлены интерфейсы и драйверы
This commit is contained in:
commit
b870fb10df
|
|
@ -0,0 +1,134 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 25.03.24.
|
||||||
|
//
|
||||||
|
#include "SerialPorts.h"
|
||||||
|
|
||||||
|
tSerialPorts SERIAL_PORTS;
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t buf_USART2_DMA[256];
|
||||||
|
|
||||||
|
|
||||||
|
static void DMA_USART2_ErrorCallback() {
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
__asm("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DMA_USART2_TransferCompleteCallback() {
|
||||||
|
++SERIAL_PORTS.Lin.UART_DMA_RECEIVED_LEN_BUF;
|
||||||
|
|
||||||
|
if (SERIAL_PORTS.Lin.UART_DMA_RECEIVED_LEN_BUF >= SERIAL_PORTS.Lin.DMA_BUF_LEN) {
|
||||||
|
|
||||||
|
SerialPort_RxDmaBufToQueue(&SERIAL_PORTS.Lin, buf_USART2_DMA);
|
||||||
|
|
||||||
|
DMA_ModifyAddress(DMA_INSTANCE_0, SERIAL_PORTS.Lin.RX_DMA_CHANNEL, &(SERIAL_PORTS.Lin.UART->DATA),
|
||||||
|
(void *) ((uint32_t) (buf_USART2_DMA)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FCUART_IldeInterrupt_CallBack(uint8_t u8UartIndex) {
|
||||||
|
|
||||||
|
SerialPort_RxDmaBufToQueue(&SERIAL_PORTS.Lin, buf_USART2_DMA);
|
||||||
|
|
||||||
|
DMA_ModifyAddress(DMA_INSTANCE_0, SERIAL_PORTS.Lin.RX_DMA_CHANNEL, &(SERIAL_PORTS.Lin.UART->DATA), (void *)((uint32_t)(buf_USART2_DMA)));
|
||||||
|
|
||||||
|
PROCESS_UNUSED_VAR(u8UartIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FCUART_ErrorInterrupt_CallBack(uint8_t u8UartIndex, uint32_t u32Error) {
|
||||||
|
PROCESS_UNUSED_VAR(u8UartIndex)
|
||||||
|
PROCESS_UNUSED_VAR(u32Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FCUART_TxEmptyInterrupt_CallBack(uint8_t u8UartIndex, FCUART_DataType *pTxData) {
|
||||||
|
PROCESS_UNUSED_VAR(u8UartIndex)
|
||||||
|
PROCESS_UNUSED_VAR(pTxData)
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FCUART_TxCompleteInterrupt_CallBack(uint8_t u8UartIndex, FCUART_DataType *pTxData) {
|
||||||
|
PROCESS_UNUSED_VAR(u8UartIndex)
|
||||||
|
PROCESS_UNUSED_VAR(pTxData)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Настройка порта
|
||||||
|
static void vSerialPort_InitUSART2(tSerialPortFlagchip *env) {
|
||||||
|
PORT_InitType tInitStruct = {0};
|
||||||
|
GPIO_InitType tGpioInitStruct = {0};
|
||||||
|
|
||||||
|
// Port D6: MUX = ALT2, UART2_RX
|
||||||
|
tInitStruct.u32PortPins = PORT_PIN_6;
|
||||||
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTD_6_FCUART2_RX;
|
||||||
|
PORT_InitPins(PORT_D, &tInitStruct);
|
||||||
|
|
||||||
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_6;
|
||||||
|
tGpioInitStruct.ePinDirection = GPIO_IN;
|
||||||
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
||||||
|
|
||||||
|
// Port D7: MUX = ALT2, UART2_TX
|
||||||
|
tInitStruct.u32PortPins = PORT_PIN_7;
|
||||||
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTD_7_FCUART2_TX;
|
||||||
|
PORT_InitPins(PORT_D, &tInitStruct);
|
||||||
|
|
||||||
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_7;
|
||||||
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
||||||
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
||||||
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
||||||
|
|
||||||
|
vSerialPortInitDMA(
|
||||||
|
env,
|
||||||
|
|
||||||
|
FCUART2,
|
||||||
|
PCC_CLK_FCUART2,
|
||||||
|
115200,
|
||||||
|
|
||||||
|
2, // UART0 = 0 ... UART7 = 7
|
||||||
|
FCUART2_IRQn, // FCUART0_IRQn ... FCUART7_IRQn
|
||||||
|
0xFF,
|
||||||
|
|
||||||
|
DMA_CHANNEL_0,
|
||||||
|
DMA_REQ_FCUART2_RX,
|
||||||
|
|
||||||
|
buf_USART2_DMA,
|
||||||
|
sizeof(buf_USART2_DMA),
|
||||||
|
|
||||||
|
DMA0_IRQn,
|
||||||
|
0xFF, // IRQ_DMA_PRIORITY
|
||||||
|
2, // IRQ_DMA_CHANNEL_PRIORITY
|
||||||
|
|
||||||
|
1024,
|
||||||
|
1024,
|
||||||
|
|
||||||
|
DMA_USART2_TransferCompleteCallback,
|
||||||
|
DMA_USART2_ErrorCallback,
|
||||||
|
|
||||||
|
FCUART_IldeInterrupt_CallBack,
|
||||||
|
FCUART_ErrorInterrupt_CallBack,
|
||||||
|
|
||||||
|
FCUART_TxEmptyInterrupt_CallBack,
|
||||||
|
FCUART_TxCompleteInterrupt_CallBack
|
||||||
|
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
///конец------------------------------------------Модем-----------------------------------------------------------------
|
||||||
|
|
||||||
|
void SerialPorts_Init() {
|
||||||
|
|
||||||
|
tSerialPorts *env = &SERIAL_PORTS;
|
||||||
|
|
||||||
|
vSerialPort_InitUSART2(&env->Lin);
|
||||||
|
SERIAL_PORTS.Lin_IO = vSerialPortGetIo(&env->Lin);
|
||||||
|
|
||||||
|
//// Виртуальный сериал порт
|
||||||
|
SerialPortP2p_Init(&env->cliVirtualPort, 3 * 1024, 1024);
|
||||||
|
env->cliVirtualInIo = SerialPortP2p_GetIoFirst(&env->cliVirtualPort);
|
||||||
|
env->cliVirtualOutIo = SerialPortP2p_GetIoSecond(&env->cliVirtualPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 25.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef HVAC_M7_SERIALPORTS_H
|
||||||
|
#define HVAC_M7_SERIALPORTS_H
|
||||||
|
|
||||||
|
#include "SerialPortFlagchip.h"
|
||||||
|
#include "SerialPortP2p.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tSerialPortFlagchip Lin;
|
||||||
|
tSerialPortIO Lin_IO;
|
||||||
|
tSerialPortIO Lin_snif_IO;
|
||||||
|
|
||||||
|
tSerialPortP2p cliVirtualPort;
|
||||||
|
tSerialPortIO cliVirtualInIo;
|
||||||
|
tSerialPortIO cliVirtualOutIo;
|
||||||
|
|
||||||
|
} tSerialPorts;
|
||||||
|
|
||||||
|
extern tSerialPorts SERIAL_PORTS;
|
||||||
|
|
||||||
|
void SerialPorts_Init();
|
||||||
|
|
||||||
|
#endif //HVAC_M7_SERIALPORTS_H
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"./**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue