X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=simavr%2Fsim%2Fsim_io.h;h=f0d44e64dc4bbb42f624530caf2d0ae7ed0901ad;hb=b8993c5f0de4c62c7ed9718612f028ad27fd31d9;hp=eeb2f4887e4789e28bbfb6d6545cc931924dfacc;hpb=eab7a03e7ab811e50497f1316f6dac1b622d007f;p=simavr diff --git a/simavr/sim/sim_io.h b/simavr/sim/sim_io.h index eeb2f48..f0d44e6 100644 --- a/simavr/sim/sim_io.h +++ b/simavr/sim/sim_io.h @@ -24,6 +24,10 @@ #include "sim_avr.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * used by the ioports to implement their own features * see avr_eeprom.* for an example, and avr_ioctl(). @@ -40,15 +44,18 @@ typedef struct avr_io_t { avr_t * avr; // avr we are attached to const char * kind; // pretty name, for debug + const char ** irq_names; // IRQ names + uint32_t irq_ioctl_get; // used to get irqs from this module int irq_count; // number of (optional) irqs struct avr_irq_t * irq; // optional external IRQs - // called at every instruction - void (*run)(struct avr_io_t *io); // called at reset time void (*reset)(struct avr_io_t *io); // called externally. allow access to io modules and so on int (*ioctl)(struct avr_io_t *io, uint32_t ctl, void *io_param); + + // optional, a function to free up allocated system resources + void (*dealloc)(struct avr_io_t *io); } avr_io_t; /* @@ -57,25 +64,64 @@ typedef struct avr_io_t { // registers an IO module, so it's run(), reset() etc are called // this is called by the AVR core init functions, you /could/ register an external -// one after instanciation, for whatever purpose... -void avr_register_io(avr_t *avr, avr_io_t * io); +// one after instantiation, for whatever purpose... +void +avr_register_io( + avr_t *avr, + avr_io_t * io); +// Sets an IO module "official" IRQs and the ioctl used to get to them. if 'irqs' is NULL, +// 'count' will be allocated +avr_irq_t * +avr_io_setirqs( + avr_io_t * io, + uint32_t ctl, + int count, + avr_irq_t * irqs ); + // register a callback for when IO register "addr" is read -void avr_register_io_read(avr_t *avr, avr_io_addr_t addr, avr_io_read_t read, void * param); +void +avr_register_io_read( + avr_t *avr, + avr_io_addr_t addr, + avr_io_read_t read, + void * param); // register a callback for when the IO register is written. callback has to set the memory itself -void avr_register_io_write(avr_t *avr, avr_io_addr_t addr, avr_io_write_t write, void * param); +void +avr_register_io_write( + avr_t *avr, + avr_io_addr_t addr, + avr_io_write_t write, + void * param); // call every IO modules until one responds to this -int avr_ioctl(avr_t *avr, uint32_t ctl, void * io_param); +int +avr_ioctl( + avr_t *avr, + uint32_t ctl, + void * io_param); // get the specific irq for a module, check AVR_IOCTL_IOPORT_GETIRQ for example struct avr_irq_t * avr_io_getirq(avr_t * avr, uint32_t ctl, int index); // get the IRQ for an absolute IO address // this allows any code to hook an IRQ in any io address, for example // tracing changes of values into a register -// Note that the values do not "magicaly" change, they change only +// Note that the values do not "magically" change, they change only // when the AVR code attempt to read and write at that address // // the "index" is a bit number, or ALL bits if index == 8 #define AVR_IOMEM_IRQ_ALL 8 -struct avr_irq_t * avr_iomem_getirq(avr_t * avr, avr_io_addr_t addr, int index); +avr_irq_t * +avr_iomem_getirq( + avr_t * avr, + avr_io_addr_t addr, + int index); + +// Terminates all IOs and remove from them from the io chain +void +avr_deallocate_ios( + avr_t *avr); + +#ifdef __cplusplus +}; +#endif #endif /* __SIM_IO_H__ */