ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_bscan.c
Go to the documentation of this file.
1
24
25#include "ra8_bscan.h"
26
27#include <stdint.h>
28
29#include "ra8_attributes.h"
30#include "ra8_bscan_regs.h"
31#include "ra8_check.h"
32#include "ra8_err.h"
33#include "ra8_log.h"
34
39static const char* s_tag = "BSCAN";
40
51typedef enum : uint32_t {
54
64
73 .initialized = false,
74 .last_instruction = k_ra8_bscan_instr_bypass,
75 .expected_idcode = 0U,
76};
77
95{
96 /* HUM Ch 50.2.1 "JTIR : Instruction Register", p 3258 */
97 switch (instr) {
104 return true;
105 default:
106 return false;
107 }
108}
109
110[[nodiscard]] ra8_err_t ra8_bscan_init(void)
111{
112 /* HUM Ch 50.2 "Register Descriptions", Table 50.3 p 3258 -- JTIDR
113 * is hardwired to 0x085D_A447 and the JTIR power-on value is 0xE
114 * (BYPASS path selected by the TAP controller on reset). */
115 s_bscan_state.initialized = true;
116 s_bscan_state.last_instruction = k_ra8_bscan_instr_bypass;
117 s_bscan_state.expected_idcode = k_ra8_bscan_jtidr_reset;
118 ra8_log_info(s_tag, "bscan init");
119 return k_ra8_ok;
120}
121
122[[nodiscard]] ra8_err_t ra8_bscan_deinit(void)
123{
124 /* HUM Ch 50.3 "Operation", p 3259 -- TAP returns to its reset
125 * state when the external fixture holds TMS=1 for >=5 TCK clocks.
126 * From a CPU-side bookkeeping viewpoint we just drop our cached
127 * fields back to the power-on equivalents. */
128 s_bscan_state.initialized = false;
129 s_bscan_state.last_instruction = k_ra8_bscan_instr_bypass;
130 s_bscan_state.expected_idcode = 0U;
131 return k_ra8_ok;
132}
133
134[[nodiscard]] ra8_err_t ra8_bscan_get_idcode(uint32_t* out)
135{
136 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
137 if (!s_bscan_state.initialized) {
139 }
140 /* HUM Ch 50.2.2 "JTIDR : ID Code Register", p 3258-3259 -- DID[31:0]
141 * is fixed at 0x085D_A447 by Renesas. The constant is the source of
142 * truth; no hardware fetch is possible. */
143 *out = s_bscan_state.expected_idcode;
144 return k_ra8_ok;
145}
146
148{
149 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
150 /* HUM Ch 50.2.3 "JTBPR : Bypass Register", p 3259 explicitly states
151 * the TAP registers cannot be read from the CPU -- so this is a
152 * pure firmware-side snapshot. */
153 out->initialized = s_bscan_state.initialized;
154 out->last_instruction = s_bscan_state.last_instruction;
155 out->expected_idcode = s_bscan_state.expected_idcode;
156 return k_ra8_ok;
157}
158
159[[nodiscard]] ra8_err_t ra8_bscan_clear_status(uint32_t mask)
160{
161 if (mask != k_ra8_bscan_clear_mask_none) {
163 }
164 if (!s_bscan_state.initialized) {
166 }
167 /* HUM Ch 50.2.1 "JTIR : Instruction Register", p 3258 -- the TAP
168 * reset value 0xE selects the BYPASS path, so "cleared" maps to
169 * BYPASS in our bookkeeping. */
170 s_bscan_state.last_instruction = k_ra8_bscan_instr_bypass;
171 return k_ra8_ok;
172}
173
175{
176 if (!s_bscan_state.initialized) {
178 }
179 if (!internal_is_known_instruction(instr)) {
181 }
182 /* HUM Ch 50.2.1 "JTIR : Instruction Register", p 3258 -- valid
183 * opcodes are EXTEST / SAMPLE_PRELOAD / IDCODE / CLAMP / HIGHZ /
184 * BYPASS. All other 4-bit codes are reserved and rejected above. */
185 s_bscan_state.last_instruction = instr;
186 ra8_log_info_val(s_tag, "set instruction", (uint32_t)instr);
187 return k_ra8_ok;
188}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
ra8_err_t ra8_bscan_get_status(ra8_bscan_status_t *out)
Get a snapshot of the driver's TAP bookkeeping state.
Definition ra8_bscan.c:147
ra8_err_t ra8_bscan_clear_status(uint32_t mask)
Clear the recorded last-instruction state (no hardware effect).
Definition ra8_bscan.c:159
ra8_err_t ra8_bscan_deinit(void)
Tear down the bookkeeping object.
Definition ra8_bscan.c:122
ra8_err_t ra8_bscan_set_instruction(ra8_bscan_instr_t instr)
Record the JTIR opcode the external fixture is currently driving.
Definition ra8_bscan.c:174
ra8_err_t ra8_bscan_init(void)
Initialise the firmware-side TAP bookkeeping object.
Definition ra8_bscan.c:110
static ra8_bscan_state_t s_bscan_state
Singleton bookkeeping state.
Definition ra8_bscan.c:72
static bool internal_is_known_instruction(ra8_bscan_instr_t instr)
Validate that an instruction code is one of the named opcodes.
Definition ra8_bscan.c:94
ra8_bscan_clear_arg_t
Allowed values for the mask argument of ra8_bscan_clear_status.
Definition ra8_bscan.c:51
@ k_ra8_bscan_clear_mask_none
No-op mask – the only legal value.
Definition ra8_bscan.c:52
ra8_err_t ra8_bscan_get_idcode(uint32_t *out)
Get the chip's hardwired JTIDR device ID code.
Definition ra8_bscan.c:134
JTAG / IEEE-1149.1 Boundary Scan TAP HAL surface.
JTAG / IEEE-1149.1 Boundary Scan TAP constants for the RA8D2.
@ k_ra8_bscan_jtidr_reset
JTIDR fixed device ID.
ra8_bscan_instr_t
JTIR Test Bit Set (TS[3:0]) command codes.
@ k_ra8_bscan_instr_idcode
Read JTIDR (Renesas code).
@ k_ra8_bscan_instr_clamp
Clamp output pins.
@ k_ra8_bscan_instr_extest
External test mode.
@ k_ra8_bscan_instr_bypass
Bypass register selected.
@ k_ra8_bscan_instr_sample_preload
Sample / preload.
@ k_ra8_bscan_instr_highz
High-impedance output.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Definition ra8_log.h:366
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
Firmware-side TAP bookkeeping object.
Definition ra8_bscan.c:59
bool initialized
True between init and deinit.
Definition ra8_bscan.c:60
uint32_t expected_idcode
JTIDR value the fixture should see.
Definition ra8_bscan.c:62
ra8_bscan_instr_t last_instruction
Last opcode the fixture reported.
Definition ra8_bscan.c:61
Snapshot of the firmware-side TAP bookkeeping object.
Definition ra8_bscan.h:95
uint32_t expected_idcode
JTIDR value the fixture should observe.
Definition ra8_bscan.h:98
ra8_bscan_instr_t last_instruction
Last JTIR opcode reported by the fixture.
Definition ra8_bscan.h:97
bool initialized
True once ra8_bscan_init ran.
Definition ra8_bscan.h:96