Beispiel #1
0
/*----------------------------------------------------------------------------*/
static enum Result adcInit(void *object, const void *configBase)
{
  const struct AdcOneShotConfig * const config = configBase;
  assert(config);

  const struct AdcBaseConfig baseConfig = {
      .frequency = config->frequency,
      .accuracy = 0,
      .channel = config->channel
  };
  struct AdcOneShot * const interface = object;

  /* Call base class constructor */
  const enum Result res = AdcBase->init(interface, &baseConfig);

  if (res == E_OK)
  {
    /* Enable analog function on the input pin */
    interface->pin = adcConfigPin(&interface->base, config->pin);
    /* Calculate Control register value */
    interface->base.control |= CR_START(ADC_SOFTWARE)
        | CR_SEL_CHANNEL(interface->pin.channel);
  }

  return res;
}
/*----------------------------------------------------------------------------*/
#ifndef CONFIG_PLATFORM_NXP_ADC_NO_DEINIT
static void adcDeinit(void *object)
{
  struct AdcOneShot * const interface = object;

  adcReleasePin(interface->pin);
  if (AdcBase->deinit)
    AdcBase->deinit(interface);
}
#endif
/*----------------------------------------------------------------------------*/
static enum Result adcSetCallback(void *object __attribute__((unused)),
    void (*callback)(void *) __attribute__((unused)),
    void *argument __attribute__((unused)))
{
  return E_INVALID;
}
/*----------------------------------------------------------------------------*/
static enum Result adcGetParam(void *object __attribute__((unused)),
    enum IfParameter parameter __attribute__((unused)),
    void *data __attribute__((unused)))
{
  return E_INVALID;
}
/*----------------------------------------------------------------------------*/
static enum Result adcSetParam(void *object __attribute__((unused)),
    enum IfParameter parameter __attribute__((unused)),
    const void *data __attribute__((unused)))
{
  return E_INVALID;
}
/*----------------------------------------------------------------------------*/
static size_t adcRead(void *object, void *buffer, size_t length)
{
  /* Ensure proper alignment of the output buffer length */
  assert((uintptr_t)buffer % 2 == 0);

  if (length < sizeof(uint16_t))
    return 0;

  struct AdcOneShot * const interface = object;

  if (adcSetInstance(interface->base.channel, &interface->base))
  {
    *(uint16_t *)buffer = makeChannelConversion(interface);
    adcResetInstance(interface->base.channel);
    return sizeof(uint16_t);
  }
  else
    return 0;
}
Beispiel #2
0
int main(int argc, char* argv[])
{
	uint32_t tmp = 0;
	uint32_t volatile timing_barrier = 0;

	// we explicitly create the array of CR_CONTEXT structures
	CR_CONTEXT context_array[CONTEXT_ARRAY_CNT];

	// register a cleanup function
	atexit(cleanup);

	// some signal handlers
	if (signal(SIGFPE, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGFPE signal handler.\n");
	} else if (signal( SIGILL, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGILL signal handler.\n");
	} else if (signal( SIGINT, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGINT signal handler.\n");
	} else if (signal( SIGSEGV, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGSEGV signal handler.\n");
	}

	// 1. init the cr library
	assert(((sizeof(context_array) / sizeof(CR_CONTEXT)) == CONTEXT_ARRAY_CNT)
			&& "context_array size mismatch!\n");

	cr_init(context_array, CONTEXT_ARRAY_CNT);

	// 2. register the threads
	cr_register_thread(Thread_A);
	cr_register_thread(Thread_B);
	cr_register_thread(Thread_C);
	cr_register_thread(Thread_D);

	//--------------------------------------------------------------------------
	//-------------------- Simulated ISR Thread Setup --------------------------
	pthread_attr_init(&isr_thread_attr);

	pthread_attr_setschedpolicy(&isr_thread_attr, SCHED_RR);

	pthread_attr_setstacksize(&isr_thread_attr, PTHREAD_STACK_MIN);

// XXX: the scheduling priority could be set here

	pthread_attr_setschedparam(&isr_thread_attr, &isr_thread_sched);

	isr_thread_run = true;

	tmp = pthread_create(&isr_thread_id, &isr_thread_attr, isr_thread, 0);

	assert((tmp == 0) && "pthread_create failed!");

	timing_barrier = 1000;

	// Code block to stop the compiler from messing with the code
	{
		while(timing_barrier--)
			/* no code */ ;
	}
	//--------------------------------------------------------------------------

	// 3. bootstrap the system
	CR_START(cr_idle);

	return EXIT_SUCCESS;
}