IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
| Source at commit 9c64024af55259eb27fe2d86aa8e26257c996342 created 7 years 1 month ago. By Stefan Schmidt, atusb/Makefile: add missing atusb back layer to upload target | |
|---|---|
| 1 | /* |
| 2 | * fw/spi.c - ATmega8 family SPI I/O |
| 3 | * |
| 4 | * Written 2011, 2013 by Werner Almesberger |
| 5 | * Copyright 2011, 2013 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <stdbool.h> |
| 15 | #include <stdint.h> |
| 16 | |
| 17 | #include <avr/io.h> |
| 18 | |
| 19 | #include "board.h" |
| 20 | #include "spi.h" |
| 21 | |
| 22 | |
| 23 | uint8_t spi_io(uint8_t v) |
| 24 | { |
| 25 | // while (!(UCSR1A & 1 << UDRE1)); |
| 26 | SPI_DATA = v; |
| 27 | SPI_WAIT_DONE(); |
| 28 | return SPI_DATA; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | void spi_end(void) |
| 33 | { |
| 34 | // while (!(UCSR1A & 1 << TXC1)); |
| 35 | SET(nSS); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | void spi_recv_block(uint8_t *buf, uint8_t n) |
| 40 | { |
| 41 | if (!n) |
| 42 | return; |
| 43 | SPI_DATA = 0; |
| 44 | while (--n) { |
| 45 | SPI_WAIT_DONE(); |
| 46 | *buf++ = SPI_DATA; |
| 47 | SPI_DATA = 0; |
| 48 | } |
| 49 | SPI_WAIT_DONE(); |
| 50 | *buf++ = SPI_DATA; |
| 51 | } |
| 52 | |
