1 /* 2 * FreeModbus Libary: RT-Thread Port 3 * Copyright (C) 2013 Armink <[email protected]> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 * File: $Id: portevent.c,v 1.60 2013/08/13 15:07:05 Armink $ 20 */ 21 22 /* ----------------------- Modbus includes ----------------------------------*/ 23 #include "mb.h" 24 #include "mbport.h" 25 26 /* ----------------------- Variables ----------------------------------------*/ 27 static struct rt_event xSlaveOsEvent; 28 /* ----------------------- Start implementation -----------------------------*/ 29 BOOL 30 xMBPortEventInit( void ) 31 { 32 rt_event_init(&xSlaveOsEvent,"slave event",RT_IPC_FLAG_PRIO); 33 return TRUE; 34 } 35 36 BOOL 37 xMBPortEventPost( eMBEventType eEvent ) 38 { 39 rt_event_send(&xSlaveOsEvent, eEvent); 40 return TRUE; 41 } 42 43 BOOL 44 xMBPortEventGet( eMBEventType * eEvent ) 45 { 46 rt_uint32_t recvedEvent; 47 /* waiting forever OS event */ 48 rt_event_recv(&xSlaveOsEvent, 49 EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | EV_FRAME_SENT, 50 RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, 51 &recvedEvent); 52 switch (recvedEvent) 53 { 54 case EV_READY: 55 *eEvent = EV_READY; 56 break; 57 case EV_FRAME_RECEIVED: 58 *eEvent = EV_FRAME_RECEIVED; 59 break; 60 case EV_EXECUTE: 61 *eEvent = EV_EXECUTE; 62 break; 63 case EV_FRAME_SENT: 64 *eEvent = EV_FRAME_SENT; 65 break; 66 } 67 return TRUE; 68 } 69