serialrpcclient.c
来自「PNX系列设备驱动 PNX系列设备驱动」· C语言 代码 · 共 210 行
C
210 行
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1995,1996,1997 by Philips Semiconductors. |
* | |
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | Philips Semiconductors. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*
*
* Module name : SerialRPCClient.c 1.11
*
* Last update : 12:23:28 - 99/12/10
*
* Title : Implementation of HostCall interface
*
* Author : Juul van der Spek
*
* Reviewed :
*
* Revision history :
*
* Description :
* This module is part of an implementation of the HostCall interface.
* HostCall is the software component which is required by
* the TCS toolset to adapt the programs generated by this toolset
* to a specific host (see file HostCall.h in the TCS include dir).
*
* SerialRPCClient interfaces to this host by means of a message
* passing interface. This message passing interface is defined
* in SerialRPCDriver, and must be implemented by the user.
*
*/
/*----------------------------includes----------------------------------------*/
#define SERIAL_RPC
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <tmlib/tmtypes.h>
#include "HostIF.h"
#include <ops/custom_defs.h>
#include <tm1/mmio.h>
#include <tm1/tmSEM.h>
#include <tm1/tmInterrupts.h>
#include <tmlib/AppSem.h>
#include <tmlib/AppModel.h>
#include <tmlib/dprintf.h>
#include "RPC_Common.h"
#include "SerialRPC.h"
#include "SerialRPCDriver.h"
#include "AppGate.h"
/*-----------------------------module state-----------------------------------*/
static struct _AppSem_Semaphore send_lock = _AppSem_INITIALISED_SEM;
static struct _AppGate_Gate receive_gate = _AppGate_INITIALISED_GATE;
/*----------------------------functions---------------------------------------*/
static void SerialRPC_write_byte(Byte b)
{
SerialRPC_write_buffer(&b,1);
}
static void SerialRPC_write_int(Int32 b)
{
SerialRPC_write_buffer(&b,sizeof(Int32));
}
static Int32 SerialRPC_read_int()
{
Int32 result;
SerialRPC_read_buffer(&result,sizeof(Int32));
return result;
}
/*----------------------------functions---------------------------------------*/
static Pointer g_result_buf;
static Int g_result_buf_len;
static void XFER_DATA(Pointer addr, Int len)
{
SerialRPC_write_byte ( SERIAL_XFer_Input );
SerialRPC_write_int ( len );
SerialRPC_write_buffer ( addr, len );
}
#define XFER_DATA2 XFER_DATA
static Pointer RESULT_BUFF_DEF(
HostCall_command *command,
Int result_buf_len,
Pointer result_buf,
Bool preserve
)
{
if (result_buf == Null) {
g_result_buf = Null;
g_result_buf_len = 0;
} else {
g_result_buf = *(Pointer*)result_buf;
g_result_buf_len = result_buf_len;
if (preserve) {
SerialRPC_write_byte ( SERIAL_XFer_IOutput );
SerialRPC_write_int ( result_buf_len );
SerialRPC_write_buffer ( g_result_buf, result_buf_len );
} else {
SerialRPC_write_byte ( SERIAL_XFer_Output );
SerialRPC_write_int ( result_buf_len );
}
}
SerialRPC_write_byte ( SERIAL_XFer_Command );
SerialRPC_write_buffer ( command, sizeof(*command) );
return Null;
}
void _HostCall_host_send( HostCall_command *command )
{
Pointer result_buf;
Int result_buf_len;
HostCall_command *shadow_command; /* dummy; is assigned in include file RPCSend.c */
AppSem_P(&send_lock);
#include "RPCSend.c"
result_buf = g_result_buf;
result_buf_len = g_result_buf_len;
AppSem_V(&send_lock);
if (command->status == HostCall_BUSY) {
while ( AppGate_p(&receive_gate) == AppGate_GateKeeper ) {
AppGate_v( &receive_gate, (AppModel_AppId)SerialRPC_read_int() );
}
if (result_buf != Null) {
SerialRPC_read_buffer( result_buf, result_buf_len );
}
SerialRPC_read_buffer( command, sizeof(*command) );
AppGate_v( &receive_gate, Null );
command->status= HostCall_DONE;
}
}
/*--------------------------- Initialisation / Termination -------------------*/
Bool _HostCall_init()
{
if ( SerialRPC_init() ) {
SerialRPC_write_byte(SERIAL_XFer_endian_probe);
SerialRPC_write_int(1);
return True;
} else {
return False;
}
}
void _HostCall_term()
{
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?