示例#1
0
void i2c_init(void) {
    bool status;
    
    // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3)
    SysCtrlPeripheralEnable(I2C_PERIPHERAL);
    SysCtrlPeripheralSleepEnable(I2C_PERIPHERAL);
    SysCtrlPeripheralDeepSleepDisable(I2C_PERIPHERAL);

    // Reset peripheral previous to configuring it
    SysCtrlPeripheralReset(I2C_PERIPHERAL);

    // Configure the SCL pin
    GPIOPinTypeI2C(I2C_BASE, I2C_SCL);
    IOCPinConfigPeriphInput(I2C_BASE, I2C_SCL, IOC_I2CMSSCL);
    IOCPinConfigPeriphOutput(I2C_BASE, I2C_SCL, IOC_MUX_OUT_SEL_I2C_CMSSCL);

    // Configure the SDA pin
    GPIOPinTypeI2C(I2C_BASE, I2C_SDA);
    IOCPinConfigPeriphInput(I2C_BASE, I2C_SDA, IOC_I2CMSSDA);
    IOCPinConfigPeriphOutput(I2C_BASE, I2C_SDA, IOC_MUX_OUT_SEL_I2C_CMSSDA);

    // Configure the I2C clock
    status = (I2C_BAUDRATE == 400000 ? true : false);
    I2CMasterInitExpClk(SysCtrlClockGet(), status);

    // Enable the I2C module as master
    I2CMasterEnable();
}
示例#2
0
/*************************************************************************************************
 * @fn      sbUartInit()
 *
 * @brief   Initialize the UART.
 *
 * @param   none
 *
 * @return  none
 */
void sbUartInit(void)
{
  //
  // Set IO clock to the same as system clock
  //
  SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
   
  //
  // Enable UART peripheral module
  //
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0);

  //
  // Disable UART function
  //
  UARTDisable(UART0_BASE);

  //
  // Disable all UART module interrupts
  //
  UARTIntDisable(UART0_BASE, 0x1FFF);

  //
  // Set IO clock as UART clock source
  //
  UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

  //
  // Map UART signals to the correct GPIO pins and configure them as
  // hardware controlled.
  //
  IOCPinConfigPeriphOutput(GPIO_A_BASE, GPIO_PIN_1, IOC_MUX_OUT_SEL_UART0_TXD);
  GPIOPinTypeUARTOutput(GPIO_A_BASE, GPIO_PIN_1); 
  IOCPinConfigPeriphInput(GPIO_A_BASE, GPIO_PIN_0, IOC_UARTRXD_UART0);
  GPIOPinTypeUARTInput(GPIO_A_BASE, GPIO_PIN_0);
     
  //
  // Configure the UART for 115,200, 8-N-1 operation.
  // This function uses SysCtrlClockGet() to get the system clock
  // frequency.  This could be also be a variable or hard coded value
  // instead of a function call.
  //
  UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200,
                     (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
  UARTEnable(UART0_BASE);
}
示例#3
0
文件: uart.c 项目: aeliot/openthread
/**
 * Function documented in platform/uart.h
 */
otError otPlatUartEnable(void)
{
    PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL);

    while (PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON);

    PRCMPeripheralRunEnable(PRCM_PERIPH_UART0);
    PRCMPeripheralSleepEnable(PRCM_PERIPH_UART0);
    PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_UART0);
    PRCMLoadSet();

    while (!PRCMLoadGet());

    IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3, IOID_UNUSED, IOID_UNUSED);

    UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200,
                        UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    UARTIntRegister(UART0_BASE, UART0_intHandler);
    UARTEnable(UART0_BASE);
    return OT_ERROR_NONE;
}
示例#4
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();
}
示例#5
0
/*************************************************************************************************
 * @fn      HalUARTOpenIsr()
 *
 * @brief   Open a port based on the configuration
 *
 * @param   port   - UART port
 *          config - contains configuration information
 *          cBack  - Call back function where events will be reported back
 *
 * @return  Status of the function call
 *************************************************************************************************/
uint8 HalUARTOpenIsr(uint8 port, halUARTCfg_t *config)
{
  if (uartRecord.configured)
  {
    HalUARTClose(port);
  }

  if (config->baudRate > HAL_UART_BR_115200)
  {
    return HAL_UART_BAUDRATE_ERROR;
  }

  if (((uartRecord.rx.pBuffer = osal_mem_alloc(config->rx.maxBufSize)) == NULL) ||
      ((uartRecord.tx.pBuffer = osal_mem_alloc(config->tx.maxBufSize)) == NULL))
  {
    if (uartRecord.rx.pBuffer != NULL)
    {
      osal_mem_free(uartRecord.rx.pBuffer);
      uartRecord.rx.pBuffer = NULL;
    }

    return HAL_UART_MEM_FAIL;
  }
  
  if(config->flowControl)
  {
    IOCPinConfigPeriphOutput(GPIO_D_BASE, GPIO_PIN_3, IOC_MUX_OUT_SEL_UART1_RTS);
    GPIOPinTypeUARTOutput(GPIO_D_BASE, GPIO_PIN_3);
    IOCPinConfigPeriphInput(GPIO_B_BASE, GPIO_PIN_0, IOC_UARTCTS_UART1);
    GPIOPinTypeUARTInput(GPIO_B_BASE, GPIO_PIN_0);
  }
  
  IntEnable(HAL_UART_INT_CTRL);

  uartRecord.configured = TRUE;
  uartRecord.baudRate = config->baudRate;
  uartRecord.flowControl = config->flowControl;
  uartRecord.flowControlThreshold = (config->flowControlThreshold > config->rx.maxBufSize) ? 0 :
                                     config->flowControlThreshold;
  uartRecord.idleTimeout = config->idleTimeout;
  uartRecord.rx.maxBufSize = config->rx.maxBufSize;
  uartRecord.tx.maxBufSize = config->tx.maxBufSize;
  uartRecord.intEnable = config->intEnable;
  uartRecord.callBackFunc = config->callBackFunc;

  UARTConfigSetExpClk(HAL_UART_PORT, SysCtrlClockGet(), UBRRTable[uartRecord.baudRate],
                         (UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE));

  /* FIFO level set to 1/8th for both RX and TX which is 2 bytes */
  UARTFIFOLevelSet(HAL_UART_PORT, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
  UARTFIFOEnable(HAL_UART_PORT);

  /* Clear and enable UART TX, RX, CTS and Recieve Timeout interrupt */
  UARTIntClear(HAL_UART_PORT, (UART_INT_RX | UART_INT_TX | UART_INT_CTS | UART_INT_RT ));
  UARTIntEnable(HAL_UART_PORT, (UART_INT_RX | UART_INT_TX | UART_INT_CTS | UART_INT_RT ));
  
  if(config->flowControl)
  {
    /* Enable hardware flow control by enabling CTS and RTS */
    HWREG(HAL_UART_PORT + UART_O_CTL) |= (UART_CTL_CTSEN | UART_CTL_RTSEN );
  }
  UARTEnable(HAL_UART_PORT);

  return HAL_UART_SUCCESS;
}
示例#6
0
/**************************************************************************************************
* @fn          npSpiInit
*
* @brief       This function is called to set up the SPI interface.
*
* input parameters
*
* None.
*
* output parameters
*
* None.
*
* @return      None.
**************************************************************************************************
*/
void npSpiInit(void) 
{
  uint32 ulDummy;
  
  if (ZNP_CFG1_UART == znpCfg1)
  {
    return;
  }
  
  /* Configure SRDY and deassert SRDY */
  GPIOPinTypeGPIOOutput(HAL_SPI_SRDY_BASE, HAL_SPI_SRDY_PIN);
  GPIOPinWrite(HAL_SPI_SRDY_BASE, HAL_SPI_SRDY_PIN, HAL_SPI_SRDY_PIN);
  
  /* Configure MRDY and deassert MRDY */
  GPIOPinTypeGPIOInput(HAL_SPI_MRDY_BASE, HAL_SPI_MRDY_PIN);
  GPIOPinWrite(HAL_SPI_MRDY_BASE, HAL_SPI_MRDY_PIN, HAL_SPI_MRDY_PIN);
  
  /* Enable SSI peripheral module */
  SysCtrlPeripheralEnable(BSP_SPI_SSI_ENABLE_BM);
  
  /* Delay is essential for this customer */
  SysCtrlDelay(32);
  
  /* Configure pin type */
  GPIOPinTypeSSI(BSP_SPI_BUS_BASE, (BSP_SPI_MOSI | BSP_SPI_MISO | BSP_SPI_SCK | HAL_SPI_SS_PIN));
  
  /* Map SSI signals to the correct GPIO pins and configure them as HW ctrl'd */
  IOCPinConfigPeriphOutput(BSP_SPI_BUS_BASE, BSP_SPI_MISO, IOC_MUX_OUT_SEL_SSI0_TXD); 
  IOCPinConfigPeriphInput(BSP_SPI_BUS_BASE, BSP_SPI_SCK, IOC_CLK_SSIIN_SSI0);
  IOCPinConfigPeriphInput(BSP_SPI_BUS_BASE, BSP_SPI_MOSI, IOC_SSIRXD_SSI0);
  IOCPinConfigPeriphInput(BSP_SPI_BUS_BASE, HAL_SPI_SS_PIN, IOC_SSIFSSIN_SSI0);
  
  /* Disable SSI function */
  SSIDisable(BSP_SPI_SSI_BASE);
  
  /* Set system clock as SSI clock source */
  SSIClockSourceSet(BSP_SPI_SSI_BASE, SSI_CLOCK_SYSTEM);
  
  /* Configure SSI module to Motorola/Freescale SPI mode 3 Slave:
   * Polarity  = 1, observed in scope from MSP430 master 
   * Phase     = 1, observed in scope from MSP430 master
   * Word size = 8 bits
   * Clock     = 2MHz, observed MSP430 master clock is 2049180Hz 
   */
  SSIConfigSetExpClk(BSP_SPI_SSI_BASE, SysCtrlClockGet(), SSI_FRF_MOTO_MODE_3,
                     SSI_MODE_SLAVE, 2000000UL, 8); 
  
  /* Register SPI uDMA complete interrupt */
  SSIIntRegister(BSP_SPI_SSI_BASE, &npSpiUdmaCompleteIsr);
  
  /* Enable uDMA complete interrupt for SPI RX and TX */
  SSIDMAEnable(BSP_SPI_SSI_BASE, SSI_DMA_RX | SSI_DMA_TX);
  
  /* Configure SPI priority */
  IntPrioritySet(INT_SSI0, HAL_INT_PRIOR_SSI0);
  IntPrioritySet(INT_GPIOB, HAL_INT_PRIOR_SSI_MRDY);
  
  /* Enable the SSI function */
  SSIEnable(BSP_SPI_SSI_BASE);
  
  GPIOIntTypeSet(HAL_SPI_MRDY_BASE, HAL_SPI_MRDY_PIN, GPIO_BOTH_EDGES);
  GPIOPortIntRegister(HAL_SPI_MRDY_BASE, *npSpiMrdyIsr);
  GPIOPinIntEnable(HAL_SPI_MRDY_BASE, HAL_SPI_MRDY_PIN);
  
  /* Initialize uDMA for SPI */
  npSpiUdmaInit();
}
示例#7
0
//*****************************************************************************
//
// Configure the UART and perform reads and writes using polled I/O.
//
//*****************************************************************************
int
main(void)
{
    char cThisChar;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // (no ext 32k osc, no internal osc)
    //
    SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);

    //
    // Set IO clock to the same as system clock
    //
    SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
   
    //
    // Enable UART peripheral module
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0);

    //
    // Disable UART function
    //
    UARTDisable(UART0_BASE);

    //
    // Disable all UART module interrupts
    //
    UARTIntDisable(UART0_BASE, 0x1FFF);

    //
    // Set IO clock as UART clock source
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Map UART signals to the correct GPIO pins and configure them as
    // hardware controlled.
    //
    IOCPinConfigPeriphOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD, IOC_MUX_OUT_SEL_UART0_TXD);
    GPIOPinTypeUARTOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD); 
    IOCPinConfigPeriphInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD, IOC_UARTRXD_UART0);
    GPIOPinTypeUARTInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD);
     
    //
    // Configure the UART for 115,200, 8-N-1 operation.
    // This function uses SysCtrlClockGet() to get the system clock
    // frequency.  This could be also be a variable or hard coded value
    // instead of a function call.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);
    
    //
    // Put a character to show start of example.  This will display on the
    // terminal.
    //
    UARTCharPut(UART0_BASE, '!');

    //
    // Enter a loop to read characters from the UART, and write them back
    // (echo).  When a line end is received, the loop terminates.
    //
    do
    {
        //
        // Read a character using the blocking read function.  This function
        // will not return until a character is available.
        //
        cThisChar = UARTCharGet(UART0_BASE);

        //
        // Write the same character using the blocking write function.  This
        // function will not return until there was space in the FIFO and
        // the character is written.
        //
        UARTCharPut(UART0_BASE, cThisChar);

    //
    // Stay in the loop until either a CR or LF is received.
    //
    } while((cThisChar != '\n') && (cThisChar != '\r'));

    //
    // Put a character to show the end of the example.  This will display on
    // the terminal.
    //
    UARTCharPut(UART0_BASE, '@');

    //
    // Enter an infinite loop.
    //
    while(1)
    {
    }    
}