[Oberon] Volatile variables in Oberon
Jörg Straube
joerg.straube at iaeth.ch
Sun Jul 31 19:13:38 CEST 2016
And in Oberon
VAR c: BYTE;
SYSTEM.GET(UART0UDR, c);
Have fun
Jörg
> Am 30.07.2016 um 19:00 schrieb Magnus Karlsson <magnus at saanlima.com>:
>
> 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 mailing list for ETH Oberon and related systems
>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>>
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20160731/13c96c7f/attachment.html>
More information about the Oberon
mailing list