ULP处理器数据如何与主控交互数据的?

Moderator: ESP_ZT

gezhia
Posts: 38
Joined: Thu Nov 24, 2022 10:45 am

ULP处理器数据如何与主控交互数据的?

Postby gezhia » Thu Jun 22, 2023 5:01 am

根据官方提供的ULP计数例程里,主控代码里的ulp_edge_count 变量只在主控区域被引用,并没有跟ULP关联。而ULP代码里的计数变量edge_count也是跟主控代码没有任何关联。它们之间到底是如何交互数据的呢?



主控代码

Code: Select all

static void update_pulse_count(void)
{
    const char* namespace = "plusecnt";
    const char* count_key = "count";

    ESP_ERROR_CHECK( nvs_flash_init() );
    nvs_handle_t handle;
    ESP_ERROR_CHECK( nvs_open(namespace, NVS_READWRITE, &handle));
    uint32_t pulse_count = 0;
    esp_err_t err = nvs_get_u32(handle, count_key, &pulse_count);
    assert(err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND);
    printf("Read pulse count from NVS: %5d\n", (int)pulse_count);

    /* ULP program counts signal edges, convert that to the number of pulses */
    uint32_t pulse_count_from_ulp = (ulp_edge_count & UINT16_MAX) / 2;
    /* In case of an odd number of edges, keep one until next time */
    ulp_edge_count = ulp_edge_count % 2;
    printf("Pulse count from ULP: %5d\n",(int) pulse_count_from_ulp);

    /* Save the new pulse count to NVS */
    pulse_count += pulse_count_from_ulp;
    ESP_ERROR_CHECK(nvs_set_u32(handle, count_key, pulse_count));
    ESP_ERROR_CHECK(nvs_commit(handle));
    nvs_close(handle);
    printf("Wrote updated pulse count to NVS: %5d\n", (int)pulse_count);
}


ULP代码

Code: Select all

edge_detected:
	/* Reset debounce_counter to debounce_max_count */
	move r3, debounce_max_count
	move r2, debounce_counter
	ld r3, r3, 0
	st r3, r2, 0
	/* Flip next_edge */
	move r3, next_edge
	ld r2, r3, 0
	add r2, r2, 1
	and r2, r2, 1
	st r2, r3, 0
	/* Increment edge_count */
	move r3, edge_count
	ld r2, r3, 0
	add r2, r2, 1
	st r2, r3, 0
	/* Compare edge_count to edge_count_to_wake_up */
	move r3, edge_count_to_wake_up
	ld r3, r3, 0
	sub r3, r3, r2
	jump wake_up, eq
	/* Not yet. End program */
	halt

ESP_ICY
Posts: 404
Joined: Mon Aug 23, 2021 11:10 am

Re: ULP处理器数据如何与主控交互数据的?

Postby ESP_ICY » Tue Jun 27, 2023 10:06 am

https://docs.espressif.com/projects/esp ... -variables 请查看官方文档的说明,这两个是一样的变量,只不过主程序要用ULP里的变量时前面要加ulp声明

gezhia
Posts: 38
Joined: Thu Nov 24, 2022 10:45 am

Re: ULP处理器数据如何与主控交互数据的?

Postby gezhia » Fri Jun 30, 2023 3:09 am

根据这段文字意思,主控变量measurement count在ULP的头文件里声明成ulp measurement count,就可以在ULP里使用了。这么理解
是否正确?

那是否意味着主控和ULP相互之间是不知道哪个变量是共享的,如果某个共享变量名书写错误,比如主控里M_easurement_count,而ULP里写成了ulp_measurement_count,会导致变量内容无法共享,而编译运行没有任何问题?

例如,ULP RISC-V 程序可以定义 measurement_count 变量,此变量可以定义程序从深度睡眠中唤醒芯片之前需要进行的 ADC 测量的次数。

volatile int measurement_count;

int some_function()
{
//读取测量计数,后续需使用
int temp = measurement_count;

...do something.
}
构建系统生成定义 ULP 编程中全局符号的 ${ULP_APP_NAME}.h 和 ${ULP_APP_NAME}.ld 文件,使主程序能够访问全局 ULP RISC-V 程序变量。上述两个文件包含 ULP RISC-V 程序中定义的所有全局符号,且这些符号均以 ulp_ 开头。

头文件包含对此类符号的声明:

extern uint32_t ulp_measurement_count;

ESP_ICY
Posts: 404
Joined: Mon Aug 23, 2021 11:10 am

Re: ULP处理器数据如何与主控交互数据的?

Postby ESP_ICY » Mon Jul 17, 2023 11:52 am

应该说是 ULP 程序里的变量,在主程序里加上 ulp 前缀后使用

Who is online

Users browsing this forum: No registered users and 16 guests