transport: use a bitmask for the transport

Move the transport's names in a local array in the transport
framework.

Replace the string struct transport::name, that identifies the
transport, with a bitmask where each bit corresponds to one of the
available transports.

Change-Id: I6bdf7264d5979c355299f63fcf80bf54dcd95cee
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8674
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
This commit is contained in:
Antonio Borneo
2024-12-22 17:06:12 +01:00
parent 9a5de74423
commit 236208a5ff
7 changed files with 102 additions and 31 deletions

View File

@@ -12,8 +12,27 @@
#include "config.h"
#endif
#include "helper/bits.h"
#include "helper/command.h"
#define TRANSPORT_JTAG BIT(0)
#define TRANSPORT_SWD BIT(1)
#define TRANSPORT_HLA_JTAG BIT(2)
#define TRANSPORT_HLA_SWD BIT(3)
#define TRANSPORT_DAPDIRECT_JTAG BIT(4)
#define TRANSPORT_DAPDIRECT_SWD BIT(5)
#define TRANSPORT_SWIM BIT(6)
/* mask for valid ID */
#define TRANSPORT_VALID_MASK \
(TRANSPORT_JTAG | \
TRANSPORT_SWD | \
TRANSPORT_HLA_JTAG | \
TRANSPORT_HLA_SWD | \
TRANSPORT_DAPDIRECT_JTAG | \
TRANSPORT_DAPDIRECT_SWD | \
TRANSPORT_SWIM)
/**
* Wrapper for transport lifecycle operations.
*
@@ -34,11 +53,10 @@
*/
struct transport {
/**
* Each transport has a unique name, used to select it
* from among the alternatives. Examples might include
* "jtag", * "swd", "AVR_ISP" and more.
* Each transport has a unique ID, used to select it
* from among the alternatives.
*/
const char *name;
unsigned int id;
/**
* When a transport is selected, this method registers
@@ -75,6 +93,8 @@ int transport_register(struct transport *new_transport);
struct transport *get_current_transport(void);
const char *get_current_transport_name(void);
int transport_register_commands(struct command_context *ctx);
int allow_transports(struct command_context *ctx, const char * const *vector);