#include <nitro/cp.h> void CP_SetDiv32_32( u32 numer, u32 denom ); void CP_SetDiv64_32( u64 numer, u32 denom ); void CP_SetDiv64_64( u64 numer, u64 denom );
Sets parameters for division. Sets division mode first, and then stores dividend and divisor in each register. CP_SetDivImm* is used to store dividend and divisor.
There are three division modes as follows:
|
Division Mode |
Calculation |
Results |
|
CP_DIV_32_32BIT_MODE |
32-bit divided by 32-bit |
Quotient 32-bit, remainder 32-bit |
|
CP_DIV_64_32BIT_MODE |
64-bit divided by 32-bit |
Quotient 64-bit, remainder 32-bit |
|
CP_DIV_64_64BIT_MODE |
64-bit divided by 64-bit |
Quotient 64-bit, remainder 64-bit |
Set mode to CP_DIV_32_32BIT_MODE with
CP_SetDiv32_32().
Set mode to CP_DIV_64_32BIT_MODE with CP_SetDiv64_32().
Set mode to CP_DIV_64_64BIT_MODE with CP_SetDiv64_64().
With the Divider, sometimes the value is overwritten in the interrupt. If the division parameters are set up, an interrupt occurs during division, and the Divider is used, the original calculated result is irregular. Therefore, if you are using the Divider in an interrupt, the status of the Divider needs to be temporarily stored/restored using CP_SaveContext and CP_RestoreContext.
During a thread switch, the contents of the Divider are also automatically saved/restored.
Example: Restore the Divider status
intr_func( void )
{
CPContext context;
CP_SaveContext( &context );
CP_SetDiv32_32( 1000, 5 );
CP_WaitDiv();
result = CP_GetDivResult();
CP_RestoreContext( &context );
}
Stores values in DIVCNT(0x4000280), DIV_NUMER(0x4000290), and DIV_DENOM(0x4000298) of the IO register.
|
|
Numerator of fraction. Represents dividend of division here. |
|
|
Denominator of fraction. Represents divisor of division here. |
None.
CP_SetDivImm*, CP_IsDivBusy, CP_WaitDiv, CP_GetDivResult*, CP_GetDivRemainder*, CP_SaveContext, CP_RestoreContext
11/02/2004 Corrected IO register address in Internal Operation.
05/06/2004 Changes to description due to thread safe process.
03/31/2004 Description of non-thread safe factors.
01/09/2004 Added content.
12/01/2003 Initial version.