コード例 #1
0
/*
  Init the GPIO chip. It also init SPI bus.
	There's a lot of stuff running inside this function, it checks
	for legal pins and SPI bus, can handle alternative SPI bus and pins,
	init correctly SPI bus and only once (in case of multiple instances).
	Parameters
	avoidSpiInit: if you use this library after any other SPI devices
	that already have SPI inited, you may use this option that will avoid SPI.begin().
	Normally you better don't use at all this option...
*/
void gpio_MCP23SXX::begin(bool avoidSpiInit)
{
	if (_chip == MCPNONE) return;//unknow chip
	_readCmd =  (_adrs << 1) | 1;
	_writeCmd = _adrs << 1;
	_gpioDirection	= 0xFFFF;//all inputs
	_gpioState		= 0x0000;//bogus
	gpio_MCP23SXX_instance += 1;//instance counter
	if (gpio_MCP23SXX_instance > 1) avoidSpiInit = true;//do not init SPI again
	#if defined(SPI_LEGACY_METHOD)
	//using internal SPI methods
		if (beginSpi(avoidSpiInit) != 0xFF) return;//if != 0xFF cannot continue
		//set SPI speed...
		#if defined(SPI_HAS_TRANSACTION)
			setSpiSettings(SPISettings(_maxGpioSPIspeed, MSBFIRST, SPI_MODE0));
		#else
			//pre - SPI transaction era...
			SPI.setClockDivider(SPI_CLOCK_DIV4);
			SPI.setBitOrder(MSBFIRST);
			SPI.setDataMode(SPI_MODE0);
		#endif
	#else
	//using high speed external SPI libraries
		#if (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__))
			_spi.postInstance(_cs,255,_mosi,_sclk,_miso);
		#elif (defined(__AVR__) || defined(ESP8266))
			_spi.postInstance(_cs,255);
		#endif
		//begin SPI and set SPI speed...
		#if defined(SPI_HAS_TRANSACTION)
			_spi.begin(SPISettings(_maxGpioSPIspeed, MSBFIRST, SPI_MODE0),avoidSpiInit);
		#else
			_spi.begin(avoidSpiInit);
		#endif
	#endif
/*
The IOCON register!
                 7     6     5   	4      3    2    1      0
MCP23S08 IOCON = NA   NA     SEQOP DISSLW HAEN ODR INTPOL  NA
MCP23S09 IOCON = NA   NA     SEQOP NA     NA   ODR INTPOL  INTCC
MCP23S17 IOCON = BANK MIRROR SEQOP DISSLW HAEN ODR INTPOL  NA
MCP23S18 IOCON = BANK MIRROR SEQOP NA     NA   ODR INTPOL  INTCC
*/
	if (_chip == MCP23S09 || _chip == MCP23S18){
		//these chip doesn't use HAEN
		gpioSetup(_SEQOP | _INTCC);//enable INTCC always
	} else {
		_useHaen == 1 ? gpioSetup(_SEQOP | _HAEN) : gpioSetup(_SEQOP);
	}
	//as default, GPIO init as High-Impedance input
	gpioPinMode(INPUT);
}
コード例 #2
0
ファイル: Lab3_B2.c プロジェクト: ozzieem/UniCpp
int main()
{
	gpioSetup();
	GPIO led_4, led_5;
	led_4 = create(_4, OUT_PIN);
	led_5 = create(_5, OUT_PIN);

	struct sched_param sp, sp2;
	sp.__sched_priority = 80;
	sp2.__sched_priority = 70;

	pthread_t t1, t2;

	pthread_create(&t2, NULL, t2_function, &led_5);
	pthread_setschedparam(t2, SCHED_FIFO, &sp2);

	pthread_create(&t1, NULL, t1_function, &led_4);
	pthread_setschedparam(t1, SCHED_FIFO, &sp);

	pthread_join(t1, NULL);
	pthread_join(t2, NULL);

	destroy(led_4);
	destroy(led_5);
}
コード例 #3
0
ファイル: clock.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Ensure core frequency has been updated */
  SystemCoreClockUpdate();

  /* Init LCD with no voltage boost */
  SegmentLCD_Init(oldBoost);

  /* Setup RTC to generate an interrupt every minute */
  rtcSetup();

  /* Setup GPIO with interrupts to serve the pushbuttons */
  gpioSetup();

  /* Main function loop */
  clockLoop();

  return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: geirivtu/brewHelper
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* Ensure core frequency has been updated */
  SystemCoreClockUpdate();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Init LCD with no voltage boost */
  SegmentLCD_Init(oldBoost);

  /* Setup RTC to generate an interrupt every minute */
  rtcSetup();

  /* Enable GPIO clock */
  CMU_ClockEnable(cmuClock_GPIO, true);

  /* Setup GPIO interrupt to set the time */
  gpioSetup();

  /* Main function loop */
  //clockLoop();

  main_loop();

  return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function of clock example.
 *
 *****************************************************************************/
