If anyone is ever interested in this... for some reason ...here is the macro I've wrote for it. It's huge and totally impractical, as it is so large, that if you use 2 of them like this: A -> ioset -> ioset -> B, you will not be able to call a jump from A to B, because of
. As discussed
, this is because that jump exceeds some arbitrary relative address value..
This is the macro. As you see, due to the nested jumps one has to use the
Code: Select all
// Needed to be able to use LOCAL labels inside of macros
.altmacro
.text
.macro ioset pin state
LOCAL ioset_state
LOCAL ioset_done
move r0, \pin
move r1, \state
move r2, ioset_state
// Multiply pin number by 4 (each RTCIO requires 4 instructions)
lsh r0, r0, 2
// Multiply state by 2 (instruction for setting HIGH is offset by 2 instr.)
lsh r1, r1, 1
// Add together the label address, instruction offset & the state offset
add r0, r0, r1
add r0, r0, r2
// Jump to the correct instruction
jump r0
ioset_state:
// RTCIO 0 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 0, 1, 1)
jump ioset_done
// RTCIO 0 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 0, 1, 1)
jump ioset_done
// RTCIO 1 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 1, 1, 1)
jump ioset_done
// RTCIO 1 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 1, 1, 1)
jump ioset_done
// RTCIO 2 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 2, 1, 1)
jump ioset_done
// RTCIO 2 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 2, 1, 1)
jump ioset_done
// RTCIO 3 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 3, 1, 1)
jump ioset_done
// RTCIO 3 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 3, 1, 1)
jump ioset_done
// RTCIO 4 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 4, 1, 1)
jump ioset_done
// RTCIO 4 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 4, 1, 1)
jump ioset_done
// RTCIO 5 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 5, 1, 1)
jump ioset_done
// RTCIO 5 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 5, 1, 1)
jump ioset_done
// RTCIO 6 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 6, 1, 1)
jump ioset_done
// RTCIO 6 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 6, 1, 1)
jump ioset_done
// RTCIO 7 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 7, 1, 1)
jump ioset_done
// RTCIO 7 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 7, 1, 1)
jump ioset_done
// RTCIO 8 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 8, 1, 1)
jump ioset_done
// RTCIO 8 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 8, 1, 1)
jump ioset_done
// RTCIO 9 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 9, 1, 1)
jump ioset_done
// RTCIO 9 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 9, 1, 1)
jump ioset_done
// RTCIO 10 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 10, 1, 1)
jump ioset_done
// RTCIO 10 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 10, 1, 1)
jump ioset_done
// RTCIO 11 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 11, 1, 1)
jump ioset_done
// RTCIO 11 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 11, 1, 1)
jump ioset_done
// RTCIO 12 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 12, 1, 1)
jump ioset_done
// RTCIO 12 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 12, 1, 1)
jump ioset_done
// RTCIO 13 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 13, 1, 1)
jump ioset_done
// RTCIO 13 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 13, 1, 1)
jump ioset_done
// RTCIO 14 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 14, 1, 1)
jump ioset_done
// RTCIO 14 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 14, 1, 1)
jump ioset_done
// RTCIO 15 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 15, 1, 1)
jump ioset_done
// RTCIO 15 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 15, 1, 1)
jump ioset_done
// RTCIO 16 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 16, 1, 1)
jump ioset_done
// RTCIO 16 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 16, 1, 1)
jump ioset_done
// RTCIO 17 LOW
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + 17, 1, 1)
jump ioset_done
// RTCIO 17 HIGH
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + 17, 1, 1)
jump ioset_done
ioset_done:
.endm //ioset
From my limited testing on pins 10, 11, 17, it seems to work fine and the rest of the program runs as expected as well.
Who knows if this is the best way of doing it. Macros of course have readability disadvantages (and will override registers if you aren't careful), but I believe this to be the only good option for my use case.