altos: Clean up usage of port parameters
authorKeith Packard <keithp@keithp.com>
Wed, 27 Jun 2012 06:01:58 +0000 (23:01 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 27 Jun 2012 06:01:58 +0000 (23:01 -0700)
Make stm port parameters always be pointers; this avoids the confusion
where some macros took '&port' and others took a bare 'port', and also
unifies code to run on other processors in a consistent fashion.

Signed-off-by: Keith Packard <keithp@keithp.com>
12 files changed:
src/cc1111/ao_arch_funcs.h
src/cc1111/ao_pins.h
src/drivers/ao_25lc1024.c
src/drivers/ao_at45db161d.c
src/drivers/ao_companion.c
src/drivers/ao_hmc5883.c
src/drivers/ao_ms5607.c
src/megametrum-v0.1/ao_pins.h
src/stm-demo/ao_pins.h
src/stm/ao_adc_stm.c
src/stm/ao_arch_funcs.h
src/stm/ao_led.c

index d9f5955a75b3326f03d0cb985bd872942062da40..728f1f76d935507787aa6f8b6ef3749fd6720b3d 100644 (file)
@@ -31,14 +31,14 @@ extern __xdata uint8_t      ao_spi_mutex;
        ao_mutex_put(&ao_spi_mutex); \
        } while (0)
 
-#define ao_spi_get_bit(bit,bus) do {    \
-       ao_mutex_get(&ao_spi_mutex); \
-       (bit) = 0; \
+#define ao_spi_get_bit(reg,bit,pin,bus) do {   \
+               ao_mutex_get(&ao_spi_mutex);    \
+               pin = 0;                        \
        } while (0)
 
-#define ao_spi_put_bit(bit,bus) do {           \
-       (bit) = 1; \
-       ao_mutex_put(&ao_spi_mutex); \
+#define ao_spi_put_bit(reg,bit,pin,bus) do {   \
+               pin = 1;                        \
+               ao_mutex_put(&ao_spi_mutex);    \
        } while (0)
 
 
@@ -65,3 +65,15 @@ ao_spi_init(void);
                SPI_CS_DIR |= mask;             \
                SPI_CS_SEL &= ~mask;            \
        } while (0)
+
+#define cc1111_enable_output(port,dir,sel,mask,v) do { \
+       port = port & ~(mask) | v; \
+       dir |= mask; \
+       sel &= ~mask; \
+} while (0)
+
+#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,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), 1 << pin, 1 << v)
index 0923e75de146a16dda07a1719277de53a7548a3c..e28a7b65da256149e7a49de478bfa563644b1cd6 100644 (file)
@@ -41,8 +41,9 @@
 
        #define HAS_COMPANION           1
        #define COMPANION_CS_ON_P1      1
-       #define COMPANION_CS_MASK       0x4     /* CS1 is P1_2 */
-       #define COMPANION_CS            P1_2
+       #define AO_COMPANION_CS_PORT    P1
+       #define AO_COMPANION_CS_PIN     2
+       #define AO_COMPANION_CS         P1_2
 
        #define AO_LED_RED              1
        #define LEDS_AVAILABLE          (AO_LED_RED)
@@ -72,9 +73,9 @@
        #define PACKET_HAS_SLAVE        1
 
        #define HAS_COMPANION           1
-       #define COMPANION_CS_ON_P1      1
-       #define COMPANION_CS_MASK       0x4     /* CS1 is P1_2 */
-       #define COMPANION_CS            P1_2
+       #define AO_COMPANION_CS_PORT    P1
+       #define AO_COMPANION_CS_PIN     2
+       #define AO_COMPANION_CS         P1_2
 
        #define AO_LED_RED              1
        #define LEDS_AVAILABLE          (AO_LED_RED)
        #define PACKET_HAS_SLAVE        1
 
        #define HAS_COMPANION           1
-       #define COMPANION_CS_ON_P1      1
-       #define COMPANION_CS_MASK       0x4     /* CS1 is P1_2 */
-       #define COMPANION_CS            P1_2
+       #define AO_COMPANION_CS_PORT    P1
+       #define AO_COMPANION_CS_PIN     2
+       #define AO_COMPANION_CS         P1_2
 
        #define AO_LED_RED              1
        #define LEDS_AVAILABLE          (AO_LED_RED)
 #endif /* HAS_ADC */
 
 #if IGNITE_ON_P2