int main(void)
{  
  EMSTATUS status;
  bool redraw;
  ClockMode_t prevClockMode = CLOCK_MODE_DIGITAL;
  
  /* Chip errata */
  CHIP_Init();

  /* Use the 21 MHz band in order to decrease time spent awake.
     Note that 21 MHz is the highest HFRCO band on ZG. */
  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFRCO  );
  CMU_HFRCOBandSet( cmuHFRCOBand_21MHz );

  /* Setup GPIO for pushbuttons. */
  gpioSetup();

  /* Initialize display module */    
  status = DISPLAY_Init();
  if (DISPLAY_EMSTATUS_OK != status)
    while (true)
      ;

  /* Initialize the DMD module for the DISPLAY device driver. */
  status = DMD_init(0);
  if (DMD_OK != status)
    while (true)
      ;

  status = GLIB_contextInit(&gc);
  if (GLIB_OK != status)
    while (true)
      ;
  
  /* Set PCNT to generate interrupt every second */
  pcntInit();
  
  /* Pre-compte positions for the analog graphics */
  analogClockInitGraphics();

  /* Enter infinite loop that switches between analog and digitcal clock
   * modes, toggled by pressing the button PB0. */
  while (true)
  {    
    redraw = (prevClockMode != clockMode);
    prevClockMode = clockMode;
    if (CLOCK_MODE_ANALOG == clockMode)
    {
      analogClockShow(redraw);
    }
    else
    {
      digitalClockShow(redraw);
    }
    /* Sleep between each frame update */
    EMU_EnterEM2(false);
  }
}
コード例 #6
0
/**
* This is called when the kernel attaches the module.
* This is the first time the class can be expected to have kernel access.
*
* @return 0 on no action, 1 on action, -1 on failure.
*/
int8_t PMU::attached() {
  if (EventReceiver::attached()) {
    gpioSetup();
    cpu_scale(1);
    platform.kernel()->addSchedule(&_periodic_pmu_read);
    _ina219->init();
    return 1;
  }
  return 0;
}
コード例 #7
0
void setupTemperatureSensor(void){
	    
	    gpioSetup();	
	    adcSetup();
	    //initializeMovingAverage(&ma);
    int init_buffer = 0;
		ma.newIndex = 0;
		ma.buffer_length = 0;
		while(init_buffer < DEPTH_D)
		{
			ma.filterBuffer[init_buffer] = 0;
			init_buffer++;
		}
	   
}
コード例 #8
0
ファイル: main.cpp プロジェクト: kairobert/forget-me-not
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  gpioSetup();
  SegmentLCD_Init(false); //init the segment lcd, bool used to check if power supply i low
  rtcSetup();
  leTimerSetup();
  leTimerTurnOff();

  /* Infinite loop */
  while (1) {
	  EMU_EnterEM2(true);
  }
}
コード例 #9
0
ファイル: bootloader.c プロジェクト: AndreMiras/EFM32-Library
/*****************************************************************************
 * Bootloader entry point. 
 *****************************************************************************/
