Defines | |
| #define | CPU_USE_GENERIC_BITFIELD_CODE TRUE |
| #define | CPU_USE_GENERIC_BITFIELD_DATA TRUE |
| #define | _CPU_Bitfield_Find_first_bit(_value, _output) |
| #define | _CPU_Priority_bits_index(_priority) (_priority) |
| #define _CPU_Bitfield_Find_first_bit | ( | _value, | |||
| _output | ) |
Value:
{ \
(_output) = 0; /* do something to prevent warnings */ \
}
There are a number of variables in using a "find first bit" type instruction.
RTEMS guarantees that (1) will never happen so it is not a concern. (2),(3), (4) are handled by the macros _CPU_Priority_Mask and _CPU_Priority_bits_index. These three form a set of routines which must logically operate together. Bits in the _value are set and cleared based on masks built by _CPU_Priority_Mask. The basic major and minor values calculated by _Priority_Major and _Priority_Minor are "massaged" by _CPU_Priority_bits_index to properly range between the values returned by the "find first bit" instruction. This makes it possible for _Priority_Get_highest to calculate the major and directly index into the minor table. This mapping is necessary to ensure that 0 (a high priority major/minor) is the first bit found.
This entire "find first bit" and mapping process depends heavily on the manner in which a priority is broken into a major and minor components with the major being the 4 MSB of a priority and minor the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest priority. And (15 << 4) + 14 corresponds to priority 254 -- the next to the lowest priority.
If your CPU does not have a "find first bit" instruction, then there are ways to make do without it. Here are a handful of ways to implement this in software:
- a series of 16 bit test instructions
- a "binary search using if's"
- _number = 0
if _value > 0x00ff
_value >>=8
_number = 8;
if _value > 0x0000f
_value >=8
_number += 4
_number += bit_set_table[ _value ]
where bit_set_table[ 16 ] has values which indicate the first bit set
| [in] | _value | is the value to be scanned |
| [in] | _output | is the first bit set |
XXX document implementation including references if appropriate
| #define _CPU_Priority_bits_index | ( | _priority | ) | (_priority) |
This routine translates the bit numbers returned by _CPU_Bitfield_Find_first_bit into something suitable for use as a major or minor component of a priority. See the discussion for that routine.
| [in] | _priority | is the major or minor number to translate |
XXX document implementation including references if appropriate
| #define CPU_USE_GENERIC_BITFIELD_CODE TRUE |
This definition is set to TRUE if the port uses the generic bitfield manipulation implementation.
| #define CPU_USE_GENERIC_BITFIELD_DATA TRUE |
This definition is set to TRUE if the port uses the data tables provided by the generic bitfield manipulation implementation. This can occur when actually using the generic bitfield manipulation implementation or when implementing the same algorithm in assembly language for improved performance. It is unlikely that a port will use the data if it has a bitfield scan instruction.
1.5.6