--- a/LPCBus/MC9_Devices_decl.c Fri Dec 04 15:51:34 2015 +0100
+++ b/LPCBus/MC9_Devices_decl.c Wed Jan 27 10:34:56 2016 +0100
@@ -212,6 +212,8 @@
/* UART bus read and write buffer size */
+#define UART_RETRY_NUM 10 /* Tables containing information about connected devices on UART port
(initialized by Composer) */
unsigned char uartDev[MAX_UART_DEVICES][2];
@@ -237,8 +239,13 @@
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 void (*uartPortFunct)(char*, char*, char);
+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) */
@@ -250,7 +257,9 @@
void UART_task_proc(void *arg)
+ static unsigned char i=0; while (rt_task_sleep_until(TM_INFINITE) == -EINTR){
if(!rt_mutex_acquire(&UART_WriteMutex, TM_INFINITE )){
if(uartDevWriteBuf_plc_state == FULL){
@@ -264,8 +273,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)
@@ -280,16 +289,30 @@
if(uartPortDevices[i] != NULL)
- if((uartPortTim[i].status == TIM_DISABLED)
+ if((uartPortTim[i].status == TIM_DISABLED) || (uartPortTim[i].status == TIM_EN_EXPIRED))
// Communicate with device
- &uartDevWriteBuf[i][0],
+ commStat = (*uartPortDevices[i])( + &uartDevWriteBuf[i][0], - // If timer is enabled, reset it's value,
+ // 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)
@@ -299,12 +322,11 @@
else /* Keep timer disabled */
uartPortTim[i].status = TIM_DISABLED;
memcpy(uartDevReadBuf_drv, &uartDevReadBuf, sizeof(uartDevReadBuf_t));
@@ -380,9 +402,9 @@
* @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 *****************************************************************************/
-void UARTDevice(char* readBuf, char* writeBuf, char address)
+unsigned char UARTDevice(char* readBuf, char* writeBuf, char address) @@ -455,11 +477,12 @@
/* Copy received buffer */
if(count == UART_BUFSIZE){
memcpy(readBuf,tmp+1,UART_BUFSIZE-TAIL_LEN-1);
tcflush(UART_fd, TCIOFLUSH);
/* Macro to transform milliseconds to ns */
--- a/LPCBus/MC9_Devices_init.c Fri Dec 04 15:51:34 2015 +0100
+++ b/LPCBus/MC9_Devices_init.c Wed Jan 27 10:34:56 2016 +0100
@@ -16,6 +16,9 @@
uartDevWriteBuf_drv = &uartDevWriteBufA;
uartDevWriteBuf_plc = &uartDevWriteBufB;
+bzero(&uartCommStatusBuf, sizeof(uartCommStatusBuf)); +bzero(&uartCommErrCntBuf, sizeof(uartCommErrCntBuf)); if((err = rt_mutex_create (&UART_WriteMutex, "UART_WriteMutex")))
@@ -41,6 +44,6 @@
if((err = rt_task_create(&UART_task, "UART_task", 0, 50, T_JOINABLE)))
-if(rt_task_start(&UART_task, &UART_task_proc, NULL))
+if((err = rt_task_start(&UART_task, &UART_task_proc, NULL)))