コード例 #1
0
ファイル: oled.c プロジェクト: billybillycheng/Genesys2
/******************************************************************************
 * This function initializes the SPI and GPIO drivers needed to control the
 * OLED display.
 *
 * @param	psSpi is the pointer to the SPI driver structure.
 * @param	psGpio is the pointer to the GPIO driver structure.
 *
 * @return	XST_SUCCESS - Everything went well
 * 			XST_DEVICE_NOT_FOUND - Device not found
 * 			XST_FAILURE - Failure
 *****************************************************************************/
XStatus fnOledDriverInit(XSpi *psSpi, XGpio *psGpio) {

	XStatus Status;
	XSpi_Config *SpiConfigPtr;
	XGpio_Config *GpioConfigPtr;

	// Initialize the SPI driver so that it is  ready to use.
	SpiConfigPtr = XSpi_LookupConfig(OLED_SPI_DEVICE_ID);
	if(SpiConfigPtr == NULL) {
		return XST_DEVICE_NOT_FOUND;
	}

	Status = XSpi_CfgInitialize(psSpi, SpiConfigPtr,
			SpiConfigPtr->BaseAddress);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	// Initialize the GPIO driver
	GpioConfigPtr = XGpio_LookupConfig(OLED_GPIO_DEVICE_ID);
	if(GpioConfigPtr == NULL) {
		return XST_DEVICE_NOT_FOUND;
	}

	Status = XGpio_CfgInitialize(psGpio, GpioConfigPtr,
			GpioConfigPtr->BaseAddress);

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

	return XST_SUCCESS;
}
コード例 #2
0
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);


}
コード例 #3
0
/*
 * Initialize GPIO instance for qdrA Testing
 */
