Skip to content

Commit 7e71137

Browse files
clarify bitfield order, remove related TODOs, #2
1 parent 9982807 commit 7e71137

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

esp32_ulp/opcodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
def make_ins_struct_def(layout):
4949
lines = layout.strip().splitlines()
50-
pos = 0
50+
pos = 0 # bitfield definitions start from lsb
5151
struct_def = {}
5252
for line in lines:
5353
bitfield = line.split('#', 1)[0] # get rid of comment

tests/opcodes.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44
OPCODE_DELAY = 4
55
LAYOUT_DELAY = """
6-
cycles : 16 # Number of cycles to sleep
7-
unused : 12 # Unused
8-
opcode : 4 # Opcode (OPCODE_DELAY)
6+
cycles : 16 # Number of cycles to sleep
7+
unused : 12 # Unused
8+
opcode : 4 # Opcode (OPCODE_DELAY)
99
"""
1010

1111

1212
def test_make_ins_struct_def():
1313
sd = make_ins_struct_def(LAYOUT_DELAY)
1414
assert set(sd) == {'cycles', 'unused', 'opcode', 'all'}
15-
# TODO check if the expected values are correct (bitfield order)
1615
assert sd['cycles'] == BFUINT32 | 0 << BF_POS | 16 << BF_LEN
1716
assert sd['unused'] == BFUINT32 | 16 << BF_POS | 12 << BF_LEN
1817
assert sd['opcode'] == BFUINT32 | 28 << BF_POS | 4 << BF_LEN
@@ -27,9 +26,7 @@ def test_make_ins():
2726
assert _delay.cycles == 0x23
2827
assert _delay.unused == 0
2928
assert _delay.opcode == OPCODE_DELAY
30-
# TODO: check if the expected value is correct (byte order, bitfield order)
31-
expected = 0x40000023
32-
assert _delay.all == expected, '%x != %x' % (_delay.all, expected)
29+
assert _delay.all == 0x40000023
3330

3431

3532
test_make_ins_struct_def()

0 commit comments

Comments
 (0)