424 lines
13 KiB
C
424 lines
13 KiB
C
//
|
|
// Created by Cfif on 14.12.23.
|
|
//
|
|
#include <stdbool.h>
|
|
#include "fc7xxx_driver_port.h"
|
|
#include "fc7xxx_driver_gpio.h"
|
|
#include "Lins.h"
|
|
|
|
tLinPorts LIN_PORTS;
|
|
|
|
|
|
|
|
//начало--------------------------LIN 1-------------------------------------------------
|
|
//начало--------------------------LIN 1-------------------------------------------------
|
|
//начало--------------------------LIN 1-------------------------------------------------
|
|
|
|
#define numOfClassicPID 20
|
|
|
|
const uint8_t classicPID[numOfClassicPID] = {
|
|
CFR_INI,
|
|
CFR_SET,
|
|
CFR_MOD,
|
|
CFR_ADR,
|
|
CFR_PRG,
|
|
DFR_PRG,
|
|
RFR_PRG,
|
|
RFR_ISSR1,
|
|
RFR_ISSR2,
|
|
RFR_ISSR3,
|
|
RFR_ISSR4,
|
|
RFR_ISSR5,
|
|
RFR_ISSR6,
|
|
RFR_ISSR7,
|
|
RFR_ISSR8,
|
|
RFR_ISSR9,
|
|
DFR_STA,
|
|
RFR_STA,
|
|
DFR_IDE,
|
|
RFR_IDE
|
|
};
|
|
|
|
static void Lin1CallbackHandler(uint8_t u8LinIndex, void *state) {
|
|
LIN_PORTS.lin1.LinExtCallbackHandler(LIN_PORTS.lin1.envCallExtBack, u8LinIndex, state);
|
|
}
|
|
|
|
void FCUART4_RxTx_IRQHandler(void) {
|
|
LIN_DrvIRQHandler(LIN_PORTS.lin1.UART_INDEX);
|
|
}
|
|
|
|
tLinData *Lin1_Init(lin_callback_ext_t Lin_ExtCallbackHandler) {
|
|
|
|
tLinPorts *env = &LIN_PORTS;
|
|
|
|
PORT_InitType tInitStruct = {0};
|
|
GPIO_InitType tGpioInitStruct = {0};
|
|
|
|
// Port D12: MUX = ALT3, UART4_RX
|
|
tInitStruct.u32PortPins = PORT_PIN_12;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTD_12_FCUART4_RX;
|
|
tInitStruct.bPullEn = true;
|
|
tInitStruct.ePullSel = PORT_PULL_UP;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_12;
|
|
tGpioInitStruct.ePinDirection = GPIO_IN;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
// Port D5: MUX = ALT3, UART4_TX
|
|
tInitStruct.u32PortPins = PORT_PIN_5;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTD_5_FCUART4_TX;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_5;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
// Port D18: MUX = GPIO output ENABLE
|
|
tInitStruct.u32PortPins = PORT_PIN_18;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_18;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
LIN_Initial(
|
|
&env->lin1,
|
|
FCUART4,
|
|
9600,
|
|
|
|
4, // UART0 = 0 ... UART7 = 7
|
|
FCUART4_IRQn, // FCUART0_IRQn ... FCUART7_IRQn
|
|
0xFF,
|
|
|
|
NULL,
|
|
Lin1CallbackHandler,
|
|
Lin_ExtCallbackHandler,
|
|
&env->lin1.linData,
|
|
|
|
classicPID,
|
|
numOfClassicPID
|
|
|
|
);
|
|
|
|
env->lin1_Io = vLinGetIo(&env->lin1);
|
|
|
|
return &env->lin1.linData;
|
|
}
|
|
|
|
//конец--------------------------LIN 1-------------------------------------------------
|
|
//конец--------------------------LIN 1-------------------------------------------------
|
|
//конец--------------------------LIN 1-------------------------------------------------
|
|
|
|
|
|
//начало--------------------------LIN 2-------------------------------------------------
|
|
//начало--------------------------LIN 2-------------------------------------------------
|
|
//начало--------------------------LIN 2-------------------------------------------------
|
|
static void Lin2CallbackHandler(uint8_t u8LinIndex, void *state) {
|
|
LIN_PORTS.lin2.LinExtCallbackHandler(LIN_PORTS.lin2.envCallExtBack, u8LinIndex, state);
|
|
}
|
|
|
|
void FCUART5_RxTx_IRQHandler(void) {
|
|
LIN_DrvIRQHandler(LIN_PORTS.lin2.UART_INDEX);
|
|
}
|
|
|
|
tLinData *Lin2_Init(lin_callback_ext_t Lin_ExtCallbackHandler) {
|
|
|
|
tLinPorts *env = &LIN_PORTS;
|
|
|
|
PORT_InitType tInitStruct = {0};
|
|
GPIO_InitType tGpioInitStruct = {0};
|
|
|
|
// Port C16: MUX = ALT7, UART5_RX
|
|
tInitStruct.u32PortPins = PORT_PIN_16;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTC_16_FCUART5_RX;
|
|
tInitStruct.bPullEn = true;
|
|
tInitStruct.ePullSel = PORT_PULL_UP;
|
|
PORT_InitPins(PORT_C, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_16;
|
|
tGpioInitStruct.ePinDirection = GPIO_IN;
|
|
GPIO_InitPins(GPIO_C, &tGpioInitStruct);
|
|
|
|
// Port C15: MUX = ALT7, UART5_TX
|
|
tInitStruct.u32PortPins = PORT_PIN_15;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTC_15_FCUART5_TX;
|
|
PORT_InitPins(PORT_C, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_15;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_C, &tGpioInitStruct);
|
|
|
|
// Port D19: MUX = GPIO output ENABLE
|
|
tInitStruct.u32PortPins = PORT_PIN_19;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_19;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
LIN_Initial(
|
|
&env->lin2,
|
|
FCUART5,
|
|
9600,
|
|
|
|
5, // UART0 = 0 ... UART7 = 7
|
|
FCUART5_IRQn, // FCUART0_IRQn ... FCUART7_IRQn
|
|
0xFF,
|
|
|
|
NULL,
|
|
Lin2CallbackHandler,
|
|
Lin_ExtCallbackHandler,
|
|
&env->lin2.linData,
|
|
|
|
classicPID,
|
|
numOfClassicPID
|
|
|
|
);
|
|
|
|
env->lin2_Io = vLinGetIo(&env->lin2);
|
|
|
|
return &env->lin2.linData;
|
|
}
|
|
|
|
//конец--------------------------LIN 2-------------------------------------------------
|
|
//конец--------------------------LIN 2-------------------------------------------------
|
|
//конец--------------------------LIN 2-------------------------------------------------
|
|
|
|
|
|
//начало--------------------------LIN 3-------------------------------------------------
|
|
//начало--------------------------LIN 3-------------------------------------------------
|
|
//начало--------------------------LIN 3-------------------------------------------------
|
|
static void Lin3CallbackHandler(uint8_t u8LinIndex, void *state) {
|
|
LIN_PORTS.lin3.LinExtCallbackHandler(LIN_PORTS.lin3.envCallExtBack, u8LinIndex, state);
|
|
}
|
|
|
|
void FCUART3_RxTx_IRQHandler(void) {
|
|
LIN_DrvIRQHandler(LIN_PORTS.lin3.UART_INDEX);
|
|
}
|
|
|
|
tLinData *Lin3_Init(lin_callback_ext_t Lin_ExtCallbackHandler) {
|
|
|
|
tLinPorts *env = &LIN_PORTS;
|
|
|
|
PORT_InitType tInitStruct = {0};
|
|
GPIO_InitType tGpioInitStruct = {0};
|
|
|
|
// Port D9: MUX = ALT7, UART3_RX
|
|
tInitStruct.u32PortPins = PORT_PIN_9;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTD_9_FCUART3_RX;
|
|
tInitStruct.bPullEn = true;
|
|
tInitStruct.ePullSel = PORT_PULL_UP;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_9;
|
|
tGpioInitStruct.ePinDirection = GPIO_IN;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
// Port C1: MUX = ALT7, UART3_TX
|
|
tInitStruct.u32PortPins = PORT_PIN_1;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTC_1_FCUART3_TX;
|
|
PORT_InitPins(PORT_C, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_1;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_C, &tGpioInitStruct);
|
|
|
|
// Port D20: MUX = GPIO output ENABLE
|
|
tInitStruct.u32PortPins = PORT_PIN_20;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_20;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
LIN_Initial(
|
|
&env->lin3,
|
|
FCUART3,
|
|
9600,
|
|
|
|
3, // UART0 = 0 ... UART7 = 7
|
|
FCUART3_IRQn, // FCUART0_IRQn ... FCUART7_IRQn
|
|
0xFF,
|
|
|
|
NULL,
|
|
Lin3CallbackHandler,
|
|
Lin_ExtCallbackHandler,
|
|
&env->lin3.linData,
|
|
|
|
classicPID,
|
|
numOfClassicPID
|
|
|
|
);
|
|
|
|
env->lin3_Io = vLinGetIo(&env->lin3);
|
|
|
|
return &env->lin3.linData;
|
|
}
|
|
|
|
//конец--------------------------LIN 3-------------------------------------------------
|
|
//конец--------------------------LIN 3-------------------------------------------------
|
|
//конец--------------------------LIN 3-------------------------------------------------
|
|
|
|
//начало--------------------------LIN 4-------------------------------------------------
|
|
//начало--------------------------LIN 4-------------------------------------------------
|
|
//начало--------------------------LIN 4-------------------------------------------------
|
|
static void Lin4CallbackHandler(uint8_t u8LinIndex, void *state) {
|
|
LIN_PORTS.lin4.LinExtCallbackHandler(LIN_PORTS.lin4.envCallExtBack, u8LinIndex, state);
|
|
}
|
|
|
|
void FCUART2_RxTx_IRQHandler(void) {
|
|
LIN_DrvIRQHandler(LIN_PORTS.lin4.UART_INDEX);
|
|
}
|
|
|
|
tLinData *Lin4_Init(lin_callback_ext_t Lin_ExtCallbackHandler) {
|
|
|
|
tLinPorts *env = &LIN_PORTS;
|
|
|
|
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;
|
|
tInitStruct.bPullEn = true;
|
|
tInitStruct.ePullSel = PORT_PULL_UP;
|
|
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);
|
|
|
|
// Port D8: MUX = GPIO output ENABLE
|
|
tInitStruct.u32PortPins = PORT_PIN_8;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_8;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
LIN_Initial(
|
|
&env->lin4,
|
|
FCUART2,
|
|
9600,
|
|
|
|
2, // UART0 = 0 ... UART7 = 7
|
|
FCUART2_IRQn, // FCUART0_IRQn ... FCUART7_IRQn
|
|
0xFF,
|
|
|
|
NULL,
|
|
Lin4CallbackHandler,
|
|
Lin_ExtCallbackHandler,
|
|
&env->lin4.linData,
|
|
|
|
classicPID,
|
|
numOfClassicPID
|
|
|
|
);
|
|
|
|
env->lin4_Io = vLinGetIo(&env->lin4);
|
|
|
|
return &env->lin4.linData;
|
|
}
|
|
|
|
//конец--------------------------LIN 4-------------------------------------------------
|
|
//конец--------------------------LIN 4-------------------------------------------------
|
|
//конец--------------------------LIN 4-------------------------------------------------
|
|
|
|
//начало--------------------------LIN 5-------------------------------------------------
|
|
//начало--------------------------LIN 5-------------------------------------------------
|
|
//начало--------------------------LIN 5-------------------------------------------------
|
|
static void Lin5CallbackHandler(uint8_t u8LinIndex, void *state) {
|
|
LIN_PORTS.lin5.LinExtCallbackHandler(LIN_PORTS.lin5.envCallExtBack, u8LinIndex, state);
|
|
}
|
|
|
|
void FCUART0_RxTx_IRQHandler(void) {
|
|
LIN_DrvIRQHandler(LIN_PORTS.lin5.UART_INDEX);
|
|
}
|
|
|
|
tLinData *Lin5_Init(lin_callback_ext_t Lin_ExtCallbackHandler) {
|
|
|
|
tLinPorts *env = &LIN_PORTS;
|
|
|
|
PORT_InitType tInitStruct = {0};
|
|
GPIO_InitType tGpioInitStruct = {0};
|
|
|
|
// Port A2: MUX = ALT6, UART0_RX
|
|
tInitStruct.u32PortPins = PORT_PIN_2;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTA_2_FCUART0_RX;
|
|
tInitStruct.bPullEn = true;
|
|
tInitStruct.ePullSel = PORT_PULL_UP;
|
|
PORT_InitPins(PORT_A, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_2;
|
|
tGpioInitStruct.ePinDirection = GPIO_IN;
|
|
GPIO_InitPins(GPIO_A, &tGpioInitStruct);
|
|
|
|
// Port A3: MUX = ALT6, UART0_TX
|
|
tInitStruct.u32PortPins = PORT_PIN_3;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORTA_3_FCUART0_TX;
|
|
PORT_InitPins(PORT_A, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_3;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_A, &tGpioInitStruct);
|
|
|
|
// Port D8: MUX = GPIO output ENABLE
|
|
tInitStruct.u32PortPins = PORT_PIN_8;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
|
PORT_InitPins(PORT_D, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = GPIO_PIN_8;
|
|
tGpioInitStruct.ePinDirection = GPIO_OUT;
|
|
tGpioInitStruct.ePinLevel = GPIO_HIGH;
|
|
GPIO_InitPins(GPIO_D, &tGpioInitStruct);
|
|
|
|
LIN_Initial(
|
|
&env->lin5,
|
|
FCUART0,
|
|
9600,
|
|
|
|
0, // UART0 = 0 ... UART7 = 7
|
|
FCUART0_IRQn, // FCUART0_IRQn ... FCUART7_IRQn
|
|
0xFF,
|
|
|
|
NULL,
|
|
Lin5CallbackHandler,
|
|
Lin_ExtCallbackHandler,
|
|
&env->lin5.linData,
|
|
|
|
classicPID,
|
|
numOfClassicPID
|
|
|
|
);
|
|
|
|
env->lin5_Io = vLinGetIo(&env->lin5);
|
|
|
|
return &env->lin5.linData;
|
|
}
|
|
|
|
//конец--------------------------LIN 5-------------------------------------------------
|
|
//конец--------------------------LIN 5-------------------------------------------------
|
|
//конец--------------------------LIN 5-------------------------------------------------
|