Example #1
0
int main()
{
    BIGNUM *x, *y, *exp, *m;
    BIGNUM t;
    COMPLEX a, b, r;

    BN_init( &t );
    x = BN_new();
    y = BN_new();
    exp = BN_new();
    m = BN_new();
    COMP_init( &a );
    COMP_init( &b );
    COMP_init( &r );

    if ( Context == NULL )
    	Context = BN_CTX_new();

    if(!BN_set_word(m, 43l))
    	goto err;
    BN_set_word(x, 38l);
    BN_set_word(y, 13l);
    BN_set_word(exp, 168l);
    BN_copy( &t ,m );

    if (!COMP_set(&a, x, y, m))
    	goto err;
    if (!COMP_pow(&r, &a, exp, m))
    	goto err;


    BN_free( &t );
    BN_free( x );
    BN_free( y );
    BN_free( exp );
    BN_free( m );
    COMP_free( &a );
    COMP_free( &b );
    COMP_free( &r );

	return 0;
err:
	BN_free( &t );
	BN_free( x );
	BN_free( y );
	BN_free( exp );
	BN_free( m );
	COMP_free( &a );
	COMP_free( &b );
	COMP_free( &r );

	return 0;
}
void main(void)
{
    ADC_Handle myAdc;
    CPU_Handle myCpu;
    PLL_Handle myPll;
    WDOG_Handle myWDog;

    // Initialize all the handles needed for this application
    myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
    myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
    myComp = COMP_init((void *)COMP1_BASE_ADDR, sizeof(COMP_Obj));
    myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
    myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
    myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
    myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
    myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
    myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));
    myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));

    // Perform basic system initialization
    WDOG_disable(myWDog);
    CLK_enableAdcClock(myClk);
    (*Device_cal)();
    CLK_disableAdcClock(myClk);

    //Select the internal oscillator 1 as the clock source
    CLK_setOscSrc(myClk, CLK_OscSrc_Internal);

    // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2
    PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2);

    // Disable the PIE and all interrupts
    PIE_disable(myPie);
    PIE_disableAllInts(myPie);
    CPU_disableGlobalInts(myCpu);
    CPU_clearIntFlags(myCpu);

    // If running from flash copy RAM only functions to RAM
#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif

    // For this case just init GPIO pins for ePWM1
    GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A);
    GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B);

    // Setup a debug vector table and enable the PIE
    PIE_setDebugIntVectorTable(myPie);
    PIE_enable(myPie);

    // Register interrupt handlers in the PIE vector table
    PIE_registerPieIntHandler(myPie, PIE_GroupNumber_2, PIE_SubGroupNumber_1,
                              (intVec_t)&epwm1_tzint_isr);

    // Enable Clock to the ADC
    CLK_enableAdcClock(myClk);
    // Comparator shares the internal BG reference of the ADC,
    // must be powered even if ADC is unused
    ADC_enableBandGap(myAdc);
    // Delay to allow BG reference to settle.
    DELAY_US(1000L);

    // Enable clock to the Comparator 1 block
    CLK_enableCompClock(myClk, CLK_CompNumber_1);
    // Power up Comparator 1 locally
    COMP_enable(myComp);
    // Connect the inverting input to pin COMP1B
    COMP_disableDac(myComp);
////////////////Uncomment following 4 lines to use DAC instead of pin COMP1B //////////////////
//    // Connect the inverting input to the internal DAC
//    COMP_enableDac(myComp);
//    // Set DAC output to midpoint
//    COMP_setDacValue(myComp, 512);
//////////////////////////////////////////////////////////////////////////////////////////////

    CLK_disableTbClockSync(myClk);

    InitEPwm1Example();

    CLK_enableTbClockSync(myClk);

    // Initialize counters
    EPwm1TZIntCount = 0;

    // Enable CPU INT3 which is connected to EPWM1-3 INT
    CPU_enableInt(myCpu, CPU_IntNumber_2);

    // Enable EPWM INTn in the PIE: Group 2 interrupt 1-3
    PIE_enablePwmTzInt(myPie, PWM_Number_1);

    // Enable global Interrupts and higher priority real-time debug events
    CPU_enableGlobalInts(myCpu);
    CPU_enableDebugInt(myCpu);

    for(;;)
    {
        __asm(" NOP");
    }
}