ulp simple counter

macdeveloper
Posts: 2
Joined: Sat Feb 24, 2018 6:55 pm

ulp simple counter

Postby macdeveloper » Wed Dec 05, 2018 9:22 am

Hi to all,
I'm trying to do a simple ulp test that act as counter:
this is my ULP code:

Code: Select all

const ulp_insn_t  ulp_asm[] = {
        I_MOVI(R3, 32),         // R0 <- 32
        I_LD(R2, R3, 0),        // R1 <- RTC_SLOW_MEM[R3]
        I_ADDR(R2, R2, 1),      // R1 <- R1 + R1
        I_ST(R2, R3, 0),        // R1 -> RTC_SLOW_MEM[R3 + 0]
        I_HALT(),
  };
the c code to load program is:

Code: Select all

RTC_SLOW_MEM[32] = 10;
printf("RTC_SLOW_MEM[32] is %d\n", RTC_SLOW_MEM[32] & 0xffff);
size_t size = sizeof(ulp_asm) / sizeof(ulp_insn_t);
printf("Load ulp program of size %d...\n", size);
ulp_process_macros_and_load(0, ulp_asm, &size);
ulp_run(0);
the is have a task that run every second that print the RTC_SLOW_MEM[32] (initialised to 10 for test):

Code: Select all

void update_count(void *pvParameter) {
        printf("Show ulp hints!\n");
        for (int i = 100; i >= 0; i--) {
                printf("hit readed %d \n", RTC_SLOW_MEM[32] & 0xffff);
                vTaskDelay(1000 / portTICK_RATE_MS);
        }
        printf("Restarting now.\n");
        fflush(stdout);
        system_restart();
}
what I got is a "hit readed 10" data is never update. Someone can help me please?

thanks in advance
claudio

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: ulp simple counter

Postby ESP_igrr » Wed Dec 05, 2018 11:22 am

The mistake is in

I_ADDR(R2, R2, 1)

This should be

I_ADDI(R2, R2, 1)

Otherwise you are calculating R2=R2+R1 (1 is treated as register index), and R1 is 0.

Who is online

Users browsing this forum: No registered users and 12 guests