altos/teletiny-v2.0: Support multiple SPI busses on CC1111
authorKeith Packard <keithp@keithp.com>
Wed, 12 Jun 2013 07:43:31 +0000 (00:43 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 26 Aug 2013 05:24:01 +0000 (22:24 -0700)
Needed for TeleMini v2.0

Signed-off-by: Keith Packard <keithp@keithp.com>
src/cc1111/ao_arch.h
src/cc1111/ao_arch_funcs.h
src/cc1111/ao_spi.c
src/drivers/ao_ms5607.c
src/telemini-v2.0/ao_pins.h
src/telemini-v2.0/ao_telemini.c

index 9097557ffd3460359f148aa8343dba3851b0a462..34235b085421d3c49d2d86852d57f0ff39b335eb 100644 (file)
@@ -321,4 +321,9 @@ void
 ao_serial1_tx_isr(void) ao_arch_interrupt(14);
 #endif
 
 ao_serial1_tx_isr(void) ao_arch_interrupt(14);
 #endif
 
+#if HAS_EXTI_0
+void
+ao_p0_isr(void) __interrupt(13);
+#endif
+
 #endif /* _AO_ARCH_H_ */
 #endif /* _AO_ARCH_H_ */
index 8f1cc09476e099766247de88705fe3bbd22bb54d..ae1841089c0a59383b6919c7fcd424a5c9bfd7e6 100644 (file)
  * ao_spi.c
  */
 
  * ao_spi.c
  */
 
-extern __xdata uint8_t ao_spi_mutex;
+#if !HAS_SPI_0 && !HAS_SPI_1
+#define HAS_SPI_0      1
+#define SPI_0_ALT_2    1
+#endif
+
+#if HAS_SPI_0 && HAS_SPI_1
+#define MULTI_SPI      1
+#define N_SPI          2
+#else
+#define MULTI_SPI      0
+#define N_SPI          1
+#endif
+
+extern __xdata uint8_t ao_spi_mutex[N_SPI];
+
+#if MULTI_SPI
+#define ao_spi_get(bus)        ao_mutex_get(&ao_spi_mutex[bus])
+#define ao_spi_put(bus)        ao_mutex_put(&ao_spi_mutex[bus])
+#else
+#define ao_spi_get(bus)        ao_mutex_get(&ao_spi_mutex[0])
+#define ao_spi_put(bus)        ao_mutex_put(&ao_spi_mutex[0])
+#endif
 
 #define AO_SPI_SPEED_FAST      17
 #define AO_SPI_SPEED_200kHz    13
 
 
 #define AO_SPI_SPEED_FAST      17
 #define AO_SPI_SPEED_200kHz    13
 
-#define ao_spi_set_speed(speed) (U0GCR = (UxGCR_CPOL_NEGATIVE |                \
-                                         UxGCR_CPHA_FIRST_EDGE |       \
-                                         UxGCR_ORDER_MSB |             \
-                                         ((speed) << UxGCR_BAUD_E_SHIFT)))
+#if MULTI_SPI
+#define ao_spi_set_speed(bus,speed) (*(bus ? &U1GCR : &U0GCR) =(UxGCR_CPOL_NEGATIVE | \
+                                                               UxGCR_CPHA_FIRST_EDGE | \
+                                                               UxGCR_ORDER_MSB | \
+                                                               ((speed) << UxGCR_BAUD_E_SHIFT)))
+#else
+#define ao_spi_set_speed(bus,speed) (U0GCR = (UxGCR_CPOL_NEGATIVE |    \
+                                             UxGCR_CPHA_FIRST_EDGE |   \
+                                             UxGCR_ORDER_MSB |         \
+                                             ((speed) << UxGCR_BAUD_E_SHIFT)))
+#endif
 
 #define ao_spi_get_slave(bus) do {                     \
 
 #define ao_spi_get_slave(bus) do {                     \
-               ao_mutex_get(&ao_spi_mutex);            \
-               ao_spi_set_speed(AO_SPI_SPEED_FAST);    \
+               ao_spi_get(bus);                        \
+               ao_spi_set_speed(bus,AO_SPI_SPEED_FAST);        \
        } while (0)
 
 #define ao_spi_put_slave(bus) do {             \
        } while (0)
 
 #define ao_spi_put_slave(bus) do {             \
-               ao_mutex_put(&ao_spi_mutex);    \
+               ao_spi_put(bus);                \
        } while (0)
 
 #define ao_spi_get_mask(reg,mask,bus,speed) do {       \
        } while (0)
 
 #define ao_spi_get_mask(reg,mask,bus,speed) do {       \
-               ao_mutex_get(&ao_spi_mutex);            \
-               ao_spi_set_speed(speed);                \
+               ao_spi_get(bus);                        \
+               ao_spi_set_speed(bus,speed);            \
                (reg) &= ~(mask);                       \
        } while (0)
 
 #define ao_spi_put_mask(reg,mask,bus) do {             \
        (reg) |= (mask); \
                (reg) &= ~(mask);                       \
        } while (0)
 
 #define ao_spi_put_mask(reg,mask,bus) do {             \
        (reg) |= (mask); \
-       ao_mutex_put(&ao_spi_mutex); \
+       ao_spi_put(bus); \
        } while (0)
 
 
 #define ao_spi_get_bit(reg,bit,pin,bus,speed) do {     \
        } while (0)
 
 
 #define ao_spi_get_bit(reg,bit,pin,bus,speed) do {     \
-               ao_mutex_get(&ao_spi_mutex);    \
-               ao_spi_set_speed(speed);        \
-               pin = 0;                        \
+               ao_spi_get(bus);                        \
+               ao_spi_set_speed(bus,speed);            \
+               pin = 0;                                \
        } while (0)
 
 #define ao_spi_put_bit(reg,bit,pin,bus) do {   \
                pin = 1;                        \
        } while (0)
 
 #define ao_spi_put_bit(reg,bit,pin,bus) do {   \
                pin = 1;                        \
-               ao_mutex_put(&ao_spi_mutex);    \
+               ao_spi_put(bus);                \
        } while (0)
 
 
        } while (0)
 
 
@@ -68,6 +96,13 @@ extern __xdata uint8_t       ao_spi_mutex;
  * from chip select low to chip select high
  */
 
  * from chip select low to chip select high
  */
 
+#if MULTI_SPI
+void
+ao_spi_send(void __xdata *block, uint16_t len, uint8_t bus) __reentrant;
+
+void
+ao_spi_recv(void __xdata *block, uint16_t len, uint8_t bus) __reentrant;
+#else
 void
 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
 
 void
 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
 
@@ -76,6 +111,7 @@ ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant;
 
 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
 
 #define ao_spi_send(block, len, bus) ao_spi_send_bus(block, len)
 #define ao_spi_recv(block, len, bus) ao_spi_recv_bus(block, len)
+#endif
 
 #if AO_SPI_SLAVE
 void
 
 #if AO_SPI_SLAVE
 void
@@ -88,10 +124,15 @@ ao_spi_recv_wait(void);
 void
 ao_spi_init(void);
 
 void
 ao_spi_init(void);
 
-#define ao_spi_init_cs(port, mask) do {                \
-               SPI_CS_PORT |= mask;            \
-               SPI_CS_DIR |= mask;             \
-               SPI_CS_SEL &= ~mask;            \
+#define token_paster(x,y)      x ## y
+#define token_paster3(x,y,z)   x ## y ## z
+#define token_evaluator(x,y)   token_paster(x,y)
+#define token_evaluator3(x,y,z)        token_paster3(x,y,z)
+
+#define ao_spi_init_cs(port, mask) do {                        \
+               port |= mask;                           \
+               token_evaluator(port,DIR) |= mask;      \
+               token_evaluator(port,SEL) &= ~mask;     \
        } while (0)
 
 #define cc1111_enable_output(port,dir,sel,pin,bit,v) do {      \
        } while (0)
 
 #define cc1111_enable_output(port,dir,sel,pin,bit,v) do {      \
@@ -102,7 +143,6 @@ ao_spi_init(void);
 
 #define disable_unreachable    _Pragma("disable_warning 126")
 
 
 #define disable_unreachable    _Pragma("disable_warning 126")
 
-#define token_paster(x,y)      x ## y
-#define token_evaluator(x,y)   token_paster(x,y)
 #define ao_enable_output(port,bit,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), pin, bit, v)
 #define ao_gpio_set(port, bit, pin, v) ((pin) = (v))
 #define ao_enable_output(port,bit,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), pin, bit, v)
 #define ao_gpio_set(port, bit, pin, v) ((pin) = (v))
+
index cdef6bda9d85948bc45ec0fd3f427068c62b4560..fb08f3f5311332226901aaf71a6f2801813e22a4 100644 (file)
 #include "ao.h"
 
 /* Default pin usage for existing Altus Metrum devices */
 #include "ao.h"
 
 /* Default pin usage for existing Altus Metrum devices */
-#if !HAS_SPI_0 && !HAS_SPI_1
-#define HAS_SPI_0      1
-#define SPI_0_ALT_2    1
-#endif
 
 #ifndef SPI_CONST
 #define SPI_CONST      0xff
 
 #ifndef SPI_CONST
 #define SPI_CONST      0xff
  */
 
 #if HAS_SPI_0
  */
 
 #if HAS_SPI_0
-#define SPI_CSR                U0CSR
-#define SPI_BUF                U0DBUFXADDR
-#define SPI_BAUD       U0BAUD
-#define SPI_GCR                U0GCR
-#define SPI_CFG_MASK   PERCFG_U0CFG_ALT_MASK
-#define SPI_DMA_TX     DMA_CFG0_TRIGGER_UTX0
-#define SPI_DMA_RX     DMA_CFG0_TRIGGER_URX0
+#define SPI_BUF_0      &U0DBUFXADDR
+#define SPI_CSR_0      U0CSR
+#define SPI_BAUD_0     U0BAUD
+#define SPI_GCR_0      U0GCR
+#define SPI_CFG_MASK_0 PERCFG_U0CFG_ALT_MASK
+#define SPI_DMA_TX_0   DMA_CFG0_TRIGGER_UTX0
+#define SPI_DMA_RX_0   DMA_CFG0_TRIGGER_URX0
 
 #if SPI_0_ALT_1
 
 #if SPI_0_ALT_1
-#define SPI_CFG                PERCFG_U0CFG_ALT_1
-#define SPI_SEL                P0SEL
-#define SPI_BITS       (1 << 3) | (1 << 2) | (1 << 5)
-#define SPI_CSS_BIT    (1 << 4)
+#define SPI_CFG_0      PERCFG_U0CFG_ALT_1
+#define SPI_SEL_0      P0SEL
+#define SPI_BITS_0     (1 << 3) | (1 << 2) | (1 << 5)
+#define SPI_CSS_BIT_0  (1 << 4)
 #endif
 
 #if SPI_0_ALT_2
 #endif
 
 #if SPI_0_ALT_2
-#define SPI_CFG                PERCFG_U0CFG_ALT_2
-#define SPI_SEL                P1SEL
-#define SPI_PRI                P2SEL_PRI3P1_USART0
-#define SPI_BITS       (1 << 5) | (1 << 4) | (1 << 3)
-#define SPI_CSS_BIT    (1 << 2)
+#define SPI_CFG_0      PERCFG_U0CFG_ALT_2
+#define SPI_SEL_0      P1SEL
+#define SPI_PRI_0      P2SEL_PRI3P1_USART0
+#define SPI_BITS_0     (1 << 5) | (1 << 4) | (1 << 3)
+#define SPI_CSS_BIT_0  (1 << 2)
 #endif
 
 #endif
 
 #if HAS_SPI_1
 #endif
 
 #endif
 
 #if HAS_SPI_1
-#define SPI_CSR                U1CSR
-#define SPI_BUF                U1DBUFXADDR
-#define SPI_BAUD       U1BAUD
-#define SPI_GCR                U1GCR
-#define SPI_CFG_MASK   PERCFG_U1CFG_ALT_MASK
-#define SPI_DMA_TX     DMA_CFG0_TRIGGER_UTX1
-#define SPI_DMA_RX     DMA_CFG0_TRIGGER_URX1
+#define SPI_BUF_1      &U1DBUFXADDR
+#define SPI_CSR_1      U1CSR
+#define SPI_BAUD_1     U1BAUD
+#define SPI_GCR_1      U1GCR
+#define SPI_CFG_MASK_1 PERCFG_U1CFG_ALT_MASK
+#define SPI_DMA_TX_1   DMA_CFG0_TRIGGER_UTX1
+#define SPI_DMA_RX_1   DMA_CFG0_TRIGGER_URX1
 
 #if SPI_1_ALT_1
 
 #if SPI_1_ALT_1
-#define SPI_CFG                PERCFG_U1CFG_ALT_1
-#define SPI_SEL                P0SEL
-#define SPI_BITS       (1 << 4) | (1 << 5) | (1 << 3)
-#define SPI_CSS_BIT    (1 << 2)
+#define SPI_CFG_1      PERCFG_U1CFG_ALT_1
+#define SPI_SEL_1      P0SEL
+#define SPI_BITS_1     (1 << 4) | (1 << 5) | (1 << 3)
+#define SPI_CSS_BIT_1  (1 << 2)
 #endif
 
 #if SPI_1_ALT_2
 #endif
 
 #if SPI_1_ALT_2
-#define SPI_CFG                PERCFG_U1CFG_ALT_2
-#define SPI_SEL                P1SEL
-#define SPI_PRI                P2SEL_PRI3P1_USART1
-#define SPI_BITS       (1 << 6) | (1 << 7) | (1 << 5)
-#define SPI_CSS_BIT    (1 << 4)
+#define SPI_CFG_1      PERCFG_U1CFG_ALT_2
+#define SPI_SEL_1      P1SEL
+#define SPI_PRI_1      P2SEL_PRI3P1_USART1
+#define SPI_BITS_1     (1 << 6) | (1 << 7) | (1 << 5)
+#define SPI_CSS_BIT_1  (1 << 4)
 #endif
 
 #endif
 
 #endif
 
 #endif
 
+#if MULTI_SPI
+
+#define SPI_BUF(bus)           ((bus) ? SPI_BUF_1 : SPI_BUF_0)
+#define SPI_CSR(bus)           ((bus) ? SPI_CSR_1 : SPI_CSR_0)
+#define SPI_BAUD(bus)          ((bus) ? SPI_BAUD_1 : SPI_BAUD_0)
+#define SPI_GCR(bus)           ((bus) ? SPI_GCR_1 : SPI_GCR_0)
+#define SPI_CFG_MASK(bus)      ((bus) ? SPI_CFG_MASK_1 : SPI_CFG_MASK_0)
+#define SPI_DMA_TX(bus)                ((bus) ? SPI_DMA_TX_1 : SPI_DMA_TX_0)
+#define SPI_DMA_RX(bus)                ((bus) ? SPI_DMA_RX_1 : SPI_DMA_RX_0)
+#define SPI_CFG(bus)           ((bus) ? SPI_CFG_1 : SPI_CFG_0)
+#define SPI_SEL(bus)           ((bus) ? SPI_SEL_1 : SPI_SEL_0)
+#define SPI_BITS(bus)          ((bus) ? SPI_BITS_1 : SPI_BITS_0)
+#define SPI_CSS_BIT(bus)       ((bus) ? SPI_CSS_BIT_1 : SPI_CSS_BIT_0)
+
+#else
+
+#if HAS_SPI_0
+#define SPI_BUF(bus)           SPI_BUF_0
+#define SPI_CSR(bus)           SPI_CSR_0
+#define SPI_BAUD(bus)          SPI_BAUD_0
+#define SPI_GCR(bus)           SPI_GCR_0
+#define SPI_CFG_MASK(bus)      SPI_CFG_MASK_0
+#define SPI_DMA_TX(bus)                SPI_DMA_TX_0
+#define SPI_DMA_RX(bus)                SPI_DMA_RX_0
+#define SPI_CFG(bus)           SPI_CFG_0
+#define SPI_SEL(bus)           SPI_SEL_0
+#define SPI_BITS(bus)          SPI_BITS_0
+#define SPI_CSS_BIT(bus)       SPI_CSS_BIT_0
+#endif
+#if HAS_SPI_1
+#define SPI_BUF(bus)           SPI_BUF_1
+#define SPI_CSR(bus)           SPI_CSR_1
+#define SPI_BAUD(bus)          SPI_BAUD_1
+#define SPI_GCR(bus)           SPI_GCR_1
+#define SPI_CFG_MASK(bus)      SPI_CFG_MASK_1
+#define SPI_DMA_TX(bus)                SPI_DMA_TX_1
+#define SPI_DMA_RX(bus)                SPI_DMA_RX_1
+#define SPI_CFG(bus)           SPI_CFG_1
+#define SPI_SEL(bus)           SPI_SEL_1
+#define SPI_BITS(bus)          SPI_BITS_1
+#define SPI_CSS_BIT(bus)       SPI_CSS_BIT_1
+#endif
+
+#endif /* MULTI_SPI */
+
 #if AO_SPI_SLAVE
 #if AO_SPI_SLAVE
