ESP32-S2 ULP-FSM helps write source code

vuthai
Posts: 6
Joined: Tue Nov 28, 2023 5:00 am

ESP32-S2 ULP-FSM helps write source code

Postby vuthai » Tue Nov 28, 2023 8:10 am

Hello, I am using ESP32-S2 on Arduino and I am having difficulty writing ULP-FSM code, can anyone help me convert it to ULP-FSM code?

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];
        }
    }
}


Who is online

Users browsing this forum: Majestic-12 [Bot] and 83 guests