+#define AO_IGNITER_PORT                P2
+#define AO_IGNITER_DROGUE_PORT AO_IGNITER_PORT
 #define AO_IGNITER_DROGUE      P2_3
 #define AO_IGNITER_MAIN                P2_4
 #define AO_IGNITER_DIR         P2DIR
 #define AO_IGNITER_DROGUE_BIT  (1 << 3)
 #define AO_IGNITER_MAIN_BIT    (1 << 4)
+#define AO_IGNITER_DROGUE_PIN  3
+#define AO_IGNITER_MAIN_PIN    4
 #endif
 
 #if IGNITE_ON_P0
+#define AO_IGNITER_PORT                P0
 #define AO_IGNITER_DROGUE      P0_5
 #define AO_IGNITER_MAIN                P0_4
 #define AO_IGNITER_DIR         P0DIR
 #define AO_IGNITER_DROGUE_BIT  (1 << 5)
 #define AO_IGNITER_MAIN_BIT    (1 << 4)
+#define AO_IGNITER_DROGUE_PIN  5
+#define AO_IGNITER_MAIN_PIN    4
 #endif
 
+#define AO_IGNITER_DROGUE_PORT AO_IGNITER_PORT
+#define AO_IGNITER_MAIN_PORT   AO_IGNITER_PORT
+
 /* test these values with real igniters */
 #define AO_IGNITER_OPEN                1000
 #define AO_IGNITER_CLOSED      7000
index f0fb13c97ddfb91087231356e5249f13e9fd3d40..b25d52c4e7e7e529325ca84ce056885c3485dd2f 100644 (file)
@@ -38,8 +38,9 @@ __pdata uint16_t      ao_storage_unit;
  * Using SPI on USART 0, with P1_2 as the chip select
  */
 
+#define EE_CS_PORT     P1
 #define EE_CS          P1_2
-#define EE_CS_INDEX    2
+#define EE_CS_PIN      2
 
 static __xdata uint8_t ao_ee_mutex;
 
@@ -49,9 +50,9 @@ static __xdata uint8_t ao_ee_mutex;
        _asm nop _endasm; \
 } while(0)
 
-#define ao_ee_cs_low() ao_spi_get_bit(EE_CS, AO_EE_SPI_BUS)
+#define ao_ee_cs_low() ao_spi_get_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS)
 
-#define ao_ee_cs_high()        ao_spi_put_bit(EE_CS, AO_EE_SPI_BUS)
+#define ao_ee_cs_high()        ao_spi_put_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS)
 
 struct ao_ee_instruction {
        uint8_t instruction;
@@ -235,7 +236,5 @@ void
 ao_storage_device_init(void)
 {
        /* set up CS */
-       EE_CS = 1;
-       P1DIR |= (1 << EE_CS_INDEX);
-       P1SEL &= ~(1 << EE_CS_INDEX);
+       ao_enable_output(EE_CS_PORT, EE_CS_PIN,1);
 }
index afe0080b87f78243e5f947b45549d8cf3e4a5833..5eb25acf29bbf6efaaa4297899f0b9f95a774950 100644 (file)
@@ -43,9 +43,9 @@ __xdata uint8_t ao_flash_mutex;
        _asm nop _endasm; \
 } while(0)
 
-#define ao_flash_cs_low()      ao_spi_get_bit(FLASH_CS, AO_FLASH_SPI_BUS)
+#define ao_flash_cs_low()      ao_spi_get_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS)
 
-#define ao_flash_cs_high()     ao_spi_put_bit(FLASH_CS, AO_FLASH_SPI_BUS)
+#define ao_flash_cs_high()     ao_spi_put_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS)
 
 struct ao_flash_instruction {
        uint8_t instruction;
index fe88e998f0cca54139c86245b1fd2ea2dad3d9ca..a31cc2eadf2e5742917b33872519e382b0b3a75c 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#include "ao.h"
-
-#define ao_spi_slow() (U0GCR = (UxGCR_CPOL_NEGATIVE |          \
-                               UxGCR_CPHA_FIRST_EDGE |         \
-                               UxGCR_ORDER_MSB |               \
-                               (13 << UxGCR_BAUD_E_SHIFT)))
-
-#define ao_spi_fast() (U0GCR = (UxGCR_CPOL_NEGATIVE |          \
-                               UxGCR_CPHA_FIRST_EDGE |         \
-                               UxGCR_ORDER_MSB |               \
-                               (17 << UxGCR_BAUD_E_SHIFT)))
-
-#define COMPANION_SELECT()     do { ao_spi_get_bit(COMPANION_CS, AO_COMPANION_BUS); ao_spi_slow(); } while (0)
-#define COMPANION_DESELECT()   do { ao_spi_fast(); ao_spi_put_bit(COMPANION_CS, AO_COMPANION_BUS); } while (0)
+#include <ao.h>
+#include <ao_companion.h>
+
+#ifndef ao_spi_slow
+#define ao_spi_slow(bus) (U0GCR = (UxGCR_CPOL_NEGATIVE |       \
+                                  UxGCR_CPHA_FIRST_EDGE |      \
+                                  UxGCR_ORDER_MSB |            \
+                                  (13 << UxGCR_BAUD_E_SHIFT)))
+
+#define ao_spi_fast(bus) (U0GCR = (UxGCR_CPOL_NEGATIVE |       \
+                                  UxGCR_CPHA_FIRST_EDGE |      \
+                                  UxGCR_ORDER_MSB |            \
+                                  (17 << UxGCR_BAUD_E_SHIFT)))
+#endif
+
+#define COMPANION_SELECT()     do {                    \
+               ao_spi_get_bit(AO_COMPANION_CS_PORT,    \
+                              AO_COMPANION_CS_PIN,     \
+                              AO_COMPANION_CS,         \
+                              AO_COMPANION_SPI_BUS);   \
+               ao_spi_slow(AO_COMPANION_SPI_BUS);      \
+       } while (0)
+
+#define COMPANION_DESELECT()   do {                    \
+               ao_spi_fast(AO_COMPANION_SPI_BUS);      \
+               ao_spi_put_bit(AO_COMPANION_CS_PORT,    \
+                              AO_COMPANION_CS_PIN,     \
+                              AO_COMPANION_CS,         \
+                              AO_COMPANION_SPI_BUS);   \
+       } while (0)
 
 __xdata struct ao_companion_command            ao_companion_command;
 __xdata struct ao_companion_setup              ao_companion_setup;
@@ -123,10 +139,7 @@ static __xdata struct ao_task ao_companion_task;
 void
 ao_companion_init(void)
 {
-       COMPANION_CS_PORT |= COMPANION_CS_MASK; /* raise all CS pins */
-       COMPANION_CS_DIR |= COMPANION_CS_MASK;  /* set CS pins as outputs */
-       COMPANION_CS_SEL &= ~COMPANION_CS_MASK; /* set CS pins as GPIO */
-
+       ao_enable_output(AO_COMPANION_CS_PORT, AO_COMPANION_CS_PIN, 1);
        ao_cmd_register(&ao_companion_cmds[0]);
        ao_add_task(&ao_companion_task, ao_companion, "companion");
 }
index 1bc914e68a6c6908dceff487b9e9670f4df3f6fc..64663ea6d33d618b794213a7726a0f5dc7919d69 100644 (file)
@@ -58,7 +58,7 @@ static uint8_t ao_hmc5883_done;
 static void
 ao_hmc5883_isr(void)
 {
-       ao_exti_disable(&AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
+       ao_exti_disable(AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
        ao_hmc5883_done = 1;
        ao_wakeup(&ao_hmc5883_done);
 }
@@ -71,7 +71,7 @@ ao_hmc5883_sample(struct ao_hmc5883_sample *sample)
        uint8_t         single = HMC5883_MODE_SINGLE;
 
        ao_hmc5883_done = 0;
-       ao_exti_enable(&AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
+       ao_exti_enable(AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
        ao_hmc5883_reg_write(HMC5883_MODE, HMC5883_MODE_SINGLE);
 
        cli();
@@ -159,7 +159,7 @@ ao_hmc5883_init(void)
        ao_hmc5883_valid = 0;
 
        ao_enable_port(AO_HMC5883_INT_PORT);
-       ao_exti_setup(&AO_HMC5883_INT_PORT,
+       ao_exti_setup(AO_HMC5883_INT_PORT,
                      AO_HMC5883_INT_PIN,
                      AO_EXTI_MODE_FALLING | AO_EXTI_MODE_PULL_UP,
                      ao_hmc5883_isr);
index 0f0625d09bd305e87c6c4a33a378ae2db887a749..e08f4d406e7b4e58281285688af3df3d19b7b771 100644 (file)
@@ -25,12 +25,12 @@ static uint8_t                      ms5607_configured;
 static void
 ao_ms5607_start(void) {
        ao_spi_get(AO_MS5607_SPI_INDEX);
-       stm_gpio_set(&AO_MS5607_CS_GPIO, AO_MS5607_CS, 0);
+       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 0);
 }
 
 static void
 ao_ms5607_stop(void) {
-       stm_gpio_set(&AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
        ao_spi_put(AO_MS5607_SPI_INDEX);
 }
 
@@ -132,12 +132,12 @@ ao_ms5607_get_sample(uint8_t cmd) {
 
        ao_ms5607_start();
        ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX);
-       ao_exti_enable(&AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+       ao_exti_enable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
        cli();
        while (!ao_ms5607_done)
                ao_sleep(&ao_ms5607_done);
        sei();
-       ao_exti_disable(&AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+       ao_exti_disable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
        ao_ms5607_stop();
 
        ao_ms5607_start();
@@ -203,7 +203,7 @@ ao_ms5607(void)
        ao_ms5607_setup();
        for (;;)
        {
-               struct ao_ms5607_sample ao_ms5607_next;
+               static struct ao_ms5607_sample  ao_ms5607_next;
                ao_ms5607_sample(&ao_ms5607_next);
                ao_arch_critical(
                        ao_ms5607_current = ao_ms5607_next;
@@ -260,7 +260,7 @@ ao_ms5607_init(void)
         * conversion is complete, the MS5607 will raise this
         * pin as a signal
         */
-       ao_exti_setup(&AO_MS5607_MISO_GPIO,
+       ao_exti_setup(AO_MS5607_MISO_GPIO,
                      AO_MS5607_MISO,
                      AO_EXTI_MODE_RISING,
                      ao_ms5607_isr);
@@ -268,7 +268,7 @@ ao_ms5607_init(void)
        /* Reset the pin from INPUT to ALTERNATE so that SPI works
         * This needs an abstraction at some point...
         */
-       stm_moder_set(&AO_MS5607_MISO_GPIO,
+       stm_moder_set(AO_MS5607_MISO_GPIO,
                      AO_MS5607_MISO,
                      STM_MODER_ALTERNATE);
 }
index 9d9113c8934100ac08f200ffc3d5ca4e476b013c..f5bd3e0d164c7abc6ba667a189edff7cad8dd8f4 100644 (file)
@@ -76,7 +76,7 @@
 #define HAS_SPI_2              1
 #define SPI_2_PB13_PB14_PB15   1
 #define SPI_2_PD1_PD3_PD4      0
-#define SPI_2_GPIO             stm_gpiob
+#define SPI_2_GPIO             (&stm_gpiob)
 #define SPI_2_SCK              13
 #define SPI_2_MISO             14
 #define SPI_2_MOSI             15
 #define HAS_I2C_2              1
 #define I2C_2_PB10_PB11                1
 
-#define PACKET_HAS_SLAVE       0
+#define PACKET_HAS_SLAVE       1
+#define PACKET_HAS_MASTER      0
 
-#define LOW_LEVEL_DEBUG                1
+#define LOW_LEVEL_DEBUG                0
 
 #define LED_PORT_ENABLE                STM_RCC_AHBENR_GPIOCEN
-#define LED_PORT               stm_gpioc
+#define LED_PORT               (&stm_gpioc)
 #define LED_PIN_RED            8
 #define LED_PIN_GREEN          9
 #define AO_LED_RED             (1 << LED_PIN_RED)
 #define HAS_ACCEL_REF          1
 #define HAS_LOG                        1
 
+/*
+ * Igniter
+ */
+
+#define HAS_IGNITE             1
+#define HAS_IGNITE_REPORT      1
+
+#define AO_SENSE_DROGUE(p)     ((p)->adc.sense[0])
+#define AO_SENSE_MAIN(p)       ((p)->adc.sense[1])
+#define AO_IGNITER_CLOSED      400
+#define AO_IGNITER_OPEN                60
+
+#define AO_IGNITER_PORT_A      (&stm_gpiod)
+#define AO_IGNITER_PIN_A       6
+
+#define AO_IGNITER_PORT_B      (&stm_gpiod)
+#define AO_IGNITER_PIN_B       7
+
+#define AO_IGNITER_PORT_C      (&stm_gpiob)
+#define AO_IGNITER_PIN_C       5
+
+#define AO_IGNITER_PORT_D      (&stm_gpioe)
+#define AO_IGNITER_PIN_D       4
+
+#define AO_IGNITER_PORT_E      (&stm_gpioe)
+#define AO_IGNITER_PIN_E       6
+
+#define AO_IGNITER_PORT_F      (&stm_gpioe)
+#define AO_IGNITER_PIN_F       5
+
+#define AO_IGNITER_DROGUE_PORT AO_IGNITER_PORT_A
+#define AO_IGNITER_DROGUE_PIN  AO_IGNITER_PIN_A
+
+#define AO_IGNITER_MAIN_PORT   AO_IGNITER_PORT_B
+#define AO_IGNITER_MAIN_PIN    AO_IGNITER_PIN_B
+
+#define AO_IGNITER_SET_DROGUE(v)       stm_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, v)
+#define AO_IGNITER_SET_MAIN(v)         stm_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, v)
+
+/*
+ * ADC
+ */
 #define AO_DATA_RING           32
 #define AO_ADC_NUM_SENSE       6
 
@@ -120,43 +163,43 @@ struct ao_adc {
 };
 
 #define AO_ADC_SENSE_A         0
-#define AO_ADC_SENSE_A_PORT    stm_gpioa
+#define AO_ADC_SENSE_A_PORT    (&stm_gpioa)
 #define AO_ADC_SENSE_A_PIN     0
 
 #define AO_ADC_SENSE_B         1
-#define AO_ADC_SENSE_B_PORT    stm_gpioa
+#define AO_ADC_SENSE_B_PORT    (&stm_gpioa)
 #define AO_ADC_SENSE_B_PIN     1
 
 #define AO_ADC_SENSE_C         2
-#define AO_ADC_SENSE_C_PORT    stm_gpioa
+#define AO_ADC_SENSE_C_PORT    (&stm_gpioa)
 #define AO_ADC_SENSE_C_PIN     2
 
 #define AO_ADC_SENSE_D         3
-#define AO_ADC_SENSE_D_PORT    stm_gpioa
+#define AO_ADC_SENSE_D_PORT    (&stm_gpioa)
 #define AO_ADC_SENSE_D_PIN     3
 
 #define AO_ADC_SENSE_E         4
-#define AO_ADC_SENSE_E_PORT    stm_gpioa
+#define AO_ADC_SENSE_E_PORT    (&stm_gpioa)
 #define AO_ADC_SENSE_E_PIN     4
 
 #define AO_ADC_SENSE_F         22
-#define AO_ADC_SENSE_F_PORT    stm_gpioe
+#define AO_ADC_SENSE_F_PORT    (&stm_gpioe)
 #define AO_ADC_SENSE_F_PIN     7
 
 #define AO_ADC_V_BATT          8
-#define AO_ADC_V_BATT_PORT     stm_gpiob
+#define AO_ADC_V_BATT_PORT     (&stm_gpiob)
 #define AO_ADC_V_BATT_PIN      0
 
 #define AO_ADC_V_PBATT         9
-#define AO_ADC_V_PBATT_PORT    stm_gpiob
+#define AO_ADC_V_PBATT_PORT    (&stm_gpiob)
 #define AO_ADC_V_PBATT_PIN     1
 
 #define AO_ADC_ACCEL_REF       10
-#define AO_ADC_ACCEL_REF_PORT  stm_gpioc
+#define AO_ADC_ACCEL_REF_PORT  (&stm_gpioc)
 #define AO_ADC_ACCEL_REF_PIN   0
 
 #define AO_ADC_ACCEL           11
-#define AO_ADC_ACCEL_PORT      stm_gpioc
+#define AO_ADC_ACCEL_PORT      (&stm_gpioc)
 #define AO_ADC_ACCEL_PIN       1
 
 #define AO_ADC_TEMP            16
@@ -207,10 +250,10 @@ struct ao_adc {
  * Pressure sensor settings
  */
 #define HAS_MS5607             1
-#define AO_MS5607_CS_GPIO      stm_gpioc
+#define AO_MS5607_CS_GPIO      (&stm_gpioc)
 #define AO_MS5607_CS           4
 #define AO_MS5607_CS_MASK      (1 << AO_MS5607_CS)
-#define AO_MS5607_MISO_GPIO    stm_gpioa
+#define AO_MS5607_MISO_GPIO    (&stm_gpioa)
 #define AO_MS5607_MISO         6
 #define AO_MS5607_MISO_MASK    (1 << AO_MS5607_MISO)
 #define AO_MS5607_SPI_INDEX    (STM_SPI_INDEX(1))
@@ -220,7 +263,7 @@ struct ao_adc {
  */
 
 #define M25_MAX_CHIPS          1
-#define AO_M25_SPI_CS_PORT     stm_gpiod
+#define AO_M25_SPI_CS_PORT     (&stm_gpiod)
 #define AO_M25_SPI_CS_MASK     (1 << 3)
 #define AO_M25_SPI_BUS         STM_SPI_INDEX(2)
 
@@ -228,21 +271,23 @@ struct ao_adc {
  * Radio (cc1120)
  */
 
-#define AO_CC1120_SPI_CS_PORT  stm_gpioc
+#define AO_FEC_DEBUG           1
+#define AO_CC1120_SPI_CS_PORT  (&stm_gpioc)
 #define AO_CC1120_SPI_CS_PIN   5
 #define AO_CC1120_SPI_BUS      STM_SPI_INDEX(2)
 
-#define AO_CC1120_INT_PORT     stm_gpioc
+#define AO_CC1120_INT_PORT     (&stm_gpioc)
 #define AO_CC1120_INT_PIN      14
 
 #define AO_CC1120_INT_GPIO     2
+#define HAS_BOOT_RADIO         1
 
 /*
  * Mag sensor (hmc5883)
  */
 
 #define HAS_HMC5883            1
-#define AO_HMC5883_INT_PORT    stm_gpioc
+#define AO_HMC5883_INT_PORT    (&stm_gpioc)
 #define AO_HMC5883_INT_PIN     12
 #define AO_HMC5883_I2C_INDEX   STM_I2C_INDEX(1)
 
@@ -251,7 +296,7 @@ struct ao_adc {
  */
 
 #define HAS_MPU6000            1       
-#define AO_MPU6000_INT_PORT    stm_gpioc
+#define AO_MPU6000_INT_PORT    (&stm_gpioc)
 #define AO_MPU6000_INT_PIN     13
 #define AO_MPU6000_I2C_INDEX   STM_I2C_INDEX(1)
 
@@ -259,4 +304,28 @@ struct ao_adc {
 
 #define NUM_CMDS               16
 
+/*
+ * Companion
+ */
+
+#define AO_COMPANION_CS_PORT   (&stm_gpiod)
+#define AO_COMPANION_CS_PIN    (0)
+#define AO_COMPANION_SPI_BUS   STM_SPI_INDEX(2)
+
+/*
+ * Monitor
+ */
+
+#define HAS_MONITOR            0
+#define LEGACY_MONITOR         0
+#define HAS_MONITOR_PUT                1
+#define AO_MONITOR_LED         0
+#define HAS_RSSI               0
+
+/*
+ * Profiling Viterbi decoding
+ */
+
+#define AO_PROFILE             0
+
 #endif /* _AO_PINS_H_ */
index d02c071c4d2f2312039eeca1227d044f6c0b6d63..7e22212223033d1c50363a253cf4c245708f2186 100644 (file)
@@ -70,7 +70,7 @@
 #define LOW_LEVEL_DEBUG                1
 
 #define LED_PORT_ENABLE                STM_RCC_AHBENR_GPIOBEN
-#define LED_PORT               stm_gpiob
+#define LED_PORT               (&stm_gpiob)
 #define LED_PIN_GREEN          7
 #define LED_PIN_BLUE           6
 #define AO_LED_GREEN           (1 << LED_PIN_GREEN)
@@ -147,7 +147,7 @@ struct ao_adc {
 };
 
 #define AO_ADC_IDD             4
-#define AO_ADC_PIN0_PORT       stm_gpioa
+#define AO_ADC_PIN0_PORT       (&stm_gpioa)
 #define AO_ADC_PIN0_PIN                4
 
 #define AO_ADC_RCC_AHBENR      ((1 << STM_RCC_AHBENR_GPIOAEN))
index ed1d20c9a454eb342f642d69d7125361b2b7c33d..7564c7fa9a0a810e466b0ce5418e0d27b800f53c 100644 (file)
@@ -156,43 +156,43 @@ ao_adc_init(void)
 #endif
 
 #ifdef AO_ADC_PIN0_PORT
-       stm_moder_set(&AO_ADC_PIN0_PORT, AO_ADC_PIN0_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN0_PORT, AO_ADC_PIN0_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN1_PORT
-       stm_moder_set(&AO_ADC_PIN1_PORT, AO_ADC_PIN1_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN1_PORT, AO_ADC_PIN1_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN2_PORT
-       stm_moder_set(&AO_ADC_PIN2_PORT, AO_ADC_PIN2_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN2_PORT, AO_ADC_PIN2_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN3_PORT
-       stm_moder_set(&AO_ADC_PIN3_PORT, AO_ADC_PIN3_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN3_PORT, AO_ADC_PIN3_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN4_PORT
-       stm_moder_set(&AO_ADC_PIN4_PORT, AO_ADC_PIN4_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN4_PORT, AO_ADC_PIN4_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN5_PORT
-       stm_moder_set(&AO_ADC_PIN5_PORT, AO_ADC_PIN5_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN5_PORT, AO_ADC_PIN5_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN6_PORT
-       stm_moder_set(&AO_ADC_PIN6_PORT, AO_ADC_PIN6_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN6_PORT, AO_ADC_PIN6_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN7_PORT
-       stm_moder_set(&AO_ADC_PIN7_PORT, AO_ADC_PIN7_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN7_PORT, AO_ADC_PIN7_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN8_PORT
-       stm_moder_set(&AO_ADC_PIN8_PORT, AO_ADC_PIN8_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN8_PORT, AO_ADC_PIN8_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN9_PORT
-       stm_moder_set(&AO_ADC_PIN9_PORT, AO_ADC_PIN9_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN9_PORT, AO_ADC_PIN9_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN10_PORT
-       stm_moder_set(&AO_ADC_PIN10_PORT, AO_ADC_PIN10_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN10_PORT, AO_ADC_PIN10_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN11_PORT
-       stm_moder_set(&AO_ADC_PIN11_PORT, AO_ADC_PIN11_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN11_PORT, AO_ADC_PIN11_PIN, STM_MODER_ANALOG);
 #endif
 #ifdef AO_ADC_PIN12_PORT
-       stm_moder_set(&AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG);
+       stm_moder_set(AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG);
 #endif
 
        stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_ADC1EN);
@@ -281,8 +281,10 @@ ao_adc_init(void)
 #endif
        /* Clear any stale status bits */
        stm_adc.sr = 0;
-       ao_adc_ready = 1;
 
        ao_dma_alloc(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
+
        ao_cmd_register(&ao_adc_cmds[0]);
+
+       ao_adc_ready = 1;
 }
index 447042dd6a0ad3bda8c04d8c74d5368dc780d7d9..62b100631bc0bf87320c0e7afd5ece89fd8caa2b 100644 (file)
@@ -40,36 +40,54 @@ ao_spi_recv(void *block, uint16_t len, uint8_t spi_index);
 void
 ao_spi_duplex(void *out, void *in, uint16_t len, uint8_t spi_index);
 
+#define AO_SPI_SPEED_FAST      STM_SPI_CR1_BR_PCLK_16
+#define AO_SPI_SPEED_200kHz    STM_SPI_CR1_BR_PCLK_256
+
+extern uint16_t        ao_spi_speed[STM_NUM_SPI];
+
+#define ao_spi_slow(bus)       (ao_spi_speed[bus] = AO_SPI_SPEED_200kHz)
+
+#define ao_spi_fast(bus)       (ao_spi_speed[bus] = AO_SPI_SPEED_FAST)
+
 void
 ao_spi_init(void);
 
 #define ao_spi_get_mask(reg,mask,bus) do {             \
                ao_spi_get(bus);                        \
-               (reg).bsrr = ((uint32_t) mask) << 16;   \
+               (reg)->bsrr = ((uint32_t) mask) << 16;  \
        } while (0)
 
 #define ao_spi_put_mask(reg,mask,bus) do {     \
-               (reg).bsrr = mask;              \
+               (reg)->bsrr = mask;             \
                ao_spi_put(bus);                \
        } while (0)
 
+#define ao_spi_get_bit(reg,bit,pin,bus) ao_spi_get_mask(reg,(1<<bit),bus)
+#define ao_spi_put_bit(reg,bit,pin,bus) ao_spi_put_mask(reg,(1<<bit),bus)
+
 #define ao_enable_port(port) do {                                      \
-               if (&(port) == &stm_gpioa)                              \
+               if ((port) == &stm_gpioa)                               \
                        stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOAEN); \
-               else if (&(port) == &stm_gpiob)                         \
+               else if ((port) == &stm_gpiob)                          \
                        stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOBEN); \
-               else if (&(port) == &stm_gpioc)                         \
+               else if ((port) == &stm_gpioc)                          \
                        stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOCEN); \
-               else if (&(port) == &stm_gpiod)                         \
+               else if ((port) == &stm_gpiod)                          \
                        stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIODEN); \
-               else if (&(port) == &stm_gpioe)                         \
+               else if ((port) == &stm_gpioe)                          \
                        stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOEEN); \
        } while (0)
 
 
+#define ao_enable_output(port,pin,v) do {                      \
+               ao_enable_port(port);                           \
+               stm_gpio_set(port, pin, v);                     \
+               stm_moder_set(port, pin, STM_MODER_OUTPUT);     \
+       } while (0)
+
 #define ao_enable_cs(port,bit) do {                            \
-               stm_gpio_set(&(port), bit, 1);                  \
-               stm_moder_set(&(port), bit, STM_MODER_OUTPUT);  \
+               stm_gpio_set((port), bit, 1);                   \
+               stm_moder_set((port), bit, STM_MODER_OUTPUT);   \
        } while (0)
 
 #define ao_spi_init_cs(port, mask) do {                                \
index d649f3d7a03a71559bff81fbb638d35c2aab19bb..ee313b6fa5b8e16b9dd83f9cdea9a937326d1965 100644 (file)
@@ -22,25 +22,28 @@ __pdata uint16_t ao_led_enable;
 void
 ao_led_on(uint16_t colors)
 {
-       LED_PORT.odr |= (colors & ao_led_enable);
+       LED_PORT->bsrr = (colors & ao_led_enable);
 }
 
 void
 ao_led_off(uint16_t colors)
 {
-       LED_PORT.odr &= ~(colors & ao_led_enable);
+       LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16;
 }
 
 void
 ao_led_set(uint16_t colors)
 {
-       LED_PORT.odr = (LED_PORT.odr & ~(ao_led_enable)) | (colors & ao_led_enable);
+       uint16_t        on = colors & ao_led_enable;
+       uint16_t        off = ~colors & ao_led_enable;
+
+       LED_PORT->bsrr = off << 16 | on;
 }
 
 void
 ao_led_toggle(uint16_t colors)
 {
-       LED_PORT.odr ^= (colors & ao_led_enable);
+       LED_PORT->odr ^= (colors & ao_led_enable);
 }
 
 void
@@ -58,11 +61,11 @@ ao_led_init(uint16_t enable)
 
        stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE);
        ao_led_enable = enable;
-       LED_PORT.odr &= ~enable;
+       LED_PORT->odr &= ~enable;
        for (bit = 0; bit < 16; bit++) {
                if (enable & (1 << bit)) {
-                       stm_moder_set(&LED_PORT, bit, STM_MODER_OUTPUT);
-                       stm_otyper_set(&LED_PORT, bit, STM_OTYPER_PUSH_PULL);
+                       stm_moder_set(LED_PORT, bit, STM_MODER_OUTPUT);
+                       stm_otyper_set(LED_PORT, bit, STM_OTYPER_PUSH_PULL);
                }
        }
 }