This still has the semi-unused variables, and the redundant check of ptdata in the C code...
boolean getData2(uint8_t* ptdata, uint8_t* ptend) {
uint32_t st_value = 0x80000; // from EPM3064
boolean retval = true;
do {
asm volatile (
"str %[VTICPIN], [%[PIOCSODR], #0] \n\t" // set TICPIN (bit23 of PortC)
"1: \n\t" // wait for FLAG
"ldr r2, [%[PIOCSODR], #12] \n\t" // input PORTC von REG_PIOC_PDSR
"lsls r1, r2, #22 \n\t" // FLAG is bit 9 of register R2
"bpl 1b \n\t" // jump back to "1:" if FLAG=0
"lsr r2, r2, #1 \n\t" // shift right r2
"strb r2, [%[PTDAT]], #1 \n\t" // store shifted r2 to memory
// confirm read:
"str %[FLAGCLR], [%[PIODSODR], #4] \n\t" // FLAG_CLEAR low, REG_PIOD_CODR
"str %[FLAGCLR], [%[PIODSODR], #0] \n\t" // FLAG_CLEAR high, REG_PIOD_SODR
// check error flag
"lsls r1, r2, #13 \n\t" // ERROR_FLAG now (after lsr 1) is bit18 of R2
"bmi 2f \n\t" // break, end read loop
"str %[VTICPIN], [%[PIOCSODR], #4] \n\t" // clear TICPIN, REG_PIOC_CODR
"cmp %[PTEND], %[PTDAT] \n\t" // ptdata == ptend?
"bne 1b \n\t" // jump back to „1:“ for next data
"2: \n\t"
"nop"
:
: [PIOCSODR] "r" (0x400e1230), // (0x400e1230) REG_PIOC_SODR
[PIODSODR] "r" (0x400e1430), // (0x400e1430) REG_PIOD_SODR
[PTDAT] "r" (ptdata),
[PTEND] "r" (ptend),
[VTICPIN] "r" (0x00800000), // value to set/clear TICPIN
[FLAGCLR] "r" (0x400)
: "cc", "memory"
);
// check ERROR_FLAG (force break)
if (st_value & ERROR_FLAG) {
break; // end while loop
}
} while (ptdata < ptend);
return (retval);
}
And the full assembler:
000801a0 <getData2(unsigned char*, unsigned char*)>:
boolean getData2(uint8_t* ptdata, uint8_t* ptend) {
801a0: b430 push {r4, r5}
[PTDAT] "r" (ptdata),
[PTEND] "r" (ptend),
[VTICPIN] "r" (0x00800000), // value to set/clear TICPIN
[FLAGCLR] "r" (0x400)
: "cc", "memory"
);
801a2: 4d0d ldr r5, [pc, #52] ; (801d8 <getData2(unsigned char*, unsigned char*)+0x38>)
801a4: 4c0d ldr r4, [pc, #52] ; (801dc <getData2(unsigned char*, unsigned char*)+0x3c>)
801a6: f44f 0200 mov.w r2, #8388608 ; 0x800000
801aa: f44f 6380 mov.w r3, #1024 ; 0x400
801ae: 602a str r2, [r5, #0]
801b0: 68ea ldr r2, [r5, #12]
801b2: 0591 lsls r1, r2, #22
801b4: d5fc bpl.n 801b0 <getData2(unsigned char*, unsigned char*)+0x10>
801b6: ea4f 0252 mov.w r2, r2, lsr #1
801ba: f800 2b01 strb.w r2, [r0], #1
801be: 6063 str r3, [r4, #4]
801c0: 6023 str r3, [r4, #0]
801c2: 0351 lsls r1, r2, #13
801c4: d402 bmi.n 801cc <getData2(unsigned char*, unsigned char*)+0x2c>
801c6: 606a str r2, [r5, #4]
801c8: 4281 cmp r1, r0
801ca: d1f1 bne.n 801b0 <getData2(unsigned char*, unsigned char*)+0x10>
801cc: bf00 nop
do {
801ce: 4288 cmp r0, r1
801d0: d3ed bcc.n 801ae <getData2(unsigned char*, unsigned char*)+0xe>
if (st_value & ERROR_FLAG) {
break; // end while loop
}
} while (ptdata < ptend);
return (retval);
}
801d2: 2001 movs r0, #1
801d4: bc30 pop {r4, r5}
801d6: 4770 bx lr
801d8: 400e1230 .word 0x400e1230
801dc: 400e1430 .word 0x400e1430