Esempio n. 1
0
void JtagInitGpio ()
{
	js_printf("===== Initializing PS GPIO pins...\n\r");
	XGpioPs_Config *ptrConfigPtrPs = XGpioPs_LookupConfig(0);
	XGpioPs_CfgInitialize(&structXGpioPs,ptrConfigPtrPs,ptrConfigPtrPs->BaseAddr);

	/* Unlock the SLCR block */
	Xil_Out32 (0xF8000000 + 0x8, 0xDF0D);

	GpioConfig((GPIO_BASE_ADDR+(g_mio_jtag_tdi*4)),GPIO_MASK_VAL, GPIO_TDI_VAL);
    GpioConfig((GPIO_BASE_ADDR+(g_mio_jtag_tdo*4)),GPIO_MASK_VAL, GPIO_TDO_VAL);
    GpioConfig((GPIO_BASE_ADDR+(g_mio_jtag_tck*4)),GPIO_MASK_VAL, GPIO_TCK_VAL);
    GpioConfig((GPIO_BASE_ADDR+(g_mio_jtag_tms*4)),GPIO_MASK_VAL, GPIO_TMS_VAL);
    GpioConfig((GPIO_BASE_ADDR+(g_mio_jtag_mux_sel*4)),GPIO_MASK_VAL, GPIO_MUX_SEL_VAL);

	XGpioPs_SetDirectionPin(&structXGpioPs,MIO_TCK,1);
	XGpioPs_SetOutputEnablePin(&structXGpioPs,MIO_TCK,1);

	XGpioPs_SetDirectionPin(&structXGpioPs,MIO_TMS,1);
	XGpioPs_SetOutputEnablePin(&structXGpioPs,MIO_TMS,1);

	XGpioPs_SetDirectionPin(&structXGpioPs,MIO_TDI,1);
	XGpioPs_SetOutputEnablePin(&structXGpioPs,MIO_TDI,1);

	XGpioPs_SetDirectionPin(&structXGpioPs,MIO_MUX_SELECT,1);
	XGpioPs_SetOutputEnablePin(&structXGpioPs,MIO_MUX_SELECT,1);
	XGpioPs_WritePin(&structXGpioPs, MIO_MUX_SELECT, g_mux_sel_def_val);
	
	XGpioPs_SetDirectionPin(&structXGpioPs,MIO_TDO,0);
	XGpioPs_SetOutputEnablePin(&structXGpioPs,MIO_TDO,0);
} /* initGpio() */
Esempio n. 2
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;
}
Esempio n. 3
0
/***************************************************************************//**
 * @brief gpio_direction
*******************************************************************************/
void gpio_direction(uint8_t pin, uint8_t direction)
{
#ifdef _XPARAMETERS_PS_H_
	XGpioPs_SetDirectionPin(&gpio_instance, pin, direction);
	XGpioPs_SetOutputEnablePin(&gpio_instance, pin, 1);
#endif
}
/*-----------------------------------------------------------*/
void prvSetGpioHardware( void )
{
 	int Status;
 	/*
 	 * Initialize the GPIO driver.
 	 */
 	ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
 	Status = XGpioPs_CfgInitialize(&Gpio, ConfigPtr,
 					ConfigPtr->BaseAddr);
 	if (Status != XST_SUCCESS) {
 		xil_printf("GPIO Initialize failed\n");
 	}

 	/*
 	 * Set the direction for the pin to be output and
 	 * Enable the Output enable for the LED Pin.
 	 */
 	XGpioPs_SetDirectionPin(&Gpio, OUTPUT_PIN, 1);
 	XGpioPs_SetOutputEnablePin(&Gpio, OUTPUT_PIN, 1);

 	/*
 	 * Set the GPIO output to be low.
 	 */
 	XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x0);
}
int main()
{
	XGpioPs_Config *GPIOConfigPtr;      //gpio config
	//int io;



	init_platform();

	//GPIO Initilization
	GPIOConfigPtr = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);
	XGpioPs_CfgInitialize(&Gpio, GPIOConfigPtr,GPIOConfigPtr->BaseAddr);
	//set direction and enable output

	XGpioPs_SetDirectionPin(&Gpio, intpin, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, intpin, 1);
	XGpioPs_WritePin(&Gpio, intpin, 0);

    //set direction input pin
    XGpioPs_SetDirectionPin(&Gpio, pbsw, 0);

    SetupInterruptSystem(&Intc,&FPGA,FPGA_INT,&Gpio, GPIO_INTERRUPT_ID);

    printf("system running\n\r");
while(1){
}

    return 0;

}
Esempio n. 6
0
/***************************************************************************//**
 * @brief gpio_direction
*******************************************************************************/
void 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 config = 0;
	uint32_t tri_reg_addr;

	if (pin >= 32) {
		tri_reg_addr = XGPIO_TRI2_OFFSET;
		pin -= 32;
	} else
		tri_reg_addr = XGPIO_TRI_OFFSET;

	config = Xil_In32((gpio_config->BaseAddress + tri_reg_addr));
	if(direction)
	{
		config &= ~(1 << pin);
	}
	else
	{
		config |= (1 << pin);
	}
	Xil_Out32((gpio_config->BaseAddress + tri_reg_addr), config);
#endif
}
Esempio n. 7
0
/*****************************************************************************
*
* This function sets GPIO LED device state configured as OUTPUT.
*
* @param	None.
*
* @return	0 if successful, else -1.
*
* @note		None.
*
****************************************************************************/
int ps_gpio_set_led(zed_ali3_controller_demo_t *pDemo, int led_number, int led_state)
{
    /*
     * Set the direction for the GPIO pin to be output and
     * Enable the Output enable for the LED Pin.
     */
#ifdef PS_GPIO_USER_LED0
    if (led_number == 0)
    {
        XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), PS_GPIO_USER_LED0, 1);
        XGpioPs_SetOutputEnablePin(&(pDemo->gpio_driver), PS_GPIO_USER_LED0, 1);
    }
#ifdef PS_GPIO_USER_LED1
    else if (led_number == 1)
    {
    	XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), PS_GPIO_USER_LED1, 1);
        XGpioPs_SetOutputEnablePin(&(pDemo->gpio_driver), PS_GPIO_USER_LED1, 1);
    }
#endif
#else
    XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), (PS_GPIO_USER_LED_START + led_number), 1);
    XGpioPs_SetOutputEnablePin(&(pDemo->gpio_driver), (PS_GPIO_USER_LED_START + led_number), 1);
#endif

    /*
     * Set the GPIO output to the specified state.
     */
#ifdef PS_GPIO_USER_LED0
    if (led_number == 0)
    {
        XGpioPs_WritePin(&(pDemo->gpio_driver), PS_GPIO_USER_LED0, led_state);
    }
#ifdef PS_GPIO_USER_LED1
    else if (led_number == 1)
    {
    	XGpioPs_WritePin(&(pDemo->gpio_driver), PS_GPIO_USER_LED1, led_state);
    }
#endif
#else
    XGpioPs_WritePin(&(pDemo->gpio_driver), (PS_GPIO_USER_LED_START + led_number), led_state);
#endif

    return 0;
}
Esempio n. 8
0
/**
 * @brief Enable the output direction of the specified GPIO.
 * @param desc - The GPIO descriptor.
 * @param value - The value.
 *                Example: GPIO_HIGH
 *                         GPIO_LOW
 * @return SUCCESS in case of success, FAILURE otherwise.
 */
int32_t gpio_direction_output(struct gpio_desc *desc,
			      uint8_t value)
{
	XGpioPs_SetDirectionPin(&desc->instance, desc->number, 1);

	XGpioPs_SetOutputEnablePin(&desc->instance, desc->number, 1);

	XGpioPs_WritePin(&desc->instance, desc->number, value);

	return SUCCESS;
}
Esempio n. 9
0
void vParTestInitialise( void )
{
XGpioPs_Config *pxConfigPtr;
BaseType_t xStatus;

	/* Initialise the GPIO driver. */
	pxConfigPtr = XGpioPs_LookupConfig( XPAR_XGPIOPS_0_DEVICE_ID );
	xStatus = XGpioPs_CfgInitialize( &xGpio, pxConfigPtr, pxConfigPtr->BaseAddr );
	configASSERT( xStatus == XST_SUCCESS );
	( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */

	/* Enable outputs and set low. */
	XGpioPs_SetDirectionPin( &xGpio, partstLED_OUTPUT, partstDIRECTION_OUTPUT );
	XGpioPs_SetOutputEnablePin( &xGpio, partstLED_OUTPUT, partstOUTPUT_ENABLED );
	XGpioPs_WritePin( &xGpio, partstLED_OUTPUT, 0x0 );
}
Esempio n. 10
0
/*****************************************************************************
*
* This function sets GPIO LED device state configured as OUTPUT.
*
* @param	None.
*
* @return	0 if successful, else -1.
*
* @note		None.
*
****************************************************************************/
int ps_gpio_set_led(zed_ali3_controller_demo_t *pDemo, int led_number, int led_state)
{
    /*
     * Set the direction for the GPIO pin to be output and
     * Enable the Output enable for the LED Pin.
     */
    XGpioPs_SetDirectionPin(&(pDemo->gpio_driver), (PS_GPIO_USER_LED_START + led_number), 1);
    XGpioPs_SetOutputEnablePin(&(pDemo->gpio_driver), (PS_GPIO_USER_LED_START + led_number), 1);

    /*
     * Set the GPIO output to the specified state.
     */
    XGpioPs_WritePin(&(pDemo->gpio_driver), (PS_GPIO_USER_LED_START + led_number), led_state);

    return 0;
}
void vApplicationSetupHardware( void )
{
	XScuGic * InterruptController = prvGetInterruptControllerInstance();
	int iPinNumberEMIO = 54;
	u32 uPinDirectionEMIO = 0x0;
	u32 uPinDirection = 0x1;
	print("##### Application Starts #####\n\r");
	print("\r\n");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-1 :AXI GPIO Initialization
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	u32 xStatus = XGpio_Initialize(&GPIOInstance_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);
	if(XST_SUCCESS != xStatus)
		print("GPIO INIT FAILED\n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-2 :AXI GPIO Set the Direction
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XGpio_SetDataDirection(&GPIOInstance_Ptr, 1,1);
	//set up GPIO interrupt
	XGpio_InterruptEnable(&GPIOInstance_Ptr, 0x1);
	XGpio_InterruptGlobalEnable(&GPIOInstance_Ptr);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-3 :AXI Timer Initialization
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	xStatus = XTmrCtr_Initialize(&TimerInstancePtr, XPAR_AXI_TIMER_0_DEVICE_ID);
	if(XST_SUCCESS != xStatus)
		print("TIMER INIT FAILED \n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-4 :Set Timer Handler
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XTmrCtr_SetHandler(&TimerInstancePtr, Timer_InterruptHandler, &TimerInstancePtr);
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-5 :Setting timer Reset Value
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XTmrCtr_SetResetValue(&TimerInstancePtr, 0, 0x0F000000);
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-6 :Setting timer Option (Interrupt Mode And Auto Reload )
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XTmrCtr_SetOptions(&TimerInstancePtr, XPAR_AXI_TIMER_0_DEVICE_ID, (XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION));
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-7 :PS GPIO Intialization
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
	if(GpioConfigPtr == NULL)
		print(" PS GPIO config lookup FAILED \n\r");
	xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr, GpioConfigPtr, GpioConfigPtr->BaseAddr);
	if(XST_SUCCESS != xStatus)
		print(" PS GPIO INIT FAILED \n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-8 :PS GPIO pin setting to Output
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XGpioPs_SetDirectionPin(&psGpioInstancePtr, 54, uPinDirection);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, 54,1);
//	XGpioPs_SetDirectionPin(&psGpioInstancePtr, 8,uPinDirection);
//	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, 8, 1);
	print(" INITED MIO \n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-9 :EMIO PIN Setting to Input port
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XGpioPs_SetDirectionPin(&psGpioInstancePtr,	iPinNumberEMIO, uPinDirectionEMIO);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberEMIO, 0);
	//XGpioPs_IntrEnable(&psGpioInstancePtr, XGPIOPS_BANK2, 0x1);
	// instance, bank, edge, rising, single edge
	XGpioPs_IntrEnablePin(&psGpioInstancePtr, iPinNumberEMIO);
	XGpioPs_SetIntrType(&psGpioInstancePtr, XGPIOPS_BANK2, 1, 1, 0);
	XGpioPs_SetCallbackHandler(&psGpioInstancePtr, (void *) &psGpioInstancePtr, EMIO_Button_InterruptHandler);

	print(" INITED FIRST EMIO \n\r");
	// EMIO output
	XGpioPs_SetDirectionPin(&psGpioInstancePtr, 55, uPinDirection);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, 55, 1);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-10 : SCUGIC interrupt controller Initialization
	//Registration of the Timer ISR
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	u32 Status = XScuGic_Connect(InterruptController,
							 XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR,
							 (Xil_ExceptionHandler)XTmrCtr_InterruptHandler,
							 (void *)&TimerInstancePtr);

	if (Status != XST_SUCCESS) {
		print(" Error connection timer interrupt \n \r");
	}

	Status = XScuGic_Connect(InterruptController,
							XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR,
							 (Xil_ExceptionHandler)Button_InterruptHandler,
							 (void *)&GPIOInstance_Ptr);
	if (Status != XST_SUCCESS) {
		print(" Error connection button interrupt \n \r");
	}

	/*
	 * Connect the device driver handler that will be called when an
	 * interrupt for the device occurs, the handler defined above performs
	 * the specific interrupt processing for the device.
	 */
	Status = XScuGic_Connect(InterruptController,
							XPS_GPIO_INT_ID,
							(Xil_ExceptionHandler)XGpioPs_IntrHandler,
							(void *)&psGpioInstancePtr);
	if (Status != XST_SUCCESS) {
		print(" Error connection button EMIO interrupt \n \r");
	}

	/*
	* Enable the interrupt for the device and then cause (simulate) an
	* interrupt so the handlers will be called
	*/
	XScuGic_Enable(InterruptController, XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR);
	XScuGic_Enable(InterruptController, XPS_GPIO_INT_ID);
	XScuGic_Enable(InterruptController, XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR);

	// turn off all LEDs
	XGpioPs_WritePin(&psGpioInstancePtr, iPinNumber, 0);
	XGpioPs_WritePin(&psGpioInstancePtr, 55, 0);

	print(" End of init \n\r");
}
Esempio n. 12
0
/**
*
* This function does a minimal test on the GPIO device configured as OUTPUT.
*
* @param	None.
*
* @return	- XST_SUCCESS if the example has completed successfully.
*		- XST_FAILURE if the example has failed.
*
* @note		None.
*
****************************************************************************/
static int GpioOutputExample(void)
{
	u32 Data;
	volatile int Delay;
	u32 LedLoop;

	/*
	 * Set the direction for the pin to be output and
	 * Enable the Output enable for the LED Pin.
	 */
	XGpioPs_SetDirectionPin(&Gpio, OUTPUT_PIN, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, OUTPUT_PIN, 1);

	/*
	 * Set the GPIO output to be low.
	 */
	XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x0);


	for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop ++) {


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

#endif
		/*
		 * Set the GPIO Output to High.
		 */
		XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x1);

		/*
		 * Read the state of the data and verify. If the data
		 * read back is not the same as the data written then
		 * return FAILURE.
		 */
		Data = XGpioPs_ReadPin(&Gpio, OUTPUT_PIN);
		if (Data != 1 ) {
			return XST_FAILURE;
		}

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

#endif

		/*
		 * Clear the GPIO Output.
		 */
		XGpioPs_WritePin(&Gpio, OUTPUT_PIN, 0x0);

		/*
		 * Read the state of the data and verify. If the data
		 * read back is not the same as the data written then
		 * return FAILURE.
		 */
		Data = XGpioPs_ReadPin(&Gpio, OUTPUT_PIN);
		if (Data != 0) {
			return XST_FAILURE;
		}
	}
	return XST_SUCCESS;
}
Esempio n. 13
0
int main (void) 
{

      XGpio sw, led;
	  int i, pshb_check, sw_check;
	  XGpioPs_Config*GpioConfigPtr;
	  int xStatus;
	  int iPinNumberEMIO = 54;
	  u32 uPinDirectionEMIO = 0x0;
	  u32 uPinDirection = 0x1;
	
	  xil_printf("-- Start of the Program --\r\n");

	  // AXI GPIO switches Intialization
	  XGpio_Initialize(&sw, XPAR_SWITCHES_DEVICE_ID);

	  // AXI GPIO leds Intialization
	  XGpio_Initialize(&led, XPAR_LEDS_DEVICE_ID);

	  // PS GPIO Intialization
	  GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
	  if(GpioConfigPtr == NULL)
	    return XST_FAILURE;
	  xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr,
	      GpioConfigPtr,
	      GpioConfigPtr->BaseAddr);
	  if(XST_SUCCESS != xStatus)
	    print(" PS GPIO INIT FAILED \n\r");
	  //PS GPIO pin setting to Output
	  XGpioPs_SetDirectionPin(&psGpioInstancePtr, iPinNumber,uPinDirection);
	  XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumber,1);
	  //EMIO PIN Setting to Input port
	  XGpioPs_SetDirectionPin(&psGpioInstancePtr,
	      iPinNumberEMIO,uPinDirectionEMIO);
	  XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberEMIO,0);

	  xil_printf("-- Press BTNR (Zedboard) or BTN3 (Zybo) to see the LED light --\r\n");
	  xil_printf("-- Change slide switches to see corresponding output on LEDs --\r\n");
	  xil_printf("-- Set slide switches to 0x0F to exit the program --\r\n");

	  while (1)
	  {
		  sw_check = XGpio_DiscreteRead(&sw, 1);
		  XGpio_DiscreteWrite(&led, 1, sw_check);
	      pshb_check = XGpioPs_ReadPin(&psGpioInstancePtr,iPinNumberEMIO);
          XGpioPs_WritePin(&psGpioInstancePtr,iPinNumber,pshb_check);
          if((sw_check & 0x0f)==0x0F)
        	  break;
		  for (i=0; i<9999999; i++); // delay loop
	   }
	  xil_printf("-- End of Program --\r\n");
