roneos
Operating System for the r-one robot
 All Data Structures Files Functions Variables Typedefs Groups
spi.h
Go to the documentation of this file.
1 
10 #ifndef SPI_H_
11 #define SPI_H_
12 
13 /******** Defines ********/
14 
15 #define SPI_NULL 0
16 #define SPI_RADIO 1
17 #define SPI_ACCELEROMETER 2
18 #define SPI_LEDS_ONOFF 3
19 #define SPI_LEDS_DIMMER 4
20 #define SPI_MSP430 5
21 #define SPI_SDCARD 7
22 #define SPI_AUDIOSDI 8
23 #define SPI_AUDIOSCI 9
24 #define SPI_EXPAND0 10
25 #define SPI_EXPAND1 11
26 
27 //TODO Determine what speed we set the SPI clock to, it might be a bottleneck.
28 #define SPI_RADIO_FREQUENCY 5000000
29 #define SPI_MSP430_FREQUENCY 2000000
30 #define SPI_SDCARD_FREQUENCY 350000
31 #define SPI_AUDIOSDI_FREQUENCY 2000000
32 #define SPI_AUDIOSCI_FREQUENCY 2000000
33 #define SPI_EXPAND0_FREQUENCY 1000000
34 #define SPI_EXPAND1_FREQUENCY 1000000
35 #define SPI_NULL_FREQUENCY 1000000
36 
37 #define SPI_RADIO_WORDSIZE 8
38 #define SPI_LEDS_ONOFF_WORDSIZE 16
39 #define SPI_LEDS_DIMMER_WORDSIZE 7
40 #define SPI_MSP430_WORDSIZE 8
41 #define SPI_SDCARD_WORDSIZE 8
42 #define SPI_AUDIO_WORDSIZE 16
43 //TODO: maj5 - added the define because when I tried to define RONE_V6 it wasn't define, so the number is random
44 #define SPI_ACCELEROMETER_WORDSIZE 8
45 #define SPI_EXPAND_WORDSIZE 8
46 
47 #if defined(RONE_V6)
48 
49 #define SPI_MOSI_PIN GPIO_PIN_5
50 #define SPI_MISO_PIN GPIO_PIN_4
51 #define SPI_CLK_PIN GPIO_PIN_2
52 
53 #define RADIO_SELECT_PORT GPIO_PORTA_BASE
54 #define RADIO_SELECT_PERIPH SYSCTL_PERIPH_GPIOA
55 #define RADIO_SELECT_PIN GPIO_PIN_7
56 
57 #define LED_LE_SYSCTL SYSCTL_PERIPH_GPIOA
58 #define LED_LE_PORT GPIO_PORTA_BASE
59 #define LED_LE_PIN GPIO_PIN_6
60 
61 #define ACCELEROMETER_SELECT_SYSCTL SYSCTL_PERIPH_GPIOA
62 #define ACCELEROMETER_SELECT_PORT GPIO_PORTA_BASE
63 #define ACCELEROMETER_SELECT_PIN GPIO_PIN_3
64 #elif defined(RONE_V9)
65  #define SPI_ENABLE_PERIPH SYSCTL_PERIPH_GPIOG
66  #define SPI_ENABLE_PORT GPIO_PORTG_BASE
67  #define SPI_ENABLE_PIN GPIO_PIN_0
68 
69  #define SPI_MOSI_PIN GPIO_PIN_5
70  #define SPI_MISO_PIN GPIO_PIN_4
71  #define SPI_CLK_PIN GPIO_PIN_2
72 
73  #define SPI_SELECT_PERIPH SYSCTL_PERIPH_GPIOA
74  #define SPI_SELECT_PORT GPIO_PORTA_BASE
75  #define SPI_SELECT_PINS (GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_7)
76  #define NULL_SELECT_PINS (0 | 0 | 0 )
77  #define MSP430_SELECT_PINS (GPIO_PIN_3 | 0 | 0 )
78  #define RADIO_SELECT_PINS (0 | GPIO_PIN_6 | 0 )
79  #define AUDIOSCI_SELECT_PINS (GPIO_PIN_3 | GPIO_PIN_6 | 0 )
80  #define AUDIOSDI_SELECT_PINS (0 | 0 | GPIO_PIN_7)
81  #define SDCARD_SELECT_PINS (GPIO_PIN_3 | 0 | GPIO_PIN_7)
82  #define EXPAND0_SELECT_PINS (0 | GPIO_PIN_6 | GPIO_PIN_7)
83  #define EXPAND1_SELECT_PINS (GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_7)
84 #elif defined(RONE_V12)
85  #define SPI_ENABLE_PERIPH SYSCTL_PERIPH_GPIOG
86  #define SPI_ENABLE_PORT GPIO_PORTG_BASE
87  #define SPI_ENABLE_PIN GPIO_PIN_0
88 
89  #define SPI_MOSI_PIN GPIO_PIN_5
90  #define SPI_MISO_PIN GPIO_PIN_4
91  #define SPI_CLK_PIN GPIO_PIN_2
92 
93  #define SPI_SELECT_PERIPH SYSCTL_PERIPH_GPIOA
94  #define SPI_SELECT_PORT GPIO_PORTA_BASE
95  #define SPI_SELECT_PINS (GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_7)
96  #define NULL_SELECT_PINS (0 | 0 | 0 )
97  #define MSP430_SELECT_PINS (GPIO_PIN_3 | 0 | 0 )
98  #define RADIO_SELECT_PINS (0 | GPIO_PIN_6 | 0 )
99  #define AUDIOSCI_SELECT_PINS (GPIO_PIN_3 | GPIO_PIN_6 | 0 )
100  #define AUDIOSDI_SELECT_PINS (0 | 0 | GPIO_PIN_7)
101  #define SDCARD_SELECT_PINS (GPIO_PIN_3 | 0 | GPIO_PIN_7)
102  #define EXPAND0_SELECT_PINS (0 | GPIO_PIN_6 | GPIO_PIN_7)
103  #define EXPAND1_SELECT_PINS (GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_7)
104 #else
105  //#error "Robot type must be defined: V6, V9, V12, or IR Beacon"
106 #endif
107 
108 #define SPI_MAX_XFER_IRQ_DELAY 32
109 
110 /******** Functions ********/
111 
112 
122 void SPIInit(void);
123 
124 
132 void SPISelectDevice(uint8 device);
133 
134 
140 void SPISelectDeviceISR(uint8 device);
141 
142 
149 void SPIDeselect(void);
150 
151 
158 void SPIDeselectSynchronous(void);
159 
160 
166 boolean SPIDeselectISR(void);
167 
168 
176 void SPISemaphoreGiveFromISR(void);
177 
178 
189 boolean SPIXmitNullByte(uint8 dat);
190 
191 
205 void SPIXmitNullBytes(uint8 device, uint16 numBytes);
206 
207 
222 void SPIConfigure(uint32 ulBase, uint8 wordSize, uint8 mode, uint32 frequency);
223 
224 
231 void SPIConfigureDevice(uint8 device);
232 
233 
234 #endif /* SPI_H_ */