int main (void) 
{

    XGpio dip, push;
	int i, psb_check, dip_check;
	
    xil_printf("-- Start of the Program --\r\n");
 
    XGpio_Initialize(&dip, XPAR_SW_4BIT_DEVICE_ID);
	XGpio_SetDataDirection(&dip, 1, 0xffffffff);
	
	XGpio_Initialize(&push, XPAR_BTNS_4BIT_DEVICE_ID);
	XGpio_SetDataDirection(&push, 1, 0xffffffff);
	
	while (1)
	{
	  psb_check = XGpio_DiscreteRead(&push, 1);
	  xil_printf("Push Buttons Status %x\r\n", psb_check);
	  dip_check = XGpio_DiscreteRead(&dip, 1);
	  xil_printf("DIP Switch Status %x\r\n", dip_check);
	  
	  for (i=0; i<9999999; i++); 
	}
 
}
int main (void) 
{

   XGpio dip, push;
   int i, psb_check, dip_check;
	
   xil_printf("-- Start of the Program --\r\n");
 
   XGpio_Initialize(&dip, XPAR_SW_4BIT_DEVICE_ID); // Modify this
   XGpio_SetDataDirection(&dip, 1, 0xffffffff);
	
   XGpio_Initialize(&push, XPAR_BTNS_4BIT_DEVICE_ID); // Modify this
   XGpio_SetDataDirection(&push, 1, 0xffffffff);
	

   while (1)
   {
	  psb_check = XGpio_DiscreteRead(&push, 1);
	  xil_printf("Push Buttons Status %x\r\n", psb_check);
	  dip_check = XGpio_DiscreteRead(&dip, 1);
	  xil_printf("DIP Switch Status %x\r\n", dip_check);
	  
	  // output dip switches value on LED_ip device
	  LED_IP_mWriteReg(XPAR_LED_IP_0_S_AXI_BASEADDR,0,dip_check);
	  
	  for (i=0; i<9999999; i++);
   }
}
Beispiel #3
0
void Initialize()
{
    XGpio_Initialize(&Dips, XPAR_DIP_DEVICE_ID);
    XGpio_SetDataDirection(&Dips, 1, 0xff);

    XGpio_Initialize(&Btns, XPAR_BUTTON_DEVICE_ID);
    XGpio_SetDataDirection(&Btns, 1, 0xff);

    XIntc_Initialize(&intCtrl, XPAR_AXI_INTC_0_DEVICE_ID);

    XGpio_InterruptEnable(&Btns, 1);
    XGpio_InterruptGlobalEnable(&Btns);

    XGpio_InterruptEnable(&Dips, 1);
    XGpio_InterruptGlobalEnable(&Dips);

    XIntc_Enable(&intCtrl, XPAR_AXI_INTC_0_BUTTON_IP2INTC_IRPT_INTR);
    XIntc_Enable(&intCtrl, XPAR_AXI_INTC_0_DIP_IP2INTC_IRPT_INTR);

    XIntc_Connect(&intCtrl, XPAR_AXI_INTC_0_BUTTON_IP2INTC_IRPT_INTR,
        (XInterruptHandler)PushBtnHandler, (void *)0);
    XIntc_Connect(&intCtrl, XPAR_AXI_INTC_0_DIP_IP2INTC_IRPT_INTR,
        (XInterruptHandler)SwitchHandler,(void *)0);

    microblaze_enable_interrupts();

    microblaze_register_handler((XInterruptHandler)XIntc_InterruptHandler, (void *)&intCtrl);
    XIntc_Start(&intCtrl, XIN_REAL_MODE);
}
Beispiel #4
0
int main(void){
	int status;
	int delay = 100000;
	int temp=148;


	//INITILIZE THE GPIO
	status = XGpio_Initialize(&SwitchInst, SWITCH_DEVICE_ID);
		if(status != XST_SUCCESS) return XST_FAILURE;

	status = XGpio_Initialize(&DutycycleInst, DUTYCYCLE_DEVICE_ID);
		if(status != XST_SUCCESS) return XST_FAILURE;

	//SET GPIO DATA DIRECTIONS
	XGpio_SetDataDirection(&SwitchInst, 1, 0xFF);
	XGpio_SetDataDirection(&DutycycleInst, 1, 0x00);

	//DO SOMETHING HERE IN MAIN **EDIT**
	  while(1){
		  switch_value = XGpio_DiscreteRead(&SwitchInst, 1);
		  //for(int i = 0; i < delay; i++);
		  temp = (100+(switch_value*5.625));
		  XGpio_DiscreteWrite(&DutycycleInst, 1, temp);
	  }

	return 0;
}
Beispiel #5
0
int SetupPeripherals( void )
{
    XGpio_Initialize(&gpio_blinky, XPAR_AXI_GPIO_LED_DEVICE_ID);
    XGpio_SetDataDirection(&gpio_blinky, 2, 0);
    XGpio_SetDataDirection(&gpio_blinky, 1, 0);
    XGpio_DiscreteWrite(&gpio_blinky, 1, 0);
    XGpio_DiscreteWrite(&gpio_blinky, 2, 0);
    return XST_SUCCESS;
}
void initGPIO()
{
	XGpio_Initialize(&xgpio_pushButtons, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
	XGpio_SetDataDirection(&xgpio_pushButtons, 1, 0x0000001F);

	XGpio_Initialize(&xgpio_LEDs, XPAR_LEDS_8BITS_DEVICE_ID);
	XGpio_SetDataDirection(&xgpio_LEDs, 1, 0x00000000);

	XGpio_Initialize(&xgpio_switches, XPAR_SLIDE_SWITCHES_8BITS_DEVICE_ID);
	XGpio_SetDataDirection(&xgpio_switches, 1, 0x000000FF);
}
Beispiel #7
0
int init_axi_gpio() {
    // Initialize the LED
    if (XGpio_Initialize(&XGpio_LED, LED_DEVICE_ID) != XST_SUCCESS)  {
        return XST_FAILURE;
    }

    // Set the direction for all signals to be outputs
    XGpio_SetDataDirection(&XGpio_LED, LED_CHANNEL, 0x0);

    // Set the GPIO outputs to low
    XGpio_DiscreteWrite(&XGpio_LED, LED_CHANNEL, 0x0);

    // Initialize the DEBUG output
    if (XGpio_Initialize(&XGpio_debug, DEBUG_DEVICE_ID) != XST_SUCCESS)  {
        return XST_FAILURE;
    }

    // Set the direction for all signals to be outputs
    XGpio_SetDataDirection(&XGpio_debug, DEBUG_CHANNEL, 0x0);

    // Set the GPIO outputs to low
    XGpio_DiscreteWrite(&XGpio_debug, DEBUG_CHANNEL, 0x0);

    // Initialize the Guard Trigger
    if (XGpio_Initialize(&XGpio_Guard_Trigger, GUARD_TRIGGER_DEVICE_ID) != XST_SUCCESS)  {
        return XST_FAILURE;
    }

    // Set the direction for all signals to be outputs
    XGpio_SetDataDirection(&XGpio_Guard_Trigger, GUARD_TRIGGER_CHANNEL, 0x0);

    // Set the GPIO outputs to low
    XGpio_DiscreteWrite(&XGpio_Guard_Trigger, GUARD_TRIGGER_CHANNEL, 0x0);

    // Initialize the BTN
    if (XGpio_Initialize(&XGpio_BTN, BTN_DEVICE_ID) != XST_SUCCESS)  {
        return XST_FAILURE;
    }

    // Set the direction for all signals to be inputs
    XGpio_SetDataDirection(&XGpio_BTN, BTN_CHANNEL, 0xF);

    // Initialize the SW
    if (XGpio_Initialize(&XGpio_SW, SW_DEVICE_ID) != XST_SUCCESS)  {
        return XST_FAILURE;
    }

    // Set the direction for all signals to be inputs
    XGpio_SetDataDirection(&XGpio_SW, SW_CHANNEL, 0xF);

    return 0;
}
void do_gpio_init(void) {
	FUNC_ENTER();
	// direction: Bits set to 0 are output and bits set to 1 are input.

    XGpio_Initialize(&m_gpioDIP8, XPAR_DIP_SWITCHES_8BIT_DEVICE_ID);
    XGpio_SetDataDirection(&m_gpioDIP8, 1, 0xFFFFFFFF);	// dip switches are inputs

    XGpio_Initialize(&m_gpioPBs5, XPAR_PUSH_BUTTONS_5BIT_DEVICE_ID);
	XGpio_SetDataDirection(&m_gpioPBs5, 1, 0xFFFFFFFF);	// push buttons are inputs

    XGpio_Initialize(&m_gpioLEDs8, XPAR_LEDS_8BIT_DEVICE_ID);
    XGpio_SetDataDirection(&m_gpioLEDs8, 1, 0x00000000);	// LEDs are outputs
}
Beispiel #9
0
static void prvSetupHardware( void )
{
portBASE_TYPE xStatus;
const unsigned char ucSetToOutput = 0U;

	/* Initialize the GPIO for the LEDs. */
	xStatus = XGpio_Initialize( &xOutputGPIOInstance, XPAR_LEDS_4BITS_DEVICE_ID );
	if( xStatus == XST_SUCCESS )
	{
		/* All bits on this channel are going to be outputs (LEDs). */
		XGpio_SetDataDirection( &xOutputGPIOInstance, ulGPIOOutputChannel, ucSetToOutput );

		/* Start with all LEDs off. */
		ucGPIOState = 0U;
		XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );
	}

	/* Initialise the GPIO for the button inputs. */
	if( xStatus == XST_SUCCESS )
	{
		xStatus = XGpio_Initialize( &xInputGPIOInstance, XPAR_PUSH_BUTTONS_4BITS_DEVICE_ID );
	}

	if( xStatus == XST_SUCCESS )
	{
		/* Install the handler defined in this task for the button input.
		*NOTE* The FreeRTOS defined xPortInstallInterruptHandler() API function
		must be used for this purpose. */
		xStatus = xPortInstallInterruptHandler( XPAR_MICROBLAZE_0_INTC_PUSH_BUTTONS_4BITS_IP2INTC_IRPT_INTR, prvButtonInputInterruptHandler, NULL );

		if( xStatus == pdPASS )
		{
			/* Set buttons to input. */
			XGpio_SetDataDirection( &xInputGPIOInstance, ulGPIOInputChannel, ~( ucSetToOutput ) );

			/* Enable the button input interrupts in the interrupt controller.
			*NOTE* The vPortEnableInterrupt() API function must be used for this
			purpose. */
			vPortEnableInterrupt( XPAR_MICROBLAZE_0_INTC_PUSH_BUTTONS_4BITS_IP2INTC_IRPT_INTR );

			/* Enable GPIO channel interrupts. */
			XGpio_InterruptEnable( &xInputGPIOInstance, ulGPIOInputChannel );
			XGpio_InterruptGlobalEnable( &xInputGPIOInstance );
		}
	}

	configASSERT( ( xStatus == pdPASS ) );
}
/*****
 * 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;
}
int main()
{


	XScuTimer_Config *TMRConfigPtr;     //timer config

    //Disable cache on OCM
	Xil_SetTlbAttributes(0xFFFF0000,0x14de2);           // S=b1 TEX=b100 AP=b11, Domain=b1111, C=b0, B=b0
	print("CPU1: starting\n\r");

	//GPIO Initilization
	XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
	XGpio_SetDataDirection(&Gpio, CHANNEL, 0x00);
	XGpio_DiscreteWrite(&Gpio,CHANNEL, 0xff);

    //timer initialisation
    TMRConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID);
    XScuTimer_CfgInitialize(&Timer, TMRConfigPtr,TMRConfigPtr->BaseAddr);
    XScuTimer_SelfTest(&Timer);

	//load the timer
    XScuTimer_LoadTimer(&Timer, TIMER_LOAD_VALUE);

    SetupInterruptSystem(&Intc, &Timer,TIMER_IRPT_INTR);

    XScuTimer_Start(&Timer);
    print("CPU1: configured\n\r");
    while(1){


    }

    return 0;
}
void init_mb_adc_parallel()
{
    //Initialize ADC Data GPIO
    XGpio_Initialize(&ADCData, XPAR_OPB_GPIO_0_DEVICE_ID);

    //Set lower 8 bits to input
    XGpio_SetDataDirection(&ADCData, 1, 0xFF);

    //Initialize ADC Control GPIO
    XGpio_Initialize(&ADCControl, XPAR_OPB_GPIO_1_DEVICE_ID);

    //Set direction, only input is busy signal
    XGpio_SetDataDirection(&ADCControl, 1, 0x2);

    XGpio_DiscreteWrite(&ADCControl, 1, MB_ADC_PARALLEL_RD);
}
Beispiel #13
0
/*
 * Setup the IO for the LED outputs.
 */
