Beispiel #1
0
/**************************************************************************************************
 * @fn          SysCtrlRunSetting
 *
 * @brief       Setup which peripherals are enabled/disabled while in active/run state
 *
 * input parameters
 *
 * @param       None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************/
void SysCtrlRunSetting(void)
{
  /* Disable unused peripherals and enable used periperals */
  /* Disable General Purpose Timers 0, 1, 2, 3 when running */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT0);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT1);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT2);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT3);
  
  /* Disable SSI 0, 1 when running */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_SSI0);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_SSI1);
  
  /* Enable UART 0, 1 when running */
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0);
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART1);
  
  SysCtrlPeripheralReset(SYS_CTRL_PERIPH_AES);
  SysCtrlPeripheralReset(SYS_CTRL_PERIPH_PKA);
  
  /* Enable AES and PKA while running and disable I2C */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_I2C);
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_PKA);
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_AES);
  
  /* 
   * Enable RFC during run. Please note that this setting is 
   * only valid for PG2.0. For PG1.0 since the RFC is always on, 
   * this is only a dummy  instruction
   */
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
}
Beispiel #2
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();
}
Beispiel #3
0
void tempInit( void ) {
    // Enable the RF Core
    SysCtrlPeripheralEnable( SYS_CTRL_PERIPH_RFC );
    // Connect temperature sensor to ADC
    HWREG( CCTEST_TR0 ) |= CCTEST_TR0_ADCTM;
    SOCADCSingleConfigure( SOCADC_12_BIT, SOCADC_REF_INTERNAL );
}
Beispiel #4
0
/*********************************************************************
 * @fn      HalTimer1Init
 *
 * @brief   Initialize Timer Service
 *
 * @param   None
 *
 * @return  None
 */
void HalTimer1Init (halTimerCBack_t cBack)
{
  //not used for now
  (void) cBack;

  //
  // Enable GPT0
  //  
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);
    
  //
  // Configure Timer0A for PWM use
  //
  TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                 GPTIMER_CFG_A_PWM);

  //
  // Set Duty cycle and enable
  //
  TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
  TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
  TimerEnable(GPTIMER0_BASE, GPTIMER_A);

  //
  // Set duty cycle to 0
  //
  TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, 0); 
}
Beispiel #5
0
/*
 * Public API
 */
void
ws_radio_init(void)
{
    WS_DEBUG("init\n");

    /* Reset state */
    memset(&radio_state, 0, sizeof(radio_state));

    /* Enable the clock */
    /* TODO: Power saving. We're basically leaving the radio on all the time */
    SysCtrlPeripheralReset(SYS_CTRL_PERIPH_RFC);
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
    SysCtrlPeripheralSleepEnable(SYS_CTRL_PERIPH_RFC);
    SysCtrlPeripheralDeepSleepEnable(SYS_CTRL_PERIPH_RFC);

    /* Configure CCA */
    HWREG(RFCORE_XREG_CCACTRL0) = CC2538_RFCORE_CCA_THRES;

    /* User Manual 23.15 - TX and RX settings */
    HWREG(RFCORE_XREG_AGCCTRL1) = CC2538_RFCORE_AGC_TARGET;
    HWREG(RFCORE_XREG_TXFILTCFG) = CC2538_RFCORE_TX_AA_FILTER;
    HWREG(ANA_REGS_BASE + ANA_REGS_O_IVCTRL) = CC2538_RFCORE_BIAS_CURRENT;
    HWREG(RFCORE_XREG_FSCAL1) = CC2538_RFCORE_FREQ_CAL;

    /* Enable auto CRC calculation (hardware) */
    HWREG(RFCORE_XREG_FRMCTRL0) = RFCORE_XREG_FRMCTRL0_AUTOCRC;

    /* Enable auto ACK */
    HWREG(RFCORE_XREG_FRMCTRL0) |= RFCORE_XREG_FRMCTRL0_AUTOACK;

    /* Configure the FIFOP signal to trigger when there are one or more
     * complete frames in the RX FIFO */
    HWREG(RFCORE_XREG_FIFOPCTRL) = WS_RADIO_MAX_PACKET_LEN;

    /* Set the TX output power */
    HWREG(RFCORE_XREG_TXPOWER) = CC2538_RFCORE_TX_POWER;

    /* Interrupt wth FIFOP signal */
    HWREG(RFCORE_XREG_RFIRQM0) = 0x04;
    IntRegister(INT_RFCORERTX, &rf_isr);
    IntEnable(INT_RFCORERTX);

    /* Interrupt with all RF ERROR signals */
    HWREG(RFCORE_XREG_RFERRM) = 0x7f;
    IntRegister(INT_RFCOREERR, &rf_err_isr);
    IntEnable(INT_RFCOREERR);

    /* Configure the frame filtering */
    HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_MAX_FRAME_VERSION_M;
    HWREG(RFCORE_XREG_FRMFILT0) |= WS_MAC_MAX_FRAME_VERSION <<
        RFCORE_XREG_FRMFILT0_MAX_FRAME_VERSION_S;
    /* Don't bother filtering out the source addresses */
    HWREG(RFCORE_XREG_SRCMATCH) &= ~RFCORE_XREG_SRCMATCH_SRC_MATCH_EN;
}
Beispiel #6
0
/*************************************************************************************************
 * @fn      HalUARTInitIsr()
 *
 * @brief   Initialize the UART
 *
 * @param   none
 *
 * @return  none
 *************************************************************************************************/
void HalUARTInitIsr(void)
{
   SysCtrlPeripheralEnable(HAL_UART_SYS_CTRL);

  /* Setup PB0 as UART_CTS, PD3 as UART_RTS  
   * PA1 as UART_TX and PA0 as UART_RX
   */ 
  IOCPinConfigPeriphOutput(GPIO_A_BASE, GPIO_PIN_1, IOC_MUX_OUT_SEL_UART1_TXD);
  IOCPinConfigPeriphInput(GPIO_A_BASE, GPIO_PIN_0, IOC_UARTRXD_UART1);
  GPIOPinTypeUARTInput(GPIO_A_BASE, GPIO_PIN_0);
  GPIOPinTypeUARTOutput(GPIO_A_BASE, GPIO_PIN_1);  
  recRst();

}
bool TemperatureSensor::enable(void) {
    // Enable RF Core (needed to enable temp sensor)
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
    
    // Connect temp sensor to ADC
    HWREG(CCTEST_TR0) |= CCTEST_TR0_ADCTM;
    
    // Enable the temperature sensor 
    HWREG(RFCORE_XREG_ATEST) = 0x01;
    
    // Configure ADC, Internal reference, 512 decimation rate (12bit)
    SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);

    return true;
}
Beispiel #8
0
void SysCtrlRunSetting(void)
{
  /* Disable General Purpose Timers 0, 1, 2, 3 when running */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT0);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT1);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT2);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_GPT3);

  /* Disable SSI 0, 1 when running */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_SSI0);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_SSI1);

  /* Disable UART1 when running */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_UART1);

  /* Disable I2C, AES and PKA when running */
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_I2C);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_PKA);
  SysCtrlPeripheralDisable(SYS_CTRL_PERIPH_AES);

  /* Enable UART0 and RFC when running */
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0);
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
}
Beispiel #9
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);
}
Beispiel #10
0
void Spi::enable(uint32_t baudrate)
{
    GpioConfig& miso = miso_.getGpioConfig();
    GpioConfig& mosi = mosi_.getGpioConfig();
    GpioConfig& clk  = clk_.getGpioConfig();
    // GpioConfig& ncs  = ncs_.getGpioConfig();

    // Store baudrate in configuration
    if (baudrate != 0) {
        config_.baudrate = baudrate;
    }
    
    // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3)
    SysCtrlPeripheralEnable(config_.peripheral);
    SysCtrlPeripheralSleepEnable(config_.peripheral);
    SysCtrlPeripheralDeepSleepDisable(config_.peripheral);

    // Reset peripheral previous to configuring it
    SSIDisable(config_.base);

    // Set IO clock as SPI0 clock source
    SSIClockSourceSet(config_.base, config_.clock);

    // Configure the MISO, MOSI, CLK and nCS pins as peripheral
    IOCPinConfigPeriphInput(miso.port, miso.pin, miso.ioc);
    IOCPinConfigPeriphOutput(mosi.port, mosi.pin, mosi.ioc);
    IOCPinConfigPeriphOutput(clk.port, clk.pin, clk.ioc);
    // IOCPinConfigPeriphOutput(ncs.port, ncs.pin, ncs.ioc);

    // Configure MISO, MOSI, CLK and nCS GPIOs
    GPIOPinTypeSSI(miso.port, miso.pin);
    GPIOPinTypeSSI(mosi.port, mosi.pin);
    GPIOPinTypeSSI(clk.port, clk.pin);
    // GPIOPinTypeSSI(ncs.port, ncs.pin);

    // Configure the SPI0 clock
    SSIConfigSetExpClk(config_.base, SysCtrlIOClockGet(), config_.protocol, \
                       config_.mode, config_.baudrate, config_.datawidth);

    // Enable the SPI0 module
    SSIEnable(config_.base);
}
Beispiel #11
0
void Uart::enable(uint32_t baudrate)
{
    // Get GpioConfig structures
    GpioConfig& rx = rx_.getGpioConfig();
    GpioConfig& tx = tx_.getGpioConfig();

    // Store baudrate in configuration
    if (baudrate != 0) {
        config_.baudrate = baudrate;
    }

    // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3)
    SysCtrlPeripheralEnable(config_.peripheral);
    SysCtrlPeripheralSleepEnable(config_.peripheral);
    SysCtrlPeripheralDeepSleepDisable(config_.peripheral);

    // Disable peripheral previous to configuring it
    UARTDisable(config_.peripheral);

    // Set IO clock as UART clock source
    UARTClockSourceSet(config_.base, config_.clock);

    // Configure the UART RX and TX pins
    IOCPinConfigPeriphInput(rx.port, rx.pin, rx.ioc);
    IOCPinConfigPeriphOutput(tx.port, tx.pin, tx.ioc);

    // Configure the UART GPIOs
    GPIOPinTypeUARTInput(rx.port, rx.pin);
    GPIOPinTypeUARTOutput(tx.port, tx.pin);

    // Configure the UART
    UARTConfigSetExpClk(config_.base, SysCtrlIOClockGet(), config_.baudrate, config_.mode);

    // Disable FIFO as we only use a one-byte buffer
    UARTFIFODisable(config_.base);

    // Raise an interrupt at the end of transmission
    UARTTxIntModeSet(config_.base, UART_TXINT_MODE_EOT);

    // Enable UART hardware
    UARTEnable(config_.base);
}
Beispiel #12
0
void Uart::enable(uint32_t baudrate, uint32_t config, uint32_t mode)
{
    // Store the UART baudrate, configuration and mode
    baudrate_ = baudrate;
    config_   = config;
    mode_     = mode;

    // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3)
    SysCtrlPeripheralEnable(uart_.peripheral);
    SysCtrlPeripheralSleepEnable(uart_.peripheral);
    SysCtrlPeripheralDeepSleepDisable(uart_.peripheral);

    // Disable peripheral previous to configuring it
    UARTDisable(uart_.peripheral);

    // Set IO clock as UART clock source
    UARTClockSourceSet(uart_.base, uart_.clock);

    // Configure the UART RX and TX pins
    IOCPinConfigPeriphInput(rx_.getPort(), rx_.getPin(), rx_.getIoc());
    IOCPinConfigPeriphOutput(tx_.getPort(), tx_.getPin(), tx_.getIoc());

    // Configure the UART GPIOs
    GPIOPinTypeUARTInput(rx_.getPort(), rx_.getPin());
    GPIOPinTypeUARTOutput(tx_.getPort(), tx_.getPin());

    // Configure the UART
    UARTConfigSetExpClk(uart_.base, SysCtrlIOClockGet(), baudrate_, config_);

    // Disable FIFO as we only use a one-byte buffer
    UARTFIFODisable(uart_.base);

    // Raise an interrupt at the end of transmission
    UARTTxIntModeSet(uart_.base, mode_);

    // Enable UART hardware
    UARTEnable(uart_.base);
}
Beispiel #13
0
void Spi::enable(uint32_t mode, uint32_t protocol, uint32_t datawidth, uint32_t baudrate)
{
    // Store SPI mode, protoco, baudrate and datawidth
    mode_      = mode;
    protocol_  = protocol;
    baudrate_  = baudrate;
    datawidth_ = datawidth;

    // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3)
    SysCtrlPeripheralEnable(peripheral_);
    SysCtrlPeripheralSleepEnable(peripheral_);
    SysCtrlPeripheralDeepSleepDisable(peripheral_);

    // Reset peripheral previous to configuring it
    SSIDisable(base_);

    // Set IO clock as SPI0 clock source
    SSIClockSourceSet(base_, clock_);

    // Configure the MISO, MOSI, CLK and nCS pins as peripheral
    IOCPinConfigPeriphInput(miso_.getPort(), miso_.getPin(), miso_.getIoc());
    IOCPinConfigPeriphOutput(mosi_.getPort(), mosi_.getPin(), mosi_.getIoc());
    IOCPinConfigPeriphOutput(clk_.getPort(), clk_.getPin(), clk_.getIoc());
    // IOCPinConfigPeriphOutput(ncs_.getPort(), ncs_.getPin(), ncs_.getIoc());

    // Configure MISO, MOSI, CLK and nCS GPIOs
    GPIOPinTypeSSI(miso_.getPort(), miso_.getPin());
    GPIOPinTypeSSI(mosi_.getPort(), mosi_.getPin());
    GPIOPinTypeSSI(clk_.getPort(), clk_.getPin());
    // GPIOPinTypeSSI(ncs_.getPort(), ncs_.getPin());

    // Configure the SPI0 clock
    SSIConfigSetExpClk(base_, SysCtrlIOClockGet(), protocol_, \
                       mode_, baudrate_, datawidth_);

    // Enable the SPI0 module
    SSIEnable(base_);
}
Beispiel #14
0
PROCESS_THREAD(hello_world_process, ev, data)
{

    //static struct etimer timer;
    PROCESS_BEGIN();
    //begintimer();
    //etimer_set(&timer, CLOCK_CONF_SECOND * 1);
    uint32_t ui32PrevCount = 0;

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

    //
    // 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.
    //
    printf(" 16-Bit Timer Interrupt ->\n\r");
    printf(" Timer = Timer0B\n\r");
    printf(" Mode = Periodic\n\r");
    printf(" Number of interrupts = %d \n\r", NUMBER_OF_INTS);
    printf(" Rate = 1ms\n\r");

    //
    // Configure Timer0B as a 16-bit periodic timer.
    //
    TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                   GPTIMER_CFG_A_PERIODIC | GPTIMER_CFG_B_PWM);
    /*   TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                       GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PWM);  */

    //
    // Set the Timer0B load value to 1ms.
    //
    TimerLoadSet(GPTIMER0_BASE, GPTIMER_B, sys_ctrl_get_sys_clock() / 100 );
    // TimerLoadSet(GPTIMER0_BASE, GPTIMER_B, SYS_CTRL_32MHZ );
    //
    // The following call will result in a dynamic interrupt table being used.
    // The table resides in RAM.
    // Alternatively SysTickIntHandler can be statically registred in your
    // application.
    //
    TimerIntRegister(GPTIMER0_BASE, GPTIMER_B, Timer0BIntHandler);

    //
    // Enable processor interrupts.
    //
    //IntMasterEnable();
    INTERRUPTS_ENABLE();
    //
    // Configure the Timer0B interrupt for timer timeout.
    //
    TimerIntEnable(GPTIMER0_BASE, GPTIMER_TIMB_TIMEOUT);

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

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

    //
    // Enable Timer0B.
    //
    TimerEnable(GPTIMER0_BASE, GPTIMER_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.
            //
            printf("Number of interrupts: %d\r", g_ui32Counter);
            ui32PrevCount = g_ui32Counter;
        }
    }

    /*
      while(1) {
        	//PROCESS_YIELD();
     	//if(ev == PROCESS_EVENT_TIMER) {


    	printf(" Hello Hi \n\r" );
    	//etimer_set(&timer, CLOCK_SECOND);

        //}
      }
     */

    PROCESS_END();
}
Beispiel #15
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();
}
Beispiel #16
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();
}
Beispiel #17
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)
    {
    }    
}
Beispiel #18
0
//*****************************************************************************
//
// Main function. Sets up the ADC to use the temperature sensor as input. Note 
// that you must enable to RF Core in order to use the ADC.
// The function runs a while forever loop converting the readout from ADC
// to temperature values and print it on the console.
//
//*****************************************************************************
int
main(void)
{
    uint16_t ui16Dummy;
    double dOutputVoltage;
    char pcTemp[20];

    //
    // 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 RF Core (needed to enable temp sensor)
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_RFC);
    
    //
    // 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("ADC temp sens\n");
    
    //
    // Connect temp sensor to ADC
    //
    HWREG(CCTEST_TR0) |= CCTEST_TR0_ADCTM;

    //
    // Enable the temperature sensor 
    //
    HWREG(RFCORE_XREG_ATEST) = 0x01;
    
    //
    // Configure ADC, Internal reference, 512 decimation rate (12bit)
    //
    SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);
     
    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Trigger single conversion on internal temp sensor
        //
        SOCADCSingleStart(SOCADC_TEMP_SENS);
        
        //
        // Wait until conversion is completed
        //
        while(!SOCADCEndOfCOnversionGet())
        {
        }

        //
        // Get data and shift down based on decimation rate
        //
        ui16Dummy = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
        
        //
        // Convert to temperature
        //
        dOutputVoltage = ui16Dummy * CONST;       
        dOutputVoltage = ((dOutputVoltage - OFFSET_0C) / TEMP_COEFF);
        
        //
        // Convert float to string
        //
        sprintf(pcTemp, "%.1f", dOutputVoltage);
                
        //
        // Print the result on UART
        //
        UARTprintf("ADC raw readout: %d\n", ui16Dummy);
        UARTprintf("Temperature: %s", pcTemp);
        UARTprintf(" C\n");
        
        //
        // Simple delay
        //
        for(int i=0;i<1000000;i++)
        {
        }
    }
}
Beispiel #19
0
//*****************************************************************************
//
// Main function of example.
//
//*****************************************************************************
void  main(void)
{
    uint8_t status;
    
    //
    // 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 AES peripheral
    //
    SysCtrlPeripheralReset(SYS_CTRL_PERIPH_AES);
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_AES);
    
    //
    // Register AES interrupt
    //
    IntRegister(INT_AES, CCMIntHandler);
    
    //
    // Enable global interrupts
    //
    IntAltMapEnable();
    IntMasterEnable();
    
    for(uint8_t i = 0; i < sizeof(sCCMNodecryptExample)/
        sizeof(sCCMNodecryptExample[0] ); i++)
    {
        //
        // Run and Verify CCM Inverse Authentication only
        //
        status = CCMDecryptExamples(sCCMNodecryptExample[i].ui8CCMDecrypt,
                                    sCCMNodecryptExample[i].ui8CCMKey,
                                    sCCMNodecryptExample[i].ui8CCMMval,
                                    sCCMNodecryptExample[i].ui8CCMN,
                                    sCCMNodecryptExample[i].ui8CCMC,
                                    sCCMNodecryptExample[i].ui16CCMLenC,
                                    sCCMNodecryptExample[i].ui8CCMA,
                                    sCCMNodecryptExample[i].ui16CCMLenA,
                                    sCCMNodecryptExample[i].ui8CCMKeyLocation,
                                    sCCMNodecryptExample[i].ui8CCMCstate,
                                    sCCMNodecryptExample[i].ui8CCMLVal,
                                    sCCMNodecryptExample[i].ui8CCMIntEnable,
                                    sCCMNodecryptExample[i].
                                        ui8CCMExpectedOutput);
        if(status != AES_SUCCESS)
        {
            while(1)
            {
                //
                // AES CCM failed
                //
            }
        }
    }
    
    for(uint8_t i = 0; i < sizeof(sCCMNoencryptExample)/
        sizeof(sCCMNoencryptExample[0] ); i++)
    {
        //
        // Run and Verify CCM Authentication only
        //
        status = CCMEncryptExample(sCCMNoencryptExample[i].ui8CCMEncrypt,
                                      sCCMNoencryptExample[i].ui8CCMkey,
                                      sCCMNoencryptExample[i].ui8CCMMval,
                                      sCCMNoencryptExample[i].ui8CCMN,
                                      sCCMNoencryptExample[i].ui8CCMM,
                                      sCCMNoencryptExample[i].ui16CCMLenM,
                                      sCCMNoencryptExample[i].ui8CCMA,
                                      sCCMNoencryptExample[i].ui16CCMLenA,
                                      sCCMNoencryptExample[i].ui8CCMKeyLocation,
                                      sCCMNoencryptExample[i].ui8CCMCstate,
                                      sCCMNoencryptExample[i].ui8CCMCCMLVal,
                                      sCCMNoencryptExample[i].ui8CCMIntEnable,
                                      sCCMNoencryptExample[i].
                                          ui8CCMExpectedOutput);
        if(status != AES_SUCCESS)
        {
            while(1)
            {
                //
                // AES CCM failed
                //
            }
        }
    }
    
    for(uint8_t i = 0; i < sizeof(sCCMEncryptExample)/
        sizeof(sCCMEncryptExample[0] ); i++)
    {
        //
        // Run and Verify CCM Authentication + Encryption
        //
        status = CCMEncryptExample(sCCMEncryptExample[i].ui8CCMEncrypt,
                                      sCCMEncryptExample[i].ui8CCMkey,
                                      sCCMEncryptExample[i].ui8CCMMval,
                                      sCCMEncryptExample[i].ui8CCMN,
                                      sCCMEncryptExample[i].ui8CCMM,
                                      sCCMEncryptExample[i].ui16CCMLenM,
                                      sCCMEncryptExample[i].ui8CCMA,
                                      sCCMEncryptExample[i].ui16CCMLenA,
                                      sCCMEncryptExample[i].ui8CCMKeyLocation,
                                      sCCMEncryptExample[i].ui8CCMCstate,
                                      sCCMEncryptExample[i].ui8CCMCCMLVal,
                                      sCCMEncryptExample[i].ui8CCMIntEnable,
                                      sCCMEncryptExample[i].
                                          ui8CCMExpectedOutput);
        if(status != AES_SUCCESS)
        {
            while(1)
            {
                //
                // AES CCM failed
                //
            }
        }
    }
    
    for(uint8_t i = 0; i < sizeof(sCCMDecryptExample)/
        sizeof(sCCMDecryptExample[0] ); i++)
    {
        //
        // Run and Verify CCM Inverse Authentication + Decryption
        //
        status = CCMDecryptExamples(sCCMDecryptExample[i].ui8CCMDecrypt,
                                    sCCMDecryptExample[i].ui8CCMKey,
                                    sCCMDecryptExample[i].ui8CCMMval,
                                    sCCMDecryptExample[i].ui8CCMN,
                                    sCCMDecryptExample[i].ui8CCMC,
                                    sCCMDecryptExample[i].ui16CCMLenC,
                                    sCCMDecryptExample[i].ui8CCMA,
                                    sCCMDecryptExample[i].ui16CCMLenA,
                                    sCCMDecryptExample[i].ui8CCMKeyLocation,
                                    sCCMDecryptExample[i].ui8CCMCstate,
                                    sCCMDecryptExample[i].ui8CCMLVal,
                                    sCCMDecryptExample[i].ui8CCMIntEnable,
                                    sCCMDecryptExample[i].
                                        ui8CCMExpectedOutput);
        if(status != AES_SUCCESS)
        {
            while(1)
            {
                //
                // AES CCM failed
                //
            }
        }
    }
    
    // CCM was successful
    while(1)
    {
    }
}