lpcmanager

Parents d6e1794f897a
Children 9d2ddec22c98
Added support for short uart Smarteh buffer (26bytes, 19200kbps). Buffer length and baudrate are initialised from Composer. Added control of CAN1 & CAN2 enable pin: When PLC app is started both drivers are enabled and then disabled when PLC app is stopped.
--- a/LPCBus/MC9_Devices_decl.c Wed Sep 21 10:31:30 2016 +0200
+++ b/LPCBus/MC9_Devices_decl.c Mon Oct 10 11:02:19 2016 +0200
@@ -505,7 +505,7 @@
/* Macro to transform milliseconds to ns */
#define msTOns(ms) (1000000L*ms)
-void InitUartPortDevices(void)
+void InitUartPortDevices_longBuffer(void)
{
unsigned char i=0;
@@ -577,67 +577,14 @@
uartPortTim[i].toValue = msTOns(50); /* 50ms */
uartPortTim[i].status = TIM_EN_RUNNING;
break;
-// case(130): /* P01, P02, P01V, P02V */
-// case(132):
-// case(134):
-// case(136):
- case(138): /* CA1 */
- case(140):
- case(142):
- case(144):
- case(154): /* CR1 */
- case(156):
- case(158):
- case(160):
- case(162): /* IR1V */
- case(164):
- case(166):
- case(168):
- case(186): /* TH1V */
- case(188):
- case(190):
- case(192):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(200); /* 200ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- break;
- case(146): /* CH1 */
- case(148):
- case(150):
- case(152):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(600); /* 600ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- break;
- case(170): /* ID1, ID2, ID3 */
- case(172):
- case(174):
- case(176):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(400); /* 400ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- break;
- case(194): /* DP1V */
- case(196):
- case(198):
- case(200):
- case(202): /* DP2V */
- case(204):
- case(206):
- case(208):
- case(210): /* DT1V */
- case(212):
- case(214):
- case(216):
- case(218): /* DU1V */
- case(220):
- case(222):
- case(224):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(400); /* 400ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- break;
-
+ case(240): /* 240-254 are reserved for EEPROM settings */
+ case(242):
+ case(244):
+ case(246):
+ case(248):
+ case(250):
+ case(252):
+ case(254):
default:
uartPortDevices[i] = NULL; /* "Empty" or unknown module */
uartPortTim[i].status = TIM_DISABLED;
@@ -647,3 +594,87 @@
}
}
+void InitUartPortDevices_shortBuffer(void)
+{
+ unsigned char i=0;
+
+ for(i=0;i<MAX_UART_DEVICES;i++)
+ {
+ switch(uartDev[i][1])
+ {
+ case(114): /* U0x */
+ case(116):
+ case(118):
+ case(120):
+ case(122):
+ case(124):
+ case(126):
+ case(128):
+ case(130): /* P01, P02, P01V, P02V */
+ case(132):
+ case(134):
+ case(136):
+ case(138): /* CA1 */
+ case(140):
+ case(142):
+ case(144):
+ case(154): /* CR1 */
+ case(156):
+ case(158):
+ case(160):
+ case(162): /* IR1V */
+ case(164):
+ case(166):
+ case(168):
+ case(186): /* TH1V */
+ case(188):
+ case(190):
+ case(192):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = 20; /* 20 x10ms = 200ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+ case(146): /* CH1 */
+ case(148):
+ case(150):
+ case(152):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = 60; /* 60 x10ms = 600ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+ case(170): /* ID1, ID2, ID3 */
+ case(172):
+ case(174):
+ case(176):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = 40; /* 40 x10ms = 400ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+ case(194): /* DP1V */
+ case(196):
+ case(198):
+ case(200):
+ case(202): /* DP2V */
+ case(204):
+ case(206):
+ case(208):
+ case(210): /* DT1V */
+ case(212):
+ case(214):
+ case(216):
+ case(218): /* DU1V */
+ case(220):
+ case(222):
+ case(224):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = 40; /* 40 x10ms = 400ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+
+ default:
+ uartPortDevices[i] = NULL; /* "Empty" or unknown module */
+ uartPortTim[i].status = TIM_DISABLED;
+ break;
+ }
+ }
+}
--- a/LPCBus/MC9_Devices_init.c Wed Sep 21 10:31:30 2016 +0200
+++ b/LPCBus/MC9_Devices_init.c Mon Oct 10 11:02:19 2016 +0200
@@ -20,9 +20,6 @@
bzero(&uartCommErrCntBuf, sizeof(uartCommErrCntBuf));
%(init_code)s
-// TODO XXX remove next 2 lines when initialization is done from Composer:
-uartBufSize = UART_BUFSIZE_LONG; // UART_BUFSIZE_SHORT
-uartBaudrate = 115200; // 19200
if((err = rt_mutex_create (&UART_WriteMutex, "UART_WriteMutex")))
return err;
@@ -36,13 +33,16 @@
return 1;
}
-UART_fd = openserial(serialdev, uartBaudrate);
+UART_fd = openserial(serialdev, uartBaudrate); /* uartBaudrate is initialized from Composer */
if (!UART_fd) {
fprintf(stderr, "Error while initializing %%s.\n", serialdev);
return 1;
}
-InitUartPortDevices();
+if(uartBufSize == UART_BUFSIZE_LONG) /* uartBufSize is initialized from Composer */
+ InitUartPortDevices_longBuffer();
+else
+ InitUartPortDevices_shortBuffer();
if((err = rt_task_create(&UART_task, "UART_task", 0, 50, T_JOINABLE)))
return err;
--- a/LPCBus/MC9_OnBoard_cleanup.c Wed Sep 21 10:31:30 2016 +0200
+++ b/LPCBus/MC9_OnBoard_cleanup.c Mon Oct 10 11:02:19 2016 +0200
@@ -5,5 +5,9 @@
rt_task_join(&RTU_task);
rt_mutex_delete(&RTU_BuffMutex);
gpio_close(RTU_GPIO_dev);
+gpio_set_pin_value(CAN0_EN_dev, 1);
+gpio_close(CAN0_EN_dev);
+gpio_set_pin_value(CAN1_EN_dev, 1);
+gpio_close(CAN1_EN_dev);
gpio_set_pin_value(RUN_LED_dev, 1);
gpio_close(RUN_LED_dev);
--- a/LPCBus/MC9_OnBoard_decl.c Wed Sep 21 10:31:30 2016 +0200
+++ b/LPCBus/MC9_OnBoard_decl.c Mon Oct 10 11:02:19 2016 +0200
@@ -23,6 +23,8 @@
struct gpio_device *RTU_GPIO_dev;
struct gpio_device *RUN_LED_dev;
+struct gpio_device *CAN0_EN_dev;
+struct gpio_device *CAN1_EN_dev;
static int write_file_bool(int fd, int value)
{
--- a/LPCBus/MC9_OnBoard_init.c Wed Sep 21 10:31:30 2016 +0200
+++ b/LPCBus/MC9_OnBoard_init.c Mon Oct 10 11:02:19 2016 +0200
@@ -10,6 +10,11 @@
%(init_code)s
+CAN0_EN_dev = gpio_open(21);
+gpio_set_pin_value(CAN0_EN_dev, 0);
+CAN1_EN_dev = gpio_open(17);
+gpio_set_pin_value(CAN1_EN_dev, 0);
+
RTU_GPIO_dev = gpio_open(111);
if (!RTU_GPIO_dev) {
fprintf(stderr, "Error while initializing RTU GPIO.\n");