SimAVR
AVR Simulator
avr_spi.h
Go to the documentation of this file.
1 /*
2  * avr_spi.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_SPI_H__
26 #define __AVR_SPI_H__
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "sim_avr.h"
34 
35  enum
36  {
40  };
41 
43 #define AVR_IOCTL_SPI_GETIRQ(_name) AVR_IOCTL_DEF('s','p','i',(_name))
44 
45  typedef struct avr_spi_t
46  {
48  char name;
50 
54 
58 
60 
62  } avr_spi_t;
63 
64  void avr_spi_init (avr_t * avr, avr_spi_t * port);
65 
66 #define AVR_SPI_DECLARE(_prr, _prspi) \
67  .spi = { \
68  .disabled = AVR_IO_REGBIT(_prr, _prspi), \
69  \
70  .r_spdr = SPDR, \
71  .r_spcr = SPCR, \
72  .r_spsr = SPSR, \
73  \
74  .spe = AVR_IO_REGBIT(SPCR, SPE), \
75  .mstr = AVR_IO_REGBIT(SPCR, MSTR), \
76  \
77  .spr = { AVR_IO_REGBIT(SPCR, SPR0), AVR_IO_REGBIT(SPCR, SPR1), AVR_IO_REGBIT(SPSR, SPI2X) }, \
78  .spi = { \
79  .enable = AVR_IO_REGBIT(SPCR, SPIE), \
80  .raised = AVR_IO_REGBIT(SPSR, SPIF), \
81  .vector = SPI_STC_vect, \
82  }, \
83  }
84 
85 #ifdef __cplusplus
86 };
87 #endif
88 
89 #endif /*__AVR_SPI_H__*/
90 
avr_regbit_t spr[4]
clock divider
Definition: avr_spi.h:57
avr_regbit_t disabled
bit in the PRR
Definition: avr_spi.h:49
avr_regbit_t spe
spi enable
Definition: avr_spi.h:55
char name
Definition: avr_spi.h:48
uint16_t avr_io_addr_t
Definition: sim_avr_types.h:37
avr_io_addr_t r_spdr
data register
Definition: avr_spi.h:51
avr_io_addr_t r_spsr
status register
Definition: avr_spi.h:53
avr_t * avr
Definition: run_avr.c:54
Definition: avr_spi.h:37
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_spi.h:38
avr_int_vector_t spi
spi interrupt
Definition: avr_spi.h:59
Definition: avr_spi.h:45
Definition: avr_spi.h:39
struct avr_spi_t avr_spi_t
avr_io_addr_t r_spcr
control register
Definition: avr_spi.h:52
uint8_t input_data_register
Definition: avr_spi.h:61
avr_io_t io
Definition: avr_spi.h:47
void avr_spi_init(avr_t *avr, avr_spi_t *port)
Definition: avr_spi.c:106
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
avr_regbit_t mstr
master/slave
Definition: avr_spi.h:56