err_t 
led_init(void)
{
	portBASE_TYPE xStatus;
	const u8 ucSetToOutput = 0U;

	/* Initialise the GPIO for the LEDs. */
	xStatus = XGpio_Initialize(
			&xOutputGPIOInstance, 
			LED_GPIO_DEVICE_ID);

	if (xStatus == XST_SUCCESS) {
		/* All bits on this channel are going to be outputs (LEDs). */
		XGpio_SetDataDirection(
				&xOutputGPIOInstance, 
				uxGPIOOutputChannel, 
				ucSetToOutput);

		/* Start with all LEDs off. */
		ucGPIOState = 0U;
		XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, ucGPIOState );
	}
	
	/* FIXME return valid FlexCOS error code */
	return xStatus;
}
void init_GPIO_BUTTONS(XGpio *InstancePtr, u16 Device_ID)
{
    int Status;
    XGpio_Config *Config;

    Config = XGpio_LookupConfig(Device_ID);

    Status = XGpio_CfgInitialize(InstancePtr, Config, Config->BaseAddress);

    // Initialise GPIO devices
    Status = XGpio_Initialize(InstancePtr, Device_ID);



    // Set GPIO direction  (output for LEDs and input for BTNS)


    XGpio_SetDataDirection(InstancePtr, 1, 0xFF);
    if(Status != XST_FAILURE) {
        xil_printf("BUTTONS initialized!\n \r");
    }

    XGpio_InterruptEnable(&ButtonsInstancePtr, 1);
    XGpio_InterruptGlobalEnable(&ButtonsInstancePtr);

    // Initialize interrupt controller
    //IntcInitFunction(INTCONTROLLER_DEVICE_ID, InstancePtr);


}
Beispiel #15
0
int main(int argc, char *argv[])
{
        XGpio led_gpio;              /* LED Instance */

        /* Initialize LED GPIO settings */
        XGpio_Initialize(&led_gpio, XPAR_AXI_GPIO_0_DEVICE_ID);
        XGpio_SetDataDirection(&led_gpio, 1, 0);

        /* Output something via UART1, 115200 baudrate */
        printf("Start to blink led_gpio !!!\n\r");

        int led_value = 0x03;   /* default led_gpio value */
        while(1) {
                printf("led_gpio value set to 0x%X\n\r", led_value);

                /* Set GPIO Channel 1 value. */
                XGpio_DiscreteWrite(&led_gpio, 1 , led_value);

                /* sleep and change led_gpio value */
                simple_delay(10000000);
                led_value = ~led_value;
        }

        return 0;
}
int LEDOutputExample(void)
{

	volatile int Delay;
	int Status;
	int led = LED; /* Hold current LED value. Initialize to LED definition */

		/* GPIO driver initialization */
		Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}

		/*Set the direction for the LEDs to output. */
		XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0x00);

		/* Loop forever blinking the LED. */
			while (1) {
				/* Write output to the LEDs. */
				XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, led);

				/* Flip LEDs. */
				led = ~led;

				/* Wait a small amount of time so that the LED blinking is visible. */
				for (Delay = 0; Delay < LED_DELAY; Delay++);
			}

		return XST_SUCCESS; /* Ideally unreachable */
}
int main() {
    init_platform();

    // Initialize the GPIO peripherals.
	XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
	// Set the push button peripheral to be inputs.
	XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);
	// Enable the global GPIO interrupt for push buttons.
	XGpio_InterruptGlobalEnable(&gpPB);
	// Enable all interrupts in the push button peripheral.
	XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF);

    interrupts_init();

    print("made it past interrupts_init\n\r");

    // apparently we don't need to init it, just HardReset
    XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_ExtendedAudioStat, 1);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCM_DAC_Rate, AC97_PCM_RATE_11025_HZ);
    XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_MasterVol, AC97_VOL_MAX);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCMOutVol, AC97_VOL_MAX);


    while (1);

    cleanup_platform();

    return 0;
}
Beispiel #18
0
/***************************************************************************//**
 * @brief gpio_direction
*******************************************************************************/
int32_t gpio_direction(uint8_t pin, uint8_t direction)
{
#ifdef _XPARAMETERS_PS_H_
	XGpioPs_SetDirectionPin(&gpio_instance, pin, direction);
	XGpioPs_SetOutputEnablePin(&gpio_instance, pin, 1);
#else
	uint32_t channel = 1;
	uint32_t config	 = 0;

	/* We assume that pin 32 is the first pin from channel 2 */
	if (pin >= 32) {
		channel = 2;
		pin -= 32;
	}

	config = XGpio_GetDataDirection(&gpio_instance, channel);
	if (direction) {
		config &= ~(1 << pin);
	} else {
		config |= (1 << pin);
	}
	XGpio_SetDataDirection(&gpio_instance, channel, config);
#endif

	return 0;
}
/**
*
* This function  performs a test on the GPIO driver/device with the GPIO
* configured as INPUT
*
* @param	 DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from
*			  xparameters.h
* @param	 DataRead is the pointer where the data read from GPIO Input is
*			  returned
*
* @return	XST_SUCCESS if the Test is successful, otherwise XST_FAILURE
*
* @note	  None.
*
******************************************************************************/
int GpioInputExample(u16 DeviceId, u32 *DataRead)
{
	 int Status;

	 /*
	  * Initialize the GPIO driver so that it's ready to use,
	  * specify the device ID that is generated in xparameters.h
	  */
	 Status = XGpio_Initialize(&GpioInput, DeviceId);
	 if (Status != XST_SUCCESS) {
		  return XST_FAILURE;
	 }

	 /*
	  * Set the direction for all signals to be inputs
	  */
	 XGpio_SetDataDirection(&GpioInput, LED_CHANNEL, 0xFFFFFFFF);

	 /*
	  * Read the state of the data so that it can be  verified
	  */
	 *DataRead = XGpio_DiscreteRead(&GpioInput, LED_CHANNEL);

	 return XST_SUCCESS;

}
/**
* This function is the main function of the GPIO example.  It is responsible
* for initializing the GPIO device, setting up interrupts and providing a
* foreground loop such that interrupt can occur in the background.
*
* @param	None.
*
* @return
*		- XST_SUCCESS to indicate success.
*		- XST_FAILURE to indicate Failure.
*
* @note		None.
*
*
*****************************************************************************/
int main(void)
{
	int Status;

	/* Initialize the GPIO driver. If an error occurs then exit */

	Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test on the GPIO.  This is a minimal test and only
	 * verifies that there is not any bus error when reading the data
	 * register
	 */
	XGpio_SelfTest(&Gpio);

	/*
	 * Setup direction register so the switch is an input and the LED is
	 * an output of the GPIO
	 */
	XGpio_SetDataDirection(&Gpio, BUTTON_CHANNEL, GPIO_ALL_BUTTONS);
	XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~GPIO_ALL_LEDS);

	/* Sequence the LEDs to show this example is starting to run */

	SequenceLeds();

	/*
	 * Setup the interrupts such that interrupt processing can occur. If
	 * an error occurs then exit
	 */
	Status = SetupInterruptSystem();
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Loop forever while the button changes are handled by the interrupt
	 * level processing
	 */
	while (1) {
	}

	return XST_SUCCESS;
}
Beispiel #21
0
static int hw_init()
{
#if defined(CYGHWR_HAL_VIRTEX_BOARD_ML403)
    XGpio_SetDataDirection( &gpio_manager_device, 1, 0xFFFFFE00 );      // lower nine bits are outpus
#elif defined(CYGHWR_HAL_VIRTEX_BOARD_XUP)
    XGpio_SetDataDirection( &gpio_manager_device, 1, 0xFFFFFFF0 );      // lower four bits are outputs
#else
#error Unsupported board.
#endif

#if defined(UPBHWR_VIRTEX4_GPIOINTR)
    // turn on the global interrupts by default
    XGpio_InterruptGlobalEnable(&gpio_manager_device);
#endif
    
    return 0;
}
Beispiel #22
0
void init_mb_dipsw()
{
    //Initialize ADC Data GPIO
    XGpio_Initialize(&DipSW, XPAR_DIPSWS_4BIT_DEVICE_ID);

    //Set lower 8 bits to input
    XGpio_SetDataDirection(&DipSW, 1, 0xFF);
}
Beispiel #23
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 #24
0
int init_gpio(XGpio *GpioInstancePtr){
	int Status;
	Status = XGpio_Initialize(GpioInstancePtr, GPIO_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XGpio_SetDataDirection(GpioInstancePtr, LED_CHANNEL, 0x0);
	return XST_SUCCESS;
}
Beispiel #25
0
int main(void){

	printf ("-- Entering main () -- \r\n");

	int status;
	int statusAll = 1;
	XGpio dip, leds;
	int i, dip_check;

	int count=0;

	status = XGpio_Initialize (&dip, XPAR_DIP_SWITCHES_8BIT_DEVICE_ID);
	if (status != XST_SUCCESS){
		statusAll = 0;
		printf("DIP switch initialization failure! \r \n");
	}
	else {
		XGpio_SetDataDirection (&dip, 1, 0xffffffff);\
		printf("DIP switch initialization success. \r \n");
	}
	status = XGpio_Initialize(&leds, XPAR_LEDS_8BIT_DEVICE_ID);
	if (status != XST_SUCCESS){
			statusAll = 0;
			printf("LEDs initialization failure! \r \n");
		}
	else {
		XGpio_SetDataDirection (&leds, 1, 0x00000000);
		printf("LEDs initialization Success! \r \n");
	}
	while(1){

		dip_check = XGpio_DiscreteRead(&dip,1);
		printf("Prog2: DIP switches status %x \r\n", dip_check);

		XGpio_DiscreteWrite (&leds, 1, count);

		for(i=0; i<999999; i++);

		count++;
	}

	printf("--Exiting main() -- \r\n");
	return 0;
}
Beispiel #26
0
int status_init(void) {
  int rv;
  // initialize the GPIO hardware
	XGpio_Initialize(&LED, XPAR_XPS_GPIO_1_DEVICE_ID );
	XGpio_SetDataDirection(&LED, 1, 0 );
  XGpio_DiscreteWrite(&LED,1,0x1F);
	
	XGpio_Initialize(&JP1, XPAR_XPS_GPIO_0_DEVICE_ID );
	XGpio_SetDataDirection(&JP1, 1, 0xF );

  status_set( 0, s_init );
  
  #ifdef __XMK__
  // I think using pthread_create is OK since this thread does not access any LwIP stuff.
  return pthread_create( &status_tid, NULL, status_thread, NULL );
  #else
    return 0;
  #endif
}
Beispiel #27
0
void init_all(void) {
  XIntc_Initialize(&intc, XPAR_XPS_INTC_0_DEVICE_ID);
  microblaze_enable_interrupts();
  XIntc_mMasterEnable(XPAR_INTC_0_BASEADDR);
  XUartLite_mEnableIntr(XPAR_UARTLITE_0_BASEADDR);
  ////  пецхярпюжхъ  напюанрвхйнб ////////////////////////////////////////////
  XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
                        XPAR_INTC_0_UARTLITE_0_VEC_ID,
                        (XInterruptHandler)handler_RS232,
                        (void *)0);
  XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
                        XPAR_INTC_0_TMRCTR_0_VEC_ID,
                        (XInterruptHandler)handler_Timer,
                        (void *)0);
  ///////////////////////////////////////////////////////////////////////////////
  //// мюярпнийю  рюилепю //////////////////////////////////////////////////////
  XTmrCtr_mSetLoadReg(XPAR_XPS_TIMER_0_BASEADDR,
                      0,
                      0x61a8 //(25 MHz / 25000 = 1mS
                    //0x124F8//(75 MHz : 75.000 = 1 mS
                      );
  XIntc_mEnableIntr(XPAR_INTC_0_BASEADDR,
              //    XPAR_XPS_TIMER_0_INTERRUPT_MASK |
                    XPAR_XPS_UARTLITE_0_INTERRUPT_MASK);
  XTmrCtr_mSetControlStatusReg(XPAR_XPS_TIMER_0_BASEADDR,
                               0,
                               XTC_CSR_ENABLE_TMR_MASK |
                               XTC_CSR_ENABLE_INT_MASK |
                               XTC_CSR_AUTO_RELOAD_MASK |
                               XTC_CSR_DOWN_COUNT_MASK);
  /////////////////////////////////////////////////////////////////////////////////
  ///////// мюярпнийю  сярпниярб  ббндю-бшбндю ////////////////////////////////////
  XGpio_Initialize(&photo, XPAR_XPS_GPIO_0_DEVICE_ID);
  XGpio_Initialize(&ircom, XPAR_XPS_GPIO_1_DEVICE_ID);
  XGpio_Initialize(&kt,    XPAR_XPS_GPIO_2_DEVICE_ID);

  XGpio_SetDataDirection(&photo, 1, 0xffffffff);  // ББНД
  XGpio_SetDataDirection(&photo, 2, 0x00);        // БШБНД
  XGpio_SetDataDirection(&ircom, 1, 0x00);        // БШБНД
  XGpio_SetDataDirection(&ircom, 2, 0x00);        // БШБНД
  XGpio_SetDataDirection(&kt,    1, 0x00);        // БШБНД
};
Beispiel #28
0
/*
 * Initialize GPIO
 */
