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