[Oberon] Volatile variables in Oberon

Skulski, Wojciech skulski at pas.rochester.edu
Mon Aug 1 01:37:34 CEST 2016


Magnus:

thank you for your C code example. I am not a C wizard at all. I cobbled my convoluted solution after a discussion with Analog Devices software engineers. To summarize the story, after going through Linux kernel books I wanted to use memmap for interfacing with an FPGA (yes, it all revolves around the FPGA!). The engineers pointed out that under uClinux, which has no memory management, I can reach directly to the FPGA memory with pointers. My code reflected my level of understanding. Once I succeeded, I never changed my way. 

Wojtek
------------------------------------------------------------------------------

Your C code seems to a bit convoluted if just want to access a register.
This is quite often done by defining the registers as volatile pointers like this:

Register address definitions (in this case for a UART):
#define UART0_UDR      (*(volatile  uint8_t *)(0x44000000))
#define UART0_UCR      (*(volatile uint16_t *)(0x44000004))
#define UART0_UBRR     (*(volatile uint16_t *)(0x44000008))

You can then access registers like this (read UART data register):
uint8_t c = UART0_UDR;

Magnus

On 7/29/2016 11:06 PM, Skulski, Wojciech wrote:

Chris:



But Oberon variables are not mapped to registers that can be changed "from
the other end". The explicit operations SYSTEM.GET and SYSTEM.PUT are used
when you want to transfer data between a peripheral register (mapped to an
absolute memory location) and Oberon variables.



 Pardon my C on this mailing list. The point I want to make is that it is ugly.

Here is a sample of my C program where I am reading from an absolute memory location mapped to an FPGA register. The "target" is an integer, which is then used to retrieve a value from the FPGA. The address is not constant, but I can make it constant using a #define.

 long target; /* long int holds addr, needs a typecast */
 short value;
 short *virt_saddr;     /* typed pointer to 16-bit short */

 virt_saddr = (short *) target; /* convert target to pointer */
 value = * virt_saddr;            /* read value from address   */

I would prefer to write in C something like the following:

 short value at address; /* address is constant, which is most often the case*/

In Oberon it would be something like this:

 CONST address = ....;
  VAR value: INTEGER AT address; (* address must be constant*)

Now the question, is this unreasonable?

Wojtek
--
Oberon at lists.inf.ethz.ch<mailto:Oberon at lists.inf.ethz.ch> mailing list for ETH Oberon and related systems
https://lists.inf.ethz.ch/mailman/listinfo/oberon<https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMD-g&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=GdEsRimEB9m8X9OXouuVUhhgfyy3vcBesxy8skf6sCE&s=8zQGHST621GUv3jCAVjZE73PrkThNzL8OWk3QU4sbYs&e=>






More information about the Oberon mailing list