03.08.2013 Views

Embedded Software and Motor Control Libraries for PXR40xx

Embedded Software and Motor Control Libraries for PXR40xx

Embedded Software and Motor Control Libraries for PXR40xx

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.163.4 Description<br />

This function rounds the first argument to nearest value defined by the number of bits<br />

defined by second argument <strong>and</strong> saturate if an overflow is detected. The function returns<br />

a saturated fractional value if the return value cannot fit into the return type.<br />

Note<br />

The round amount cannot exceed in magnitude the bit-width of<br />

the rounded value, that means must be within the range 0...31.<br />

Otherwise the result of the function is undefined. Due to<br />

effectivity reason this function is implemented as inline <strong>and</strong><br />

thus is not ANSI-C compliant.<br />

4.163.5 Re-entrancy<br />

The function is re-entrant.<br />

4.163.6 Code Example<br />

#include "mlib.h"<br />

tFrac32 f32In1;<br />

tFrac32 f32Out;<br />

tU16 u16In2;<br />

void main(void)<br />

{<br />

// first input = 0.5<br />

f32In1 = FRAC32 (0.5);<br />

// second input = 29<br />

u16In2 = 29;<br />

}<br />

// output should be 0x60000000 ~ FRAC32(0.75)<br />

f32Out = MLIB_Round_F32(f32In1,u16In2);<br />

// output should be 0x60000000 ~ FRAC32(0.75)<br />

f32Out = MLIB_Round (f32In1,u16In2,Define F32);<br />

// ##############################################################<br />

// Available only if 32-bit fractional implementation selected<br />

// as default<br />

// ##############################################################<br />

// output should be 0x60000000 ~ FRAC32(0.75)<br />

f32Out = MLIB_Round (f32In1,u16In2);<br />

<strong>Embedded</strong> <strong>Software</strong> <strong>and</strong> <strong>Motor</strong> <strong>Control</strong> <strong>Libraries</strong> <strong>for</strong> <strong>PXR40xx</strong>, Rev. 1.0<br />

Chapter 4 API References<br />

Freescale Semiconductor, Inc. 643

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!