-#define CSS            SPI_CSS_BIT
+#define CSS(bus)               SPI_CSS_BIT(bus)
 #define UxCSR_DIRECTION        UxCSR_SLAVE
 #else
 #define UxCSR_DIRECTION        UxCSR_SLAVE
 #else
-#define CSS            0
+#define CSS(bus)               0
 #define UxCSR_DIRECTION        UxCSR_MASTER
 #endif
 
 #define UxCSR_DIRECTION        UxCSR_MASTER
 #endif
 
  * operation, from CS low to CS high. This means that any SPI
  * user must protect the SPI bus with this mutex
  */
  * operation, from CS low to CS high. This means that any SPI
  * user must protect the SPI bus with this mutex
  */
-__xdata uint8_t        ao_spi_mutex;
-__xdata uint8_t ao_spi_dma_in_done;
-__xdata uint8_t ao_spi_dma_out_done;
+__xdata uint8_t        ao_spi_mutex[N_SPI];
+__xdata uint8_t ao_spi_dma_in_done[N_SPI];
+__xdata uint8_t ao_spi_dma_out_done[N_SPI];
 
 
-uint8_t        ao_spi_dma_out_id;
-uint8_t ao_spi_dma_in_id;
+uint8_t        ao_spi_dma_out_id[N_SPI];
+uint8_t ao_spi_dma_in_id[N_SPI];
 
 static __xdata uint8_t ao_spi_const;
 
 
 static __xdata uint8_t ao_spi_const;
 
+
 /* Send bytes over SPI.
  *
  * This sets up two DMA engines, one writing the data and another reading
 /* Send bytes over SPI.
  *
  * This sets up two DMA engines, one writing the data and another reading
@@ -140,45 +182,52 @@ static __xdata uint8_t ao_spi_const;
  * is complete, as the transmit register is double buffered and hence signals
  * completion one byte before the transfer is actually complete
  */
  * is complete, as the transmit register is double buffered and hence signals
  * completion one byte before the transfer is actually complete
  */
+#if MULTI_SPI
+void
+ao_spi_send(void __xdata *block, uint16_t len, uint8_t bus) __reentrant
+#else
 void
 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant
 void
 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant
+#define bus    0
+#endif
 {
 {
-       ao_dma_set_transfer(ao_spi_dma_in_id,
-                           &SPI_BUF,
+       ao_dma_set_transfer(ao_spi_dma_in_id[bus],
+                           SPI_BUF(bus),
                            &ao_spi_const,
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
                            &ao_spi_const,
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
-                           SPI_DMA_RX,
+                           SPI_DMA_RX(bus),
                            DMA_CFG1_SRCINC_0 |
                            DMA_CFG1_DESTINC_0 |
                            DMA_CFG1_PRIORITY_NORMAL);
                            DMA_CFG1_SRCINC_0 |
                            DMA_CFG1_DESTINC_0 |
                            DMA_CFG1_PRIORITY_NORMAL);
-       ao_dma_set_transfer(ao_spi_dma_out_id,
+       ao_dma_set_transfer(ao_spi_dma_out_id[bus],
                            block,
                            block,
-                           &SPI_BUF,
+                           SPI_BUF(bus),
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
-                           SPI_DMA_TX,
+                           SPI_DMA_TX(bus),
                            DMA_CFG1_SRCINC_1 |
                            DMA_CFG1_DESTINC_0 |
                            DMA_CFG1_PRIORITY_NORMAL);
 
                            DMA_CFG1_SRCINC_1 |
                            DMA_CFG1_DESTINC_0 |
                            DMA_CFG1_PRIORITY_NORMAL);
 
-       ao_dma_start(ao_spi_dma_in_id);
-       ao_dma_start(ao_spi_dma_out_id);
-       ao_dma_trigger(ao_spi_dma_out_id);
+       ao_dma_start(ao_spi_dma_in_id[bus]);
+       ao_dma_start(ao_spi_dma_out_id[bus]);
+       ao_dma_trigger(ao_spi_dma_out_id[bus]);
 #if !AO_SPI_SLAVE
 #if !AO_SPI_SLAVE
-       __critical while (!ao_spi_dma_in_done)
-               ao_sleep(&ao_spi_dma_in_done);
+       __critical while (!ao_spi_dma_in_done[bus])
+               ao_sleep(&ao_spi_dma_in_done[bus]);
 #endif
 #endif
+#undef bus
 }
 
 #if AO_SPI_SLAVE
 void
 ao_spi_send_wait(void)
 {
 }
 
 #if AO_SPI_SLAVE
 void
 ao_spi_send_wait(void)
 {
-       __critical while (!ao_spi_dma_in_done)
-               ao_sleep(&ao_spi_dma_in_done);
+       __critical while (!ao_spi_dma_in_done[0])
+               ao_sleep(&ao_spi_dma_in_done[0]);
 }
 #endif
 
 }
 #endif
 
@@ -188,16 +237,22 @@ ao_spi_send_wait(void)
  * writing constant values to the SPI transmitter as that is what
  * clocks the data coming in.
  */
  * writing constant values to the SPI transmitter as that is what
  * clocks the data coming in.
  */
+#if MULTI_SPI
+void
+ao_spi_recv(void __xdata *block, uint16_t len, uint8_t bus) __reentrant
+#else
 void
 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant
 void
 ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant
+#define bus 0
+#endif
 {
 {
-       ao_dma_set_transfer(ao_spi_dma_in_id,
-                           &SPI_BUF,
+       ao_dma_set_transfer(ao_spi_dma_in_id[bus],
+                           SPI_BUF(bus),
                            block,
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
                            block,
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
-                           SPI_DMA_RX,
+                           SPI_DMA_RX(bus),
                            DMA_CFG1_SRCINC_0 |
                            DMA_CFG1_DESTINC_1 |
                            DMA_CFG1_PRIORITY_NORMAL);
                            DMA_CFG1_SRCINC_0 |
                            DMA_CFG1_DESTINC_1 |
                            DMA_CFG1_PRIORITY_NORMAL);
@@ -205,24 +260,24 @@ ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant
        ao_spi_const = SPI_CONST;
 
 #if !AO_SPI_SLAVE
        ao_spi_const = SPI_CONST;
 
 #if !AO_SPI_SLAVE
-       ao_dma_set_transfer(ao_spi_dma_out_id,
+       ao_dma_set_transfer(ao_spi_dma_out_id[bus],
                            &ao_spi_const,
                            &ao_spi_const,
-                           &SPI_BUF,
+                           SPI_BUF(bus),
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
                            len,
                            DMA_CFG0_WORDSIZE_8 |
                            DMA_CFG0_TMODE_SINGLE |
-                           SPI_DMA_TX,
+                           SPI_DMA_TX(bus),
                            DMA_CFG1_SRCINC_0 |
                            DMA_CFG1_DESTINC_0 |
                            DMA_CFG1_PRIORITY_NORMAL);
 #endif
 
                            DMA_CFG1_SRCINC_0 |
                            DMA_CFG1_DESTINC_0 |
                            DMA_CFG1_PRIORITY_NORMAL);
 #endif
 
-       ao_dma_start(ao_spi_dma_in_id);
+       ao_dma_start(ao_spi_dma_in_id[bus]);
 #if !AO_SPI_SLAVE
 #if !AO_SPI_SLAVE
-       ao_dma_start(ao_spi_dma_out_id);
-       ao_dma_trigger(ao_spi_dma_out_id);
-       __critical while (!ao_spi_dma_in_done)
-               ao_sleep(&ao_spi_dma_in_done);
+       ao_dma_start(ao_spi_dma_out_id[bus]);
+       ao_dma_trigger(ao_spi_dma_out_id[bus]);
+       __critical while (!ao_spi_dma_in_done[bus])
+               ao_sleep(&ao_spi_dma_in_done[bus]);
 #endif
 }
 
 #endif
 }
 
