Exemplo n.º 1
0
/*
 * MPC5x00 MSCAN device initialization
 */
rtems_device_driver mscan_initialize(rtems_device_major_number major,
                                     rtems_device_minor_number minor, void *arg)
{
  rtems_status_code status;

  /* Initialization requested via RTEMS */
  if ((status = mscan_channel_initialize(major, MSCAN_A)) != RTEMS_SUCCESSFUL)
    bsp_fatal(MPC5200_FATAL_MSCAN_A_INIT);

  if ((status = mscan_channel_initialize(major, MSCAN_B)) != RTEMS_SUCCESSFUL)
    bsp_fatal(MPC5200_FATAL_MSCAN_B_INIT);

  if ((status =
       mpc5200_mscan_set_mode(MSCAN_A,
                              MSCAN_INIT_NORMAL_MODE)) != RTEMS_SUCCESSFUL)
    bsp_fatal(MPC5200_FATAL_MSCAN_A_SET_MODE);

  if ((status =
       mpc5200_mscan_set_mode(MSCAN_B,
                              MSCAN_INIT_NORMAL_MODE)) != RTEMS_SUCCESSFUL)
    bsp_fatal(MPC5200_FATAL_MSCAN_B_SET_MODE);

  return status;

}
Exemplo n.º 2
0
static void mpc55xx_clock_initialize(void)
{
  volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
  union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS;
  union EMIOS_CSR_tag csr = MPC55XX_ZERO_FLAGS;
  unsigned prescaler = mpc55xx_emios_global_prescaler();
  uint64_t reference_clock = bsp_clock_speed;
  uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
  uint64_t interval = (reference_clock * us_per_tick) / 1000000;

  /* Apply prescaler */
  if (prescaler > 0) {
    interval /= (uint64_t) prescaler;
  } else {
    bsp_fatal(MPC55XX_FATAL_CLOCK_EMIOS_PRESCALER);
  }

  /* Check interval */
  if (interval == 0 || interval > MPC55XX_EMIOS_VALUE_MAX) {
    bsp_fatal(MPC55XX_FATAL_CLOCK_EMIOS_INTERVAL);
  }

  /* Configure eMIOS channel */

  /* Set channel in GPIO mode */
  ccr.B.MODE = MPC55XX_EMIOS_MODE_GPIO_INPUT;
  regs->CCR.R = ccr.R;

  /* Clear status flags */
  csr.B.OVR = 1;
  csr.B.OVFL = 1;
  csr.B.FLAG = 1;
  regs->CSR.R = csr.R;

  /* Set internal counter start value */
  regs->CCNTR.R = 1;

  /* Set timer period */
  regs->CADR.R = (uint32_t) interval - 1;

  /* Set control register */
  #if MPC55XX_CHIP_FAMILY == 551
    ccr.B.MODE = MPC55XX_EMIOS_MODE_MCB_UP_INT_CLK;
  #else
    ccr.B.MODE = MPC55XX_EMIOS_MODE_MC_UP_INT_CLK;
  #endif
  ccr.B.UCPREN = 1;
  ccr.B.FEN = 1;
  ccr.B.FREN = 1;
  regs->CCR.R = ccr.R;

  rtems_timecounter_simple_install(
    &mpc55xx_tc,
    reference_clock,
    interval,
    mpc55xx_tc_get_timecount
  );
}
Exemplo n.º 3
0
Arquivo: pio_it.c Projeto: RTEMS/rtems
/**
 * Configures a PIO or a group of PIO to generate an interrupt on status
 * change. The provided interrupt handler will be called with the triggering
 * pin as its parameter (enabling different pin instances to share the same
 * handler).
 * \param pPin  Pointer to a Pin instance.
 * \param handler  Interrupt handler function pointer.
 * \param arg Pointer to interrupt handler argument
 */