int qthTest_Init() {
	XGpio_Config* gpioConfigPtr;
	int i;
	int Status;

	gpioConfigPtr = XGpio_LookupConfig(XPAR_AXI_GPIO_RW_0_DEVICE_ID);
	if (gpioConfigPtr == NULL) {
		return XST_FAILURE;
	}

	Status = XGpio_CfgInitialize(&gpioRW0_ctrl, gpioConfigPtr, gpioConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	gpioConfigPtr = XGpio_LookupConfig(XPAR_AXI_GPIO_RO_0_DEVICE_ID);
	if (gpioConfigPtr == NULL) {
		return XST_FAILURE;
	}

	Status = XGpio_CfgInitialize(&gpioRO0_status, gpioConfigPtr, gpioConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	for(i = 0; i < 8; i++) {
		gpioConfigPtr = XGpio_LookupConfig(arGpioDevIds[i]);
		if (gpioConfigPtr == NULL) {
			return XST_FAILURE;
		}

		Status = XGpio_CfgInitialize(&gpioROs[i], gpioConfigPtr, gpioConfigPtr->BaseAddress);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}

	XGpio_DiscreteWrite(&gpioRW0_ctrl, 1, 0x01);

	for(i = 0; i < 100; i++) {
		asm("nop");
	}

	XGpio_DiscreteWrite(&gpioRW0_ctrl, 1, 0x00);

	return XST_SUCCESS;
}
コード例 #4
0
int main() {

    unsigned int value=0;
    int i;
    u32 input;

    unsigned int my_array[] = {
    		1841,1371,1356,1435,1364,1474,1741,1790,1720,1770,6770,7460,3660,5045,1111,9481 ,99,100,99,92,159,163,114,177,101,44,55,192,58,81,129,193,124,76,38,181,147,182,77,71,
    		17,164,149,193,62,45,81,176,184,165,28,199,1,199,1,199,1,199,1,199,1,199,1,199,15,12,9,98,9,134,14,15,
    		16,7,2,6,1,4,7,18,1,5,20,21,22,23,24,25,15,15,15,101,199,102,198,103,197,104,196,105,195,111,189,122,
    		184,137,136,135,134,144,141,190,120,170,60,70,30,50,111,981,141,171

    };

    GPIO_0_conf.BaseAddress = XPAR_AXI_GPIO_0_BASEADDR;
    GPIO_0_conf.DeviceId = XPAR_GPIO_0_DEVICE_ID;
    GPIO_0_conf.InterruptPresent = XPAR_GPIO_0_INTERRUPT_PRESENT;
    GPIO_0_conf.IsDual = XPAR_GPIO_0_IS_DUAL;

    //Initialize the XGpio instance
    XGpio_CfgInitialize(&GPIO_0, &GPIO_0_conf, GPIO_0_conf.BaseAddress);

    init_platform();
    print("*Init*\n\r");

    for(i=0;i<size;i++){
    	value = 0xe0000000 | (i<<16) | my_array[i];
    	XGpio_DiscreteWrite(&GPIO_0, 1, value);
    	print("Preencheu RAM! \n\r");
    }

    print("Fim do preenchimento\n\r");
    print("Pressionar btnC\n\r");


	input = XGpio_DiscreteRead(&GPIO_0, 2);


	// Separar valor para mostrar
	outbyte((char)((input/100)+0x30));
	outbyte((char)((input/10)%10+0x30));
	outbyte((char)(input%10+0x30));
	print("\n");







    cleanup_platform();
    return 0;
}
コード例 #5
0
/*
 * Initialize GPIO instance for qdrA Testing
 */
int qdrTest_Init() {
	XGpio_Config* gpioConfigPtr;
	int Status;

	gpioConfigPtr = XGpio_LookupConfig(XPAR_AXI_GPIO_RO_0_DEVICE_ID);
	if (gpioConfigPtr == NULL) {
		return XST_FAILURE;
	}

	Status = XGpio_CfgInitialize(&gpioInstance, gpioConfigPtr, gpioConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
コード例 #6
0
ファイル: platform_drivers.c プロジェクト: Deepak1108/no-OS
/***************************************************************************//**
 * @brief gpio_init
*******************************************************************************/
int32_t gpio_init(uint32_t device_id)
{
	uint32_t base_addr = 0;

#ifdef _XPARAMETERS_PS_H_
	gpio_config = XGpioPs_LookupConfig(device_id);

	base_addr = gpio_config->BaseAddr;
	XGpioPs_CfgInitialize(&gpio_instance, gpio_config, base_addr);
#else
	gpio_config = XGpio_LookupConfig(device_id);

	base_addr = gpio_config->BaseAddress;
	XGpio_CfgInitialize(&gpio_instance, gpio_config, base_addr);
#endif

	return 0;
}
コード例 #7
0
/**
* Initialize the XGpio instance provided by the caller based on the
* given DeviceID.
*
* Nothing is done except to initialize the InstancePtr.
*
* @param	InstancePtr is a pointer to an XGpio instance. The memory the
*		pointer references must be pre-allocated by the caller. Further
*		calls to manipulate the component through the XGpio API must be
*		made with this pointer.
*
* @param	DeviceId is the unique id of the device controlled by this XGpio
*		component. Passing in a device id associates the generic XGpio
*		instance to a specific device, as chosen by the caller or
*		application developer.
*
* @return
*		- XST_SUCCESS if the initialization was successfull.
* 		- XST_DEVICE_NOT_FOUND  if the device configuration data was not
*		found for a device with the supplied device ID.
*
* @note		None.
*
*****************************************************************************/
int XGpio_Initialize(XGpio * InstancePtr, u16 DeviceId)
{
	XGpio_Config *ConfigPtr;

	/*
	 * Assert arguments
	 */
	XASSERT_NONVOID(InstancePtr != NULL);

	/*
	 * Lookup configuration data in the device configuration table.
	 * Use this configuration info down below when initializing this
	 * component.
	 */
	ConfigPtr = XGpio_LookupConfig(DeviceId);
	if (ConfigPtr == (XGpio_Config *) NULL) {
		InstancePtr->IsReady = 0;
		return (XST_DEVICE_NOT_FOUND);
	}

	return XGpio_CfgInitialize(InstancePtr, ConfigPtr,
				   ConfigPtr->BaseAddress);
}
コード例 #8
0
void init_GPIO_LEDS(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, 0x00);

    if(Status != XST_FAILURE) {
        xil_printf("LEDS initialized!\n \r");
    }

}
コード例 #9
0
ファイル: xusb_mouse.c プロジェクト: Hunter-why/embeddedsw
/**
 * This function implements the USB mouse application.
 * This function sets up the ML403 evaluation board as a USB mouse.
 * The mouse cursor movement can be seen on the PC as and when any of the push
 * buttons SW3, SW4, SW5 and SW7 on the ML403 Evaluation board is pressed.
 * Pressing the push button SW6 stops the test.
 *
 * @param	UsbId is the USB device id.
 * @param	GpioId is the GPIO device id.
 *
 * @return
 *		- XST_SUCCESS if successful.
 *		- XST_FAILURE if test fails.
 *
 * @note	None.
 *
 *****************************************************************************/
int UsbMouseExample (u16 UsbId,	u16 GpioId)
{
	int Status;

	/*
	 * Initialize the USB driver.
	 */
	UsbConfigPtr = XUsb_LookupConfig(UsbId);
	if (NULL == UsbConfigPtr) {
		return XST_FAILURE;
	}

	/*
	 * We are passing the physical base address as the third argument
	 * because the physical and virtual base address are the same in our
	 * example. For systems that support virtual memory, the third
	 * argument needs to be the virtual base address.
	 */
	Status = XUsb_CfgInitialize(&UsbInstance,
				       UsbConfigPtr,
				       UsbConfigPtr->BaseAddress);
	if (XST_SUCCESS != Status) {
		return XST_FAILURE;
	}

	/*
	 * Initialize the GPIO driver.
	 */
	GpioConfigPtr = XGpio_LookupConfig(GpioId);
	if (GpioConfigPtr == NULL) {
		return XST_FAILURE;
	}

	/*
	 * We are passing the physical base address as the third argument
	 * because the physical and virtual base address are the same in our
	 * example. For systems that support virtual memory, the third
	 * argument needs to be the virtual base address.
	 */
	Status = XGpio_CfgInitialize(&Gpio,
					GpioConfigPtr,
					GpioConfigPtr->BaseAddress);

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

	XGpio_SetDataDirection(&Gpio, BUTTON_CHANNEL, GPIO_ALL_BUTTONS);

	/*
	 * Initialize the USB instance as required for the USB mouse
	 * application.
	 */
	InitUsbInterface(&UsbInstance);

	/*
	 * Set USB device address to 0 which is the unenumerated state.
	 */
	Status = XUsb_SetDeviceAddress(&UsbInstance, 0);
	if (XST_SUCCESS != Status) {
		return XST_FAILURE;
	}

	/*
	 * Setup the interrupt handlers.
	 */
	XUsb_IntrSetHandler(&UsbInstance, (void *)UsbIfIntrHandler,
				&UsbInstance);

	XUsb_EpSetHandler(&UsbInstance, 0,
				(XUsb_EpHandlerFunc *)Ep0IntrHandler,
				&UsbInstance);

	XUsb_EpSetHandler(&UsbInstance, 1,
				(XUsb_EpHandlerFunc *)Ep1IntrHandler,
				&UsbInstance);

	/*
	 * Setup the interrupt system.
	 */
	Status = SetupInterruptSystem(&UsbInstance, &Gpio);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the interrupts.
	 */
	XUsb_IntrEnable(&UsbInstance, XUSB_STATUS_GLOBAL_INTR_MASK |
				XUSB_STATUS_RESET_MASK |
				XUSB_STATUS_SUSPEND_MASK |
				XUSB_STATUS_DISCONNECT_MASK |
				XUSB_STATUS_FIFO_BUFF_RDY_MASK |
				XUSB_STATUS_FIFO_BUFF_FREE_MASK |
				XUSB_STATUS_EP0_BUFF1_COMP_MASK |
				XUSB_STATUS_EP1_BUFF1_COMP_MASK |
				XUSB_STATUS_EP1_BUFF2_COMP_MASK );

	XUsb_Start(&UsbInstance);

	/*
	 * Set the device configuration to unenumerated state.
	 */
	UsbInstance.DeviceConfig.CurrentConfiguration = 0;

	/*
	 * Observe that the mouse movement is seen on the PC whenever any of the
	 * ML403 evaluation board push button is pressed. The test ends when the
	 * center push button on the ML403 Evaluation board is pressed.
	 */
	while (!StopTest);


	return XST_SUCCESS;
}
コード例 #10
0
ファイル: mrf24j.cpp プロジェクト: eusebiuburlacu/WWS
int Mrf24j::initDrivers(void)
{
	// TODO: check pin direction
	/*pinMode(_pin_reset, OUTPUT);
	pinMode(_pin_cs, OUTPUT);
	pinMode(_pin_int, INPUT);*/

	XSpi_Config *SPIConfigPtr;
	XGpio_Config *GPIOConfigPtr;

	int status;

	/*
	* Initialize the SPI driver so that it is  ready to use.
	*/
	SPIConfigPtr = XSpi_LookupConfig(XPAR_SPI_0_DEVICE_ID);
	if (SPIConfigPtr == NULL)
	{
		return XST_DEVICE_NOT_FOUND;
	}

	status = XSpi_CfgInitialize(&MSpiInstance, SPIConfigPtr, SPIConfigPtr->BaseAddress);
	if (status != XST_SUCCESS)
	{
		return XST_FAILURE;
	}

	/*
	 * Set the Spi device as a master.
	 */
	status = XSpi_SetOptions( &MSpiInstance, XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION ); //TO DO, add msb first config
	if (status != XST_SUCCESS)
	{
		return XST_FAILURE;
	}

	/*
	* Start the SPI driver so that the device is enabled.
	*/
	XSpi_Start(&MSpiInstance);

	/*
	* Disable Global interrupt to use polled mode operation
	*/
	XSpi_IntrGlobalDisable(&MSpiInstance);

	//GPIO config
	GPIOConfigPtr = XGpio_LookupConfig(XPAR_GPIO_1_DEVICE_ID);

	status = XGpio_CfgInitialize(&gpioInstance, GPIOConfigPtr, GPIOConfigPtr->BaseAddress);
	if (status != XST_SUCCESS)
	{
		return XST_FAILURE;
	}

	XGpio_SetDataDirection(&gpioInstance, 1, 0x1); //check data direction

	XGpio_DiscreteWrite(&gpioInstance, 1, 0x6); //check register, check wake pin if it is ok high


	//for(int i = 0; i < 20; i++)
	//{
	//u32 intr = XGpio_InterruptGetEnabled(&gpioInstance);

	//u32 sts = XGpio_InterruptGetStatus(&gpioInstance);

	//XGpio_InterruptClear(&gpioInstance, XGPIO_IR_CH1_MASK);

	 ///sts = XGpio_InterruptGetStatus(&gpioInstance);

	//u32 usts = sts;
	//}
	/*SPI.setBitOrder(MSBFIRST) ;
	SPI.setDataMode(SPI_MODE0);
	SPI.begin();*/
	return XST_SUCCESS;
}
コード例 #11
0
ファイル: OledDriver.cpp プロジェクト: LucianBurlacu/WWS
void OledHostInit()
{
	XSpi_Config *SPIConfigPtr;

	XGpio_Config *GPIOConfigPtr;
	int status;
	/*
	* Initialize the SPI driver so that it is  ready to use.
	*/
	SPIConfigPtr = XSpi_LookupConfig(XPAR_SPI_1_DEVICE_ID);
	if (SPIConfigPtr == NULL)
	{
		printf("OledHostInit: ERROR: SPI device not found");
	}

	status = XSpi_CfgInitialize(&SpiInstance, SPIConfigPtr, SPIConfigPtr->BaseAddress);
	if (status != XST_SUCCESS)
	{
		printf("OledHostInit: ERROR: cannot init SPI");
	}

	/*
	 * Set the Spi device as a master.
	 */
	status = XSpi_SetOptions( &SpiInstance, XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION |
			XSP_CLK_ACTIVE_LOW_OPTION | XSP_CLK_PHASE_1_OPTION);
	if (status != XST_SUCCESS)
	{
		printf("OledHostInit: ERROR: set SPI options");
	}


	/*
	* Start the SPI driver so that the device is enabled.
	*/
	XSpi_Start(&SpiInstance);

	/*
	* Disable Global interrupt to use polled mode operation
	*/
	XSpi_IntrGlobalDisable(&SpiInstance);

	u32 slaveReg = XSpi_GetSlaveSelectReg(&SpiInstance);

	XSpi_SetSlaveSelectReg(&SpiInstance, 0x00);

	slaveReg = XSpi_GetSlaveSelectReg(&SpiInstance);

	//GPIO config
	GPIOConfigPtr = XGpio_LookupConfig(XPAR_GPIO_0_DEVICE_ID);
	if (GPIOConfigPtr == NULL)
	{
		printf("OledHostInit: ERROR: GPIO device not found");
	}

	status = XGpio_CfgInitialize(&gpioInstance, GPIOConfigPtr, GPIOConfigPtr->BaseAddress);
	if (status != XST_SUCCESS)
	{
		printf("OledHostInit: ERROR: cannot init GPIO");
	}

	XGpio_SetDataDirection(&gpioInstance, 1, 0xf0);

	XGpio_DiscreteWrite(&gpioInstance, 1, 0x0F);

}