Writing Peripheral Simulation for or1ksim

Scheduling Activities

Most peripherals have to perform some activity periodically. Examples of activities are

  • reading keystrokes from a file/or user
  • refreshing the display
  • transmitting/receiving bits over a serial line

The period could be either every clock cycle, or every nth clock cycle. To schedule such activities or1ksim provides the SCHED_ADD macro.

SCHED_ADD(job_func, job_param, job_time)

Here job_func gets called at job_time with job_param as argument. job_time should be given as the clock cycle count since the start of the simulation. To schedule an activity after x cycles, you can use the global variable runtime.sim.cycles which specifies the current clock cycle count since the start of the simulation, as follows

SCHED_ADD(job_func, job_param, runtime.sim.cycles + x)

Simulating IO Ports

In OpenRISC, IO ports of a peripheral is memory-mapped. A range of memory for a device can be grabbed using register_memoryarea.

void register_memoryarea(unsigned long addr,
                         unsigned long size, unsigned granularity, unsigned mc_dev,
                         unsigned long (readfunc)(unsigned long),
                         void (writefunc)(unsigned long, unsigned long));

When a read/write occurs in the range addr to (addr + size)(rounded off to the nearest power of 2), readfunc/writefunc is called respectively. If two or more devices have requested the same area of memory the one that called the function with mc_dev as 1 will be called. Ofcourse, only one peripheral can call this function with mc_dev set to 1, for the same region of memory. (FIXME What is granularity for?)

Simulating Interrupts

void report_interrupt(int line);

Accessing Main Memory

inline unsigned char evalsim_mem8(unsigned long memaddr);

Configuration

struct config;
 
or1ksim-peripheral.txt · Last modified: 2005/07/30 13:08 by vijaykumar
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
This work is licensed under the GNU Free Documentation License..