Ejemplo n.º 1
0
void __malloc_unlock(struct _reent *reent) {
	--lock;
	if (lock == 0) {
		IntMasterEnable();
	}
}
Ejemplo n.º 2
0
// *******************************************************
// Resets the systick counter to a desired time.
// Becareful of the systick rate!
void mRTCSet(unsigned long long ullTime)
{
	IntMasterDisable();
	g_ullRTCTicks = ullTime;
	IntMasterEnable();
}
Ejemplo n.º 3
0
//*****************************************************************************
//
// Configure the I2C0 master and slave and connect them using loopback mode.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32DataTx;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // The I2C0 peripheral must be enabled before use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    //
    // For this example I2C0 is used with PortB[3:2].  The actual port and
    // pins used may be different on your part, consult the data sheet for
    // more information.  GPIO port B needs to be enabled so these pins can
    // be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Configure the pin muxing for I2C0 functions on port B2 and B3.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    //
    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.  Consult the data sheet
    // to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Enable loopback mode.  Loopback mode is a built in feature that helps
    // for debug the I2Cx module.  It internally connects the I2C master and
    // slave terminals, which effectively lets you send data as a master and
    // receive data as a slave.  NOTE: For external I2C operation you will need
    // to use external pull-ups that are faster than the internal pull-ups.
    // Refer to the datasheet for more information.
    //
    HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01;

    //
    // Enable the I2C0 interrupt on the processor (NVIC).
    //
    IntEnable(INT_I2C0);

    //
    // Configure and turn on the I2C0 slave interrupt.  The I2CSlaveIntEnableEx()
    // gives you the ability to only enable specific interrupts.  For this case
    // we are only interrupting when the slave device receives data.
    //
    I2CSlaveIntEnableEx(I2C0_BASE, I2C_SLAVE_INT_DATA);

    //
    // Enable and initialize the I2C0 master module.  Use the system clock for
    // the I2C0 module.  The last parameter sets the I2C data transfer rate.
    // If false the data rate is set to 100kbps and if true the data rate will
    // be set to 400kbps.  For this example we will use a data rate of 100kbps.
    //
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);

    //
    // Enable the I2C0 slave module.
    //
    I2CSlaveEnable(I2C0_BASE);

    //
    // Set the slave address to SLAVE_ADDRESS.  In loopback mode, it's an
    // arbitrary 7-bit number (set in a macro above) that is sent to the
    // I2CMasterSlaveAddrSet function.
    //
    I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);

    //
    // Tell the master module what address it will place on the bus when
    // communicating with the slave.  Set the address to SLAVE_ADDRESS
    // (as set in the slave module).  The receive parameter is set to false
    // which indicates the I2C Master is initiating a writes to the slave.  If
    // true, that would indicate that the I2C Master is initiating reads from
    // the slave.
    //
    I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

    //
    // Set up the serial console to use for displaying messages.  This is just
    // for this example program and is not needed for proper I2C operation.
    //
    InitConsole();

    //
    // Enable interrupts to the processor.
    //
    IntMasterEnable();

    //
    // Display the example setup on the console.
    //
    UARTprintf("I2C Slave Interrupt Example ->");
    UARTprintf("\n   Module = I2C0");
    UARTprintf("\n   Mode = Receive interrupt on the Slave module");
    UARTprintf("\n   Rate = 100kbps\n\n");

    //
    // Initialize the data to send.
    //
    ui32DataTx = 'I';

    //
    // Indicate the direction of the data.
    //
    UARTprintf("Transferring from: Master -> Slave\n");

    //
    // Display the data that I2C0 is transferring.
    //
    UARTprintf("  Sending: '%c'", ui32DataTx);

    //
    // Place the data to be sent in the data register.
    //
    I2CMasterDataPut(I2C0_BASE, ui32DataTx);

    //
    // Initiate send of single piece of data from the master.  Since the
    // loopback mode is enabled, the Master and Slave units are connected
    // allowing us to receive the same data that we sent out.
    //
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

    //
    // Wait for interrupt to occur.
    //
    while(!g_bIntFlag)
    {
    }

    //
    // Display that interrupt was received.
    //
    UARTprintf("\n  Slave Interrupt Received!\n");

    //
    // Display the data that the slave has received.
    //
    UARTprintf("  Received: '%c'\n\n", g_ui32DataRx);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
Ejemplo n.º 4
0
void prvSetupHardware( void ){
	tBoolean found;
    long lEEPROMRetStatus;
    unsigned short data,data2;
	unsigned long uart_speed;
		
    /* If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    a workaround to allow the PLL to operate reliably. */
    if( DEVICE_IS_REVA2 )    {
        SysCtlLDOSet( SYSCTL_LDO_2_75V );
    }

	/* Set the clocking to run from the PLL at 50 MHz */
	SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );

	/* 	Enable Port F for Ethernet LEDs
		LED0        Bit 3   Output
		LED1        Bit 2   Output */
	SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOF );
	GPIODirModeSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3), GPIO_DIR_MODE_HW );
	GPIOPadConfigSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3 ), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD );

    //
    // Enable the GPIO pin for the LED (PF0).  Set the direction as output, and
    // enable the GPIO pin for digital function.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    if(SoftEEPROMInit(0x1F000, 0x20000, 0x800) != 0)  {
		LWIPDebug("SoftEEPROM initialisation failed.");
    }


    lEEPROMRetStatus = SoftEEPROMRead(UART0_SPEED_HIGH_ID, &data, &found);
	if(lEEPROMRetStatus == 0 && found) {
	    SoftEEPROMRead(UART0_SPEED_LOW_ID, &data2, &found);
		uart_speed = (data << 16 & 0xFFFF0000) | (data2 & 0x0000FFFF);
	    SoftEEPROMRead(UART0_CONFIG_ID, &data, &found);
	} else {
		uart_speed=115200;
		data = (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
	}

	uart_init(0, uart_speed, data);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
	
	IntPriorityGroupingSet(4);

	IntPrioritySet(INT_WATCHDOG,SET_SYSCALL_INTERRUPT_PRIORITY(5));
    IntEnable(INT_WATCHDOG); // Enable the watchdog interrupt.
    WatchdogReloadSet(WATCHDOG0_BASE, SysCtlClockGet());
    WatchdogResetEnable(WATCHDOG0_BASE);
    WatchdogEnable(WATCHDOG0_BASE);


	rtc_init();
	modules_init();

}
Ejemplo n.º 5
0
//*****************************************************************************
//
//! Add bytes to the ring buffer by advancing the write index.
//!
//! \param ptRingBuf points to the ring buffer to which bytes have been added.
//! \param ulNumBytes is the number of bytes added to the buffer.
//!
//! This function should be used by clients who wish to add data to the buffer
//! directly rather than via calls to RingBufWrite() or RingBufWriteOne(). It
//! advances the write index by a given number of bytes.  If the \e ulNumBytes
//! parameter is larger than the amount of free space in the buffer, the
//! read pointer will be advanced to cater for the addition.  Note that this
//! will result in some of the oldest data in the buffer being discarded.
//!
//! \return None.
//
//*****************************************************************************
void
RingBufAdvanceWrite(tRingBufObject *ptRingBuf,
                       unsigned long ulNumBytes)
{
    unsigned long ulCount;
    tBoolean bIntsOff;

    //
    // Check the arguments.
    //
    ASSERT(ptRingBuf != NULL);

    //
    // Make sure we were not asked to add a silly number of bytes.
    //
    ASSERT(ulNumBytes <= ptRingBuf->ulSize);

    //
    // Determine how much free space we currently think the buffer has.
    //
    ulCount = RingBufFree(ptRingBuf);

    //
    // Advance the buffer write index by the required number of bytes and
    // check that we have not run past the read index. Note that we must do
    // this within a critical section (interrupts disabled) to prevent
    // race conditions that could corrupt one or other of the indices.
    //
    bIntsOff = IntMasterDisable();

    //
    // Update the write pointer.
    //
    ptRingBuf->ulWriteIndex += ulNumBytes;

    //
    // Check and correct for wrap.
    //
    if(ptRingBuf->ulWriteIndex >= ptRingBuf->ulSize)
    {
        ptRingBuf->ulWriteIndex -= ptRingBuf->ulSize;
    }

    //
    // Did the client add more bytes than the buffer had free space for?
    //
    if(ulCount < ulNumBytes)
    {
        //
        // Yes - we need to advance the read pointer to ahead of the write
        // pointer to discard some of the oldest data.
        //
        ptRingBuf->ulReadIndex = ptRingBuf->ulWriteIndex + 1;

        //
        // Correct for buffer wrap if necessary.
        //
        if(ptRingBuf->ulReadIndex >= ptRingBuf->ulSize)
        {
            ptRingBuf->ulReadIndex -= ptRingBuf->ulSize;
        }
    }

    //
    // Restore interrupts if we turned them off earlier.
    //
    if(!bIntsOff)
    {
        IntMasterEnable();
    }
}
int main(void)
{
	// setup the system clock to run at 80 MHz from the external crystal:
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	// enable peripherals to operate when CPU is in sleep:
	ROM_SysCtlPeripheralClockGating(true);

	// enable all of the GPIOs:
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOC);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOD);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);

	// setup pins connected to RGB LED:
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	//setup the UART console
	InitConsole();

// Test either the interrupts on a simple pushbutton to turn-on a led:
// 			1- interrupt with static allocation on the vector table
//			2- interrupt with dynamic allocation on the vector table

//			2- interrupt with dynamic allocation on the vector table

// setup pin connected to SW1 and SW2

	// Unlock PF0 so we can change it to a GPIO input
	// Once we have enabled (unlocked) the commit register then re-lock it
	// to prevent further changes.  PF0 is muxed with NMI thus a special case.
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_AFSEL) |= 0x000;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;

	//Configures pin(s) for use as GPIO inputs
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0);
    //Sets the pad configuration for the specified pin(s).
    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
    // Make PORT F pin 0,4 high level triggered interrupts.
    ROM_GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0,GPIO_BOTH_EDGES);


    //dynamic allocation on the vector table of GPIO_PORTF_isr interrupt handler
    GPIOIntRegister(GPIO_PORTF_BASE, GPIO_PORTF_isr);

    //Enables the specified GPIO interrupt
    IntEnable(INT_GPIOF);
    GPIOIntEnable(GPIO_PORTF_BASE,GPIO_INT_PIN_4 | GPIO_INT_PIN_0);

    IntMasterEnable();

    uint8_t PORTF_status;

	//uint32_t ui32Loop = 0;

    //
    // Loop forever
    //
    while(1)
    {
    	uint8_t PORTF_status=GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4);
    	/*
    	if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4))
    	{
    		ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 ,0);
    	}
    	else
    	{
    		ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_1);
    	}
    	*/

    	/*
        //
        // Turn on the red LED .
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_1);
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }

        //
        // Turn on the green LED.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_2);
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }

        //
        // Turn on the blue LED.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_3);
        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }
        */
    }
}
//*****************************************************************************
//
// This is the main loop for the application.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run directly from the PLL at 50MHz.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Configure CAN 0 Pins.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure LED pin.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Configure GPIO Pin used for the LED.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

    //
    // Turn off the LED.
    //
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

    //
    // Enable the CAN controller.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);

    //
    // Reset the state of all the message object and the state of the CAN
    // module to a known state.
    //
    CANInit(CAN0_BASE);

    //
    // Configure the bit rate for the CAN device, the clock rate to the CAN
    // controller is fixed at 8MHz for this class of device and the bit rate is
    // set to CAN_BITRATE.
    //
    CANBitRateSet(CAN0_BASE, 8000000, CAN_BITRATE);

    //
    // Take the CAN0 device out of INIT state.
    //
    CANEnable(CAN0_BASE);

    //
    // Enable interrupts from CAN controller.
    //
    CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR);

    //
    // Enable interrupts for the CAN in the NVIC.
    //
    IntEnable(INT_CAN0);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set the initial state to wait for data.
    //
    g_sCAN.eState = CAN_WAIT_RX;

    //
    // Reset the buffer pointer.
    //
    g_sCAN.MsgObjectRx.pucMsgData = g_sCAN.pucBuffer;

    //
    // Set the total number of bytes expected.
    //
    g_sCAN.ulBytesRemaining = CAN_FIFO_SIZE;

    //
    // Configure the receive message FIFO.
    //
    CANReceiveFIFO(g_sCAN.pucBuffer, CAN_FIFO_SIZE);

    //
    // Initialized the LED toggle count.
    //
    g_ulLEDCount = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        switch(g_sCAN.eState)
        {
            case CAN_IDLE:
            {
                //
                // Switch to sending state.
                //
                g_sCAN.eState = CAN_SENDING;

                //
                // Initialize the transmit count to zero.
                //
                g_sCAN.ulBytesTransmitted = 0;

                //
                // Schedule all of the CAN transmissions.
                //
                CANTransmitFIFO(g_sCAN.pucBuffer, CAN_FIFO_SIZE);

                break;
            }
            case CAN_SENDING:
            {
                //
                // Wait for all bytes to go out.
                //
                if(g_sCAN.ulBytesTransmitted == CAN_FIFO_SIZE)
                {
                    //
                    // Switch to wait for RX state.
                    //
                    g_sCAN.eState = CAN_WAIT_RX;
                }

                break;
            }
            case CAN_WAIT_RX:
            {
                //
                // Wait for all new data to be received.
                //
                if(g_sCAN.ulBytesRemaining == 0)
                {
                    //
                    // Switch to wait for Process data state.
                    //
                    g_sCAN.eState = CAN_PROCESS;

                    //
                    // Reset the buffer pointer.
                    //
                    g_sCAN.MsgObjectRx.pucMsgData = g_sCAN.pucBuffer;

                    //
                    // Reset the number of bytes expected.
                    //
                    g_sCAN.ulBytesRemaining = CAN_FIFO_SIZE;
                }
                break;
            }
            case CAN_PROCESS:
            {
                //
                // Handle the LED toggle.
                //
                ToggleLED();

                //
                // Return to the idle state.
                //
                g_sCAN.eState = CAN_IDLE;

                break;
            }
            default:
            {
                break;
            }
        }
    }
}
Ejemplo n.º 8
0
int main(void) {
	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;

	volatile uint8_t ui8AdjustRed, ui8AdjustGreen, ui8AdjustBlue;
	ui8AdjustRed = 254;
	ui8AdjustGreen = 2;
	ui8AdjustBlue = 2;

	// Set the system clock to 40 MHz
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	// Set the PWM Clock to 1/64 of the system clock i.e. 625 kHz
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	// Timer related intializations, time period is 10 ms.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

	uint32_t ui32Period;
	ui32Period = (SysCtlClockGet()/100)/ 2;
	TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
	IntEnable(INT_TIMER0A);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	IntMasterEnable();
	TimerEnable(TIMER0_BASE, TIMER_A);

	// Enable the PWM module 1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

	// Enable the GPIO Port F
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	// PWM related initializations
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);
	GPIOPinConfigure(GPIO_PF2_M1PWM6);
	GPIOPinConfigure(GPIO_PF3_M1PWM7);

	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
	GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8AdjustRed * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8AdjustBlue * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT, true);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8AdjustGreen * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_3);

	// Detecting the phase while in the auto mode, RG, GB or BR.
	int autoLedState = 0;

	while(1) {
		if(mode==0) {
			if(autoLedState==0) {
				ui8AdjustRed--;
				ui8AdjustGreen++;

				if(ui8AdjustRed==2 && ui8AdjustGreen==254) autoLedState = 1;
			}
			else if(autoLedState==1) {
				ui8AdjustGreen--;
				ui8AdjustBlue++;

				if(ui8AdjustGreen==2 && ui8AdjustBlue==254) autoLedState = 2;
			}
			else if(autoLedState==2) {
				ui8AdjustBlue--;
				ui8AdjustRed++;

				if(ui8AdjustBlue==2 && ui8AdjustRed==254) autoLedState = 0;
			}

			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8AdjustRed * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8AdjustBlue * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8AdjustGreen * ui32Load / 1000);

			SysCtlDelay(delay);
		}
		else {
			if(mode==1) {
				ui8AdjustBlue = 2;
				ui8AdjustGreen = 2;

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) {
					ui8AdjustRed--;
					if (ui8AdjustRed < 20) ui8AdjustRed = 20;
				}

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) {
					ui8AdjustRed++;
					if (ui8AdjustRed > 254) ui8AdjustRed = 254;
				}
			}
			else if(mode==2) {
				ui8AdjustRed = 2;
				ui8AdjustGreen = 2;

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) {
					ui8AdjustBlue--;
					if (ui8AdjustBlue < 20) ui8AdjustBlue = 20;
				}

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) {
					ui8AdjustBlue++;
					if (ui8AdjustBlue > 254) ui8AdjustBlue = 254;
				}

			}
			else if(mode==3) {
				ui8AdjustBlue = 2;
				ui8AdjustRed = 2;

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) {
					ui8AdjustGreen--;
					if (ui8AdjustGreen < 20) ui8AdjustGreen = 20;
				}

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) {
					ui8AdjustGreen++;
					if (ui8AdjustGreen > 254) ui8AdjustGreen = 254;
				}
			}

			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8AdjustRed * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8AdjustBlue * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8AdjustGreen * ui32Load / 1000);

			SysCtlDelay(100000);
		}
	}
}
Ejemplo n.º 9
0
  main()
  {
     uint8 option=0;
     uint8 key;
  
    SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
    Uart0Init(19200);
	Uart1Init(9600);
	Uart2Init(19200);
    IntMasterEnable();
    SysLinearTimer =0;
    IoPortInit();	  //IO口初始化
    I2C1Init() ;//Fm31256
   	TimerInit();
	xs6963_init();
	PIN_TDA7367stand_Write(ETDA7367work_no);
	FlashUsecSet(49);
	//T1Init_LM331();
    DPRINTF(("Bat=%d  ,cha=%d ,Temp=%d \n",1,2,3));
    Usb_Host_Init();  
    mainHandleinit();
	
    signPWM_init(50.0);
    PWM_sign_stop();
	/*LCD初始化*/
	start_mune();
	/* fm31256 eeprom 8 */
    readbyte_much(setsto_addr,settype_nub,set.byte );
 	/*修正系数*/
    modify_read();
	/**/
	Oiltempset.oilTwork=EOiltemp_Workon; 
	/*lm331初始化 温度测量使用*/
	T1Init_LM331();
	/*系统节拍*/
    SysLinearTimer=0;	
	while(SysLinearTimer<3*TIMER_FREQ)//后台参数设置
     {
       key=Keyset.keyEfficiency;
       if(key==key_modify)
    	 {
		   while(Keyset.keyEfficiency==key_modify); 
    	   option++;
		   if(option>=4)
	       	{
			   modify_read();//读取修正参数
			   TgC_read();
    	       modify();//修正
	   	    }
       	 }
    }	
   	modifyK_js();
    SysLinearTimer=0;
    rx_flag=0;
 	option=0;
mainset_go:
	  key=Keyset.keyEfficiency;
      mainset_mune();
      Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
	  while(1)
	  	{
	      while(key==Keyset.keyEfficiency)
		    {
		     if(SysLinearTimer>(3*TIMER_FREQ/4))  	   
              {
			    // Temp_account();
			  if(TRUE_z==Gandispose())//地线检测
			  	{
			  	  mainset_mune();
				  Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
			  	}
           	 
			   read_time();
			    {
				 uint8 byte[12];	
			   	 Clock_viewxs(byte)	;
			   	}
				 SysLinearTimer=0;
			 }
	  	   }
		   key=Keyset.keyEfficiency;
		  /*按键处理*/
           switch(key)
		   	{
               case key_no:
			   case key_back:
			   	        continue;
		       case key_down:
			   case key_up:
			   	      Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
			   	      option=keyoption_js(option, key,4,Emune_key);//
					  Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
                    /*  if(key==key_up)
                      	{
                         PWM_sign_acc(0.0, 0.0);
						 delay(0x80000);
                         PIN_DCAC_pwm(EDC_power);
                      	 PWM_sign_acc(0.0, 0.7);
                      	}
					  else
					  	{
					  	 PWM_sign_acc(0.0, 0.0);
						 delay(0x80000);
					   	 PIN_DCAC_pwm(EAC_power);
					  	 PWM_sign_acc(50.0, 0.8);
					  	}
					 */ 	
					  break;				
			   case key_ok:	
			   	      switch(option)
			   	      	{
			   	      	 
                          case ELan_main://语言
							    set.mune.Langue++;
							    set.mune.Langue&=0x01;
                                //ShowtextLine(mainset_lin+option*mainset_high, mainset_column+0x10,Lanset_p[set.mune.Langue]);	
								break;
					      case EOilset_main://油样设置
						  	    oidset();
							    break;
						  case EView_main://历史数据
						  	    Viewdata_Hander();
						  	   break;
						  case EClock_main://时钟设置
							   clockset_mune();
                               break;			   
			   	      	}					  
					    goto mainset_go ;
               case key_oil:                     			
			          Oilclear();//排油
					 break;
			   	     					  
		   	}
	  	}
}	
Ejemplo n.º 10
0
//*****************************************************************************
//
// Configure the SysTick and SysTick interrupt with a period of 1 second.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulPrevCount = 0;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Systick operation.
    //
    InitConsole();

    //
    // Display the setup on the console.
    //
    UARTprintf("SysTick Firing Interrupt ->");
    UARTprintf("\n   Rate = 1sec\n\n");

    //
    // Initialize the interrupt counter.
    //
    g_ulCounter = 0;

    //
    // Set up the period for the SysTick timer.  The SysTick timer period will
    // be equal to the system clock, resulting in a period of 1 second.
    //
    SysTickPeriodSet(SysCtlClockGet());

    //
    // Enable interrupts to the processor.
    //
    IntMasterEnable();

    //
    // Enable the SysTick Interrupt.
    //
    SysTickIntEnable();

    //
    // Enable SysTick.
    //
    SysTickEnable();

    //
    // Loop forever while the SysTick runs.
    //
    while(1)
    {
        //
        // Check to see if systick interrupt count changed, and if so then
        // print a message with the count.
        //
        if(ulPrevCount != g_ulCounter)
        {
            //
            // Print the interrupt counter.
            //
            UARTprintf("Number of interrupts: %d\r", g_ulCounter);
            ulPrevCount = g_ulCounter;
        }
    }
}
Ejemplo n.º 11
0
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////    MAIN    ///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int main(void)
{
	IntMasterDisable();

	//=====SYSTEM PERIPHERAL INITIALIZATION=====

	// Initialize real time clock
	mRTCInit(RTC_RATE_HZ);

	// Millisecond timekeeping variable
	int time;

	//Add periodic tasks to be executed by systick
	mRTCAddTask(heightSample, HEIGHT_SAMPLE_RATE_HZ);

	// Set up display
    mDisplayInit(1000000);
    mDisplayLine("     Waiting...    ", 0, 5, 15);

	// Set up buttons
    ButtonInit();

	// Set up PWM
	mPWMInit();
	mPWMEnable(PWM4, false); // tail rotor, yaw control.
	mPWMEnable(PWM1, false); // main rotor, height control.

	//=========CONTROL INITIALIZATION========


	//-----altitude PID control------

    // Initialize altitude module
	heightInit();

	// =========PID parameters========================

	//Phils
	float H_kp = 1;float H_ki = 1.5;float H_kd = -0.5;

	short heightPIDOffset = 40;

	float Y_kp = 0.6;float Y_ki = 0;float Y_kd = 0;

	short YawPIDOffset = 0;//50;


	// Windup regulator
	float H_windup_limit = 10;
	if (H_ki)
		H_windup_limit /= H_ki;

	// height PID controller
	pid_t heightPID;
	PIDInit(&heightPID);
	PIDSet(&heightPID, H_kp, H_ki, H_kd, H_windup_limit); // set PID constants

	// height PID control variables
	//35; // PID out offset such that the rotor is at near-takoff speed
	short height = 0;
    short heightSetpoint = 0; // in degrees
    short heightError = 0;
    short heightPIDOut = 0;


	//-----yaw PID control-------

	// Initialise Yaw decoder module
	yawInit(); // yaw monitor



	float Y_windup_limit = 20; // Maximum integral contribution to PID output value
	if (Y_ki)
		Y_windup_limit /= Y_ki;	// devide by Y_ki to find maximum value in terms of error

	// Yaw PID controller
	pid_t yawPID;
	PIDInit(&yawPID);
	PIDSet(&yawPID, Y_kp, Y_ki, Y_kd, Y_windup_limit); // set PID constants

	// yaw PID control variables
	short yaw = 0;
	short yawSetpoint = 0;
    short yawError = 0;
    short yawPIDOut = 0;


    //
    // Enable interrupts to the processor.
    IntMasterEnable();


    short takeOffFlag = false;
	while (!takeOffFlag)
	{
		if (ButtonCheck(SELECT))
		//if (GPIOPinRead(GPIO_PORTG_BASE, 0x80))
		{
			takeOffFlag = true;
		}
	}

	// Reset setpoints to current position
	heightSetpoint = heightGet();
	yawSetpoint = yawGetAngle();



	mPWMEnable(PWM4, true); // tail rotor, yaw control.
	mPWMEnable(PWM1, true); // main rotor, height control.


	//spin up routine
	//spinUp(heightPIDOffset, yawPID);

	// Reset clock to zero for effective helicopter launch time
	mRTCSet(0);

	while (1)
	{
		//mDisplayClear();

		time = mRTCGetMilliSeconds();

		// Update Setpoints
		updateSetpoints(&yawSetpoint, &heightSetpoint);

		// ==================PID Control=================
		if ((time % (RTC_RATE_HZ/PID_RATE_HZ)) /*1000/(float)PID_RATE_HZ*/ == 0)
		{
			//
			// ~~~~~~~~~~~~~~~~~ HEIGHT PID ~~~~~~~~~~~~~~~~

			height = heightGet();

			heightError = heightSetpoint - height;

			heightPIDOut = PIDUpdate(&heightPID, heightError, 1.00 / (float)PID_RATE_HZ) + heightPIDOffset;

			if (heightPIDOut > 79)
				//heightPIDOut = 79;
			if (heightPIDOut < 2)
				heightPIDOut = 2;

			mPWMSet(PWM1, (unsigned short)heightPIDOut);


			//
			// ~~~~~~~~~~~~~~~~~~ YAW PID ~~~~~~~~~~~~~~~~~~~
			yaw = yawGetAngle();

			yawError = yaw - yawSetpoint;

			yawPIDOut = PIDUpdate(&yawPID, yawError, 1.00 / (float)PID_RATE_HZ) + YawPIDOffset;

			if (yawPIDOut > 79)
				yawPIDOut = 79;
			if (yawPIDOut < 2)
				yawPIDOut = 2;

			mPWMSet(PWM4, (unsigned short)yawPIDOut);

			// ===============================================
		}

		// RTC_RATE_HZ - PID_RATE_HZ
		if (( (time) % 10) == 0)
		{
			mDisplayLine("time:%.6d mS", time, 0, 7);
			mDisplayLine("Yaw  = %.4d'    ", (int)yaw, 1, 15);
			mDisplayLine("YSet = %.4d'    ", (int)yawSetpoint, 2, 15);
			mDisplayLine("YErr = %.4d'    ", (int)yawError, 3, 15);
			mDisplayLine("YOut = %.4d'    ", (int)yawPIDOut, 4, 15);
			mDisplayLine("height = ~%.3d ", (int)height, 5, 15);
			mDisplayLine("Hset   = %.4d   ", (int)heightSetpoint, 6, 15);
			mDisplayLine("Herr   = %.4d   ", (int)heightError, 7, 15);
			mDisplayLine("Hout   = %.4d   ", (int)heightPIDOut, 8, 15);
		}

		// should put this as part of the main while loop condition
		//if (ButtonCheck(SELECT))
		//{
		//	spinDown();
		//}

	}
}
Ejemplo n.º 12
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    //
    // Initialize the display driver.
    //
    Formike128x128x16Init();

    //
    // Turn on the backlight.
    //
    Formike128x128x16BacklightOn();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sFormike128x128x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 14;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "uart_echo", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Initialize the CSTN display and write status.
    //
    GrStringDraw(&g_sContext, "Port:   Uart 0",       -1, 12, 24, 0);
    GrStringDraw(&g_sContext, "Baud:   115,200 bps",  -1, 12, 32, 0);
    GrStringDraw(&g_sContext, "Data:   8 Bit",        -1, 12, 40, 0);
    GrStringDraw(&g_sContext, "Parity: None",         -1, 12, 48, 0);
    GrStringDraw(&g_sContext, "Stop:   1 Bit",        -1, 12, 56, 0);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"Ingrese un Texto: ", 18);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
Ejemplo n.º 13
0
int
main(void)
{
	display[0] = '\0';
	display2[0] = '\0';
    	// Set the clocking to run directly from the crystal.
    	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    	// Initialize the OLED display and write status.
    	RIT128x96x4Init(1000000);
	RIT128x96x4StringDraw("----------------------", 0, 50, 15);

    	// Enable the peripherals used by this example.

    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);		
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
		
	// Status
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
	GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_DIR_MODE_OUT);
		
	//PB1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
	GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_DIR_MODE_IN);
		
	GPIOPortIntRegister(GPIO_PORTB_BASE, PortBIntHandler);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_BOTH_EDGES);
	GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_1);
		
	IntPrioritySet(INT_GPIOB,0x80);
	SysTickIntRegister(SysTickHandler);                  
	SysTickPeriodSet(SysCtlClockGet()/10000);	// 0.1ms
	SysTickIntEnable();
	waitTime = 0;					// initialize
	waitTime2 = 0;
	SysTickEnable();


    	// Enable processor interrupts.
    	IntMasterEnable();

    	// Set GPIO A0 and A1 as UART pins.
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    	// Configure the UART for 115,200, 8-N-1 operation.
    	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
												 
	UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,
                  	(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

   	 // Enable the UART interrupt.
    	IntEnable(INT_UART0);
   	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
		IntEnable(INT_UART1);
    	UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);



    	while(1)
   	{
    	}
}
//*****************************************************************************
//
// The main routine
//
//*****************************************************************************
int
main(void)
{
    int TypeID;
    tTRF79x0TRFMode eCurrentTRF79x0Mode = P2P_PASSIVE_TARGET_MODE;
    uint32_t x;
    uint16_t ui16MaxSizeRemaining=0;
    bool bCheck=STATUS_FAIL;
    uint8_t pui8Instructions[]="Instructions:\n "
                "You will need a NFC capable device and a NFC boosterpack for "
                "this demo\n "
                "To use this demo put the phone or tablet within 2 inches of "
                "the NFC boosterpack\n "
                "Messages sent to the microcontroller will be displayed on "
                "the terminal and screen\n "
                "Messages can be sent back to the NFC device via the "
                "'Echo Tag' button on the pull down menu\n";

    //
    // Run from the PLL at 120 MHz.
    //
    g_ui32SysClk = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                       SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_PLL |
                                       SYSCTL_CFG_VCO_480), 120000000);
    //
    // Select NFC Boosterpack Type
    //
    g_eRFDaughterType = RF_DAUGHTER_TRF7970ATB;

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, g_ui32SysClk);

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(g_ui32SysClk);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Initialize the Touch Screen Frames and related Animations.
    //
    ScreenInit();

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "nfc-p2p-demo");

    //
    // Initialize USER LED to Blue. (May Overlap TriColor LED)
    //
    ENABLE_LED_PERIPHERAL;
    SET_LED_DIRECTION;

    //
    // Initialize TriColer LED if it exists.
    //
    if(BOARD_HAS_TRICOLOR_LED)
    {
        ENABLE_LED_TRICOLOR_RED_PERIPH;
        SET_LED_TRICOLOR_RED_DIRECTION;
        ENABLE_LED_TRICOLOR_BLUE_PERIPH;
        SET_LED_TRICOLOR_BLUE_DIRECTION;
        ENABLE_LED_TRICOLOR_GREEN_PERIPH;
        SET_LED_TRICOLOR_GREEN_DIRECTION;
    }

    //
    // Initialize the TRF79x0 and SSI.
    //
    TRF79x0Init();

    //
    // Initialize Timer0A.
    //
    Timer0AInit();

    //
    // Enable First Mode.
    //
    NFCP2P_init(eCurrentTRF79x0Mode,FREQ_212_KBPS);

    //
    // Enable Interrupts.
    //
    IntMasterEnable();

    //
    // Print a prompt to the console.
    //
    UARTprintf("\n****************************\n");
    UARTprintf("*       NFC P2P Demo       *\n");
    UARTprintf("****************************\n");

    //
    // Print instructions to the console / screen.
    //
    UARTprintf((char *)pui8Instructions);
    ScreenPayloadWrite(pui8Instructions,sizeof(pui8Instructions),1);

    while(1)
    {
        //
        // Update Screen.
        //
        ScreenPeriodic();

        //
        // NFC-P2P-Initiator-Statemachine.
        //
        if(NFCP2P_proccessStateMachine() == NFC_P2P_PROTOCOL_ACTIVATION)
        {
            if(eCurrentTRF79x0Mode == P2P_INITATIOR_MODE)
            {
                eCurrentTRF79x0Mode = P2P_PASSIVE_TARGET_MODE;
                //Toggle LED's
                if(BOARD_HAS_TRICOLOR_LED)
                {
                    TURN_OFF_LED_TRICOLOR_GREEN
                    TURN_OFF_LED_TRICOLOR_RED;
                    TURN_ON_LED_TRICOLOR_BLUE
                }

            }
            else if(eCurrentTRF79x0Mode == P2P_PASSIVE_TARGET_MODE)
            {
                eCurrentTRF79x0Mode = P2P_INITATIOR_MODE;

                //
                // Toggle LED's.
                //
                if(BOARD_HAS_TRICOLOR_LED)
                {
                    TURN_OFF_LED_TRICOLOR_BLUE
                    TURN_ON_LED_TRICOLOR_RED
                    TURN_ON_LED_TRICOLOR_GREEN
                }
            }
Ejemplo n.º 15
0
int main(void)
{
#ifdef PART_LM4F120H5QR // ARM code
  SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN ); //set system clock to 80 MHz
  FPUEnable(); //enable the Floating Point Unit
//  FPULazyStackingEnable(); // Enable stacking for interrupt handlers
#endif

  // Initialize system
  serial_init(); // Setup serial baud rate and interrupts
  settings_init(); // Load grbl settings from EEPROM
  st_init(); // Setup stepper pins and interrupt timers

#ifdef PART_LM4F120H5QR // ARM code
  IntMasterEnable();
#else // AVR code
  sei(); // Enable interrupts
#endif
  
  memset(&sys, 0, sizeof(sys));  // Clear all system variables
  sys.abort = true;   // Set abort to complete initialization
  sys.state = STATE_INIT;  // Set alarm state to indicate unknown initial position
  
  for(;;) {
  
    // Execute system reset upon a system abort, where the main program will return to this loop.
    // Once here, it is safe to re-initialize the system. At startup, the system will automatically
    // reset to finish the initialization process.
    if (sys.abort) {
      // Reset system.
      serial_reset_read_buffer(); // Clear serial read buffer
      plan_init(); // Clear block buffer and planner variables
      gc_init(); // Set g-code parser to default state
      protocol_init(); // Clear incoming line data and execute startup lines
      spindle_init();
      coolant_init();
      limits_init();
      st_reset(); // Clear stepper subsystem variables.

      // Sync cleared gcode and planner positions to current system position, which is only
      // cleared upon startup, not a reset/abort. 
      sys_sync_current_position();

      // Reset system variables.
      sys.abort = false;
      sys.execute = 0;
      if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; }
      
      // Check for power-up and set system alarm if homing is enabled to force homing cycle
      // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
      // startup scripts, but allows access to settings and internal commands. Only a homing
      // cycle '$H' or kill alarm locks '$X' will disable the alarm.
      // NOTE: The startup script will run after successful completion of the homing cycle, but
      // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
      // things uncontrollably. Very bad.
      #ifdef HOMING_INIT_LOCK
        if (sys.state == STATE_INIT && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
      #endif
      
      // Check for and report alarm state after a reset, error, or an initial power up.
      if (sys.state == STATE_ALARM) {
        report_feedback_message(MESSAGE_ALARM_LOCK); 
      } else {
        // All systems go. Set system to ready and execute startup script.
        sys.state = STATE_IDLE;
        protocol_execute_startup(); 
      }
    }
    
    protocol_execute_runtime();
    protocol_process(); // ... process the serial protocol
    
    // When the serial protocol returns, there are no more characters in the serial read buffer to
    // be processed and executed. This indicates that individual commands are being issued or 
    // streaming is finished. In either case, auto-cycle start, if enabled, any queued moves.
    if (sys.auto_start) { st_cycle_start(); }
    
  }
  // return 0;   /* never reached */
}
Ejemplo n.º 16
0
//*****************************************************************************
//
// Main function performs init and manages system.
//
// Called automatically after the system and compiler pre-init sequences.
// Performs system init calls, restores state from hibernate if needed and
// then manages the application context duties of the system.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Status;
    uint32_t ui32ResetCause;
    int32_t i32CommandStatus;

    //
    // Enable stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPUEnable();
    ROM_FPUStackingEnable();

    //
    // Set the system clock to run at 40Mhz off PLL with external crystal as
    // reference.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Enable the hibernate module
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Enable and Initialize the UART.
    //
    ConfigureUART();

    UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n");
    UARTprintf("Type 'help' for a list of commands\n");
    UARTprintf("> ");

    //
    // Determine why system reset occurred and respond accordingly.
    //
    ui32ResetCause = SysCtlResetCauseGet();
    SysCtlResetCauseClear(ui32ResetCause);
    if(ui32ResetCause == SYSCTL_CAUSE_POR)
    {
        if(HibernateIsActive())
        {
            //
            // Read the status bits to see what caused the wake.
            //
            ui32Status = HibernateIntStatus(0);
            HibernateIntClear(ui32Status);

            //
            // Wake was due to the push button.
            //
            if(ui32Status & HIBERNATE_INT_PIN_WAKE)
            {
                UARTprintf("Hibernate Wake Pin Wake Event\n");
                UARTprintf("> ");

                //
                // Recover the application state variables from battery backed
                // hibernate memory.  Set ui32Mode to normal.
                //
                HibernateDataGet((uint32_t*) &g_sAppState,
                                 sizeof(tAppState) / 4 + 1);
                g_sAppState.ui32Mode = APP_MODE_NORMAL;
            }

            //
            // Wake was due to RTC match
            //
            else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
            {
                UARTprintf("Hibernate RTC Wake Event\n");
                UARTprintf("> ");
                //
                // Recover the application state variables from battery backed
                // hibernate memory. Set ui32Mode to briefly flash the RGB.
                //
                HibernateDataGet((uint32_t*) &g_sAppState,
                                sizeof(tAppState) / 4 + 1);
                g_sAppState.ui32Mode = APP_MODE_HIB_FLASH;
            }
        }

        else
        {
            //
            // Reset was do to a cold first time power up.
            //
            UARTprintf("Power on reset. Hibernate not active.\n");
            UARTprintf("> ");

            g_sAppState.ui32Mode = APP_MODE_NORMAL;
            g_sAppState.fColorWheelPos = 0;
            g_sAppState.fIntensity = APP_INTENSITY_DEFAULT;
            g_sAppState.ui32Buttons = 0;
        }
    }
    else
    {
        //
        // External Pin reset or other reset event occured.
        //
        UARTprintf("External or other reset\n");
        UARTprintf("> ");

        //
        // Treat this as a cold power up reset without restore from hibernate.
        //
        g_sAppState.ui32Mode = APP_MODE_NORMAL;
        g_sAppState.fColorWheelPos = APP_PI;
        g_sAppState.fIntensity = APP_INTENSITY_DEFAULT;
        g_sAppState.ui32Buttons = 0;

    //
        // colors get a default initialization later when we call AppRainbow.
        //
    }

    //
    // Initialize clocking for the Hibernate module
    //
    HibernateEnableExpClk(SysCtlClockGet());

    //
    // Initialize the RGB LED. AppRainbow typically only called from interrupt
    // context. Safe to call here to force initial color update because
    // interrupts are not yet enabled.
    //
    RGBInit(0);
    RGBIntensitySet(g_sAppState.fIntensity);
    AppRainbow(1);
    RGBEnable();

    //
    // Initialize the buttons
    //
    ButtonsInit();

    //
    // Initialize the SysTick interrupt to process colors and buttons.
    //
    SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC);
    SysTickEnable();
    SysTickIntEnable();
    IntMasterEnable();

    //
    // spin forever and wait for carriage returns or state changes.
    //
    while(1)
    {

        UARTprintf("\n>");


        //
        // Peek to see if a full command is ready for processing
        //
        while(UARTPeek('\r') == -1)
        {
            //
            // millisecond delay.  A SysCtlSleep() here would also be OK.
            //
            SysCtlDelay(SysCtlClockGet() / (1000 / 3));

            //
            // Check for change of mode and enter hibernate if requested.
            // all other mode changes handled in interrupt context.
            //
            if(g_sAppState.ui32Mode == APP_MODE_HIB)
            {
                AppHibernateEnter();
            }
        }

        //
        // a '\r' was detected get the line of text from the user.
        //
        UARTgets(g_cInput,sizeof(g_cInput));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32CommandStatus = CmdLineProcess(g_cInput);

        //
        // Handle the case of bad command.
        //
        if(i32CommandStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("Bad command!\n");
        }

        //
        // Handle the case of too many arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("Too many arguments for command processor!\n");
        }
    }
}
Ejemplo n.º 17
0
int main(void)
{ 
    unsigned int i = 0;

    // Clock (80MHz)
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
    
    // GPIO
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);

    
    // UART (Serial)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8));

    UARTEnable(UART0_BASE);
    UARTFIFODisable(UART0_BASE);
  
    
    /*I2CInit();

    // PCA9557
    i2c_buff[0] = 0x03;
    i2c_buff[1] = 0x00; // 0: Output   1: Input
    I2CWrite(0x18, i2c_buff, 2);  // IO Direction

    i2c_buff[0] = 0x02;
    i2c_buff[1] = 0x00;
    I2CWrite(0x18, i2c_buff, 2);  // IO Polarity

    i2c_buff[0] = 0x01;
    i2c_buff[1] = 0x8F;
    I2CWrite(0x18, i2c_buff, 2);  // Output H/L
*/


    //initLEDs();
    //initMotors();
    //initEncoders();
    initServos();
    //initBluetooth();
    
    //invertMotor(0);
    //invertMotor(1);
    //invertEncoder(0);

    

    // Do some tests
    //setMotor(0, 0.85);
    //setMotor(1, 0.85);
    setServoLimits(5, 0.35, 0.85);


    // Enable Interrupts
    IntMasterEnable();


    while(1)
    {

        //for(i=0; i<12; i++)
        //{
            setServo(5, 0.0);
            toggleRed();
            SysCtlDelay(SysCtlClockGet());
        //    printf("%d\r\n", i*5);
            
            setServo(5, 0.6);
            toggleRed();
            SysCtlDelay(SysCtlClockGet());


        //}



        // LED On
       /* toggleRed();

        printf("0:% 6ld  1:% 6ld\r\n", readEnc(0), readEnc(1));

        SysCtlDelay(SysCtlClockGet() / 3 / 5);


        if (i == 10)  // 5 Seconds
        {
           i2c_buff[0] = 0x01;
           i2c_buff[1] = 0x0F | 0x00;
           I2CWrite(0x18, i2c_buff, 2);  // Output H/L
        }

        i++;
*/

        /*I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);  // Set Outputs Directions
        I2CMasterDataPut(I2C0_BASE, 0x01);             
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        while(I2CMasterBusy(I2C0_BASE));
        I2CMasterDataPut(I2C0_BASE, 0x00);            
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_BASE));


        I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);  // Set Outputs Directions
        I2CMasterDataPut(I2C0_BASE, 0x01);             
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        while(I2CMasterBusy(I2C0_BASE));
        I2CMasterDataPut(I2C0_BASE, 0xF0);            
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_BASE));
        */


        //UART1Write("A\r\n", 3);
        //UARTCharPut(UART1_BASE, 'B');
        
        //UART1WriteChar(UARTCharGet(UART0_BASE));
        
       /* 
        for (i=0; i<8; i++)
        {
            unsigned char tmp;  
          
            i2c_buff[0] = 0x84 | (i << 4);
            I2CWrite(0x48, i2c_buff, 1);
            if (I2CMasterErr(I2C0_BASE))
                printf("Err: %d\r\n", (unsigned int) I2CMasterErr(I2C0_BASE));

            I2CRead(0x48, &tmp, 1);
            if (I2CMasterErr(I2C0_BASE))
                printf("Err: %d\r\n", (unsigned int) I2CMasterErr(I2C0_BASE));


            printf("% 3d ", tmp);
        }*/

       /* toggleRed();

        for(i=0; i<=100; i++)
        {
            setMotor(0, 0.01 * i);
            setMotor(1, 0.01 * i);
            setMotor(2, 0.01 * i);
            setMotor(3, 0.01 * i);
            printf("%d\r\n", i);
            SysCtlDelay(SysCtlClockGet() / 3 / 100);
        }

        toggleRed();

        for(; i>0; i--)
        {
            setMotor(0, 0.01 * i);
            setMotor(1, 0.01 * i);
            setMotor(2, 0.01 * i);
            setMotor(3, 0.01 * i);
            printf("%d\r\n", i);
            SysCtlDelay(SysCtlClockGet() / 3 / 100);
        }*/


        
        //printf("%d\r\n", (unsigned int) (((ADCRead(3) >> 4) - 45) * 0.45));
        //setServo(0, (((ADCRead(3) >> 4) - 45) * 0.45) / 100.0);

/*
        I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);  // Set Outputs Directions
        I2CMasterDataPut(I2C0_BASE, 0x01);             
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        while(I2CMasterBusy(I2C0_BASE));
        if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4) == 0)
            I2CMasterDataPut(I2C0_BASE, 0x80);            
        else
            I2CMasterDataPut(I2C0_BASE, 0x70);            
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_BASE));*/


        /*I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);
        I2CMasterDataPut(I2C0_BASE, 0x00);
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
        while(I2CMasterBusy(I2C0_BASE));

        I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, true);
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
        while(I2CMasterBusy(I2C0_BASE));

        if( (I2CMasterDataGet(I2C0_BASE) & 0x01) != 0)
            toggleBlue();*/
    }


}
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display and write status.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("UART Echo",            36,  0, 15);
    RIT128x96x4StringDraw("Port:   Uart 0",       12, 16, 15);
    RIT128x96x4StringDraw("Baud:   115,200 bps",  12, 24, 15);
    RIT128x96x4StringDraw("Data:   8 Bit",        12, 32, 15);
    RIT128x96x4StringDraw("Parity: None",         12, 40, 15);
    RIT128x96x4StringDraw("Stop:   1 Bit",        12, 48, 15);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
Ejemplo n.º 19
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
  
  static struct etimer timer;
  static int count;
  PROCESS_BEGIN();
/*  i2c_init(I2C_SCL_PORT, I2C_SCL_PIN, I2C_SDA_PORT, I2C_SDA_PIN, 
             I2C_SCL_NORMAL_BUS_SPEED);*/

  etimer_set(&timer, CLOCK_CONF_SECOND * 1);
  count = 0;
  relay_enable(PORT_D,LED_RELAY_PIN);
 
   while(1) {

    PROCESS_WAIT_EVENT();

    if(ev == PROCESS_EVENT_TIMER) {
        
      if(count %2 == 0){
		//relay_on(PORT_D,LED_RELAY_PIN);
	int delayIndex;

  	unsigned int pwmDutyCycle = 0x0000;

 

    //

    // Initialize the interrupt counter.

    //

    int g_ui32Counter = 0;

 

   

    //

    // Set the clocking to run directly from the external crystal/oscillator.

    // (no ext 32k osc, no internal osc)

    //

    SysCtrlClockSet(false, false, 32000000);

 

    //

    // Set IO clock to the same as system clock

    //

    SysCtrlIOClockSet(32000000);   

   

    //

    // The Timer0 peripheral must be enabled for use.

    //

    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);   

 

    //

    // Set up the serial console to use for displaying messages.  This is

    // just for this example program and is not needed for Timer operation.

    //

    //InitConsole();  

 

    //

    // Display the example setup on the console.

    //

    UARTprintf("16-Bit Timer PWM ->");

    UARTprintf("\n   Timer = Timer0B");

    UARTprintf("\n   Mode = PWM with variable duty cycle");

 

    //

    // Configure GPTimer0A as a 16-bit PWM Timer.

    //

    TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |

                   GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PWM);

 

    //

    // Set the GPTimer0B load value to 1sec by setting the timer load value

    // to SYSCLOCK / 255. This is determined by:

    //      Prescaled clock = 16Mhz / 255

    //      Cycles to wait = 1sec * Prescaled clock

    TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, SysCtrlClockGet() / 4000);       

 

    TimerControlLevel(GPTIMER0_BASE, GPTIMER_A, false);

   

    // Configure GPIOPortA.0 as the Timer0_InputCapturePin.1

    IOCPinConfigPeriphOutput(GPIO_A_BASE, GPIO_PIN_0, IOC_MUX_OUT_SEL_GPT0_ICP1);

       

    // Tell timer to use GPIOPortA.0

    // Does Direction Selection and PAD Selection

    GPIOPinTypeTimer(GPIO_A_BASE, GPIO_PIN_0);

    

    //

    // Enable processor interrupts.

    //

    IntMasterEnable();    

 

    //

    // Enable GPTimer0B.

    //

    TimerEnable(GPTIMER0_BASE, GPTIMER_A);   

 

    UARTprintf("\n");

    //

    // Loop forever while the Timer0B runs.

    //

    while(1)

    {

      for (delayIndex = 0; delayIndex < 100000; delayIndex++);

     

      pwmDutyCycle += 0x0F;

      pwmDutyCycle &= 0xFFFF;

     

      TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, pwmDutyCycle);

     

      UARTprintf("PWM DC Value: %04X -- %04X -- %04X\r",

                      pwmDutyCycle,

                      TimerValueGet(GPTIMER0_BASE, GPTIMER_A),

                      TimerMatchGet(GPTIMER0_BASE, GPTIMER_A) );

     

    	}

	



		
		  //SENSORS_ACTIVATE(cc2538_temp_sensor);
                  // printf( "%d is temp\n",cc2538_temp_sensor.value); 
		

      	}
      	else {  
       		//relay_off(PORT_D,LED_RELAY_PIN);
      	} 
/*	if(count %2 == 0)
	{	
		relay_toggle(PORT_D,LED_RELAY_PIN);
		relay_status(PORT_D,LED_RELAY_PIN);
	}
*/
	count ++;
	etimer_reset(&timer);
    }
  }
  
  
  PROCESS_END();
}
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock;
    tContext sContext;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "uart-echo");

    //
    // Display UART configuration on the display.
    //
    GrStringDraw(&sContext, "Port:",       -1,  70, 70, 0);
    GrStringDraw(&sContext, "Baud:",       -1,  70, 95, 0);
    GrStringDraw(&sContext, "Data:",       -1,  70, 120, 0);
    GrStringDraw(&sContext, "Parity:",     -1,  70, 145, 0);
    GrStringDraw(&sContext, "Stop:",       -1,  70, 170, 0);
    GrStringDraw(&sContext, "Uart 0",      -1, 150, 70, 0);
    GrStringDraw(&sContext, "115,200 bps", -1, 150, 95, 0);
    GrStringDraw(&sContext, "8 Bit",       -1, 150, 120, 0);
    GrStringDraw(&sContext, "None",        -1, 150, 145, 0);
    GrStringDraw(&sContext, "1 Bit",       -1, 150, 170, 0);

    //
    // Enable the (non-GPIO) peripherals used by this example.  PinoutSet()
    // already enabled GPIO Port A.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((uint8_t *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
Ejemplo n.º 21
0
//*****************************************************************************
//
// This is the main example program.  It checks to see that the interrupts are
// processed in the correct order when they have identical priorities,
// increasing priorities, and decreasing priorities.  This exercises interrupt
// preemption and tail chaining.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulError;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_6MHZ);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Initialize the OLED display and write status.
    //
    Display96x16x1Init(false);
    Display96x16x1StringDraw("Act:    Pend:   ", 0, 1);

    //
    // Configure the first three pins of GPIO port D to be outputs to indicate
    // entry/exit of one of the interrupt handlers.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,
                          GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0);

    //
    // Set up and enable the SysTick timer.  It will be used as a reference
    // for delay loops in the interrupt handlers.  The SysTick timer period
    // will be set up for one second.
    //
    SysTickPeriodSet(SysCtlClockGet());
    SysTickEnable();

    //
    // Reset the error indicator.
    //
    ulError = 0;

    //
    // Enable interrupts to the processor.
    //
    IntMasterEnable();

    //
    // Enable the interrupts.
    //
    IntEnable(INT_GPIOA);
    IntEnable(INT_GPIOB);
    IntEnable(INT_GPIOC);

    //
    // Indicate that the equal interrupt priority test is beginning.
    //
    Display96x16x1StringDraw("Equal Priority  ", 0, 0);

    //
    // Set the interrupt priorities so they are all equal.
    //
    IntPrioritySet(INT_GPIOA, 0x00);
    IntPrioritySet(INT_GPIOB, 0x00);
    IntPrioritySet(INT_GPIOC, 0x00);

    //
    // Reset the interrupt flags.
    //
    g_ulGPIOa = 0;
    g_ulGPIOb = 0;
    g_ulGPIOc = 0;
    g_ulIndex = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the LCD.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1))
    {
        ulError |= 1;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Indicate that the decreasing interrupt priority test is beginning.
    //
    Display96x16x1StringDraw("Dec. Priority   ", 0, 0);

    //
    // Set the interrupt priorities so that they are decreasing (i.e. C > B >
    // A).
    //
    IntPrioritySet(INT_GPIOA, 0x80);
    IntPrioritySet(INT_GPIOB, 0x40);
    IntPrioritySet(INT_GPIOC, 0x00);

    //
    // Reset the interrupt flags.
    //
    g_ulGPIOa = 0;
    g_ulGPIOb = 0;
    g_ulGPIOc = 0;
    g_ulIndex = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the LCD.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1))
    {
        ulError |= 2;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Indicate that the increasing interrupt priority test is beginning.
    //
    Display96x16x1StringDraw("Inc. Priority   ", 0, 0);

    //
    // Set the interrupt priorities so that they are increasing (i.e. C < B <
    // A).
    //
    IntPrioritySet(INT_GPIOA, 0x00);
    IntPrioritySet(INT_GPIOB, 0x40);
    IntPrioritySet(INT_GPIOC, 0x80);

    //
    // Reset the interrupt flags.
    //
    g_ulGPIOa = 0;
    g_ulGPIOb = 0;
    g_ulGPIOc = 0;
    g_ulIndex = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the LCD.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ulGPIOa != 1) || (g_ulGPIOb != 2) || (g_ulGPIOc != 3))
    {
        ulError |= 4;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Disable the interrupts.
    //
    IntDisable(INT_GPIOA);
    IntDisable(INT_GPIOB);
    IntDisable(INT_GPIOC);

    //
    // Disable interrupts to the processor.
    //
    IntMasterDisable();

    //
    // Print out the test results.
    //
    Display96x16x1StringDraw("Int Priority    ", 0, 0);
    if(ulError)
    {
        Display96x16x1StringDraw("=: P  >: P  <: P", 0, 1);
        if(ulError & 1)
        {
            Display96x16x1StringDraw("F", 18, 1);
        }
        if(ulError & 2)
        {
            Display96x16x1StringDraw("F", 54, 1);
        }
        if(ulError & 4)
        {
            Display96x16x1StringDraw("F", 90, 1);
        }
    }
    else
    {
        Display96x16x1StringDraw("Success.        ", 0, 1);
    }

    //
    // Finished.
    //
    while(1)
    {
    }
}
Ejemplo n.º 22
0
void GPS::InterruptEnable(){
	// Enable interrupts for GPS-side UART
	IntMasterEnable();		// master interrupt enable
	IntEnable(INT_UART1);
	UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);	// receiver RX and receiver timeout interrupts RT(timeout = 32 bits)
}
Ejemplo n.º 23
0
//  void setup(void) runs ONCE when the program just STARTS
void setup()
{
  // First SET the SYSTEM CLOCK to 80 [MHz]
  //  Sets the Clock DIVIDER to 2.5, so that SYS_CLOCK runs at 200/2.5 ==> 80 [MHz]
  SysCtlClockSet( SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

  uint32_t Timer0_Period;
  // Enable & Configure Serial(UART0) to BAUDRATE = 9216000
  Serial.begin(BAUDRATE);  

  // Configure PINS for LED OUTPUT
  pinMode(RED,OUTPUT);
  pinMode(BLUE,OUTPUT);
  pinMode(GREEN,OUTPUT);

  // Set LED OUTPUT pins to OFF initially
  digitalWrite(RED,LOW);
  digitalWrite(BLUE,LOW);
  digitalWrite(GREEN,LOW);
  state_led=0;  // initialize the STATE to STATE0

    // Initialize the 'Wire' class for the I2C-bus.
  Wire.begin();

  // Clear the 'sleep' bit to start the sensor.
  MPU9150_writeSensor(MPU9150_PWR_MGMT_1, 0);
  int temp0;
  temp0=  MPU9150_readSensor(0x1c);
  temp0 |= (0x10);
  temp0 &=~(0x08);

  
  MPU9150_writeSensor(0x1c,temp0);
  
  MPU9150_writeSensor(0x19,0x0f);
  MPU9150_setupCompass();

  
  SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0); // Enable Timer0

    TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // Set Timer0 mode PERIODIC



    // Timer0_Period ==> 80e6 * A / B, (1/2)=0.5
  Timer0_Period = ( 80000000 * A ) / B;      
  TimerLoadSet( TIMER0_BASE, TIMER_A, Timer0_Period-1);


  // REGISTER ISR to TIMER0 INTERRUPT
  TimerIntRegister( TIMER0_BASE, TIMER_A, Timer0_isr );

  // Enable Interrupts from Timer0_A
  IntEnable( INT_TIMER0A);


  // Set Timer Interrupt Condition and Enable Timer Interrupt
  TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  // Enable INTERRUPTS for the SYSTEM
  IntMasterEnable();

  // Start Timer0	
  TimerEnable(TIMER0_BASE, TIMER_A);        
}
/* ISR to key-scan, i have been thinking to just raise a flag and then later on check keypad */
void scan_key(void)
{
	/* convention *='e' #='f' */
	int i;
	int key=0;

	/* switch case is heavily hard-coded to actual pin connection, i need to think how to parametrize
	 * this */

	IntMasterDisable(); //disable interrupts
	//we have 4 rows so check one by one
	for (i=0;i<4;i++)
	{
		GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, (i==0)?0:GPIO_PIN_0);
		GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, (i==1)?0:GPIO_PIN_1);
		GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, (i==2)?0:GPIO_PIN_4);
		GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, (i==3)?0:GPIO_PIN_5);

		if ( GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_7) == 0)
		{
				switch (i)
				{
					case 0: key=0x0a;break;
					case 1: key=0x0b;break;
					case 2: key=0x0c;break;
					case 3: key=0x0d;break;
					default: key=-1;
				}
				break;
		}
		else if (GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_6) == 0)
		{
				switch (i)
				{
					case 0: key=3;break;
					case 1: key=6;break;
					case 2: key=9;break;
					case 3: key=0x0f;break;
					default: key=-1;
				}
				break;
		}
		else if (GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_5) == 0)
		{
				switch (i)
				{
					case 0: key=2;break;
					case 1: key=5;break;
					case 2: key=8;break;
					case 3: key=0;break;
					default: key=-1;
				}
				break;
		}
		else if (GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_4) == 0)
		{
				switch (i)
				{
					case 0: key=1;break;
					case 1: key=4;break;
					case 2: key=7;break;
					case 3: key=0x0e;break;
					default: key=-1;
				}
				break;
		}
	}

	//get ready for next interruption
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0);

	//store the value
	num = key;
	GPIOPinIntClear(GPIO_PORTB_BASE,GPIO_PIN_4);
	GPIOPinIntClear(GPIO_PORTA_BASE,GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
	IntMasterEnable();
}
Ejemplo n.º 25
0
//*****************************************************************************
//
// Toggle the JTAG pins between JTAG and GPIO mode with a push button selecting
// between the two.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Mode;

    //
    // Set the clocking to run directly from the crystal at 120MHz.
    //
    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                             SYSCTL_OSC_MAIN |
                                             SYSCTL_USE_PLL |
                                             SYSCTL_CFG_VCO_480), 120000000);
    //
    // Enable the peripherals used by this application.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);


    //
    // Initialize the button driver.
    //
    ButtonsInit();

    //
    // Set up a SysTick Interrupt to handle polling and debouncing for our
    // buttons.
    //
    SysTickPeriodSet(g_ui32SysClock / 100);
    SysTickIntEnable();
    SysTickEnable();

    IntMasterEnable();

    //
    // Configure the LEDs as outputs and turn them on in the JTAG state.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_PIN_0);

    //
    // Set the global and local indicator of pin mode to zero, meaning JTAG.
    //
    g_ui32Mode = 0;
    ui32Mode = 0;

    //
    // Initialize the UART, clear the terminal, print banner.
    //
    ConfigureUART();
    UARTprintf("\033[2J\033[H");
    UARTprintf("GPIO <-> JTAG\n");

    //
    // Indicate that the pins start out as JTAG.
    //
    UARTprintf("Pins are JTAG\n");

    //
    // Loop forever.  This loop simply exists to display on the UART the
    // current state of PC0-3; the handling of changing the JTAG pins to and
    // from GPIO mode is done in GPIO Interrupt Handler.
    //
    while(1)
    {
        //
        // Wait until the pin mode changes.
        //
        while(g_ui32Mode == ui32Mode)
        {
        }

        //
        // Save the new mode locally so that a subsequent pin mode change can
        // be detected.
        //
        ui32Mode = g_ui32Mode;

        //
        // See what the new pin mode was changed to.
        //
        if(ui32Mode == 0)
        {
            //
            // Indicate that PC0-3 are currently JTAG pins.
            //
            UARTprintf("Pins are JTAG\n");
        }
        else
        {
            //
            // Indicate that PC0-3 are currently GPIO pins.
            //
            UARTprintf("Pins are GPIO\n");
        }
    }
}
Ejemplo n.º 26
0
/*
 * main.c
 */
