Set version to 1.5.9.1
[fw/altos] / src / lpc / ao_arch_funcs.h
index 0891903ea5f00cb2adae5dbf57506fcdcb81a5c5..b963d3ab72a72c0b6c7c824c7cf8231c7e6257b6 100644 (file)
 
 #define ao_gpio_get(port, bit, pin)    (lpc_gpio.byte[lpc_all_bit(port,bit)])
 
+#define PORT0_JTAG_REGS        ((1 << 11) | (1 << 12) | (1 << 14))
+
+static inline void lpc_set_gpio(int port, int bit) {
+       if (port == 0 && (1 << bit) & (PORT0_JTAG_REGS)) {
+               vuint32_t *_ioconf = &lpc_ioconf.pio0_0 + ((port)*24+(bit));
+
+               *_ioconf = (*_ioconf & ~LPC_IOCONF_FUNC_MASK) | LPC_IOCONF_FUNC_PIO0_11;
+       }
+}
+
 #define ao_enable_output(port,bit,pin,v) do {                  \
                ao_enable_port(port);                           \
+               lpc_set_gpio(port,bit);                         \
                ao_gpio_set(port, bit, pin, v);                 \
                lpc_gpio.dir[port] |= (1 << bit);               \
        } while (0)
@@ -52,6 +63,7 @@
 
 #define ao_enable_input(port,bit,mode) do {                            \
                ao_enable_port(port);                                   \
+               lpc_set_gpio(port,bit);                                 \
                lpc_gpio.dir[port] &= ~(1 << bit);                      \
                ao_gpio_set_mode(port,bit,mode);                        \
        } while (0)
@@ -161,16 +173,17 @@ static inline void ao_arch_restore_stack(void) {
 
 #endif /* HAS_TASK */
 
-#define ao_arch_wait_interrupt() do {                  \
-               asm(".global ao_idle_loc\n\twfi\nao_idle_loc:");        \
-               ao_arch_release_interrupts();                           \
-               ao_arch_block_interrupts();                             \
+#define ao_arch_wait_interrupt() do {                          \
+               asm("\twfi\n");                                 \
+               ao_arch_release_interrupts();                   \
+               asm(".global ao_idle_loc\n\nao_idle_loc:");     \
+               ao_arch_block_interrupts();                     \
        } while (0)
 
-#define ao_arch_critical(b) do {                               \
-               ao_arch_block_interrupts();                     \
-               do { b } while (0);                             \
-               ao_arch_release_interrupts();                   \
+#define ao_arch_critical(b) do {                       \
+               uint32_t __mask = ao_arch_irqsave();    \
+               do { b } while (0);                     \
+               ao_arch_irqrestore(__mask);             \
        } while (0)
 
 /*
@@ -200,7 +213,7 @@ void
 ao_spi_put(uint8_t spi_index);
 
 void
-ao_spi_send(void *block, uint16_t len, uint8_t spi_index);
+ao_spi_send(const void *block, uint16_t len, uint8_t spi_index);
 
 void
 ao_spi_send_fixed(uint8_t value, uint16_t len, uint8_t spi_index);
@@ -209,9 +222,7 @@ void
 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);
-
-extern uint16_t        ao_spi_speed[LPC_NUM_SPI];
+ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t spi_index);
 
 void
 ao_spi_init(void);
@@ -238,4 +249,10 @@ static inline void ao_arch_start_scheduler(void) {
        asm("isb");
 }
 
+void *
+ao_usb_alloc(uint16_t len);
+
+void
+ao_usb_write(void *block, int len);
+
 #endif /* _AO_ARCH_FUNCS_H_ */