Обновление
This commit is contained in:
commit
9e41782f73
|
|
@ -0,0 +1,104 @@
|
||||||
|
//
|
||||||
|
// Created by cfif on 03.06.2024.
|
||||||
|
//
|
||||||
|
#include "CanPorts.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "fc7xxx_driver_port.h"
|
||||||
|
#include "fc7xxx_driver_gpio.h"
|
||||||
|
|
||||||
|
tCanPorts CAN_PORTS;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t u32CanRAM[4];
|
||||||
|
} Can_RamType;
|
||||||
|
|
||||||
|
ALIGN(256) extern Can_RamType g_aRxDataBuf[16]; // dma ring buffer size is 256
|
||||||
|
|
||||||
|
static void DMA_TransferCompleteCallback(void) {
|
||||||
|
CanSerialPortFrameIrqRxProcessing(CAN_PORTS.Can0_IO.env, (uint32_t *)&g_aRxDataBuf[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DMA_ErrorCallback(void) {
|
||||||
|
while (1) {
|
||||||
|
__asm("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vCanPort_InitCAN0RxTxPin() {
|
||||||
|
PORT_InitType tInitStruct = {0U};
|
||||||
|
GPIO_InitType tGpioInitStruct = {0};
|
||||||
|
|
||||||
|
/* CAN0_STB */
|
||||||
|
/* PortC 30: MUX = GPIO output */
|
||||||
|
tInitStruct.u32PortPins = PORT_PIN_30;
|
||||||
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
||||||
|
PORT_InitPins(PORT_C, &tInitStruct);
|
||||||
|
tGpioInitStruct.u32GpioPins = PORT_PIN_30;
|
||||||
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
||||||
|
tGpioInitStruct.ePinLevel = GPIO_LOW;
|
||||||
|
GPIO_InitPins(GPIO_C, &tGpioInitStruct);
|
||||||
|
|
||||||
|
/* Port C2: MUX = ALT3, CAN0_RX */
|
||||||
|
tInitStruct.u32PortPins = PORT_PIN_2;
|
||||||
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTC_2_FLEXCAN0_RX;
|
||||||
|
tInitStruct.bPullEn = FALSE;
|
||||||
|
tInitStruct.ePullSel = PORT_PULL_UP;
|
||||||
|
PORT_InitPins(PORT_C, &tInitStruct);
|
||||||
|
tGpioInitStruct.u32GpioPins = PORT_PIN_2;
|
||||||
|
tGpioInitStruct.ePinDirection = GPIO_IN;
|
||||||
|
GPIO_InitPins((GPIO_InstanceType) PORT_C, &tGpioInitStruct);
|
||||||
|
|
||||||
|
/* Port C3: MUX = ALT3, CAN0_TX */
|
||||||
|
tInitStruct.u32PortPins = PORT_PIN_3;
|
||||||
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTC_3_FLEXCAN0_TX;
|
||||||
|
PORT_InitPins(PORT_C, &tInitStruct);
|
||||||
|
tGpioInitStruct.u32GpioPins = PORT_PIN_3;
|
||||||
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
||||||
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
||||||
|
GPIO_InitPins(GPIO_C, &tGpioInitStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vCanPort_InitCan0() {
|
||||||
|
vCanPort_InitCAN0RxTxPin();
|
||||||
|
|
||||||
|
vCanSerialPortFrameDMAInit(
|
||||||
|
&CAN_PORTS.Can0,
|
||||||
|
|
||||||
|
FLEXCAN0,
|
||||||
|
PCC_CLK_FLEXCAN0,
|
||||||
|
0, // CAN0 = 0 ... CAN3 = 3
|
||||||
|
|
||||||
|
FlexCAN0_IRQn, // FlexCAN0_IRQn ... FlexCAN3_IRQn
|
||||||
|
0xFF,
|
||||||
|
|
||||||
|
DMA_CHANNEL_1,
|
||||||
|
DMA_REQ_FLEXCAN0,
|
||||||
|
|
||||||
|
(uint8_t *)&g_aRxDataBuf[0],
|
||||||
|
|
||||||
|
DMA1_IRQn,
|
||||||
|
0x55,
|
||||||
|
1,
|
||||||
|
|
||||||
|
FLEXCAN_BAUD_500K,
|
||||||
|
FLEXCAN_ID_STD,
|
||||||
|
0x55,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
|
||||||
|
DMA_TransferCompleteCallback,
|
||||||
|
DMA_ErrorCallback
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CanPorts_Init() {
|
||||||
|
CAN_PORTS.Can0.reInit = false;
|
||||||
|
vCanPort_InitCan0();
|
||||||
|
CAN_PORTS.Can0_IO = CanPortFrame_GetIo(&CAN_PORTS.Can0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
//
|
||||||
|
// Created by cfif on 03.06.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SMART_COMPONENTS_CANPORTS_H
|
||||||
|
#define SMART_COMPONENTS_CANPORTS_H
|
||||||
|
|
||||||
|
#include "CanSerialPortFrame.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tCanSerialPortFrameFlagchip Can0;
|
||||||
|
tSerialPortFrameIO Can0_IO;
|
||||||
|
} tCanPorts;
|
||||||
|
|
||||||
|
extern tCanPorts CAN_PORTS;
|
||||||
|
|
||||||
|
void CanPorts_Init();
|
||||||
|
|
||||||
|
#endif //SMART_COMPONENTS_CANPORTS_H
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"./**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue