Overhaul of timeouts so they may be nested.
This commit is contained in:
parent
6b6ac1b961
commit
8b4342394f
|
@ -82,16 +82,17 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW,
|
|||
addr &= 0xff;
|
||||
uint64_t request, response;
|
||||
uint8_t ack;
|
||||
platform_timeout timeout;
|
||||
|
||||
request = ((uint64_t)value << 3) | ((addr >> 1) & 0x06) | (RnW?1:0);
|
||||
|
||||
jtag_dev_write_ir(dp->dev, APnDP ? IR_APACC : IR_DPACC);
|
||||
|
||||
platform_timeout_set(2000);
|
||||
platform_timeout_set(&timeout, 2000);
|
||||
do {
|
||||
jtag_dev_shift_dr(dp->dev, (uint8_t*)&response, (uint8_t*)&request, 35);
|
||||
ack = response & 0x07;
|
||||
} while(!platform_timeout_is_expired() && (ack == JTAGDP_ACK_WAIT));
|
||||
} while(!platform_timeout_is_expired(&timeout) && (ack == JTAGDP_ACK_WAIT));
|
||||
|
||||
if (ack == JTAGDP_ACK_WAIT)
|
||||
raise_exception(EXCEPTION_TIMEOUT, "JTAG-DP ACK timeout");
|
||||
|
|
|
@ -120,6 +120,7 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW,
|
|||
uint8_t request = 0x81;
|
||||
uint32_t response = 0;
|
||||
uint8_t ack;
|
||||
platform_timeout timeout;
|
||||
|
||||
if(APnDP && dp->fault) return 0;
|
||||
|
||||
|
@ -131,11 +132,11 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW,
|
|||
if((addr == 4) || (addr == 8))
|
||||
request ^= 0x20;
|
||||
|
||||
platform_timeout_set(2000);
|
||||
platform_timeout_set(&timeout, 2000);
|
||||
do {
|
||||
swdptap_seq_out(request, 8);
|
||||
ack = swdptap_seq_in(3);
|
||||
} while (!platform_timeout_is_expired() && ack == SWDP_ACK_WAIT);
|
||||
} while (!platform_timeout_is_expired(&timeout) && ack == SWDP_ACK_WAIT);
|
||||
|
||||
if (ack == SWDP_ACK_WAIT)
|
||||
raise_exception(EXCEPTION_TIMEOUT, "SWDP ACK timeout");
|
||||
|
|
|
@ -307,7 +307,7 @@ bool cortexa_attach(target *t)
|
|||
target_halt_request(t);
|
||||
tries = 10;
|
||||
while(!platform_srst_get_val() && !target_halt_wait(t) && --tries)
|
||||
platform_delay(2);
|
||||
platform_delay(200);
|
||||
if(!tries)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ bool cortexm_attach(target *t)
|
|||
target_halt_request(t);
|
||||
tries = 10;
|
||||
while(!platform_srst_get_val() && !target_halt_wait(t) && --tries)
|
||||
platform_delay(2);
|
||||
platform_delay(200);
|
||||
if(!tries)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -30,11 +30,13 @@ void platform_init(int argc, char **argv);
|
|||
void platform_init(void);
|
||||
#endif
|
||||
|
||||
typedef struct platform_timeout platform_timeout;
|
||||
void platform_timeout_set(platform_timeout *t, uint32_t ms);
|
||||
bool platform_timeout_is_expired(platform_timeout *t);
|
||||
void platform_delay(uint32_t ms);
|
||||
|
||||
const char *platform_target_voltage(void);
|
||||
int platform_hwversion(void);
|
||||
void platform_timeout_set(uint32_t ms);
|
||||
bool platform_timeout_is_expired(void);
|
||||
void platform_delay(uint32_t delay);
|
||||
void platform_srst_set_val(bool assert);
|
||||
bool platform_srst_get_val(void);
|
||||
bool platform_target_get_power(void);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of the Black Magic Debug project.
|
||||
*
|
||||
* Copyright (C) 2016 Black Sphere Technologies Ltd.
|
||||
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "general.h"
|
||||
|
||||
void platform_timeout_set(platform_timeout *t, uint32_t ms)
|
||||
{
|
||||
t->time = platform_time_ms() + ms;
|
||||
}
|
||||
|
||||
bool platform_timeout_is_expired(platform_timeout *t)
|
||||
{
|
||||
return platform_time_ms() > t->time;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This file is part of the Black Magic Debug project.
|
||||
*
|
||||
* Copyright (C) 2016 Black Sphere Technologies Ltd.
|
||||
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef __TIMING__H
|
||||
#define __TIMING_H
|
||||
|
||||
struct platform_timeout {
|
||||
uint32_t time;
|
||||
};
|
||||
|
||||
uint32_t platform_time_ms(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -20,6 +20,7 @@ SRC += cdcacm.c \
|
|||
usbuart.c \
|
||||
serialno.c \
|
||||
timing.c \
|
||||
timing_stm32.c \
|
||||
|
||||
all: blackmagic.bin
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "gpio.h"
|
||||
#include "timing.h"
|
||||
#include "timing_stm32.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <setjmp.h>
|
||||
|
|
|
@ -20,6 +20,7 @@ SRC += cdcacm.c \
|
|||
usbuart.c \
|
||||
serialno.c \
|
||||
timing.c \
|
||||
timing_stm32.c \
|
||||
|
||||
all: blackmagic.bin blackmagic.hex blackmagic.dfu
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "gpio.h"
|
||||
#include "timing.h"
|
||||
#include "timing_stm32.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <setjmp.h>
|
||||
|
|
|
@ -15,6 +15,7 @@ VPATH += platforms/tm4c
|
|||
|
||||
SRC += cdcacm.c \
|
||||
usbuart.c \
|
||||
timing.c \
|
||||
traceswo.o
|
||||
|
||||
all: blackmagic.bin
|
||||
|
|
|
@ -33,14 +33,19 @@
|
|||
|
||||
extern void trace_tick(void);
|
||||
|
||||
volatile platform_timeout * volatile head_timeout;
|
||||
uint8_t running_status;
|
||||
volatile uint32_t timeout_counter;
|
||||
static volatile uint32_t time_ms;
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
if(timeout_counter)
|
||||
timeout_counter--;
|
||||
trace_tick();
|
||||
time_ms += 10;
|
||||
}
|
||||
|
||||
uint32_t platform_time_ms(void)
|
||||
{
|
||||
return time_ms;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -101,20 +106,11 @@ bool platform_srst_get_val(void)
|
|||
return gpio_get(SRST_PORT, SRST_PIN) == 0;
|
||||
}
|
||||
|
||||
void platform_timeout_set(uint32_t ms)
|
||||
void platform_delay(uint32_t ms)
|
||||
{
|
||||
timeout_counter = ms / 10;
|
||||
}
|
||||
|
||||
bool platform_timeout_is_expired(void)
|
||||
{
|
||||
return timeout_counter == 0;
|
||||
}
|
||||
|
||||
void platform_delay(uint32_t delay)
|
||||
{
|
||||
platform_timeout_set(delay);
|
||||
while (platform_timeout_is_expired());
|
||||
platform_timeout timeout;
|
||||
platform_timeout_set(&timeout, ms);
|
||||
while (!platform_timeout_is_expired(&timeout));
|
||||
}
|
||||
|
||||
const char *platform_target_voltage(void)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <libopencm3/lm4f/gpio.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
|
||||
#include "timing.h"
|
||||
#include "version.h"
|
||||
|
||||
#define BOARD_IDENT "Black Magic Probe (Launchpad ICDI), (Firmware " FIRMWARE_VERSION ")"
|
||||
|
@ -28,7 +29,6 @@
|
|||
#define DFU_IFACE_STRING "lolwut"
|
||||
|
||||
extern uint8_t running_status;
|
||||
extern volatile uint32_t timeout_counter;
|
||||
|
||||
#define TMS_PORT GPIOA_BASE
|
||||
#define TMS_PIN GPIO3
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
CFLAGS += -DLIBFTDI
|
||||
LDFLAGS += -lftdi -lusb
|
||||
|
||||
SRC += timing.c \
|
||||
|
|
|
@ -279,26 +279,15 @@ const char *platform_target_voltage(void)
|
|||
return "not supported";
|
||||
}
|
||||
|
||||
void platform_delay(uint32_t delay)
|
||||
void platform_delay(uint32_t ms)
|
||||
{
|
||||
usleep(delay * 100000);
|
||||
usleep(ms * 1000);
|
||||
}
|
||||
|
||||
static uint32_t timeout_time;
|
||||
static uint32_t time_ms(void)
|
||||
uint32_t platform_time_ms(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
void platform_timeout_set(uint32_t ms)
|
||||
{
|
||||
timeout_time = time_ms() + ms;
|
||||
}
|
||||
|
||||
bool platform_timeout_is_expired(void)
|
||||
{
|
||||
return time_ms() > timeout_time;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <ftdi.h>
|
||||
|
||||
#include "timing.h"
|
||||
|
||||
#ifndef WIN32
|
||||
# include <alloca.h>
|
||||
#else
|
||||
|
|
|
@ -19,6 +19,7 @@ SRC += cdcacm.c \
|
|||
usbuart.c \
|
||||
serialno.c \
|
||||
timing.c \
|
||||
timing_stm32.c \
|
||||
|
||||
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "gpio.h"
|
||||
#include "timing.h"
|
||||
#include "timing_stm32.h"
|
||||
|
||||
#define PLATFORM_HAS_TRACESWO
|
||||
#define PLATFORM_HAS_POWER_SWITCH
|
||||
|
|
|
@ -19,6 +19,7 @@ SRC += cdcacm.c \
|
|||
usbuart.c \
|
||||
serialno.c \
|
||||
timing.c \
|
||||
timing_stm32.c \
|
||||
|
||||
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "gpio.h"
|
||||
#include "timing.h"
|
||||
#include "timing_stm32.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <libopencm3/cm3/common.h>
|
||||
|
|
|
@ -113,7 +113,8 @@ unsigned char gdb_if_getchar(void)
|
|||
|
||||
unsigned char gdb_if_getchar_to(int timeout)
|
||||
{
|
||||
platform_timeout_set(timeout);
|
||||
platform_timeout t;
|
||||
platform_timeout_set(&t, timeout);
|
||||
|
||||
if (!(out_ptr < count_out)) do {
|
||||
/* Detach if port closed */
|
||||
|
@ -121,7 +122,7 @@ unsigned char gdb_if_getchar_to(int timeout)
|
|||
return 0x04;
|
||||
|
||||
gdb_if_update_buf();
|
||||
} while (!platform_timeout_is_expired() && !(out_ptr < count_out));
|
||||
} while (!platform_timeout_is_expired(&t) && !(out_ptr < count_out));
|
||||
|
||||
if(out_ptr < count_out)
|
||||
return gdb_if_getchar();
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include <libopencm3/cm3/scb.h>
|
||||
|
||||
uint8_t running_status;
|
||||
|
||||
static volatile uint32_t timeout_counter;
|
||||
static volatile uint32_t time_ms;
|
||||
|
||||
void platform_timing_init(void)
|
||||
{
|
||||
|
@ -37,20 +36,11 @@ void platform_timing_init(void)
|
|||
systick_counter_enable();
|
||||
}
|
||||
|
||||
void platform_timeout_set(uint32_t ms)
|
||||
void platform_delay(uint32_t ms)
|
||||
{
|
||||
timeout_counter = ms / 100;
|
||||
}
|
||||
|
||||
bool platform_timeout_is_expired(void)
|
||||
{
|
||||
return timeout_counter == 0;
|
||||
}
|
||||
|
||||
void platform_delay(uint32_t delay)
|
||||
{
|
||||
platform_timeout_set(delay);
|
||||
while (!platform_timeout_is_expired());
|
||||
platform_timeout timeout;
|
||||
platform_timeout_set(&timeout, ms);
|
||||
while (!platform_timeout_is_expired(&timeout));
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
|
@ -58,9 +48,13 @@ void sys_tick_handler(void)
|
|||
if(running_status)
|
||||
gpio_toggle(LED_PORT, LED_IDLE_RUN);
|
||||
|
||||
if(timeout_counter)
|
||||
timeout_counter--;
|
||||
time_ms += 100;
|
||||
|
||||
SET_ERROR_STATE(morse_update());
|
||||
}
|
||||
|
||||
uint32_t platform_time_ms(void)
|
||||
{
|
||||
return time_ms;
|
||||
}
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef __TIMING_H
|
||||
#define __TIMING_H
|
||||
#ifndef __TIMING_STM32_H
|
||||
#define __TIMING_STM32_H
|
||||
|
||||
extern uint8_t running_status;
|
||||
|
|
@ -19,6 +19,7 @@ SRC += cdcacm.c \
|
|||
usbuart.c \
|
||||
serialno.c \
|
||||
timing.c \
|
||||
timing_stm32.c \
|
||||
|
||||
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "gpio.h"
|
||||
#include "timing.h"
|
||||
#include "timing_stm32.h"
|
||||
#include "version.h"
|
||||
|
||||
#define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware " FIRMWARE_VERSION ")"
|
||||
|
|
|
@ -84,7 +84,8 @@ unsigned char gdb_if_getchar(void)
|
|||
|
||||
unsigned char gdb_if_getchar_to(int timeout)
|
||||
{
|
||||
timeout_counter = timeout/100;
|
||||
platform_timeout t;
|
||||
platform_timeout_set(&t, timeout);
|
||||
|
||||
if(head_out == tail_out) do {
|
||||
/* Detach if port closed */
|
||||
|
@ -92,7 +93,7 @@ unsigned char gdb_if_getchar_to(int timeout)
|
|||
return 0x04;
|
||||
|
||||
while(cdcacm_get_config() != 1);
|
||||
} while(timeout_counter && head_out == tail_out);
|
||||
} while(!platform_timeout_is_expired(&t) && head_out == tail_out);
|
||||
|
||||
if(head_out != tail_out)
|
||||
return gdb_if_getchar();
|
||||
|
|
Loading…
Reference in New Issue