Skip to content

Commit

Permalink
Add poke and peek debug commands
Browse files Browse the repository at this point in the history
Also move debug commands in dedicated `debug.c` file
  • Loading branch information
Baldanos committed Jan 21, 2025
1 parent bb39551 commit 8a7a6ff
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 180 deletions.
178 changes: 1 addition & 177 deletions src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "bsp_gpio.h"
#include "microsd.h"
#include "hydrabus_sd.h"
#include "debug.h"

#define HYDRAFW_VERSION "HydraFW (HydraBus) " HYDRAFW_GIT_TAG " " HYDRAFW_CHECKIN_DATE
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
Expand Down Expand Up @@ -270,183 +271,6 @@ int cmd_show(t_hydra_console *con, t_tokenline_parsed *p)
return TRUE;
}

/* Just debug to check Timing and accuracy with output pin */
int cmd_debug_timing(t_hydra_console *con, t_tokenline_parsed *p)
{
uint8_t i;

(void)p;

#if 0
register volatile uint16_t* gpio_set;
register volatile uint16_t* gpio_clr;
/* GPIO B3 */
gpio_set = (uint16_t*)&(((GPIO_TypeDef *)(0x40000000ul + 0x00020000ul + 0x0400ul))->BSRR.H.set);
gpio_clr = (uint16_t*)&(((GPIO_TypeDef *)(0x40000000ul + 0x00020000ul + 0x0400ul))->BSRR.H.clear);
//#define gpio_val (uint16_t)(((ioportmask_t)(1 << (3))))
register uint16_t gpio_val = (uint16_t)(((ioportmask_t)(1 << (3))));

#define TST_OFF (*gpio_clr=gpio_val)
#define TST_ON (*gpio_set=gpio_val)
#endif
volatile systime_t tick, ticks10MHz, ticks3_39MHz, tick1MHz, ticks_1us;

bsp_gpio_init(BSP_GPIO_PORTB, 3, MODE_CONFIG_DEV_GPIO_OUT_PUSHPULL, MODE_CONFIG_DEV_GPIO_NOPULL);

/* 168MHz Clk=5.84ns/cycle */
ticks10MHz = 8; /* 10MHz= (100ns/2) / 5.84 */
ticks3_39MHz = 25; /* 3.39MHz= (295ns/2) / 5.84 */
tick1MHz = 85; /* 1MHz= (1000ns/2) / 5.84 */
ticks_1us = 171;
cprintf(con, "50ns=%.2ld ticks\r\n", (uint32_t)ticks10MHz);
cprintf(con, "148ns=%.2ld ticks\r\n", (uint32_t)ticks3_39MHz);
cprintf(con, "500ns=%.2ld ticks\r\n", (uint32_t)tick1MHz);
cprintf(con, "Test dbg Out Freq Max 84Mhz(11.9ns),10MHz(100ns/2),3.39MHz(295ns/2),1MHz(1us/2)\r\nPress User Button to exit\r\n");
chThdSleepMilliseconds(1);

/* Lock Kernel for sniffer */
chSysLock();

while (1) {
/* Exit if User Button is pressed */
if (hydrabus_ubtn()) {
break;
}


TST_OFF;

/* Fastest possible 0/1 */
for(i=0; i<16; i++) {
TST_ON;
TST_OFF;

TST_ON;
TST_OFF;

TST_ON;
TST_OFF;

TST_ON;
TST_OFF;
}

/* Delay 1us */
tick = ticks_1us;
wait_delay(tick);

/* Freq 10Mhz */
tick = ticks10MHz;
for(i=0; i<16; i++) {
TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);
}

/* Delay 1us */
tick = ticks_1us;
wait_delay(tick);

/* Freq 3.39Mhz */
tick = ticks3_39MHz;
for(i=0; i<16; i++) {
TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);
}

/* Delay 1us */
tick = ticks_1us;
wait_delay(tick);

/* Freq 1Mhz */
tick = tick1MHz;
for(i=0; i<16; i++) {
TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);

TST_ON;
wait_delay(tick);
TST_OFF;
wait_delay(tick);
}

}

chSysUnlock();
cprintf(con, "Test dbg Out Freq end\r\n");

/* Reconfigure GPIOB3 in Safe Mode / Input */
bsp_gpio_init(BSP_GPIO_PORTB, 3, MODE_CONFIG_DEV_GPIO_IN, MODE_CONFIG_DEV_GPIO_NOPULL);

return TRUE;
}

/* Just debug rx speed ignore all data received until UBTN + a key is pressed */
int cmd_debug_test_rx(t_hydra_console *con, t_tokenline_parsed *p)
{
(void)p;
BaseSequentialStream* chp = con->bss;
uint8_t * inbuf = pool_alloc_bytes(0x1000); // 4096 bytes

cprintf(con, "Test debug-rx started, stop it with UBTN + Key\r\n");
while(1) {
chnRead(chp, inbuf, 0x0FFF);

/* Exit if User Button is pressed */
if (hydrabus_ubtn()) {
break;
}
//get_char(con);
}
pool_free(inbuf);
return TRUE;
}

uint8_t hexchartonibble(char hex)
{
if (hex >= '0' && hex <= '9') return hex - '0';
Expand Down
2 changes: 0 additions & 2 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ int cmd_mode_exec(t_hydra_console *con, t_tokenline_parsed *p);
typedef int (*cmdfunc)(t_hydra_console *con, t_tokenline_parsed *p);
int mode_exit(t_hydra_console *con, t_tokenline_parsed *p);
int cmd_show(t_hydra_console *con, t_tokenline_parsed *p);
int cmd_debug_timing(t_hydra_console *con, t_tokenline_parsed *p);
int cmd_debug_test_rx(t_hydra_console *con, t_tokenline_parsed *p);
int cmd_adc(t_hydra_console *con, t_tokenline_parsed *p);
int cmd_dac(t_hydra_console *con, t_tokenline_parsed *p);
int cmd_pwm(t_hydra_console *con, t_tokenline_parsed *p);
Expand Down
3 changes: 2 additions & 1 deletion src/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ COMMONSRC = common/common.c \
common/usb1cfg.c \
common/usb2cfg.c \
common/script.c \
common/alloc.c
common/alloc.c \
common/debug.c

# Required include directories
COMMONINC = ./common
Loading

0 comments on commit 8a7a6ff

Please sign in to comment.