*/
#include "ao.h"
-
-#define DBG_CLOCK (1 << 3)
-#define DBG_DATA (1 << 4)
-#define DBG_RESET_N (1 << 5)
-
-#define DBG_CLOCK_PIN (P0_3)
-#define DBG_DATA_PIN (P0_4)
-#define DBG_RESET_N_PIN (P0_5)
+#include "ao_pins.h"
static void
-ao_dbg_send_bits(uint8_t msk, uint8_t val)
+ao_dbg_send_bits(uint8_t msk, uint8_t val) __reentrant
{
- P0 = (P0 & ~msk) | (val & msk);
+ DBG_PORT = (DBG_PORT & ~msk) | (val & msk);
_asm
nop
nop
{
__xdata uint8_t b, d;
- P0 |= DBG_DATA;
- P0DIR |= DBG_DATA;
+ DBG_PORT |= DBG_DATA;
+ DBG_PORT_DIR |= DBG_DATA;
for (b = 0; b < 8; b++) {
d = 0;
if (byte & 0x80)
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA, DBG_CLOCK|d);
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA, 0 |d);
}
- P0DIR &= ~DBG_DATA;
+ DBG_PORT_DIR &= ~DBG_DATA;
}
uint8_t
static void
ao_dbg_set_pins(void)
{
- /* Disable peripheral use of P0 */
- ADCCFG = 0;
- P0SEL = 0;
+ /* Make the DBG pins GPIOs. On TeleMetrum, this will
+ * disable the SPI link, so don't expect SPI to work after
+ * using the debugger.
+ */
+ DBG_PORT_SEL &= ~(DBG_CLOCK|DBG_DATA|DBG_RESET_N);
-
- /* make P0_4 tri-state */
- P0INP = DBG_DATA;
- P2INP &= ~(P2INP_PDUP0_PULL_DOWN);
+ /* make DBG_DATA tri-state */
+ DBG_PORT_INP |= DBG_DATA;
/* Raise RESET_N and CLOCK */
- P0 = DBG_RESET_N | DBG_CLOCK;
+ DBG_PORT |= DBG_RESET_N | DBG_CLOCK;
/* RESET_N and CLOCK are outputs now */
- P0DIR = DBG_RESET_N | DBG_CLOCK;
+ DBG_PORT_DIR |= DBG_RESET_N | DBG_CLOCK;
+ DBG_PORT_DIR &= ~DBG_DATA;
}
static void
_asm nop _endasm;
}
+#define AO_RESET_LOW_DELAY AO_MS_TO_TICKS(100)
+#define AO_RESET_HIGH_DELAY AO_MS_TO_TICKS(100)
+
void
ao_dbg_debug_mode(void)
{
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N);
ao_dbg_long_delay();
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, 0 |DBG_DATA| 0 );
- ao_dbg_long_delay();
+ ao_delay(AO_RESET_LOW_DELAY);
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 );
ao_dbg_long_delay();
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, 0 |DBG_DATA| 0 );
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 );
ao_dbg_long_delay();
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, 0 |DBG_DATA|DBG_RESET_N);
- ao_dbg_long_delay();
+ ao_delay(AO_RESET_HIGH_DELAY);
}
void
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N);
ao_dbg_long_delay();
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 );
- ao_dbg_long_delay();
+ ao_delay(AO_RESET_LOW_DELAY);
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 );
ao_dbg_long_delay();
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 );
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 );
ao_dbg_long_delay();
ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N);
- ao_dbg_long_delay();
+ ao_delay(AO_RESET_HIGH_DELAY);
}
static void
}
__code struct ao_cmds ao_dbg_cmds[7] = {
- { 'D', debug_enable, "D Enable debug mode" },
- { 'G', debug_get, "G <count> Get data from debug port" },
- { 'I', debug_input, "I <count> <addr> Input <count> bytes to target at <addr>" },
- { 'O', debug_output, "O <count> <addr> Output <count> bytes to target at <addr>" },
- { 'P', debug_put, "P <byte> ... Put data to debug port" },
- { 'R', debug_reset, "R Reset target" },
- { 0, debug_reset, 0 },
+ { debug_enable, "D\0Enable debug mode" },
+ { debug_get, "G <count>\0Get data from debug port" },
+ { debug_input, "I <count> <addr>\0Input <count> bytes to target at <addr>" },
+ { debug_output, "O <count> <addr>\0Output <count> bytes to target at <addr>" },
+ { debug_put, "P <byte> ...\0Put data to debug port" },
+ { debug_reset, "R\0Reset target" },
+ { 0, NULL },
};
void