SimAVR
AVR Simulator
avr_twi.h
Go to the documentation of this file.
1 /*
2  * avr_twi.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_TWI_H__
26 #define __AVR_TWI_H__
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "sim_avr.h"
34 
35  // #include "sim_twi.h"
36 
37  enum
38  {
43  };
44 
45  enum
46  {
47  TWI_COND_START = (1 << 0),
48  TWI_COND_STOP = (1 << 1),
49  TWI_COND_ADDR = (1 << 2),
50  TWI_COND_ACK = (1 << 3),
51  TWI_COND_WRITE = (1 << 4),
52  TWI_COND_READ = (1 << 5),
54  TWI_COND_SLAVE = (1 << 6),
55  };
56 
57  typedef struct avr_twi_msg_t
58  {
59  uint32_t unused:8, msg:8, addr:8, data:8;
60  } avr_twi_msg_t;
61 
62  typedef struct avr_twi_msg_irq_t
63  {
64  union
65  {
66  uint32_t v;
68  } u;
70 
72 #define AVR_IOCTL_TWI_GETIRQ(_name) AVR_IOCTL_DEF('t','w','i',(_name))
73 
74  typedef struct avr_twi_t
75  {
77  char name;
78 
80 
87 
93 
96 
98 
99  uint8_t state;
100  uint8_t peer_addr;
101  uint8_t next_twstate;
102  } avr_twi_t;
103 
104  void avr_twi_init (avr_t * avr, avr_twi_t * port);
105 
110  uint32_t avr_twi_irq_msg (uint8_t msg, uint8_t addr, uint8_t data);
111 
112 #ifdef __cplusplus
113 };
114 #endif
115 
116 #endif /*__AVR_TWI_H__*/
117 
avr_io_addr_t r_twdr
data register
Definition: avr_twi.h:86
uint8_t state
Definition: avr_twi.h:99
internal state, do not use in irq messages
Definition: avr_twi.h:54
avr_io_addr_t r_twbr
bit rate register
Definition: avr_twi.h:81
uint32_t v
Definition: avr_twi.h:66
Definition: avr_twi.h:42
uint8_t next_twstate
Definition: avr_twi.h:101
uint32_t msg
Definition: avr_twi.h:59
Definition: avr_twi.h:52
uint16_t avr_io_addr_t
Definition: sim_avr_types.h:37
avr_regbit_t twsr
status registers, (5 bits)
Definition: avr_twi.h:94
char name
Definition: avr_twi.h:77
struct avr_twi_msg_t avr_twi_msg_t
avr_t * avr
Definition: run_avr.c:54
uint32_t addr
Definition: avr_twi.h:59
Definition: avr_twi.h:47
avr_io_addr_t r_twsr
status register
Definition: avr_twi.h:83
uint8_t peer_addr
Definition: avr_twi.h:100
avr_io_addr_t r_twar
address register (slave)
Definition: avr_twi.h:84
Definition: avr_twi.h:62
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
avr_regbit_t twsto
stop condition
Definition: avr_twi.h:91
struct avr_twi_msg_irq_t avr_twi_msg_irq_t
Definition: avr_twi.h:39
Definition: avr_twi.h:41
uint32_t avr_twi_irq_msg(uint8_t msg, uint8_t addr, uint8_t data)
Create a message value for twi including the 'msg' bitfield, 'addr' and data.
Definition: avr_twi.c:476
Definition: avr_twi.h:50
avr_regbit_t twen
twi enable bit
Definition: avr_twi.h:88
avr_io_addr_t r_twamr
address mask register
Definition: avr_twi.h:85
struct avr_twi_t avr_twi_t
avr_int_vector_t twi
twi interrupt
Definition: avr_twi.h:97
union avr_twi_msg_irq_t::@17 u
avr_regbit_t twps
prescaler bits (2 bits)
Definition: avr_twi.h:95
avr_regbit_t twea
enable acknowledge bit
Definition: avr_twi.h:89
Definition: avr_twi.h:51
uint32_t data
Definition: avr_twi.h:59
Definition: avr_twi.h:74
avr_regbit_t twsta
start condition
Definition: avr_twi.h:90
Definition: avr_twi.h:40
Definition: avr_twi.h:57
Definition: avr_twi.h:48
uint32_t unused
Definition: avr_twi.h:59
avr_regbit_t twwc
write collision
Definition: avr_twi.h:92
avr_io_addr_t r_twcr
control register
Definition: avr_twi.h:82
avr_twi_msg_t twi
Definition: avr_twi.h:67
avr_io_t io
Definition: avr_twi.h:76
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
void avr_twi_init(avr_t *avr, avr_twi_t *port)
Definition: avr_twi.c:458
Definition: avr_twi.h:49
avr_regbit_t disabled
bit in the PRR
Definition: avr_twi.h:79