lpcmanager

Parents 030c244f6e84
Children 94f413797e6c
LPCArch : Name product "product" and architecture "arch". LPCBus : rename C code templates to make space for new target, added product/arch bus definitions in LPCBus.py
--- a/LPCArch.py Tue May 28 13:21:34 2019 +0200
+++ b/LPCArch.py Wed May 29 13:42:55 2019 +0200
@@ -1,15 +1,27 @@
#!/usr/bin/env python
# XXX Where is MC8 ?
-PLC_GOT_modules = ['GOT', 'GOT_111', 'GOT_131']
-PLC_MC9_modules = ['MC9', 'MW1']
-SOM28_modules = PLC_MC9_modules + PLC_GOT_modules
+WX_GOT_modules = ['GOT', 'GOT_111', 'GOT_131']
+SVG_GOT_modules = ['GOT6']
+MC9_modules = ['MC9', 'MW1']
+SOM28_modules = MC9_modules + WX_GOT_modules
+SOM6_modules = SVG_GOT_modules
-arch = None
+product = None
-def SetLPCArch(given):
- global arch
- arch = given
+def SetLPCProduct(given):
+ global product
+ product = given
+
+def GetLPCProduct():
+ return product
def GetLPCArch():
- return arch
+ if product in SOM28_modules:
+ bus_template_name = "MC9"
+ elif product in SOM6_modules:
+ bus_template_name = "MC10"
+ elif product is "MC8" :
+ bus_template_name = "MC8"
+ else:
+ bus_template_name = None
--- a/LPCBus.py Tue May 28 13:21:34 2019 +0200
+++ b/LPCBus.py Wed May 29 13:42:55 2019 +0200
@@ -3,31 +3,40 @@
modpath = os.path.split(__file__)[0]
-from LPCArch import GetLPCArch, SOM28_modules
+from LPCArch import GetLPCArch, GetLPCProduct, SOM28_modules
+
+product = GetLPCProduct()
arch = GetLPCArch()
-if arch in SOM28_modules:
- bus_template_name = "MC9"
-else:
- bus_template_name = arch
-
LPCBusSourcePath = os.path.join(modpath,"LPCBus")
def GetLocalCode(fname):
return open(os.path.join(LPCBusSourcePath,fname)).read()
-Busses = [ "Right", "On Board", "Devices" ]
+# busses available per architecture
+Busses = {"MC8" :[ ("Right", "uC_Right"),
+ ("On Board", "uC_OnBoard"),
+ ("Devices", "uC_Devices")],
+ "MC9" :[ ("Right", "SOM28_Right"),
+ ("On Board", "SOM_OnBoard"),
+ ("Devices", "SOM_Devices" ],
+ "MC10" :[("On Board", "SOM_OnBoard"),
+ ("Devices", "SOM_Devices" ]}
-# This matches names of .h files in LPCBus with Arch from LPCArch
+# This matches names of .h files in LPCBus with product from LPCArch
headernames = {
"MC9":"MC9",
"MW1":"MC9",
"GOT":"GOT",
"GOT_131":"GOT100",
- "GOT_111":"GOT100"
+ "GOT_111":"GOT100",
+ "GOT6":"GOT6"
}
-bus_template_code = { plc:GetLocalCode(plc+".c") for plc in ["MC8", "MC9"] }
+bus_template_code = { plc: GetLocalCode(
+ {"MC8": "uC",
+ "MC9": "SOM",
+ "MC10": "SOM"}[plc]+".c") for plc in Busses.keys()}
# This is in case some bus has some special LDFLAGS
@@ -223,16 +232,16 @@
"publish_code": "",
}
- bus_code = { "MC9:%s"%bus :
+ bus_code = { "%s:%s"%(arch, bus_name) :
{ section :
- header + GetLocalCode("%s_%s_%s.c"%("MC9",''.join(bus.split()),section))
+ header + GetLocalCode("%s_%s.c"%(bus_template,section))
for section, header in [
- ("decl",GetLocalCode("%s.h" % headernames[arch])),
+ ("decl",GetLocalCode("%s.h" % headernames[product])),
("init", ""),
("retrieve", ""),
("publish", ""),
("cleanup", "")]}
- for bus in Busses}
+ for bus_name, bus_template in Busses[arch]}
for module in GetModuleChildren(self):
if module["init"] != "":
@@ -279,7 +288,7 @@
if var["Publish"] != "":
code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n"
- BusName = bus_template_name + ":" + self.BaseParams.getName()
+ BusName = arch + ":" + self.BaseParams.getName()
def bcode(section):
@@ -297,12 +306,12 @@
"bus_publish_code": bcode("publish"),
})
- if bus_template_name not in bus_template_code:
- raise Exception, "Unknown arch %s. Please use %s"%(
- bus_template_name,repr(bus_template_code.keys()))
+ if arch not in bus_template_code:
+ raise Exception, "Unknown product %s. Please use %s"%(
+ arch,repr(bus_template_code.keys()))
Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
module = open(Gen_Module_path,'w')
- module.write(bus_template_code[bus_template_name] % code_str)
+ module.write(bus_template_code[arch] % code_str)
module.close()
cflags = '"-I%s" "-I%s" -Wno-unused-function'%(
--- a/LPCBus/MC9_Devices_cleanup.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-
-pthread_mutex_lock(&UART_WakeCondLock);
-
-UART_task_active = 0;
-pthread_cond_signal(&UART_WakeCond);
-pthread_mutex_unlock(&UART_WakeCondLock);
-pthread_join(UART_task, NULL);
-closeserial(UART_fd);
--- a/LPCBus/MC9_Devices_decl.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,576 +0,0 @@
-#include <stdio.h>
-#include <termios.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/select.h>
-
-#include <alchemy/task.h>
-#include <alchemy/mutex.h>
-#include <alchemy/timer.h>
-
-#include "beremiz.h"
-
-static struct termios oldterminfo;
-
-void closeserial(int fd)
-{
- tcsetattr(fd, TCSANOW, &oldterminfo);
- if (close(fd) < 0)
- perror("closeserial()");
-}
-
-/*--------------------------- Serial Port handling ---------------------------*/
-
-int openserial(char *devicename, unsigned long baudrate)
-{
- int fd;
- struct termios attr;
- speed_t baud = B115200; /* baud rate */
-
- switch(baudrate)
- {
- case 19200:
- baud = B19200;
- break;
- case 115200:
- baud = B115200;
- break;
- default:
- baud = B115200;
- }
-
- if ((fd = open(devicename, O_RDWR)) == -1) {
- perror("openserial(): open()");
- return 0;
- }
- if (tcgetattr(fd, &oldterminfo) == -1) {
- perror("openserial(): tcgetattr()");
- return 0;
- }
- attr = oldterminfo;
- attr.c_oflag = 0;
- attr.c_iflag = 0;
- attr.c_lflag = 0;
-
- attr.c_cflag = 0;
- attr.c_cflag |= CREAD;
- attr.c_cflag |= CLOCAL;
- attr.c_cflag |= CS8 ; /* 8 bits */
- /* no parity, 1 stop bit */
-
- cfsetspeed(&attr, baud); /* baud rate */
-
- if (tcflush(fd, TCIOFLUSH) == -1) {
- perror("openserial(): tcflush()");
- return 0;
- }
- if (tcsetattr(fd, TCSANOW, &attr) == -1) {
- perror("initserial(): tcsetattr()");
- return 0;
- }
-
- return fd;
-}
-
-
-#define EMPTY 0
-#define LOCKED 1
-#define FULL 2
-
-#define MAX_UART_DEVICES 32
-#define UART_BUFSIZE_SHORT 26 /* UART bus read & write buffer size - short buffer for LPC-2 */
-#define UART_BUFSIZE_LONG 48 /* UART bus read & write buffer size - long buffer for LHC-2 */
-#define UART_RETRY_NUM 0
-
-char uartBufSize = UART_BUFSIZE_SHORT; /* Smarteh uart bus: buffer size */
-unsigned long uartBaudrate = 19200; /* Smarteh uart bus: baudrate */
-struct timeval uartTimeout = {0,40000}; /* Smarteh uart bus: timeout */
-
-/* Tables containing information about connected devices on UART port
- (initialized by Composer) */
-unsigned char uartDev[MAX_UART_DEVICES][2];
-unsigned char uartDevNum = MAX_UART_DEVICES;
-
-/* Buffers for reading data from UART port devices */
-typedef char uartDevReadBuf_t[MAX_UART_DEVICES][UART_BUFSIZE_LONG];
-uartDevReadBuf_t uartDevReadBufA;
-uartDevReadBuf_t uartDevReadBufB;
-uartDevReadBuf_t *uartDevReadBuf_drv;
-uartDevReadBuf_t *uartDevReadBuf_plc;
-/* MC8 compatibility */
-uartDevReadBuf_t uartDevReadBuf;
-
-/* Buffers for writing data to UART port devices */
-typedef char uartDevWriteBuf_t[MAX_UART_DEVICES][UART_BUFSIZE_LONG];
-uartDevWriteBuf_t uartDevWriteBufA;
-uartDevWriteBuf_t uartDevWriteBufB;
-uartDevWriteBuf_t *uartDevWriteBuf_drv;
-uartDevWriteBuf_t *uartDevWriteBuf_plc;
-/* MC8 compatibility */
-#define uartDevWriteBuf (*uartDevWriteBuf_drv)
-
-int uartDevWriteBuf_plc_state;
-int uartDevReadBuf_plc_state;
-
-/* Buffers for communication statuses with UART port devices */
-/* 2D arrays due to compatibility with Composer (LpcSmartehIDE) */
-char uartCommErrCntBuf [MAX_UART_DEVICES][1];
-char uartCommStatusBuf[MAX_UART_DEVICES][1];
-
-/* Function interface definition for modules on UART (RS485) bus */
-typedef unsigned char (*uartPortFunct)(char*, char*, char);
-/* Table describing module positions on UART (RS485) bus (parsed from Composer data) */
-uartPortFunct uartPortDevices[MAX_UART_DEVICES] = {NULL};
-/* Table of timers (one for each position) */
-static commTimer uartPortTim[MAX_UART_DEVICES];
-
-static pthread_t UART_task;
-static pthread_mutex_t UART_WriteMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t UART_ReadMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER;
-static int UART_WakeCondValue = 0;
-static int UART_task_active;
-
-void* UART_task_proc(void *arg)
-{
- static unsigned char i=0;
- char commStat;
- uint64_t actTime;
- static uint64_t lastCommTime=0;
-
- struct sched_param param = { .sched_priority = 10 };
- pthread_setname_np(pthread_self(), "UART_task");
- pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
-
- while (1){
- int active;
- pthread_mutex_lock(&UART_WakeCondLock);
- active = UART_task_active;
- while(!UART_WakeCondValue && active){
- pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock);
- active = UART_task_active;
- }
-
- UART_WakeCondValue = 0;
- pthread_mutex_unlock(&UART_WakeCondLock);
-
- if(!active)
- break;
-
- // Communicate only with initialised UART devices
- if(uartPortDevices[i] != NULL)
- {
-
- // Timers for UART port modules
- if(uartPortTim[i].status != TIM_DISABLED)
- {
- struct timespec time_ref;
- if(clock_gettime(CLOCK_MONOTONIC, &time_ref)){
- perror("clock_gettime(time_ref)");
- }
- actTime = time_ref.tv_nsec + time_ref.tv_sec * 1000000000LL;
- uartPortTim[i].actValue = actTime - uartPortTim[i].oldTime;
-
- if((uartPortTim[i].actValue < uartPortTim[i].toValue)
- || (actTime - lastCommTime < 50000000))
- uartPortTim[i].status = TIM_EN_RUNNING;
- else {
- uartPortTim[i].status = TIM_EN_EXPIRED;
- uartPortTim[i].oldTime = actTime;
- lastCommTime = actTime;
- }
- }
-
- // Check timer status
- if((uartPortTim[i].status == TIM_DISABLED)
- || (uartPortTim[i].status == TIM_EN_EXPIRED))
- {
- if(!pthread_mutex_lock(&UART_WriteMutex)){
- if(uartDevWriteBuf_plc_state == FULL){
- uartDevWriteBuf_t *uartDevWriteBuf_tmp;
- uartDevWriteBuf_tmp = uartDevWriteBuf_plc;
- uartDevWriteBuf_plc = uartDevWriteBuf_drv;
- uartDevWriteBuf_drv = uartDevWriteBuf_tmp;
- uartDevWriteBuf_plc_state = EMPTY;
- }
- pthread_mutex_unlock(&UART_WriteMutex);
- }
-
- // Communicate with device
- commStat = (*uartPortDevices[i])(
- &uartDevReadBuf[i][0],
- &uartDevWriteBuf[i][0],
- uartDev[i][1]);
-
- memcpy(uartDevReadBuf_drv, &uartDevReadBuf, sizeof(uartDevReadBuf_t));
-
- if(!pthread_mutex_lock(&UART_ReadMutex)){
- if(uartDevReadBuf_plc_state == EMPTY){
- uartDevReadBuf_t *uartDevReadBuf_tmp;
- uartDevReadBuf_tmp = uartDevReadBuf_plc;
- uartDevReadBuf_plc = uartDevReadBuf_drv;
- uartDevReadBuf_drv = uartDevReadBuf_tmp;
- uartDevReadBuf_plc_state = FULL;
- }
- pthread_mutex_unlock(&UART_ReadMutex);
- }
-
- // Check communication status:
- if(commStat == TRUE)
- {
- uartCommStatusBuf[i][0] = TRUE;
- uartCommErrCntBuf[i][0] = 0;
- }
- else
- {
- if(uartCommErrCntBuf[i][0] < UART_RETRY_NUM)
- uartCommErrCntBuf[i][0]++;
- else
- uartCommStatusBuf[i][0] = FALSE;
- }
-
- // If timer is enabled, reset it's value,
- // otherwise keep it disabled
- if(uartPortTim[i].status != TIM_DISABLED)
- {
- uartPortTim[i].actValue = 0;
- uartPortTim[i].status = TIM_EN_RUNNING;
- }
- else /* Keep timer disabled */
- uartPortTim[i].status = TIM_DISABLED;
-
- // Procede with next UART device only after
- // communication with the current one is done
- if(i < (uartDevNum-1))
- i++;
- else /* Go back to the first UART device */
- i=0;
- }
- }
- else i=0;
- }
- return NULL;
-}
-
-#define TAIL_LEN 3 /* Length of data tail in bytes */
-/**************************************************************************//**
-* Calculate checksum of a buffer
-* @param [in] buffer Pointer to buffer
-* @param [in] bufLen Buffer length
-* @return Checksum values on buffer locations bufLen-TAIL_LEN &
-* bufLen-TAIL_LEN+1
-******************************************************************************/
-void Checksum(unsigned char *buffer, unsigned char bufLen)
-{
- unsigned char i=0, j=0;
- unsigned char checksum1=0, checksum2=0;
- unsigned char checksum1Temp=0;
-
- for(i=0;i<bufLen-TAIL_LEN;i++)
- {
- checksum1Temp=buffer[i];
- for(j=0;j<8;j++) /* Compute number of '1' of whole buff. */
- {
- if((checksum1Temp & 0x01)>0)
- checksum1++;
- checksum1Temp = checksum1Temp >> 1;
- }
- checksum2 = checksum2 ^ buffer[i]; /* Compute XOR of whole buffer */
- }
-
- buffer[bufLen-TAIL_LEN] = checksum2; /* Write number of '1' to buffer */
- buffer[bufLen-TAIL_LEN+1] = checksum1; /* Write XOR to buffer */
-}
-
-/**************************************************************************//**
-* Check if checksum values of received buffer are valid
-* @param [in] buffer Pointer to buffer
-* @param [in] bufLen Buffer length
-* @return TRUE if valid, otherwise FALSE
-******************************************************************************/
-unsigned char ChecksumValid(unsigned char *buffer, unsigned char bufLen)
-{
- unsigned char i=0, j=0;
- unsigned char checksum1=0, checksum2=0;
- unsigned char checksum1Temp=0;
-
- for(i=0;i<bufLen-TAIL_LEN;i++)
- {
- checksum1Temp = buffer[i];
- for(j=0;j<8;j++) /* Compute number of '1' of whole buff. */
- {
- if((checksum1Temp & 0x01)>0)
- checksum1++;
- checksum1Temp = checksum1Temp >> 1; /* Compute XOR of whole buffer */
- }
- checksum2 = checksum2 ^ buffer[i];
- }
-
- /* Check if computed checksums are the same as those in buffer (=> no error) */
- if((checksum2==buffer[bufLen-TAIL_LEN]) && (checksum1==buffer[bufLen-TAIL_LEN+1]))
- return TRUE;
- else
- return FALSE;
-}
-
-static int UART_fd;
-/*************************************************************************//**
-* Support for UART modules
-* @param [in] readBuf Pointer to read buffer (for previously polled UART device!)
-* @param [out] writeBuf Pointer to write buffer (for current device)
-* @param [in] address UART device address
-* @return TRUE if communication was successful, otherwise FALSE
-*****************************************************************************/
-unsigned char UARTDevice(char* readBuf, char* writeBuf, char address)
-{
- fd_set set;
- struct timeval timeout;
- int rv;
- int count = 0;
- char tmp[uartBufSize];
-
- /* Prepare transmit buffer */
- memcpy(tmp+1,writeBuf,uartBufSize-TAIL_LEN-1);
- tmp[0] = 'S';
- tmp[uartBufSize-TAIL_LEN] = address;
- Checksum((unsigned char*)tmp+1, uartBufSize);
-
- tcflush(UART_fd, TCIOFLUSH);
-
- if(write(UART_fd, tmp, uartBufSize) != uartBufSize){
- goto UARTDevfail;
- }
-
- FD_ZERO(&set); /* clear the set */
- FD_SET(UART_fd, &set); /* add our file descriptor to the set */
-
- timeout.tv_sec = uartTimeout.tv_sec;
- timeout.tv_usec = uartTimeout.tv_usec;
-
- while(count < uartBufSize){
- rv = select(UART_fd + 1, &set, NULL, NULL, &timeout);
- if(rv == -1)
- printf("RS485 select error\n");
- else if(rv == 0)
- {
- //printf("timeout\n");
- break;
- }
- else {
- int rr = read(UART_fd, tmp + count, uartBufSize - count);
- if(rr > 0){
- count += rr;
- }else{
- printf("RS485 read error %%d\n",rr);
- }
- }
- }
-
- /* Copy received buffer */
- if((count == uartBufSize) && (tmp[uartBufSize-TAIL_LEN] == address)){
- if(ChecksumValid((unsigned char*)tmp+1, uartBufSize)){
- memcpy(readBuf,tmp+1,uartBufSize-TAIL_LEN-1);
- return(TRUE);
- }
- }
-
- UARTDevfail:
- tcflush(UART_fd, TCIOFLUSH);
- return(FALSE);
-}
-
-/* Macro to transform milliseconds to ns */
-#define msTOns(ms) (1000000L*ms)
-
-void InitUartPortDevices_longBuffer(void)
-{
- unsigned char i=0;
-
- uartTimeout.tv_sec = 0;
- uartTimeout.tv_usec = 20000; /* 20 ms timeout */
-
- for(i=0;i<MAX_UART_DEVICES;i++)
- {
- switch(uartDev[i][1])
- {
- case(2): /* MU1 */
- case(4):
- case(6):
- case(8):
- case(10):
- case(12):
- case(14):
- case(16):
- case(18):
- case(20):
- case(22):
- case(24):
- case(26):
- case(28):
- case(30):
- case(32):
- case(34):
- case(36):
- case(38):
- case(40):
- case(42):
- case(44):
- case(46):
- case(48):
- case(66): /* MU2 */
- case(68):
- case(70):
- case(72):
- case(74): /* MU3 */
- case(76):
- case(78):
- case(80):
- case(82): /* MU4 */
- case(84):
- case(86):
- case(88):
- case(90): /* MU5 */
- case(92):
- case(94):
- case(96):
- case(98): /* MU6 */
- case(100):
- case(102):
- case(104):
- case(106): /* M4U */
- case(108):
- case(110):
- case(112):
- case(114): /* TH1 */
- case(116):
- case(118):
- case(120):
- case(122):
- case(124):
- case(126):
- case(128):
- case(130):
- case(132):
- case(134):
- case(136):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(50); /* 50ms */
- 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;
- uartDevNum--; /* Substract unused devices from MAX_UART_DEVICES */
- break;
- }
- }
-}
-
-void InitUartPortDevices_shortBuffer(void)
-{
- unsigned char i=0;
-
- uartTimeout.tv_sec = 0;
- uartTimeout.tv_usec = 40000; /* 40 ms timeout */
-
- 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(178): /* AQ1, SM1, SM5, SM6, SM7 */
- case(180):
- case(182):
- case(184):
- case(186): /* TH1V */
- case(188):
- case(190):
- case(192):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(250); /* 250ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- break;
- case(146): /* CH1 */
- case(148):
- case(150):
- case(152):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(650); /* 650ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- break;
- case(170): /* ID1, ID2, ID3 */
- case(172):
- case(174):
- case(176):
- 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):
- case(226): /* WP1 */
- case(228):
- case(230):
- case(232):
- case(234): /* WP2 */
- case(236):
- case(238):
- case(240):
- case(242): /* WT1 */
- case(244):
- case(246):
- case(248):
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(450); /* 450ms */
- 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 Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-int err;
-char *serialdev = "/dev/ttyAPP1";
-
-uartDevWriteBuf_plc_state = EMPTY;
-uartDevReadBuf_plc_state = EMPTY;
-bzero(&uartDev, sizeof(uartDev));
-
-bzero(&uartDevReadBufA, sizeof(uartDevReadBuf_t));
-bzero(&uartDevReadBufB, sizeof(uartDevReadBuf_t));
-uartDevReadBuf_drv = &uartDevReadBufA;
-uartDevReadBuf_plc = &uartDevReadBufB;
-
-bzero(&uartDevWriteBufA, sizeof(uartDevWriteBuf_t));
-bzero(&uartDevWriteBufB, sizeof(uartDevWriteBuf_t));
-uartDevWriteBuf_drv = &uartDevWriteBufA;
-uartDevWriteBuf_plc = &uartDevWriteBufB;
-
-bzero(&uartCommStatusBuf, sizeof(uartCommStatusBuf));
-bzero(&uartCommErrCntBuf, sizeof(uartCommErrCntBuf));
-
-%(init_code)s
-
-UART_fd = openserial(serialdev, uartBaudrate); /* uartBaudrate is initialized from Composer */
-if (!UART_fd) {
- fprintf(stderr, "Error while initializing %%s.\n", serialdev);
- return 1;
-}
-
-if(uartBufSize == UART_BUFSIZE_LONG) /* uartBufSize is initialized from Composer */
- InitUartPortDevices_longBuffer();
-else
- InitUartPortDevices_shortBuffer();
-
-UART_task_active = 1;
-
-if(err = pthread_create(&UART_task, NULL, &UART_task_proc, NULL));
- return err;
-
--- a/LPCBus/MC9_Devices_publish.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-if(!pthread_mutex_lock(&UART_WriteMutex)){
-
- int prevstate;
- prevstate=uartDevWriteBuf_plc_state;
- uartDevWriteBuf_plc_state = LOCKED;
-
- pthread_mutex_unlock(&UART_WriteMutex);
-
-%(publish_code)s
-
- /* unlock plc buffer */
- uartDevWriteBuf_plc_state = FULL;
-
- /* wakeup task */
- pthread_mutex_lock(&UART_WakeCondLock);
- UART_WakeCondValue = 1;
- pthread_cond_signal(&UART_WakeCond);
- pthread_mutex_unlock(&UART_WakeCondLock);
-}
--- a/LPCBus/MC9_Devices_retrieve.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-if(!pthread_mutex_lock(&UART_ReadMutex)){
-
- int prevstate;
- if((prevstate=uartDevReadBuf_plc_state) == FULL){
- uartDevReadBuf_plc_state = LOCKED;
- }
-
- pthread_mutex_unlock(&UART_ReadMutex);
-
- if(prevstate == FULL){
-
-%(retrieve_code)s
-
- /* unlock plc buffer */
- uartDevReadBuf_plc_state = EMPTY;
- }else{
- /* No new data -> no update */
- }
-}
--- a/LPCBus/MC9_OnBoard_cleanup.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-#ifdef ONBOARD_I2C
-if(onboardbusfd!=-1)
- close(onboardbusfd);
-#endif /* ONBOARD_I2C */
-
-#ifdef CAN0_EN_GPIO_0_21
-gpio_set_pin_value(CAN0_EN_dev, 1);
-gpio_close(CAN0_EN_dev);
-#endif /* CAN0_EN_GPIO_0_21 */
-
-#ifdef CAN1_EN_GPIO_0_17
-gpio_set_pin_value(CAN1_EN_dev, 1);
-gpio_close(CAN1_EN_dev);
-#endif /* CAN1_EN_GPIO_0_17 */
-
-gpio_set_pin_value(RUN_LED_dev, 1);
-gpio_close(RUN_LED_dev);
--- a/LPCBus/MC9_OnBoard_decl.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,170 +0,0 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include <rtdm/rtdm.h>
-#include "beremiz.h"
-
-/*------------------------- GPIO -------------------------------------*/
-/* from armadeus/target/packages/as_devices/c/as_gpio* */
-
-//#ifdef DEBUG
-# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-//#else
-//# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
-//#endif
-
-struct gpio_device {
- int port_num;
- int pin_file; /* pin file for 2.6.29 interface*/
-};
-
-struct gpio_device *RUN_LED_dev;
-#ifdef CAN0_EN_GPIO_0_21
-struct gpio_device *CAN0_EN_dev;
-#endif /* CAN0_EN_GPIO_0_21 */
-#ifdef CAN1_EN_GPIO_0_17
-struct gpio_device *CAN1_EN_dev;
-#endif /* CAN1_EN_GPIO_0_17 */
-
-static int write_file_bool(int fd, int value)
-{
- int ret;
-
- ret = write(fd, value?"1":"0", 1);
- if (ret < 0) {
- ERROR("write error\n");
- return ret;
- }
- if (lseek(fd, 0, SEEK_SET) < 0) {
- ERROR("lseek error\n");
- return ret;
- }
-
- return ret;
-}
-
-#define BUFF_SIZE 256
-static int gpio_set_pin_value(struct gpio_device *aDev, int aValue)
-{
- int pin_file = aDev->pin_file;
- int retval;
-
- retval = write_file_bool(pin_file, aValue);
- if (retval < 0) {
- ERROR("Can't write value\n");
- close(pin_file);
- return -1;
- }
-
- return aValue;
-}
-
-static struct gpio_device *gpio_open(int aGpioNum)
-{
- struct gpio_device *dev;
- int pin_file;
- int export_file;
- int gpio_dir_fd;
- int retval;
- char buf[BUFF_SIZE];
- int ret = 0;
-
- export_file = open("/sys/class/gpio/export", O_WRONLY);
- if (export_file < 0) {
- ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
- return NULL;
- }
-
- snprintf(buf, BUFF_SIZE, "%%d", aGpioNum);
- retval = write(export_file, buf, strlen(buf));
- close(export_file);
- if (retval < 0) {
- ERROR("/sys/class/gpio/export can't be written\n");
- return NULL;
- }
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/direction", aGpioNum);
- gpio_dir_fd = open(buf, O_WRONLY);
- if (gpio_dir_fd < 0) {
- ERROR("Can't open gpio%%d direction\n", aGpioNum);
- return NULL;
- }
-
- ret = write(gpio_dir_fd, "out", 3);
- close(gpio_dir_fd);
- if (ret < 0){
- ERROR("Error writing direction\n");
- return NULL;
- }
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/value", aGpioNum);
- pin_file = open(buf, O_RDWR);
- if (pin_file < 0) {
- ERROR("Can't export gpio number %%d\n", aGpioNum);
- return NULL;
- }
-
- dev = malloc(sizeof(struct gpio_device));
- if (dev == NULL) {
- ERROR("Can't allocate gpio_device structure\n");
- close(pin_file);
- return NULL;
- }
-
- dev->port_num = aGpioNum;
- dev->pin_file = pin_file;
-
- gpio_set_pin_value(dev, 1);
-
- return dev;
-}
-
-static int gpio_close(struct gpio_device *aDev)
-{
- int unexport_file;
- char buf[BUFF_SIZE];
- int retval;
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -1;
- }
-
- unexport_file = open("/sys/class/gpio/unexport", O_WRONLY);
- if (unexport_file < 0) {
- ERROR("Can't open /sys/class/gpio/unexport\nBe sure that gpiolib is under your kernel\n");
- return -1;
- }
-
- snprintf(buf, BUFF_SIZE, "%%d", aDev->port_num);
- retval = write(unexport_file, buf, strlen(buf));
- close(unexport_file);
- if (retval < 0) {
- ERROR("/sys/class/gpio/unexport can't be written\n");
- return -1;
- }
-
- close(aDev->pin_file);
-
- return 0;
-}
-
-/* TODO : DELETE !... but keep this until composer stops sending code snippets for mbrtu */
-typedef enum
-{
- MB_PAR_ODD = 0, /**< ODD parity. */
- MB_PAR_EVEN = 1, /**< Even parity. */
- MB_PAR_NONE = 2 /**< No parity. */
-} eMBSerialParity;
-unsigned long mbBaudRate = 115200; /**< Modbus baud-rate setting: 9600, 19200, 38400, 57600, 115200 */
-eMBSerialParity mbParity = MB_PAR_NONE; /**< Modbus parity setting: odd, even, none */
-
-#ifdef ONBOARD_I2C
-
-#include "rt_imx_smt_onboard.h"
-
-static readBuf_t onBoardReadBuf;
-static writeBuf_t onBoardWriteBuf;
-static busInit_t onBoardBusInit;
-
-static int onboardbusfd = -1;
-#endif /* ONBOARD_I2C */
--- a/LPCBus/MC9_OnBoard_init.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#define ONBOARDDEVFILENAME "/dev/rtdm/onboard"
-
-int err;
-
-#ifdef ONBOARD_I2C
-bzero(&onBoardReadBuf , sizeof(readBuf_t));
-bzero(&onBoardWriteBuf, sizeof(writeBuf_t));
-bzero(&onBoardBusInit , sizeof(busInit_t));
-
-onBoardBusInit.common_ticktime__ = common_ticktime__;
-#define onBoardDev (onBoardBusInit.rightI2CMod)
-#endif /* ONBOARD_I2C */
-
-%(init_code)s
-
-#ifdef CAN0_EN_GPIO_0_21
-CAN0_EN_dev = gpio_open(21);
-gpio_set_pin_value(CAN0_EN_dev, 0);
-#endif /* CAN0_EN_GPIO_0_21 */
-#ifdef CAN1_EN_GPIO_0_17
-CAN1_EN_dev = gpio_open(17);
-gpio_set_pin_value(CAN1_EN_dev, 0);
-#endif /* CAN1_EN_GPIO_0_17 */
-
-#ifdef ONBOARD_I2C
-unsigned char i;
-for(i=0; i<MAX_RIGHT_MODULES; i++) {
- switch(onBoardDev[i][1]) {
- case 1:
- /* OnBoard I2C bus */
- onboardbusfd = open(ONBOARDDEVFILENAME, 0);
- if(onboardbusfd < 0) {
- printf("can't open %%s rtdm device, %%s\n", ONBOARDDEVFILENAME,
- strerror(-onboardbusfd));
- return onboardbusfd;
- }
- err = ioctl(onboardbusfd, RTSMT_RTIOC_INIT, &onBoardBusInit);
- if(err) {
- printf("error while RTSMT_RTIOC_INIT, %%s\n", strerror(-err));
- close(onboardbusfd);
- return err;
- }
- break;
- default:
- break;
- }
-}
-#endif /* ONBOARD_I2C */
-
-#if defined RUN_LED_GPIO_1_13
-RUN_LED_dev = gpio_open(45);
-#elif defined RUN_LED_GPIO_1_31
-RUN_LED_dev = gpio_open(63);
-#endif /* RUN LED GPIO_1_13/GPIO_1_31 */
-gpio_set_pin_value(RUN_LED_dev, 0);
--- a/LPCBus/MC9_OnBoard_publish.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-%(publish_code)s
-
-#ifdef ONBOARD_I2C
-if(onboardbusfd!=-1)
- ioctl(onboardbusfd, RTSMT_RTIOC_WRITE, &onBoardWriteBuf);
-#endif /* ONBOARD_I2C */
--- a/LPCBus/MC9_OnBoard_retrieve.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifdef ONBOARD_I2C
-if(onboardbusfd!=-1)
- ioctl(onboardbusfd, RTSMT_RTIOC_READ, &onBoardReadBuf);
-#endif /* ONBOARD_I2C */
-
-%(retrieve_code)s
--- a/LPCBus/MC9_Right_cleanup.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-close(rightbusfd);
--- a/LPCBus/MC9_Right_decl.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-
-#include <rtdm/rtdm.h>
-#include "beremiz.h"
-#include "rt_imx_smt_right.h"
-
-static readBuf_t rightReadBuf;
-static writeBuf_t rightWriteBuf;
-static busInit_t rightBusInit;
-
-static int rightbusfd = -1;
-
-/* XXX TODO #include "smarteh.h" */
--- a/LPCBus/MC9_Right_init.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#define DEVICEFILENAME "/dev/rtdm/rightbus"
-
-bzero(&rightReadBuf, sizeof(readBuf_t));
-bzero(&rightWriteBuf, sizeof(writeBuf_t));
-bzero(&rightBusInit, sizeof(busInit_t));
-
-rightBusInit.common_ticktime__ = common_ticktime__;
-
-#define rightI2CMod (rightBusInit.rightI2CMod)
-%(init_code)s
-
-int err;
-rightbusfd = open( DEVICEFILENAME, 0);
-if (rightbusfd < 0) {
- printf("can't open %%s rtdm device, %%s\\n", DEVICEFILENAME,
- strerror(-rightbusfd));
- return rightbusfd;
-}
-
-err = ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit);
-if (err) {
- printf("error while RTSMT_RTIOC_INIT, %%s\\n",
- strerror(-err));
- close(rightbusfd);
- return err;
-}
--- a/LPCBus/MC9_Right_publish.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-%(publish_code)s
-ioctl(rightbusfd, RTSMT_RTIOC_WRITE, &rightWriteBuf);
--- a/LPCBus/MC9_Right_retrieve.c Tue May 28 13:21:34 2019 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-ioctl(rightbusfd, RTSMT_RTIOC_READ, &rightReadBuf);
-%(retrieve_code)s
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM28_Right_cleanup.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,1 @@
+close(rightbusfd);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM28_Right_decl.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,12 @@
+
+#include <rtdm/rtdm.h>
+#include "beremiz.h"
+#include "rt_imx_smt_right.h"
+
+static readBuf_t rightReadBuf;
+static writeBuf_t rightWriteBuf;
+static busInit_t rightBusInit;
+
+static int rightbusfd = -1;
+
+/* XXX TODO #include "smarteh.h" */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM28_Right_init.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,26 @@
+#define DEVICEFILENAME "/dev/rtdm/rightbus"
+
+bzero(&rightReadBuf, sizeof(readBuf_t));
+bzero(&rightWriteBuf, sizeof(writeBuf_t));
+bzero(&rightBusInit, sizeof(busInit_t));
+
+rightBusInit.common_ticktime__ = common_ticktime__;
+
+#define rightI2CMod (rightBusInit.rightI2CMod)
+%(init_code)s
+
+int err;
+rightbusfd = open( DEVICEFILENAME, 0);
+if (rightbusfd < 0) {
+ printf("can't open %%s rtdm device, %%s\\n", DEVICEFILENAME,
+ strerror(-rightbusfd));
+ return rightbusfd;
+}
+
+err = ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit);
+if (err) {
+ printf("error while RTSMT_RTIOC_INIT, %%s\\n",
+ strerror(-err));
+ close(rightbusfd);
+ return err;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM28_Right_publish.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,2 @@
+%(publish_code)s
+ioctl(rightbusfd, RTSMT_RTIOC_WRITE, &rightWriteBuf);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM28_Right_retrieve.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,2 @@
+ioctl(rightbusfd, RTSMT_RTIOC_READ, &rightReadBuf);
+%(retrieve_code)s
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_Devices_cleanup.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,8 @@
+
+pthread_mutex_lock(&UART_WakeCondLock);
+
+UART_task_active = 0;
+pthread_cond_signal(&UART_WakeCond);
+pthread_mutex_unlock(&UART_WakeCondLock);
+pthread_join(UART_task, NULL);
+closeserial(UART_fd);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_Devices_decl.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,576 @@
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <sys/select.h>
+
+#include <alchemy/task.h>
+#include <alchemy/mutex.h>
+#include <alchemy/timer.h>
+
+#include "beremiz.h"
+
+static struct termios oldterminfo;
+
+void closeserial(int fd)
+{
+ tcsetattr(fd, TCSANOW, &oldterminfo);
+ if (close(fd) < 0)
+ perror("closeserial()");
+}
+
+/*--------------------------- Serial Port handling ---------------------------*/
+
+int openserial(char *devicename, unsigned long baudrate)
+{
+ int fd;
+ struct termios attr;
+ speed_t baud = B115200; /* baud rate */
+
+ switch(baudrate)
+ {
+ case 19200:
+ baud = B19200;
+ break;
+ case 115200:
+ baud = B115200;
+ break;
+ default:
+ baud = B115200;
+ }
+
+ if ((fd = open(devicename, O_RDWR)) == -1) {
+ perror("openserial(): open()");
+ return 0;
+ }
+ if (tcgetattr(fd, &oldterminfo) == -1) {
+ perror("openserial(): tcgetattr()");
+ return 0;
+ }
+ attr = oldterminfo;
+ attr.c_oflag = 0;
+ attr.c_iflag = 0;
+ attr.c_lflag = 0;
+
+ attr.c_cflag = 0;
+ attr.c_cflag |= CREAD;
+ attr.c_cflag |= CLOCAL;
+ attr.c_cflag |= CS8 ; /* 8 bits */
+ /* no parity, 1 stop bit */
+
+ cfsetspeed(&attr, baud); /* baud rate */
+
+ if (tcflush(fd, TCIOFLUSH) == -1) {
+ perror("openserial(): tcflush()");
+ return 0;
+ }
+ if (tcsetattr(fd, TCSANOW, &attr) == -1) {
+ perror("initserial(): tcsetattr()");
+ return 0;
+ }
+
+ return fd;
+}
+
+
+#define EMPTY 0
+#define LOCKED 1
+#define FULL 2
+
+#define MAX_UART_DEVICES 32
+#define UART_BUFSIZE_SHORT 26 /* UART bus read & write buffer size - short buffer for LPC-2 */
+#define UART_BUFSIZE_LONG 48 /* UART bus read & write buffer size - long buffer for LHC-2 */
+#define UART_RETRY_NUM 0
+
+char uartBufSize = UART_BUFSIZE_SHORT; /* Smarteh uart bus: buffer size */
+unsigned long uartBaudrate = 19200; /* Smarteh uart bus: baudrate */
+struct timeval uartTimeout = {0,40000}; /* Smarteh uart bus: timeout */
+
+/* Tables containing information about connected devices on UART port
+ (initialized by Composer) */
+unsigned char uartDev[MAX_UART_DEVICES][2];
+unsigned char uartDevNum = MAX_UART_DEVICES;
+
+/* Buffers for reading data from UART port devices */
+typedef char uartDevReadBuf_t[MAX_UART_DEVICES][UART_BUFSIZE_LONG];
+uartDevReadBuf_t uartDevReadBufA;
+uartDevReadBuf_t uartDevReadBufB;
+uartDevReadBuf_t *uartDevReadBuf_drv;
+uartDevReadBuf_t *uartDevReadBuf_plc;
+/* MC8 compatibility */
+uartDevReadBuf_t uartDevReadBuf;
+
+/* Buffers for writing data to UART port devices */
+typedef char uartDevWriteBuf_t[MAX_UART_DEVICES][UART_BUFSIZE_LONG];
+uartDevWriteBuf_t uartDevWriteBufA;
+uartDevWriteBuf_t uartDevWriteBufB;
+uartDevWriteBuf_t *uartDevWriteBuf_drv;
+uartDevWriteBuf_t *uartDevWriteBuf_plc;
+/* MC8 compatibility */
+#define uartDevWriteBuf (*uartDevWriteBuf_drv)
+
+int uartDevWriteBuf_plc_state;
+int uartDevReadBuf_plc_state;
+
+/* Buffers for communication statuses with UART port devices */
+/* 2D arrays due to compatibility with Composer (LpcSmartehIDE) */
+char uartCommErrCntBuf [MAX_UART_DEVICES][1];
+char uartCommStatusBuf[MAX_UART_DEVICES][1];
+
+/* Function interface definition for modules on UART (RS485) bus */
+typedef unsigned char (*uartPortFunct)(char*, char*, char);
+/* Table describing module positions on UART (RS485) bus (parsed from Composer data) */
+uartPortFunct uartPortDevices[MAX_UART_DEVICES] = {NULL};
+/* Table of timers (one for each position) */
+static commTimer uartPortTim[MAX_UART_DEVICES];
+
+static pthread_t UART_task;
+static pthread_mutex_t UART_WriteMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t UART_ReadMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER;
+static int UART_WakeCondValue = 0;
+static int UART_task_active;
+
+void* UART_task_proc(void *arg)
+{
+ static unsigned char i=0;
+ char commStat;
+ uint64_t actTime;
+ static uint64_t lastCommTime=0;
+
+ struct sched_param param = { .sched_priority = 10 };
+ pthread_setname_np(pthread_self(), "UART_task");
+ pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
+
+ while (1){
+ int active;
+ pthread_mutex_lock(&UART_WakeCondLock);
+ active = UART_task_active;
+ while(!UART_WakeCondValue && active){
+ pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock);
+ active = UART_task_active;
+ }
+
+ UART_WakeCondValue = 0;
+ pthread_mutex_unlock(&UART_WakeCondLock);
+
+ if(!active)
+ break;
+
+ // Communicate only with initialised UART devices
+ if(uartPortDevices[i] != NULL)
+ {
+
+ // Timers for UART port modules
+ if(uartPortTim[i].status != TIM_DISABLED)
+ {
+ struct timespec time_ref;
+ if(clock_gettime(CLOCK_MONOTONIC, &time_ref)){
+ perror("clock_gettime(time_ref)");
+ }
+ actTime = time_ref.tv_nsec + time_ref.tv_sec * 1000000000LL;
+ uartPortTim[i].actValue = actTime - uartPortTim[i].oldTime;
+
+ if((uartPortTim[i].actValue < uartPortTim[i].toValue)
+ || (actTime - lastCommTime < 50000000))
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ else {
+ uartPortTim[i].status = TIM_EN_EXPIRED;
+ uartPortTim[i].oldTime = actTime;
+ lastCommTime = actTime;
+ }
+ }
+
+ // Check timer status
+ if((uartPortTim[i].status == TIM_DISABLED)
+ || (uartPortTim[i].status == TIM_EN_EXPIRED))
+ {
+ if(!pthread_mutex_lock(&UART_WriteMutex)){
+ if(uartDevWriteBuf_plc_state == FULL){
+ uartDevWriteBuf_t *uartDevWriteBuf_tmp;
+ uartDevWriteBuf_tmp = uartDevWriteBuf_plc;
+ uartDevWriteBuf_plc = uartDevWriteBuf_drv;
+ uartDevWriteBuf_drv = uartDevWriteBuf_tmp;
+ uartDevWriteBuf_plc_state = EMPTY;
+ }
+ pthread_mutex_unlock(&UART_WriteMutex);
+ }
+
+ // Communicate with device
+ commStat = (*uartPortDevices[i])(
+ &uartDevReadBuf[i][0],
+ &uartDevWriteBuf[i][0],
+ uartDev[i][1]);
+
+ memcpy(uartDevReadBuf_drv, &uartDevReadBuf, sizeof(uartDevReadBuf_t));
+
+ if(!pthread_mutex_lock(&UART_ReadMutex)){
+ if(uartDevReadBuf_plc_state == EMPTY){
+ uartDevReadBuf_t *uartDevReadBuf_tmp;
+ uartDevReadBuf_tmp = uartDevReadBuf_plc;
+ uartDevReadBuf_plc = uartDevReadBuf_drv;
+ uartDevReadBuf_drv = uartDevReadBuf_tmp;
+ uartDevReadBuf_plc_state = FULL;
+ }
+ pthread_mutex_unlock(&UART_ReadMutex);
+ }
+
+ // Check communication status:
+ if(commStat == TRUE)
+ {
+ uartCommStatusBuf[i][0] = TRUE;
+ uartCommErrCntBuf[i][0] = 0;
+ }
+ else
+ {
+ if(uartCommErrCntBuf[i][0] < UART_RETRY_NUM)
+ uartCommErrCntBuf[i][0]++;
+ else
+ uartCommStatusBuf[i][0] = FALSE;
+ }
+
+ // If timer is enabled, reset it's value,
+ // otherwise keep it disabled
+ if(uartPortTim[i].status != TIM_DISABLED)
+ {
+ uartPortTim[i].actValue = 0;
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ }
+ else /* Keep timer disabled */
+ uartPortTim[i].status = TIM_DISABLED;
+
+ // Procede with next UART device only after
+ // communication with the current one is done
+ if(i < (uartDevNum-1))
+ i++;
+ else /* Go back to the first UART device */
+ i=0;
+ }
+ }
+ else i=0;
+ }
+ return NULL;
+}
+
+#define TAIL_LEN 3 /* Length of data tail in bytes */
+/**************************************************************************//**
+* Calculate checksum of a buffer
+* @param [in] buffer Pointer to buffer
+* @param [in] bufLen Buffer length
+* @return Checksum values on buffer locations bufLen-TAIL_LEN &
+* bufLen-TAIL_LEN+1
+******************************************************************************/
+void Checksum(unsigned char *buffer, unsigned char bufLen)
+{
+ unsigned char i=0, j=0;
+ unsigned char checksum1=0, checksum2=0;
+ unsigned char checksum1Temp=0;
+
+ for(i=0;i<bufLen-TAIL_LEN;i++)
+ {
+ checksum1Temp=buffer[i];
+ for(j=0;j<8;j++) /* Compute number of '1' of whole buff. */
+ {
+ if((checksum1Temp & 0x01)>0)
+ checksum1++;
+ checksum1Temp = checksum1Temp >> 1;
+ }
+ checksum2 = checksum2 ^ buffer[i]; /* Compute XOR of whole buffer */
+ }
+
+ buffer[bufLen-TAIL_LEN] = checksum2; /* Write number of '1' to buffer */
+ buffer[bufLen-TAIL_LEN+1] = checksum1; /* Write XOR to buffer */
+}
+
+/**************************************************************************//**
+* Check if checksum values of received buffer are valid
+* @param [in] buffer Pointer to buffer
+* @param [in] bufLen Buffer length
+* @return TRUE if valid, otherwise FALSE
+******************************************************************************/
+unsigned char ChecksumValid(unsigned char *buffer, unsigned char bufLen)
+{
+ unsigned char i=0, j=0;
+ unsigned char checksum1=0, checksum2=0;
+ unsigned char checksum1Temp=0;
+
+ for(i=0;i<bufLen-TAIL_LEN;i++)
+ {
+ checksum1Temp = buffer[i];
+ for(j=0;j<8;j++) /* Compute number of '1' of whole buff. */
+ {
+ if((checksum1Temp & 0x01)>0)
+ checksum1++;
+ checksum1Temp = checksum1Temp >> 1; /* Compute XOR of whole buffer */
+ }
+ checksum2 = checksum2 ^ buffer[i];
+ }
+
+ /* Check if computed checksums are the same as those in buffer (=> no error) */
+ if((checksum2==buffer[bufLen-TAIL_LEN]) && (checksum1==buffer[bufLen-TAIL_LEN+1]))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static int UART_fd;
+/*************************************************************************//**
+* Support for UART modules
+* @param [in] readBuf Pointer to read buffer (for previously polled UART device!)
+* @param [out] writeBuf Pointer to write buffer (for current device)
+* @param [in] address UART device address
+* @return TRUE if communication was successful, otherwise FALSE
+*****************************************************************************/
+unsigned char UARTDevice(char* readBuf, char* writeBuf, char address)
+{
+ fd_set set;
+ struct timeval timeout;
+ int rv;
+ int count = 0;
+ char tmp[uartBufSize];
+
+ /* Prepare transmit buffer */
+ memcpy(tmp+1,writeBuf,uartBufSize-TAIL_LEN-1);
+ tmp[0] = 'S';
+ tmp[uartBufSize-TAIL_LEN] = address;
+ Checksum((unsigned char*)tmp+1, uartBufSize);
+
+ tcflush(UART_fd, TCIOFLUSH);
+
+ if(write(UART_fd, tmp, uartBufSize) != uartBufSize){
+ goto UARTDevfail;
+ }
+
+ FD_ZERO(&set); /* clear the set */
+ FD_SET(UART_fd, &set); /* add our file descriptor to the set */
+
+ timeout.tv_sec = uartTimeout.tv_sec;
+ timeout.tv_usec = uartTimeout.tv_usec;
+
+ while(count < uartBufSize){
+ rv = select(UART_fd + 1, &set, NULL, NULL, &timeout);
+ if(rv == -1)
+ printf("RS485 select error\n");
+ else if(rv == 0)
+ {
+ //printf("timeout\n");
+ break;
+ }
+ else {
+ int rr = read(UART_fd, tmp + count, uartBufSize - count);
+ if(rr > 0){
+ count += rr;
+ }else{
+ printf("RS485 read error %%d\n",rr);
+ }
+ }
+ }
+
+ /* Copy received buffer */
+ if((count == uartBufSize) && (tmp[uartBufSize-TAIL_LEN] == address)){
+ if(ChecksumValid((unsigned char*)tmp+1, uartBufSize)){
+ memcpy(readBuf,tmp+1,uartBufSize-TAIL_LEN-1);
+ return(TRUE);
+ }
+ }
+
+ UARTDevfail:
+ tcflush(UART_fd, TCIOFLUSH);
+ return(FALSE);
+}
+
+/* Macro to transform milliseconds to ns */
+#define msTOns(ms) (1000000L*ms)
+
+void InitUartPortDevices_longBuffer(void)
+{
+ unsigned char i=0;
+
+ uartTimeout.tv_sec = 0;
+ uartTimeout.tv_usec = 20000; /* 20 ms timeout */
+
+ for(i=0;i<MAX_UART_DEVICES;i++)
+ {
+ switch(uartDev[i][1])
+ {
+ case(2): /* MU1 */
+ case(4):
+ case(6):
+ case(8):
+ case(10):
+ case(12):
+ case(14):
+ case(16):
+ case(18):
+ case(20):
+ case(22):
+ case(24):
+ case(26):
+ case(28):
+ case(30):
+ case(32):
+ case(34):
+ case(36):
+ case(38):
+ case(40):
+ case(42):
+ case(44):
+ case(46):
+ case(48):
+ case(66): /* MU2 */
+ case(68):
+ case(70):
+ case(72):
+ case(74): /* MU3 */
+ case(76):
+ case(78):
+ case(80):
+ case(82): /* MU4 */
+ case(84):
+ case(86):
+ case(88):
+ case(90): /* MU5 */
+ case(92):
+ case(94):
+ case(96):
+ case(98): /* MU6 */
+ case(100):
+ case(102):
+ case(104):
+ case(106): /* M4U */
+ case(108):
+ case(110):
+ case(112):
+ case(114): /* TH1 */
+ case(116):
+ case(118):
+ case(120):
+ case(122):
+ case(124):
+ case(126):
+ case(128):
+ case(130):
+ case(132):
+ case(134):
+ case(136):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = msTOns(50); /* 50ms */
+ 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;
+ uartDevNum--; /* Substract unused devices from MAX_UART_DEVICES */
+ break;
+ }
+ }
+}
+
+void InitUartPortDevices_shortBuffer(void)
+{
+ unsigned char i=0;
+
+ uartTimeout.tv_sec = 0;
+ uartTimeout.tv_usec = 40000; /* 40 ms timeout */
+
+ 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(178): /* AQ1, SM1, SM5, SM6, SM7 */
+ case(180):
+ case(182):
+ case(184):
+ case(186): /* TH1V */
+ case(188):
+ case(190):
+ case(192):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = msTOns(250); /* 250ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+ case(146): /* CH1 */
+ case(148):
+ case(150):
+ case(152):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = msTOns(650); /* 650ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+ case(170): /* ID1, ID2, ID3 */
+ case(172):
+ case(174):
+ case(176):
+ 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):
+ case(226): /* WP1 */
+ case(228):
+ case(230):
+ case(232):
+ case(234): /* WP2 */
+ case(236):
+ case(238):
+ case(240):
+ case(242): /* WT1 */
+ case(244):
+ case(246):
+ case(248):
+ uartPortDevices[i] = &UARTDevice;
+ uartPortTim[i].toValue = msTOns(450); /* 450ms */
+ uartPortTim[i].status = TIM_EN_RUNNING;
+ break;
+ default:
+ uartPortDevices[i] = NULL; /* "Empty" or unknown module */
+ uartPortTim[i].status = TIM_DISABLED;
+ break;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_Devices_init.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,38 @@
+int err;
+char *serialdev = "/dev/ttyAPP1";
+
+uartDevWriteBuf_plc_state = EMPTY;
+uartDevReadBuf_plc_state = EMPTY;
+bzero(&uartDev, sizeof(uartDev));
+
+bzero(&uartDevReadBufA, sizeof(uartDevReadBuf_t));
+bzero(&uartDevReadBufB, sizeof(uartDevReadBuf_t));
+uartDevReadBuf_drv = &uartDevReadBufA;
+uartDevReadBuf_plc = &uartDevReadBufB;
+
+bzero(&uartDevWriteBufA, sizeof(uartDevWriteBuf_t));
+bzero(&uartDevWriteBufB, sizeof(uartDevWriteBuf_t));
+uartDevWriteBuf_drv = &uartDevWriteBufA;
+uartDevWriteBuf_plc = &uartDevWriteBufB;
+
+bzero(&uartCommStatusBuf, sizeof(uartCommStatusBuf));
+bzero(&uartCommErrCntBuf, sizeof(uartCommErrCntBuf));
+
+%(init_code)s
+
+UART_fd = openserial(serialdev, uartBaudrate); /* uartBaudrate is initialized from Composer */
+if (!UART_fd) {
+ fprintf(stderr, "Error while initializing %%s.\n", serialdev);
+ return 1;
+}
+
+if(uartBufSize == UART_BUFSIZE_LONG) /* uartBufSize is initialized from Composer */
+ InitUartPortDevices_longBuffer();
+else
+ InitUartPortDevices_shortBuffer();
+
+UART_task_active = 1;
+
+if(err = pthread_create(&UART_task, NULL, &UART_task_proc, NULL));
+ return err;
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_Devices_publish.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,19 @@
+if(!pthread_mutex_lock(&UART_WriteMutex)){
+
+ int prevstate;
+ prevstate=uartDevWriteBuf_plc_state;
+ uartDevWriteBuf_plc_state = LOCKED;
+
+ pthread_mutex_unlock(&UART_WriteMutex);
+
+%(publish_code)s
+
+ /* unlock plc buffer */
+ uartDevWriteBuf_plc_state = FULL;
+
+ /* wakeup task */
+ pthread_mutex_lock(&UART_WakeCondLock);
+ UART_WakeCondValue = 1;
+ pthread_cond_signal(&UART_WakeCond);
+ pthread_mutex_unlock(&UART_WakeCondLock);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_Devices_retrieve.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,19 @@
+if(!pthread_mutex_lock(&UART_ReadMutex)){
+
+ int prevstate;
+ if((prevstate=uartDevReadBuf_plc_state) == FULL){
+ uartDevReadBuf_plc_state = LOCKED;
+ }
+
+ pthread_mutex_unlock(&UART_ReadMutex);
+
+ if(prevstate == FULL){
+
+%(retrieve_code)s
+
+ /* unlock plc buffer */
+ uartDevReadBuf_plc_state = EMPTY;
+ }else{
+ /* No new data -> no update */
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_OnBoard_cleanup.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,17 @@
+#ifdef ONBOARD_I2C
+if(onboardbusfd!=-1)
+ close(onboardbusfd);
+#endif /* ONBOARD_I2C */
+
+#ifdef CAN0_EN_GPIO_0_21
+gpio_set_pin_value(CAN0_EN_dev, 1);
+gpio_close(CAN0_EN_dev);
+#endif /* CAN0_EN_GPIO_0_21 */
+
+#ifdef CAN1_EN_GPIO_0_17
+gpio_set_pin_value(CAN1_EN_dev, 1);
+gpio_close(CAN1_EN_dev);
+#endif /* CAN1_EN_GPIO_0_17 */
+
+gpio_set_pin_value(RUN_LED_dev, 1);
+gpio_close(RUN_LED_dev);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_OnBoard_decl.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,170 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <rtdm/rtdm.h>
+#include "beremiz.h"
+
+/*------------------------- GPIO -------------------------------------*/
+/* from armadeus/target/packages/as_devices/c/as_gpio* */
+
+//#ifdef DEBUG
+# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+//#else
+//# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+//#endif
+
+struct gpio_device {
+ int port_num;
+ int pin_file; /* pin file for 2.6.29 interface*/
+};
+
+struct gpio_device *RUN_LED_dev;
+#ifdef CAN0_EN_GPIO_0_21
+struct gpio_device *CAN0_EN_dev;
+#endif /* CAN0_EN_GPIO_0_21 */
+#ifdef CAN1_EN_GPIO_0_17
+struct gpio_device *CAN1_EN_dev;
+#endif /* CAN1_EN_GPIO_0_17 */
+
+static int write_file_bool(int fd, int value)
+{
+ int ret;
+
+ ret = write(fd, value?"1":"0", 1);
+ if (ret < 0) {
+ ERROR("write error\n");
+ return ret;
+ }
+ if (lseek(fd, 0, SEEK_SET) < 0) {
+ ERROR("lseek error\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+#define BUFF_SIZE 256
+static int gpio_set_pin_value(struct gpio_device *aDev, int aValue)
+{
+ int pin_file = aDev->pin_file;
+ int retval;
+
+ retval = write_file_bool(pin_file, aValue);
+ if (retval < 0) {
+ ERROR("Can't write value\n");
+ close(pin_file);
+ return -1;
+ }
+
+ return aValue;
+}
+
+static struct gpio_device *gpio_open(int aGpioNum)
+{
+ struct gpio_device *dev;
+ int pin_file;
+ int export_file;
+ int gpio_dir_fd;
+ int retval;
+ char buf[BUFF_SIZE];
+ int ret = 0;
+
+ export_file = open("/sys/class/gpio/export", O_WRONLY);
+ if (export_file < 0) {
+ ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
+ return NULL;
+ }
+
+ snprintf(buf, BUFF_SIZE, "%%d", aGpioNum);
+ retval = write(export_file, buf, strlen(buf));
+ close(export_file);
+ if (retval < 0) {
+ ERROR("/sys/class/gpio/export can't be written\n");
+ return NULL;
+ }
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/direction", aGpioNum);
+ gpio_dir_fd = open(buf, O_WRONLY);
+ if (gpio_dir_fd < 0) {
+ ERROR("Can't open gpio%%d direction\n", aGpioNum);
+ return NULL;
+ }
+
+ ret = write(gpio_dir_fd, "out", 3);
+ close(gpio_dir_fd);
+ if (ret < 0){
+ ERROR("Error writing direction\n");
+ return NULL;
+ }
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/value", aGpioNum);
+ pin_file = open(buf, O_RDWR);
+ if (pin_file < 0) {
+ ERROR("Can't export gpio number %%d\n", aGpioNum);
+ return NULL;
+ }
+
+ dev = malloc(sizeof(struct gpio_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate gpio_device structure\n");
+ close(pin_file);
+ return NULL;
+ }
+
+ dev->port_num = aGpioNum;
+ dev->pin_file = pin_file;
+
+ gpio_set_pin_value(dev, 1);
+
+ return dev;
+}
+
+static int gpio_close(struct gpio_device *aDev)
+{
+ int unexport_file;
+ char buf[BUFF_SIZE];
+ int retval;
+
+ if(aDev == NULL){
+ ERROR("device is NULL\n");
+ return -1;
+ }
+
+ unexport_file = open("/sys/class/gpio/unexport", O_WRONLY);
+ if (unexport_file < 0) {
+ ERROR("Can't open /sys/class/gpio/unexport\nBe sure that gpiolib is under your kernel\n");
+ return -1;
+ }
+
+ snprintf(buf, BUFF_SIZE, "%%d", aDev->port_num);
+ retval = write(unexport_file, buf, strlen(buf));
+ close(unexport_file);
+ if (retval < 0) {
+ ERROR("/sys/class/gpio/unexport can't be written\n");
+ return -1;
+ }
+
+ close(aDev->pin_file);
+
+ return 0;
+}
+
+/* TODO : DELETE !... but keep this until composer stops sending code snippets for mbrtu */
+typedef enum
+{
+ MB_PAR_ODD = 0, /**< ODD parity. */
+ MB_PAR_EVEN = 1, /**< Even parity. */
+ MB_PAR_NONE = 2 /**< No parity. */
+} eMBSerialParity;
+unsigned long mbBaudRate = 115200; /**< Modbus baud-rate setting: 9600, 19200, 38400, 57600, 115200 */
+eMBSerialParity mbParity = MB_PAR_NONE; /**< Modbus parity setting: odd, even, none */
+
+#ifdef ONBOARD_I2C
+
+#include "rt_imx_smt_onboard.h"
+
+static readBuf_t onBoardReadBuf;
+static writeBuf_t onBoardWriteBuf;
+static busInit_t onBoardBusInit;
+
+static int onboardbusfd = -1;
+#endif /* ONBOARD_I2C */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_OnBoard_init.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,55 @@
+#define ONBOARDDEVFILENAME "/dev/rtdm/onboard"
+
+int err;
+
+#ifdef ONBOARD_I2C
+bzero(&onBoardReadBuf , sizeof(readBuf_t));
+bzero(&onBoardWriteBuf, sizeof(writeBuf_t));
+bzero(&onBoardBusInit , sizeof(busInit_t));
+
+onBoardBusInit.common_ticktime__ = common_ticktime__;
+#define onBoardDev (onBoardBusInit.rightI2CMod)
+#endif /* ONBOARD_I2C */
+
+%(init_code)s
+
+#ifdef CAN0_EN_GPIO_0_21
+CAN0_EN_dev = gpio_open(21);
+gpio_set_pin_value(CAN0_EN_dev, 0);
+#endif /* CAN0_EN_GPIO_0_21 */
+#ifdef CAN1_EN_GPIO_0_17
+CAN1_EN_dev = gpio_open(17);
+gpio_set_pin_value(CAN1_EN_dev, 0);
+#endif /* CAN1_EN_GPIO_0_17 */
+
+#ifdef ONBOARD_I2C
+unsigned char i;
+for(i=0; i<MAX_RIGHT_MODULES; i++) {
+ switch(onBoardDev[i][1]) {
+ case 1:
+ /* OnBoard I2C bus */
+ onboardbusfd = open(ONBOARDDEVFILENAME, 0);
+ if(onboardbusfd < 0) {
+ printf("can't open %%s rtdm device, %%s\n", ONBOARDDEVFILENAME,
+ strerror(-onboardbusfd));
+ return onboardbusfd;
+ }
+ err = ioctl(onboardbusfd, RTSMT_RTIOC_INIT, &onBoardBusInit);
+ if(err) {
+ printf("error while RTSMT_RTIOC_INIT, %%s\n", strerror(-err));
+ close(onboardbusfd);
+ return err;
+ }
+ break;
+ default:
+ break;
+ }
+}
+#endif /* ONBOARD_I2C */
+
+#if defined RUN_LED_GPIO_1_13
+RUN_LED_dev = gpio_open(45);
+#elif defined RUN_LED_GPIO_1_31
+RUN_LED_dev = gpio_open(63);
+#endif /* RUN LED GPIO_1_13/GPIO_1_31 */
+gpio_set_pin_value(RUN_LED_dev, 0);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_OnBoard_publish.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,6 @@
+%(publish_code)s
+
+#ifdef ONBOARD_I2C
+if(onboardbusfd!=-1)
+ ioctl(onboardbusfd, RTSMT_RTIOC_WRITE, &onBoardWriteBuf);
+#endif /* ONBOARD_I2C */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM_OnBoard_retrieve.c Wed May 29 13:42:55 2019 +0200
@@ -0,0 +1,6 @@
+#ifdef ONBOARD_I2C
+if(onboardbusfd!=-1)
+ ioctl(onboardbusfd, RTSMT_RTIOC_READ, &onBoardReadBuf);
+#endif /* ONBOARD_I2C */
+
+%(retrieve_code)s
--- a/LPCExtension.py Tue May 28 13:21:34 2019 +0200
+++ b/LPCExtension.py Wed May 29 13:42:55 2019 +0200
@@ -8,7 +8,7 @@
import features
from POULibrary import SimplePOULibraryFactory
-from LPCArch import arch, PLC_MC9_modules, PLC_GOT_modules
+from LPCArch import GetLPCProduct, MC9_modules, WX_GOT_modules, SVG_GOT_modules
# _lpcmanager_path, arch, etc are defined here because
# globals() of LPCManager.py are passed to extentions
@@ -18,14 +18,13 @@
def _poulibpath(name):
return os.path.join(_lpcmanager_path, 'Pous', "pous"+name+".xml")
-if arch in PLC_MC9_modules:
+product = GetLPCProduct()
+if product in MC9_modules + WX_GOT_modules + SVG_GOT_modules:
features.libraries += [('Python', 'py_ext.PythonLibrary', True),
('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True)]
-elif arch in PLC_GOT_modules:
- features.libraries += [('Python', 'py_ext.PythonLibrary', True),
- ('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True),
- ('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)]
-else:
+ if product in WX_GOT_modules:
+ features.libraries += [('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)]
+else: # MC8 ?
features.libraries += [('LPC', SimplePOULibraryFactory(_poulibpath("LPC")), True)]
#
--- a/LPCManager.py Tue May 28 13:21:34 2019 +0200
+++ b/LPCManager.py Wed May 29 13:42:55 2019 +0200
@@ -22,7 +22,7 @@
# Path of directory containing current python file
_lpcmanager_path = os.path.split(__file__)[0]
-from LPCArch import SetLPCArch
+from LPCArch import SetLPCProduct
from Beremiz import BeremizIDELauncher
class LPCManagerLauncher(BeremizIDELauncher):