forked from phdussud/pico-dirtyJtag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpio_jtag.h
More file actions
87 lines (66 loc) · 3.04 KB
/
Copy pathpio_jtag.h
File metadata and controls
87 lines (66 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* The MIT License (MIT)
*
* Copyright (c) 2020-2022 Patrick Dussud
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#ifndef _PIO_JTAG_H
#define _PIO_JTAG_H
#include "hardware/pio.h"
typedef struct pio_jtag_inst {
PIO pio;
uint sm;
uint pin_tdi;
uint pin_tdo;
uint pin_tck;
uint pin_tms;
uint pin_rst;
uint pin_trst;
} pio_jtag_inst_t;
void init_gow1n_pins(uint pin_jtagsel_n, uint pin_recon_n, uint pin_done);
void init_jtag(pio_jtag_inst_t* jtag, uint freq, uint pin_tck, uint pin_tdi, uint pin_tdo, uint pin_tms, uint pin_rst, uint pin_trst);
void pio_jtag_write_blocking(const pio_jtag_inst_t *jtag, const uint8_t *src, size_t len);
void pio_jtag_write_read_blocking(const pio_jtag_inst_t *jtag, const uint8_t *src, uint8_t *dst, size_t len);
uint8_t pio_jtag_write_tms_blocking(const pio_jtag_inst_t *jtag, bool tdi, bool tms, size_t len);
void jtag_set_clk_freq(const pio_jtag_inst_t *jtag, uint freq_khz);
void jtag_transfer(const pio_jtag_inst_t *jtag, uint32_t length, const uint8_t* in, uint8_t* out);
uint8_t jtag_strobe(const pio_jtag_inst_t *jtag, uint32_t length, bool tms, bool tdi);
static inline void jtag_set_tms(const pio_jtag_inst_t *jtag, bool value)
{
gpio_put(jtag->pin_tms, value);
}
static inline void jtag_set_rst(const pio_jtag_inst_t *jtag, bool value)
{
/* Change the direction to out to drive pin to 0 or to in to emulate open drain */
gpio_set_dir(jtag->pin_rst, !value);
}
static inline void jtag_set_trst(const pio_jtag_inst_t *jtag, bool value)
{
gpio_put(jtag->pin_trst, value);
}
// The following APIs assume that they are called in the following order:
// jtag_set_XXX where XXX is any pin. if XXX is clk it needs to be false
// jtag_set_clk where clk is true This will initiate a one cycle pio_jtag_write_read_blocking
// possibly jtag_get_tdo which will get what was read during the previous step
void jtag_set_tdi(const pio_jtag_inst_t *jtag, bool value);
void jtag_set_clk(const pio_jtag_inst_t *jtag, bool value);
bool jtag_get_tdo(const pio_jtag_inst_t *jtag);
#endif