int main(void)
{
  CHIP_Init();
  
  gpioSetup();

  uint32_t pinTest = GPIO_PinInGet(BOOTLOADER_PIN);
  
  /* The bootloader pin is left high, boot normally */
  if ( pinTest ) 
  {
    
    /* Verify firmware before booting */
    if ( isFirmwareValid() ) 
    {
      BOOT_boot();
    } 
    else 
    {
      
      /* Firmware is invalid. Check temp storage */
      if ( USE_TEMP_STORAGE && isTempStorageValid() )
      {
        FLASH_init();
        copyFirmwareFromTempStorage();
        markFirmwareAsVerified();
        
        /* Application will boot after reset */
        NVIC_SystemReset();
      }
      
      /* No valid application is present. Enter bootloader mode. */
      else 
      {
        enterBootloaderMode();
      }
    }
  } 
  /* The bootloader pin is pulled high, enter bootloader */
  else 
  {
    enterBootloaderMode();
  }
  
  /* Never reached */
  return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: D-Jack/EFM32LG_STK3600
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize gpio */
  gpioSetup();

  /* Initialize LED driver */
  BSP_LedsInit();

  /* Infinite loop */
  while (1);
}
コード例 #11
0
ファイル: Lab3_B1.c プロジェクト: ozzieem/UniCpp
int main()
{
	gpioSetup();
	GPIO led_4, led_5;
	led_4 = create(_4, OUT_PIN);
	led_5 = create(_5, OUT_PIN);

	pthread_t t1, t2;

	pthread_create(&t1, NULL, t1_function, &led_4);
	pthread_create(&t2, NULL, t2_function, &led_5);

	pthread_join(t1, NULL);
	pthread_join(t2, NULL);

	destroy(led_4);
	destroy(led_5);
}
コード例 #12
0
ファイル: Lab2_A1.c プロジェクト: ozzieem/UniCpp
int main(int argc, char *argv[])
{
	gpioSetup();
	GPIO led_4 = create(_4, OUT_PIN);
	struct timespec lightOn, lightOff;

	lightOn.tv_sec = 0;
	lightOff.tv_sec = 0;
	lightOn.tv_nsec = 20000000L;
	lightOff.tv_nsec = 20000000L;

	for (int i = 0; i < 100; i++)
	{
		onOff(led_4, ON);
		nanosleep(&lightOn, NULL);
		onOff(led_4, OFF);
		nanosleep(&lightOff, NULL);
	}
	destroy(led_4);
	return 0;
}
コード例 #13
0
ファイル: main.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint32_t j;
  
  /* Chip errata */
  CHIP_Init();

  /* Select clock source for HF clock. */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
  
  /* Prescale the core clock -> HF/4 = 32/4 = 8Mhz */
  CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_4);

  /* Configure push button interrupts. */
  gpioSetup();
  
  /* configure SWO output for debugging. */
  setupSWO();
  
  /* Init Segment LCD without boost. */
  SegmentLCD_Init(false);

  /* Turn on relevant symbols on the LCD. */
  SegmentLCD_Symbol(LCD_SYMBOL_GECKO, true);

  /* Print welcome text on the LCD. */
  SegmentLCD_Write("HiJack");

  /* Init the HiJack interface. */
  HIJACK_Init(NULL);
  
  /* While loop sending a range of values upon wakeup.  */
  while(1){    
    for(j = 0;j<254;j++){
      HIJACK_ByteTx(j);
      Delay(10000);
    }
    
  }   
}
コード例 #14
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Ensure core frequency has been updated */
  SystemCoreClockUpdate();

  /* Initialize capsense */
  CAPLESENSE_Init(true);

  /* Initialize GPIO interrupts */
  gpioSetup();

  /* Start capsense demo. */
  capSenseDemo();

  return 0;
}
コード例 #15
0
int main () {

    if (gpioSetup() != OK)
    {
        dbgPrint(DBG_INFO, "gpioSetup failed. Exiting\n");
        return 1;
    }


    seq_handle = open_seq();
	connect2MidiThroughPort(seq_handle);

    init_cmd_defaults();

    while (1) {
	midi_read();
    }

    snd_seq_close (seq_handle);
	gpioCleanup();
    return (0);
}
コード例 #16
0
ファイル: userpage.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize LCD controller without boost */
  SegmentLCD_Init(false);

  /* Disable all segments */
  SegmentLCD_AllOff();

  /* Copy contents of the userpage (flash) into the userData struct */
  memcpy((void *) &userData, (void *) USERPAGE, sizeof(UserData_TypeDef));

  /* Special case for uninitialized data */
  if (userData.number > 10000)
    userData.number = 0;
  if (userData.numWrites == 0xFFFFFFFF)
    userData.numWrites = 0;

  /* Display the number */
  SegmentLCD_Number(userData.number);

  /* Setup GPIO interrupts. PB0 to increase number, PB1 to save to flash */
  gpioSetup();

  /* No save has occured yet */
  recentlySaved = false;

  /* Main loop - just scroll informative text describing the current state of
   * the system */
  while (1)
  {
    switch (currentError)
    {
    case mscReturnInvalidAddr:
      ScrollText("     ERROR: INVALID ADDRESS      ");
      break;
    case mscReturnLocked:
      ScrollText("     ERROR: USER PAGE IS LOCKED      ");
      break;
    case mscReturnTimeOut:
      ScrollText("     ERROR: TIMEOUT OCCURED      ");
      break;
    case mscReturnUnaligned:
      ScrollText("     ERROR: UNALIGNED ACCESS     ");
    default:
      if (recentlySaved)
      {
        recentlySaved = false;
        SegmentLCD_Number(userData.numWrites);
        ScrollText("     SAVE NUMBER       ");
      }
      else
      {
        SegmentLCD_Number(userData.number);
        ScrollText("     PRESS PB0 TO INCREASE NUMBER. PB1 TO SAVE TO INTERNAL FLASH        ");
      }
      break;
    }
  }
}
コード例 #17
0
ファイル: emode.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  const int msDelay = 100;

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

    /* Power down special RAM blocks to reduce current consumption with some nA. */
  CMU_ClockEnable(cmuClock_CORELE, true);
  LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
  CMU_ClockEnable(cmuClock_CORELE, false);

  /* Configure push button interrupts */
  gpioSetup();

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClockGet() / 1000)) while (1) ;

  /* Initialize LCD controller */
  SegmentLCD_Init(false);

  /* Run countdown for user to select energy mode */
  msCountDown = 4000; /* milliseconds */
  while (msCountDown > 0)
  {
    switch (eMode)
    {
    case 0:
      SegmentLCD_Write("EM0 32M");
      break;
    case 1:
      SegmentLCD_Write("EM1 32M");
      break;
    case 2:
      SegmentLCD_Write("EM2 32K");
      break;
    case 3:
      SegmentLCD_Write("EM3");
      break;
    case 4:
      SegmentLCD_Write("EM4");
      break;
    case 5:
      SegmentLCD_Write("EM2+RTC");
      break;
    case 6:
      SegmentLCD_Write("RTC+LCD");
      break;
    case 7:
      SegmentLCD_Write("EM3+RTC");
      break;
    case 8:
      SegmentLCD_Write("USER");
      break;
    }
    SegmentLCD_Number(msCountDown);
    Delay(msDelay);
    msCountDown -= msDelay;
  }
  /* Disable components, reenable when needed */
  SegmentLCD_Disable();
  RTC_Enable(false);

  /* GPIO->ROUTE = 0x00000000; */

  /* Go to energy mode and wait for reset */
  switch (eMode)
  {
  case 0:
    /* Disable pin input */
    GPIO_PinModeSet(gpioPortB, 10, gpioModeDisabled, 1);

    /* Disable systick timer */
    SysTick->CTRL = 0;

    /* 32Mhz primes demo - running off HFXO */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    /* Disable HFRCO, LFRCO and all unwanted clocks */
    CMU->OSCENCMD     = CMU_OSCENCMD_HFRCODIS;
    CMU->OSCENCMD     = CMU_OSCENCMD_LFRCODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    CMU->LFCLKSEL     = 0x00000000;
    /* Supress Conditional Branch Target Prefetch */
    MSC->READCTRL = MSC_READCTRL_MODE_WS1SCBTP;
    {
      #define PRIM_NUMS    64
      uint32_t i, d, n;
      uint32_t primes[PRIM_NUMS];

      /* Find prime numbers forever */
      while (1)
      {
        primes[0] = 1;
        for (i = 1; i < PRIM_NUMS;)
        {
          for (n = primes[i - 1] + 1;; n++)
          {
            for (d = 2; d <= n; d++)
            {
              if (n == d)
              {
                primes[i] = n;
                goto nexti;
              }
              if (n % d == 0) break;
            }
          }
 nexti:
          i++;
        }
      }
    }
  case 1:
    /* Disable pin input */
    GPIO_PinModeSet(gpioPortB, 10, gpioModeDisabled, 1);

    /* Disable systick timer */
    SysTick->CTRL = 0;

    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    /* Disable HFRCO, LFRCO and all unwanted clocks */
    CMU->OSCENCMD     = CMU_OSCENCMD_HFRCODIS;
    CMU->OSCENCMD     = CMU_OSCENCMD_LFRCODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    CMU->LFCLKSEL     = 0x00000000;
    EMU_EnterEM1();
    break;
  case 2:
    /* Enable LFRCO */
    CMU->OSCENCMD = CMU_OSCENCMD_LFRCOEN;
    /* Disable everything else */
    CMU->OSCENCMD     = CMU_OSCENCMD_LFXODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    /* Disable LFB clock select */
    CMU->LFCLKSEL     = 0x00000000;
    EMU_EnterEM2(false);
    break;
  case 3:
    /* Disable all clocks */
    CMU->OSCENCMD     = CMU_OSCENCMD_LFXODIS;
    CMU->OSCENCMD     = CMU_OSCENCMD_LFRCODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    CMU->LFCLKSEL     = 0x00000000;
    EMU_EnterEM3(false);
    break;
  case 4:
    /* Go straight down to EM4 */
    EMU_EnterEM4();
    break;
  case 5:
    /* EM2 + RTC - only briefly wake up to reconfigure every 2 seconds */
    /* Disable LFB clock select */
    CMU->LFCLKSEL     &= ~(_CMU_LFCLKSEL_LFB_MASK);
    RTCDRV_Setup(cmuSelect_LFRCO, cmuClkDiv_32);
    while (1)
    {
      RTCDRV_Trigger(2000, NULL);
      EMU_EnterEM2(false);
    }
  case 6:
    /* EM2 + RTC + LCD (if battery slips below 3V vboost should be enabled) */
    /* Disable LFB clock select */
    CMU->LFCLKSEL     &= ~(_CMU_LFCLKSEL_LFB_MASK);
    SegmentLCD_Init(false);
    RTCDRV_Setup(cmuSelect_LFRCO, cmuClkDiv_32);
    while (1)
    {
      SegmentLCD_Write("Silicon");
      /* Sleep in EM2 */
      RTCDRV_Trigger(2000, NULL);
      EMU_EnterEM2(false);

      SegmentLCD_Write(" Labs");
      /* Sleep in EM2 */
      RTCDRV_Trigger(2000, NULL);
      EMU_EnterEM2(false);
    }
  case 7:
    /* EM3 + RTC - only briefly wake up to reconfigure every ~5 seconds */
    while (1)
    {
      /* Disable LFB clock select */
      CMU->LFCLKSEL     &= ~(_CMU_LFCLKSEL_LFB_MASK);
      /* This RTCDRV_Setup will configure LFCLK A as ULFRCO */
      RTCDRV_Setup(cmuSelect_ULFRCO, cmuClkDiv_1);
      RTCDRV_Trigger(5000, NULL);
      /* Sleep in EM3, wake up on RTC trigger */
      EMU_EnterEM3(false);
      /* SegmentLCD_Init will configure LFCLK A as LFRCO */
      SegmentLCD_Init(false);
      SegmentLCD_Write("ULFRCO");
      Delay(1000);
      SegmentLCD_Disable();
    }
  case 8:
  default:
    /* User defined */
    break;
  }

  return 0;
}
コード例 #18
0
ファイル: main.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  unsigned char pucMACArray[8];
  uint32_t      temp;

  /* Chip revision alignment and errata fixes */
  CHIP_Init();

  /* Ensure core frequency has been updated */
  SystemCoreClockUpdate();
  CMU_ClockEnable(cmuClock_ADC0, true);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClock / 1000)) while (1) ;

  /* Setup ADC for sampling internal temperature sensor. */
  setupSensor();

  /* Spi init*/
  spiInit();


#if LWIP_DHCP
  /* Initialze the lwIP library, using DHCP.*/
  lwIPInit(pucMACArray, 0, 0, 0, IPADDR_USE_DHCP);
#else
  /* Initialze the lwIP library, using Static IP.*/
  lwIPInit(pucMACArray, IPADDR(192, 168, 79, 160), IPADDR(255, 255, 255, 0), \
           IPADDR(192, 168, 79, 1), IPADDR_USE_STATIC);
#endif

  /* Initialize a sample httpd server.*/
  httpd_init();

  /* Start one ADC sample */
  ADC_Start(ADC0, adcStartSingle);

  /* Enable board control interrupts */
  gpioSetup();

  axspi_write_reg(~IMR_RXPKT, P0_IMR);

  /* Start LCD  without boost */
  SegmentLCD_Init(false);

  CMU_ClockEnable(cmuClock_RTC, true);
  /* RTC configuration structure */
  RTC_Init_TypeDef rtcInit = {
    .enable   = false,
    .debugRun = false,
    .comp0Top = true
  };

  /* Initialize RTC */
  RTC_Init(&rtcInit);

  /* Set COMP0 value which will be the top value as well */
  RTC_CompareSet(RTC_COMP, RTC_COMP_VALUE);

  /* Clear all pending interrupts */
  RTC_IntClear(0x7);

  /* Enable COMP0 interrupts */
  RTC_IntEnable(0x2);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);

  RTC_Enable(true);

  while (1)
  {
    /* check temperature flag*/
    if (read_temperature)
    {
      temp = ADC_DataSingleGet(ADC0);

      /* Show Celsius on numeric part of display */
      temperature = (int)(convertToCelsius(temp));

      /* Start a new conversion */
      ADC_Start(ADC0, adcStartSingle);

      /* Reset temperature flag */
      read_temperature = 0;
    }

    if (updateIpFlag)
    {
      switch (ip_field)
      {
      case 1:
      {
        SegmentLCD_Write(IP_ADDR_FIRST_TEXT);
        SegmentLCD_Number(IP_ADDR_FIRST_NUM(lwip_netif.ip_addr.addr));
        ip_field++;
      }
      break;

      case 2:
      {
        SegmentLCD_Write(IP_ADDR_SECOND_TEXT);
        SegmentLCD_Number(IP_ADDR_SECOND_NUM(lwip_netif.ip_addr.addr));
        ip_field++;
      }
      break;

      case 3:
      {
        SegmentLCD_Write(IP_ADDR_THIRD_TEXT);
        SegmentLCD_Number(IP_ADDR_THIRD_NUM(lwip_netif.ip_addr.addr));
        ip_field++;
      }
      break;

      case 4:
      {
        SegmentLCD_Write(IP_ADDR_FOURTH_TEXT);
        SegmentLCD_Number(IP_ADDR_FOURTH_NUM(lwip_netif.ip_addr.addr));
        ip_field = 1;
      }
      break;

      default: break;
      }

      updateIpFlag = false;
    }
  }
}
コード例 #19
0
ファイル: emode.c プロジェクト: EnergyMicro/EFM32_Gxxx_STK
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int msCountDown;
  const int msDelay = 100;
  char displayString[8];
  LCD_AnimInit_TypeDef anim = {
    true,
    0x00,
    lcdAnimShiftNone,
    0x03,
    lcdAnimShiftLeft,
    lcdAnimLogicOr
  };
  LCD_FrameCountInit_TypeDef fc = {
    true,
    2, /* Update each 2nd frame */
    lcdFCPrescDiv1,
  };

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Configure push button interrupts */
  gpioSetup();

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClockGet() / 1000)) while (1) ;

  /* Initialize LCD controller */
  SegmentLCD_Init(false);

  /* Run countdown for user to select energy mode */
  msCountDown = 4000; /* milliseconds */
  while(msCountDown > 0)
  {
    if ( eMode >=3 && eMode<=4) {
      sprintf(displayString, "EM%d", eMode);
      SegmentLCD_Write(displayString);
    }
    switch( eMode )
    {
    case 0:
      SegmentLCD_Write("EM0 32M");
      break;
    case 1:
      SegmentLCD_Write("EM1 32M");
      break;
    case 2:
      SegmentLCD_Write("EM2 32K");
      break;
    case 5:
      SegmentLCD_Write("EM2+RTC");
      break;
    case 6:
      SegmentLCD_Write("RTC+LCD");
      break;
    }
    SegmentLCD_Number(msCountDown);
    Delay(msDelay);
    msCountDown -= msDelay;
  }
  /* Disable components, reenable when needed */
  SegmentLCD_Disable();
  RTC_Enable(false);

  /* Go to energy mode and wait for reset */
  switch(eMode)
  {
  case 0:
    /* Disable pin input */
    GPIO_PinModeSet(gpioPortB, 10, gpioModeDisabled, 1);

    /* Disable systick timer */
    SysTick->CTRL  = 0;

    /* 32Mhz primes demo - running off HFXO */
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    /* Disable HFRCO, LFRCO and all unwanted clocks */
    CMU->OSCENCMD = CMU_OSCENCMD_HFRCODIS;
    CMU->OSCENCMD = CMU_OSCENCMD_LFRCODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    CMU->LFCLKSEL     = 0x00000000;
    /* Supress Conditional Branch Target Prefetch */
    MSC->READCTRL = MSC_READCTRL_MODE_WS1SCBTP;
    {
      #define PRIM_NUMS 64
      uint32_t i, d, n;
      uint32_t primes[PRIM_NUMS];

      /* Find prime numbers forever */
      while (1)
      {
        primes[0] = 1;
        for (i = 1; i < PRIM_NUMS;)
        {
          for (n = primes[i - 1] + 1; ;n++)
          {
            for (d = 2; d <= n; d++)
            {
              if (n == d)
              {
                primes[i] = n;
                goto nexti;
              }
              if (n%d == 0) break;
            }
          }
        nexti:
          i++;
        }
      }
    }
  case 1:
    /* Disable pin input */
    GPIO_PinModeSet(gpioPortB, 10, gpioModeDisabled, 1);

    /* Disable systick timer */
    SysTick->CTRL  = 0;

    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    /* Disable HFRCO, LFRCO and all unwanted clocks */
    CMU->OSCENCMD = CMU_OSCENCMD_HFRCODIS;
    CMU->OSCENCMD = CMU_OSCENCMD_LFRCODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    CMU->LFCLKSEL     = 0x00000000;
    EMU_EnterEM1();
    break;
  case 2:
    /* Enable LFRCO */
    CMU->OSCENCMD = CMU_OSCENCMD_LFRCOEN;
    /* Disable everything else */
    CMU->OSCENCMD = CMU_OSCENCMD_LFXODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    CMU->LFCLKSEL     = 0x00000000;
    EMU_EnterEM2(false);
    break;
  case 3:
    /* Disable all clocks */
    CMU->OSCENCMD = CMU_OSCENCMD_LFXODIS;
    CMU->OSCENCMD = CMU_OSCENCMD_LFRCODIS;
    CMU->HFPERCLKEN0  = 0x00000000;
    CMU->HFCORECLKEN0 = 0x00000000;
    CMU->LFACLKEN0    = 0x00000000;
    CMU->LFBCLKEN0    = 0x00000000;
    EMU_EnterEM3(false);
    break;
  case 4:
    EMU_EnterEM4();
    break;
  case 5:
    /* EM2 + RTC - only briefly wake up to reconfigure each second */
    CMU->LFCLKSEL     = CMU_LFCLKSEL_LFA_LFRCO;
    while(1)
    {
      RTCDRV_Trigger(2000, NULL);
      EMU_EnterEM2(false);
    }
  case 6:
  default:
    /* EM2 + RTC + LCD (if battery slips below 3V vboost should be */
    /* enabled) */
    CMU->LFCLKSEL     = CMU_LFCLKSEL_LFA_LFRCO;
    SegmentLCD_Init(false);
    /* Animate LCD */
    LCD_FrameCountInit(&fc);
    LCD_AnimInit(&anim);
    while(1)
    {
      SegmentLCD_Write("Energy");
      /* Sleep in EM2 */
      RTCDRV_Trigger(2000,NULL);
      EMU_EnterEM2(false);

      SegmentLCD_Write("Micro");
      /* Sleep in EM2 */
      RTCDRV_Trigger(2000,NULL);
      EMU_EnterEM2(false);
    }
  }

  return 0;
}
コード例 #20
0
ファイル: inttemp.c プロジェクト: SiliconLabs/Gecko_SDK
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint8_t prod_rev;
  char string[8];
  int i;

  uint32_t temp;
  uint32_t temp_offset;

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Enable peripheral clocks */
  CMU_ClockEnable(cmuClock_HFPER, true);
  CMU_ClockEnable(cmuClock_ADC0, true);

  /* Initialize RTC timer. */
  RTCDRV_Init();
  RTCDRV_AllocateTimer( &xTimerForWakeUp);

  /* Initialize LCD controller without boost */
  SegmentLCD_Init(false);
  SegmentLCD_AllOff();

  /* This is a work around for Chip Rev.D Errata, Revision 0.6. */
  /* Check for product revision 16 and 17 and set the offset */
  /* for ADC0_TEMP_0_READ_1V25. */
  prod_rev = (DEVINFO->PART & _DEVINFO_PART_PROD_REV_MASK) >> _DEVINFO_PART_PROD_REV_SHIFT;

  if( (prod_rev == 16) || (prod_rev == 17) )
  {
      temp_offset = 112;
  }
  else
  {
      temp_offset = 0;
  }

  /* Enable board control interrupts */
  gpioSetup();

  /* Setup ADC for sampling internal temperature sensor. */
  setupSensor();

  /* Main loop - just read temperature and update LCD */
  while (1)
  {

    /* Start one ADC sample */
    ADC_Start(ADC0, adcStartSingle);

    /* Wait in EM1 for ADC to complete */
    EMU_EnterEM1();

    /* Read sensor value */
    /* According to rev. D errata ADC0_TEMP_0_READ_1V25 should be decreased */
    /* by the offset  but it is the same if ADC reading is increased - */
    /* reference manual 28.3.4.2. */
    temp = ADC_DataSingleGet(ADC0) + temp_offset;

    /* Convert ADC sample to Fahrenheit / Celsius and print string to display */
    if (showFahrenheit)
    {
      /* Show Fahrenheit on alphanumeric part of display */
      i = (int)(convertToFahrenheit(temp) * 10);
      snprintf(string, 8, "%2d,%1d%%F", (i/10), abs(i%10));
      /* Show Celsius on numeric part of display */
      i = (int)(convertToCelsius(temp) * 10);
      SegmentLCD_Number(i*10);
      SegmentLCD_Symbol(LCD_SYMBOL_DP10, 1);
      SegmentLCD_Symbol(LCD_SYMBOL_DEGC, 1);
      SegmentLCD_Symbol(LCD_SYMBOL_DEGF, 0);
   }
    else
    {
      /* Show Celsius on alphanumeric part of display */
      i = (int)(convertToCelsius(temp) * 10);
      snprintf(string, 8, "%2d,%1d%%C", (i/10), abs(i%10));
      /* Show Fahrenheit on numeric part of display */
      i = (int)(convertToFahrenheit(temp) * 10);
      SegmentLCD_Number(i*10);
      SegmentLCD_Symbol(LCD_SYMBOL_DP10, 1);
      SegmentLCD_Symbol(LCD_SYMBOL_DEGC, 0);
      SegmentLCD_Symbol(LCD_SYMBOL_DEGF, 1);
    }
    SegmentLCD_Write(string);

    /* Sleep for 2 seconds in EM 2 */
    RTCDRV_StartTimer( xTimerForWakeUp, rtcdrvTimerTypeOneshot, 2000, NULL, NULL);
    EMU_EnterEM2(true);
  }
}
コード例 #21
0
int main(int argc, char **argv)
{
    /// interval cannot be more that 999
    int interval= RDS_PACKET_INTERVAL *NANOSEC_PER_MILLISEC;
    Mode mode;
    mode = transmit;
    int cmd_option;

    // Parse Options
    while((cmd_option=getopt(argc, argv, "i:m")) != EOF)
        switch(cmd_option)
        {
            default: 
            case 'i': interval=atoi(optarg)*NANOSEC_PER_MILLISEC; break;
            case 'm': mode=testing; break; // really just for me when not using transmitter

        }
    
    if(mode==transmit)
    {
        if (gpioSetup() != OK)
        {
            dbgPrint(DBG_INFO, "gpioSetup failed. Exiting\n");
            return 1;
        }

        LS_CMD(10,0xffff,0);
        sleep(1);
        LS_CMD(10,0xffff,0);
        sleep(1);
        RDS_CONFIG();
        sleep(1);
        RDS_ENABLE_UDG1();
        sleep(1);
    }
    


    struct itimerspec timspec;
    bzero(&timspec, sizeof(timspec));
    timspec.it_interval.tv_sec = 0;
    timspec.it_interval.tv_nsec = interval;
    timspec.it_value.tv_nsec =1;

    int timerfd = timerfd_create(CLOCK_MONOTONIC,0);
    timerfd_settime(timerfd, 0, &timspec, 0);

    struct pollfd ufds;
    ufds.fd = timerfd;
    ufds.events = POLLIN;
    uint64_t loopcount=0;
    int rv;

    uint32_t fake_data=0;
    for(;;)
    {
        rv = poll(&ufds,1,5); // 5 sec timeout....
        
        if (rv == -1) 
        {
            perror("poll"); // error occurred in poll()
        } else if (rv == 0) 
        {
            // Do Nothing 

        } else 
        {
            if (ufds.revents & POLLIN)
            {
                read(timerfd, &loopcount, sizeof(uint64_t)); // reset Time
                if(mode==transmit)
                {
                    LS_RAW(20,fake_data,0);
                } else {fprintf(stderr,"RDS COMMAND \n");}

                fake_data++;
                                
            }
        }
    }

    return 0;
}