src: Add explicit 'pin' argument to ao_enable_output
authorKeith Packard <keithp@keithp.com>
Sat, 14 Jul 2012 09:44:17 +0000 (02:44 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 14 Jul 2012 09:44:17 +0000 (02:44 -0700)
This lets the cc1111 use the atomic bit operation instead of a mask,
which is immune to interrupt issues as well as being a shorter code sequence.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/avr/ao_arch_funcs.h
src/cc1111/ao_arch_funcs.h
src/core/ao_ignite.c
src/core/ao_pyro.c
src/drivers/ao_25lc1024.c
src/drivers/ao_companion.c
src/stm/ao_arch_funcs.h

index e400c98b62468a25ce961592e2171de5fe586476..792ff7440bf724d5e824abf351cd391891a52a0a 100644 (file)
@@ -41,12 +41,29 @@ extern __xdata uint8_t      ao_spi_mutex;
                ao_mutex_put(&ao_spi_mutex);    \
        } while (0)
 
+
+#define ao_gpio_token_paster(x,y)              x ## y
+#define ao_gpio_token_evaluator(x,y)   ao_gpio_token_paster(x,y)
+
+#define ao_gpio_set(port, bit, pin, v) do {                            \
+               if (v)                                                  \
+                       (ao_gpio_token_evaluator(PORT,port)) |= (1 << bit); \
+               else                                                    \
+                       (ao_gpio_token_evaluator(PORT,port)) &= ~(1 << bit); \
+       } while (0)
+
 /*
  * The SPI mutex must be held to call either of these
  * functions -- this mutex covers the entire SPI operation,
  * from chip select low to chip select high
  */
 
+#define ao_enable_output(port, bit, pin, v) do {                       \
+               ao_gpio_set(port, bit, pin, v);                         \
+               ao_gpio_token_evaluator(DDR,port) |= (1 << bit);        \
+       } while (0)
+
+
 void
 ao_spi_send_bus(void __xdata *block, uint16_t len) __reentrant;
 
index 0a32296165a8ee7f63ee984018cef7499b6e0042..0737e7abeb2c113449e9ee839d4a68328d5dc265 100644 (file)
@@ -77,14 +77,14 @@ ao_spi_init(void);
                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 cc1111_enable_output(port,dir,sel,pin,bit,v) do {      \
+               pin = v;                                        \
+               dir |= (1 << bit);                              \
+               sel &= ~(1 << bit);                             \
+       } 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)
+#define ao_enable_output(port,bit,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), pin, bit, v)
index e82de355abbaa6f7de57494ed0f7d0a622159b53..c7829fc3b543334f19c99db52985dae0f7e39b8c 100644 (file)
@@ -195,8 +195,8 @@ __xdata struct ao_task ao_igniter_task;
 void
 ao_ignite_set_pins(void)
 {
-       ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, 0);
-       ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, 0);
+       ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, 0);
+       ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, 0);
 }
 
 void
index c060a8661d4fabb11905a6f4f68cbe3977e59b1a..943413e699a9224f1d05f850c249dae74508fe59 100644 (file)
@@ -102,16 +102,18 @@ ao_pyro_ready(struct ao_pyro *pyro)
                        /* handled separately */
                        continue;
                        
+               case ao_pyro_none:
+                       break;
                }
                return FALSE;
        }
        return TRUE;
 }
 
-#define ao_pyro_fire_port(port, pin) do {              \
-               ao_gpio_set(port, pin, 1);      \
+#define ao_pyro_fire_port(port, bit, pin) do { \
+               ao_gpio_set(port, bit, pin, 1); \
                ao_delay(AO_MS_TO_TICKS(50));   \
-               ao_gpio_set(port, pin, 0);      \
+               ao_gpio_set(port, bit, pin, 0); \
        } while (0)
        
 
