Пример #1
0
void LED_Init(void) {

	LEDPIN_Init();

	/*while(1)
			{
				//MB_Sleep(1000);
				LED_WrCmd(0xaa);
				//MB_Sleep(1000);
				XGpio_DiscreteWrite(&led2, reset_CHANNEL, 0x1);
				XGpio_DiscreteWrite(&led1, reset_CHANNEL, 0x0);
			}*/
	XGpio_DiscreteWrite(&reset, reset_CHANNEL, 0x0);
	//usleep(800);
	MB_Sleep(80);
	XGpio_DiscreteWrite(&reset, reset_CHANNEL, 0x1);
	Set_Display_On_Off(0x00);		  // Display Off (0x00/0x01)
	Set_Display_Clock(0x80);		  // Set Clock as 100 Frames/Sec
	Set_Multiplex_Ratio(0x3F);	  // 1/64 Duty (0x0F~0x3F)
	Set_Display_Offset(0x00);		  // Shift Mapping RAM Counter (0x00~0x3F)
	SetStartLine(0x00);		// Set Mapping RAM Display Start Line (0x00~0x3F)
	Set_Charge_Pump(0x04);		  // Enable Embedded DC/DC Converter (0x00/0x04)
	SetAddressingMode(0x02);	  // Set Page Addressing Mode (0x00/0x01/0x02)
	Set_Segment_Remap(0x01);	// Set SEG/Column Mapping     0x00左右反置 0x01正常
	Set_Common_Remap(0x08);	  // Set COM/Row Scan Direction 0x00上下反置 0x08正常
	Set_Common_Config(0x10);	  // Set Sequential Configuration (0x00/0x10)
	SetContrastControl(0xCF); // Set SEG Output Current
	Set_Precharge_Period(0xF1);	// Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
	Set_VCOMH(0x40);			  // Set VCOM Deselect Level
	Set_Entire_Display(0x00);		  // Disable Entire Display On (0x00/0x01)
	Set_Inverse_Display(0x00);	  // Disable Inverse Display On (0x00/0x01)
	Set_Display_On_Off(0x01);		  // Display On (0x00/0x01)
	LED_Fill(0x00);                               //初始清屏
	LED_Set_Pos(0, 0);
}
Пример #2
0
void OledUpdate()
{
	int gpioReg = 0;
	int		ipag;
	uint8_t *	pb;

	pb = rgbOledBmp;
	
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);

	for (ipag = 0; ipag < cpagOledMax; ipag++) 
	{
		XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg & ( RESET_MASK | VDD_CTRL_MASK | VBAT_CTRL_MASK ));

		/* Set the page address
		*/
		Spi2PutByte(0x22);		//Set page command
		Spi2PutByte(ipag);		//page number

		/* Start at the left column
		*/
		Spi2PutByte(0x00);		//set low nybble of column
		Spi2PutByte(0x10);		//set high nybble of column

		XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg | DATA_CMD_MASK);

		/* Copy this memory page of display data.
		*/
		OledPutBuffer(ccolOledMax, pb);
		pb += ccolOledMax;

	}
}
Пример #3
0
int main()
{
    int aliveLed = 0;
    static int BlinkCount = 0;
    init_platform();
    if(SetupPeripherals() != XST_SUCCESS)
    	return -1;

    if ( Chilipepper_Initialize() != 0 )
    	return -1;

    Chilipepper_SetPA( 1 );
    Chilipepper_SetTxRxSw( 1 ); // 0- transmit, 1-receive
    while (1)
    {
	   Chilipepper_ControlAgc(); //update the Chilipepper AGC
	   BlinkCount += 1;
	   if (BlinkCount > 500000)
	   {
		 if (aliveLed == 0)
			aliveLed = 1;
		 else
			aliveLed = 0;
		 BlinkCount = 1;
		 XGpio_DiscreteWrite(&gpio_blinky, 2, aliveLed);  //blink LEDs
		 XGpio_DiscreteWrite(&gpio_blinky, 1, ~aliveLed);
	   }
    }
    cleanup_platform();
    return 0;
}
/**
* This function sequences the LEDs by turning them all on, the turning each
* one on individually, then turning them all on, and finally off.
*
* @param	None.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
void SequenceLeds()
{
	u32 Mask = 0x8000;
	int Led;
	volatile int Delay;

	/* Turn on all the LEDS to show starting the sequence */

	XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, GPIO_ALL_LEDS);
	for (Delay = 0; Delay < LED_DELAY; Delay++);

	/* Sequence thru turning each LED on one at a time */

	for (Led = 1; Led <= 16; Led++) {
		XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, Mask);
		Mask >>= 1;

		/* Wait a small amount of time so the LED is visible */

		for (Delay = 0; Delay < LED_DELAY; Delay++);
	}

	/* Turn on all LEDS to show stopping the sequence */

	XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, GPIO_ALL_LEDS);
	for (Delay = 0; Delay < LED_DELAY; Delay++);

	/* Turn off all the LEDs */

	XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0);

	XGpio_InterruptClear(&Gpio, XGPIO_IR_MASK);
}
Пример #5
0
void ledToggle() {// toggle led
	led = XGpio_DiscreteRead(&outGpio,1);
	if (led & 0x8)
		XGpio_DiscreteWrite(&outGpio,1,led & 0x7);
	else
		XGpio_DiscreteWrite(&outGpio,1,led | 0x8);
};
Пример #6
0
int SetupPeripherals( void )
{
	int status;

    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);

    XGpio_Initialize(&gpio_gain, XPAR_AXI_GPIO_GAIN_DEVICE_ID);
    XGpio_SetDataDirection(&gpio_gain, 1, 0); // out

    XGpio_Initialize(&gpio_sw_test, XPAR_AXI_GPIO_SWITCH_TEST_MODES_DEVICE_ID);
    XGpio_SetDataDirection(&gpio_sw_test, 1, 3);

    XGpio_Initialize(&gpio_sw_tx_pa, XPAR_AXI_GPIO_PA_DEVICE_ID);
    XGpio_SetDataDirection(&gpio_sw_tx_pa, 1, 1+2+4+8+16);

    XGpio_Initialize(&gpio_btn, XPAR_AXI_GPIO_BUTTON_DEVICE_ID);
    XGpio_SetDataDirection(&gpio_btn, 1, 1);

    pUartPsConfig = XUartPs_LookupConfig(XPAR_PS7_UART_1_DEVICE_ID);
	if (NULL == pUartPsConfig) {
		return XST_FAILURE;
	}
	status = XUartPs_CfgInitialize(&uartPs, pUartPsConfig, pUartPsConfig->BaseAddress);
	if (status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XUartPs_SetBaudRate(&uartPs, 115200);

	return XST_SUCCESS;
}
Пример #7
0
int main(void)
{
	u32 Data;
	u32 InData;
	int Status;
	volatile int Delay;
	char test_vect_idx =0;
	char charidx = 0;
	u8 DataWrittenDone = 0;
	char curchar;

	 init_platform();



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


	for (test_vect_idx=0;test_vect_idx<num_test_vectors;test_vect_idx++)
	{
		for (charidx=0;charidx<64;charidx++)
		{
			curchar = testvector[test_vect_idx][charidx]; //Read the current character
			Data = createDataPacket(curchar,charidx,test_vect_idx); //Send the 'A' character to byte 3 of testvector 1
			print("Sending character \n");
			XGpio_DiscreteWrite(&Gpio, OUPTPUT_CHANNEL, Data); //Write into the PL
			//Double check by reading from the PL
			for (Delay = 0; Delay < LED_DELAY; Delay++); //Wait for a while
			//Read back the data from the PL side to see its status
			do
			{
				InData = XGpio_DiscreteRead(&Gpio, INPUT_CHANNEL);
				for (Delay = 0; Delay < LED_DELAY; Delay++); //Wait for a while before recheck
			}
			while (InData&(1<<31));
			if ((InData&0xFF)==(Data&0xFF))
			{
				print("Correct\n");
			}
			else
			{
				print("Incorrect\n");
			}
			XGpio_DiscreteWrite(&Gpio, OUPTPUT_CHANNEL, 0x00000000); //Release the bus immediately
			for (Delay = 0; Delay < LED_DELAY; Delay++); //Wait for a while

		}
	}
	print("Done sending. Please press the center button to begin...");

	cleanup_platform();
	return XST_SUCCESS;
}
Пример #8
0
void generateTone(int period_us) {
    // turn-ON speaker
    XGpio_DiscreteWrite(&pb_speaker, SPEAKER_CHANNEL, 1<<shift);
    delay_us(period_us>>1);
    // turn-OFF speaker
    XGpio_DiscreteWrite(&pb_speaker, SPEAKER_CHANNEL, 0);
    delay_us(period_us>>1);
}
Пример #9
0
void OledDevInit()
{
	int gpioReg = 0;
	/* We're going to be sending commands, so clear the Data/Cmd bit
	*/
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);

	XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg & (RESET_MASK | VBAT_CTRL_MASK));
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	printf("OledDevInit: d/cmd, vdd set to 0, gpioReg: %X", gpioReg);
	usleep(1000);

	/* Display off command
	*/
	Spi2PutByte(cmdOledDisplayOff);

	/* Bring Reset low and then high
	*/

	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg & ( VBAT_CTRL_MASK | VDD_CTRL_MASK | DATA_CMD_MASK));
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	printf("OledDevInit: reset set to 0, gpioReg: %X", gpioReg);
	usleep(1000);
	XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg | RESET_MASK);
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	printf("OledDevInit: reset set to 1, gpioReg: %X", gpioReg);

	/* Send the Set Charge Pump and Set Pre-Charge Period commands
	*/
	Spi2PutByte(0x8D);		//From Univision data sheet, not in SSD1306 data sheet
	Spi2PutByte(0x14);

	Spi2PutByte(0xD9);		//From Univision data sheet, not in SSD1306 data sheet
	Spi2PutByte(0xF1);

	/* Turn on VCC and wait 100ms
	*/
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg & ( RESET_MASK | VDD_CTRL_MASK | DATA_CMD_MASK));
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	printf("OledDevInit: vbat set to 0, gpioReg: %X", gpioReg);
	usleep(100000);

	/* Send the commands to invert the display.
	*/
	Spi2PutByte(cmdOledSegRemap);		//remap columns
	Spi2PutByte(cmdOledComDir);			//remap the rows

	/* Send the commands to select sequential COM configuration
	*/
	Spi2PutByte(cmdOledComConfig);		//set COM configuration command
	Spi2PutByte(0x20);					//sequential COM, left/right remap enabled

	/* Send Display On command
	*/
	Spi2PutByte(cmdOledDisplayOn);
}
Пример #10
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;
}
Пример #11
0
void Mrf24j::reset(void) 
{
	int gpioReg = 0;
	
	gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
	XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg & RF_WAKE_MASK); //reset low
    usleep(10000);  // just my gut
    XGpio_DiscreteWrite(&gpioInstance, 1, gpioReg | RF_RESET_MASK); //reset high
    usleep(20000);  // from manual
}
Пример #12
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--;
    }
}
Пример #13
0
void LED_WrCmd(u8 cmd)
{

	XGpio_DiscreteWrite(&dc, DC_CHANNEL, 0x0);
	XSpi_Transfer(&Spi, &cmd, 0, sizeof(cmd));

	XGpio_DiscreteWrite(&led1, reset_CHANNEL, 0x1);
	//oled_gpio->digitalWrite(oled_gpio, 0, OLED_DC_PIN, 0);

	//oled_SPI->RWOneByte(oled_SPI, cmd, 0);

}
Пример #14
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;
}
Пример #15
0
int main()
{
	xil_printf("Program Started\n\r");
    init_platform();
    init_spi(&SpiInstance);
    init_gpio(&GpioInstance);

    u8 LED_data = 0x1;
    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);
    xil_printf("Tests started.\n\r");
    LED_data |= 0x1<<1;
    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);

    // Test for proper initial read/write
    int addr = 0;
    int value = 10;
	spi_write(&SpiInstance, addr, value);
	u8 res = spi_read(&SpiInstance, addr);
	xil_printf("Wrote to %X. %d transmitted. %d read back. The send and received values should match.\n\r", addr, value, res);
	// Test for proper overwriting of same address with new value
	value = 16;
	spi_write(&SpiInstance, addr, value);
	res = spi_read(&SpiInstance, addr);
	xil_printf("Wrote to %X again. %d transmitted. %d read back. The received value should be updated to the new sent value.\n\r", addr, value, res);
	// Test for making sure multiple addresses work
	addr = 1;
	value = 20;
	spi_write(&SpiInstance, addr, value);
	res = spi_read(&SpiInstance, addr);
	xil_printf("Wrote to %X. %d transmitted. %d read back. The new address should function as well as the old one.\n\r", addr, value, res);
	// Test to make sure every address works
	xil_printf("Writing and reading to all 32 memory addresses:\r\n(sent and received values should match, value + address should sum to 32)\n\r");
	int i;
	for (i = 0; i < 32; ++i){
		addr = i;
		value = 32 - i;
		spi_write(&SpiInstance, addr, value);
		res = spi_read(&SpiInstance, addr);
		xil_printf("Wrote to %X. %d transmitted. %d read back.\n\r", addr, value, res);
	}


    LED_data |= 0x1<<2;
    xil_printf("Tests complete. Please review results.\n\r");

    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);
    LED_data |= 0x1<<3;
    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);
    cleanup_platform();
    return 0;
}
Пример #16
0
void blinkLED(int numberOfBlinks) {
    int i;
    long j;

    XGpio_Initialize(&Gpio, XPAR_GPIO_0_DEVICE_ID);

    for (i = 0; i < numberOfBlinks; i++) {
        XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0xff);
        for (j = 0; j < LED_DELAY; j++) ; // NOP

        XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0x00);
        for (j = 0; j < LED_DELAY; j++) ; // NOP
    }
}
Пример #17
0
int main()
{
	xil_printf("Program Started\n\r");
    init_platform();
    init_spi(&SpiInstance);
    init_gpio(&GpioInstance);

    u8 LED_data = 0x1;
    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);
    xil_printf("Tests started.\n\r");
    LED_data |= 0x1<<1;
    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);

    //TODO: Create better tests
    // no.
 //    int addr = 0;
 //    int value = 10;
	// spi_write(&SpiInstance, addr, value);
	// u8 res = spi_read(&SpiInstance, addr);
	// xil_printf("Wrote to %X. %X transmitted. %X readback.\n\r", addr, value, res);
	int tests_passed = 1;
	for(int addr = 0; addr < 128; addr = addr + 1 )
	{
		for (int value = 0; value < 256; value = value + 1 )
		{
			spi_write(&SpiInstance, addr, value);
			u8 res = spi_read(&SpiInstance, addr);
			if (res != value)
			{
				xil_printf("Test failed!!! Wrote to %X. %X transmitted. %X readback.\n\r", addr, value, res);
				tests_passed = 0;
			} else
			{
				xil_printf("Test passed");
			}

		}
	}

    LED_data |= 0x1<<2;
    xil_printf("Tests complete. Result: %X.\n\r", tests_passed);

    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);
    LED_data |= 0x1<<3;
    XGpio_DiscreteWrite(&GpioInstance, LED_CHANNEL, LED_data);
    cleanup_platform();
    return 0;
}
Пример #18
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 */
}
Пример #19
0
Файл: led.c Проект: FlexCOS/code
/*
 * 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;
}
Пример #20
0
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
unsigned char ucLED = 1U;

	/* Only attempt to toggle the LED if it is in range. */
	if( uxLED < partstMAX_LED )
	{
		ucLED <<= ( unsigned char ) uxLED;

		portENTER_CRITICAL();
		{
			if( ( ucGPIOState & ucLED ) != 0 )
			{
				ucGPIOState &= ~ucLED;
			}
			else
			{
				ucGPIOState |= ucLED;
			}

			XGpio_DiscreteWrite( &xOutputGPIOInstance, uxGPIOOutputChannel, ucGPIOState );
		}
		portEXIT_CRITICAL();
	}
}
Пример #21
0
static void prvQueueReceiveTask( void *pvParameters )
{
unsigned long ulReceivedValue;

	for( ;; )
	{
		/* Wait until something arrives in the queue - this task will block
		indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
		FreeRTOSConfig.h. */
		xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );

		/*  To get here something must have been received from the queue, but
		is it the expected value?  If it is, toggle the green LED. */
		if( ulReceivedValue == 100UL )
		{
			/* NOTE - accessing the LED port should use a critical section
			because it is accessed from multiple tasks, and the button interrupt
			- in this trivial case, for simplicity, the critical section is
			omitted. */
			if( ( ucGPIOState & mainTASK_CONTROLLED_LED ) != 0 )
			{
				ucGPIOState &= ~mainTASK_CONTROLLED_LED;
			}
			else
			{
				ucGPIOState |= mainTASK_CONTROLLED_LED;
			}

			XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );
		}
	}
}
Пример #22
0
/***************************************************************************//**
 * @brief gpio_set_value
*******************************************************************************/
int32_t gpio_set_value(uint8_t pin, uint8_t data)
{
#ifdef _XPARAMETERS_PS_H_
	XGpioPs_WritePin(&gpio_instance, pin, data);
#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_DiscreteRead(&gpio_instance, channel);
	if(data) {
		config |= (1 << pin);
	} else {
		config &= ~(1 << pin);
	}
	XGpio_DiscreteWrite(&gpio_instance, channel, config);
#endif

	return 0;
}
Пример #23
0
void setThreshold(){
	//memcpy(gpioThreshAddr,&THRESH_VALS[threshold],1);
//	memcpy(gpioBlankingAddr,)
	XGpio_DiscreteWrite(&Gpio_blanking,2,blanking_position);


}
Пример #24
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;
}
/*****
 * 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;
}
Пример #26
0
/****************************************************************************
 *
 * FUNCTION:
 *
 * TimerCounterHandler
 *
 * DESCRIPTION:
 *
 * This function is the handler which performs processing for the timer counter.
 * It is called from an interrupt context such that the amount of processing
 * performed should be minimized.  It is called when the timer counter expires
 * if interrupts are enabled.
 *
 * This handler provides an example of how to handle timer counter interrupts
 * but is application specific.
 *
 * ARGUMENTS:
 *
 * None.
 *
 * RETURN VALUE:
 *
 * None.
 *
 * NOTES:
 *
 * None.
 *
 ****************************************************************************/
void TimerCounterHandler(void *CallBackRef, Xuint8 TimerCounterNumber) {
	Xuint32 Leds;

	TimerExpiredCount++;

	/* Toggle the LEDs so that they are flashing at the rate specified
	 * by the time slice
	 */
	Leds = XGpio_DiscreteRead(&Gpio, 1) & LED;

	if (Leds) {
		XGpio_DiscreteWrite(&Gpio, 1, ~LED);
	} else {
		XGpio_DiscreteWrite(&Gpio, 1, LED);
	}
}
/*
 * PWMController::Write
 * Overloaded method that takes an pwmdutyCycle integer variable, stores
 * in this object, and writes it in the output port
 *
 */
void PWMController::Write(int pwmDutyCycle){
	dutyCycle = pwmDutyCycle;

	if ( dutyCycle >= minDutyCycle && dutyCycle <= maxDutyCycle ) {
		XGpio_DiscreteWrite(&gpioObj, gpioChannel, dutyCycle);
	}
}
void prvLed_Toggle (int Mode)
{
	portTickType xNextWakeTime;
	static u32 Data = 1;

	xSemaphoreTake(xMutex_Led, ( portTickType ) portMAX_DELAY);

	/*
	 * Set the GPIO Output for each of 8 LEDs to the value of Mode.
	 */
	if (Mode == 0) Data<<=1;
	if (Data == 256) Data = 1;
	XGpio_DiscreteWrite(&GpioOutput, LED_CHANNEL, Mode?Data:0);


	if (Mode == 0x1)
		xil_printf("LED ON\r\n");
	else
		xil_printf("LED OFF\r\n");

	/* Initialize xNextWakeTime - this only needs to be done once. */
	xNextWakeTime = xTaskGetTickCount();

	/* Place this task in the blocked state until it is time to run again.
	The block time is specified in ticks, the constant used converts ticks
	to ms.  While in the Blocked state this task will not consume any CPU
	time. */
	vTaskDelayUntil(&xNextWakeTime, BLINK_PERIOD );

	xSemaphoreGive(xMutex_Led);
}
Пример #29
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;
}
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;
}