uint_32 _mcf54xx_uart_serial_int_init
   (
      /* [IN] the interrupt I/O initialization information */
      IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr,

      /* [IN] the rest of the name of the device opened */
      char _PTR_                      open_name_ptr
   )
{ /* Body */
   MCF54XX_UART_SERIAL_INFO_STRUCT_PTR uart_info_ptr;
   MCF54XX_UART_SERIAL_INIT_STRUCT_PTR uart_init_ptr;
   uint_32                             result;

   uart_init_ptr = int_io_dev_ptr->DEV_INIT_DATA_PTR;
   result = _mcf54xx_uart_serial_polled_init((pointer)uart_init_ptr,
      &int_io_dev_ptr->DEV_INFO_PTR, open_name_ptr);
   if (result != MQX_OK) {
      return(result);
   }/* Endif */

   uart_info_ptr = int_io_dev_ptr->DEV_INFO_PTR;
   uart_info_ptr->OLD_ISR_DATA = _int_get_isr_data(uart_init_ptr->VECTOR);
   uart_info_ptr->OLD_ISR_EXCEPTION_HANDLER =
      _int_get_exception_handler(uart_init_ptr->VECTOR);

   uart_info_ptr->OLD_ISR =
      _int_install_isr(uart_init_ptr->VECTOR, _mcf54xx_uart_serial_int_isr,
      int_io_dev_ptr);

   return(MQX_OK);

} /* Endbody */
Beispiel #2
0
uint_32 _kuart_int_init
   (
      /* [IN] the interrupt I/O initialization information */
      IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr,

      /* [IN] the rest of the name of the device opened */
      char _PTR_                      open_name_ptr
   )
{ /* Body */
   KUART_INFO_STRUCT_PTR sci_info_ptr;
   KUART_INIT_STRUCT_PTR sci_init_ptr;
   uint_32                     result;

   sci_init_ptr = int_io_dev_ptr->DEV_INIT_DATA_PTR;
   result = _kuart_polled_init((pointer)sci_init_ptr, &int_io_dev_ptr->DEV_INFO_PTR, open_name_ptr);
   if (result != MQX_OK) {
       return(result);
   }/* Endif */

      sci_info_ptr = int_io_dev_ptr->DEV_INFO_PTR;
   /* wk */
   UART_MemMapPtr                         sci_ptr = sci_info_ptr->SCI_PTR;
   sci_ptr->C2 &= 0x77;
   /* end */

   sci_info_ptr->OLD_ISR_DATA = _int_get_isr_data(sci_init_ptr->RX_TX_VECTOR);
   sci_info_ptr->OLD_ISR_EXCEPTION_HANDLER = _int_get_exception_handler(sci_init_ptr->RX_TX_VECTOR);

   /* wk */
   sci_ptr->C2 &= 0x77;
   /* end */
   
   /* Init RX/TX interrupt vector */
   sci_info_ptr->OLD_ISR =
//     _int_install_isr(sci_init_ptr->RX_TX_VECTOR, _kuart_int_rx_tx_isr, int_io_dev_ptr);
     _int_install_isr(sci_init_ptr->RX_TX_VECTOR, uart_isr, int_io_dev_ptr);  // wk

   /* wk */
   sci_ptr->C2 &= 0x77;
   /* end */

#if defined (BSP_TWRMCF51FD) || defined (BSP_TWRMCF51JF) || defined (BSP_TWRMCF51QM)
#else
   /* Init RX interrupt vector */
   sci_info_ptr->OLD_ISR =
     _int_install_isr(sci_init_ptr->ERR_VECTOR, _kuart_int_err_isr, int_io_dev_ptr);

    _cortex_int_init(sci_init_ptr->RX_TX_VECTOR, sci_init_ptr->RX_TX_PRIORITY, TRUE);
    _cortex_int_init(sci_init_ptr->ERR_VECTOR, sci_init_ptr->ERR_PRIORITY, TRUE);
#endif
   return(MQX_OK);

} /* Endbody */
Beispiel #3
0
uint_32 _vf_rtc_init
   (
      /* [IN] the initialization information for the device being opened */
      IO_RTC_IF_DEVICE_STRUCT_PTR   io_dev_ptr,

      /* [IN] the rest of the name of the device opened */
      char_ptr                        open_name_ptr

   )
{ /* Body */
   
   VF_RTC_IF_INFO_STRUCT                   _PTR_ io_info_ptr;
   VF_RTC_IF_INIT_STRUCT                   _PTR_ io_init_ptr;
   VF_RTC_REGS_T                 _PTR_ regs_ptr;
   uint_32                                     result;  
   
   io_init_ptr = io_dev_ptr->DEV_INIT_DATA_PTR;
   io_info_ptr = (VF_RTC_IF_INFO_STRUCT _PTR_)(_mem_alloc_system_zero((uint_32)sizeof(VF_RTC_IF_INFO_STRUCT)));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (io_info_ptr == NULL) {
      return(MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   io_dev_ptr->DEV_INFO_PTR = io_info_ptr;
   //get init value
   io_info_ptr->INIT = *io_init_ptr;   
   /* reg_ptr will point to the rtc Registers */
   regs_ptr  =  (VF_RTC_REGS_T _PTR_)io_info_ptr->INIT.BASE_ADDRESS;
   io_info_ptr->RTC_REGS_PTR   = regs_ptr;   
   //set up rtc interrupt
   io_info_ptr->RTC_VECTOR = BSP_RTC_INTERRUPT_VECTOR;
   io_info_ptr->OLD_ISR_DATA = _int_get_isr_data(io_info_ptr->RTC_VECTOR);
   io_info_ptr->OLD_ISR_EXCEPTION_HANDLER =
	   _int_get_exception_handler(io_info_ptr->RTC_VECTOR);
   io_info_ptr->OLD_ISR =
      _int_install_isr(io_info_ptr->RTC_VECTOR,_vf_rtc_int_isr,io_info_ptr);   
   //now init ssp regs with defult values
   //	APB_RTC->rtcicr = 0x1;
   //	APB_RTC->rtcimsc = 0x1;
   //	APB_RTC->rtclr = 0x2;
   //	APB_RTC->rtccr = 0x1;
   //	APB_RTC->rtcmr = 0x50;   
   SysCtl_EnableRtc();
   _vf_enable_int(BSP_RTC_INTERRUPT_VECTOR);    
   //======================
   return (MQX_OK);
   
} /* Endbody */
Beispiel #4
0
uint32_t _kuart_mix_init
	(
	   /* [IN] the interrupt I/O initialization information */
	   IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr,

	   /* [IN] the rest of the name of the device opened */
	   char *                     open_name_ptr
	)
{ /* Body */
      KUART_INFO_STRUCT_PTR sci_info_ptr;
      KUART_INIT_STRUCT_PTR sci_init_ptr;
      uint32_t                     result = MQX_OK;

      //Init basic uart setting
      sci_init_ptr = int_io_dev_ptr->DEV_INIT_DATA_PTR;
      result = _kuart_polled_init((void *)sci_init_ptr, &int_io_dev_ptr->DEV_INFO_PTR, open_name_ptr);
      if (result != MQX_OK) {
          return(result);
      }/* Endif */
      sci_info_ptr = int_io_dev_ptr->DEV_INFO_PTR;
      sci_info_ptr->RX_KEEP = 1;

      /* Add a timer config to check the UART RX state */    
      sci_info_ptr->LW_TIMER_PTR = (LWTIMER_PERIOD_STRUCT_PTR)_mem_alloc_system_zero(sizeof(LWTIMER_PERIOD_STRUCT) + sizeof(LWTIMER_STRUCT));
      if (!sci_info_ptr->LW_TIMER_PTR)
      {
          result = MQX_OUT_OF_MEMORY;
          goto error_free_timer;
      }
      sci_info_ptr->LW_TIMER = (LWTIMER_STRUCT_PTR)((uint8_t *)sci_info_ptr->LW_TIMER_PTR + sizeof(LWTIMER_PERIOD_STRUCT));
      _time_init_ticks(&sci_info_ptr->ticks, 1);  
      _lwtimer_create_periodic_queue(sci_info_ptr->LW_TIMER_PTR ,*(uint32_t *)(&sci_info_ptr->ticks), 0);

      _lwtimer_add_timer_to_queue(
              sci_info_ptr->LW_TIMER_PTR, 
              sci_info_ptr->LW_TIMER,
              0,
              _kuart_period_isr,
              (void *)int_io_dev_ptr);

      /* RX DMA setting */
      sci_info_ptr->RX_BUF = _mem_alloc_system_zero_uncached(sci_init_ptr->IQUEUE_SIZE);
      sci_info_ptr->RX_ACTIVE = sci_info_ptr->RX_BUF;
      if (!sci_info_ptr->RX_BUF)
      {
              result = MQX_OUT_OF_MEMORY;
              goto error_free_buf;
      }
      sci_info_ptr->RX_DMA_CHAN = sci_init_ptr->RX_DMA_CHANNEL;
      sci_info_ptr->RX_DMA_HARDWARE_REQUEST = _bsp_get_serial_rx_dma_request(sci_init_ptr->DEVICE);
#if PSP_MQX_CPU_IS_KINETIS
      sci_info_ptr->ERR_INT = _bsp_get_serial_error_int_num(sci_init_ptr->DEVICE);
#endif
    sci_info_ptr->RX_DMA_SEQ = 0;
    result = dma_channel_claim(&sci_info_ptr->RX_DCH, sci_info_ptr->RX_DMA_CHAN);
    if (result != MQX_OK)
    {
            goto error_free_channel;
    }
    result = dma_callback_reg(sci_info_ptr->RX_DCH, _kuart_dma_rx_isr, int_io_dev_ptr);
    dma_channel_setup(sci_info_ptr->RX_DCH, 1, DMA_CHANNEL_FLAG_LOOP_MODE);
    dma_request_source(sci_info_ptr->RX_DCH, sci_info_ptr->RX_DMA_HARDWARE_REQUEST);

    if (result != MQX_OK)
    {
            goto error_free_channel;
    }


    /* Init RX/TX interrupt vector */

    sci_info_ptr->OLD_ISR_TXRX_DATA = _int_get_isr_data(sci_init_ptr->RX_TX_VECTOR);
    sci_info_ptr->OLD_ISR_EXCEPTION_HANDLER = _int_get_exception_handler(sci_init_ptr->RX_TX_VECTOR);

    sci_info_ptr->OLD_ISR_TXRX =
    _int_install_isr(sci_init_ptr->RX_TX_VECTOR, _kuart_mix_int_tx_isr, int_io_dev_ptr);
    _bsp_int_init(sci_init_ptr->RX_TX_VECTOR, sci_init_ptr->RX_TX_PRIORITY, 0, TRUE);


    /* Init mix error vector */
    sci_info_ptr->OLD_ISR_ERR =
    _int_install_isr(sci_info_ptr->ERR_INT, _kuart_mix_err_isr, int_io_dev_ptr);
    _bsp_int_init(sci_info_ptr->ERR_INT, sci_init_ptr->ERR_PRIORITY, 0, TRUE);

    /* config the UART RX channel first */
    _kuart_prepare_rx_dma(int_io_dev_ptr);      
    return(MQX_OK);

error_free_timer:
    if (!sci_info_ptr->LW_TIMER_PTR)
    _mem_free(sci_info_ptr->LW_TIMER_PTR);

error_free_channel:
    dma_channel_release(sci_info_ptr->RX_DCH);
    
error_free_buf:
    if (sci_info_ptr->RX_BUF)
            _mem_free(sci_info_ptr->RX_BUF);

    return result;
} /* Endbody */
Beispiel #5
0
/*!
 * \brief To provide support for exception handlers, applications can use this ISR
 * to replace the default ISR. The ISR is specific to the PSP.
 * 
 * An application calls _int_install_exception_isr() to install _int_exception_isr().
 * \n The function _int_exception_isr() does the following:
 * \n - If an exception occurs when a task is running and a task exception ISR 
 * exists, MQX runs the ISR; if a task exception ISR does not exist, MQX aborts 
 * the task by calling _task_abort().
 * \n - If an exception occurs when an ISR is running and an ISR exception ISR 
 * exists, MQX aborts the running ISR and runs the ISR’s exception ISR.
 * \n - The function walks the interrupt stack looking for information about the 
 * ISR or task that was running before the exception occurred. If the function 
 * determines that the interrupt stack contains incorrect information, it calls 
 * _mqx_fatal_error() with error code MQX_CORRUPT_INTERRUPT_STACK.
 * 
 * \param[in] parameter Parameter passed to the default ISR (the vector number).
 * 
 * \warning See description.
 * 
 * \see _int_install_exception_isr
 * \see _mqx_fatal_error
 * \see _task_abort     
 */   
void _int_exception_isr
   (
      pointer parameter
   )
{ /* Body */
    KERNEL_DATA_STRUCT_PTR         kernel_data;
    TD_STRUCT_PTR                  td_ptr;
    PSP_INT_CONTEXT_STRUCT_PTR     exception_frame_ptr;
    PSP_INT_CONTEXT_STRUCT_PTR     isr_frame_ptr;
    INTERRUPT_TABLE_STRUCT_PTR     table_ptr;
    INT_EXCEPTION_FPTR             exception_handler;
    uint_32                        isr_vector;
/*    uint_32                        exception_vector; */

    _GET_KERNEL_DATA(kernel_data);
    td_ptr = kernel_data->ACTIVE_PTR;

    /* Stop all interrupts */
    _PSP_SET_DISABLE_SR(kernel_data->DISABLE_SR);
    /*_int_disable(); */

    if ( kernel_data->IN_ISR > 1 ) {
        /* We have entered this function from an exception that happened
         * while an isr was running.
         */
    
        /* Get our current exception frame */
        exception_frame_ptr = kernel_data->INTERRUPT_CONTEXT_PTR;

        /* the current context contains a pointer to the next one */
        isr_frame_ptr = (PSP_INT_CONTEXT_STRUCT_PTR)exception_frame_ptr->PREV_CONTEXT;
        if (isr_frame_ptr == NULL) {
            /* This is not allowable */
            _mqx_fatal_error(MQX_CORRUPT_INTERRUPT_STACK);
        }
        
        isr_vector =  isr_frame_ptr->EXCEPTION_NUMBER;

        /* Call the isr exception handler for the ISR that WAS running */
        table_ptr = kernel_data->INTERRUPT_TABLE_PTR;
#if MQX_CHECK_ERRORS
        if ((table_ptr != NULL) &&
            (isr_vector >= kernel_data->FIRST_USER_ISR_VECTOR) &&
            (isr_vector <= kernel_data->LAST_USER_ISR_VECTOR))
        {
#endif
        /* Call the exception handler for the isr on isr_vector,
         * passing the isr_vector, the exception_vector, the isr_data and
         * the basic frame pointer for the exception
         */
        exception_handler = _int_get_exception_handler(isr_vector);
   
        if (exception_handler) {
            (*exception_handler)(isr_vector, (_mqx_uint)parameter, _int_get_isr_data(isr_vector)/*table_ptr->APP_ISR_DATA*/, exception_frame_ptr);
        }
    
#if MQX_CHECK_ERRORS
        } else {
            /* In this case, the exception occured in this handler */
            _mqx_fatal_error(MQX_INVALID_VECTORED_INTERRUPT);
        }
#endif

        /* Indicate we have popped 1 interrupt stack frame (the exception frame) */
        --kernel_data->IN_ISR;

        /* Reset the stack to point to the interrupt frame */
        /* And off we go. Will never return */
        _psp_exception_return( (pointer)isr_frame_ptr );

    } else {
        /* We have entered this function from an exception that happened
         * while a task was running.
         */

        if (td_ptr->EXCEPTION_HANDLER_PTR != NULL ) {
            (*td_ptr->EXCEPTION_HANDLER_PTR)((_mqx_uint)parameter, 
            td_ptr->STACK_PTR);
        } else {
            /* Abort the current task */
            _task_abort(MQX_NULL_TASK_ID);
        }
   }
}