@@ -120,28 +122,28 @@ ao_pyro_fire(uint8_t p)
 {
        switch (p) {
 #if AO_PYRO_NUM > 0
-       case 0: ao_pyro_fire_port(AO_PYRO_PORT_0, AO_PYRO_PIN_0); break;
+       case 0: ao_pyro_fire_port(AO_PYRO_PORT_0, AO_PYRO_PIN_0, AO_PYRO_0); break;
 #endif
 #if AO_PYRO_NUM > 1
-       case 1: ao_pyro_fire_port(AO_PYRO_PORT_1, AO_PYRO_PIN_1); break;
+       case 1: ao_pyro_fire_port(AO_PYRO_PORT_1, AO_PYRO_PIN_1, AO_PYRO_1); break;
 #endif
 #if AO_PYRO_NUM > 2
-       case 2: ao_pyro_fire_port(AO_PYRO_PORT_2, AO_PYRO_PIN_2); break;
+       case 2: ao_pyro_fire_port(AO_PYRO_PORT_2, AO_PYRO_PIN_2, AO_PYRO_2); break;
 #endif
 #if AO_PYRO_NUM > 3
-       case 3: ao_pyro_fire_port(AO_PYRO_PORT_3, AO_PYRO_PIN_3); break;
+       case 3: ao_pyro_fire_port(AO_PYRO_PORT_3, AO_PYRO_PIN_3, AO_PYRO_3); break;
 #endif
 #if AO_PYRO_NUM > 4
-       case 4: ao_pyro_fire_port(AO_PYRO_PORT_4, AO_PYRO_PIN_4); break;
+       case 4: ao_pyro_fire_port(AO_PYRO_PORT_4, AO_PYRO_PIN_4, AO_PYRO_4); break;
 #endif
 #if AO_PYRO_NUM > 5
-       case 5: ao_pyro_fire_port(AO_PYRO_PORT_5, AO_PYRO_PIN_5); break;
+       case 5: ao_pyro_fire_port(AO_PYRO_PORT_5, AO_PYRO_PIN_5, AO_PYRO_5); break;
 #endif
 #if AO_PYRO_NUM > 6
-       case 6: ao_pyro_fire_port(AO_PYRO_PORT_6, AO_PYRO_PIN_6); break;
+       case 6: ao_pyro_fire_port(AO_PYRO_PORT_6, AO_PYRO_PIN_6, AO_PYRO_6); break;
 #endif
 #if AO_PYRO_NUM > 7
-       case 7: ao_pyro_fire_port(AO_PYRO_PORT_7, AO_PYRO_PIN_7); break;
+       case 7: ao_pyro_fire_port(AO_PYRO_PORT_7, AO_PYRO_PIN_7, AO_PYRO_7); break;
 #endif
        default: break;
        }
@@ -291,7 +293,6 @@ void
 ao_pyro_set(void)
 {
        uint8_t p;
-       struct ao_pyro *pyro;
        struct ao_pyro pyro_tmp;
        char    name[AO_PYRO_NAME_LEN];
        uint8_t c;
@@ -351,28 +352,28 @@ void
 ao_pyro_init(void)
 {
 #if AO_PYRO_NUM > 0
-       ao_enable_output(AO_PYRO_PORT_0, AO_PYRO_PIN_0, 0);
+       ao_enable_output(AO_PYRO_PORT_0, AO_PYRO_PIN_0, AO_PYRO_0, 0);
 #endif
 #if AO_PYRO_NUM > 1
-       ao_enable_output(AO_PYRO_PORT_1, AO_PYRO_PIN_1, 0);
+       ao_enable_output(AO_PYRO_PORT_1, AO_PYRO_PIN_1, AO_PYRO_1, 0);
 #endif
 #if AO_PYRO_NUM > 2
-       ao_enable_output(AO_PYRO_PORT_2, AO_PYRO_PIN_2, 0);
+       ao_enable_output(AO_PYRO_PORT_2, AO_PYRO_PIN_2, AO_PYRO_2, 0);
 #endif
 #if AO_PYRO_NUM > 3
-       ao_enable_output(AO_PYRO_PORT_3, AO_PYRO_PIN_3, 0);
+       ao_enable_output(AO_PYRO_PORT_3, AO_PYRO_PIN_3, AO_PYRO_3, 0);
 #endif
 #if AO_PYRO_NUM > 4
-       ao_enable_output(AO_PYRO_PORT_4, AO_PYRO_PIN_4, 0);
+       ao_enable_output(AO_PYRO_PORT_4, AO_PYRO_PIN_4, AO_PYRO_4, 0);
 #endif
 #if AO_PYRO_NUM > 5
-       ao_enable_output(AO_PYRO_PORT_5, AO_PYRO_PIN_5, 0);
+       ao_enable_output(AO_PYRO_PORT_5, AO_PYRO_PIN_5, AO_PYRO_5, 0);
 #endif
 #if AO_PYRO_NUM > 6
-       ao_enable_output(AO_PYRO_PORT_6, AO_PYRO_PIN_6, 0);
+       ao_enable_output(AO_PYRO_PORT_6, AO_PYRO_PIN_6, AO_PYRO_6, 0);
 #endif
 #if AO_PYRO_NUM > 7
-       ao_enable_output(AO_PYRO_PORT_7, AO_PYRO_PIN_7, 0);
+       ao_enable_output(AO_PYRO_PORT_7, AO_PYRO_PIN_7, AO_PYRO_7, 0);
 #endif
        ao_add_task(&ao_pyro_task, ao_pyro, "pyro");
 }
index c5d811f7bfc73905219c1b9cd5b6fb0ddb683aaf..fac0a430f1b97406fefa92d31a4936c5b2fd2aa9 100644 (file)
@@ -236,5 +236,5 @@ void
 ao_storage_device_init(void)
 {
        /* set up CS */
-       ao_enable_output(EE_CS_PORT, EE_CS_PIN,1);
+       ao_enable_output(EE_CS_PORT, EE_CS_PIN, EE_CS, 1);
 }
index 85d68c44151c4de4029af86318ad9914d10b906a..a3167956fd9ca25d464a42426e570e214e9dd7f1 100644 (file)
@@ -131,7 +131,7 @@ static __xdata struct ao_task ao_companion_task;
 void
 ao_companion_init(void)
 {
-       ao_enable_output(AO_COMPANION_CS_PORT, AO_COMPANION_CS_PIN, 1);
+       ao_enable_output(AO_COMPANION_CS_PORT, AO_COMPANION_CS_PIN, AO_COMPANION_CS, 1);
        ao_cmd_register(&ao_companion_cmds[0]);
        ao_add_task(&ao_companion_task, ao_companion, "companion");
 }
index 4416bbabcd4194f7c3cbf9070f1f3abab7f63dbe..d2c973f5d9cc149b87917186a4b3aff3ccd97417 100644 (file)
@@ -76,12 +76,12 @@ ao_spi_init(void);
        } while (0)
 
 
-#define ao_gpio_set(port, pin, v) stm_gpio_set(port, pin, v)
+#define ao_gpio_set(port, bit, pin, v) stm_gpio_set(port, bit, v)
 
-#define ao_enable_output(port,pin,v) do {                      \
+#define ao_enable_output(port,bit,pin,v) do {                  \
                ao_enable_port(port);                           \
-               ao_gpio_set(port, pin, v);                      \
-               stm_moder_set(port, pin, STM_MODER_OUTPUT);     \
+               ao_gpio_set(port, bit, pin, v);                 \
+               stm_moder_set(port, bit, STM_MODER_OUTPUT);\
        } while (0)
 
 #define ao_enable_cs(port,bit) do {                            \