Skip to content

Commit f1b6073

Browse files
maxd-nordicaescolar
authored andcommitted
driver: swdp_bitbang: hardcode request lut
Hardcode the lookup table for SWDP requests. This is an optimization to save some space. Documentation was added to understand the values. Signed-off-by: Maximilian Deubel <[email protected]>
1 parent 05a45a1 commit f1b6073

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

drivers/dp/swdp_bitbang.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,20 @@ struct sw_cfg_data {
5858
bool fast_clock;
5959
};
6060

61-
static uint8_t sw_request_lut[16] = {0U};
62-
63-
static void mk_sw_request_lut(void)
64-
{
65-
uint32_t parity = 0U;
66-
67-
for (int request = 0; request < sizeof(sw_request_lut); request++) {
68-
parity = request;
69-
parity ^= parity >> 2;
70-
parity ^= parity >> 1;
71-
72-
/*
73-
* Move A[3:3], RnW, APnDP bits to their position,
74-
* add start bit, stop bit(6), and park bit.
75-
*/
76-
sw_request_lut[request] = BIT(7) | (request << 1) | BIT(0);
77-
/* Add parity bit */
78-
if (parity & 0x01U) {
79-
sw_request_lut[request] |= BIT(5);
80-
}
81-
}
82-
83-
LOG_HEXDUMP_DBG(sw_request_lut, sizeof(sw_request_lut), "request lut");
84-
}
61+
/*
62+
* Move A[2:3], RnW, APnDP bits to their position,
63+
* add start bit, stop bit(6), park bit and parity bit.
64+
* For example, reading IDCODE would be APnDP=0, RnW=1, A2=0, A3=0.
65+
* The request would be 0xa5, which is 10100101 in binary.
66+
*
67+
* For more information, see:
68+
* - CMSIS-DAP Command Specification, DAP_Transfer
69+
* - ARM Debug Interface v5 Architecture Specification
70+
*/
71+
const static uint8_t sw_request_lut[16] = {
72+
0x81, 0xa3, 0xa5, 0x87, 0xa9, 0x8b, 0x8d, 0xaf,
73+
0xb1, 0x93, 0x95, 0xb7, 0x99, 0xbb, 0xbd, 0x9f
74+
};
8575

8676
static ALWAYS_INLINE uint32_t sw_get32bit_parity(uint32_t data)
8777
{
@@ -678,7 +668,6 @@ static int sw_gpio_init(const struct device *dev)
678668
sw_data->fast_clock = false;
679669
sw_data->clock_delay = CLOCK_DELAY(SWDP_DEFAULT_SWCLK_FREQUENCY,
680670
config->port_write_cycles);
681-
mk_sw_request_lut();
682671

683672
return 0;
684673
}

0 commit comments

Comments
 (0)