/*****
 * do_init() - initialize the system
 * 
 * This function is executed once at start-up and after a reset.  It initializes
 * the peripherals and registers the interrupt handlers
 *****/
XStatus do_init(void) {
	XStatus Status; // status from Xilinx Lib calls

	// initialize the N3EIF driver
	// rotary encoder is set to increment from 0 by 1
	// NOTE: it's the relative change from the last time the rotary encoder was sampled
	// not the absolute change that matters.  The actual change is handled in main() so we
	// can apply a "speedup" factor if the knob is being turned quickly.
	N3EIF_init(N3EIF_BASEADDR);
	ROT_init(1, false);
	ROT_clear();

	// initialize the GPIO instance
	Status = XGpio_Initialize(&GPIOInst, GPIO_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	// GPIO channel 1 is an 8-bit output port that your application can
	// use.  None of the bits are used by this program
	XGpio_SetDataDirection(&GPIOInst, GPIO_OUTPUT_CHANNEL, 0xF0);
	XGpio_DiscreteWrite(&GPIOInst, GPIO_OUTPUT_CHANNEL, gpio_port);

	// initialize the PWM timer/counter instance but do not start it
	// do not enable PWM interrupts
	Status = PWM_Initialize(&PWMTimerInst, PWM_TIMER_DEVICE_ID, false);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// initialize the PmodCtlSys
	Status = PmodCtlSys_init(&SPIInst, SPI_DEVICEID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// initialize the interrupt controller
	Status = XIntc_Initialize(&IntrptCtlrInst, INTC_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// connect the fixed interval timer (FIT) handler to the interrupt
	Status = XIntc_Connect(&IntrptCtlrInst, FIT_INTERRUPT_ID,
			(XInterruptHandler) FIT_Handler, (void *) 0);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// start the interrupt controller such that interrupts are enabled for
	// all devices that cause interrupts, specifically real mode so that
	// the the  FIT can cause interrupts thru the interrupt controller.
	Status = XIntc_Start(&IntrptCtlrInst, XIN_REAL_MODE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// enable the FIT interrupt
	XIntc_Enable(&IntrptCtlrInst, FIT_INTERRUPT_ID);
	return XST_SUCCESS;
}
Beispiel #2
0
/*****
 * do_init() - initialize the system
 * 
 * This function is executed once at start-up and after resets.  It initializes
 * the peripherals and registers the interrupt handlers
 *****/
XStatus do_init(void)
{
	XStatus 	Status;				// status from Xilinx Lib calls	
	
	// initialize the S3E starter board interface
	// rotary encoder is set to increment from 0 by DUTY_CYCLE_CHANGE 
 	N3EIF_init(N3EIF_BASEADDR);
 	ROT_init(DUTY_CYCLE_CHANGE, true);
	ROT_clear();
	
	
	// initialize the GPIO instance
	Status = XGpio_Initialize(&GPIOInst, GPIO_DEVICE_ID);
	if (Status != XST_SUCCESS)
	{
		return XST_FAILURE;
	}
	// GPIO channel 1 is an 8-bit input port.  bit[7:1] = reserved, bit[0] = PWM output (for duty cycle calculation)
	// GPIO channel 2 is an 8-bit output port.  bit[7:1] = reserved, bit[0] = FIT clock
	XGpio_SetDataDirection(&GPIOInst, GPIO_OUTPUT_CHANNEL, 0xFE);
			
	// initialize the PWM timer/counter instance but do not start it
	// do not enable PWM interrupts
	Status = PWM_Initialize(&PWMTimerInst, PWM_TIMER_DEVICE_ID, false);
	if (Status != XST_SUCCESS)
	{
		return XST_FAILURE;
	}
	
	// initialize the interrupt controller
	Status = XIntc_Initialize(&IntrptCtlrInst,INTC_DEVICE_ID);
    if (Status != XST_SUCCESS)
    {
       return XST_FAILURE;
    }

	// connect the fixed interval timer (FIT) handler to the interrupt
    Status = XIntc_Connect(&IntrptCtlrInst, FIT_INTERRUPT_ID,
                           (XInterruptHandler)FIT_Handler,
                           (void *)0);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }
 
	// start the interrupt controller such that interrupts are enabled for
	// all devices that cause interrupts.
    Status = XIntc_Start(&IntrptCtlrInst, XIN_REAL_MODE);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

	// enable the FIT interrupt
    XIntc_Enable(&IntrptCtlrInst, FIT_INTERRUPT_ID);
	return XST_SUCCESS;
}
Beispiel #3
0
static void initialize()
{
    CLOCK_StopTimer();
    if (PPMin_Mode())
        return;

    PWM_Initialize();
    num_channels = Model.num_channels;
    if (Model.proto_opts[CENTER_PW] == 0) {
        Model.proto_opts[CENTER_PW] = 1100;
        Model.proto_opts[DELTA_PW] = 400;
        Model.proto_opts[NOTCH_PW] = 400;
        Model.proto_opts[PERIOD_PW] = 22500;
    }
    
    CLOCK_StartTimer(1000, ppmout_cb);
}
Beispiel #4
0
void SYS_Initialize ( void* data )
{
    /* Core Processor Initialization */
    SYS_CLK_Initialize( NULL );
    sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit);
    SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
    SYS_DEVCON_JTAGDisable();
    SYS_PORTS_Initialize();

    /* Initialize Drivers */
    /* Initialize ADC */
    DRV_ADC_Initialize();
    /*Initialize TMR0 */
    DRV_TMR0_Initialize();
 
     DRV_USART0_Initialize();


    /*Initialize OC0 */
    DRV_OC0_Initialize();

    /*Initialize OC1 */
    DRV_OC1_Initialize();

    /*Initialize OC2 */
    DRV_OC2_Initialize();

    /*Initialize OC3 */
    DRV_OC3_Initialize();

    /* Initialize System Services */
    SYS_INT_Initialize();  

    /* Initialize Middleware */

    /* Initialize the Application */
    PWM_Initialize();
}
Beispiel #5
0
int do_init(void) {

	int status;				// status from Xilinx Lib calls
	
	// initialize the Nexys4IO and Pmod544IO hardware and drivers
	// rotary encoder is set to increment from 0 by DUTY_CYCLE_CHANGE 
	
	status = NX4IO_initialize(NX4IO_BASEADDR);

	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	
	status = PMDIO_initialize(PMDIO_BASEADDR);

	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	
	// successful initialization.  Set the rotary encoder
	// to increment from 0 by DUTY_CYCLE_CHANGE counts per rotation

	PMDIO_ROT_init(DUTY_CYCLE_CHANGE, true);
	PMDIO_ROT_clear();
	
	
	// initialize the GPIO instances

	status = XGpio_Initialize(&GPIOInst0, GPIO_0_DEVICE_ID);
	
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	status = XGpio_Initialize(&GPIOInst1, GPIO_1_DEVICE_ID);
	
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// GPIO_0 channel 1 is an 8-bit input port.  bit[7:1] = reserved, bit[0] = PWM output (for duty cycle calculation)
	// GPIO_0 channel 2 is an 8-bit output port.  bit[7:1] = reserved, bit[0] = FIT clock

	XGpio_SetDataDirection(&GPIOInst0, GPIO_0_INPUT_CHANNEL, 0xFF);
	XGpio_SetDataDirection(&GPIOInst0, GPIO_0_OUTPUT_CHANNEL, 0xFE);

	// GPIO_1 channel 1 is a 32-bit input port - used to pass hw_detect 'high' count to application
	// GPIO_1 channel 2 is an 8-bit output port - used to pass hw_detect 'low' count to application
	
	XGpio_SetDataDirection(&GPIOInst1, GPIO_1_HIGH_COUNT, 0xFFFFFFFF);
	XGpio_SetDataDirection(&GPIOInst1, GPIO_1_LOW_COUNT, 0xFFFFFFFF);

	// initialize the PWM timer/counter instance but do not start it
	// do not enable PWM interrupts.  Clock frequency is the AXI clock frequency
	
	status = PWM_Initialize(&PWMTimerInst, PWM_TIMER_DEVICE_ID, false, AXI_CLOCK_FREQ_HZ);
	
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	
	// initialize the interrupt controller
	
	status = XIntc_Initialize(&IntrptCtlrInst, INTC_DEVICE_ID);
	
	if (status != XST_SUCCESS) {
	   return XST_FAILURE;
	}

	// connect the fixed interval timer (FIT) handler to the interrupt
	
	status = XIntc_Connect(&IntrptCtlrInst, FIT_INTERRUPT_ID, (XInterruptHandler)FIT_Handler, (void *)0);

	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}
 
	// start the interrupt controller such that interrupts are enabled for
	// all devices that cause interrupts

	status = XIntc_Start(&IntrptCtlrInst, XIN_REAL_MODE);
	
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// enable the FIT interrupt

	XIntc_Enable(&IntrptCtlrInst, FIT_INTERRUPT_ID);

	// set the duty cycles for RGB1.  The channels will be enabled/disabled
	// in the FIT interrupt handler.  Red and Blue make purple

	NX4IO_RGBLED_setDutyCycle(RGB1, 64, 0, 64);
	NX4IO_RGBLED_setChnlEn(RGB1, false, false, false);

	return XST_SUCCESS;
}
/*****
 * do_init() - initialize the system
 *
 * This function is executed once at start-up and after a reset.  It initializes
 * the peripherals and registers the interrupt handlers
 *****/
XStatus do_init(void)
{
    XStatus 	Status;				// status from Xilinx Lib calls

    // initialize the N3EIF hardware and driver
    // rotary encoder is set to increment duty cycle from 0 by 5 w/
    // no negative counts
    N3EIF_init(N3EIF_BASEADDR);
    ROT_init(DUTY_CYCLE_CHANGE, true);
    ROT_clear();

    // initialize the GPIO instance
    Status = XGpio_Initialize(&GPIOInst, GPIO_DEVICE_ID);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }
    // GPIO channel 1 is an 8-bit output port that your application can
    // use.  None of the bits are used by this program
    XGpio_SetDataDirection(&GPIOInst, GPIO_OUTPUT_CHANNEL, 0xF0);
    XGpio_DiscreteWrite(&GPIOInst, GPIO_OUTPUT_CHANNEL, gpio_port);


    // initialize the PWM timer/counter instance but do not start it
    // do not enable PWM interrupts
    Status = PWM_Initialize(&PWMTimerInst, PWM_TIMER_DEVICE_ID, false);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    //Initialize LIGHTSENSOR peripheral
    Status = LIGHTSENSOR_Init(LIGHTSENSOR_BASEADDR);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    // initialize the interrupt controller
    Status = XIntc_Initialize(&IntrptCtlrInst,INTC_DEVICE_ID);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    // connect the fixed interval timer (FIT) handler to the interrupt
    Status = XIntc_Connect(&IntrptCtlrInst, FIT_INTERRUPT_ID,
                           (XInterruptHandler)FIT_Handler,
                           (void *)0);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    // start the interrupt controller such that interrupts are enabled for
    // all devices that cause interrupts, specifically real mode so that
    // the the  FIT can cause interrupts thru the interrupt controller.
    Status = XIntc_Start(&IntrptCtlrInst, XIN_REAL_MODE);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    // start the lightsensor

    Status = LIGHTSENSOR_Start(LIGHTSENSOR_BASEADDR);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    // enable the FIT interrupt
    XIntc_Enable(&IntrptCtlrInst, FIT_INTERRUPT_ID);
    return XST_SUCCESS;
}
Beispiel #7
0
void ApplicationEntryPoint()
{

#if defined(TEST_DAC)
    UINT32 FramesNum = g_LPC24XX_DAC_Driver.GetBufferFrameCapacity();
    if (DAC_FRAME_BUFFERS_NUM!=FramesNum)
    {
        debug_printf( "Error, BufferFrameCapacity != DAC_FRAME_BUFFERS_NUM: %d != %d.\r\n", FramesNum, DAC_FRAME_BUFFERS_NUM );
    }

    UINT32 nextInFrameOffset=0;
    UINT16 frameLength = MAX_DECODED_FRAME_SIZE/2;
    short* frameSignedStart = NULL;


    LPC24XX_VIC& VIC = LPC24XX::VIC();

    /*debug_printf("VIC INTRSEL = 0x%08x\r\n", VIC.INTRSEL);
    VIC.INTRSEL |= 1 << LPC24XX_TIMER::getIntNo(LPC24XX_DAC::Timer);
    debug_printf("new VIC INTRSEL = 0x%08x\r\n", VIC.INTRSEL);*/

    VIC.VECTPRIORITY[LPC24XX_TIMER::getIntNo(LPC24XX_DAC::Timer)] = 0;

    for(int i= 0; i< 32; i++)
    {
        debug_printf("PRIO INTR%02d = %d \r\n", i,VIC.VECTPRIORITY[i]);
    }


    debug_printf( "Init DAC, 8kHz output.\r\n" );
    g_LPC24XX_DAC_Driver.Initialize(OUT_FREQ);




    debug_printf( "BUFFER PRE-FILL TEST.\r\n" );
    debug_printf( "Adding frames to the DAC driver buffer: " );


    debug_printf("total frames to be added = %d\r\n", TEST_SAMPLES_NUM/MAX_DECODED_FRAME_SIZE-CUTOUT);
    debug_printf("DAC frame buffers available = %d\r\n", DAC_FRAME_BUFFERS_NUM);
    if(DAC_FRAME_BUFFERS_NUM<(TEST_SAMPLES_NUM/MAX_DECODED_FRAME_SIZE-CUTOUT))
        debug_printf("ONLY THE FIRST %d FRAMES OF THE SAMPLE WILL BE PLAYED.\r\n", DAC_FRAME_BUFFERS_NUM);

    while(nextInFrameOffset+(MAX_DECODED_FRAME_SIZE*CUTOUT) < TEST_SAMPLES_NUM)
    {
        //if(i%(1024*256)) continue;


        frameSignedStart = (short*)(bin_data+nextInFrameOffset);

        if(g_LPC24XX_DAC_Driver.AddFrame(frameSignedStart, frameLength))
        {
            debug_printf( "     done.\r\n" );
            nextInFrameOffset+=MAX_DECODED_FRAME_SIZE;
        }
        else
        {
            debug_printf( "Buffer full, starting playout.\r\n");
            break;
        }
    }

    resetDACISRTiming();


    debug_printf( "DAC.On() in 2 seconds\r\n");
    Events_WaitForEvents( 0, 2000 );

    if(!hijackISRs())
        return;

    if(g_LPC24XX_DAC_Driver.On())
    {
        //debug_printf( "Done. 2sec wait.\r\n" ); don't output to avoid adding serial activity during the test
    }
    else
    {
        debug_printf( "FAILED.\r\n" );
    }

    while(g_LPC24XX_DAC_Driver.GetBufferLevel()>0)
    {
        //debug_printf("Samples left: %d\r\n", g_LPC24XX_DAC_Driver.GetBufferLevel());
        //debug_printf("Frames left:  %d\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft());
    }

    //stop logging interrupts before starting to output again

    int finalIrqCount = irq_count;
    irq_count = 8192;

    Events_WaitForEvents( 0, 5000 );

    if(!restoreISRs())
        return;

    debug_printf("%d frames left.\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft());
    debug_printf("Final IRQ count = %u\r\n", finalIrqCount);
    debug_printf( "BUFFER PRE-FILL TEST OVER.\r\n");

    displayRunTestResults();
    debug_printf("CSV DATA OUTPUT FOLLOWS\r\n");
    //csvRunTestResults();



    debug_printf("\r\nPARALLEL BUFFER FILL TEST\r\n" );


    Events_WaitForEvents( 0, 3000 );

    debug_printf( "DAC.Off()\r\n");
    if(g_LPC24XX_DAC_Driver.Off())
    {
        debug_printf( "Done.\r\n" );
    }
    else
    {
        debug_printf( "FAILED.\r\n" );
    }

    debug_printf( "Uninit DAC\r\n");
    g_LPC24XX_DAC_Driver.Uninitialize();
    debug_printf( "Done.\r\n");

    debug_printf( "Init DAC, 8kHz output.\r\n" );
    g_LPC24XX_DAC_Driver.Initialize(OUT_FREQ);

    resetDACISRTiming();

    debug_printf( "DAC.On() in 2 seconds\r\n");
    Events_WaitForEvents( 0, 2000 );
    if(g_LPC24XX_DAC_Driver.On())
    {
        //debug_printf( "Done.\r\n" );
    }
    else
    {
        debug_printf( "FAILED.\r\n" );
    }

    debug_printf( "Adding frames to the DAC driver buffer: " );

    nextInFrameOffset=0;

    debug_printf("total frames to be added = %d\r\n", TEST_SAMPLES_NUM/MAX_DECODED_FRAME_SIZE-CUTOUT);

    //FILL JUST ONCE
    while(nextInFrameOffset+(MAX_DECODED_FRAME_SIZE*CUTOUT) < TEST_SAMPLES_NUM)
    {
        //if(i%(1024*256)) continue;


        frameSignedStart = (short*)(bin_data+nextInFrameOffset);

        if(g_LPC24XX_DAC_Driver.AddFrame(frameSignedStart, frameLength))
        {
            debug_printf( "     done.\r\n" );
            nextInFrameOffset+=MAX_DECODED_FRAME_SIZE;
        }
        else
        {
            //debug_printf( "FAIL.\r\n");
        }
    }

    while(g_LPC24XX_DAC_Driver.GetBufferLevel()>0)
    {
        //debug_printf("Samples left: %d\r\n", g_LPC24XX_DAC_Driver.GetBufferLevel());
        //debug_printf("Frames left:  %d\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft());
    }

    Events_WaitForEvents( 0, 3000 );

    displayRunTestResults();

    debug_printf("CSV DATA OUTPUT FOLLOWS\r\n");
    csvRunTestResults();

    /*CONTINUOUS REFILL with samples
    while(true)
    {
        //if(i%(1024*256)) continue;


        frameSignedStart = (short*)(bin_data+nextInFrameOffset);

        if(g_LPC24XX_DAC_Driver.AddFrame(frameSignedStart, frameLength))
        {
            //debug_printf( "     done.\r\n" );
            nextInFrameOffset+=MAX_DECODED_FRAME_SIZE;
            if(nextInFrameOffset+(MAX_DECODED_FRAME_SIZE*CUTOUT)>=TEST_SAMPLES_NUM)
                nextInFrameOffset = 0;
        }
        else
        {
            //debug_printf( "FAIL.\r\n");
        }
        debug_printf("Samples left: %d\r\n", g_LPC24XX_DAC_Driver.GetBufferLevel());
        debug_printf("Frames left:  %d\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft());
    }*///end continuous refill


    debug_printf("%d frames left.\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft());
    debug_printf( "PARALLEL BUFFER FILL TEST OVER.\r\n\r\n" );


    //Events_WaitForEvents( 0, 10000 );

    debug_printf( "DAC.Off()\r\n");
    if(g_LPC24XX_DAC_Driver.Off())
    {
        debug_printf( "Done.\r\n" );
    }
    else
    {
        debug_printf( "FAILED.\r\n" );
    }

    debug_printf( "Uninit DAC()\r\n");
    g_LPC24XX_DAC_Driver.Uninitialize();
    debug_printf( "Done.\r\n");

#endif


#if defined(TEST_JOYSTICK)
    extern LPC24XX_GPIO_Driver g_LPC24XX_GPIO_Driver;

    wait_joystick = true;

    for(UINT32 pin = LPC24XX_GPIO::c_P2_22; pin < LPC24XX_GPIO::c_P2_28; pin++)
    {
        if(pin == LPC24XX_GPIO::c_P2_24)
            continue;
        if(!g_LPC24XX_GPIO_Driver.EnableInputPin( pin, false,  joystickISR, NULL, GPIO_INT_EDGE_HIGH, (GPIO_RESISTOR)2 ))
        {
            debug_printf("Cannot enable pin %u as INPUT pin.\r\n", pin);
            exit(1);
        }
        debug_printf("Enabled pin %u as INPUT pin.\r\n", pin);
    }

    while(wait_joystick) {};

#endif

#if    defined(TEST_SST39WF)

    while(1)
    {
        lcd_printf  ( "Hello, world from the LCD!\r\n" );
        hal_printf  ( "Hello, world from the HAL!\r\n" );
        debug_printf( "Hello, world from the debug intf!\r\n" );
        if(BlockStorageList::GetNumDevices() != 1)
        {
            debug_printf( "%d Block Devices present!\r\n", BlockStorageList::GetNumDevices() );
            break;
        }

        BlockStorageDevice* SST = BlockStorageList::GetFirstDevice();
        if(SST == NULL)
        {
            debug_printf( "GetFirstDevice failed.\r\n" );
            break;
        }

        const BlockDeviceInfo* SSTInfo = SST->GetDeviceInfo();
        if(SSTInfo == NULL)
        {
            debug_printf( "GetDeviceInfo failed.\r\n" );
            break;
        }

        debug_printf( "NumRegions in BSDevice: %d\r\n", SSTInfo->NumRegions);

        ByteAddress PhyAddress = (ByteAddress) 0xC0FFEEEE;

        SectorAddress SectAddress = 0xC0FFEEEE;
        UINT32 RangeIndex;
        UINT32 RegionIndex;

        const BlockRegionInfo *pBlockRegionInfo;
        SST->FindForBlockUsage(    /*UINT32*/ BlockRange::BLOCKTYPE_DEPLOYMENT ,
                                              PhyAddress , RegionIndex, RangeIndex );
        if(PhyAddress == 0xC0FFEEEE)
        {
            debug_printf( "FindForBlockUsage failed.\r\n" );
            break;
        }


        debug_printf( "Sector 0x%08x physical address: 0x%08x\r\n", SectAddress, PhyAddress);

        BYTE pSectorBuf[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};

        //ERASE before writing!
        if(!SST->IsBlockErased(PhyAddress, 0x1000))
        {
            debug_printf( "Erasing block " );
            if(!SST->EraseBlock(SectAddress))
            {
                debug_printf( "failed.\r\n" );
                break;
            }
            debug_printf( "successful.\r\n" );
        }

        if(SST->Write(/*UINT32*/ PhyAddress, /*UINT32 NumOfBytes*/ 16, /*BYTE* */ pSectorBuf, /*SectorMetadata* */ FALSE))
            debug_printf( "Correctly written 16 bytes to Sector 0x%08x\r\n", SectAddress);

        Events_WaitForEvents( 0, 2000 );
    }
#endif        //TEST_SST39WF

#if defined(TEST_PWM)

    PWM_Initialize(PWM_CHANNEL_0);

    // NOTE: on the EA_LPC2478 board the first pin we will return is the 11th pin on the left side from the top of the J1 connector
    GPIO_PIN pin = PWM_GetPinForChannel( PWM_CHANNEL_0 );

    // from 90% to 2/3, to 50%, to 1/3 to 10%
    float dc[5] = { 0.9, 0.666, 0.5, 0.333, 0.1 };
    UINT32 period1 = 1000; // 1Kxz
    for(UINT32 idx = 0; idx < 5; ++idx)
    {
        UINT32 duration1 = (UINT32)((float)period1 * dc[idx]);

        PWM_ApplyConfiguration( PWM_CHANNEL_0, pin, period1, duration1, FALSE);
        PWM_Start             ( PWM_CHANNEL_0, pin );

        // 2 secs, then change
        HAL_Time_Sleep_MicroSeconds_InterruptEnabled(1 * 1000 * 1000);
        //Events_WaitForEvents( 0, 2 * 1000);

        PWM_Stop              ( PWM_CHANNEL_0, pin );
    }

    // from 10Khz to 1Khz, 50% duty cycle
    for(UINT32 period = 10000; period >= 1000; period -= 1000)
    {
        UINT32 duration = period / 2;

        PWM_ApplyConfiguration( PWM_CHANNEL_0, pin, period, duration, FALSE);
        PWM_Start             ( PWM_CHANNEL_0, pin );

        // 2 secs, then change
        HAL_Time_Sleep_MicroSeconds_InterruptEnabled(1 * 1000 * 1000);
        //Events_WaitForEvents( 0, 2 * 1000);

        PWM_Stop              ( PWM_CHANNEL_0, pin );
    }

    PWM_Uninitialize(PWM_CHANNEL_0);

#endif // TEST_PWM

    while(1)
    {
        lcd_printf  ( "Hello, world!\r\n" );
        hal_printf  ( "Hello, world!\r\n" );
        debug_printf( "Hello, world!\r\n" );


        Events_WaitForEvents( 0, 1000 );
    }

}
Beispiel #8
0
XStatus init_axi_devices(void) {
   int status;
   
   // INITIALIZE : Nexys4IO
   status = NX4IO_initialize(XPAR_NEXYS4IO_0_S00_AXI_BASEADDR);
   if (status != XST_SUCCESS) return XST_FAILURE;
   NX4IO_setLEDs(0x0000FFFF);

   // INITIALIZE : PMOD544IO
   status = PMDIO_initialize(XPAR_PMOD544IOR2_0_S00_AXI_BASEADDR);
   if (status != XST_SUCCESS) return XST_FAILURE;
   // SET : Encoder val = 0, increment val = DUTY_CYCLE_CHANGE
   NX4IO_setLEDs(0x0000FFFE);
   PMDIO_ROT_init(DUTY_CYCLE_INCREMENTS, true);
   PMDIO_ROT_clear();
   NX4IO_setLEDs(0x0000FFFD);
   
   // This is currently crashing the program =/
   // No GPIO for now
   // INITIALIZE : Degug signal GPIO (1X 4-bit)
   
   /*status = XGpio_Initialize(&instGPIODebug,  XPAR_AXI_GPIO_0_BASEADDR);*/
   /*if (status != XST_SUCCESS) return XST_FAILURE;*/
   /*NX4IO_setLEDs(0x0000FFFC);*/
   /*// SET : Direction of output ports */
   /*XGpio_SetDataDirection(&instGPIODebug, 0, 0xFFFFFFF0);*/
   /*NX4IO_setLEDs(0x0000FFFB);*/

   // INITIALIZE : PWM timer/counter
   status = PWM_Initialize(&instPWMTimer, XPAR_AXI_TIMER_0_DEVICE_ID, false, XPAR_CPU_CORE_CLOCK_FREQ_HZ);
   if (status != XST_SUCCESS) return XST_FAILURE;
   NX4IO_setLEDs(0x0000FFFA);
   
   // INITIALIZE : Interrupt controller
   status = XIntc_Initialize(&instIntrCtrl, XPAR_MICROBLAZE_0_AXI_INTC_DEVICE_ID);
   if (status != XST_SUCCESS) return XST_FAILURE;
   NX4IO_setLEDs(0x0000FFF9);

   // SET : GPIO handler to interrupt vector
   status = XIntc_Connect(&instIntrCtrl, XPAR_MICROBLAZE_0_AXI_INTC_FIT_TIMER_0_INTERRUPT_INTR,
                         (XInterruptHandler)FIT_Handler,
                         (void *)0);
   if (status != XST_SUCCESS) return XST_FAILURE;
   NX4IO_setLEDs(0x0000FFF8);
 
   // SET : Interrupt controller enabled for all devices
   status = XIntc_Start(&instIntrCtrl, XIN_REAL_MODE);
   if (status != XST_SUCCESS) return XST_FAILURE;
   NX4IO_setLEDs(0x0000FFF7);

   // SET : Interrupts enabled
   XIntc_Enable(&instIntrCtrl, XPAR_MICROBLAZE_0_AXI_INTC_FIT_TIMER_0_INTERRUPT_INTR);
   NX4IO_setLEDs(0x0000FFF6);

   // SET : RGB LED duty cycles and disable output
   NX4IO_RGBLED_setDutyCycle(RGB1, 64, 0, 64);
   NX4IO_RGBLED_setChnlEn(RGB1, false, false, false);
   NX4IO_setLEDs(0x0000FFF5);

   return XST_SUCCESS;
}