Merge pull request #47 from richardeoin/target-power

Added monitor option to toggle target power
This commit is contained in:
Gareth McMullin 2014-07-30 14:19:46 +12:00
commit bfe5d1168b
4 changed files with 32 additions and 5 deletions

View File

@ -47,6 +47,7 @@ static bool cmd_swdp_scan(void);
static bool cmd_targets(target *t);
static bool cmd_morse(void);
static bool cmd_connect_srst(target *t, int argc, const char **argv);
static bool cmd_target_power(target *t, int argc, const char **argv);
#ifdef PLATFORM_HAS_TRACESWO
static bool cmd_traceswo(void);
#endif
@ -59,6 +60,7 @@ const struct command_s cmd_list[] = {
{"targets", (cmd_handler)cmd_targets, "Display list of available targets" },
{"morse", (cmd_handler)cmd_morse, "Display morse error message" },
{"connect_srst", (cmd_handler)cmd_connect_srst, "Configure connect under SRST: (enable|disable)" },
{"tpwr", (cmd_handler)cmd_target_power, "Supplies power to the target: (enable|disable)"},
#ifdef PLATFORM_HAS_TRACESWO
{"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture" },
#endif
@ -221,6 +223,16 @@ static bool cmd_connect_srst(target *t, int argc, const char **argv)
connect_assert_srst = !strcmp(argv[1], "enable");
return true;
}
static bool cmd_target_power(target *t, int argc, const char **argv)
{
(void)t;
if (argc == 1)
gdb_outf("Target Power: %s\n",
!platform_target_get_power() ? "enabled" : "disabled");
else
platform_target_set_power(!strncmp(argv[1], "enable", strlen(argv[1])));
return true;
}
#ifdef PLATFORM_HAS_TRACESWO
static bool cmd_traceswo(void)

View File

@ -158,7 +158,18 @@ void platform_srst_set_val(bool assert)
gpio_set_val(SRST_PORT, SRST_PIN, !assert);
}
}
bool platform_target_get_power(void) {
if (platform_hwversion() > 0) {
return gpio_get(PWR_BR_PORT, PWR_BR_PIN);
}
return 1; // 1 = Unpowered
}
void platform_target_set_power(bool power)
{
if (platform_hwversion() > 0) {
gpio_set_val(PWR_BR_PORT, PWR_BR_PIN, !power);
}
}
void platform_delay(uint32_t delay)
{
timeout_counter = delay;

View File

@ -231,3 +231,5 @@ static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios)
void assert_boot_pin(void);
void setup_vbus_irq(void);
void platform_srst_set_val(bool assert);
bool platform_target_get_power(void);
void platform_target_set_power(bool power);

View File

@ -42,10 +42,12 @@ int jtagtap_init(void)
void jtagtap_reset(void)
{
#ifdef TRST_PORT
volatile int i;
gpio_clear(TRST_PORT, TRST_PIN);
for(i = 0; i < 10000; i++) asm("nop");
gpio_set(TRST_PORT, TRST_PIN);
if (platform_hwversion() == 0) {
volatile int i;
gpio_clear(TRST_PORT, TRST_PIN);
for(i = 0; i < 10000; i++) asm("nop");
gpio_set(TRST_PORT, TRST_PIN);
}
#endif
jtagtap_soft_reset();
}