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