--- a/LPCBus.py Thu Dec 11 18:35:34 2014 +0100
+++ b/LPCBus.py Fri Dec 12 14:15:57 2014 +0100
@@ -101,6 +101,9 @@
+############################################################################### +######################## Right Bus I2C (RT) ######################### +############################################################################### @@ -120,17 +123,21 @@
/**< Tables containing information about connected modules
on right bus (initialized by Composer) */
typedef char rightI2CMod_t[MAX_RIGHT_MODULES][2];
+ rightI2CMod_t rightI2CMod; + unsigned long long common_ticktime__; #define RTIOC_TYPE_SMT RTDM_CLASS_EXPERIMENTAL
-#define RTSMT_RTIOC_INIT _IOR(RTIOC_TYPE_SMT, 0x00, rightI2CMod_t)
+#define RTSMT_RTIOC_INIT _IOR(RTIOC_TYPE_SMT, 0x00, rightBusInit_t) //#define RTSMT_RTIOC_CLEAN _IOR(RTIOC_TYPE_SMT, 0x01, int)
#define RTSMT_RTIOC_READ _IOR(RTIOC_TYPE_SMT, 0x02, rightReadBuf_t)
#define RTSMT_RTIOC_WRITE _IOR(RTIOC_TYPE_SMT, 0x03, rightWriteBuf_t)
static rightReadBuf_t rightReadBuf;
static rightWriteBuf_t rightWriteBuf;
-static rightI2CMod_t rightI2CMod;
+static rightBusInit_t rightBusInit; static int rightbusfd = -1;
@@ -141,8 +148,9 @@
bzero(&rightReadBuf, sizeof(rightReadBuf_t));
bzero(&rightWriteBuf, sizeof(rightWriteBuf_t));
-bzero(&rightI2CMod, sizeof(rightI2CMod_t));
+bzero(&rightBusInit, sizeof(rightBusInit_t)); +#define rightI2CMod (rightBusInit.rightI2CMod) @@ -153,7 +161,7 @@
-err = rt_dev_ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightI2CMod);
+err = rt_dev_ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit); printf("error while RTSMT_RTIOC_INIT, %%s\\n",
@@ -173,6 +181,9 @@
rt_dev_close(rightbusfd);
+############################################################################### +######################## OnBoard devices ######################### +############################################################################### #define MAX_ONBOARD_DEVICES 2
@@ -188,6 +199,9 @@
"publish":"%(publish_code)s",
+############################################################################### +######################## RS 485 non real time ######################### +############################################################################### @@ -357,7 +371,7 @@
return gpio_set_pin_value(RS485_GPIO_dev, 0);
-/*------------------------------------------------------------------------------*/
+/*--------------------------- Serial Port handling ---------------------------*/ int openserial(char *devicename)
@@ -403,8 +417,8 @@
typedef struct /* Type definition for timers for right modules */
unsigned char status; /* Current status of timer - running / expired */
- RTIME actValue; /* Actual timer value */
- RTIME toValue; /* Timeout value - initialized at startup */
+ long long actValue; /* Actual timer value */ + long long toValue; /* Timeout value - initialized at startup */ @@ -455,6 +469,8 @@
static RT_MUTEX UART_WriteMutex;
static RT_MUTEX UART_ReadMutex;
+extern unsigned long long common_ticktime__; void UART_task_proc(void *arg)
@@ -473,11 +489,11 @@
/* Scan all positions for attached UART port modules */
for(i=0;i<MAX_UART_DEVICES;i++)
- RTIME now = rt_timer_read();
/* Timers for right modules */
if(uartPortTim[i].status != TIM_DISABLED)
- if(now - uartPortTim[i].actValue < uartPortTim[i].toValue)
+ uartPortTim[i].actValue += common_ticktime__; + if(uartPortTim[i].actValue < uartPortTim[i].toValue) uartPortTim[i].status = TIM_EN_RUNNING;
@@ -500,7 +516,7 @@
// otherwise keep it disabled
if(uartPortTim[i].status != TIM_DISABLED)
- uartPortTim[i].actValue = now;
+ uartPortTim[i].actValue = 0; uartPortTim[i].status = TIM_EN_RUNNING;
else /* Keep timer disabled */
@@ -606,10 +622,10 @@
/* Sleep until transmission completes + 0.5ms safety */
- now + rt_timer_ns2ticks(
- 1000000000LL * UART_BUFSIZE * 10 / 115200
+ while(rt_task_sleep_until( + now + rt_timer_ns2ticks( + 1000000000LL * UART_BUFSIZE * 10 / 115200 @@ -660,8 +676,8 @@
tcflush(UART_fd, TCIOFLUSH);
-/* Macro to transform milliseconds to xenomai ticks */
-#define msTOxn(ms) rt_timer_ns2ticks(1000000L*ms)
+/* Macro to transform milliseconds to ns */ +#define msTOns(ms) (1000000L*ms) void InitUartPortDevices(void)
@@ -704,7 +720,7 @@
uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOxn(50); /* 50ms */
+ uartPortTim[i].toValue = msTOns(50); /* 50ms */ uartPortTim[i].status = TIM_EN_RUNNING;
case(130): /* P01, P02, P01V, P02V */
@@ -728,7 +744,7 @@
uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOxn(200); /* 200ms */
+ uartPortTim[i].toValue = msTOns(200); /* 200ms */ uartPortTim[i].status = TIM_EN_RUNNING;
@@ -736,7 +752,7 @@
uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOxn(600); /* 600ms */
+ uartPortTim[i].toValue = msTOns(600); /* 600ms */ uartPortTim[i].status = TIM_EN_RUNNING;
case(170): /* ID1, ID2, ID3 */
@@ -744,7 +760,7 @@
uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOxn(400); /* 400ms */
+ uartPortTim[i].toValue = msTOns(400); /* 400ms */ uartPortTim[i].status = TIM_EN_RUNNING;
@@ -764,7 +780,7 @@
uartPortDevices[i] = &UARTDevice;
- uartPortTim[i].toValue = msTOxn(400); /* 400ms */
+ uartPortTim[i].toValue = msTOns(400); /* 400ms */ uartPortTim[i].status = TIM_EN_RUNNING;