SimAVR
AVR Simulator
avr_ioport.h
Go to the documentation of this file.
1 /*
2  * avr_ioport.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 __AVR_IOPORT_H__
26 #define __AVR_IOPORT_H__
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "sim_avr.h"
34 
35  enum
36  {
44  };
45 
46 #define AVR_IOPORT_OUTPUT 0x100
47 
49 #define AVR_IOCTL_IOPORT_GETIRQ(_name) AVR_IOCTL_DEF('i','o','g',(_name))
50 
53  typedef struct avr_ioport_getirq_t
54  {
56  avr_irq_t *irq[8];
58 
59 #define AVR_IOCTL_IOPORT_GETIRQ_REGBIT AVR_IOCTL_DEF('i','o','g','r')
60 
71  typedef struct avr_ioport_state_t
72  {
73  unsigned long name:7, port:8, ddr:8, pin:8;
75 
77 #define AVR_IOCTL_IOPORT_GETSTATE(_name) AVR_IOCTL_DEF('i','o','s',(_name))
78 
80  typedef struct avr_ioport_external_t
81  {
82  unsigned long name:7, mask:8, value:8;
84 
86 #define AVR_IOCTL_IOPORT_SET_EXTERNAL(_name) AVR_IOCTL_DEF('i','o','p',(_name))
87 
89  typedef struct avr_iopin_t
90  {
91  uint16_t port:8;
92  uint16_t pin:8;
93  } avr_iopin_t;
94 #define AVR_IOPIN(_port, _pin) { .port = _port, .pin = _pin }
95 
97  typedef struct avr_ioport_t
98  {
100  char name;
104 
107 
111  struct
112  {
114  } external;
115  } avr_ioport_t;
116 
117  void avr_ioport_init (avr_t * avr, avr_ioport_t * port);
118 
119 #define AVR_IOPORT_DECLARE(_lname, _cname, _uname) \
120  .port ## _lname = { \
121  .name = _cname, .r_port = PORT ## _uname, .r_ddr = DDR ## _uname, .r_pin = PIN ## _uname, \
122  }
123 
124 #ifdef __cplusplus
125 };
126 #endif
127 
128 #endif /* __AVR_IOPORT_H__ */
129 
uint8_t pull_mask
Definition: avr_ioport.h:113
Definition: avr_ioport.h:40
uint16_t port
port e.g. 'B'
Definition: avr_ioport.h:91
Definition: avr_ioport.h:37
avr_regbit_t bit
bit wanted
Definition: avr_ioport.h:55
unsigned long ddr
Definition: avr_ioport.h:73
avr_irq_t * irq[8]
result, terminated by NULL if < 8
Definition: avr_ioport.h:56
pin structure
Definition: avr_ioport.h:89
Definition: avr_ioport.h:38
uint16_t avr_io_addr_t
Definition: sim_avr_types.h:37
avr_io_addr_t r_port
Definition: avr_ioport.h:101
uint8_t pull_value
Definition: avr_ioport.h:113
Definition: avr_ioport.h:37
struct avr_ioport_t::@8 external
this represent the default IRQ value when the port is set as input.
Definition: avr_ioport.h:37
struct avr_iopin_t avr_iopin_t
pin structure
avr_t * avr
Definition: run_avr.c:54
Definition: avr_ioport.h:37
struct avr_ioport_state_t avr_ioport_state_t
ioctl used to get a port state.
unsigned long port
Definition: avr_ioport.h:73
Definition: avr_ioport.h:38
avr_io_addr_t r_pin
Definition: avr_ioport.h:103
Definition: avr_ioport.h:42
ioctl used to set default port state when set as input.
Definition: avr_ioport.h:80
unsigned long name
Definition: avr_ioport.h:73
unsigned long mask
Definition: avr_ioport.h:82
interrupt vector for the IO modules
Definition: sim_interrupts.h:37
This 'structure' is a packed representation of an IO register 'bit' (or consecutive bits)...
Definition: sim_avr_types.h:47
Definition: avr_ioport.h:43
this ioctl takes a avr_regbit_t, compares the register address to PORT/PIN/DDR and return the corresp...
Definition: avr_ioport.h:53
avr_io_addr_t r_ddr
Definition: avr_ioport.h:102
Definition: avr_ioport.h:38
struct avr_ioport_t avr_ioport_t
Definition for an IO port.
Definition: avr_ioport.h:39
void avr_ioport_init(avr_t *avr, avr_ioport_t *port)
Definition: avr_ioport.c:240
avr_io_t io
Definition: avr_ioport.h:99
unsigned long name
Definition: avr_ioport.h:82
ioctl used to get a port state.
Definition: avr_ioport.h:71
avr_io_addr_t r_pcint
pcint 8 pins mask
Definition: avr_ioport.h:106
unsigned long pin
Definition: avr_ioport.h:73
unsigned long value
Definition: avr_ioport.h:82
Definition: avr_ioport.h:38
avr_int_vector_t pcint
PCINT vector.
Definition: avr_ioport.h:105
char name
Definition: avr_ioport.h:100
uint16_t pin
pin number
Definition: avr_ioport.h:92
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_ioport_external_t avr_ioport_external_t
ioctl used to set default port state when set as input.
Public IRQ structure.
Definition: sim_irq.h:76
struct avr_ioport_getirq_t avr_ioport_getirq_t
this ioctl takes a avr_regbit_t, compares the register address to PORT/PIN/DDR and return the corresp...
Definition: avr_ioport.h:41
Definition for an IO port.
Definition: avr_ioport.h:97