#ifdef MULTIBOOT
	  // Driver Instantiations
	  XDcfg XDcfg_0;
	  u32 MultiBootReg = 0;
	  #define PS_RST_CTRL_REG	(XPS_SYS_CTRL_BASEADDR + 0x200)
	  #define PS_RST_MASK	0x1	/* PS software reset */
	  #define SLCR_UNLOCK_OFFSET 0x08

	  // Initialize Device Configuration Interface
	  XDcfg_Config *Config = XDcfg_LookupConfig(XPAR_XDCFG_0_DEVICE_ID);
	  XDcfg_CfgInitialize(&XDcfg_0, Config, Config->BaseAddr);

	  MultiBootReg = 0; // Once done, boot the master image stored at 0xfc00_0000
	  Xil_Out32(0xF8000000 + SLCR_UNLOCK_OFFSET, 0xDF0DDF0D); // unlock SLCR
	  XDcfg_WriteReg(XDcfg_0.Config.BaseAddr, XDCFG_MULTIBOOT_ADDR_OFFSET, MultiBootReg); // write to multiboot reg
	  // synchronize
		__asm__(
			"dsb\n\t"
			"isb"
		);
      Xil_Out32(PS_RST_CTRL_REG, PS_RST_MASK);
#endif
	  return 0;
}
int main()
{

	XSpiPs_Config *SpiConfig_EMIO;
	XGpioPs_Config *GPIOConfigPtr;    //gpio config

	int delay;
	u8 cmd[1];
	int byte_i, temp;
	int loop;
    init_platform();

    printf("SPI Demo MicroZed Chronicles\n\r");

    SpiConfig_EMIO = XSpiPs_LookupConfig((u16)SPI_EMIO);
    XSpiPs_CfgInitialize(&SpiInstance_EMIO, SpiConfig_EMIO,SpiConfig_EMIO->BaseAddress);
    XSpiPs_SetOptions(&SpiInstance_EMIO,XSPIPS_MASTER_OPTION |  XSPIPS_FORCE_SSELECT_OPTION);
    XSpiPs_SetClkPrescaler(&SpiInstance_EMIO, XSPIPS_CLK_PRESCALE_256);

    GPIOConfigPtr = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);
    XGpioPs_CfgInitialize(&Gpio, GPIOConfigPtr,GPIOConfigPtr->BaseAddr);

    //set direction and enable output
    XGpioPs_SetDirectionPin(&Gpio, sig, 1);
    XGpioPs_SetOutputEnablePin(&Gpio, sig, 1);

    XGpioPs_SetDirectionPin(&Gpio, res, 1);
    XGpioPs_SetOutputEnablePin(&Gpio, res, 1);

    XGpioPs_SetDirectionPin(&Gpio, vdd, 1);
    XGpioPs_SetOutputEnablePin(&Gpio, vdd, 1);

    XGpioPs_SetDirectionPin(&Gpio, bat, 1);
    XGpioPs_SetOutputEnablePin(&Gpio, bat, 1);

    XGpioPs_SetDirectionPin(&Gpio, dc, 1);
    XGpioPs_SetOutputEnablePin(&Gpio, dc, 1);

    XGpioPs_WritePin(&Gpio, sig, 0);
    XGpioPs_WritePin(&Gpio, res, 0);
    XGpioPs_WritePin(&Gpio, vdd, 1);
    XGpioPs_WritePin(&Gpio, bat, 1);
    XGpioPs_WritePin(&Gpio, dc, 1);

    XGpioPs_WritePin(&Gpio, vdd, 0);
	for( delay = 0; delay < DELAY; delay++)//wait
	{}
    XGpioPs_WritePin(&Gpio, res, 1);
    config_oled();
    XGpioPs_WritePin(&Gpio, bat, 0);
    blank_oled();//clear screen


