New SYSTEM Bitfield functions

Topics related to the use of Oberon language features
Locked
cfbsoftware
Site Admin
Posts: 405
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

New SYSTEM Bitfield functions

Post by cfbsoftware » Wed Oct 01, 2014 1:16 pm

Two new in-line SYSTEM functions in v5.2 Astrobe for Cortex-M3 and Cortex-M4 are used to efficiently extract or update a bitfield, i.e. just a portion of 32-bit word. Each efficiently uses the Thumb-2 instruction with the same name:
  • BFI: Bitfield Insert
    UBFX: Unsigned Bitfield Extract

Code: Select all

  PROCEDURE BFI*(VAR x: INTEGER; msb, lsb, y: INTEGER); 
  PROCEDURE BFI*(VAR x: INTEGER; bitNo, y: INTEGER); 

Code: Select all

  PROCEDURE UBFX*(VAR x: INTEGER; y, msb, lsb: INTEGER); 
  PROCEDURE UBFX*(VAR x: INTEGER; y, bitNo: INTEGER); 
x is the target variable and y is the source data. msb is the most-significant bit and lsb is the least-significant bit of the bitfield. If msb = lsb (i.e. only a single-bit is accessed) then the two parameters can be replaced by the single bitNo.

Examples of their use can be seen in the realtime clock (RTC) library module. The NXP LPC408x/407x User Manual shows that the hours, minutes and seconds values are each separate bitfields stored in a single-word register CTIME0:
ctime.JPG
ctime.JPG (31.69 KiB) Viewed 1645 times
Using the bit numbers shown in the information above, the following statement updates just the value of minutes stored in ctime; the values of hours and seconds remain unchanged:

Code: Select all

  SYSTEM.BFI(ctime, 13, 8, minutes);    (* ctime:13:8 := minutes *)
Conversely, the following statement extracts just the value of minutes from ctime:

Code: Select all

  SYSTEM.UBFX(minutes, ctime, 13, 8);   (* minutes := ctime:13:8 *)

Locked