Modbus RTU/ASCII/TCP with lwip TCP working partial, but with errors (retransmitions)

Dependencies:   EthernetNetIf mbed

Committer:
tmav123
Date:
Mon Dec 05 22:49:02 2011 +0000
Revision:
0:f54e9507171b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tmav123 0:f54e9507171b 1 /*
tmav123 0:f54e9507171b 2 * FreeModbus Libary: BARE Port
tmav123 0:f54e9507171b 3 * Copyright (C) 2006 Christian Walter <wolti@sil.at>
tmav123 0:f54e9507171b 4 *
tmav123 0:f54e9507171b 5 * This library is free software; you can redistribute it and/or
tmav123 0:f54e9507171b 6 * modify it under the terms of the GNU Lesser General Public
tmav123 0:f54e9507171b 7 * License as published by the Free Software Foundation; either
tmav123 0:f54e9507171b 8 * version 2.1 of the License, or (at your option) any later version.
tmav123 0:f54e9507171b 9 *
tmav123 0:f54e9507171b 10 * This library is distributed in the hope that it will be useful,
tmav123 0:f54e9507171b 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
tmav123 0:f54e9507171b 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
tmav123 0:f54e9507171b 13 * Lesser General Public License for more details.
tmav123 0:f54e9507171b 14 *
tmav123 0:f54e9507171b 15 * You should have received a copy of the GNU Lesser General Public
tmav123 0:f54e9507171b 16 * License along with this library; if not, write to the Free Software
tmav123 0:f54e9507171b 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
tmav123 0:f54e9507171b 18 *
tmav123 0:f54e9507171b 19 * File: $Id: porttimer.c,v 1.1 2006/08/22 21:35:13 wolti Exp $
tmav123 0:f54e9507171b 20 */
tmav123 0:f54e9507171b 21
tmav123 0:f54e9507171b 22 /* ----------------------- System includes ----------------------------------*/
tmav123 0:f54e9507171b 23 #include "mbed.h" // Cam
tmav123 0:f54e9507171b 24
tmav123 0:f54e9507171b 25 /* ----------------------- Platform includes --------------------------------*/
tmav123 0:f54e9507171b 26 #include "port.h"
tmav123 0:f54e9507171b 27
tmav123 0:f54e9507171b 28 /* ----------------------- Modbus includes ----------------------------------*/
tmav123 0:f54e9507171b 29 #include "mb.h"
tmav123 0:f54e9507171b 30 #include "mbport.h"
tmav123 0:f54e9507171b 31
tmav123 0:f54e9507171b 32 /* ----------------------- static functions ---------------------------------*/
tmav123 0:f54e9507171b 33 static void prvvTIMERExpiredISR( void );
tmav123 0:f54e9507171b 34
tmav123 0:f54e9507171b 35 /* ----------------------- System Variables ---------------------------------*/
tmav123 0:f54e9507171b 36 Timeout toMBUS; // Cam - mbed timeout
tmav123 0:f54e9507171b 37 static ULONG usInterval; // Cam - timeout interval in microseconds
tmav123 0:f54e9507171b 38
tmav123 0:f54e9507171b 39 /* ----------------------- Start implementation -----------------------------*/
tmav123 0:f54e9507171b 40 BOOL
tmav123 0:f54e9507171b 41 xMBPortTimersInit( USHORT usTim1Timerout50us )
tmav123 0:f54e9507171b 42 {
tmav123 0:f54e9507171b 43 usInterval = 50 * usTim1Timerout50us;
tmav123 0:f54e9507171b 44 return TRUE;
tmav123 0:f54e9507171b 45 }
tmav123 0:f54e9507171b 46
tmav123 0:f54e9507171b 47
tmav123 0:f54e9507171b 48 /*inline*/ void
tmav123 0:f54e9507171b 49 vMBPortTimersEnable( )
tmav123 0:f54e9507171b 50 {
tmav123 0:f54e9507171b 51 /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */
tmav123 0:f54e9507171b 52
tmav123 0:f54e9507171b 53 // Cam - firstly detach from any existing timeout
tmav123 0:f54e9507171b 54 toMBUS.detach();
tmav123 0:f54e9507171b 55 // Cam - now attach the timeout to the prvvTIMERExpiredISR routine
tmav123 0:f54e9507171b 56 toMBUS.attach_us(&prvvTIMERExpiredISR, usInterval);
tmav123 0:f54e9507171b 57 }
tmav123 0:f54e9507171b 58
tmav123 0:f54e9507171b 59 /*inline*/ void
tmav123 0:f54e9507171b 60 vMBPortTimersDisable( )
tmav123 0:f54e9507171b 61 {
tmav123 0:f54e9507171b 62 /* Disable any pending timers. */
tmav123 0:f54e9507171b 63
tmav123 0:f54e9507171b 64 // Cam - disable further interrupts by detaching
tmav123 0:f54e9507171b 65 toMBUS.detach();
tmav123 0:f54e9507171b 66 }
tmav123 0:f54e9507171b 67
tmav123 0:f54e9507171b 68 /* Create an ISR which is called whenever the timer has expired. This function
tmav123 0:f54e9507171b 69 * must then call pxMBPortCBTimerExpired( ) to notify the protocol stack that
tmav123 0:f54e9507171b 70 * the timer has expired.
tmav123 0:f54e9507171b 71 */
tmav123 0:f54e9507171b 72 static void prvvTIMERExpiredISR( void )
tmav123 0:f54e9507171b 73 {
tmav123 0:f54e9507171b 74 ( void )pxMBPortCBTimerExpired( );
tmav123 0:f54e9507171b 75 // Cam - disable further interrupts by detaching
tmav123 0:f54e9507171b 76 toMBUS.detach();
tmav123 0:f54e9507171b 77 }
tmav123 0:f54e9507171b 78