Forum > Embedded - ARM

Raspberry Pi Pico and Freepascal

<< < (8/8)

VisualLab:
I purchased an RPi Pico clone (RP2040-Plus) a week ago. And I've been browsing the Raspberry Pi Pico SDK for a few days now. In the header file address_mapped.h in the directory (relative path): ... \pico-sdk-master\src \rp2_common\hardware_base\include\hardware, I came across a line of code:


--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---*(io_rw_32 *) hw_set_alias_untyped((volatile void *) addr) = mask;
The file address_mapped.h is available at: https://raspberrypi.github.io/pico-sdk-doxygen/address__mapped_8h_source.html. The quoted line comes from the function: hw_set_bits. Its code is:


--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---__force_inline static void hw_set_bits(io_rw_32 *addr, uint32_t mask) {    *(io_rw_32 *) hw_set_alias_untyped((volatile void *) addr) = mask;}
This line has a macro named "hw_set_alias_untyped" (located in the same file). The question is: to "what" is assigned the value of "mask" argument?

On the left side there is a macro "hw_set_alias_untyped" which will be replaced with: "((uintptr_t) (addr))". After its substitution and expansion, the following expression will appear (unless I made a mistake):


--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---*(io_rw_32 *) ((uintptr_t)(volatile void *) addr) = mask;
The argument "addr" is the address of register RP2040, mapped to memory. This address ("addr") is cast to the amorphous pointer ("volatile void *") and then to the pointer "uintptr_t" (again: unless I made a mistake). To make the analysis easier, I simplified it to:


--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---macro_result = ((uintptr_t)(volatile void *) addr) // simplification that I mean*(io_rw_32 *) macro_result = mask; // the resulting expression after simplification
Is the macro output some "anonymous variable" (no name)? Is the left part of the expression a dereference of a pointer of type "io_rw_32" whose content is computed from this expression? Does this mean that the contents of the "mask" argument are assigned to "that something" that arises after dereference?

Navigation

[0] Message Index

[*] Previous page

Go to full version