📄 hostif_generic.c
字号:
/*
* +-------------------------------------------------------------------+
* | 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 : HostIF_Generic.c 1.30
*
* Last update : 21:51:42 - 99/06/24
*
* Title : Low level Win95 communication, TM-1 part
*
* 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).
*
* HostIF is one of two modules which form an implementation of
* the HostCall interface (the other one is RPCClient), and provides
* the necessary communication layer.
* This communication layer consists of functions for sending and
* receiving pointer values to/from the RPCServer running on the
* host.
*
* The implementation of HostCall is partitioned between RPCClient
* and HostIF as follows:
*
* - _HostCall_notify is provided in HostIF
* - _HostCall_host_send is provided in RPCClient.
* - _HostCall_init and -terminate are provided in RPCClient.
* - Module RPCClient provides the general implementation strategy
* and solves all cache problems.
* - HostIF provides a simple communication interface for sending
* pointers hence and forth.
* - RPCClient communicates with a RPCServer on the host.
*
* More specific, HostIF should provide for the following:
*
* 1) It must implement functions _HostIF_init and _HostIF_term,
* for whatever initialisation and termination is needed.
* 2) It must implement a function _HostIF_send for sending a pointer
* (to a command buffer) to the RPCServer on the host.
* This function must return a success status.
* 3) It must be able to receive similar pointers from the
* RPCServer on the host, which must each be passed to a call
* to function _RPCClient_notify.
* 4) A debug print routine to whatever destination
*
* This is a simple HostIF implementation for communicating with
* one RPCServer on a host, by means of polling. Communication by
* polling is inherently synchronous, in the sense that the
* target always waits for host requests to fully complete. This
* is not very friendly in a multithreaded TM-1 system.
*/
/*----------------------------includes----------------------------------------*/
#include <stdio.h>
#include <stdarg.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/dprintf.h>
#include "RPC_Common.h"
/*-----------------------------module state-----------------------------------*/
extern Pointer _HostCall_commvar_init[];
static volatile Pointer *_HostCall_commvar=(Pointer)_HostCall_commvar_init;
static struct _AppSem_Semaphore module_lock= _AppSem_INITIALISED_SEM;
#define THE_SEMDEV 0
/*----------------------------functions---------------------------------------*/
Bool _HostIF_send( Pointer command )
{
/*
* Prevent multiple tasks on the same
* node from simultaneously accessing
* the HostCall_commvar:
*/
AppSem_P(&module_lock);
{
/*
* Prevent multiple nodes
* simultaneously accessing
* the HostCall_commvar.
* Use the semaphore
* device at node 0 for this:
*/
semdevGet(THE_SEMDEV,True);
{
_HostCall_commvar[0] = command;
while (_HostCall_commvar[0] != Null) {}
}
semdevRelease(THE_SEMDEV);
}
AppSem_V(&module_lock);
return True;
}
/*--------------------------- Initialisation / Termination -------------------*/
static void
real_notify ( void )
{
Pointer command;
/* Bug workaround, spurious host interrupts */
intClear(intHOSTCOMM);
command= _HostCall_commvar[1];
_HostCall_commvar[1]= Null;
_RPCClient_notify( command );
}
static void
notify ( void )
{
#pragma TCS_interruptible_handler
AppModel_suspend_scheduling();
AppModel_run_on_sstack( (Pointer)real_notify, Null );
AppModel_resume_scheduling();
}
Bool _HostIF_init()
{
intInstanceSetup_t setup;
if (intOpen(intHOSTCOMM) != 0) {
return False;
} else {
setup.enabled = True;
setup.handler = notify;
setup.priority = intPRIO_0;
setup.level_triggered = False;
return intInstanceSetup( intHOSTCOMM, &setup ) == TMLIBDEV_OK;
}
}
void _HostIF_term()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -