--- a/LPCBus.py Fri Dec 12 14:15:57 2014 +0100
+++ b/LPCBus.py Fri Jan 09 13:15:03 2015 +0100
@@ -48,12 +48,13 @@
static inline int16_t getWord(char *buffer)
- return *((int16_t*)buffer);
+ return ((int16_t)*buffer<<8) + (int16_t)*(buffer+1); static inline void setWord(char *buffer, int16_t word)
- *((int16_t*)buffer) = word;
+ *buffer = (char)(word>>8); + *(buffer+1) = (char)(word); static inline int8_t getBit(char *buffer, unsigned char bitOffset)
@@ -107,6 +108,7 @@
/* LPCBus confnode includes */
#define RIGHT_READ_BUFSIZE 30 /**< Right bus read buffer size */
@@ -150,6 +152,8 @@
bzero(&rightWriteBuf, sizeof(rightWriteBuf_t));
bzero(&rightBusInit, sizeof(rightBusInit_t));
+rightBusInit.common_ticktime__ = common_ticktime__; #define rightI2CMod (rightBusInit.rightI2CMod)
@@ -215,6 +219,8 @@
#include <native/mutex.h>
#include <native/timer.h>
static struct termios oldterminfo;
@@ -469,11 +475,9 @@
static RT_MUTEX UART_WriteMutex;
static RT_MUTEX UART_ReadMutex;
-extern unsigned long long common_ticktime__;
void UART_task_proc(void *arg)
while (rt_task_sleep_until(TM_INFINITE) == -EINTR){
if(!rt_mutex_acquire(&UART_WriteMutex, TM_INFINITE )){
if(uartDevWriteBuf_plc_state == FULL){
@@ -487,8 +491,8 @@
/* Scan all positions for attached UART port modules */
- for(i=0;i<MAX_UART_DEVICES;i++)
+// for(i=0;i<MAX_UART_DEVICES;i++) /* Timers for right modules */
if(uartPortTim[i].status != TIM_DISABLED)
@@ -522,8 +526,12 @@
else /* Keep timer disabled */
uartPortTim[i].status = TIM_DISABLED;
if(!rt_mutex_acquire(&UART_ReadMutex, TM_INFINITE )){
if(uartDevReadBuf_plc_state == EMPTY){
@@ -589,6 +597,7 @@
+#define TAIL_LEN 3 /* Length of data tail in bytes */ /*************************************************************************//**
@@ -605,19 +614,19 @@
+ char tmp[UART_BUFSIZE]; - // writeBuf[45] = address;
- char tmp[UART_BUFSIZE];
- Checksum((unsigned char*)writeBuf+1);
+ /* Prepare transmit buffer */ + memcpy(tmp+1,writeBuf,UART_BUFSIZE-TAIL_LEN-1); + Checksum((unsigned char*)tmp+1); tcflush(UART_fd, TCIOFLUSH);
- if(write(UART_fd, writeBuf, UART_BUFSIZE) != UART_BUFSIZE){
+ if(write(UART_fd, tmp, UART_BUFSIZE) != UART_BUFSIZE){ @@ -640,10 +649,10 @@
rv = select(UART_fd + 1, &set, NULL, NULL, &timeout);
- printf("select error\\n");
+ printf("RS485 select error\\n");
+ //printf("timeout\\n"); @@ -651,24 +660,26 @@
- printf("read error %%d\\n",rr);
+ printf("RS485 read error %%d\\n",rr); - // for (i=0; i<UART_BUFSIZE; i++){
- // printf("|%%c:%%d", tmp[i], tmp[i]);
+// for (i=0; i<UART_BUFSIZE; i++){ +// printf("|%%c:%%d", tmp[i], tmp[i]); /* Turn to transmit mode*/
+ /* Copy received buffer */ if(count == UART_BUFSIZE){
- memcpy(readBuf,tmp+1,UART_BUFSIZE-1);
+ memcpy(readBuf,tmp+1,UART_BUFSIZE-TAIL_LEN-1); @@ -688,8 +699,8 @@