Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's a bitwise <code>or</code>, as distinct to your normal logical <code>or</code>. It basically sets the bits in the target variable if the corresponding bit in either of the source variables was set.</p> <p>For example, the expression <code>43 | 17</code> can be calculated as:</p> <pre><code>43 = 0x2b = binary 0010 1011 17 = 0x11 = binary 0001 0001 ==== ==== "or" them: 0011 1011 = 0x3b = 59 </code></pre> <p>See <a href="https://stackoverflow.com/questions/1746613/bitwise-operation-and-usage/1746642#1746642">this answer</a> for a more thorough examination of the various bitwise operators.</p> <p>It's typically used when you want to manipulate specific bits within a data type, such as control of a watchdog timer in an embedded system (your particular use case).</p> <p>You can use <code>or (|)</code> to turn bits on and <code>and (&amp;)</code> to turn them off (with the inversion of the bitmask that's used to turn them on.</p> <p>So, to turn on the <code>b3</code> bit, use:</p> <pre><code>val = val | 0x08; // 0000 1000 </code></pre> <p>To turn it off, use:</p> <pre><code>val = val &amp; 0xf7; // 1111 0111 </code></pre> <p>To detect if <code>b3</code> is currently set, use:</p> <pre><code>if ((val &amp; 0x08) != 0) { // it is set. } </code></pre> <p>You'll typically see the bitmasks defined something like:</p> <pre><code>#define B0 0x01 #define B1 0x02 #define B2 0x04 #define B3 0x08 #define B4 0x10 </code></pre> <p>or:</p> <pre><code>enum BitMask { B0 = 0x01, B1 = 0x02, B2 = 0x04, B3 = 0x08, B4 = 0x10 }; </code></pre> <p>As to what this means:</p> <pre><code>WriteIoCR (0x72, cSetWatchDogUnit|cSetTriggerSignal); </code></pre> <p>More than likely, <code>0x72</code> will be an I/O port of some sort that you're writing to and <code>cSetWatchDogUnit</code> and <code>cSetTriggerSignal</code> will be bitmasks that you combine to output the command (set the trigger signal and use a unit value for the watchdog). What that command means in practice can be inferred but you're safer referring to the documentation for the watchdog circuitry itself.</p> <p>And, on the off chance that you don't know what a watchdog circuit is <em>for,</em> it's a simple circuit that, if you don't kick it often enough (with <em>another</em> command), it will reset your system, probably by activating the reset pin on whatever processor you're using.</p> <p>It's a way to detect badly behaving software automatically and return a device to a known initial state, subscribing to the theory that it's better to reboot than continue executing badly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload