Code: Select all
RTC_NOINIT_ATTR uint16_t FSM_Data[18]; //RTC RAM offset = 0B; FSM_Data[0-15] Data stack; FSM_Data[16] CMD read/write; FSM_Data[17] Data read
void FSM_Stack_Function(){ //RTC ULP-FSM offset = 64B
uint16_t a, b; //R0, R1
while(1){ //LOOP
a = FSM_Data[16];
if(a & 0x8000){ //write
a = a & 0xFF; //8bit data
FSM_Data[16] = 0; //clear flag
FSM_Data[15] = FSM_Data[14]; FSM_Data[14] = FSM_Data[13]; FSM_Data[13] = FSM_Data[12]; FSM_Data[12] = FSM_Data[11]; //copy [a] = [a-1]
FSM_Data[11] = FSM_Data[10]; FSM_Data[10] = FSM_Data[9]; FSM_Data[9] = FSM_Data[8]; FSM_Data[8] = FSM_Data[7];
FSM_Data[7] = FSM_Data[6]; FSM_Data[6] = FSM_Data[5]; FSM_Data[5] = FSM_Data[4]; FSM_Data[4] = FSM_Data[3];
FSM_Data[3] = FSM_Data[2]; FSM_Data[2] = FSM_Data[1]; FSM_Data[1] = FSM_Data[0];
FSM_Data[0] = a;
}else if(a & 0x4000){ //read
a = a & 0x0F; //4bit address
FSM_Data[17] = FSM_Data[a]; //read
FSM_Data[16] = 0; //clear flag
while(a > 0){
b = a; a--;
FSM_Data[b] = FSM_Data[a]; //copy [a] = [a-1]
}
FSM_Data[0] = FSM_Data[17];
}
}
}