[Oberon] FPGA - Bitfield operations

Jörg joerg.straube at iaeth.ch
Thu Aug 16 15:10:16 CEST 2018


Chris

My Pack() would be:
  ctime := ss + 100H * mm + 1000H* hh;

Jörg

Am 16.08.18, 14:52 schrieb "Oberon im Auftrag von Chris Burrows" <oberon-bounces at lists.inf.ethz.ch im Auftrag von chris at cfbsoftware.com>:

    > 
    > From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
    > Jan de Kruyf
    > Sent: Thursday, 16 August 2018 7:23 PM
    > To: ETH Oberon and related systems
    > Subject: Re: [Oberon] FPGA - Simple OOP example
    > 
    > For Oberon to be a real alternative I would minimally need:
    > 1. single bit variables.
    > 2. packed arrays of those.
    > 3. if at all possible multi bit variables (2, 3, 4, 5 etc.) 
    > 4. packed
    > records of single and multi bit variables.
    > 
    
    I have also been thinking about ways to implement the very same set of features. E.g. something similar to the way PACKED RECORDS works with subranges in Pascal but with some finer control over alignment and endian issues etc. 
    
    Two aspects of programming the ARM Cortex-M devices have triggered these thoughts:
    
    1. Microcontroller designers cram many different values of different data types into a single 32-bit word. This requires many packing / unpacking / type casting operations to get at the values.
    
    2. The 'Thumb-2' instruction set used in the ARM Cortex-M3, M4 and M7 microcontrollers has efficient 'bitfield' instructions. 
    
    So far I just have used the simplest approach by implementing these instructions directly as SYSTEM functions. SYSTEM.BFI is Bitfield Insert and SYSTEM.UBFX is Unsigned Bitfield extract. The following examples illustrate this. E.g. hours are stored in a time variable as a 5-bit value in bits 20..16
    
    PROCEDURE* Pack*(hh, mm, ss: INTEGER; VAR ctime: INTEGER);
    VAR
      t: INTEGER;
    BEGIN
      t := ss;
      SYSTEM.BFI(t, 13, 8, mm); 
      SYSTEM.BFI(t, 20, 16, hh);
      ctime := t
    END Pack;
    
    PROCEDURE* Unpack*(ctime: INTEGER; VAR hh, mm, ss: INTEGER);
    BEGIN
      SYSTEM.UBFX(ss, ctime, 5, 0);
      SYSTEM.UBFX(mm, ctime, 13, 8); 
      SYSTEM.UBFX(hh, ctime, 20, 16) 
    END Unpack; 
    
    In case you are wondering the missing bits 6, 7, 14, 15, 21, 22, 23 and 27..31 are reserved and bits 26..24 represent the day of the week (0..6)!
    
    I hope to have some more to say on this subject in the not too distant future ...
    
    Regards,
    Chris
    
    Chris Burrows
    CFB Software
    http://www.astrobe.com/RISC5
    
    
    
    --
    Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
    https://lists.inf.ethz.ch/mailman/listinfo/oberon
    




More information about the Oberon mailing list