X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fao_dbg.c;h=d4c9567fe519039ec28713dd97282c126c919b42;hp=b218897c627fd7664aa041a394e14243a553ec95;hb=81ad44d4b6d9ad2f6b91d0906e8543da82da424f;hpb=4486d9156e19e4280b42bcd422d81d04f2d04a92 diff --git a/src/ao_dbg.c b/src/ao_dbg.c index b218897c..d4c9567f 100644 --- a/src/ao_dbg.c +++ b/src/ao_dbg.c @@ -16,19 +16,12 @@ */ #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) __reentrant { - P0 = (P0 & ~msk) | (val & msk); + DBG_PORT = (DBG_PORT & ~msk) | (val & msk); _asm nop nop @@ -38,10 +31,10 @@ ao_dbg_send_bits(uint8_t msk, uint8_t val) __reentrant void ao_dbg_send_byte(uint8_t byte) { - __xdata uint8_t b, d; + __pdata 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) @@ -50,13 +43,13 @@ ao_dbg_send_byte(uint8_t byte) 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 ao_dbg_recv_byte(void) { - __xdata uint8_t byte, b; + __pdata uint8_t byte, b; byte = 0; for (b = 0; b < 8; b++) { @@ -96,12 +89,12 @@ ao_dbg_recv_byte(void) #define SFR_DPL1 0x84 #define SFR_DPH1 0x85 -__xdata uint8_t save_acc; -__xdata uint8_t save_psw; -__xdata uint8_t save_dpl0; -__xdata uint8_t save_dph0; -__xdata uint8_t save_dpl1; -__xdata uint8_t save_dph1; +__pdata uint8_t save_acc; +__pdata uint8_t save_psw; +__pdata uint8_t save_dpl0; +__pdata uint8_t save_dph0; +__pdata uint8_t save_dpl1; +__pdata uint8_t save_dph1; static uint8_t ao_dbg_inst1(uint8_t a) __reentrant @@ -171,20 +164,21 @@ ao_dbg_read_byte(void) 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 @@ -196,6 +190,9 @@ ao_dbg_long_delay(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) { @@ -204,7 +201,7 @@ 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 ); @@ -212,7 +209,7 @@ ao_dbg_debug_mode(void) 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 @@ -223,7 +220,7 @@ ao_dbg_reset(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 ); @@ -231,7 +228,7 @@ ao_dbg_reset(void) 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 @@ -263,9 +260,9 @@ debug_put(void) static void debug_get(void) { - __xdata uint16_t count; - __xdata uint16_t i; - __xdata uint8_t byte; + __pdata uint16_t count; + __pdata uint16_t i; + __pdata uint8_t byte; ao_cmd_hex(); if (ao_cmd_status != ao_cmd_success) return; @@ -287,7 +284,7 @@ debug_get(void) static uint8_t getnibble(void) { - __xdata char c; + __pdata char c; c = getchar(); if ('0' <= c && c <= '9') @@ -303,10 +300,10 @@ getnibble(void) static void debug_input(void) { - __xdata uint16_t count; - __xdata uint16_t addr; - __xdata uint8_t b; - __xdata uint8_t i; + __pdata uint16_t count; + __pdata uint16_t addr; + __pdata uint8_t b; + __pdata uint8_t i; ao_cmd_hex(); count = ao_cmd_lex_i; @@ -329,9 +326,9 @@ debug_input(void) static void debug_output(void) { - __xdata uint16_t count; - __xdata uint16_t addr; - __xdata uint8_t b; + __pdata uint16_t count; + __pdata uint16_t addr; + __pdata uint8_t b; ao_cmd_hex(); count = ao_cmd_lex_i; @@ -351,13 +348,13 @@ debug_output(void) } __code struct ao_cmds ao_dbg_cmds[7] = { - { 'D', debug_enable, "D Enable debug mode" }, - { 'G', debug_get, "G Get data from debug port" }, - { 'I', debug_input, "I Input bytes to target at " }, - { 'O', debug_output, "O Output bytes to target at " }, - { 'P', debug_put, "P ... Put data to debug port" }, - { 'R', debug_reset, "R Reset target" }, - { 0, debug_reset, 0 }, + { debug_enable, "D\0Enable debug" }, + { debug_get, "G \0Get data" }, + { debug_input, "I \0Input at " }, + { debug_output, "O \0Output at " }, + { debug_put, "P ...\0Put data" }, + { debug_reset, "R\0Reset" }, + { 0, NULL }, }; void