int initGpio() {
//Variables
	int status;

//Initialize GPIOs
	status = XGpio_Initialize(&outGpio, OUTGPIO_DEVICE_ID);
	status = XGpio_Initialize(&inGpio, INGPIO_DEVICE_ID);

//Set Direction
	XGpio_SetDataDirection(&outGpio, LED_CHANNEL, DIR_OUT);
	XGpio_SetDataDirection(&inGpio, 1, DIR_IN);
	XGpio_SetDataDirection(&inGpio, 2, DIR_IN);

//Clear LEDs
	if (status == XST_SUCCESS) {
		clearLEDs(status, &outGpio);
	}

	return XST_SUCCESS;
}
Beispiel #29
0
/**
*
* This function does a minimal test on the GPIO device configured as OUTPUT
* and driver as a  example.
*
*
* @param    DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from
*           xparameters.h
* @param    GpioWidth is the width of the GPIO
*
* @return   XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note     None
*
****************************************************************************/
void GpioOutputExample(Xuint16 DeviceId, Xuint32 GpioWidth)
{
    volatile int Delay;
    Xuint32 LedBit;
    Xuint32 LedLoop;
    XStatus Status;
    int numTimes = 1;

    /*
     * Initialize the GPIO driver so that it's ready to use,
     * specify the device ID that is generated in xparameters.h
     */
    Status = XGpio_Initialize(&GpioOutput, DeviceId);
    if (Status != XST_SUCCESS)
    {
        print("Gpio Instance Didn't Initialize!\r\n");
    }


    /*
     * Set the direction for all signals to be outputs
     */
    XGpio_SetDataDirection(&GpioOutput, 1, 0x0);

    /*
     * Set the GPIO outputs to low
     */
    XGpio_DiscreteWrite(&GpioOutput, 1, 0x0);
    while (numTimes > 0) {
        for (LedBit = 0x0; LedBit < GpioWidth; LedBit++) {
            for (LedLoop = 0; LedLoop < 1; LedLoop++) {

                /*
                 * Set the GPIO Output to High
                 */
                XGpio_DiscreteWrite(&GpioOutput, 1, 1 << LedBit);

                /*
                 * Wait a small amount of time so the LED is visible
                 */
                for (Delay = 0; Delay < (500000/2); Delay++)
                {
                    // Dummy read; to ensure the delay has no Cache effect
                    XGpio_DiscreteRead(&GpioOutput, 1);
                }
                /*
                 * Clear the GPIO Output
                 */
                XGpio_DiscreteClear(&GpioOutput, 1, 1 << LedBit);
            }
        }
        numTimes--;
    }
}
void initInterrupts()
{
	// Initialize the GPIO peripherals. NOTE: We wait to do this till after the HDMI to ensure that nothing happens before the HDMI is enabled.
	XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
	// Set the push button peripheral to be inputs.
	XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);

	XGpio_Initialize(&gpswitches, XPAR_SLIDE_SWITCHES_8BITS_DEVICE_ID);
	XGpio_SetDataDirection(&gpswitches, 1, 0x000000FF);

	microblaze_register_handler(interrupt_handler_dispatcher, NULL);
	XIntc_EnableIntr(XPAR_INTC_0_BASEADDR,
			(XPAR_PIT_0_INTERRUPT_MASK
		   | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK
		   | XPAR_AXI_AC97_0_INTERRUPT_MASK
		   | XPAR_PS2CTRL_0_INTERRUPT_MASK));

	XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);
	microblaze_enable_interrupts();
}