示例#1
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  struct DeviceDriver device;

  struct Interface * const i2c = init(I2c, &i2cConfig);
  assert(i2c);

  deviceInit(&device, i2c, LED_PIN, DEVICE_ADDRESS);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    deviceWrite(&device);

    while (!event)
      barrier();
    event = false;

    deviceRead(&device);
  }

  return 0;
}
示例#2
0
/**
* \fn		U8 realTimeInit(U32 tickPeriod)
* @brief	Initialised the Real-Time system to a specified sysTick period
* @note		Intensive Computation, used only at init time.
*			Keep the value between 100 and 64 535 000 to be accurate and useful
*			Use the Hardware Timer 1
*			Use a dividable number by 1000 to assure precision of the software rtcc
* @arg		U32 tickPeriod		Desired period of a sysTick (in µs)
* @return	U8 errorCode		STD Error Code (return STD_EC_SUCCESS if successful)
*/
U8 realTimeInit(U32 tickPeriod)
{
	// -- Init and set the Timer 1 -- //
	timerInit(RT_TIMER_ID,TMR_CS_PBCLK|TMR_FRZ_STOP);		//Timer 1 is based off PBCLK (and freezed in debug mode)
	timerSetOverflow(RT_TIMER_ID,tickPeriod);			//Set the overflow time to the desired sysTick period
	intFastSetPriority(RT_TIMER_INT_ID,7);				//Set the Timer 1 interrupt to max priority
	intFastSetSubPriority(RT_TIMER_INT_ID,3);
	intFastEnable(RT_TIMER_INT_ID);					//Enable Timer 1 interrupt
	// ------------------------------ //

	sysTickValue = tickPeriod;					//Save the tick period in µs

	// -- Init the soft rtcc if needed -- //
	#if RTCC_SYSTEM == RTCC_SOFTWARE
	rtTimeClear(&rtccTime);
	#endif
	// ---------------------------------- //

	// -- Reset the up-time -- //
	rtTimeClear(&upTime);
	// ----------------------- //
	
	//Start the timer
	timerStart(RT_TIMER_ID);

	return STD_EC_SUCCESS;
}
示例#3
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const adc = init(AdcOneShot, &adcConfig);
  assert(adc);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinSet(led);

    uint16_t voltage;
    const size_t bytesRead = ifRead(adc, &voltage, sizeof(voltage));
    assert(bytesRead == sizeof(voltage));
    (void)bytesRead; /* Suppress warning */

    pinReset(led);
  }

  return 0;
}
示例#4
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  static const char separator[] = "-----------------------\r\n";

  struct Interface * const ow = init(OneWireSsp, &owConfig);
  assert(ow);

  struct Interface * const serial = init(Serial, &serialConfig);
  assert(serial);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 2000);

  bool busEvent = false;
  ifSetCallback(ow, onBusEvent, &busEvent);

  bool timerEvent = false;
  timerSetCallback(timer, onTimerOverflow, &timerEvent);
  timerEnable(timer);

  while (1)
  {
    while (!timerEvent)
      barrier();
    timerEvent = false;

    enum Result res;

    res = ifSetParam(ow, IF_ONE_WIRE_START_SEARCH, 0);
    assert(res == E_OK);

    do
    {
      while (!busEvent)
        barrier();
      busEvent = false;

      res = ifGetParam(ow, IF_STATUS, 0);
      if (res != E_OK)
        break;

      uint64_t address;

      res = ifGetParam(ow, IF_ADDRESS, &address);
      assert(res == E_OK);

      printAddress(serial, address);
    }
    while (ifSetParam(ow, IF_ONE_WIRE_FIND_NEXT, 0) == E_OK);

    ifWrite(serial, separator, sizeof(separator) - 1);
  }

  return 0;
}
示例#5
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const adc = init(AdcDma, &adcConfig);
  assert(adc);
  ifSetCallback(adc, onConversionCompleted, adc);

  struct Timer * const conversionTimer = init(GpTimer, &timerConfig);
  assert(conversionTimer);
  /*
   * The overflow frequency of the timer should be two times higher
   * than that of the hardware events for ADC.
   */
  timerSetOverflow(conversionTimer, timerConfig.frequency / (ADC_RATE * 2));

  unsigned int iteration = 0;
  size_t count;

  /* Enqueue buffers */
  while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0)
  {
    const size_t index = iteration++ % BUFFER_COUNT;
    ifRead(adc, buffers[index], sizeof(buffers[index]));
  }

  /* Start conversion */
  timerEnable(conversionTimer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinSet(led);
    while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0)
    {
      const size_t index = iteration++ % BUFFER_COUNT;
      ifRead(adc, buffers[index], sizeof(buffers[index]));
    }
    pinReset(led);
  }

  return 0;
}
示例#6
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, true);

  struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit, &pwmUnitConfig);
  assert(pwmUnit);
  struct Pwm * const pwmOutput = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN);
  assert(pwmOutput);
  pwmSetDuration(pwmOutput, pwmGetResolution(pwmOutput) / 2);

  struct Timer * const counter = init(GpTimerCounter, &counterConfig);
  assert(counter);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);

  timerEnable(counter);
  pwmEnable(pwmOutput);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    const uint32_t period = timerGetValue(counter);
    timerSetValue(counter, 0);

    if (period >= 999 && period <= 1001)
      pinReset(led);
    else
      pinSet(led);
  }

  return 0;
}
示例#7
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  /* Initialize peripherals */
  struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Timer * const timer = init(SysTickTimer, 0);
  assert(timer);
  timerSetOverflow(timer, timerGetFrequency(timer) / 2);
  timerSetCallback(timer, onTimerOverflow, &led);

  /* Initialize Work Queue */
  workQueueInit(WORK_QUEUE_SIZE);

  /* Start event generation and queue handler */
  timerEnable(timer);
  workQueueStart(0);

  return 0;
}
示例#8
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, true);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 500);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinToggle(led);
  }

  return 0;
}