void
TaskBlinkNested::threadMain(void)
{
  if (os.isDebug())
    {
      os.sched.lock.enter();
        {
          debug.putString("Thread '");
          debug.putString(getName());
          debug.putString("', led=");
          debug.putDec((unsigned short)m_oLed.bitNumber());
          debug.putString(", divider=");
          debug.putDec((unsigned short)m_rate);
          debug.putNewLine();
        }
      os.sched.lock.exit();
    }

#if !defined(APP_EXCLUDE_TASKBLINKNESTED_TASKMAIN_LED)
  // initialise led port as output
  m_oLed.init();
#endif

  interruptInit();

  bool bSecond;
  bSecond = false;
  // thread endless loop
  for (;;)
    {
#if true
      os.sched.eventWait(APP_CFGINT_TASKBLINKNESTED_EVENT);
#else
      os.sched.yield();
#endif

      os.sched.critical.enter();
        {
          if (m_count >= m_rate)
            {
              m_count -= m_rate;
              bSecond = true;
            }
        }
      os.sched.critical.exit();

      if (bSecond)
        {
          bSecond = false;

          debug.putChar('.');

#if !defined(APP_EXCLUDE_TASKBLINKNESTED_TASKMAIN_LED)
          // finally toggle led
          m_oLed.toggle();
#endif
        }
    }
}
Ejemplo n.º 2
0
static void peripheryInit()
{
    settingPeripheryCLK();
    interruptInit();
    adcCalibrate();
    peripheryClockEnable();
    initGPIO();
}
Ejemplo n.º 3
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();
	setupIO();
	interruptInit();
	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	sei();
	
	while (1)
	{
		
		/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
		CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
void DeviceCAN_AT90CAN::implInit(unsigned char mode)
  {
    OSDeviceDebug::putString_P(PSTR("DeviceCAN_AT90CAN::implInit()"));
    OSDeviceDebug::putNewLine();

    transceiverInit();

    Can_reset();

    interruptInit(); // must be after reset()

    /* CAN_KING setting */
    /* 125K, 75%, Tq=0.5uS, Tbit=16*Tq=8uS */
    /* Tprs=7*Tq, Tph1=4*Tq, Tph2=4*Tq, Tsjw=1*Tq */
    CANBT1 = 0x0E; /* 125K@16MHz */
    CANBT2 = 0x0C;
    CANBT3 = 0x37;

    can_clear_all_mob();

    // enable reception on the reception mob
    Can_set_mob(NB_MOB_RX);
    Can_config_rx();

    // enable both RX and TX mobs
    CANEN2 = _BV(NB_MOB_RX) | _BV(NB_MOB_TX);

    // enable interrupts for both RX and TX mobs
    CANIE2 = _BV(NB_MOB_RX) | _BV(NB_MOB_TX);

    mode = mode; // set to given mode
    Can_enable();

    transceiverHighSpeed();

    //OSDebugLed2::init();

    interruptEnable();

    m_isConnected = true;
  }
Ejemplo n.º 5
0
int main(void) {
	char str_buffer[16];
	SystemCoreClockUpdate();

    gpioInit();
    interruptInit();
    adcInit();

	Chip_PMU_GetSleepFlags(LPC_PMU);
	Chip_PMU_ClearSleepFlags(LPC_PMU, PMU_PCON_DPDFLAG);

    Chip_SPI_Init(SPI_PORT);


    SysTick_Config(Chip_Clock_GetSystemClockRate() / TICKRATE_HZ);

    //StuckI2CHack();
    delayms(10);

    MoonLander_I2C_Init(SENSOR_I2C, MOONLANDER_I2C_100K);

    delayms(100);

    // Initialize sensors:
    HTU21D_Init(&g_HTU21D, SENSOR_I2C);
    delayms(10);
    HMC5883L_Init(&g_HMC5883L, SENSOR_I2C);
    delayms(10);

	HMC5883L_SetRange(&g_HMC5883L, HMC5883L_RANGE_2_5);

    eGFX_InitDriver();
    C12832A_Init(&g_C12832A, SPI_PORT, LCD_A0_PIN, LCD_RST_PIN, LCD_SSEL);
    delayms(10);

    Plot_Init(&g_plot_temp, -10, 40, "Temp (C)", 0);
    Plot_Init(&g_plot_rh, 0, 100, "RH", 0);

    Plot_Init(&g_plot_mag, -400, 300, "uTesla", 1);
    Plot_SetSpecialValue(&g_plot_mag, 9000, "OL");

    Compass_Init(&g_compass);

    g_left_display = DISPLAY_TEMP;
    g_right_display = DISPLAY_COMPASS;

    // Straight to sleep on boot:
    g_go_to_sleep = 1;

    // Or not:
    //g_go_to_sleep = 0;
    //wakeup();

    while(1) {

    	fillScreen(0x0);

    	if (g_go_to_sleep) {

    		// Write the empty back buffer to the screen:
    		eGFX_Dump(&eGFX_BackBuffer, &g_C12832A);

    		g_ignore_switches = 1;
    		// Sleep!
    		goToSleep();

    		// Processor has been woken up, restart clocks, etc.:
    		wakeup();

    		delayms(SW_DEBOUNCE_MS);
    		g_ignore_switches = 0;
    	}

    	switch (g_left_display) {
    	case DISPLAY_TEMP:
    		Plot_Draw(&eGFX_BackBuffer, &g_plot_temp, PLOT_LEFT);
    		break;
    	case DISPLAY_RH:
    		Plot_Draw(&eGFX_BackBuffer, &g_plot_rh, PLOT_LEFT);
    		break;
    	case DISPLAY_MAG:
    		Plot_Draw(&eGFX_BackBuffer, &g_plot_mag, PLOT_LEFT);
    		break;
    	case DISPLAY_COMPASS:
    		Compass_Draw(&eGFX_BackBuffer, &g_compass, COMPASS_LEFT);
    		break;
    	case DISPLAY_RANGE:
    		eGFX_DrawString(&eGFX_BackBuffer, "Range", 24, 1, &FONT_3_5_1BPP);
    		sprintf(str_buffer, "%0.2f cm", getRangeCentimeters());
    		eGFX_DrawString(&eGFX_BackBuffer, str_buffer, 24, 13, &FONT_3_5_1BPP);
    		break;
    	default:
    		break;
    	}

    	switch (g_right_display) {
    	case DISPLAY_TEMP:
    		Plot_Draw(&eGFX_BackBuffer, &g_plot_temp, PLOT_RIGHT);
    		break;
    	case DISPLAY_RH:
    		Plot_Draw(&eGFX_BackBuffer, &g_plot_rh, PLOT_RIGHT);
    		break;
    	case DISPLAY_MAG:
    		Plot_Draw(&eGFX_BackBuffer, &g_plot_mag, PLOT_RIGHT);
    		break;
    	case DISPLAY_COMPASS:
    		Compass_Draw(&eGFX_BackBuffer, &g_compass, COMPASS_RIGHT);
    		break;
    	case DISPLAY_RANGE:
    		eGFX_DrawString(&eGFX_BackBuffer, "Range", 88, 1, &FONT_3_5_1BPP);
    		sprintf(str_buffer, "%0.2f cm", getRangeCentimeters());
    		eGFX_DrawString(&eGFX_BackBuffer, str_buffer, 88, 13, &FONT_3_5_1BPP);
    		break;
    	default:
    		break;
    	}


    	eGFX_Dump(&eGFX_BackBuffer, &g_C12832A);

    }
    return 0 ;
}