ARM ADS 程序示例(源码),coprotest.c,partest.c,interrupts.c
源代码在线查看: parallel.c
/* Parallel.c - an example ARMulator peripheral model
*/
#include "minperip.h"
#include "armul_mem.h"
#include
static int Parallel_Access(void *handle,
struct ARMul_AccessRequest *req);
extern unsigned pport_set_irq(void* handle);
BEGIN_STATE_DECL(Parallel)
int pport_IRQ;
FILE *pportfile;
/* store details of peripheral registration */
ARMul_BusPeripAccessRegistration my_bpar;
END_STATE_DECL(Parallel)
BEGIN_INIT(Parallel)
Hostif_PrettyPrint(state->hostif, config, ", Parallel");
{
/* Note that BEGIN_INIT macro defines ParallelState *state */
unsigned err;
/* initialise state member variables */
state->pport_IRQ=0;
state->pportfile=NULL;
err = RDIError_NoError;
/* Provide memory access callback */
state->my_bpar.access_func = Parallel_Access;
state->my_bpar.access_handle = state;
state->my_bpar.capabilities = PeripAccessCapability_Minimum;
err = ARMulif_ReadBusRange(&state->coredesc, state->hostif,
ToolConf_FlatChild(config, (tag_t)"RANGE"),
&state->my_bpar,
0x123450,0x20,"");
err = state->my_bpar.bus->bus_registerPeripFunc(BusRegAct_Insert,
&state->my_bpar);
if (err)
return err;
}
END_INIT(Parallel)
BEGIN_EXIT(Parallel)
END_EXIT(Parallel)
/* Memory access function */
static int Parallel_Access(void *handle, struct ARMul_AccessRequest *req)
{
ARMWord address = req->req_address[0];
ARMWord *data = req->req_data;
unsigned type = req->req_access_type;
ParallelState *state=(ParallelState *)handle;
ARMTime Now, delay, nextEventTime;
assert(address >= state->my_bpar.range[0].lo && address my_bpar.range[0].hi);
/* We have identified a parallel port access */
if( (address == 0x123450) && acc_READ(type) ) {
Hostif_ConsolePrint( state->hostif, "Trying to open pport.txt.\n" );
state->pportfile = fopen( "pport.txt", "rb" );
if( state->pportfile == NULL ) {
Hostif_ConsolePrint( state->hostif, "Error: Could not open pport.txt\n" );
Hostif_ConsolePrint( state->hostif, "Error: Could not open pport.txt\n" );
} else {
Hostif_ConsolePrint( state->hostif, "pport.txt successfully opened.\n" );
Hostif_ConsolePrint( state->hostif, "An interrupt has been scheduled.\n" );
Now = ARMulif_Time(&state->coredesc);
delay = 20000;
nextEventTime = Now + delay;
ARMulif_ScheduleNewTimedCallback(
&state->coredesc, pport_set_irq, state, nextEventTime, 0 );
}
*data = 1234;
return PERIP_OK;
}
if( (address == 0x123460) && acc_READ(type) ) {
Hostif_ConsolePrint( state->hostif, "Read from 0x123460\n" );
if( state->pport_IRQ != 0 ) {
ARMulif_SetSignal( &(state->coredesc), RDIPropID_ARMSignal_IRQ, FALSE );
state->pport_IRQ = 0;
}
/* schedule another interrupt */
Now = ARMulif_Time(&state->coredesc);
delay = 6000;
nextEventTime = Now + delay;
ARMulif_ScheduleNewTimedCallback(
&state->coredesc, pport_set_irq, state, nextEventTime, 0 );
if( state->pportfile )
*data = fgetc(state->pportfile);
else
printf( "pportfile is null\n" );
return PERIP_OK;
}
return PERIP_NODECODE;
}
extern unsigned pport_set_irq(void* handle)
{
/* state is obtained directly from ParallelState */
ParallelState *state=(ParallelState *)handle;
Hostif_ConsolePrint( state->hostif, "An IRQ has occured\n" );
/* Assert the IRQ */
ARMulif_SetSignal( &(state->coredesc), RDIPropID_ARMSignal_IRQ, TRUE );
state->pport_IRQ = 1;
return 1;
}
/*--- ---*/
#define SORDI_DLL_NAME_STRING "Parallel"
#define SORDI_DLL_DESCRIPTION_STRING "Parallel port model"
#define SORDI_RDI_PROCVEC Parallel_AgentRDI
#include "perip_sordi.h"
#include "perip_rdi_agent.h"
IMPLEMENT_AGENT_PROCS_NOEXE_NOMODULE(Parallel)
IMPLEMENT_AGENT_PROCVEC_NOEXE(Parallel)
/*--- ---*/
/* EOF Parallel.c */