Skip to content

Instantly share code, notes, and snippets.

@mvirkkunen
Created September 3, 2020 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvirkkunen/c94266b46efdf978ccec8c6ceae9bb77 to your computer and use it in GitHub Desktop.
Save mvirkkunen/c94266b46efdf978ccec8c6ceae9bb77 to your computer and use it in GitHub Desktop.
sequence_parser
<sequence name="ResetHardware">
<block>
__var nReset = 0x80;
__var canReadPins = 0;
// De-assert nRESET line
canReadPins = (DAP_SWJ_Pins(0x00, nReset, 0) != 0xFFFFFFFF);
</block>
<!-- Keep reset active for 50 ms -->
<control while="1" timeout="50000"/>
<control if="canReadPins">
<!-- Assert nRESET line and wait max. 1s for recovery -->
<control while="(DAP_SWJ_Pins(nReset, nReset, 0) &amp; nReset) == 0" timeout="1000000"/>
</control>
<control if="!canReadPins">
<block>
// Assert nRESET line
DAP_SWJ_Pins(nReset, nReset, 0);
</block>
<!-- Wait 100ms for recovery if nRESET not readable -->
<control while="1" timeout="100000"/>
</control>
</sequence>
Ok(
Sequence {
name: "ResetHardware",
pname: None,
disable: false,
info: None,
body: [
Block(
Block {
atomic: false,
info: None,
body: [
Declare(
"nReset",
Num(
128,
Hex,
),
),
Declare(
"canReadPins",
Num(
0,
Dec,
),
),
Assign(
"canReadPins",
Binary(
Ne,
(
Call(
"DAP_SWJ_Pins",
[
Expr(
Num(
0,
Hex,
),
),
Expr(
Var(
"nReset",
),
),
Expr(
Num(
0,
Dec,
),
),
],
),
Num(
4294967295,
Hex,
),
),
),
),
],
},
),
Control(
Control {
if_cond: None,
while_cond: Some(
Num(
1,
Dec,
),
),
timeout: Some(
50000,
),
info: None,
body: [],
},
),
Control(
Control {
if_cond: Some(
Var(
"canReadPins",
),
),
while_cond: None,
timeout: None,
info: None,
body: [
Control(
Control {
if_cond: None,
while_cond: Some(
Binary(
Eq,
(
Binary(
BitAnd,
(
Call(
"DAP_SWJ_Pins",
[
Expr(
Var(
"nReset",
),
),
Expr(
Var(
"nReset",
),
),
Expr(
Num(
0,
Dec,
),
),
],
),
Var(
"nReset",
),
),
),
Num(
0,
Dec,
),
),
),
),
timeout: Some(
1000000,
),
info: None,
body: [],
},
),
],
},
),
Control(
Control {
if_cond: Some(
Unary(
Not,
Var(
"canReadPins",
),
),
),
while_cond: None,
timeout: None,
info: None,
body: [
Block(
Block {
atomic: false,
info: None,
body: [
Expr(
Call(
"DAP_SWJ_Pins",
[
Expr(
Var(
"nReset",
),
),
Expr(
Var(
"nReset",
),
),
Expr(
Num(
0,
Dec,
),
),
],
),
),
],
},
),
Control(
Control {
if_cond: None,
while_cond: Some(
Num(
1,
Dec,
),
),
timeout: Some(
100000,
),
info: None,
body: [],
},
),
],
},
),
],
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment