Volatile variables in Oberon
Dear All, In Oberon, do we have a way to specify, if a variable is volatile? If not, how do we work around for such a need? With thanks and best regards, Yours sincerely, Srinivas Nayak Home: http://www.mathmeth.com/sn/ Blog: http://srinivas-nayak.blogspot.in/
If by volatile you mean "In computer programming <https://en.wikipedia.org/wiki/Computer_programming>, particularly in the C <https://en.wikipedia.org/wiki/C_%28programming_language%29>, C++ <https://en.wikipedia.org/wiki/C%2B%2B>, C# <https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29>, and Java <https://en.wikipedia.org/wiki/Java_%28programming_language%29> programming languages <https://en.wikipedia.org/wiki/Programming_language>, the *volatile* keyword <https://en.wikipedia.org/wiki/Keyword_%28computer_programming%29> indicates that a value <https://en.wikipedia.org/wiki/Value_%28computer_science%29> may change between different accesses, even if it does not appear to be modified. This keyword prevents an optimizing compiler <https://en.wikipedia.org/wiki/Optimizing_compiler> from optimizing away subsequent reads or writes and thus incorrectly reusing a stale value or omitting writes. Volatile values primarily arise in hardware access (memory-mapped I/O <https://en.wikipedia.org/wiki/Memory-mapped_I/O>), where reading from or writing to memory is used to communicate with peripheral devices <https://en.wikipedia.org/wiki/Peripheral_device>, and in threading <https://en.wikipedia.org/wiki/Thread_%28computing%29>, where a different thread may have modified a value." Then I would say any variable, x, exported from a module m as read only, m.x-, would be nonvolatile to modules external to m. A call to any procedure m.p could, of course, change the value of m.x. The Oberon language (at least to my knowledge) does not support the concept volatile. What is the need driving your question? -Doug Danforth On 7/28/2016 9:27 AM, Srinivas Nayak wrote:
Dear All,
In Oberon, do we have a way to specify, if a variable is volatile? If not, how do we work around for such a need?
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Srinivas Nayak Sent: Friday, 29 July 2016 1:57 AM To: ETH Oberon and related systems Subject: [Oberon] Volatile variables in Oberon
In Oberon, do we have a way to specify, if a variable is volatile? If not, how do we work around for such a need?
I cannot think of a situation where you would need to specify that a variable is volatile when using Oberon-07. Can you think of one? This constraint is typically only required on systems that implement unsafe optimisations and variables that are mapped to peripheral registers. Regards, Chris Burrows CFB Software http://www.astrobe.com
Chris wrote:
I cannot think of a situation where you would need to specify that a variable is volatile when using Oberon-07. Can you think of one?
Yes I can. If a variable is mapped to a register which can be changed "from the other end" then it is volatile.
This constraint is typically only required on systems that implement unsafe optimisations and variables that are mapped to peripheral registers.
I am not sure of optimizations. But register mapping is the gist of programming the FPGA. I would rephrase the question: how do we handle memory-mapped registers whose value can change at any time? Regards, Wojtek
-----Original Message----- From: Skulski, Wojciech [mailto:skulski@pas.rochester.edu] Sent: Saturday, 30 July 2016 12:27 PM To: chris@cfbsoftware.com; ETH Oberon and related systems Subject: RE: [Oberon] Volatile variables in Oberon
Chris wrote:
I cannot think of a situation where you would need to specify that a variable is volatile when using Oberon-07. Can you think of one?
Yes I can. If a variable is mapped to a register which can be changed "from the other end" then it is volatile.
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. Regards, Chris Burrows CFB Software http://www.cfbsoftware.com
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
From very old memory, I think that Modula-2 had a construct to allow reading and writing from absolute memory addresses. I don't know if a Wirth compiler had this, or if it was from someone else.
Something similar to VAR memmap [ 100B ] : ARRAY 3 OF INTEGER; On Sat, Jul 30, 2016 at 1:06 AM, Skulski, Wojciech < skulski@pas.rochester.edu> 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@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- (email is my preferred communication media) Aubrey McIntosh, Ph.D. 1502 Devon Circle Austin TX 78723-1814 (512)-348-7401
-----Original Message----- From: Skulski, Wojciech [mailto:skulski@pas.rochester.edu] Sent: Saturday, 30 July 2016 3:36 PM To: chris@cfbsoftware.com; ETH Oberon and related systems Subject: RE: [Oberon] Volatile variables in Oberon
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?
Modula-2 has a feature like that. It is described as a 'loophole' in Wirth's paper 'Good Ideas, Through the Looking Glass'. The benefit of using SYSTEM.PUT and SYSTEM.GET is that it clearly distinguishes *where the operation is performed* that this is not the usual form of variable access. Regards, Chris.
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@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
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@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@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Joerg: thank you. This is nice. Let's talk of an array. The array access will be done the same way by stepping "c" in a loop. Since I am using SYSTEM, it has to be done inside a "low level module". Now imagine I want to use my array in a high-level code. Imagine, that I have developed a nice module DSP.Mod of DSP functions. For example, I want to find some features in the array, like for example impulses. I have my own favorite algorithm. I wrote a function DSP.FindPeaks (arr: ArrayPTR). Now I need to pass the array to the function FindPeaks. So I export the array from the low-level module, and I use the array as an argument to FindPeaks. Great! I notice that the export is read-only. No problem. Now in my DSP.FindPeaks I have a FOR loop. I access the array element like this: tmp := arr [i]; Ooops. I cannot do this because I must access the array with GET. No problem. In the low-level module I make a copy of the volatile array to a regular Oberon array which I export to be used in DSP.FindPeaks. Ooops. My waveform is 32k samples. So I must copy 32k integers in order to use the array in my high level function. It is inefficient. An efficient algorithm needs to be performed without copying the array. But how can I implement the high-level algorithm, if I cannot access the array elements in the high-level code in the first place? What am I missing? Wojtek ----------------------------------------- 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@saanlima.com<mailto:magnus@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@lists.inf.ethz.ch<mailto:Oberon@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=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=> -- Oberon@lists.inf.ethz.ch<mailto:Oberon@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=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=>
Wojtek Your low-level module looks something like that MODULE DSP: IMPORT SYSTEM; CONST ArraySize* = 32 TYPE Array* = POINTER TO RECORD a: ARRAY ArraySize OF INTEGER END; VAR a*: Array; BEGIN a := SYSTEM.VAL(Array, 32400H) END DSP. Your super-duper algo in high level (with our SYSTEM) PROCEDURE FindPeaks(arr: DSP.Array); VAR i, tmp: INTEGER; BEGIN FOR i := 0 TO 31 DO tmp := arr.a[i] (* do clever things with tmp *) END END FindPeaks; and call it with FindPeaks(DSP.a) Jörg
Am 01.08.2016 um 07:37 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
thank you. This is nice.
Let's talk of an array. The array access will be done the same way by stepping "c" in a loop. Since I am using SYSTEM, it has to be done inside a "low level module".
Now imagine I want to use my array in a high-level code. Imagine, that I have developed a nice module DSP.Mod of DSP functions. For example, I want to find some features in the array, like for example impulses. I have my own favorite algorithm. I wrote a function DSP.FindPeaks (arr: ArrayPTR).
Now I need to pass the array to the function FindPeaks. So I export the array from the low-level module, and I use the array as an argument to FindPeaks. Great!
I notice that the export is read-only. No problem.
Now in my DSP.FindPeaks I have a FOR loop. I access the array element like this:
tmp := arr [i];
Ooops. I cannot do this because I must access the array with GET.
No problem. In the low-level module I make a copy of the volatile array to a regular Oberon array which I export to be used in DSP.FindPeaks.
Ooops. My waveform is 32k samples. So I must copy 32k integers in order to use the array in my high level function. It is inefficient.
An efficient algorithm needs to be performed without copying the array. But how can I implement the high-level algorithm, if I cannot access the array elements in the high-level code in the first place?
What am I missing?
Wojtek -----------------------------------------
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@saanlima.com<mailto:magnus@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@lists.inf.ethz.ch<mailto:Oberon@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=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=>
-- Oberon@lists.inf.ethz.ch<mailto:Oberon@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=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Joerg: are you saying that the only penalty is that SYSTEM is on the import list, but otherwise the module is high level, and I can access the array as usual? If so then it looks very good to me. I must admit that I feel quite confused. If the solution is that simple, then why do we need PUT and GET? Thank you, Wojtek ________________________________________ From: Oberon [oberon-bounces@lists.inf.ethz.ch] on behalf of Joerg [joerg.straube@iaeth.ch] Sent: Monday, August 1, 2016 3:14 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Volatile variables in Oberon Wojtek Your low-level module looks something like that MODULE DSP: IMPORT SYSTEM; CONST ArraySize* = 32 TYPE Array* = POINTER TO RECORD a: ARRAY ArraySize OF INTEGER END; VAR a*: Array; BEGIN a := SYSTEM.VAL(Array, 32400H) END DSP. Your super-duper algo in high level (with our SYSTEM) PROCEDURE FindPeaks(arr: DSP.Array); VAR i, tmp: INTEGER; BEGIN FOR i := 0 TO 31 DO tmp := arr.a[i] (* do clever things with tmp *) END END FindPeaks; and call it with FindPeaks(DSP.a) Jörg
Am 01.08.2016 um 07:37 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
thank you. This is nice.
Let's talk of an array. The array access will be done the same way by stepping "c" in a loop. Since I am using SYSTEM, it has to be done inside a "low level module".
Now imagine I want to use my array in a high-level code. Imagine, that I have developed a nice module DSP.Mod of DSP functions. For example, I want to find some features in the array, like for example impulses. I have my own favorite algorithm. I wrote a function DSP.FindPeaks (arr: ArrayPTR).
Now I need to pass the array to the function FindPeaks. So I export the array from the low-level module, and I use the array as an argument to FindPeaks. Great!
I notice that the export is read-only. No problem.
Now in my DSP.FindPeaks I have a FOR loop. I access the array element like this:
tmp := arr [i];
Ooops. I cannot do this because I must access the array with GET.
No problem. In the low-level module I make a copy of the volatile array to a regular Oberon array which I export to be used in DSP.FindPeaks.
Ooops. My waveform is 32k samples. So I must copy 32k integers in order to use the array in my high level function. It is inefficient.
An efficient algorithm needs to be performed without copying the array. But how can I implement the high-level algorithm, if I cannot access the array elements in the high-level code in the first place?
What am I missing?
Wojtek -----------------------------------------
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@saanlima.com<mailto:magnus@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@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=>
-- Oberon@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e=
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e=
Joerg: I misunderstood the comment "with our SYSTEM". It probably should have been "without SYSTEM". Your solution looks ingenious to me, and also very tricky. It is basically a pointer manipulation like in C. (Are we getting close to pointer arithmetic?) Thinking of it a bit more, I would never think of this solution because I still remember that a high level Oberon array carries the hidden memory tag. But here it looks like you are assigning a starting address to the array, which is very much like C. Does it mean that the Oberon-07 records and arrays are [untagged] in the sense of Component Pascal? If so then Oberon-07 arrays would be close to C arrays. How are the runtime type guards handled without the hidden tags? Wojtek ________________________________________ From: Skulski, Wojciech Sent: Monday, August 1, 2016 4:33 AM To: ETH Oberon and related systems Subject: RE: [Oberon] Volatile variables in Oberon Joerg: are you saying that the only penalty is that SYSTEM is on the import list, but otherwise the module is high level, and I can access the array as usual? If so then it looks very good to me. I must admit that I feel quite confused. If the solution is that simple, then why do we need PUT and GET? Thank you, Wojtek ________________________________________ From: Oberon [oberon-bounces@lists.inf.ethz.ch] on behalf of Joerg [joerg.straube@iaeth.ch] Sent: Monday, August 1, 2016 3:14 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Volatile variables in Oberon Wojtek Your low-level module looks something like that MODULE DSP: IMPORT SYSTEM; CONST ArraySize* = 32 TYPE Array* = POINTER TO RECORD a: ARRAY ArraySize OF INTEGER END; VAR a*: Array; BEGIN a := SYSTEM.VAL(Array, 32400H) END DSP. Your super-duper algo in high level (with our SYSTEM) PROCEDURE FindPeaks(arr: DSP.Array); VAR i, tmp: INTEGER; BEGIN FOR i := 0 TO 31 DO tmp := arr.a[i] (* do clever things with tmp *) END END FindPeaks; and call it with FindPeaks(DSP.a) Jörg
Am 01.08.2016 um 07:37 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
thank you. This is nice.
Let's talk of an array. The array access will be done the same way by stepping "c" in a loop. Since I am using SYSTEM, it has to be done inside a "low level module".
Now imagine I want to use my array in a high-level code. Imagine, that I have developed a nice module DSP.Mod of DSP functions. For example, I want to find some features in the array, like for example impulses. I have my own favorite algorithm. I wrote a function DSP.FindPeaks (arr: ArrayPTR).
Now I need to pass the array to the function FindPeaks. So I export the array from the low-level module, and I use the array as an argument to FindPeaks. Great!
I notice that the export is read-only. No problem.
Now in my DSP.FindPeaks I have a FOR loop. I access the array element like this:
tmp := arr [i];
Ooops. I cannot do this because I must access the array with GET.
No problem. In the low-level module I make a copy of the volatile array to a regular Oberon array which I export to be used in DSP.FindPeaks.
Ooops. My waveform is 32k samples. So I must copy 32k integers in order to use the array in my high level function. It is inefficient.
An efficient algorithm needs to be performed without copying the array. But how can I implement the high-level algorithm, if I cannot access the array elements in the high-level code in the first place?
What am I missing?
Wojtek -----------------------------------------
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@saanlima.com<mailto:magnus@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@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=>
-- Oberon@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e=
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e=
implementation wise the type tag is "before" the data. if the data starts at position 0, the type tag is at position -4. but if you write your code with this kind of knowledge, you are really low kevel (either you write a compiler or debugger..). Jörg
Am 01.08.2016 um 10:51 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
I misunderstood the comment "with our SYSTEM". It probably should have been "without SYSTEM".
Your solution looks ingenious to me, and also very tricky. It is basically a pointer manipulation like in C. (Are we getting close to pointer arithmetic?)
Thinking of it a bit more, I would never think of this solution because I still remember that a high level Oberon array carries the hidden memory tag. But here it looks like you are assigning a starting address to the array, which is very much like C.
Does it mean that the Oberon-07 records and arrays are [untagged] in the sense of Component Pascal? If so then Oberon-07 arrays would be close to C arrays.
How are the runtime type guards handled without the hidden tags?
Wojtek ________________________________________ From: Skulski, Wojciech Sent: Monday, August 1, 2016 4:33 AM To: ETH Oberon and related systems Subject: RE: [Oberon] Volatile variables in Oberon
Joerg:
are you saying that the only penalty is that SYSTEM is on the import list, but otherwise the module is high level, and I can access the array as usual?
If so then it looks very good to me.
I must admit that I feel quite confused. If the solution is that simple, then why do we need PUT and GET?
Thank you, Wojtek ________________________________________ From: Oberon [oberon-bounces@lists.inf.ethz.ch] on behalf of Joerg [joerg.straube@iaeth.ch] Sent: Monday, August 1, 2016 3:14 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Volatile variables in Oberon
Wojtek
Your low-level module looks something like that
MODULE DSP: IMPORT SYSTEM; CONST ArraySize* = 32 TYPE Array* = POINTER TO RECORD a: ARRAY ArraySize OF INTEGER END; VAR a*: Array; BEGIN a := SYSTEM.VAL(Array, 32400H) END DSP.
Your super-duper algo in high level (with our SYSTEM) PROCEDURE FindPeaks(arr: DSP.Array); VAR i, tmp: INTEGER; BEGIN FOR i := 0 TO 31 DO tmp := arr.a[i] (* do clever things with tmp *) END END FindPeaks;
and call it with FindPeaks(DSP.a)
Jörg
Am 01.08.2016 um 07:37 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
thank you. This is nice.
Let's talk of an array. The array access will be done the same way by stepping "c" in a loop. Since I am using SYSTEM, it has to be done inside a "low level module".
Now imagine I want to use my array in a high-level code. Imagine, that I have developed a nice module DSP.Mod of DSP functions. For example, I want to find some features in the array, like for example impulses. I have my own favorite algorithm. I wrote a function DSP.FindPeaks (arr: ArrayPTR).
Now I need to pass the array to the function FindPeaks. So I export the array from the low-level module, and I use the array as an argument to FindPeaks. Great!
I notice that the export is read-only. No problem.
Now in my DSP.FindPeaks I have a FOR loop. I access the array element like this:
tmp := arr [i];
Ooops. I cannot do this because I must access the array with GET.
No problem. In the low-level module I make a copy of the volatile array to a regular Oberon array which I export to be used in DSP.FindPeaks.
Ooops. My waveform is 32k samples. So I must copy 32k integers in order to use the array in my high level function. It is inefficient.
An efficient algorithm needs to be performed without copying the array. But how can I implement the high-level algorithm, if I cannot access the array elements in the high-level code in the first place?
What am I missing?
Wojtek -----------------------------------------
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@saanlima.com<mailto:magnus@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@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=>
-- Oberon@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e=
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi Wojciech,
a high level Oberon array carries the hidden memory tag.
Yes, but as far as I know all recent implementation have the hidden type tags at negative address offsets. You must know these implementation details and you are absolutely correct that these are dirty tricks. Therefore the IMPORT SYSTEM is essential, but I think these tricks are essential for hardware programming. -- Bernhard
Joerg and Bernhard: thank you for the very helpful discussion. I duly saved your e-mails for future reference. I would not decipher these tricks from the SYSTEM description in the language report. Your insight was very helpful. I quickly scanned the Project Oberon from the NW website looking for implementation hints which you outlined. I did not find this discussion anywhere (excuse me if I skipped it). The NW book does not go into this level of implementation detail. I would be great if a short app note was available illustrating HW access via volatile memory structures using your examples. Thank you for your help. Wojtek ________________________________________ From: Treutwein Bernhard [Bernhard.Treutwein@Verwaltung.Uni-Muenchen.DE] Sent: Monday, August 1, 2016 6:46 AM To: 'ETH Oberon and related systems' Subject: RE: [Oberon] Volatile variables in Oberon Hi Wojciech,
a high level Oberon array carries the hidden memory tag.
Yes, but as far as I know all recent implementation have the hidden type tags at negative address offsets. You must know these implementation details and you are absolutely correct that these are dirty tricks. Therefore the IMPORT SYSTEM is essential, but I think these tricks are essential for hardware programming. -- Bernhard
In general importing SYSTEM is just a hint that you use low level functions that are not guaranteed to be portable. I mean the address I'm using in my example does not do something useful on my machine but on your FPGA it might. If address assignment to a variable would be part of the language (without using SYSTEM) you could compile your code and wonder why it doesn't work on your machine. Whenever there is SYSTEM in the import list you know: watch out when porting this code to another machine/environment. Whether you use SYSTEM.GET or address assignment via SYSTEM.VAL is a case by case decision. Jörg
Am 01.08.2016 um 10:33 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
are you saying that the only penalty is that SYSTEM is on the import list, but otherwise the module is high level, and I can access the array as usual?
If so then it looks very good to me.
I must admit that I feel quite confused. If the solution is that simple, then why do we need PUT and GET?
Thank you, Wojtek ________________________________________ From: Oberon [oberon-bounces@lists.inf.ethz.ch] on behalf of Joerg [joerg.straube@iaeth.ch] Sent: Monday, August 1, 2016 3:14 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Volatile variables in Oberon
Wojtek
Your low-level module looks something like that
MODULE DSP: IMPORT SYSTEM; CONST ArraySize* = 32 TYPE Array* = POINTER TO RECORD a: ARRAY ArraySize OF INTEGER END; VAR a*: Array; BEGIN a := SYSTEM.VAL(Array, 32400H) END DSP.
Your super-duper algo in high level (with our SYSTEM) PROCEDURE FindPeaks(arr: DSP.Array); VAR i, tmp: INTEGER; BEGIN FOR i := 0 TO 31 DO tmp := arr.a[i] (* do clever things with tmp *) END END FindPeaks;
and call it with FindPeaks(DSP.a)
Jörg
Am 01.08.2016 um 07:37 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Joerg:
thank you. This is nice.
Let's talk of an array. The array access will be done the same way by stepping "c" in a loop. Since I am using SYSTEM, it has to be done inside a "low level module".
Now imagine I want to use my array in a high-level code. Imagine, that I have developed a nice module DSP.Mod of DSP functions. For example, I want to find some features in the array, like for example impulses. I have my own favorite algorithm. I wrote a function DSP.FindPeaks (arr: ArrayPTR).
Now I need to pass the array to the function FindPeaks. So I export the array from the low-level module, and I use the array as an argument to FindPeaks. Great!
I notice that the export is read-only. No problem.
Now in my DSP.FindPeaks I have a FOR loop. I access the array element like this:
tmp := arr [i];
Ooops. I cannot do this because I must access the array with GET.
No problem. In the low-level module I make a copy of the volatile array to a regular Oberon array which I export to be used in DSP.FindPeaks.
Ooops. My waveform is 32k samples. So I must copy 32k integers in order to use the array in my high level function. It is inefficient.
An efficient algorithm needs to be performed without copying the array. But how can I implement the high-level algorithm, if I cannot access the array elements in the high-level code in the first place?
What am I missing?
Wojtek -----------------------------------------
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@saanlima.com<mailto:magnus@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@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=>
-- Oberon@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwMFaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bitBRpmXOMbIlH-tyDdfNX20KHa96OvM7K3v7PfbD1Y&s=tNIIZKSzd6zd8FsW_rRVPFPr5almnnjplw034cryWwc&e=> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e=
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=CwIFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=bwcNzK3igbLTc51joi2ukqQAKwoCpVw8KST4sPDO23k&s=XwMAdQD5p1fahnD99NTes2a0RZ-HK2lAFQ0oQhvhwjY&e= -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
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@lists.inf.ethz.ch<mailto:Oberon@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=>
Wojtek If you really want a memory-mapped variable you could do it e.g. as follows - - - TYPE MemoryMapped = POINTER TO INTEGER; VAR p: MemoryMapped; BEGIN p := SYSTEM.VAL(MemoryMapped, 0E7F00H) (* assign address of memory to variable *) WHILE p^ # 0 DO END; END - - - But as Chris mentioned the „usual" way in Oberon to do the same is as follows: - - - VAR i: INTEGER; BEGIN SYSTEM.GET(0E7F00H, i); WHILE i # 0 DO SYSTEM.Get(0E7F00H, i) END; END - - - But we don’t have to mark „p" as „volatile" as the Oberon compiler does no optimization. If the compiler generates code for the WHILE loop, and would see „oh, „p" is not changed in the loop so I load „p" to register R3 only once and just check R3", this optimized code would fail in case p is a memory mapped variable. Then you have to mark „p“ as volatile, as hint for the compiler to re-load the value every time. But the Oberon compiler does not do such kind of optimizations and loads the value of „p" every time. So no „volatile" needed in Oberon. Jörg
Am 30.07.2016 um 04:57 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Chris wrote:
I cannot think of a situation where you would need to specify that a variable is volatile when using Oberon-07. Can you think of one?
Yes I can. If a variable is mapped to a register which can be changed "from the other end" then it is volatile.
This constraint is typically only required on systems that implement unsafe optimisations and variables that are mapped to peripheral registers.
I am not sure of optimizations. But register mapping is the gist of programming the FPGA.
I would rephrase the question: how do we handle memory-mapped registers whose value can change at any time?
Regards, Wojtek -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
But the Oberon compiler does not do such kind of optimizations and loads the value of p" every time. So no volatile" needed in Oberon.
Jörg
This answers the question nicely. With thanks and best regards, Yours sincerely, Srinivas Nayak Home: http://www.mathmeth.com/sn/ Blog: http://srinivas-nayak.blogspot.in/ On 07/30/2016 11:12 AM, Jörg Straube wrote:
Wojtek
If you really want a memory-mapped variable you could do it e.g. as follows - - - TYPE MemoryMapped = POINTER TO INTEGER; VAR p: MemoryMapped; BEGIN p := SYSTEM.VAL(MemoryMapped, 0E7F00H) (* assign address of memory to variable *) WHILE p^ # 0 DO END; END - - -
But as Chris mentioned the usual" way in Oberon to do the same is as follows: - - - VAR i: INTEGER; BEGIN SYSTEM.GET(0E7F00H, i); WHILE i # 0 DO SYSTEM.Get(0E7F00H, i) END; END - - -
But we dont have to mark p" as volatile" as the Oberon compiler does no optimization. If the compiler generates code for the WHILE loop, and would see oh, p" is not changed in the loop so I load p" to register R3 only once and just check R3", this optimized code would fail in case p is a memory mapped variable. Then you have to mark p as volatile, as hint for the compiler to re-load the value every time. But the Oberon compiler does not do such kind of optimizations and loads the value of p" every time. So no volatile" needed in Oberon.
Jörg
Am 30.07.2016 um 04:57 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Chris wrote:
I cannot think of a situation where you would need to specify that a variable is volatile when using Oberon-07. Can you think of one?
Yes I can. If a variable is mapped to a register which can be changed "from the other end" then it is volatile.
This constraint is typically only required on systems that implement unsafe optimisations and variables that are mapped to peripheral registers.
I am not sure of optimizations. But register mapping is the gist of programming the FPGA.
I would rephrase the question: how do we handle memory-mapped registers whose value can change at any time?
Regards, Wojtek -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (9)
-
Aubrey.McIntosh@alumni.utexas.net -
Chris Burrows -
Douglas G. Danforth -
Joerg -
Jörg Straube -
Magnus Karlsson -
Skulski, Wojciech -
Srinivas Nayak -
Treutwein Bernhard