modified for NuMaker_PFM series

Dependents:   NuMaker-mbed-modbus-sample NuMaker_NuWicam_Lite NuMaker-mbed-modbus-sample

Fork of Modbus by Wayne Lin

Committer:
cyliang
Date:
Thu Feb 25 15:36:09 2021 +0800
Revision:
10:288aeae1458f
Parent:
0:274eb57e1df3
Change serial R/W method to fulfill OS v6.x API

Who changed what in which revision?

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