portevent.c

来自「freemodbus-v019.zip 是v0.19版本的代码」· C语言 代码 · 共 80 行

C
80
字号
/* * FreeModbus Libary: lwIP Port * Copyright (C) 2006 Christian Walter <wolti@sil.at> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA * * File: $Id: portevent.c,v 1.1 2006/08/30 23:18:07 wolti Exp $ *//* ----------------------- System includes ----------------------------------*/#include "assert.h"/* ----------------------- lwIP ---------------------------------------------*/#include "lwip/api.h"#include "lwip/sys.h"/* ----------------------- Modbus includes ----------------------------------*/#include "mb.h"/* ----------------------- Defines ------------------------------------------*/#define MB_POLL_CYCLETIME       100     /* Poll cycle time is 100ms *//* ----------------------- Static variables ---------------------------------*/static sys_mbox_t xMailBox = SYS_MBOX_NULL;static eMBEventType eMailBoxEvent;/* ----------------------- Start implementation -----------------------------*/BOOLxMBPortEventInit( void ){    eMailBoxEvent = EV_READY;    xMailBox = sys_mbox_new(  );    return xMailBox != SYS_MBOX_NULL ? TRUE : FALSE;}voidvMBPortEventClose( void ){    if( xMailBox != SYS_MBOX_NULL )    {        sys_mbox_free( xMailBox );    }}BOOLxMBPortEventPost( eMBEventType eEvent ){    eMailBoxEvent = eEvent;    sys_mbox_post( xMailBox, &eMailBoxEvent );    return TRUE;}BOOLxMBPortEventGet( eMBEventType * eEvent ){    void           *peMailBoxEvent;    BOOL            xEventHappend = FALSE;    u32_t           uiTimeSpent;    uiTimeSpent = sys_arch_mbox_fetch( xMailBox, &peMailBoxEvent, MB_POLL_CYCLETIME );    if( uiTimeSpent != SYS_ARCH_TIMEOUT )    {        *eEvent = *( eMBEventType * ) peMailBoxEvent;        eMailBoxEvent = EV_READY;        xEventHappend = TRUE;    }    return xEventHappend;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?