Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
spi_slave_hs_arch.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi 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 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi 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.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef SPI_SLAVE_HS_ARCH_H
25 #define SPI_SLAVE_HS_ARCH_H
26 
27 /*
28 
29  Highspeed SPI Slave Interface
30  SS on P0.20
31  Circular Buffer
32 
33 */
34 
35 #include "std.h"
36 
37 
38 #define SpiEnable() { \
39  SetBit(SSPCR1, SSE); \
40  }
41 
42 #define SpiDisable() { \
43  ClearBit(SSPCR1, SSE); \
44  }
45 
46 
47 #define SPI_SLAVE_HS_RX_BUFFER_SIZE 256
48 
51 
52 #define SpiSlaveChAvailable() (spi_slave_hs_rx_insert_idx != spi_slave_hs_rx_extract_idx)
53 
54 #define SpiSlaveGetch() ({\
55  uint8_t ret = spi_slave_hs_rx_buffer[spi_slave_hs_rx_extract_idx]; \
56  spi_slave_hs_rx_extract_idx = (spi_slave_hs_rx_extract_idx + 1)%SPI_SLAVE_HS_RX_BUFFER_SIZE; \
57  ret; \
58 })
59 
60 #define SPI_SLAVE_HS_TX_BUFFER_SIZE 64
61 
64 
65 #define SpiSlaveTransmit(data) {\
66  uint8_t temp = (spi_slave_hs_tx_insert_idx + 1) % SPI_SLAVE_HS_TX_BUFFER_SIZE; \
67  if (temp != spi_slave_hs_tx_extract_idx) /* there is room left */ \
68  { \
69  spi_slave_hs_tx_buffer[spi_slave_hs_tx_insert_idx] = (uint8_t)data; \
70  spi_slave_hs_tx_insert_idx = temp; \
71  } \
72 }
73 
74 
75 
76 
77 #endif
unsigned short uint16_t
Definition: types.h:16
uint16_t spi_slave_hs_rx_insert_idx
uint8_t spi_slave_hs_tx_buffer[SPI_SLAVE_HS_TX_BUFFER_SIZE]
#define SPI_SLAVE_HS_TX_BUFFER_SIZE
uint16_t spi_slave_hs_rx_extract_idx
#define SPI_SLAVE_HS_RX_BUFFER_SIZE
unsigned char uint8_t
Definition: types.h:14
uint8_t spi_slave_hs_tx_extract_idx
uint8_t spi_slave_hs_tx_insert_idx
uint8_t spi_slave_hs_rx_buffer[SPI_SLAVE_HS_RX_BUFFER_SIZE]