projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'mjb/master'
[fw/altos]
/
src
/
cc1111
/
ao_spi.c
diff --git
a/src/cc1111/ao_spi.c
b/src/cc1111/ao_spi.c
index fbe613c759762bc4766f8ab47e9c56362fcc2d88..88cff9dd11815a7a02ef107c499959e6e927d6a2 100644
(file)
--- a/
src/cc1111/ao_spi.c
+++ b/
src/cc1111/ao_spi.c
@@
-28,7
+28,7
@@
__xdata uint8_t ao_spi_dma_out_done;
uint8_t ao_spi_dma_out_id;
uint8_t ao_spi_dma_in_id;
uint8_t ao_spi_dma_out_id;
uint8_t ao_spi_dma_in_id;
-static __xdata uint8_t ao_spi_const
= 0xff
;
+static __xdata uint8_t ao_spi_const;
/* Send bytes over SPI.
*
/* Send bytes over SPI.
*
@@
-38,8
+38,9
@@
static __xdata uint8_t ao_spi_const = 0xff;
* completion one byte before the transfer is actually complete
*/
void
* completion one byte before the transfer is actually complete
*/
void
-ao_spi_send(void __xdata *block, uint16_t len) __reentrant
+ao_spi_send
_bus
(void __xdata *block, uint16_t len) __reentrant
{
{
+#if !AO_SPI_SLAVE
ao_dma_set_transfer(ao_spi_dma_in_id,
&U0DBUFXADDR,
&ao_spi_const,
ao_dma_set_transfer(ao_spi_dma_in_id,
&U0DBUFXADDR,
&ao_spi_const,
@@
-50,7
+51,7
@@
ao_spi_send(void __xdata *block, uint16_t len) __reentrant
DMA_CFG1_SRCINC_0 |
DMA_CFG1_DESTINC_0 |
DMA_CFG1_PRIORITY_NORMAL);
DMA_CFG1_SRCINC_0 |
DMA_CFG1_DESTINC_0 |
DMA_CFG1_PRIORITY_NORMAL);
-
+#endif
ao_dma_set_transfer(ao_spi_dma_out_id,
block,
&U0DBUFXADDR,
ao_dma_set_transfer(ao_spi_dma_out_id,
block,
&U0DBUFXADDR,
@@
-62,11
+63,18
@@
ao_spi_send(void __xdata *block, uint16_t len) __reentrant
DMA_CFG1_DESTINC_0 |
DMA_CFG1_PRIORITY_NORMAL);
DMA_CFG1_DESTINC_0 |
DMA_CFG1_PRIORITY_NORMAL);
+#if !AO_SPI_SLAVE
ao_dma_start(ao_spi_dma_in_id);
ao_dma_start(ao_spi_dma_in_id);
+#endif
ao_dma_start(ao_spi_dma_out_id);
ao_dma_trigger(ao_spi_dma_out_id);
ao_dma_start(ao_spi_dma_out_id);
ao_dma_trigger(ao_spi_dma_out_id);
+#if AO_SPI_SLAVE
+ __critical while (!ao_spi_dma_out_done)
+ ao_sleep(&ao_spi_dma_out_done);
+#else
__critical while (!ao_spi_dma_in_done)
ao_sleep(&ao_spi_dma_in_done);
__critical while (!ao_spi_dma_in_done)
ao_sleep(&ao_spi_dma_in_done);
+#endif
}
/* Receive bytes over SPI.
}
/* Receive bytes over SPI.
@@
-76,7
+84,7
@@
ao_spi_send(void __xdata *block, uint16_t len) __reentrant
* clocks the data coming in.
*/
void
* clocks the data coming in.
*/
void
-ao_spi_recv(void __xdata *block, uint16_t len) __reentrant
+ao_spi_recv
_bus
(void __xdata *block, uint16_t len) __reentrant
{
ao_dma_set_transfer(ao_spi_dma_in_id,
&U0DBUFXADDR,
{
ao_dma_set_transfer(ao_spi_dma_in_id,
&U0DBUFXADDR,
@@
-89,6
+97,8
@@
ao_spi_recv(void __xdata *block, uint16_t len) __reentrant
DMA_CFG1_DESTINC_1 |
DMA_CFG1_PRIORITY_NORMAL);
DMA_CFG1_DESTINC_1 |
DMA_CFG1_PRIORITY_NORMAL);
+ ao_spi_const = 0xff;
+
ao_dma_set_transfer(ao_spi_dma_out_id,
&ao_spi_const,
&U0DBUFXADDR,
ao_dma_set_transfer(ao_spi_dma_out_id,
&ao_spi_const,
&U0DBUFXADDR,
@@
-113,10
+123,19
@@
ao_spi_recv(void __xdata *block, uint16_t len) __reentrant
* MO P1_5
* MI P1_4
* CLK P1_3
* MO P1_5
* MI P1_4
* CLK P1_3
+ * CSS P1_2
*
*
- * Chip select is the responsibility of the caller
+ * Chip select is the responsibility of the caller
in master mode
*/
*/
+#if AO_SPI_SLAVE
+#define CSS (1 << 2)
+#define UxCSR_DIRECTION UxCSR_SLAVE
+#else
+#define CSS 0
+#define UxCSR_DIRECTION UxCSR_MASTER
+#endif
+
void
ao_spi_init(void)
{
void
ao_spi_init(void)
{
@@
-129,7
+148,7
@@
ao_spi_init(void)
P2SEL = (P2SEL & ~P2SEL_PRI3P1_MASK) | P2SEL_PRI3P1_USART0;
/* Make the SPI pins be controlled by the USART peripheral */
P2SEL = (P2SEL & ~P2SEL_PRI3P1_MASK) | P2SEL_PRI3P1_USART0;
/* Make the SPI pins be controlled by the USART peripheral */
- P1SEL |= ((1 << 5) | (1 << 4) | (1 << 3));
+ P1SEL |= ((1 << 5) | (1 << 4) | (1 << 3)
| CSS
);
/* Set up OUT DMA */
ao_spi_dma_out_id = ao_dma_alloc(&ao_spi_dma_out_done);
/* Set up OUT DMA */
ao_spi_dma_out_id = ao_dma_alloc(&ao_spi_dma_out_done);
@@
-141,7
+160,7
@@
ao_spi_init(void)
*
* SPI master mode
*/
*
* SPI master mode
*/
- U0CSR = (UxCSR_MODE_SPI | UxCSR_RE | UxCSR_
MASTER
);
+ U0CSR = (UxCSR_MODE_SPI | UxCSR_RE | UxCSR_
DIRECTION
);
/* Set the baud rate and signal parameters
*
/* Set the baud rate and signal parameters
*