SimAVR
AVR Simulator
sim_io.h
Go to the documentation of this file.
1 /*
2  * sim_io.h
3  *
4  * Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5  *
6  * This file is part of simavr.
7  *
8  * simavr is free software: you can redistribute it and/or modify it under the terms of the GNU
9  * General Public License as published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * simavr is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with simavr. If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
25 #ifndef __SIM_IO_H__
26 #define __SIM_IO_H__
27 
28 #include "sim_avr.h"
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
37 #define AVR_IOCTL_DEF(_a,_b,_c,_d) \
38  (((_a) << 24)|((_b) << 16)|((_c) << 8)|((_d)))
39 
42  typedef struct avr_io_t
43  {
44  struct avr_io_t *next;
46  const char *kind;
47 
48  const char **irq_names;
49 
50  uint32_t irq_ioctl_get;
51  int irq_count;
52  struct avr_irq_t *irq;
53 
55  void (*reset) (struct avr_io_t * io);
57  int (*ioctl) (struct avr_io_t * io, uint32_t ctl, void *io_param);
59  void (*dealloc) (struct avr_io_t * io);
60  } avr_io_t;
61 
62  /*
63  * IO modules helper functions
64  */
65 
70  void avr_register_io (avr_t * avr, avr_io_t * io);
74  avr_irq_t *avr_io_setirqs (avr_io_t * io, uint32_t ctl, int count, avr_irq_t * irqs);
75 
77  void avr_register_io_read (avr_t * avr, avr_io_addr_t addr, avr_io_read_t read, void *param);
79  void avr_register_io_write (avr_t * avr, avr_io_addr_t addr, avr_io_write_t write, void *param);
81  int avr_ioctl (avr_t * avr, uint32_t ctl, void *io_param);
83  struct avr_irq_t *avr_io_getirq (avr_t * avr, uint32_t ctl, int index);
84 
85 #define AVR_IOMEM_IRQ_ALL 8
86 
95  avr_io_addr_t addr,
96  const char *name /* Optional, if NULL, "ioXXXX" will be used */ ,
97  int index);
98 
100  void avr_deallocate_ios (avr_t * avr);
101 
102 #ifdef __cplusplus
103 };
104 #endif
105 
106 #endif /* __SIM_IO_H__ */
107 
struct avr_io_t * next
Definition: sim_io.h:44
void avr_register_io(avr_t *avr, avr_io_t *io)
Registers an IO module, so it's run(), reset() etc are called.
Definition: sim_io.c:44
int avr_ioctl(avr_t *avr, uint32_t ctl, void *io_param)
Call every IO modules until one responds to this.
Definition: sim_io.c:30
avr_t * avr
avr we are attached to
Definition: sim_io.h:45
avr_irq_t * avr_iomem_getirq(avr_t *avr, avr_io_addr_t addr, const char *name, int index)
Get the IRQ for an absolute IO address.
Definition: sim_io.c:153
uint16_t avr_io_addr_t
Definition: sim_avr_types.h:37
void avr_register_io_write(avr_t *avr, avr_io_addr_t addr, avr_io_write_t write, void *param)
Register a callback for when the IO register is written. callback has to set the memory itself...
Definition: sim_io.c:83
uint32_t irq_ioctl_get
used to get irqs from this module
Definition: sim_io.h:50
int(* ioctl)(struct avr_io_t *io, uint32_t ctl, void *io_param)
Called externally. allow access to io modules and so on.
Definition: sim_io.h:57
avr_t * avr
Definition: run_avr.c:54
void(* dealloc)(struct avr_io_t *io)
Optional, a function to free up allocated system resources.
Definition: sim_io.h:59
const char * kind
pretty name, for debug
Definition: sim_io.h:46
void(* avr_io_write_t)(struct avr_t *avr, avr_io_addr_t addr, uint8_t v, void *param)
Definition: sim_avr.h:63
int irq_count
number of (optional) irqs
Definition: sim_io.h:51
struct avr_io_t avr_io_t
IO module base struct Modules uses that as their first member in their own struct.
struct avr_irq_t * irq
optional external IRQs
Definition: sim_io.h:52
const char * name
Definition: sim_irq.h:79
uint8_t(* avr_io_read_t)(struct avr_t *avr, avr_io_addr_t addr, void *param)
Definition: sim_avr.h:62
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 IO register "addr" is read.
Definition: sim_io.c:52
avr_irq_t * avr_io_setirqs(avr_io_t *io, uint32_t ctl, int count, avr_irq_t *irqs)
Sets an IO module "official" IRQs and the ioctl used to get to them.
Definition: sim_io.c:194
void(* reset)(struct avr_io_t *io)
Called at reset time.
Definition: sim_io.h:55
const char ** irq_names
IRQ names.
Definition: sim_io.h:48
Main AVR instance.
Definition: sim_avr.h:142
IO module base struct Modules uses that as their first member in their own struct.
Definition: sim_io.h:42
struct avr_irq_t * avr_io_getirq(avr_t *avr, uint32_t ctl, int index)
Get the specific irq for a module, check AVR_IOCTL_IOPORT_GETIRQ for example.
Definition: sim_io.c:140
Public IRQ structure.
Definition: sim_irq.h:76
void avr_deallocate_ios(avr_t *avr)
Terminates all IOs and remove from them from the io chain.
Definition: sim_io.c:270