//output page 1
 for(loop=0;loop<16;loop++){
    	temp = (line_1[loop] * 8);
    	for(byte_i=0;byte_i<8;byte_i++){
    		data_conv[byte_i] = font[temp+byte_i];
    	}
    	conv_alg(data_conv); //convert to array
    	for(byte_i=0;byte_i<8;byte_i++){
    		page_0[(line_start-(char_size*loop))-byte_i] = results[byte_i];
    	}
 }
    cmd[0] = (u8) 0xB0;
    XGpioPs_WritePin(&Gpio, dc, 0);
    XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
    XSpiPs_PolledTransfer(&SpiInstance_EMIO, cmd, NULL, 1);
    XGpioPs_WritePin(&Gpio, dc, 1);
    XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
    XSpiPs_PolledTransfer(&SpiInstance_EMIO, page_0, NULL, 128);

//output page 2
    for(loop=0;loop<16;loop++){
    //loop =0;
       	temp = (line_2[loop] * 8);
       	for(byte_i=0;byte_i<8;byte_i++){
       		data_conv[byte_i] = font[temp+byte_i];
       	}
       	conv_alg(data_conv); //convert to array
       	for(byte_i=0;byte_i<8;byte_i++){
       		page_1[(line_start-(char_size*loop))-byte_i] = results[byte_i];
       	}
    }
       cmd[0] = (u8) 0xB1;
       XGpioPs_WritePin(&Gpio, dc, 0);
       XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
       XSpiPs_PolledTransfer(&SpiInstance_EMIO, cmd, NULL, 1);
       XGpioPs_WritePin(&Gpio, dc, 1);
       XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
       XSpiPs_PolledTransfer(&SpiInstance_EMIO, page_1, NULL, 128);

//output page 3
   for(loop=0;loop<16;loop++){
   //loop =0;
		temp = (line_3[loop] * 8);
		for(byte_i=0;byte_i<8;byte_i++){
			data_conv[byte_i] = font[temp+byte_i];
		}
		conv_alg(data_conv); //convert to array
		for(byte_i=0;byte_i<8;byte_i++){
			page_2[(line_start-(char_size*loop))-byte_i] = results[byte_i];
		}
   }
	  cmd[0] = (u8) 0xB2;
	  XGpioPs_WritePin(&Gpio, dc, 0);
	  XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
	  XSpiPs_PolledTransfer(&SpiInstance_EMIO, cmd, NULL, 1);
	  XGpioPs_WritePin(&Gpio, dc, 1);
	  XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
	  XSpiPs_PolledTransfer(&SpiInstance_EMIO, page_2, NULL, 128);

//output page 4
  for(loop=0;loop<16;loop++){
  //loop =0;
		temp = (line_4[loop] * 8);
		for(byte_i=0;byte_i<8;byte_i++){
			data_conv[byte_i] = font[temp+byte_i];
		}
		conv_alg(data_conv); //convert to array
		for(byte_i=0;byte_i<8;byte_i++){
			page_3[(line_start-(char_size*loop))-byte_i] = results[byte_i];
		}
  }
	 cmd[0] = (u8) 0xB3;
	 XGpioPs_WritePin(&Gpio, dc, 0);
	 XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
	 XSpiPs_PolledTransfer(&SpiInstance_EMIO, cmd, NULL, 1);
	 XGpioPs_WritePin(&Gpio, dc, 1);
	 XSpiPs_SetSlaveSelect(&SpiInstance_EMIO, 0x01);
	 XSpiPs_PolledTransfer(&SpiInstance_EMIO, page_3, NULL, 128);

    return 0;
}