⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialswitch.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
    return (FD_OK);
}

/*******************************************************************************
 *
 *                              dummy_fd_SetLineState
 *
 * Purpose: No action.
 *
 * Parameters: See SER_fd_SetLineState.
 *
 * Return: FD_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_FDRET
dummy_fd_SetLineState (T_fd_UartId device,
                       SYS_UWORD32 state,
                       SYS_UWORD32 mask)
{
    return (FD_OK);
}

/*******************************************************************************
 *
 *                              dummy_fd_CheckXEmpty
 *
 * Purpose: No action.
 *
 * Parameters: See SER_fd_CheckXEmpty.
 *
 * Return: FD_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_FDRET
dummy_fd_CheckXEmpty (T_fd_UartId device)
{
    return (FD_OK);
}

#ifdef BLUETOOTH
/*******************************************************************************
 *
 *                              dummy_bt_Init
 *
 * Purpose: No action.
 *
 * Parameters: See SER_bt_Init.
 *
 * Return: HCI_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_HCI_RET
dummy_bt_Init (T_bt_UartId uart_device)
{
    return (HCI_OK);
}

/*******************************************************************************
 *
 *                              dummy_bt_Start
 *
 * Purpose: No action.
 *
 * Parameters: See SER_bt_Start.
 *
 * Return: HCI_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_HCI_RET
dummy_bt_Start (void)
{
    return (HCI_OK);
}

/*******************************************************************************
 *
 *                              dummy_bt_Stop
 *
 * Purpose: No action.
 *
 * Parameters: See SER_bt_Stop.
 *
 * Return: HCI_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_HCI_RET
dummy_bt_Stop (void)
{
    return (HCI_OK);
}

/*******************************************************************************
 *
 *                              dummy_bt_Kill
 *
 * Purpose: No action.
 *
 * Parameters: See SER_bt_Kill.
 *
 * Return: HCI_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_HCI_RET
dummy_bt_Kill (void)
{
    return (HCI_OK);
}

/*******************************************************************************
 *
 *                           dummy_bt_SetBaudrate
 *
 * Purpose: No action.
 *
 * Parameters: See SER_bt_SetBaudrate.
 *
 * Return: HCI_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_HCI_RET
dummy_bt_SetBaudrate (UINT8 baudrate)
{
    return (HCI_OK);
}

/*******************************************************************************
 *
 *                         dummy_bt_TransmitPacket
 *
 * Purpose: No action.
 *
 * Parameters: See SER_bt_TransmitPacket.
 *
 * Return: HCI_OK: Successful operation.
 *
 ******************************************************************************/
 
static T_HCI_RET
dummy_bt_TransmitPacket (UINT8 hciu_packet_type,
                         void *uart_tx_buffer)

{
    return (HCI_OK);
}
#endif /* BLUETOOTH */

/*******************************************************************************
 *
 *                     analyze_uart_sleep_timer_expiration
 * 
 * Purpose  : The timer has just expired. If requested, UARTs can again be set
 *            up to enter Deep Sleep.
 *
 * Arguments: In : id: parameter not used.
 *            Out: none
 *
 * Returns  : none 
 *
 ******************************************************************************/

static VOID
analyze_uart_sleep_timer_expiration (UNSIGNED id)
{
    /*
     * Timer has expired.
     * UARTs can again be set up for Deep Sleep.
     */

    (void) NU_Control_Timer (&uart_sleep_timer,
                             NU_DISABLE_TIMER);
      
    uart_sleep_timer_enabled = 0;
}

/*******************************************************************************
 *
 *                          start_uart_sleep_timer
 * 
 * Purpose  : Starts the sleep timer once UARTs have been waked-up by an
 *            interrupt or if new incoming characters have been received.
 *
 * Arguments: In : none
 *            Out: none
 *
 * Returns  : none 
 *
 ******************************************************************************/

static void
start_uart_sleep_timer (void)
{
    /*
     * UART sleep timer is started.
     * UARTs can't no more be set up for Deep Sleep until the timer expires.
     */

    (void) NU_Reset_Timer (&uart_sleep_timer,
                           &analyze_uart_sleep_timer_expiration,
                           WAKE_UP_TIME_IN_TDMA,
                           0, /* The timer expires once. */
                           NU_DISABLE_TIMER);

    (void) NU_Control_Timer (&uart_sleep_timer,
                             NU_ENABLE_TIMER);
}

/*******************************************************************************
 *
 *                              set_flow_functions
 *
 * Purpose: Initializes a serial data flow functions set with the set of
 *          functions of the selected device.
 *
 * Parameters: In : flow         : index of the serial data flow
 *                  serial_driver: allows knowing which set of functions must
 *                                 be selected
 *             Out: none
 *
 * Return: none
 *
 ******************************************************************************/

