A followup question: I have been trying to rewrite the code directly in assembly to gain however much efficiency that will give me, but I'm having a little trouble converting the code to assembly.
I have been trying to more or less transfer it from the assembly dump of the original C code, but I have yet to figure out how to properly store the memory location of the port status.
Here's what I have so far:
volatile uint32_t *port = &(g_APinDescription[22].pPort -> PIO_PDSR);
byte sending;
uint32_t mask = g_APinDescription[22].ulPin;
void setup() {
// put your setup code here, to run once:
pinMode(22, INPUT);
Serial.begin(250000);
}
void loop() {
// put your main code here, to run repeatedly:
__asm__ volatile( "LDR R0, [%0]\n\t" ::"r"(&mask));
__asm__ volatile( "LDR R6, [%0]\n\t" ::"r"(&sending));
__asm__ volatile( "LDR R2, %0\n\t" ::"m"(g_APinDescription[22].pPort -> PIO_PDSR));
while(1)
{
__asm__ volatile( "LDR R1, [R2]\n\t");
__asm__ volatile( "TST R1, R0\n\t");
__asm__ volatile( "ITE EQ\n\t");
__asm__ volatile( "ORREQ R6, #0\n\t");
__asm__ volatile( "ORRNE R6, #128\n\t");
.
.
.
.
__asm__ volatile( "STRB R6, [%0]\n\t" ::"r"(&sending));
Serial.println(sending, BIN);
__asm__ volatile( "MOV R6, #0\n\t");
sending = 0;
}
}
But it's not working the same way as the original C code from the first post.
I have tested all of the elements of this code and the one that is causing the issue is the line:
__asm__ volatile( "LDR R2, %0\n\t" ::"m"(g_APinDescription[22].pPort -> PIO_PDSR));
How do I properly reference this to have the same functionality as the original C code?
Thanks for your help
Refernce: IAR inline assembly using global C variable - Stack Overflow