示例#1
0
/**************************************************************************************************
 * @fn          SysCtrlDeepSleepSetting
 *
 * @brief       Setup which peripherals are enabled/disabled in Deep Sleep
 *
 * input parameters
 *
 * @param       None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
void SysCtrlDeepSleepSetting(void)
{
  /* Disable General Purpose Timers 0, 1, 2, 3 during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT0);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT1);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT2);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT3);
  
  /* Disable SSI 0, 1 during deep sleep */
  SysCtrlPeripheralDeepSleepEnable(SYS_CTRL_PERIPH_SSI0);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_SSI1);
  
  /* Disable UART 0, 1 during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_UART0);
  SysCtrlPeripheralDeepSleepEnable(SYS_CTRL_PERIPH_UART1);
  
  /* Disable I2C, PKA, AES during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_I2C);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_PKA);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_AES);
  
  /* 
   * Disable RFC during deep sleep. Please note that this setting is 
   * only valid for PG2.0. For PG1.0 this is just a dummy instruction. 
   */ 
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_RFC);
}
示例#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();
}
示例#3
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);
}
示例#4
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);
}
示例#5
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);
}
示例#6
0
文件: Spi.cpp 项目: JKLLBF/firmware
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_);
}
示例#7
0
static void SysCtrlDeepSleepSetting(void)
{
  /* Disable General Purpose Timers 0, 1, 2, 3 during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT0);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT1);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT2);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_GPT3);

  /* Disable SSI 0, 1 during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_SSI0);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_SSI1);

  /* Disable UART 0, 1 during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_UART0);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_UART1);

  /* Disable I2C, PKA, AES during deep sleep */
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_I2C);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_PKA);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_AES);
  SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_RFC);
}
示例#8
0
//*****************************************************************************
//
// Configure sleep timer, put system into deep sleep and watch sleep timer 
// interrupt wakeup system again
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Val;
  
    //
    // 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);
   
    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for SSI operation.
    //
    InitConsole();
    
    //
    // Display the setup on the console.
    //
    UARTprintf("Sleepmode timer\n");

    //
    // Disable UART0 when in deep sleep
    //
    SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_UART0);
    
    //
    // Let system enter powermode 2 when going to deep sleep
    //
    SysCtrlPowerModeSet(SYS_CTRL_PM_2);

    //
    // Enable the Sleep Timer wakeup
    //
    GPIOIntWakeupEnable(GPIO_IWE_SM_TIMER); 

    //
    // Enable sleep mode interrupt
    //
    IntEnable(INT_SMTIM);
    
    //
    // Set timer to 10000 above current value
    //
    ui32Val = SleepModeTimerCountGet();
    SleepModeTimerCompareSet(ui32Val + 10000);

    //
    // Display the timer value on the console.
    //
    UARTprintf("Timer val = %d\n", ui32Val);
    
    //
    // Wait for UART to be flushed
    //
    while(UARTBusy(UART0_BASE))
    {
    }
    
    //
    // Go to sleep
    //
    SysCtrlDeepSleep();

    //
    // Display the timer value on the console.
    //    
    ui32Val = SleepModeTimerCountGet();
    UARTprintf("Timer val = %d (after wakeup)\n", ui32Val);
    
    //
    // Done - enter an infinite loop.
    //
    while(1)
    {
    }
}