int main(void) {
	float fTemperature, fHumidity;
	    int32_t i32IntegerPart;
	    int32_t i32FractionPart;


	g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
	                                             SYSCTL_OSC_MAIN |
	                                             SYSCTL_USE_PLL |
	                                             SYSCTL_CFG_VCO_480), 120000000);
	//confiugre the GPIO pins
	PinoutSet(false,false);

	ConfigureUART();

	//configure I2C pins
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8);

	GPIOPinConfigure(GPIO_PA2_I2C8SCL);
	GPIOPinConfigure(GPIO_PA3_I2C8SDA);

	GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_2);
	GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_3);

	//enable interrupts
	IntMasterEnable();

	//initialize I2C
	I2CMInit(&g_sI2CInst,I2C8_BASE,INT_I2C8,0xff,0xff,g_ui32SysClock);
	IntPrioritySet(INT_I2C7,0xE0);

	//initialize the sensors
	SHT21Init(&g_sSHT21Inst, &g_sI2CInst, SHT21_I2C_ADDRESS,
			SHT21AppCallback,&g_sSHT21Inst);

	//delay for 20 ms
	SysCtlDelay(g_ui32SysClock / (50 * 3));

	while(1){
		  //
		        // Turn on D2 to show we are starting a transaction with the sensor.
		        // This is turned off in the application callback.
		        //
		        LEDWrite(CLP_D1 | CLP_D2 , CLP_D2);

		        //
		        // Write the command to start a humidity measurement.
		        //
		        SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_RH, g_sSHT21Inst.pui8Data, 0,
		                SHT21AppCallback, &g_sSHT21Inst);

		        //
		        // Wait for the I2C transactions to complete before moving forward.
		        //
		        SHT21AppI2CWait(__FILE__, __LINE__);

		        //
		        // Wait 33 milliseconds before attempting to get the result. Datasheet
		        // claims this can take as long as 29 milliseconds.
		        //
		        SysCtlDelay(g_ui32SysClock / (30 * 3));

		        //
		        // Turn on D2 to show we are starting a transaction with the sensor.
		        // This is turned off in the application callback.
		        //
		        LEDWrite(CLP_D1 | CLP_D2 , CLP_D2);

		        //
		        // Get the raw data from the sensor over the I2C bus.
		        //
		        SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst);

		        //
		        // Wait for the I2C transactions to complete before moving forward.
		        //
		        SHT21AppI2CWait(__FILE__, __LINE__);

		        //
		        // Get a copy of the most recent raw data in floating point format.
		        //
		        SHT21DataHumidityGetFloat(&g_sSHT21Inst, &fHumidity);

		        //
		        // Turn on D2 to show we are starting a transaction with the sensor.
		        // This is turned off in the application callback.
		        //
		        LEDWrite(CLP_D1 | CLP_D2 , CLP_D2);

		        //
		        // Write the command to start a temperature measurement.
		        //
		        SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_T, g_sSHT21Inst.pui8Data, 0,
		                SHT21AppCallback, &g_sSHT21Inst);

		        //
		        // Wait for the I2C transactions to complete before moving forward.
		        //
		        SHT21AppI2CWait(__FILE__, __LINE__);

		        //
		        // Wait 100 milliseconds before attempting to get the result. Datasheet
		        // claims this can take as long as 85 milliseconds.
		        //
		        SysCtlDelay(g_ui32SysClock / (10 * 3));

		        //
		        // Turn on D2 to show we are starting a transaction with the sensor.
		        // This is turned off in the application callback.
		        //
		        LEDWrite(CLP_D1 | CLP_D2 , CLP_D2);

		        //
		        // Read the conversion data from the sensor over I2C.
		        //
		        SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst);

		        //
		        // Wait for the I2C transactions to complete before moving forward.
		        //
		        SHT21AppI2CWait(__FILE__, __LINE__);

		        //
		        // Get the most recent temperature result as a float in celcius.
		        //
		        SHT21DataTemperatureGetFloat(&g_sSHT21Inst, &fTemperature);

		        //
		        // Convert the floats to an integer part and fraction part for easy
		        // print. Humidity is returned as 0.0 to 1.0 so multiply by 100 to get
		        // percent humidity.
		        //
		        fHumidity *= 100.0f;
		        i32IntegerPart = (int32_t) fHumidity;
		        i32FractionPart = (int32_t) (fHumidity * 1000.0f);
		        i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
		        if(i32FractionPart < 0)
		        {
		            i32FractionPart *= -1;
		        }

		        //
		        // Print the humidity value using the integers we just created.
		        //
		        UARTprintf("Humidity %3d.%03d\t", i32IntegerPart, i32FractionPart);

		        //
		        // Perform the conversion from float to a printable set of integers.
		        //
		        i32IntegerPart = (int32_t) fTemperature;
		        i32FractionPart = (int32_t) (fTemperature * 1000.0f);
		        i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
		        if(i32FractionPart < 0)
		        {
		            i32FractionPart *= -1;
		        }

		        //
		        // Print the temperature as integer and fraction parts.
		        //
		        UARTprintf("Temperature %3d.%03d\n", i32IntegerPart, i32FractionPart);

		        //
		        // Delay for one second. This is to keep sensor duty cycle
		        // to about 10% as suggested in the datasheet, section 2.4.
		        // This minimizes self heating effects and keeps reading more accurate.
		        //
		        SysCtlDelay(g_ui32SysClock / 3);
	}


	
	return 0;
}
Ejemplo n.º 27
0
//*****************************************************************************
//
// Main application entry point.
//
//*****************************************************************************
int
main(void)
{
    int_fast32_t i32IPart[16], i32FPart[16];
    uint_fast32_t ui32Idx, ui32CompDCMStarted;
    float pfData[16];
    float *pfAccel, *pfGyro, *pfMag, *pfEulers, *pfQuaternion;

    //
    // Initialize convenience pointers that clean up and clarify the code
    // meaning. We want all the data in a single contiguous array so that
    // we can make our pretty printing easier later.
    //
    pfAccel = pfData;
    pfGyro = pfData + 3;
    pfMag = pfData + 6;
    pfEulers = pfData + 9;
    pfQuaternion = pfData + 12;

    //
    // Setup the system clock to run at 40 Mhz from PLL with crystal reference
    //
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    clock_rate = SysCtlClockGet(); // Note this is bug in TivaWare
    							   // Doesn't return correct clock frequency if clock frequency is greater than 50 MHz

    //
    // Enable port B used for motion interrupt.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    uint32_t k;
    for(k=0;k<1024;++k)
    {
    	SysCtlDelay( clock_rate/3);
    	UARTprintf("iteration = %4u%c%c",k,0x0d,0x0a);
    }
    //
    // Print the welcome message to the terminal.
    //
    UARTprintf("\033[2JMPU9150 Raw Example\n");

    //
    // Set the color to a purple approximation.
    //
    g_pui32Colors[RED] = 0x8000;
    g_pui32Colors[BLUE] = 0x8000;
    g_pui32Colors[GREEN] = 0x0000;

    //
    // Initialize RGB driver.
    //
    RGBInit(0);
    RGBColorSet(g_pui32Colors);
    RGBIntensitySet(0.5f);
    RGBEnable();

    //
    // The I2C3 peripheral must be enabled before use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the pin muxing for I2C3 functions on port D0 and D1.
    //
    GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    GPIOPinConfigure(GPIO_PD1_I2C3SDA);

    //
    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.  Consult the data sheet
    // to see which functions are allocated per pin.
    //
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
    GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

    //
    // Configure and Enable the GPIO interrupt. Used for INT signal from the
    // MPU9150
    //
    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
    IntEnable(INT_GPIOB);

    //
    // Keep only some parts of the systems running while in sleep mode.
    // GPIOB is for the MPU9150 interrupt pin.
    // UART0 is the virtual serial port
    // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver
    // I2C3 is the I2C interface to the ISL29023
    //
    SysCtlPeripheralClockGating(true);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5);

    //
    // Enable interrupts to the processor.
    //
    IntMasterEnable();

    //
    // Initialize I2C3 peripheral.
    //
    I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
             SysCtlClockGet());

    //
    // Initialize the MPU9150 Driver.
    //
    MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
                MPU9150AppCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MPU9150AppI2CWait(__FILE__, __LINE__);

    //
    // Write application specifice sensor configuration such as filter settings
    // and sensor range settings.
    //
    g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
    g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
                                  MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
                 MPU9150AppCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MPU9150AppI2CWait(__FILE__, __LINE__);

    //
    // Configure the data ready interrupt pin output of the MPU9150.
    //
    g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
                                    MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
                                    MPU9150_INT_PIN_CFG_LATCH_INT_EN;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
                 g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
                 &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MPU9150AppI2CWait(__FILE__, __LINE__);

    //
    // Initialize the DCM system. 50 hz sample rate.
    // accel weight = .2, gyro weight = .8, mag weight = .2
    //
    CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f);

    UARTprintf("\033[2J\033[H");
    UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n");
    UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n");
    UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n");
    UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n");
    UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n");
    UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n");
    UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n");

    UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|"
               "\033[71GQ4\n\n");
    UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n");

    //
    // Enable blinking indicates config finished successfully
    //
    RGBBlinkRateSet(1.0f);

    ui32CompDCMStarted = 0;

    while(1)
    {
        //
        // Go to sleep mode while waiting for data ready.
        //
        while(!g_vui8I2CDoneFlag)
        {
            SysCtlSleep();
        }

        //
        // Clear the flag
        //
        g_vui8I2CDoneFlag = 0;

        //
        // Get floating point version of the Accel Data in m/s^2.
        //
        MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1,
                                 pfAccel + 2);

        //
        // Get floating point version of angular velocities in rad/sec
        //
        MPU9150DataGyroGetFloat(&g_sMPU9150Inst, pfGyro, pfGyro + 1,
                                pfGyro + 2);

        //
        // Get floating point version of magnetic fields strength in tesla
        //
        MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, pfMag, pfMag + 1,
                                   pfMag + 2);

        //
        // Check if this is our first data ever.
        //
        if(ui32CompDCMStarted == 0)
        {
            //
            // Set flag indicating that DCM is started.
            // Perform the seeding of the DCM with the first data set.
            //
            ui32CompDCMStarted = 1;
            CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1],
                                 pfMag[2]);
            CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
                               pfAccel[2]);
            CompDCMGyroUpdate(&g_sCompDCMInst, pfGyro[0], pfGyro[1],
                              pfGyro[2]);
            CompDCMStart(&g_sCompDCMInst);
        }
        else
        {
            //
            // DCM Is already started.  Perform the incremental update.
            //
            CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1],
                                 pfMag[2]);
            CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
                               pfAccel[2]);
            CompDCMGyroUpdate(&g_sCompDCMInst, -pfGyro[0], -pfGyro[1],
                              -pfGyro[2]);
            CompDCMUpdate(&g_sCompDCMInst);
        }

        //
        // Increment the skip counter.  Skip counter is used so we do not
        // overflow the UART with data.
        //
        g_ui32PrintSkipCounter++;
        if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT)
        {
            //
            // Reset skip counter.
            //
            g_ui32PrintSkipCounter = 0;

            //
            // Get Euler data. (Roll Pitch Yaw)
            //
            CompDCMComputeEulers(&g_sCompDCMInst, pfEulers, pfEulers + 1,
                                 pfEulers + 2);

            //
            // Get Quaternions.
            //
            CompDCMComputeQuaternion(&g_sCompDCMInst, pfQuaternion);

            //
            // convert mag data to micro-tesla for better human interpretation.
            //
            pfMag[0] *= 1e6;
            pfMag[1] *= 1e6;
            pfMag[2] *= 1e6;

            //
            // Convert Eulers to degrees. 180/PI = 57.29...
            // Convert Yaw to 0 to 360 to approximate compass headings.
            //
            pfEulers[0] *= 57.295779513082320876798154814105f;
            pfEulers[1] *= 57.295779513082320876798154814105f;
            pfEulers[2] *= 57.295779513082320876798154814105f;
            if(pfEulers[2] < 0)
            {
                pfEulers[2] += 360.0f;
            }

            //
            // Now drop back to using the data as a single array for the
            // purpose of decomposing the float into a integer part and a
            // fraction (decimal) part.
            //
            for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
            {
                //
                // Conver float value to a integer truncating the decimal part.
                //
                i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx];

                //
                // Multiply by 1000 to preserve first three decimal values.
                // Truncates at the 3rd decimal place.
                //
                i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f);

                //
                // Subtract off the integer part from this newly formed decimal
                // part.
                //
                i32FPart[ui32Idx] = i32FPart[ui32Idx] -
                                    (i32IPart[ui32Idx] * 1000);

                //
                // make the decimal part a positive number for display.
                //
                if(i32FPart[ui32Idx] < 0)
                {
                    i32FPart[ui32Idx] *= -1;
                }
            }

            //
            // Print the acceleration numbers in the table.
            //
            UARTprintf("\033[5;17H%3d.%03d", i32IPart[0], i32FPart[0]);
            UARTprintf("\033[5;40H%3d.%03d", i32IPart[1], i32FPart[1]);
            UARTprintf("\033[5;63H%3d.%03d", i32IPart[2], i32FPart[2]);

            //
            // Print the angular velocities in the table.
            //
            UARTprintf("\033[7;17H%3d.%03d", i32IPart[3], i32FPart[3]);
            UARTprintf("\033[7;40H%3d.%03d", i32IPart[4], i32FPart[4]);
            UARTprintf("\033[7;63H%3d.%03d", i32IPart[5], i32FPart[5]);

            //
            // Print the magnetic data in the table.
            //
            UARTprintf("\033[9;17H%3d.%03d", i32IPart[6], i32FPart[6]);
            UARTprintf("\033[9;40H%3d.%03d", i32IPart[7], i32FPart[7]);
            UARTprintf("\033[9;63H%3d.%03d", i32IPart[8], i32FPart[8]);

            //
            // Print the Eulers in a table.
            //
            UARTprintf("\033[14;17H%3d.%03d", i32IPart[9], i32FPart[9]);
            UARTprintf("\033[14;40H%3d.%03d", i32IPart[10], i32FPart[10]);
            UARTprintf("\033[14;63H%3d.%03d", i32IPart[11], i32FPart[11]);

            //
            // Print the quaternions in a table format.
            //
            UARTprintf("\033[19;14H%3d.%03d", i32IPart[12], i32FPart[12]);
            UARTprintf("\033[19;32H%3d.%03d", i32IPart[13], i32FPart[13]);
            UARTprintf("\033[19;50H%3d.%03d", i32IPart[14], i32FPart[14]);
            UARTprintf("\033[19;68H%3d.%03d", i32IPart[15], i32FPart[15]);

        }
    }
}
Ejemplo n.º 28
0
//*****************************************************************************
//
// Configure Timer0B as a 16-bit periodic counter with an interrupt
// every 1ms.
//
//*****************************************************************************
int
main(void)
{
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
    defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
    uint32_t ui32SysClock;
#endif

    uint32_t ui32PrevCount = 0;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
    defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                       SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_OSC), 25000000);
#else
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);
#endif

    //
    // The Timer0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Timer operation.
    //
    InitConsole();

    //
    // Display the example setup on the console.
    //
    UARTprintf("16-Bit Timer Interrupt ->");
    UARTprintf("\n   Timer = Timer0B");
    UARTprintf("\n   Mode = Periodic");
    UARTprintf("\n   Number of interrupts = %d", NUMBER_OF_INTS);
    UARTprintf("\n   Rate = 1ms\n\n");

    //
    // Configure Timer0B as a 16-bit periodic timer.
    //
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC);

    //
    // Set the Timer0B load value to 1ms.
    //
#if defined(TARGET_IS_TM4C129_RA0) ||                                         \
    defined(TARGET_IS_TM4C129_RA1) ||                                         \
    defined(TARGET_IS_TM4C129_RA2)
    TimerLoadSet(TIMER0_BASE, TIMER_B, ui32SysClock / 1000);
#else
    TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000);
#endif

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Configure the Timer0B interrupt for timer timeout.
    //
    TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);

    //
    // Enable the Timer0B interrupt on the processor (NVIC).
    //
    IntEnable(INT_TIMER0B);

    //
    // Initialize the interrupt counter.
    //
    g_ui32Counter = 0;

    //
    // Enable Timer0B.
    //
    TimerEnable(TIMER0_BASE, TIMER_B);

    //
    // Loop forever while the Timer0B runs.
    //
    while(1)
    {
        //
        // If the interrupt count changed, print the new value
        //
        if(ui32PrevCount != g_ui32Counter)
        {
            //
            // Print the periodic interrupt counter.
            //
            UARTprintf("Number of interrupts: %d\r", g_ui32Counter);
            ui32PrevCount = g_ui32Counter;
        }
    }
}
int main(void)
{
	uint8_t token = 0U;

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	PSO_PeripheralEnable();
	PSO_GPIOConfig();
	PSO_UART0Config();


	IntMasterEnable();

    /* Timer initialization */
	PSO_Timers();

	while(1){


		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00)
		{

			switch (token)
			{
				case 0:
					PSO_LEDRedOn();
				break;

				case 1:
					PSO_LEDGreenOn();
				break;

				case 2:
					PSO_LEDBlueOn();
				break;
				case 3:
					PSO_LEDCyanOn();
				break;

				case 4:
					PSO_LEDPurpleOn();
				break;

				case 5:
					PSO_LEDYellowOn();
				break;
				case 6:
					PSO_LEDWhiteOn();
				break;

				default:
					PSO_LEDAllOff();
			} /* switch */

			SysCtlDelay(100000);
			SysCtlDelay(100000);

			token++;

			if (token > 6)
			{
				token = 0;
			}

		} /* if */

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00)
		{
			PSO_LEDAllOff();
		}

		SysCtlDelay(100000);

		read_raw_data (&g_uart0_data);
		copy_raw_data (&g_tx_buffer_uart, &g_uart0_data);
		uart_write();
		uartBatchWrite (UART0_BASE, uart_tx_buffer, 10);
	}




}
Ejemplo n.º 30
0
int main(void)
{
    //Set clock so it runs directly on the crystal
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    volatile unsigned long ulLoop;

    // Initialisation des ports
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //Enable les GPIO pour les timings des interrupts et autres
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD);
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2);

    //Mettre les interrupts du port E en haute prorités: évite collisions avec QEI logiciel
    IntPrioritySet(INT_GPIOE,0);
    //Activer les interruptions
    IntMasterEnable();


    //Initialisation des variables globales
    ulLoop = 0;
    receive_buffer.read=0;
    receive_buffer.write=0;
    send_buffer.read=0;
    send_buffer.write=0;
    send_buffer2.read=0;
    send_buffer2.write=0;
    buffer_commande.read = 0;
    buffer_commande.write = 0;
    //QEI
    position=0;
    speed=0;
    state=0;
    state_m2=0;
    state_m3=0;
    position_m2=0;
    position_m3=0;
    //Asservissement
    previous_error0=0;
    previous_error1=0;
    previous_error2=0;
    previous_error3=0;
    I0=0;
    I1=0;
    I2=0;
    I3=0;
    consigne0=0;
    consigne1=0;
    consigne2=0;
    consigne3=0;
    //Pour les déplacements rapides @6400
    Kd0 = 0.1;
    Ki0 = 7;
    Kp0 = 1.75;
    Kd1 = 0.1;
    Ki1 = 7;
    Kp1 = 1.75;
    Kd2 = 0.1;
    Ki2 = 7;
    Kp2 = 1.75;
    Kd3 = 0.1;
    Ki3 = 7;
    Kp3 = 1.75;
    Tf0 = 0.1;
    Tf1 = 0.1;
    Tf2 = 0.1;
    Tf3 = 0.1;
    //Pour les déplacements moyens @3200
    Kd0_m = 0.05;
    Ki0_m = 10;
    Kp0_m = 1.6;
    Kd1_m = 0.05;
    Ki1_m = 10;
    Kp1_m = 1.5;
    Kd2_m = 0.05;
    Ki2_m = 10;
    Kp2_m = 1.5;
    Kd3_m = 0.05;
    Ki3_m = 10;
    Kp3_m = 1.6;
    //Pour les mouvements lents @1600
    Kd0_s = 0.05;
    Ki0_s = 12;
    Kp0_s = 1.2;
    Kd1_s = 0.05;
    Ki1_s = 12;
    Kp1_s = 1.2;
    Kd2_s = 0.05;
    Ki2_s = 12;
    Kp2_s = 1.2;
    Kd3_s = 0.2;
    Ki3_s = 12;
    Kp3_s = 1.2;
    //Pour les mouvements de dessin @800
    Kd0_d = 0.2;
    Ki0_d = 10;
    Kp0_d = 1.2;
    Kd1_d = 0.05;
    Ki1_d = 10;
    Kp1_d = 1.2;
    Kd2_d = 0.05;
    Ki2_d = 10;
    Kp2_d = 1.2;
    Kd3_d = 0.2;
    Ki3_d = 10;
    Kp3_d = 1.2;
    /*Kd0_s = 0.05;
    Ki0_s = 12;//5.64;
    Kp0_s = 1.2;
    Kd1_s = 0.05;
    Ki1_s = 12;//5.64;
    Kp1_s = 1.2;
    Kd2_s = 0.05;
    Ki2_s = 12;//5.64;
    Kp2_s = 1.2;
    Kd3_s = 0.05;
    Ki3_s = 12;//5.64;
    Kp3_s = 1.2;*/
    dt = 0.1;
    tolerancePos = 0;
    posqei1 = 0;
    speedqei1=0;





    initCommande();
    initMotorCommand();
    initLED();
    initPrehenseur();
    initPWM();
    initUART();
    initQEI();
    //init_lcd();
    initTimer();



    while(1)
    {
        EncoderHandler(); // Traitement des encodeurs en quadrature pour les moteurs 2 et 3

        //si un charactère dans la Receive FIFO
        /*if(!(UART0_FR_R & UART_FR_RXFE)) //&& (send_buffer.read > send_buffer.write-256))
        {
        	receive_buffer.buffer[receive_buffer.write%BUFFER_LEN] = UART0_DR_R;
        	receive_buffer.write++;
        }*/

        /*
        if(!(UART0_FR_R & UART_FR_TXFF) && (send_buffer.read < send_buffer.write))
        {
        	UART0_DR_R = send_buffer.buffer[send_buffer.read%BUFFER_LEN];
        	send_buffer.read++;
        }*/
        /*if(receive_buffer.write - receive_buffer.read > 7){
        	long i;
        	short commande[8];
        	for(i=0; i < 8; i++){
        		commande[i] = receive_buffer.buffer[receive_buffer.read%BUFFER_LEN];
        		receive_buffer.read++;
        	}
        	traiterNouvelleCommande(commande); //Traitement des commandes
        }
        if(buffer_commande.write - buffer_commande.read >= 8){
        	CommandHandler();
        }*/
    }
}