void DRV8833_InitMotorB(){
	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlDelay(3);


	GPIOPinConfigure(GPIO_PB4_M0PWM2);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
	PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_1,
			PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

	uint32_t duty = 0;
	PWMOutputUpdateMode(PWM0_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,PWM_OUTPUT_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, freq);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);


	GPIOPinConfigure(GPIO_PB5_M0PWM3);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_5,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);

	HWREG(GPIO_PORTB_BASE+GPIO_O_AFSEL) &= ~0x30;
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);
}
void DRV8833_InitMotorA(){
	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlDelay(3);
	GPIOPinConfigure(GPIO_PB6_M0PWM0);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_6,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
	PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
			PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);


	uint32_t duty = 0;
	PWMOutputUpdateMode(PWM0_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT,PWM_OUTPUT_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, freq);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);


	GPIOPinConfigure(GPIO_PB7_M0PWM1);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);

	PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
예제 #3
0
void adc_init_and_run(void){
	// Тактирование выбранного модуля АЦП.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADCx);

	// Ожидание готовности выбранного модуля АЦП к настройке.
	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADCx)) { }

	ADCHardwareOversampleConfigure(ADCx_BASE, 4);

	// Установка триггера выбранного буфера АЦП.
	ADCSequenceConfigure(ADCx_BASE, SSy, ADC_TRIGGER, 0);

	ADCSequenceStepConfigure(ADCx_BASE, SSy, 0, ADC_CTL_CH0);
	ADCSequenceStepConfigure(
		ADCx_BASE, SSy, 1, ADC_CTL_CH1|ADC_CTL_IE|ADC_CTL_END
	);

	ADCIntClear(ADCx_BASE, SSy);

	IntEnable(INT_ADCxSSy);
	IntPrioritySet(INT_ADCxSSy, 1);

	ADCSequenceEnable(ADCx_BASE, SSy);
	ADCProcessorTrigger(ADCx_BASE, SSy);
}
//*****************************************************************************
//
// Blink the on-board LED.
//
//*****************************************************************************
int
main(void)
{
    volatile uint32_t ui32Loop;

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    //
    // Check if the peripheral access is enabled.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOG))
    {
    }

    //
    // Enable the GPIO pin for the LED (PG2).  Set the direction as output, and
    // enable the GPIO pin for digital function.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Turn on the LED.
        //
        led_turn_on();

        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
        {
        }

        //
        // Turn off the LED.
        //
        led_turn_off();

        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
        {
        }
    }
}
예제 #5
0
void TwoWire::forceStop(void) {

    //force a stop to release the bus
    GPIOPinTypeGPIOOutput(g_uli2cBase[i2cModule],
          g_uli2cSCLPins[i2cModule] | g_uli2cSDAPins[i2cModule]);
    GPIOPinWrite(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule], 0);
    GPIOPinWrite(g_uli2cBase[i2cModule],
            g_uli2cSCLPins[i2cModule], g_uli2cSCLPins[i2cModule]);
    GPIOPinWrite(g_uli2cBase[i2cModule],
          g_uli2cSDAPins[i2cModule], g_uli2cSDAPins[i2cModule]);

    GPIOPinTypeI2C(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule]);
    GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]);
    //reset I2C controller
    //without resetting the I2C controller, the I2C module will
    //bring the bus back to it's erroneous state
    SysCtlPeripheralReset(g_uli2cPeriph[i2cModule]);
    while(!SysCtlPeripheralReady(g_uli2cPeriph[i2cModule]));
    I2CMasterInitExpClk(MASTER_BASE, F_CPU, false);
}
//*****************************************************************************
//
// Initializes the ISL29023 task.
//
//*****************************************************************************
uint32_t
ISL29023TaskInit(void)
{
    //
    // Reset the GPIO port to be sure all previous interrupt config is cleared.
    //
    SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE))
    {
        //
        // Do Nothing. Wait for reset to complete.
        //
    }

    //
    // Configure and Enable the GPIO interrupt. Used for INT signal from the
    // ISL29023
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);
    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_5);
    ROM_GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);

    //
    // Change the interrupt priority so that the interrupt handler function can
    // call FreeRTOS APIs.
    //
    IntPrioritySet(INT_GPIOE, 0xE0);
    ROM_IntEnable(INT_GPIOE);

    //
    // Create a transaction complete semaphore to sync the application callback
    // which is called from the I2C master driver in I2C interrupt context and
    // the task.
    //
    vSemaphoreCreateBinary(g_xISL29023TransactionCompleteSemaphore);

    //
    // Create a semaphore for notifying from the light threshold ISR to the task
    // that the light thresholds have been exceeded (too high or too low).
    //
    vSemaphoreCreateBinary(g_xISL29023AdjustRangeSemaphore);

    //
    // Create the switch task.
    //
    if(xTaskCreate(ISL29023Task, (const portCHAR *)"ISL29023  ",
                   ISL29023_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY +
                   PRIORITY_ISL29023_TASK, g_xISL29023Handle) != pdTRUE)
    {
        //
        // Task creation failed.
        //
        return(1);
    }

    //
    // Check if Semaphore creation was successfull.
    //
    if((g_xISL29023TransactionCompleteSemaphore == NULL) ||
       (g_xISL29023AdjustRangeSemaphore == NULL))
    {
        //
        // Semaphore was not created successfully.
        //
        return(1);
    }

    //
    // Set the active flag that shows this task is running properly.
    // Initialize the other variables in the data structure.
    //
    g_sISL29023Data.bActive = true;
    g_sISL29023Data.fVisible = 0.0f;
    g_sISL29023Data.fInfrared = 0.0f;
    g_sISL29023Data.ui8Range = 0;
    g_sISL29023Data.xTimeStampTicks = 0;

    //
    // Initialize the cloud data global pointer to this sensors local data.
    //
    g_sCloudData.psISL29023Data = &g_sISL29023Data;

    //
    // Success.
    //
    return(0);

}
예제 #7
0
//*****************************************************************************
//
// The program main function.  It performs initialization, then runs a command
// processing loop to read commands from the console.
//
//*****************************************************************************
int
main(void)
{
  //  int nStatus;
    FRESULT iFResult;
  //  tRectangle sRect;

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

    //
    // Check if the peripheral access is enabled.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {
    }

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

    volatile uint32_t ui32Loop;
    int counter = 2;


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

    //
    // Set the system clock to run at 50MHz from the PLL.
    //
    g_ui32SysClock = SysCtlClockFreqSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ,50000000);

    //
    // Enable the peripherals used by this example.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);

    //
    // Configure SysTick for a 100Hz interrupt.  The FatFs driver wants a 10 ms
    // tick.
    //
    MAP_SysTickPeriodSet(g_ui32SysClock / 100);
    MAP_SysTickEnable();
    MAP_SysTickIntEnable();

    //
    // Enable Interrupts
    //
    MAP_IntMasterEnable();
    // Mount the file system, using logical disk 0.
    //
    iFResult = f_mount(0, &g_sFatFs);



    iFResult = f_open(&g_sFileObject, "testFile.txt", (FA_OPEN_ALWAYS | FA_WRITE));


    while(counter > 0){
    		GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
    		for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
    		{
    		}

    		//
    		// Turn off the LED.
    		//
    		GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);

    		//
    		// Delay for a bit.
    		//
    		for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
    		{
    		}
    		counter--;
    }

    if(iFResult != FR_OK)
    {
       return(1);
    }
}
예제 #8
0
//*****************************************************************************
//
// A simple application demonstrating use of the boot loader,
//
//*****************************************************************************
int
main(void)
{

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

    //
    // Set the system clock to run at 120MHz from the PLL
    //
    g_ui32SysClockFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                            SYSCTL_OSC_MAIN |
                                            SYSCTL_USE_PLL |
                                            SYSCTL_CFG_VCO_480), 120000000);

    //
    // Initialize the peripherals that each of the boot loader flavours
    // supports.  Since this example is intended for use with any of the
    // boot loaders and we don't know which is actually in use, we cover all
    // bases and initialize for serial, Ethernet and USB use here.
    //
    SetupForUART();
    SetupForUSB();

    //
    // Enable Port J Pin 0 for exit to UART Boot loader when Pressed Low.
    // On the EK-TM4C1294 the weak pull up is enabled to detect button
    // press.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOJ)));
    GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);
    HWREG(GPIO_PORTJ_BASE + GPIO_O_PUR) = GPIO_PIN_0;

    //
    // Configure Port N pin 0 as output.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)));
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);

    //
    // If the Switch SW1 is not pressed then blink the LED D2 at 1 Hz rate
    // On switch SW press detection exit the blinking program and jump to
    // the flash boot loader.
    //
    while((GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) & GPIO_PIN_0) != 0x0) {
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);
        SysCtlDelay(g_ui32SysClockFreq / 6);
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
        SysCtlDelay(g_ui32SysClockFreq / 6);
    }

    //
    // Before passing control make sure that the LED is turned OFF.
    //
    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);

    //
    // Pass control to whichever flavour of boot loader the board is configured
    // with.
    //
    JumpToBootLoader();

    //
    // The previous function never returns but we need to stick in a return
    // code here to keep the compiler from generating a warning.
    //
    return(0);
}
예제 #9
0
error_t tm4c129EthInit(NetInterface *interface)
{
   //Debug message
   TRACE_INFO("Initializing Tiva TM4C129 Ethernet controller...\r\n");

   //Save underlying network interface
   nicDriverInterface = interface;

   //Enable Ethernet controller clock
   SysCtlPeripheralEnable(SYSCTL_PERIPH_EMAC0);
   //Reset Ethernet controller
   SysCtlPeripheralReset(SYSCTL_PERIPH_EMAC0);
   //Wait for the reset to complete
   while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EMAC0));

   //Enable internal PHY clock
   SysCtlPeripheralEnable(SYSCTL_PERIPH_EPHY0);
   //Reset internal PHY
   SysCtlPeripheralReset(SYSCTL_PERIPH_EPHY0);
   //Wait for the reset to complete
   while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EPHY0));

   //GPIO configuration
   tm4c129EthInitGpio(interface);

   //Perform a software reset
   EMAC0_DMABUSMOD_R |= EMAC_DMABUSMOD_SWR;
   //Wait for the reset to complete
   while(EMAC0_DMABUSMOD_R & EMAC_DMABUSMOD_SWR);

   //Adjust MDC clock range depending on SYSCLK frequency
   EMAC0_MIIADDR_R = EMAC_MIIADDR_CR_100_150;

   //Reset PHY transceiver
   tm4c129EthWritePhyReg(EPHY_BMCR, EPHY_BMCR_MIIRESET);
   //Wait for the reset to complete
   while(tm4c129EthReadPhyReg(EPHY_BMCR) & EPHY_BMCR_MIIRESET);

   //Dump PHY registers for debugging purpose
   tm4c129EthDumpPhyReg();

   //Configure LED0, LED1 and LED2
   tm4c129EthWritePhyReg(EPHY_LEDCFG, EPHY_LEDCFG_LED0_TX |
      EPHY_LEDCFG_LED1_RX | EPHY_LEDCFG_LED2_LINK);

   //Configure PHY interrupts as desired
   tm4c129EthWritePhyReg(EPHY_MISR1, EPHY_MISR1_LINKSTATEN);
   //Enable PHY interrupts
   tm4c129EthWritePhyReg(EPHY_SCR, EPHY_SCR_INTEN);

   //Use default MAC configuration
   EMAC0_CFG_R = EMAC_CFG_DRO;

   //Set the MAC address
   EMAC0_ADDR0L_R = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
   EMAC0_ADDR0H_R = interface->macAddr.w[2];

   //Initialize hash table
   EMAC0_HASHTBLL_R = 0;
   EMAC0_HASHTBLH_R = 0;

   //Configure the receive filter
   EMAC0_FRAMEFLTR_R = EMAC_FRAMEFLTR_HPF | EMAC_FRAMEFLTR_HMC;
   //Disable flow control
   EMAC0_FLOWCTL_R = 0;
   //Enable store and forward mode
   EMAC0_DMAOPMODE_R = EMAC_DMAOPMODE_RSF | EMAC_DMAOPMODE_TSF;

   //Configure DMA bus mode
   EMAC0_DMABUSMOD_R = EMAC_DMABUSMOD_AAL | EMAC_DMABUSMOD_USP | EMAC_DMABUSMOD_RPBL_1 |
      EMAC_DMABUSMOD_PR_1_1 | EMAC_DMABUSMOD_PBL_1 | EMAC_DMABUSMOD_ATDS;

   //Initialize DMA descriptor lists
   tm4c129EthInitDmaDesc(interface);

   //Prevent interrupts from being generated when the transmit statistic
   //counters reach half their maximum value
   EMAC0_MMCTXIM_R = EMAC_MMCTXIM_OCTCNT | EMAC_MMCTXIM_MCOLLGF |
      EMAC_MMCTXIM_SCOLLGF | EMAC_MMCTXIM_GBF;

   //Prevent interrupts from being generated when the receive statistic
   //counters reach half their maximum value
   EMAC0_MMCRXIM_R = EMAC_MMCRXIM_UCGF | EMAC_MMCRXIM_ALGNERR |
      EMAC_MMCRXIM_CRCERR | EMAC_MMCRXIM_GBF;

   //Disable MAC interrupts
   EMAC0_IM_R = EMAC_IM_TSI | EMAC_IM_PMT;
   //Enable the desired DMA interrupts
   EMAC0_DMAIM_R = EMAC_DMAIM_NIE | EMAC_DMAIM_RIE | EMAC_DMAIM_TIE;
   //Enable PHY interrupts
   EMAC0_EPHYIM_R = EMAC_EPHYIM_INT;

   //Set priority grouping (3 bits for pre-emption priority, no bits for subpriority)
   IntPriorityGroupingSet(TM4C129_ETH_IRQ_PRIORITY_GROUPING);
   //Configure Ethernet interrupt priority
   IntPrioritySet(INT_EMAC0, TM4C129_ETH_IRQ_PRIORITY);

   //Enable MAC transmission and reception
   EMAC0_CFG_R |= EMAC_CFG_TE | EMAC_CFG_RE;
   //Enable DMA transmission and reception
   EMAC0_DMAOPMODE_R |= EMAC_DMAOPMODE_ST | EMAC_DMAOPMODE_SR;

   //Accept any packets from the upper layer
   osSetEvent(&interface->nicTxEvent);

   //Successful initialization
   return NO_ERROR;
}