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 @@
-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
+def SetLPCProduct(given):
+ 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" + 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() -if arch in SOM28_modules:
- bus_template_name = "MC9"
- bus_template_name = arch
LPCBusSourcePath = os.path.join(modpath,"LPCBus")
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
-bus_template_code = { plc:GetLocalCode(plc+".c") for plc in ["MC8", "MC9"] }
+bus_template_code = { plc: GetLocalCode( + "MC10": "SOM"}[plc]+".c") for plc in Busses.keys()} # This is in case some bus has some special LDFLAGS
@@ -223,16 +232,16 @@
- bus_code = { "MC9:%s"%bus :
+ bus_code = { "%s:%s"%(arch, bus_name) : - header + GetLocalCode("%s_%s_%s.c"%("MC9",''.join(bus.split()),section))
+ header + GetLocalCode("%s_%s.c"%(bus_template,section)) - ("decl",GetLocalCode("%s.h" % headernames[arch])),
+ ("decl",GetLocalCode("%s.h" % headernames[product])),
+ for bus_name, bus_template in Busses[arch]} for module in GetModuleChildren(self):
@@ -279,7 +288,7 @@
code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n"
- BusName = bus_template_name + ":" + self.BaseParams.getName()
+ BusName = arch + ":" + self.BaseParams.getName() @@ -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) 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);
-pthread_cond_signal(&UART_WakeCond);
-pthread_mutex_unlock(&UART_WakeCondLock);
-pthread_join(UART_task, NULL);
--- 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 <alchemy/task.h>
-#include <alchemy/mutex.h>
-#include <alchemy/timer.h>
-static struct termios oldterminfo;
-void closeserial(int fd)
- tcsetattr(fd, TCSANOW, &oldterminfo);
- perror("closeserial()");
-/*--------------------------- Serial Port handling ---------------------------*/
-int openserial(char *devicename, unsigned long baudrate)
- speed_t baud = B115200; /* baud rate */
- if ((fd = open(devicename, O_RDWR)) == -1) {
- perror("openserial(): open()");
- if (tcgetattr(fd, &oldterminfo) == -1) {
- perror("openserial(): tcgetattr()");
- 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()");
- if (tcsetattr(fd, TCSANOW, &attr) == -1) {
- perror("initserial(): tcsetattr()");
-#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;
-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;
-#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;
- 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, ¶m);
- 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);
- // 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;
- uartPortTim[i].status = TIM_EN_EXPIRED;
- uartPortTim[i].oldTime = actTime;
- lastCommTime = actTime;
- 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])(
- &uartDevWriteBuf[i][0],
- 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:
- uartCommStatusBuf[i][0] = TRUE;
- uartCommErrCntBuf[i][0] = 0;
- if(uartCommErrCntBuf[i][0] < UART_RETRY_NUM)
- uartCommErrCntBuf[i][0]++;
- 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
- else /* Go back to the first UART device */
-#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 &
-******************************************************************************/
-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)
- 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)
- 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]))
-/*************************************************************************//**
-* 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)
- struct timeval timeout;
- /* Prepare transmit buffer */
- memcpy(tmp+1,writeBuf,uartBufSize-TAIL_LEN-1);
- tmp[uartBufSize-TAIL_LEN] = address;
- Checksum((unsigned char*)tmp+1, uartBufSize);
- tcflush(UART_fd, TCIOFLUSH);
- if(write(UART_fd, tmp, uartBufSize) != uartBufSize){
- 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);
- printf("RS485 select error\n");
- int rr = read(UART_fd, tmp + count, uartBufSize - count);
- 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);
- tcflush(UART_fd, TCIOFLUSH);
-/* Macro to transform milliseconds to ns */
-#define msTOns(ms) (1000000L*ms)
-void InitUartPortDevices_longBuffer(void)
- uartTimeout.tv_sec = 0;
- uartTimeout.tv_usec = 20000; /* 20 ms timeout */
- for(i=0;i<MAX_UART_DEVICES;i++)
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(50); /* 50ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- case(240): /* 240-254 are reserved for EEPROM settings */
- uartPortDevices[i] = NULL; /* "Empty" or unknown module */
- uartPortTim[i].status = TIM_DISABLED;
- uartDevNum--; /* Substract unused devices from MAX_UART_DEVICES */
-void InitUartPortDevices_shortBuffer(void)
- uartTimeout.tv_sec = 0;
- uartTimeout.tv_usec = 40000; /* 40 ms timeout */
- for(i=0;i<MAX_UART_DEVICES;i++)
- case(130): /* P01, P02, P01V, P02V */
- case(178): /* AQ1, SM1, SM5, SM6, SM7 */
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(250); /* 250ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(650); /* 650ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- case(170): /* ID1, ID2, ID3 */
- uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOns(450); /* 450ms */
- uartPortTim[i].status = TIM_EN_RUNNING;
- uartPortDevices[i] = NULL; /* "Empty" or unknown module */
- uartPortTim[i].status = TIM_DISABLED;
--- 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 @@
-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));
-UART_fd = openserial(serialdev, uartBaudrate); /* uartBaudrate is initialized from Composer */
- fprintf(stderr, "Error while initializing %%s.\n", serialdev);
-if(uartBufSize == UART_BUFSIZE_LONG) /* uartBufSize is initialized from Composer */
- InitUartPortDevices_longBuffer();
- InitUartPortDevices_shortBuffer();
-if(err = pthread_create(&UART_task, NULL, &UART_task_proc, NULL));
--- 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)){
- prevstate=uartDevWriteBuf_plc_state;
- uartDevWriteBuf_plc_state = LOCKED;
- pthread_mutex_unlock(&UART_WriteMutex);
- /* unlock plc buffer */
- uartDevWriteBuf_plc_state = FULL;
- 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)){
- if((prevstate=uartDevReadBuf_plc_state) == FULL){
- uartDevReadBuf_plc_state = LOCKED;
- pthread_mutex_unlock(&UART_ReadMutex);
- /* unlock plc buffer */
- uartDevReadBuf_plc_state = EMPTY;
- /* 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 @@
-#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 @@
-/*------------------------- GPIO -------------------------------------*/
-/* from armadeus/target/packages/as_devices/c/as_gpio* */
-# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-//# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
- 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)
- ret = write(fd, value?"1":"0", 1);
- ERROR("write error\n");
- if (lseek(fd, 0, SEEK_SET) < 0) {
- ERROR("lseek error\n");
-static int gpio_set_pin_value(struct gpio_device *aDev, int aValue)
- int pin_file = aDev->pin_file;
- retval = write_file_bool(pin_file, aValue);
- ERROR("Can't write value\n");
-static struct gpio_device *gpio_open(int aGpioNum)
- struct gpio_device *dev;
- export_file = open("/sys/class/gpio/export", O_WRONLY);
- ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
- snprintf(buf, BUFF_SIZE, "%%d", aGpioNum);
- retval = write(export_file, buf, strlen(buf));
- ERROR("/sys/class/gpio/export can't be written\n");
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/direction", aGpioNum);
- gpio_dir_fd = open(buf, O_WRONLY);
- ERROR("Can't open gpio%%d direction\n", aGpioNum);
- ret = write(gpio_dir_fd, "out", 3);
- ERROR("Error writing direction\n");
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/value", aGpioNum);
- pin_file = open(buf, O_RDWR);
- ERROR("Can't export gpio number %%d\n", aGpioNum);
- dev = malloc(sizeof(struct gpio_device));
- ERROR("Can't allocate gpio_device structure\n");
- dev->port_num = aGpioNum;
- dev->pin_file = pin_file;
- gpio_set_pin_value(dev, 1);
-static int gpio_close(struct gpio_device *aDev)
- ERROR("device is NULL\n");
- 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");
- snprintf(buf, BUFF_SIZE, "%%d", aDev->port_num);
- retval = write(unexport_file, buf, strlen(buf));
- ERROR("/sys/class/gpio/unexport can't be written\n");
-/* TODO : DELETE !... but keep this until composer stops sending code snippets for mbrtu */
- MB_PAR_ODD = 0, /**< ODD parity. */
- MB_PAR_EVEN = 1, /**< Even parity. */
- MB_PAR_NONE = 2 /**< No parity. */
-unsigned long mbBaudRate = 115200; /**< Modbus baud-rate setting: 9600, 19200, 38400, 57600, 115200 */
-eMBSerialParity mbParity = MB_PAR_NONE; /**< Modbus parity setting: odd, even, none */
-#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"
-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 */
-#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 */
-for(i=0; i<MAX_RIGHT_MODULES; i++) {
- switch(onBoardDev[i][1]) {
- onboardbusfd = open(ONBOARDDEVFILENAME, 0);
- printf("can't open %%s rtdm device, %%s\n", ONBOARDDEVFILENAME,
- strerror(-onboardbusfd));
- err = ioctl(onboardbusfd, RTSMT_RTIOC_INIT, &onBoardBusInit);
- printf("error while RTSMT_RTIOC_INIT, %%s\n", strerror(-err));
-#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 @@
- 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 @@
- ioctl(onboardbusfd, RTSMT_RTIOC_READ, &onBoardReadBuf);
-#endif /* ONBOARD_I2C */
--- 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 @@
--- 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 "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)
-rightbusfd = open( DEVICEFILENAME, 0);
- printf("can't open %%s rtdm device, %%s\\n", DEVICEFILENAME,
- strerror(-rightbusfd));
-err = ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit);
- printf("error while RTSMT_RTIOC_INIT, %%s\\n",
--- 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 @@
-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);
--- /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 @@
--- /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 "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) +rightbusfd = open( DEVICEFILENAME, 0); + printf("can't open %%s rtdm device, %%s\\n", DEVICEFILENAME, + strerror(-rightbusfd)); +err = ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit); + printf("error while RTSMT_RTIOC_INIT, %%s\\n", --- /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 @@
+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); --- /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); +pthread_cond_signal(&UART_WakeCond); +pthread_mutex_unlock(&UART_WakeCondLock); +pthread_join(UART_task, NULL); --- /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 <alchemy/task.h> +#include <alchemy/mutex.h> +#include <alchemy/timer.h> +static struct termios oldterminfo; +void closeserial(int fd) + tcsetattr(fd, TCSANOW, &oldterminfo); + perror("closeserial()"); +/*--------------------------- Serial Port handling ---------------------------*/ +int openserial(char *devicename, unsigned long baudrate) + speed_t baud = B115200; /* baud rate */ + if ((fd = open(devicename, O_RDWR)) == -1) { + perror("openserial(): open()"); + if (tcgetattr(fd, &oldterminfo) == -1) { + perror("openserial(): tcgetattr()"); + 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()"); + if (tcsetattr(fd, TCSANOW, &attr) == -1) { + perror("initserial(): tcsetattr()"); +#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; +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; +#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; + 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, ¶m); + 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); + // 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; + uartPortTim[i].status = TIM_EN_EXPIRED; + uartPortTim[i].oldTime = actTime; + lastCommTime = actTime; + 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])( + &uartDevWriteBuf[i][0], + 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: + uartCommStatusBuf[i][0] = TRUE; + uartCommErrCntBuf[i][0] = 0; + if(uartCommErrCntBuf[i][0] < UART_RETRY_NUM) + uartCommErrCntBuf[i][0]++; + 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 + else /* Go back to the first UART device */ +#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 & +******************************************************************************/ +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) + 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) + 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])) +/*************************************************************************//** +* 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) + struct timeval timeout; + /* Prepare transmit buffer */ + memcpy(tmp+1,writeBuf,uartBufSize-TAIL_LEN-1); + tmp[uartBufSize-TAIL_LEN] = address; + Checksum((unsigned char*)tmp+1, uartBufSize); + tcflush(UART_fd, TCIOFLUSH); + if(write(UART_fd, tmp, uartBufSize) != uartBufSize){ + 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); + printf("RS485 select error\n"); + int rr = read(UART_fd, tmp + count, uartBufSize - count); + 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); + tcflush(UART_fd, TCIOFLUSH); +/* Macro to transform milliseconds to ns */ +#define msTOns(ms) (1000000L*ms) +void InitUartPortDevices_longBuffer(void) + uartTimeout.tv_sec = 0; + uartTimeout.tv_usec = 20000; /* 20 ms timeout */ + for(i=0;i<MAX_UART_DEVICES;i++) + uartPortDevices[i] = &UARTDevice; + uartPortTim[i].toValue = msTOns(50); /* 50ms */ + uartPortTim[i].status = TIM_EN_RUNNING; + case(240): /* 240-254 are reserved for EEPROM settings */ + uartPortDevices[i] = NULL; /* "Empty" or unknown module */ + uartPortTim[i].status = TIM_DISABLED; + uartDevNum--; /* Substract unused devices from MAX_UART_DEVICES */ +void InitUartPortDevices_shortBuffer(void) + uartTimeout.tv_sec = 0; + uartTimeout.tv_usec = 40000; /* 40 ms timeout */ + for(i=0;i<MAX_UART_DEVICES;i++) + case(130): /* P01, P02, P01V, P02V */ + case(178): /* AQ1, SM1, SM5, SM6, SM7 */ + uartPortDevices[i] = &UARTDevice; + uartPortTim[i].toValue = msTOns(250); /* 250ms */ + uartPortTim[i].status = TIM_EN_RUNNING; + uartPortDevices[i] = &UARTDevice; + uartPortTim[i].toValue = msTOns(650); /* 650ms */ + uartPortTim[i].status = TIM_EN_RUNNING; + case(170): /* ID1, ID2, ID3 */ + uartPortDevices[i] = &UARTDevice; + uartPortTim[i].toValue = msTOns(450); /* 450ms */ + uartPortTim[i].status = TIM_EN_RUNNING; + uartPortDevices[i] = NULL; /* "Empty" or unknown module */ + uartPortTim[i].status = TIM_DISABLED; --- /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 @@
+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)); +UART_fd = openserial(serialdev, uartBaudrate); /* uartBaudrate is initialized from Composer */ + fprintf(stderr, "Error while initializing %%s.\n", serialdev); +if(uartBufSize == UART_BUFSIZE_LONG) /* uartBufSize is initialized from Composer */ + InitUartPortDevices_longBuffer(); + InitUartPortDevices_shortBuffer(); +if(err = pthread_create(&UART_task, NULL, &UART_task_proc, NULL)); --- /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)){ + prevstate=uartDevWriteBuf_plc_state; + uartDevWriteBuf_plc_state = LOCKED; + pthread_mutex_unlock(&UART_WriteMutex); + /* unlock plc buffer */ + uartDevWriteBuf_plc_state = FULL; + 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)){ + if((prevstate=uartDevReadBuf_plc_state) == FULL){ + uartDevReadBuf_plc_state = LOCKED; + pthread_mutex_unlock(&UART_ReadMutex); + /* unlock plc buffer */ + uartDevReadBuf_plc_state = EMPTY; + /* 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 @@
+#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 @@
+/*------------------------- GPIO -------------------------------------*/ +/* from armadeus/target/packages/as_devices/c/as_gpio* */ +# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__) +//# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/ + 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) + ret = write(fd, value?"1":"0", 1); + ERROR("write error\n"); + if (lseek(fd, 0, SEEK_SET) < 0) { + ERROR("lseek error\n"); +static int gpio_set_pin_value(struct gpio_device *aDev, int aValue) + int pin_file = aDev->pin_file; + retval = write_file_bool(pin_file, aValue); + ERROR("Can't write value\n"); +static struct gpio_device *gpio_open(int aGpioNum) + struct gpio_device *dev; + export_file = open("/sys/class/gpio/export", O_WRONLY); + ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n"); + snprintf(buf, BUFF_SIZE, "%%d", aGpioNum); + retval = write(export_file, buf, strlen(buf)); + ERROR("/sys/class/gpio/export can't be written\n"); + snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/direction", aGpioNum); + gpio_dir_fd = open(buf, O_WRONLY); + ERROR("Can't open gpio%%d direction\n", aGpioNum); + ret = write(gpio_dir_fd, "out", 3); + ERROR("Error writing direction\n"); + snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/value", aGpioNum); + pin_file = open(buf, O_RDWR); + ERROR("Can't export gpio number %%d\n", aGpioNum); + dev = malloc(sizeof(struct gpio_device)); + ERROR("Can't allocate gpio_device structure\n"); + dev->port_num = aGpioNum; + dev->pin_file = pin_file; + gpio_set_pin_value(dev, 1); +static int gpio_close(struct gpio_device *aDev) + ERROR("device is NULL\n"); + 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"); + snprintf(buf, BUFF_SIZE, "%%d", aDev->port_num); + retval = write(unexport_file, buf, strlen(buf)); + ERROR("/sys/class/gpio/unexport can't be written\n"); +/* TODO : DELETE !... but keep this until composer stops sending code snippets for mbrtu */ + MB_PAR_ODD = 0, /**< ODD parity. */ + MB_PAR_EVEN = 1, /**< Even parity. */ + MB_PAR_NONE = 2 /**< No parity. */ +unsigned long mbBaudRate = 115200; /**< Modbus baud-rate setting: 9600, 19200, 38400, 57600, 115200 */ +eMBSerialParity mbParity = MB_PAR_NONE; /**< Modbus parity setting: odd, even, none */ +#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" +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 */ +#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 */ +for(i=0; i<MAX_RIGHT_MODULES; i++) { + switch(onBoardDev[i][1]) { + onboardbusfd = open(ONBOARDDEVFILENAME, 0); + printf("can't open %%s rtdm device, %%s\n", ONBOARDDEVFILENAME, + strerror(-onboardbusfd)); + err = ioctl(onboardbusfd, RTSMT_RTIOC_INIT, &onBoardBusInit); + printf("error while RTSMT_RTIOC_INIT, %%s\n", strerror(-err)); +#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 @@
+ 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 @@
+ ioctl(onboardbusfd, RTSMT_RTIOC_READ, &onBoardReadBuf); +#endif /* ONBOARD_I2C */ --- 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 @@
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 @@
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)]
+ if product in WX_GOT_modules: + features.libraries += [('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)] 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):