Skip to content

Commit cb7e1b7

Browse files
committed
allow specifying the address for reg_rd and reg_wr in 32-bit words
This change allows specifying the address in 32-bit words (i.e. the address as seen from the ULP), in addition to the existing mode of specifying a register's full address on the DPORT bus. If an address is between 0 and 0x3ff, treat it as a word offset (ULP address), otherwise treat it as a full address on the DPORT bus as before.
1 parent 8b068a6 commit cb7e1b7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

esp32_ulp/opcodes.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ def get_cond(arg):
356356
def _soc_reg_to_ulp_periph_sel(reg):
357357
# Map SoC peripheral register to periph_sel field of RD_REG and WR_REG instructions.
358358
ret = 3
359-
if reg < DR_REG_RTCCNTL_BASE:
359+
if reg < 0x3ff:
360+
ret = 0
361+
elif reg < DR_REG_RTCCNTL_BASE:
360362
raise ValueError("invalid register base")
361363
elif reg < DR_REG_RTCIO_BASE:
362364
ret = RD_REG_PERIPH_RTC_CNTL
@@ -373,7 +375,10 @@ def _soc_reg_to_ulp_periph_sel(reg):
373375

374376
def i_reg_wr(reg, high_bit, low_bit, val):
375377
reg = get_imm(reg)
376-
_wr_reg.addr = (reg & 0xff) >> 2
378+
if reg < 0x3ff: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
379+
_wr_reg.addr = reg
380+
else:
381+
_wr_reg.addr = (reg & 0xff) >> 2
377382
_wr_reg.periph_sel = _soc_reg_to_ulp_periph_sel(reg)
378383
_wr_reg.data = get_imm(val)
379384
_wr_reg.low = get_imm(low_bit)
@@ -384,7 +389,10 @@ def i_reg_wr(reg, high_bit, low_bit, val):
384389

385390
def i_reg_rd(reg, high_bit, low_bit):
386391
reg = get_imm(reg)
387-
_rd_reg.addr = (reg & 0xff) >> 2
392+
if reg < 0x3ff: # see https://github.com/espressif/binutils-esp32ulp/blob/master/gas/config/tc-esp32ulp_esp32.c
393+
_rd_reg.addr = reg
394+
else:
395+
_rd_reg.addr = (reg & 0xff) >> 2
388396
_rd_reg.periph_sel = _soc_reg_to_ulp_periph_sel(reg)
389397
_rd_reg.unused = 0
390398
_rd_reg.low = get_imm(low_bit)

tests/compat/fixes.S

+5
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ counter:
1717
entry:
1818
MOVE R1, gpio
1919
WAIT 42
20+
21+
# reg_rd/reg_wr with "short" and "long" address notation
22+
reg_rd 12, 7, 0
23+
reg_rd 0x3ff48000, 7, 0
24+
2025
halt

0 commit comments

Comments
 (0)