static void
set_flow_functions (int flow,
                    T_SerialDriver serial_driver)
{

    switch (serial_driver) {

    case UART_MODEM_FAX_DATA:

        fd_functions = &uart_modem_fax_data;
        int_uart[fd_functions->device].device_used = 1;
        int_uart[fd_functions->device].flow_type   = FAX_DATA_FLOW;
        int_uart[fd_functions->device].flow_id     = flow;
        int_uart[fd_functions->device].interrupt_handler =
                                           UAF_InterruptHandler;
        break;

    #if (CHIPSET == 12)
      case UART_MODEM2_FAX_DATA:

          fd_functions = &uart_modem2_fax_data;
          int_uart[fd_functions->device].device_used = 1;
          int_uart[fd_functions->device].flow_type   = FAX_DATA_FLOW;
          int_uart[fd_functions->device].flow_id     = flow;
          int_uart[fd_functions->device].interrupt_handler =
                                             UAF_InterruptHandler;
          break;
    #endif

    case DUMMY_FAX_DATA:
        
        fd_functions = &dummy_fax_data;                               
        break;


    case UART_IRDA_TRACE:
    case UART_MODEM_TRACE:
    #if (CHIPSET == 12)
      case UART_MODEM2_TRACE:
    #endif

        if (serial_driver == UART_IRDA_TRACE)
            tr_functions[flow] = &uart_irda_trace;
        else {
          #if (CHIPSET == 12)
            if (serial_driver == UART_MODEM2_TRACE)
                tr_functions[flow] = &uart_modem2_trace;
            else
          #endif
                tr_functions[flow] = &uart_modem_trace;
        }

        int_uart[tr_functions[flow]->device].device_used = 1;
        int_uart[tr_functions[flow]->device].flow_type   = TRACE_FLOW;
        int_uart[tr_functions[flow]->device].flow_id     = flow;
        int_uart[tr_functions[flow]->device].interrupt_handler =
                                      UA_InterruptHandler;
        break;

    case DUMMY_TRACE:

        tr_functions[flow] = &dummy_trace;
        break;

    case DUMMY_BT_HCI:

        /*
         * if serial_driver = DUMMY_BT_HCI & if BLUETOOTH is not defined
         * no action is performed.
         */

#ifdef BLUETOOTH
        bt_functions = &dummy_bt_hci;                               
        break;

    case UART_IRDA_BT_HCI:
    case UART_MODEM_BT_HCI:
    #if (CHIPSET == 12)
      case UART_MODEM2_BT_HCI:
    #endif

        if (serial_driver == UART_IRDA_BT_HCI)
            bt_functions = &uart_irda_bt_hci;
        else {
          #if (CHIPSET == 12)
            if (serial_driver == UART_MODEM2_BT_HCI)
                bt_functions = &uart_modem2_bt_hci;
            else
          #endif
                bt_functions = &uart_modem_bt_hci;
        }

        int_uart[bt_functions->device].device_used = 1;
        int_uart[bt_functions->device].flow_type   = BLUETOOTH_HCI_FLOW;
        int_uart[bt_functions->device].flow_id     = flow;
        int_uart[bt_functions->device].interrupt_handler =
                                             hciu_interrupt_handler;
#endif /* BLUETOOTH */
          break;
    }
}

/*******************************************************************************
 *
 *                          SER_InitSerialConfig
 *
 * Purpose: The parameter serial_info allows knowing all serial information
 *          necessary to set up the serial configuration of an application.
 *          From this information, the function is able to determine if the
 *          current serial configuration read out from the flash memory is
 *          valid. If it does not correspond to an allowed configuration, the
 *          default configuration is selected. This function must be called at
 *          the application's initialization, but never after.
 *
 * Parameters: In : serial_info: application serial information like the default
 *                               configuration and all allowed configurations.
 *             Out: none
 *
 * Return: none
 *
 ******************************************************************************/

void
SER_InitSerialConfig (T_AppliSerialInfo *serial_info)
{
    int         uart_id;
    int         flow;
    SYS_UWORD16 serial_driver;
    SYS_UWORD16 *allowed_config;
    SYS_UWORD8  nb_allowed_config;
    SYS_BOOL    valid_config_selected;
    SYS_BOOL    uart_used;
    SYS_BOOL    uart_used_for_trace;
    SYS_UWORD16 current_config;
    SYS_UWORD16 *pt_current_config = &(current_config);

    /*
	 * Basic UARTs initializations.
	 */

    for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {

        int_uart[uart_id].base_address = uart_base_address[uart_id];
        int_uart[uart_id].device_used = 0;
        int_uart[uart_id].deep_sleep_set_up = 0;
    }
						  
#if ((CHIPSET == 2) || (CHIPSET == 3))
    uart_spurious_interrupts = 0;
#elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12))
    uart_modem_spurious_interrupts = 0;
    uart_irda_spurious_interrupts = 0;
#endif
#if (CHIPSET == 12)
    uart_modem2_spurious_interrupts = 0;
#endif
    uart_sleep_timer_enabled = 0;

    /*
     * Compute the current serial configuration.
     */

    for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {

        switch (ser_cfg_info[uart_id]) { 

            case G23_PANEL:
                serial_cfg = serial_cfg +
                    ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK)));
                break;

            case RIVIERA_TRACE_MUX:
                serial_cfg = serial_cfg +
                    ((uart_id + 1) << (12 - (4 * SER_LAYER_1)));
                break;

            case FD_AT_COMMAND:
                serial_cfg = serial_cfg +
                    ((uart_id + 1) << (12 - (4 * SER_FAX_DATA)));
                break;

            case BLUETOOTH_HCI:
                serial_cfg = serial_cfg +
                    ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI)));
                break;

            case DUMMY:
                break;
        }
    }

    current_config = serial_cfg;
    valid_config_selected = 0;
    nb_allowed_config = serial_info->num_config;

    /*
     * Checks if the current serial config is one of the allowed.
     */
     
    while ((nb_allowed_config > 0) && !valid_config_selected) {
        
        nb_allowed_config--;
        allowed_config = (SYS_UWORD16 *)
                          &(serial_info->allowed_config[nb_allowed_config]);
        
        if (*pt_current_config == *allowed_config)
            valid_config_selected = 1;
    }

    /*
	 * If not, the default configuration is selected.
	 */

    if (!valid_config_selected) {

        pt_current_config = (SYS_UWORD16 *)&(serial_info->default_config);

        #if (defined BLUETOOTH && (CHIPSET != 12))
          /*
           * Setup the global variable accordingly.
           * The following default value are identical to the ones defined at
           * the application initialization in init.c.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -