/**************************************************************************//**
 * @brief Initialize board support package functionality.
 *
 * @param[in] flags
 *   DK3x50:  Initialize in EBI or SPI mode using @ref BSP_INIT_DK_EBI or
 *            @ref BSP_INIT_DK_SPI.
 *   Gxxx_DK: Use 0.
 *   STK:     Use @ref BSP_INIT_BCC to initialize board controller UART, 0
 *            otherwise.
 *
 *   The value BSP_INIT_DEFAULT is defined and is: @ref BSP_INIT_DK_EBI on DK3x50,
 *             0 on all other kits.
 *
 * @return @ref BSP_STATUS_OK
 *****************************************************************************/
int BSP_Init(uint32_t flags)
{
  bool ret = false;

  if (flags & BSP_INIT_DK_EBI)
  {
    bspOperationMode = BSP_INIT_DK_EBI;
    BSP_BusControlModeSet(BSP_BusControl_EBI);
    ret = EbiInit();
  }
  if (flags & BSP_INIT_DK_SPI)
  {
    bspOperationMode = BSP_INIT_DK_SPI;
    BSP_BusControlModeSet(BSP_BusControl_SPI);
    ret = SpiInit();
  }

  if (ret == false)
  {
    /* Unable to access board control, this is an abornomal situation. */
    /* Try to restart kit and reprogram EFM32 with a standard example */
    /* as this is most likely caused by a peripheral misconfiguration. */
    while (1) ;
  }

  /* Inform AEM application that we are in Energy Mode 0 by default */
  BSP_RegisterWrite(&BC_REGISTER->EM, 0);
  
  /* Read out BC firmware version */
  bcFwVersion = BSP_RegisterRead(&BC_REGISTER->FW_VERSION);

  return BSP_STATUS_OK;
}
Example #2
0
void LcdInit(void)
{
	//输出引脚初始化
	Init_LCDGpio();
	SpiInit();  //SPI初始化
	
	LCD_SCLK_LOW();
	LCD_SCLK_HIGH();
	
	LCD_SDIN_LOW();
	LCD_SDIN_HIGH();
	
	LCD_DC_LOW();
	LCD_DC_HIGH();
	
	LCD_SCE_LOW();
	LCD_SCE_HIGH();
	
	LcdReset();  /*液晶复位*/
   
	//LcdFunctionSet(ACTIVE, H_ADDR, EXT_INS);	/*扩展指令集*/	
	LcdBiasSystem(0x03);	/*推荐混合率 1:48*/	
	LcdSetVop(0x32);		/*V(6.06) = 3.06 + 0.06*Vop*/
	LcdTempCtrl(0x00);		/*温度系数 0~3*/	
	LcdFunctionSet(ACTIVE, H_ADDR, BAS_INS);	/*基本指令集*/
	LcdDispalyControl((u8)NORMAL_MODE);		/*普通模式显示*/
	//
	LcdWriteDC(LCDCMD , 0x21 ); /*扩展指令*/
	LcdWriteDC(LCDCMD , 0xc8 ); /*设置偏压*/
	LcdWriteDC(LCDCMD , 0x20 ); /*标准指令*/
	LcdWriteDC(LCDCMD , 0x0c );/*标准显示模式*/
	LcdClsScr();        
}
void BoardInit( void )
{
    uint8_t i;

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

    // Initialize unused GPIO to optimize power consumption
    InitUnusedGPIO( );

    // Initialize Selector
    SelectorInit( );

    // Initialize SPI
    SpiInit( );
    
    // Initialize LED
    for( i = 0; i < LED_NB; i++ )
    {
        LedInit( ( tLed )i );
    }

    LedOn( LED1 );
    LedOn( LED2 );
    LedOn( LED3 );
    LongDelay( 1 );
    LedOff( LED1 );
    LedOff( LED2 );
    LedOff( LED3 );
}
Example #4
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

        AdcInit( &Adc, POTI );

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

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

        if( TimerGetLowPowerEnable( ) == true )
        {
            RtcInit( );
        }
        else
        {
            TimerHwInit( );
        }
        McuInitialized = true;
    }
}
void LCDInit(void)
{
    LCD_CS_TRIS = 0; // set chip select to output
    LCD_CS = 1;  // unselect LCD 
        
    LCD_RST_TRIS = 0;  // Set LCD Reset to output
    LCD_RST = 1;   // 
        
    delay();delay(); delay();  
        
    SpiInit(); 
    PortASpiInit(); 
    PortBSpiInit();
         
    WritePortA(0,0);    
    delay();  
    
    LCDConfigWrite(0x3C); 
    delay(); 
      
    LCDConfigWrite(0x0C); //Display off 
    delay();
        
    LCDConfigWrite(0x01); //Display Clear
    delay();
          
    LCDConfigWrite(0x06); //Entry Mode 
} 
Example #6
0
/*
   Spi_Open - open function for driver
*/
INT8U Spi_Open(INT8U DeviceIndex, PVOID pContext, INT8U Flags)
{
    PSPI_DEVICE pDevice = &((PSPI_EXT)pContext)->Device[DeviceIndex];
    INT8U err;
    
    if (DeviceIndex >= SPI_DEVICE_COUNT) {
            // someone passed us a bogus device
        DEBUGMSG(TRUE, ("SPI_DRV attempt to open bad device index: 0x%X\n\r", DeviceIndex));
        return OS_DRV_NO_DEVICE;
    }
    
        // we only allow one handle to the device at a time in this driver
    if (((PSPI_EXT)pContext)->Device[DeviceIndex].OpenCount > 0) {
        DEBUGMSG(TRUE, ("SPI_DRV attempt to open too many handles\n\r"));
        return OS_DRV_NO_DEVICE;
    }
        //initialize the SPI port
    err = SpiInit(pDevice, SPI_DEFAULT_CLOCK);
    
    if (err != OS_DRV_NO_ERR) {
        return err;
    }
    // count the open handles
	((PSPI_EXT)pContext)->Device[DeviceIndex].OpenCount++;
	
	  // return success
	return OS_DRV_NO_ERR;
}
Example #7
0
void main (void)
{
	TTaskHandle xdata A2DTaskHandle, HeaterStatusTaskHandle, HeaterControlTaskHandle;
 	TTaskHandle xdata EdenProtocolTaskHandle, OHDBMessageDecodeTaskHandle;

 	WDTCN = 0xde;               // disable watchdog timer
  	WDTCN = 0xad;

	XBR_Init(); // Initialize cross bars 

    SysClkInit();
	Uart0Init();
	Timer_0_Init();

	SchedulerInit();

	InitCoolingFans(); // Material and UV
 	XilinxWatchdogInit();
 	SpiA2D_Init();
	A2D_Init();
 	SpiInit();
	E2PROMInit();
	XilinxInit();
	OHDBPotenmtrInit();
	Roller_Init();
 	Bumper_Init();
	CommunicationLossTaskInit();
	EdenProtocolInit();
	MessageDecodeInitOHDB();
	HeadData_Init();
 
	EA |= ENABLE;
	
    HeaterControlInit();
	PrintDrv_Init();
	SendWakeUpNotification();
    HeadData_ReadDataFromAllE2PROMs();

	A2DTaskHandle               = SchedulerInstallTask(SpiA2D_Task);
	EdenProtocolTaskHandle      = SchedulerInstallTask(EdenProtocolDecodeTask);
	OHDBMessageDecodeTaskHandle = SchedulerInstallTask(OHDBMessageDecodeTask);
	HeaterStatusTaskHandle      = SchedulerInstallTask(HeaterStatusTask);
	HeaterControlTaskHandle     = SchedulerInstallTask(HeaterControlTask);

	HeaterSetTasksHandles(HeaterStatusTaskHandle, HeaterControlTaskHandle);

	SchedulerResumeTask(GetXilinxWatchdogTaskHandle(),0);
	SchedulerResumeTask(A2DTaskHandle,0);
	SchedulerResumeTask(HeaterStatusTaskHandle,0); 
	SchedulerResumeTask(EdenProtocolTaskHandle,0);
	SchedulerResumeTask(OHDBMessageDecodeTaskHandle,0);
		
 
  	while(1)
  	{ 
	  	SchedulerRun();	
  	} 
}
Example #8
0
/****************************************************
 SpiTsInit
****************************************************/
int SpiTsInit(struct DibBridgeContext *pContext)
{
	int rc;
	rc = SpiInit(pContext);
	if (rc == 0)
	{
    	  SpiTsInitMode(pContext);
	}
	return rc;
}
Example #9
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( );
        }
    }
}
/****************************************************************
*FUNCTION NAME:Init
*FUNCTION     :CC1101 initialization
*INPUT        :none
*OUTPUT       :none
****************************************************************/
void ELECHOUSE_CC1101::Init(void)
{
	SpiInit();										//spi initialization
	GDO_Set();										//GDO set
	digitalWrite(SS_PIN, HIGH);
	digitalWrite(SCK_PIN, HIGH);
	digitalWrite(MOSI_PIN, LOW);
	Reset();										//CC1101 reset
	RegConfigSettings();							//CC1101 register config
	SpiWriteBurstReg(CC1101_PATABLE,PaTabel,8);		//CC1101 PATABLE config
}
Example #11
0
void MCU_Init(void)
{
	RCC_Configuration();
	NVIC_Configuration();
	GPIO_Configuration();
	//TIM2_Configuration();
	SysTick_Init();
	SpiInit();
	USART_Config();
	ADC1_Init();
//	IWDG_Configuration();
}	
Example #12
0
void hw_net_initialize (void)
{
	CC3000_START;
	SpiInit(4e6);
	hw_wait_us(10);

	wlan_init(CC3000_UsynchCallback, NULL, NULL, NULL, ReadWlanInterruptPin,
	WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin);

	wlan_start(0);

	int r = wlan_ioctl_set_connection_policy(0, 0, 0);
	if (r != 0) {
		TM_DEBUG("Fail setting policy %i", r);
	}

	r = wlan_ioctl_set_scan_params(10000, 100, 100, 5, 0x7FF, -100, 0, 205, wifi_intervals);
	if (r != 0) {
		TM_DEBUG("Fail setting scan params %i", r);
	}

	r = wlan_ioctl_set_connection_policy(0, true, true);
	if (r != 0) {
		TM_DEBUG("Fail setting connection policy %i", r);
	}

	wlan_stop();
	hw_wait_ms(10);
	wlan_start(0);

//	tm_sleep_ms(100);
//	TM_COMMAND('w',"setting event mask\n");
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT);
//	TM_COMMAND('w',"done setting event mask\n");

 	unsigned long aucDHCP = 14400;
	unsigned long aucARP = 3600;
	unsigned long aucKeepalive = 10;
	unsigned long aucInactivity = 0;
	if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) {
		TM_DEBUG("Error setting inactivity timeout!");
	}

	unsigned char version[2];
	if (nvmem_read_sp_version(version)) {
		TM_ERR("Failed to read CC3000 firmware version.");
	} 

	memcpy(hw_cc_ver, version, 2);

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

    // Initialize SPI
    SpiInit( );

}
Example #14
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

        /* 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;
    }
}
Example #15
0
/*
 * Initialization code
 */
static drApiResult_t InitSpiDriver(void)
{
    // Nothing to do here now
    drApiResult_t ret = SpiInit();
    //drApiResult_t ret = DRAPI_OK;

    /*
     * TODO: This is the function where certain initialization     
     * can be done before proceeding further. Such as HW related     
     * initialization. Update the return code accordingly     
     */    

    return ret;
}
Example #16
0
void BoardInitMcu( void )
{
    if ( McuInitialized == false ) {
        /* Initialize low level components */
        low_level_init();

        /*! SPI channel to be used by Semtech SX1276 */
#if defined(SX1276_BOARD_EMBED)
        SpiInit(&SX1276.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC);
        SX1276IoInit();
#endif

#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 );
        TimerSetLowPowerEnable(false);
#elif defined(DEBUG)
#if defined(USE_SHELL)
        Shell_Init();
#else
#if !defined(USE_CUSTOM_UART_HAL)
        FifoInit(&Uart1.FifoRx, DbgRxBuffer, DBG_FIFO_RX_SIZE);
        FifoInit(&Uart1.FifoTx, DbgTxBuffer, DBG_FIFO_TX_SIZE);
#endif

        UartInit(&Uart1, UART_1, UART1_TX, UART1_RX);
        UartConfig(&Uart1, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY,
                NO_FLOW_CTRL);
#endif
        DbgConsole_Init(&Uart1);
        TimerSetLowPowerEnable(false);
#elif( LOW_POWER_MODE_ENABLE )
        TimerSetLowPowerEnable(true);
#else
        TimerSetLowPowerEnable(false);
#endif
        BoardUnusedIoInit();

#if !defined(USE_FREE_RTOS)
        if ( TimerGetLowPowerEnable() == true ) {
            RtcInit();
        } else {
            TimerHwInit();
        }
#endif /* USE_FREE_RTOS */

        McuInitialized = true;
    }
}
Example #17
0
//-----------< FUNCTION: LocoMotoInit >--------------------------------------
// Purpose:    locomoto module initialization
// Parameters: none
// Returns:    none
//---------------------------------------------------------------------------
VOID LocoMotoInit ()
{
   // protocol initialization
   sei();
   SpiInit();
   // hardware initialization
   PinSetOutput(PIN_LED);
   ShiftRegInit(
      &(SHIFTREG_CONFIG)
      {
         .nClockPin = PIN_SHIFTREG_CLOCK,
         .nLatchPin = PIN_SHIFTREG_LATCH,
         .nDataPin  = PIN_SHIFTREG_DATA
      }
   );
Example #18
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;
    }
}
Example #19
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( );
        }
    }
}
Example #20
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;
    }
}
Example #21
0
//-----------< 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
      }
   );
Example #22
0
void BoardInit( void )
{
    uint8_t i;

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

    // Initialize SPI
    SpiInit( );
    
    // Initialize LED
    for( i = 0; i < LED_NB; i++ )
    {
        LedInit( ( tLed )i );
    }
		LedOff( LED_RED );
		LedOff( LED_GREEN );
}
Example #23
0
static int SpiMemInit(uint8_t cs, uint16_t *pages, uint16_t *pagesize)
{
    uint8_t fs;
    
    /* Init SPI memory chip select. */
    if (cs == SPIMEM_CS_BIT) {
        cbi(SPIMEM_CS_PORT, cs);
    } else {
        sbi(SPIMEM_CS_PORT, cs);
    }
    sbi(SPIMEM_CS_DDR, cs);
    
    /* Initialize the SPI interface. */
    SpiInit();
    
    /* Read the status register for a rudimentary check. */
    fs = SpiMemStatus(cs);
    if(fs & 0x80) {
        fs = (fs >> 2) & 0x0F;
        *pagesize = 264;
        if(fs == 3) {
            *pages = 512;
            return 0;
        }
        else if(fs == 5) {
            *pages = 1024;
            return 0;
        }
        else if(fs == 7) {
            *pages = 2048;
            return 0;
        }
        else if(fs == 13) {
            *pagesize = 528;
            *pages = 8192;
            return 0;
        }
    }
Example #24
0
/// \classmethod \constructor(spi, pin_cs, pin_en, pin_irq)
/// Initialise the CC3000 using the given SPI bus and pins and return a CC3k object.
//
// Note: pins were originally hard-coded to:
//      PYBv1.0: init(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4, pyb.Pin.board.Y3)
//        [SPI on Y position; Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI]
//
//      STM32F4DISC: init(pyb.SPI(2), pyb.Pin.cpu.A15, pyb.Pin.cpu.B10, pyb.Pin.cpu.B11)
STATIC mp_obj_t cc3k_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
    // check arguments
    mp_arg_check_num(n_args, n_kw, 4, 4, false);

    // set the pins to use
    SpiInit(
        spi_get_handle(args[0]),
        pin_find(args[1]),
        pin_find(args[2]),
        pin_find(args[3])
    );

    // initialize and start the module
    wlan_init(cc3k_callback, NULL, NULL, NULL,
            ReadWlanInterruptPin, SpiResumeSpi, SpiPauseSpi, WriteWlanPin);

    if (wlan_start(0) != 0) {
        nlr_raise(mp_obj_new_exception_msg(
                    &mp_type_OSError, "Failed to init wlan module"));
    }

    // set connection policy. this should be called explicitly by the user
    // wlan_ioctl_set_connection_policy(0, 0, 0);

    // Mask out all non-required events from the CC3000
    wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|
                        HCI_EVNT_WLAN_UNSOL_INIT|
                        HCI_EVNT_WLAN_ASYNC_PING_REPORT|
                        HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE);

    cc3k_obj_t *cc3k = m_new_obj(cc3k_obj_t);
    cc3k->base.type = (mp_obj_type_t*)&mod_network_nic_type_cc3k;

    // register with network module
    mod_network_register_nic(cc3k);

    return cc3k;
}
Example #25
0
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;
	}
}
Example #26
0
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();
        }
    }
}
/*
 Not all the QUPs can be used 
 Number of QUPs available: SPIPD_DEVICE_COUNT in SpiDriver.h
 Config what QUP to use: core\buses\spi\src\config\spi_[chipset].c
*/
int spi_driver_enable(void)
{
   DEBUG_PRINTF("SPI Driver enable...", 0, 0);
   int i, k;
   int success=1;
   uint32 rc;
   spi_transaction_t read_transaction_info;
   spi_transaction_t write_transaction_info;
   uint8 *rd_data = NULL;
   uint8 *wr_data = NULL;
   uint32 TransferCount = 1;
   uint32 APTTEST_SPI_MAX_BUF_SIZE = 10;

   SpiInit();
   // Allocate uncached, physically contiguous buffers
   // for the read and write data
   rd_data = (uint8 *)malloc((uint32)APTTEST_SPI_MAX_BUF_SIZE);
   if (NULL == rd_data)
   {
      //tzt_log("test_spi: Malloc for rd_data failed");
      goto cleanup;
   }
   wr_data = (uint8 *)malloc((uint32)APTTEST_SPI_MAX_BUF_SIZE);
   if (NULL == wr_data)
   {
      //tzt_log("test_spi: Malloc for wr_data failed");
      goto cleanup;
   }

   for (i = 0; i < APTTEST_SPI_MAX_BUF_SIZE; i++)
   {
      wr_data[i] = (uint8)(i + 10);
      rd_data[i] = 1;
   }

   read_transaction_info.buf_virt_addr = (void *)rd_data;
   read_transaction_info.buf_phys_addr = (void *)rd_data; //Vin: figure this out
   read_transaction_info.buf_len = APTTEST_SPI_MAX_BUF_SIZE;

   write_transaction_info.buf_virt_addr = (void *)wr_data;
   write_transaction_info.buf_phys_addr = (void *)wr_data; //Vin: figure this out
   write_transaction_info.buf_len = APTTEST_SPI_MAX_BUF_SIZE;

   rc = spi_open(SPI_DEVICE_5);
   DEBUG_PRINTF("spi_open: %x", rc, 0);

   // Perform a full duplex transfer
   for (k = 0; k < TransferCount; k++)
   {
      rc = spi_full_duplex(SPI_DEVICE_5, &test_spi_config, &write_transaction_info, &read_transaction_info);
      DEBUG_PRINTF("spi_full_duplex: %x", rc, 0);
      // Compare data written and data read back
      for (i = 0; i < APTTEST_SPI_MAX_BUF_SIZE; i++)
      {
         if (rd_data[i] != wr_data[i])
         {
			success = 0;
            break;
         }
      }
   }
   DEBUG_PRINTF("SPI Driver enable...complete? %d", success, 0);
   if (!success) {
     for (i = 0; i < APTTEST_SPI_MAX_BUF_SIZE; i++)
     {
        DEBUG_PRINTF("Read:%d, Write:%d", rd_data[i], wr_data[i])
     }
	 return -1;
   }
   return 0;
cleanup:
   if (NULL != rd_data)
   {
      free(rd_data);
   }
   if (NULL != wr_data)
   {
      free(wr_data);
   }
   return -2;
}
Example #28
0
/*JSON{ "type":"staticmethod", 
         "class" : "WLAN", "name" : "init",
         "generate" : "jswrap_wlan_init",
         "description" : "",
         "params" : [  ]
}*/
void jswrap_wlan_init() {
  SpiInit();
  wlan_init(CC3000_UsynchCallback, sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch, ReadWlanInterruptPin, WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin);
}