void PIO_ConfigureIt(const Pin *pPin, void (*handler)(const Pin *, void *arg),
    void *arg)
{
	InterruptSource *pSource;
	rtems_interrupt_level level;

	TRACE_DEBUG("PIO_ConfigureIt()\n\r");

	rtems_interrupt_disable(level);

	if (_dwNumSources == MAX_INTERRUPT_SOURCES) {
		bsp_fatal(ATSAM_FATAL_PIO_CONFIGURE_IT);
	}

	pSource = &(_aIntSources[_dwNumSources]);
	pSource->pPin = pPin;
	pSource->handler = handler;
	pSource->arg = arg;

	_dwNumSources++;

	rtems_interrupt_enable(level);

	/* Define new source */
	TRACE_DEBUG("PIO_ConfigureIt: Defining new source #%d.\n\r", _dwNumSources);
}
Exemplo n.º 4
0
rtems_device_driver console_initialize(
  rtems_device_major_number  major,
  rtems_device_minor_number  minor,
  void                      *arg
)
{
  rtems_status_code status;
  int i;
  char console_name[16];

  rtems_termios_initialize();

  /* Find UARTs */
  leon3_console_scan_uarts();

  /* Update syscon_uart_index to index used as /dev/console
   * Let user select System console by setting syscon_uart_index. If the
   * BSP is to provide the default UART (syscon_uart_index==0):
   *   non-MP: APBUART[0] is system console
   *   MP: LEON CPU index select UART
   */
  if (syscon_uart_index == 0) {
#if defined(RTEMS_MULTIPROCESSING)
    syscon_uart_index = LEON3_Cpu_Index;
#else
    syscon_uart_index = 0;
#endif
  } else {
    syscon_uart_index = syscon_uart_index - 1; /* User selected sys-console */
  }

  /*  Register Device Names
   *
   *  0 /dev/console   - APBUART[USER-SELECTED, DEFAULT=APBUART[0]]
   *  1 /dev/console_a - APBUART[0] (by default not present because is console)
   *  2 /dev/console_b - APBUART[1]
   *  ...
   *
   * On a MP system one should not open UARTs that other OS instances use.
   */
  if (syscon_uart_index < uarts) {
    status = rtems_io_register_name("/dev/console", major, 0);
    if (status != RTEMS_SUCCESSFUL)
      bsp_fatal(LEON3_FATAL_CONSOLE_REGISTER_DEV);
  }
  strcpy(console_name,"/dev/console_a");
  for (i = 0; i < uarts; i++) {
    if (i == syscon_uart_index)
      continue; /* skip UART that is registered as /dev/console */
    console_name[13] = 'a' + i;
    rtems_io_register_name( console_name, major, i+1);
  }

  return RTEMS_SUCCESSFUL;
}
Exemplo n.º 5
0
void mpc55xx_edma_init(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  unsigned channel_remaining = EDMA_CHANNEL_COUNT;
  unsigned module = 0;
  unsigned group = 0;

  for (module = 0; module < EDMA_MODULE_COUNT; ++module) {
    volatile struct EDMA_tag *edma = edma_get_regs_by_module(module);
    unsigned channel_count = channel_remaining < EDMA_CHANNELS_PER_MODULE ?
      channel_remaining : EDMA_CHANNELS_PER_MODULE;
    unsigned channel = 0;

    channel_remaining -= channel_count;

    /* Disable requests */
    edma->CERQR.B.CERQ = 0x40;

    /* Arbitration mode: group round robin, channel fixed */
    edma->CR.B.ERGA = 1;
    edma->CR.B.ERCA = 0;
    for (channel = 0; channel < channel_count; ++channel) {
      volatile struct tcd_t *tcd = &edma->TCD [channel];
      edma->CPR [channel].R = 0x80U | (channel & 0xfU);

      /* Initialize TCD, stop channel first */
      tcd->BMF.R = 0;
      tcd->SADDR = 0;
      tcd->SDF.R = 0;
      tcd->NBYTES = 0;
      tcd->SLAST = 0;
      tcd->DADDR = 0;
      tcd->CDF.R = 0;
      tcd->DLAST_SGA = 0;
    }

    /* Clear interrupt requests */
    edma->CIRQR.B.CINT = 0x40;
    edma->CER.B.CERR = 0x40;
  }

  for (group = 0; group < EDMA_GROUP_COUNT; ++group) {
    sc = mpc55xx_interrupt_handler_install(
      MPC55XX_IRQ_EDMA_ERROR(group),
      "eDMA Error",
      RTEMS_INTERRUPT_UNIQUE,
      MPC55XX_INTC_DEFAULT_PRIORITY,
      edma_interrupt_error_handler,
      NULL
    );
    if (sc != RTEMS_SUCCESSFUL) {
      bsp_fatal(MPC55XX_FATAL_EDMA_IRQ_INSTALL);
    }
  }
}
Exemplo n.º 6
0
Arquivo: bspsmp.c Projeto: AoLaD/rtems
uint32_t _CPU_SMP_Initialize( void )
{
  if ( !leon3_data_cache_snooping_enabled() )
    bsp_fatal( LEON3_FATAL_INVALID_CACHE_CONFIG_MAIN_PROCESSOR );

  if ( rtems_configuration_get_maximum_processors() > 1 ) {
    LEON_Unmask_interrupt(LEON3_mp_irq);
    set_vector(bsp_inter_processor_interrupt, LEON_TRAP_TYPE(LEON3_mp_irq), 1);
  }

  return leon3_get_cpu_count(LEON3_IrqCtrl_Regs);
}
Exemplo n.º 7
0
/**
 * @brief Serial drivers init function
 *
 * Initialize all serial drivers specified in driver_context_table
 *
 * @param[in] major
 * @param[in] minor
 * @param[in] arg
 * @retval RTEMS_SUCCESSFUL Initialization completed
 */
rtems_device_driver console_initialize(
  rtems_device_major_number  major,
  rtems_device_minor_number  minor,
  void                      *arg
)
{
  rtems_status_code sc;
#if CONSOLE_USE_INTERRUPTS
  const rtems_termios_device_handler *handler = &tms570_sci_handler_interrupt;
#else
  const rtems_termios_device_handler *handler = &tms570_sci_handler_polled;
#endif

  /*
   * Initialize the Termios infrastructure.  If Termios has already
   * been initialized by another device driver, then this call will
   * have no effect.
   */
  rtems_termios_initialize();

  /* Initialize each device */
  for (
    minor = 0;
    minor < RTEMS_ARRAY_SIZE(driver_context_table);
    ++minor
  ) {
    tms570_sci_context *ctx = &driver_context_table[minor];

    /*
     * Install this device in the file system and Termios.  In order
     * to use the console (i.e. being able to do printf, scanf etc.
     * on stdin, stdout and stderr), one device must be registered as
     * "/dev/console" (CONSOLE_DEVICE_NAME).
     */
    sc = rtems_termios_device_install(
        ctx->device_name,
        major,
        minor,
        handler,
	NULL,
        &ctx->base
    );
    if ( sc != RTEMS_SUCCESSFUL ) {
      bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV);
    }
  }
  return RTEMS_SUCCESSFUL;
}
Exemplo n.º 8
0
static void mpc55xx_clock_handler_install(rtems_isr_entry isr)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;

  sc = mpc55xx_interrupt_handler_install(
    MPC55XX_IRQ_EMIOS(MPC55XX_CLOCK_EMIOS_CHANNEL),
    "clock",
    RTEMS_INTERRUPT_UNIQUE,
    MPC55XX_INTC_MIN_PRIORITY,
    (rtems_interrupt_handler) isr,
    NULL
  );
  if (sc != RTEMS_SUCCESSFUL) {
    bsp_fatal(MPC55XX_FATAL_CLOCK_EMIOS_IRQ_INSTALL);
  }
}
Exemplo n.º 9
0
void mpc55xx_edma_release_channel(edma_channel_context *ctx)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  unsigned channel_index = edma_channel_index_of_tcd(ctx->edma_tcd);

  mpc55xx_edma_release_channel_by_tcd(ctx->edma_tcd);
  rtems_chain_extract(&ctx->node);

  sc = rtems_interrupt_handler_remove(
    MPC55XX_IRQ_EDMA(channel_index),
    edma_interrupt_handler,
    ctx
  );
  if (sc != RTEMS_SUCCESSFUL) {
    bsp_fatal(MPC55XX_FATAL_EDMA_IRQ_REMOVE);
  }
}
Exemplo n.º 10
0
Arquivo: bspsmp.c Projeto: AoLaD/rtems
void _CPU_SMP_Finalize_initialization(uint32_t cpu_count)
{
  if (cpu_count > 1) {
    rtems_status_code sc;

    sc = rtems_interrupt_handler_install(
      QORIQ_IRQ_IPI_0 + IPI_INDEX,
      "IPI",
      RTEMS_INTERRUPT_UNIQUE,
      bsp_inter_processor_interrupt,
      NULL
    );
    if (sc != RTEMS_SUCCESSFUL) {
      bsp_fatal(QORIQ_FATAL_SMP_IPI_HANDLER_INSTALL);
    }
  }
}
Exemplo n.º 11
0
void bsp_interrupt_initialize(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  size_t i = 0;

  /* Initialize handler table */
  for (i = 0; i < BSP_INTERRUPT_HANDLER_TABLE_SIZE; ++i) {
    bsp_interrupt_handler_table [i].handler = bsp_interrupt_handler_empty;
    bsp_interrupt_handler_table [i].arg = (void *) i;
  }

  sc = bsp_interrupt_facility_initialize();
  if (sc != RTEMS_SUCCESSFUL) {
    bsp_fatal(BSP_FATAL_INTERRUPT_INITIALIZATION);
  }

  bsp_interrupt_set_initialized();
}
Exemplo n.º 12
0
static void armv7m_cpu_counter_initialize(void)
{
  bool cyccnt_enabled;

  cyccnt_enabled = _ARMV7M_DWT_Enable_CYCCNT();

  if (cyccnt_enabled) {
    #ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
      uint64_t freq = BSP_ARMV7M_SYSTICK_FREQUENCY;
    #else
      volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
      uint64_t freq = ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100ULL;
    #endif

    rtems_counter_initialize_converter(freq);
  } else {
    bsp_fatal(BSP_ARM_ARMV7M_CPU_COUNTER_INIT);
  }
}
Exemplo n.º 13
0
void _CPU_SMP_Finalize_initialization(uint32_t cpu_count)
{
  if (rtems_configuration_get_maximum_processors() > 0) {
    mmu_config_undo();
  }

  if (cpu_count > 1) {
    rtems_status_code sc;

    sc = rtems_interrupt_handler_install(
      QORIQ_IRQ_IPI_0,
      "IPI",
      RTEMS_INTERRUPT_UNIQUE,
      bsp_inter_processor_interrupt,
      NULL
    );
    if (sc != RTEMS_SUCCESSFUL) {
      bsp_fatal(QORIQ_FATAL_SMP_IPI_HANDLER_INSTALL);
    }
  }
}
Exemplo n.º 14
0
static void ppc_exc_fatal_error(void)
{
  bsp_fatal(PPC_FATAL_EXCEPTION_INITIALIZATION);
}
Exemplo n.º 15
0
Arquivo: pio_it.c Projeto: RTEMS/rtems
static void PIO_SysInitializeInterrupts(void)
{
	rtems_status_code sc;

	TRACE_DEBUG("PIO_Initialize()\n\r");

	/* Configure PIO interrupt sources */
	TRACE_DEBUG("PIO_Initialize: Configuring PIOA\n\r");
	PMC_EnablePeripheral(ID_PIOA);
	PIOA->PIO_ISR;
	PIOA->PIO_IDR = 0xFFFFFFFF;
	sc = rtems_interrupt_handler_install(
		PIOA_IRQn,
		"PIO A",
		RTEMS_INTERRUPT_UNIQUE,
		PIOA_Interrupt,
		PIOA
	);
	if (sc != RTEMS_SUCCESSFUL) {
		bsp_fatal(ATSAM_FATAL_PIO_IRQ_A);
	}

	TRACE_DEBUG("PIO_Initialize: Configuring PIOB\n\r");
	PMC_EnablePeripheral(ID_PIOB);
	PIOB->PIO_ISR;
	PIOB->PIO_IDR = 0xFFFFFFFF;
	sc = rtems_interrupt_handler_install(
		PIOB_IRQn,
		"PIO B",
		RTEMS_INTERRUPT_UNIQUE,
		PIOB_Interrupt,
		PIOB
	);
	if (sc != RTEMS_SUCCESSFUL) {
		bsp_fatal(ATSAM_FATAL_PIO_IRQ_B);
	}

	TRACE_DEBUG("PIO_Initialize: Configuring PIOC\n\r");
	PMC_EnablePeripheral(ID_PIOC);
	PIOC->PIO_ISR;
	PIOC->PIO_IDR = 0xFFFFFFFF;
	sc = rtems_interrupt_handler_install(
		PIOC_IRQn,
		"PIO C",
		RTEMS_INTERRUPT_UNIQUE,
		PIOC_Interrupt,
		PIOC
	);
	if (sc != RTEMS_SUCCESSFUL) {
		bsp_fatal(ATSAM_FATAL_PIO_IRQ_C);
	}

	TRACE_DEBUG("PIO_Initialize: Configuring PIOD\n\r");
	PMC_EnablePeripheral(ID_PIOD);
	PIOD->PIO_ISR;
	PIOD->PIO_IDR = 0xFFFFFFFF;
	sc = rtems_interrupt_handler_install(
		PIOD_IRQn,
		"PIO D",
		RTEMS_INTERRUPT_UNIQUE,
		PIOD_Interrupt,
		PIOD
	);
	if (sc != RTEMS_SUCCESSFUL) {
		bsp_fatal(ATSAM_FATAL_PIO_IRQ_D);
	}

	TRACE_DEBUG("PIO_Initialize: Configuring PIOE\n\r");
	PMC_EnablePeripheral(ID_PIOE);
	PIOE->PIO_ISR;
	PIOE->PIO_IDR = 0xFFFFFFFF;
	sc = rtems_interrupt_handler_install(
		PIOE_IRQn,
		"PIO E",
		RTEMS_INTERRUPT_UNIQUE,
		PIOE_Interrupt,
		PIOE
	);
	if (sc != RTEMS_SUCCESSFUL) {
		bsp_fatal(ATSAM_FATAL_PIO_IRQ_E);
	}
}
Exemplo n.º 16
0
/**
 * @brief Serial drivers init function
 *
 * Initialize all serial drivers specified in driver_context_table
 *
 * @param[in] major
 * @param[in] minor
 * @param[in] arg
 * @retval RTEMS_SUCCESSFUL Initialization completed
 */
