SysCpuTestAndSetBit (FUN)

FUNCTION SysCpuTestAndSetBit : RTS_IEC_RESULT

<description>
<p>The function test and set or clear a bit in a variable in one processor step. This operation must be atomic to provide a multitasking save operation.</p>

<p>IMPLEMENTATION NOTE: Try to use a processor opcode, that provides this operation. If such an opcode is not available, use SysCpuTestAndSetBitBase in your platform adaptation.</p>

</description> <result><p>RESULT: Returns the runtime system error code (see CmpErrors.library).</p>

<ul>
<li>ERR_OK: bSet=1: If bit could be set and was not set before

bSet=0: If bit could be cleared and was set before</li>

<li>ERR_FAILED: bSet=1: If bit is still set

bSet=0: If bit is still cleared</li>

<li>ERR_PARAMETER: If pAddress=NULL or pAddress is unaligned or iBit is out nSize range</li> <li>ERR_NOT_SUPPORTED: If function is not available because of missing components (e.g. SysInt for locking bit access)</li> <li>ERR_NOTIMPLEMENTED: If function is not implemented on this platform</li>

</ul>

</result> <SIL2/>

InOut:

Scope

Name

Type

Comment

Return

SysCpuTestAndSetBit

RTS_IEC_RESULT

Input

pAddress

POINTER TO BYTE

<param name=”pAddress” type=”IN”>Pointer to test and set or clear a bit inside in one atomic processor step.

NOTE: The pointer must be natural aligned! nLen=2: pAddress must be 2Byte aligned; nLen=4: pAddress must be 4Byte aligned</param>

nLen

UDINT

<param name=”nLen” type=”IN”>Size of the value behind the address. Can only be 1 (unsigned char), 2 (unsigned short) or 4 (unsigned long)</param>

iBit

DINT

<param name=”iBit” type=”IN”>Bit number inside the variable to test and set or clear:
<ul>

<li>nLen = 1: iBit 0..7</li> <li>nLen = 2: iBit 0..15</li> <li>nLen = 4: iBit 0..31</li>

</ul>

</param>

bSet

DINT

<param name=”bSet” type=”IN”>1=Set bit, 0=Clear bit</param>