@@ -230,17 +285,43 @@ ao_spi_recv_bus(void __xdata *block, uint16_t len) __reentrant
 void
 ao_spi_recv_wait(void)
 {
 void
 ao_spi_recv_wait(void)
 {
-       __critical while (!ao_spi_dma_in_done)
-               ao_sleep(&ao_spi_dma_in_done);
+       __critical while (!ao_spi_dma_in_done[0])
+               ao_sleep(&ao_spi_dma_in_done[0]);
 }
 #endif
 
 }
 #endif
 
+/* Set up the USART.
+ *
+ * SPI master/slave mode
+ */
+/* Set the baud rate and signal parameters
+ *
+ * The cc1111 is limited to a 24/8 MHz SPI clock.
+ * Every peripheral I've ever seen goes faster than that,
+ * so set the clock to 3MHz (BAUD_E 17, BAUD_M 0)
+ */
+#define SPI_INIT(bus,o)        do {                                            \
+               /* Set up the USART pin assignment */                   \
+               PERCFG = (PERCFG & ~SPI_CFG_MASK(bus)) | SPI_CFG(bus);  \
+                                                                       \
+               /* Make the SPI pins be controlled by the USART peripheral */ \
+               SPI_SEL(bus) |= SPI_BITS(bus) | CSS(bus);               \
+               SPI_CSR(bus) = (UxCSR_MODE_SPI | UxCSR_RE | UxCSR_DIRECTION); \
+               SPI_BAUD(bus) = 0;                                      \
+               SPI_GCR(bus) = (UxGCR_CPOL_NEGATIVE |                   \
+                               UxGCR_CPHA_FIRST_EDGE |                 \
+                               UxGCR_ORDER_MSB |                       \
+                               (17 << UxGCR_BAUD_E_SHIFT));            \
+               /* Set up OUT DMA */                                    \
+               ao_spi_dma_out_id[o] = ao_dma_alloc(&ao_spi_dma_out_done[o]); \
+                                                                       \
+               /* Set up IN DMA */                                     \
+               ao_spi_dma_in_id[o] = ao_dma_alloc(&ao_spi_dma_in_done[o]);     \
+       } while (0)
+
 void
 ao_spi_init(void)
 {
 void
 ao_spi_init(void)
 {
-       /* Set up the USART pin assignment */
-       PERCFG = (PERCFG & ~SPI_CFG_MASK) | SPI_CFG;
-
        /* Ensure that SPI USART takes precidence over the other USART
         * for pins that they share
         */
        /* Ensure that SPI USART takes precidence over the other USART
         * for pins that they share
         */
@@ -248,30 +329,10 @@ ao_spi_init(void)
        P2SEL = (P2SEL & ~P2SEL_PRI3P1_MASK) | SPI_PRI;
 #endif
 
        P2SEL = (P2SEL & ~P2SEL_PRI3P1_MASK) | SPI_PRI;
 #endif
 
-       /* Make the SPI pins be controlled by the USART peripheral */
-       SPI_SEL |= SPI_BITS | CSS;
-
-       /* Set up OUT DMA */
-       ao_spi_dma_out_id = ao_dma_alloc(&ao_spi_dma_out_done);
-
-       /* Set up IN DMA */
-       ao_spi_dma_in_id = ao_dma_alloc(&ao_spi_dma_in_done);
-
-       /* Set up the USART.
-        *
-        * SPI master/slave mode
-        */
-       SPI_CSR = (UxCSR_MODE_SPI | UxCSR_RE | UxCSR_DIRECTION);
-
-       /* Set the baud rate and signal parameters
-        *
-        * The cc1111 is limited to a 24/8 MHz SPI clock.
-        * Every peripheral I've ever seen goes faster than that,
-        * so set the clock to 3MHz (BAUD_E 17, BAUD_M 0)
-        */
-       SPI_BAUD = 0;
-       SPI_GCR = (UxGCR_CPOL_NEGATIVE |
-                  UxGCR_CPHA_FIRST_EDGE |
-                  UxGCR_ORDER_MSB |
-                  (17 << UxGCR_BAUD_E_SHIFT));
+#if HAS_SPI_0
+       SPI_INIT(0, 0);
+#endif
+#if HAS_SPI_1
+       SPI_INIT(1, MULTI_SPI);
+#endif
 }
 }
index 4b4403a731efa2711d6e69c0ae3a666c34f3666a..7c1acdd199236dd83063277c816a8f52aef60566 100644 (file)
@@ -22,7 +22,7 @@
 #if HAS_MS5607 || HAS_MS5611
 
 static __xdata struct ao_ms5607_prom   ms5607_prom;
 #if HAS_MS5607 || HAS_MS5611
 
 static __xdata struct ao_ms5607_prom   ms5607_prom;
-static uint8_t                 ms5607_configured;
+static __xdata uint8_t                 ms5607_configured;
 
 static void
 ao_ms5607_start(void) {
 
 static void
 ao_ms5607_start(void) {
index c27f47f1b387e41c099c5be0e8611c470e828dc6..9ecd076e4e12f6e9c86d07fb6d95867e2a3f5636 100644 (file)
@@ -47,7 +47,9 @@
  */
 
 #define HAS_SPI_0              1
  */
 
 #define HAS_SPI_0              1
+#define SPI_0_ALT_1            1
 #define HAS_SPI_1              1
 #define HAS_SPI_1              1
+#define SPI_1_ALT_2            1
 #define SPI_CS_PORT            P1
 #define SPI_CS_SEL             P1SEL
 #define SPI_CS_DIR             P1DIR
 #define SPI_CS_PORT            P1
 #define SPI_CS_SEL             P1SEL
 #define SPI_CS_DIR             P1DIR
@@ -55,6 +57,7 @@
 /*
  * Flash
  */
 /*
  * Flash
  */
+#define AO_M25_SPI_BUS         1
 #define AO_M25_SPI_CS_PORT     SPI_CS_PORT
 #define AO_M25_SPI_CS_MASK     0x04    /* cs_flash is P1_2 */
 #define M25_MAX_CHIPS          1
 #define AO_M25_SPI_CS_PORT     SPI_CS_PORT
 #define AO_M25_SPI_CS_MASK     0x04    /* cs_flash is P1_2 */
 #define M25_MAX_CHIPS          1
@@ -74,6 +77,7 @@
 #define AO_MS5607_MISO_PIN     2
 #define AO_MS5607_MISO_MASK    (1 << AO_MS5607_MISO_PIN)
 #define AO_MS5607_SPI_INDEX    0
 #define AO_MS5607_MISO_PIN     2
 #define AO_MS5607_MISO_MASK    (1 << AO_MS5607_MISO_PIN)
 #define AO_MS5607_SPI_INDEX    0
+#define HAS_EXTI_0             1
 
 /*
  * Igniters
 
 /*
  * Igniters
index b85ce8c8bf381818da224cf91713baa2174c8b12..6b7545fb0ff2a31815e50890d2be3b4d49d65c82 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "ao.h"
 #include "ao_pins.h"
 
 #include "ao.h"
 #include "ao_pins.h"
+#include <ao_exti.h>
 
 __xdata uint8_t ao_force_freq;
 
 
 __xdata uint8_t ao_force_freq;