4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
25 static void avr_spi_run(avr_t * avr, avr_io_t * port)
27 // printf("%s\n", __FUNCTION__);
30 static uint8_t avr_spi_read(struct avr_t * avr, uint8_t addr, void * param)
32 avr_spi_t * p = (avr_spi_t *)param;
33 uint8_t v = avr->data[addr];
34 // printf("** PIN%c = %02x\n", p->name, v);
38 static void avr_spi_write(struct avr_t * avr, uint8_t addr, uint8_t v, void * param)
40 avr_spi_t * p = (avr_spi_t *)param;
42 if (addr == p->r_spdr) {
43 // printf("UDR%c(%02x) = %02x\n", p->name, addr, v);
44 avr_core_watch_write(avr, addr, v);
48 static void avr_spi_irq_input(avr_t * avr, struct avr_irq_t * irq, uint32_t value, void * param)
50 avr_spi_t * p = (avr_spi_t *)param;
52 // check to see fi receiver is enabled
53 if (!avr_regbit_get(avr, p->spe))
56 // double buffer the input.. ?
59 void avr_spi_reset(avr_t * avr, struct avr_io_t *io)
61 avr_spi_t * p = (avr_spi_t *)io;
62 avr_irq_register_notify(avr, p->io.irq + SPI_IRQ_INPUT, avr_spi_irq_input, p);
65 static avr_io_t _io = {
68 .reset = avr_spi_reset,
71 void avr_spi_init(avr_t * avr, avr_spi_t * p)
74 avr_register_io(avr, &p->io);
76 printf("%s SPI%c init\n", __FUNCTION__, p->name);
78 // allocate this module's IRQ
79 p->io.irq_count = SPI_IRQ_COUNT;
80 p->io.irq = avr_alloc_irq(avr, 0, p->io.irq_count);
81 p->io.irq_ioctl_get = AVR_IOCTL_SPI_GETIRQ(p->name);
83 avr_register_io_write(avr, p->r_spdr, avr_spi_write, p);
84 avr_register_io_read(avr, p->r_spdr, avr_spi_read, p);