Most peripherals have to perform some activity periodically. Examples of activities are
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)
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. (
What is granularity for?)
void report_interrupt(int line);
inline unsigned char evalsim_mem8(unsigned long memaddr);
struct config;