예제 #1
0
int main()
{
  	uart_config_t uart_conf;

	DISABLE_IRQ();

	hal_clk_init();
	sys_tick_init();
	I2cInit( &I2c, I2C_SCL, I2C_SDA );

	uart_conf.baud = 9600;
	uart_conf.word_length = 8;
	uart_conf.parity = NONE;
	uart_conf.stop_bits = 1;
	uart_init(&uart_conf);

	ENABLE_IRQ();

    app_init();
	
	DISABLE_IRQ();
	led_init();
 
	 
	while(1){
        /** polling all events */
        app_evt();
        led_evt();
	}
}
예제 #2
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      I2CcommsInit
 *
 *  DESCRIPTION
 *      This function initialises the I2C
 *
 *  RETURNS
 *      Nothing
 *
 *----------------------------------------------------------------------------*/
extern void I2CcommsInit(void)
{
    /* Initialise I2C if it is not already initialised */

    if(!i2c_initialised)
    {     
        i2c_initialised = TRUE;
        PioSetModes(    ((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                pio_mode_user);

        /* Configure the PIOs as Input */
        PioSetDirs(     ((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                FALSE);
        PioSetPullModes(((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                pio_mode_strong_pull_down); 
        PioSetEventMask(((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                pio_event_mode_disable);

        /* Configure the I2C controller */
        I2cInit(I2C_SDA_PIO,
                I2C_SCL_PIO,
                I2C_POWER_PIO_UNDEFINED,
                pio_i2c_pull_mode_strong_pull_up);

        /* Configure pull mode of the I2C pins */
        PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_up);

        /* Configure the I2C clock */
        I2cConfigClock(I2C_SCL_100KBPS_HIGH_PERIOD, I2C_SCL_100KBPS_LOW_PERIOD);
//        I2cConfigClock(I2C_SCL_400KBPS_HIGH_PERIOD, I2C_SCL_400KBPS_LOW_PERIOD);
        
        /* Enable the I2C controller */
        I2cEnable(TRUE);
    }
}
예제 #3
0
void LcdDisplayInitI2c(void)
{
    I2cEnable(TRUE);

    /* I2cInit(uint8 sda_pio, uint8 scl_pio, uint8 power_pio, pio_pull_mode pull); */
    /* I2cInit() resets clock to 100kHz. */
    I2cInit(PIO_SDA, PIO_SCL, I2C_POWER_PIO_UNDEFINED, pio_i2c_pull_mode_strong_pull_up);

    I2cConfigClock(I2C_SCL_400KBPS_HIGH_PERIOD, I2C_SCL_400KBPS_LOW_PERIOD);
} /* LcdDisplayInitI2c */
예제 #4
0
void BoardInitMcu( void )
{
    Gpio_t ioPin;

    if( McuInitialized == false )
    {
        HAL_Init( );

        // LEDs
        GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
        GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
        GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, Led3Status );

        SystemClockConfig( );

        GpioInit( &ioPin, UART_RX, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        if( GpioRead( &ioPin ) == 1 )   // Debug Mode
        {
            UsbIsConnected = true;
            FifoInit( &Uart1.FifoTx, UartTxBuffer, UART_FIFO_TX_SIZE );
            FifoInit( &Uart1.FifoRx, UartRxBuffer, UART_FIFO_RX_SIZE );
            // Configure your terminal for 8 Bits data (7 data bit + 1 parity bit), no parity and no flow ctrl
            UartInit( &Uart1, UART_1, UART_TX, UART_RX );
            UartConfig( &Uart1, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );
        }
        else
        {
            UsbIsConnected = false;
            UartDeInit( &Uart1 );
        }

        RtcInit( );

        BoardUnusedIoInit( );
    }
    else
    {
        SystemClockReConfig( );
    }

    I2cInit( &I2c, I2C_SCL, I2C_SDA );
    AdcInit( &Adc, BAT_LEVEL_PIN );

    SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
    SX1272IoInit( );

    if( McuInitialized == false )
    {
        McuInitialized = true;
        if( GetBoardPowerSource( ) == BATTERY_POWER )
        {
            CalibrateSystemWakeupTime( );
        }
    }
}
예제 #5
0
파일: init.c 프로젝트: pointhi/PointhiBoard
void InitSystem() {
    // General init
    InitOsc();
    InitPort();

    // Peripheral init
    AdcInit();
    I2cInit();

    // Interrupt init
    InterruptInit();
}
예제 #6
0
int main(void)
{
    uint32_t current_time = 0;
    SystemInit();
    GpioInit();
    //AdcInit();

    TimerInit(0, 1ul * _millisecond);
    CallbackRegister(MotorHandler, 10ul * _millisecond);
    CallbackEnable(MotorHandler);
    TimerEnable(0);
    EncoderInit();
    MotorInit();
    MotorStart();

    I2cInit(SENSOR_BUS);
    current_time = now;
    while(now < current_time + 1000);
    // center the wheels if they aren't already
    set_motor_position(MOTOR_FRONT_FRONT, FF_CENTER, 70);
    set_motor_position(MOTOR_BACK_FRONT,  BF_CENTER, 72);
    while (motor[MOTOR_FRONT_FRONT].state == MOTOR_MOVING && motor[MOTOR_BACK_FRONT].state == MOTOR_MOVING);

    current_time = now;
    while(now < current_time + 5000);

    // offset one motor
    set_motor_position(MOTOR_FRONT_FRONT, FF_CENTER, 70);
    set_motor_position(MOTOR_BACK_FRONT,  BF_CENTER + 50, 72);
    while (motor[MOTOR_FRONT_FRONT].state == MOTOR_MOVING && motor[MOTOR_BACK_FRONT].state == MOTOR_MOVING);
    current_time = now;
    while(now < current_time + 1000);

    while (1)
    {
        if (get_ir_sen())
        {
            set_motor_position(MOTOR_FRONT_FRONT, FF_CENTER + 50, -70);
            set_motor_position(MOTOR_BACK_FRONT,  BF_CENTER, -72);
            while (motor[MOTOR_FRONT_FRONT].state == MOTOR_MOVING && motor[MOTOR_BACK_FRONT].state == MOTOR_MOVING);
        }
        else
        {
            set_motor_position(MOTOR_FRONT_FRONT, FF_CENTER, 70);
            set_motor_position(MOTOR_BACK_FRONT,  BF_CENTER + 50, 72);
            while (motor[MOTOR_FRONT_FRONT].state == MOTOR_MOVING && motor[MOTOR_BACK_FRONT].state == MOTOR_MOVING);

        }
    }
    return 0;
}
예제 #7
0
파일: board.c 프로젝트: juliocdep/contiki
void BoardInitMcu( void )
{
    if( McuInitialized == false )
    {
        // We use IRQ priority group 4 for the entire project
        // When setting the IRQ, only the preemption priority is used
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

        // Disable Systick
//        SysTick->CTRL  &= ~SysTick_CTRL_TICKINT_Msk;    // Systick IRQ off
//        SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;            // Clear SysTick Exception pending flag

        /* Setup SysTick Timer for 1 ms interrupts (not too often to save power) */
        if (SysTick_Config(SystemCoreClock / 1000))
		{
			/* Capture error */
			while (1);
		}

        I2cInit( &I2c, I2C_SCL, I2C_SDA );

        SpiInit( &SX1276.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
        SX1276IoInit( );

#if defined( USE_DEBUG_PINS )
        GpioInit( &DbgPin1, J1_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin2, J1_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin3, J1_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin4, J1_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
#endif
        BoardInitPeriph( );

#if( LOW_POWER_MODE_ENABLE )
        TimerSetLowPowerEnable( true );
#else
        TimerSetLowPowerEnable( false );
#endif
        BoardUnusedIoInit( );

        if( TimerGetLowPowerEnable( ) == true )
        {
            RtcInit( );
        }
        else
        {
            TimerHwInit( );
        }
        McuInitialized = true;
    }
}
예제 #8
0
int main(void)
{
    I2cInit( &I2c, I2C_SCL, I2C_SDA );

    GpioInit( &UsbDetect, USB_ON, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
    GpioInit( &DcDcEnable, DC_DC_EN, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );

    GpioInit( &RadioPushButton, RADIO_PUSH_BUTTON, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
    
    GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
    GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
    GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
    GpioInit( &Led4, LED_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );

    if( GpioRead( &RadioPushButton ) == 0 )
    { /* Test if user code is programmed starting from address 0x8003000 */
        if( ( ( *( volatile uint32_t* )ApplicationAddress ) & 0x2FFE0000 ) == 0x20000000 )
        { /* Jump to user application */

            JumpAddress = *( volatile uint32_t* )( ApplicationAddress + 4 );
            Jump_To_Application = ( pFunction ) JumpAddress;
            /* Initialize user application's Stack Pointer */
            __set_MSP( *( volatile uint32_t* ) ApplicationAddress );
            Jump_To_Application( );
        }
    } /* Otherwise enters DFU mode to allow user to program his application */

    /* Enter DFU mode */
    DeviceState = STATE_dfuERROR;
    DeviceStatus[0] = STATUS_ERRFIRMWARE;
    DeviceStatus[4] = DeviceState;

    UsbMcuInit( );

    /* Main loop */
    while (1)
    {
        GpioWrite( &Led1, 0 );
        GpioWrite( &Led2, 0 );
        GpioWrite( &Led3, 0 );
        GpioWrite( &Led4, 0 );
        DelayLoop( 500 );
        GpioWrite( &Led1, 1 );
        GpioWrite( &Led2, 1 );
        GpioWrite( &Led3, 1 );
        GpioWrite( &Led4, 1 );
        DelayLoop( 500 );
    }
}
예제 #9
0
void BoardInitMcu( void )
{
    if( McuInitialized == false )
    {
#if defined( USE_BOOTLOADER )
        // Set the Vector Table base location at 0x3000
        NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x3000 );
#endif
        // We use IRQ priority group 4 for the entire project
        // When setting the IRQ, only the preemption priority is used
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

        // Disable Systick
        SysTick->CTRL  &= ~SysTick_CTRL_TICKINT_Msk;    // Systick IRQ off 
        SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;            // Clear SysTick Exception pending flag

        I2cInit( &I2c, I2C_SCL, I2C_SDA );
        AdcInit( &Adc, BAT_LEVEL );

        SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
        SX1272IoInit( );

#if defined( USE_DEBUG_PINS )
        GpioInit( &DbgPin1, CON_EXT_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin2, CON_EXT_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin3, CON_EXT_7, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin4, CON_EXT_9, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
#endif

        BoardUnusedIoInit( );

#if defined( USE_USB_CDC )
        UsbMcuInit( );
        UartInit( &UartUsb, UART_USB_CDC, NC, NC );
        UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );
#endif

#ifdef LOW_POWER_MODE_ENABLE
        RtcInit( );
#else
        TimerHwInit( );
#endif
        McuInitialized = true;
    }
}
예제 #10
0
void BoardInitMcu( void )
{
    if( McuInitialized == false )
    {
#if defined( USE_BOOTLOADER )
        // Set the Vector Table base location at 0x3000
        SCB->VTOR = FLASH_BASE | 0x3000;
#endif
        HAL_Init( );

        SystemClockConfig( );

#if defined( USE_USB_CDC )
        UartInit( &UartUsb, UART_USB_CDC, NC, NC );
        UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );

        DelayMs( 1000 ); // 1000 ms for Usb initialization
#endif

        RtcInit( );

        BoardUnusedIoInit( );

        I2cInit( &I2c, I2C_1, I2C_SCL, I2C_SDA );
    }
    else
    {
        SystemClockReConfig( );
    }

    AdcInit( &Adc, BAT_LEVEL_PIN );

    SpiInit( &SX1272.Spi, SPI_1, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
    SX1272IoInit( );

    if( McuInitialized == false )
    {
        McuInitialized = true;
        if( GetBoardPowerSource( ) == BATTERY_POWER )
        {
            CalibrateSystemWakeupTime( );
        }
    }
}
예제 #11
0
void BoardInitMcu( void )
{
    if( McuInitialized == false )
    {
        // We use IRQ priority group 4 for the entire project
        // When setting the IRQ, only the preemption priority is used
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

        // Disable Systick
        SysTick->CTRL  &= ~SysTick_CTRL_TICKINT_Msk;    // Systick IRQ off 
        SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;            // Clear SysTick Exception pending flag

        I2cInit( &I2c, I2C_SCL, I2C_SDA );

        SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
        SX1272IoInit( );

#if defined( USE_DEBUG_PINS )
        GpioInit( &DbgPin1, J5_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin2, J5_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin3, J5_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin4, J5_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
#endif
        BoardInitPeriph( );

#if( LOW_POWER_MODE_ENABLE )
        TimerSetLowPowerEnable( true );
#else
        TimerSetLowPowerEnable( false );
#endif
        BoardUnusedIoInit( );

        if( TimerGetLowPowerEnable( ) == true )
        {
            RtcInit( );
        }
        else
        {
            TimerHwInit( );
        }
        McuInitialized = true;
    }
}
예제 #12
0
void task_fxos_rtos( task_param_t param )
{
    /*! I2C channel to be used by digital 3D accelerometer */
    Fxos.instance = FXOS8700CQ_I2C_INSTANCE;
    I2c.I2c = &Fxos;
    I2cInit(&I2c, I2C_SCL, I2C_SDA);

    /* Initialize accelerometer */
    FxosInit (FXOS_I2C_ADDRESS);

    while (1) {
        accel_sensor_data_t sensorData;
        if ( FxosReadSensorData(&sensorData) != FAIL ) {
            LOG_DEBUG_BARE("DATA: Accelerometer (X/Y/Z) \t%d \t%d \t%d\r\n", sensorData.accelX,
                    sensorData.accelY, sensorData.accelZ);
        }
        OSA_TimeDelay(5000);
    }
}
예제 #13
0
파일: main.c 프로젝트: ytai/PixieGuitar
int main(int argc, char** argv) {
  PowerOn();

  ClockInit();

  ANSELA = 0;
  ANSELB = 0;
  SPLIM = 0xFFFF;  // TODO: implement proper handling of SPLIM.

  ModuleInit();
  I2cInit();
  ShellTaskInit();

  App * first = MainMenuAppInit(&main_menu_app);
  // Comment out the next line to skip splash.
  first = SplashAppInit(&splash_app, first);

  AppTaskInit(first);

  vTaskStartScheduler();
}
예제 #14
0
파일: quopter.c 프로젝트: bspell1/embed
//-----------< FUNCTION: QuopterInit >---------------------------------------
// Purpose:    quopter initialization
// Parameters: none
// Returns:    none
//---------------------------------------------------------------------------
void QuopterInit ()
{
   // global initialization
   memzero(&g_Control, sizeof(g_Control));
   g_Control.nThrustInput = 0.0f;
   // protocol initialization
   sei();
   I2cInit();
   SpiInit();
   // hardware initialization
   PinSetOutput(PIN_D4);
   PinSetHi(PIN_D4);
   Tlc5940Init(
      &(TLC5940_CONFIG) {
         .nPinBlank = PIN_D3,
         .nPinSClk  = PIN_D7,
         .nPinSIn   = PIN_D5,
         .nPinXlat  = PIN_B0,
         .nPinGSClk = PIN_OC0A            // PIN_D6, greyscale clock
      }
   );
예제 #15
0
파일: main.c 프로젝트: Barobo/iMobot_sensor
void main(void)
{
    WD_STOP();
    CAL_CLOCK();
    
//    TimerAInit();
    HardwareInit();
    I2cInit(0x02, 0x00);
    _EINT();
    
    while (1)
    {
        //LPM0;
        //_NOP();
        if (GetWriteEndpoint(0))
            SET_LOW(RED_LED);
        else
            SET_HIGH(RED_LED);
        
        SetReadEndpoint(0, READ_IN(LP_SWITCH));
    }
}
예제 #16
0
파일: board.c 프로젝트: hollie/LoRaMac-node
void BoardInitMcu( void )
{
	if( McuInitialized == false )
	{
		/* Chip errata */
		CHIP_Init();

		CMU_OscillatorEnable(cmuOsc_HFXO, true, true);
		CMU_ClockSelectSet(cmuClock_HF,cmuSelect_HFXO);

		/* Enable clock for HF peripherals */
		CMU_ClockEnable(cmuClock_HFPER, true);
		CMU_ClockEnable(cmuClock_GPIO, true);

		GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, LED_1_ON_STATE );
		GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, LED_2_ON_STATE );

#ifdef USE_I2C
		I2cInit( &I2c, I2C_SCL, I2C_SDA );
#endif
		SX1272IoInit( );
		SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );

		BoardUnusedIoInit( );

#ifdef LOW_POWER_MODE_ENABLE
		#error LOW_POWER_MODE_ENABLE not supported
		RtcInit( );
#else
		TimerHwInit( );
#endif
		Led_1_Off();
		Led_2_Off();

		McuInitialized = true;
	}
}
예제 #17
0
zx_status_t PlatformBus::PBusRegisterProtocol(uint32_t proto_id, const void* protocol,
                                              size_t protocol_size,
                                              const platform_proxy_cb_t* proxy_cb) {
    if (!protocol || protocol_size < sizeof(ddk::AnyProtocol)) {
        return ZX_ERR_INVALID_ARGS;
    }

    switch (proto_id) {
    case ZX_PROTOCOL_GPIO_IMPL: {
        if (proxy_cb->callback != nullptr) {
            return ZX_ERR_INVALID_ARGS;
        }
        gpio_ = ddk::GpioImplProtocolClient(static_cast<const gpio_impl_protocol_t*>(protocol));
        break;
    }
    case ZX_PROTOCOL_I2C_IMPL: {
        if (proxy_cb->callback != nullptr) {
            return ZX_ERR_INVALID_ARGS;
        }
        auto proto = static_cast<const i2c_impl_protocol_t*>(protocol);
        auto status = I2cInit(proto);
        if (status != ZX_OK) {
            return status;
        }

        i2c_ = ddk::I2cImplProtocolClient(proto);
        break;
    }
    case ZX_PROTOCOL_CLK: {
        if (proxy_cb->callback != nullptr) {
            return ZX_ERR_INVALID_ARGS;
        }
        clk_ = ddk::ClkProtocolClient(static_cast<const clk_protocol_t*>(protocol));
        break;
    }
    case ZX_PROTOCOL_IOMMU: {
        if (proxy_cb->callback != nullptr) {
            return ZX_ERR_INVALID_ARGS;
        }
        iommu_ = ddk::IommuProtocolClient(static_cast<const iommu_protocol_t*>(protocol));
        break;
    }
    default: {
        if (proxy_cb->callback == nullptr) {
            return ZX_ERR_NOT_SUPPORTED;
        }

        fbl::AutoLock lock(&proto_proxys_mutex_);
        if (proto_proxys_.find(proto_id).IsValid()) {
            zxlogf(ERROR, "%s: protocol %08x has already been registered\n", __func__, proto_id);
            return ZX_ERR_BAD_STATE;
        }

        fbl::AllocChecker ac;
        auto proxy = fbl::make_unique_checked<ProtoProxy>(&ac, proto_id,
                                                          static_cast<const ddk::AnyProtocol*>(protocol),
                                                          *proxy_cb);
        if (!ac.check()) {
            return ZX_ERR_NO_MEMORY;
        }

        proto_proxys_.insert(std::move(proxy));
        sync_completion_signal(&proto_completion_);
        return ZX_OK;
    }
    }

    fbl::AutoLock lock(&proto_completion_mutex_);
    sync_completion_signal(&proto_completion_);
    return ZX_OK;
}
예제 #18
0
파일: i2c.c 프로젝트: kaaLabs15/XRange
void I2cResetBus( I2c_t *obj )
{
    I2cInitialized = false;
    I2cInit( obj, I2C_SCL, I2C_SDA );
}
예제 #19
0
파일: init.c 프로젝트: rmmiranda/PmicMpu
int main( void )
{
    WdtInit();

    InterruptControllerInit();

    EventLogInit();

    GpioInit();

    // Configure !RSN/NMI pin for NMI mode early
    ConfigureRstNmi();

    ConfigureFll();

    V1( EventLogAdd( EVENTLOG_TIMER_INIT ) );
    TimerInit();

    WdtStartTimer();

    V1( EventLogAdd( EVENTLOG_SPI_INIT ) );
    SpiInit();

#if !defined( PLATFORM_RIMEVALBOARD )
    HostCtrlPmicRegisterReset( RESET_LCD_IO );

#if defined( PROCESSOR_PMU430 )
    //resetting the fuel gauge LDO
    PmicClear( PMIC_VRTC, 1<<7 );
    HwDelay(25000000); //25 ms delay
    PmicSet( PMIC_VRTC, 1<<7 );
#endif

#endif

    ApiInit();

#if defined( DEVID_UPDATER_SUPPORT )
    CodeUpdateStateInit( );
#endif

    V1( EventLogAdd( EVENTLOG_ADC_HW_INIT ) );
    AdcInitHw();

    V1( EventLogAdd( EVENTLOG_MSGQUE_INIT ) );
    CallQueueInit();

    V1( EventLogAdd( EVENTLOG_PMIC_INTCTRL_INIT ) );
    PmicIntCtrlInit();

    // configure charger interrupt handler
    PmicRegisterIntHandler( INT_CHARGER_IRQ, ChargerHandler );
    PmicInterruptEnable( INT_CHARGER_IRQ );

    // enable battery insertion/removal interrupts
	PmicWrite( PMIC_CHG_INT, 0x00 );
    PmicClear( PMIC_CHG_INT_MASK, CHGINT_MASK_BAT );
    PmicClear( PMIC_MIRQ, INT_MASK_CHARGER );


    I2cInitInternalBus();

    // Need to enable GIE (PoR default is OFF)
    __enable_interrupt();

    RegisterTimerExpiry( RTC_EXTERNAL_XTAL_TIMER, SwitchToXtal, 0 );
    // switch to external xtal after 2 seconds
    SetTimer( RTC_EXTERNAL_XTAL_TIMER, 0x10000 );

#if defined( PLATFORM_RIMEVALBOARD )
    I2cInit();
#else
    HostCtrlInit();
#endif

    for (;;) {
        WdtHit();

        if( !ExecuteCall() ) {
            // if there was nothing to call, enter sleep mode
            SCSleep();
        }
    }
}
예제 #20
0
void LCD_ZTOLED::begin()
{
    I2cInit();
    ScI2cMxReset(OLED_ADDRESS);
    clear();
}
예제 #21
0
uint8_t I2cWrite( uint8_t deviceAddr, uint8_t data )
{
    __IO int32_t i;
    uint32_t timeOut;

    I2cFsmcClkEnable( false );
   
    /* Test on BUSY Flag */
    timeOut = TIMEOUT_MAX;
    while( I2C_GetFlagStatus( I2C_INTERFACE, I2C_FLAG_BUSY) ) 
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    /* Send START condition */
    I2C_GenerateSTART( I2C_INTERFACE, ENABLE );

    /* Test on EV5 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_MODE_SELECT ) )
    {
        if( I2C_INTERFACE->SR1 & I2C_FLAG_RXNE )
        {
            volatile uint32_t drTemp;
            drTemp = I2C_INTERFACE->DR;
        }
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }
    /* Send device's address for write */
    I2C_Send7bitAddress( I2C_INTERFACE, deviceAddr, I2C_Direction_Transmitter );

    /* Test on EV6 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) )
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    I2C_SendData( I2C_INTERFACE, data );

    /* Test on EV8 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) )
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    I2C_GenerateSTOP( I2C_INTERFACE, ENABLE ); 
    for( i = 0 ; i < 500 ; i++ ){ ; }

    I2cFsmcClkEnable( true );
    return( SX_OK );
}
예제 #22
0
uint8_t I2cWriteBuffer( uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size, tI2cAddrSize addrSize )
{
    __IO int32_t i;
    uint32_t timeOut;

    I2cFsmcClkEnable( false );

    /* Test on BUSY Flag */
    timeOut = TIMEOUT_MAX;
    while( I2C_GetFlagStatus( I2C_INTERFACE, I2C_FLAG_BUSY) ) 
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    /* Send START condition */
    I2C_GenerateSTART( I2C_INTERFACE, ENABLE );

    /* Test on EV5 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_MODE_SELECT ) )
    {
        if( I2C_INTERFACE->SR1 & I2C_FLAG_RXNE )
        {
            volatile uint32_t drTemp;
            drTemp = I2C_INTERFACE->DR;
        }
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    /* Send device's address for write */
    I2C_Send7bitAddress( I2C_INTERFACE, deviceAddr, I2C_Direction_Transmitter );

    /* Test on EV6 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) )
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    if( addrSize == I2C_ADDR_SIZE_16 )
    {
        /* Send the device's internal address MSB to write to */
        I2C_SendData( I2C_INTERFACE, ( uint8_t )( ( addr & 0xFF00 ) >> 8 )  );

        /* Test on EV8 and clear it */
        timeOut = TIMEOUT_MAX;
        while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) )
        {
            if( ( timeOut-- ) == 0 )
            {
                I2cInit( );
                I2cFsmcClkEnable( true );
                return( SX_TIMEOUT );
            }
        }
    }
예제 #23
0
uint8_t I2cRead( uint8_t deviceAddr, uint8_t *data )
{
    __IO int32_t i;
    int32_t size = 1;
    uint32_t timeOut;

    I2cFsmcClkEnable( false );
    
    /* Test on BUSY Flag */
    timeOut = TIMEOUT_MAX;
    while( I2C_GetFlagStatus( I2C_INTERFACE, I2C_FLAG_BUSY) ) 
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    /* Send START condition a second time */
    I2C_GenerateSTART( I2C_INTERFACE, ENABLE );

    /* Test on EV5 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_MODE_SELECT ) )
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    /* Send device's address for read */
    I2C_Send7bitAddress( I2C_INTERFACE, deviceAddr, I2C_Direction_Receiver );

    /* Test on EV6 and clear it */
    timeOut = TIMEOUT_MAX;
    while( !I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ) )
    {
        if( ( timeOut-- ) == 0 )
        {
            I2cInit( );
            I2cFsmcClkEnable( true );
            return( SX_TIMEOUT );
        }
    }

    /* While there is data to be read */
    while( size )
    {
        if( size == 1 )
        {
            /* Disable Acknowledgement */
            I2C_AcknowledgeConfig( I2C_INTERFACE, DISABLE );

            /* Send STOP Condition */
            I2C_GenerateSTOP( I2C_INTERFACE, ENABLE );
        }

        /* Test on EV7 and clear it */
        timeOut = TIMEOUT_MAX;
        if( I2C_CheckEvent( I2C_INTERFACE, I2C_EVENT_MASTER_BYTE_RECEIVED ) )
        {
            /* Read a byte from the device */
            *data = I2C_ReceiveData( I2C_INTERFACE );

            /* Decrement the read bytes counter */
            size--;
        }
        else
        {
            if( ( timeOut-- ) == 0 )
            {
                I2cInit( );
                I2cFsmcClkEnable( true );
                return( SX_TIMEOUT );
            }
        }
    }

    /* Enable Acknowledgement to be ready for another reception */
    I2C_AcknowledgeConfig( I2C_INTERFACE, ENABLE );

    for( i = 0 ; i < 500 ; i++ ){ ; }

    I2cFsmcClkEnable( true );
    return( SX_OK );
}