commit 9e41782f73a85d6d18970e7b92a2b32120ad400e Author: cfif Date: Tue Oct 7 15:12:11 2025 +0300 Обновление diff --git a/CanPorts.c b/CanPorts.c new file mode 100644 index 0000000..81952da --- /dev/null +++ b/CanPorts.c @@ -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); + +} \ No newline at end of file diff --git a/CanPorts.h b/CanPorts.h new file mode 100644 index 0000000..fdcaf4d --- /dev/null +++ b/CanPorts.h @@ -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 diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..0dd1901 --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file