rtems_device_driver console_initialize(
  rtems_device_major_number  major,
  rtems_device_minor_number  minor,
  void                      *arg
)
{
  rtems_status_code sc;
#if CONSOLE_USE_INTERRUPTS
  const rtems_termios_device_handler *handler = &tms570_sci_handler_interrupt;
#else
  const rtems_termios_device_handler *handler = &tms570_sci_handler_polled;
#endif

  /*
   * Initialize the Termios infrastructure.  If Termios has already
   * been initialized by another device driver, then this call will
   * have no effect.
   */
  rtems_termios_initialize();

  /* Initialize each device */
  for (
    minor = 0;
    minor < RTEMS_ARRAY_SIZE(driver_context_table);
    ++minor
  ) {
    tms570_sci_context *ctx = &driver_context_table[minor];
    uint32_t rx_pin = 1 << 1;
    uint32_t tx_pin = 1 << 2;

    /* Resec SCI peripheral */
    ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 0;
    ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 1;

    /* Clear all interrupt sources */
    ctx->regs->CLEARINT = 0xffffffff;

    /* Map all interrupts to SCI INT0 line */
    ctx->regs->CLEARINTLVL = 0xffffffff;

    ctx->regs->GCR1 = TMS570_SCI_GCR1_TXENA * 0 |
                      TMS570_SCI_GCR1_RXENA * 0 |
                      TMS570_SCI_GCR1_CONT * 0 | /* continue operation when debugged */
                      TMS570_SCI_GCR1_LOOP_BACK * 0 |
                      TMS570_SCI_GCR1_POWERDOWN * 0 |
                      TMS570_SCI_GCR1_SLEEP * 0 |
                      TMS570_SCI_GCR1_SWnRST * 0 | /* reset state */
                      TMS570_SCI_GCR1_CLOCK * 1 | /* internal clock */
                      TMS570_SCI_GCR1_TIMING_MODE * 1 |
                      TMS570_SCI_GCR1_COMM_MODE * 0;

    /* Setup connection of SCI peripheral Rx and Tx  pins */
    ctx->regs->PIO0 = rx_pin * 1 | tx_pin * 1; /* Rx and Tx pins are not GPIO */
    ctx->regs->PIO3 = rx_pin * 0 | tx_pin * 0; /* Default output low  */
    ctx->regs->PIO1 = rx_pin * 0 | tx_pin * 0; /* Input when not used by SCI */
    ctx->regs->PIO6 = rx_pin * 0 | tx_pin * 0; /* No open drain */
    ctx->regs->PIO7 = rx_pin * 0 | tx_pin * 0; /* Pull-up/down enabled */
    ctx->regs->PIO8 = rx_pin * 1 | tx_pin * 1; /* Select pull-up */

    /* Bring device out of software reset */
    ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST;

    /*
     * Install this device in the file system and Termios.  In order
     * to use the console (i.e. being able to do printf, scanf etc.
     * on stdin, stdout and stderr), one device must be registered as
     * "/dev/console" (CONSOLE_DEVICE_NAME).
     */
    sc = rtems_termios_device_install(
        ctx->device_name,
        major,
        minor,
        handler,
        NULL,
        &ctx->base
    );
    if ( sc != RTEMS_SUCCESSFUL ) {
      bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV);
    }
  }
  return RTEMS_SUCCESSFUL;
}