User manual
DSM tutorials
The channelexample project is straightforward to run in hardware, but in simulation breakpoints must be
set in each of the two parallel loops. This is necessary because otherwise the Debugger will continue to
follow the thread it is currently in, and it will not be possible to step through the code in the other thread.
By setting breakpoints on the
Circle++ and Count++ lines, it will be possible to step through the code
continuously, and see both displays operating cycle-by-cycle.
4.1.3 Bit manipulation examples
The following examples illustrate how to use the four Handel-C bit manipulation operators which are not
used in C/C++.
•
Drop operator (see page 49)
•
Take operator (see page 50)
•
Select operator (see page 50)
•
Concatenate operator (see page 51)
Drop operator
The dropexample project in the TutorialHCBasics workspace shows how to use the drop bits \\ operator.
The source code is shown below:
while (1)
{
par
{
/*
* Increment up to 15, then wrap round to 0
*/
Count++;
/*
* Write Count and Count \\ 1 to display
*/
PalSevenSegWriteDigit (PalSevenSegCT (0), Count, 0);
PalSevenSegWriteDigit (PalSevenSegCT (1), adju( (Count \\ 1), 4), 0);
}
}
The
\\ operator returns a value with the least n significant bits dropped.
The value of
Count is shown on the first 7-segment display; the second display shows Count with the
lowest bit dropped. The
adju() macro from the Standard Macro Library is used to adjust the width of
the modified value of
Count to four bits, as this is the width required to be passed to
PalSevenSegWriteDigit(). The example uses Count \\ 1 to drop a single bit, so while the first
display counts from 0 to 0xF, the second counts from 0 to 7, but at half the rate, as shown below.
Count 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Display 1 0 1 2 3 4 5 6 7 8 9 A B C D E F
Count \\ 1 000 000 001 001 010 010 011 011 100 100 101 101 110 110 111 111
Display 2 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7
DROP EXAMPLE DISPLAYS
www.celoxica.com
Page 49