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

📄 serialswitch_core.c

📁 手机GSM TI 平台 串口 uart 驱动 源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
 * Purpose: No action. * * Parameters: See SER_tr_WriteChar. * * Return: none * ******************************************************************************/ static voiddummy_tr_WriteChar (T_tr_UartId device,                    char character){    /*     * No action.     */}/******************************************************************************* * *                          dummy_tr_WriteString * * Purpose: No action. * * Parameters: See SER_tr_WriteString. * * Return: none * ******************************************************************************/static voiddummy_tr_WriteString (T_tr_UartId device,                      char *buffer){    /*     * No action.     */}/******************************************************************************* * *                          dummy_tr_EnterSleep * * Purpose: No action. * * Parameters: See SER_tr_EnterSleep. * * Return: 1 * ******************************************************************************/static SYS_BOOLdummy_tr_EnterSleep (T_tr_UartId device){    return (1);}/******************************************************************************* * *                           dummy_tr_WakeUp * * Purpose: No action. * * Parameters: See SER_tr_WakeUp. * * Return: none * ******************************************************************************/static voiddummy_tr_WakeUp (T_tr_UartId device){    /*     * No action.     */}/******************************************************************************* * *                     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 VOIDanalyze_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 voidstart_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 voidset_flow_functions (int flow,                    T_SerialDriver serial_driver){    switch (serial_driver) {    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;    }}/******************************************************************************* * *                          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 * ******************************************************************************/voidSER_InitSerialConfig (T_AppliSerialInfo *serial_info){    int         uart_id;    int         flow;    SYS_UWORD16 serial_driver;    SYS_UWORD16 *allowed_config;    SYS_UWORD16  nb_allowed_config;      /* Type change from SYS_UWORD8 to SYS_UWORD16 to force                                          * alignment in structure serial_info.                                          * Due to change of compiler, structure 32-bit alignment                                          * is not necessary available, creating misalignment                                          * in serial_info */    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);    }    /*     * The serial data flow functions set is initialized.     */    flow = 0;    while (flow < SER_MAX_NUMBER_OF_FLOWS) {                serial_driver = (T_SerialDriver)                            (((*pt_current_config) >> (12 - flow * 4)) & 0x000F);        set_flow_functions (flow, serial_driver);        flow++;    }        /*     * Checks if both UARTs are used.     * If not, performs minimum initialization including Sleep Mode.     * Checks also if at least one UART is used by a Trace flow.     * If so, create a HISR in order to reset and restart the sleep timer     * in case of incoming characters.     */    uart_used = 0;    uart_used_for_trace = 0;    for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {        if (!(int_uart[uart_id].device_used))            initialize_uart_sleep (uart_id);        else { /* if (int_uart[uart_id].device_used) */            uart_used = 1;  /* At least one UART is used */            if (int_uart[uart_id].flow_type == TRACE_FLOW) {                /* At least one UART used by a Trace flow */                uart_used_for_trace = 1;            }        }    }    /*     * If at least one uart is used, create a timer to figure out if the system     * can enter deep sleep mode regarding the UARTs.     */    if (uart_used) {        (void) NU_Create_Timer (                   &uart_sleep_timer,                   "Sleep",                   &analyze_uart_sleep_timer_expiration,                   0, /* Parameter supplied to the routine: not used. */                   WAKE_UP_TIME_IN_TDMA,                   0, /* The timer expires once. */                   NU_DISABLE_TIMER);        /*         * If at least one uart is used by a Trace flow, create a HISR to reset         * and restart the sleep timer.         */        if (uart_used_for_trace) {            /*             * The HISR entry function is the same function than the one called             * by the Rx HISR of the UARTFAX, since the only aim is to reset             * and restart the sleep timer in case of incoming characters on             * the Trace UART.             */            (void) NU_Create_HISR (                       &timer_hisr_ctrl_block,                       "Tim_HISR",                       SER_restart_uart_sleep_timer,                       TIMER_HISR_PRIORITY,                       &(timer_hisr_stack[0]),                       TIMER_HISR_STACK_SIZE);        }    }}/******************************************************************************* * * All functions SER_tr_xxx and SER_fd_xxx call a function of the UART trace * driver or the UART fax & data driver. * All functions SER_bt_xxx call a function of the UART Bluetooth HCI driver. * See the function call for parameters and return values. * ******************************************************************************/voidSER_tr_Init (int serial_data_flow,             T_tr_Baudrate baudrate,             void (callback_function (void))){    tr_functions[serial_data_flow]->tr_Init (                tr_functions[serial_data_flow]->device, baudrate, callback_function);}SYS_UWORD32SER_tr_ReadNChars (int serial_data_flow,                   char *buffer,                   SYS_UWORD32 chars_to_read){    return (tr_functions[serial_data_flow]->tr_ReadNChars (                tr_functions[serial_data_flow]->device, buffer, chars_to_read));}SYS_UWORD32SER_tr_ReadNBytes (int serial_data_flow,                   char *buffer,                   SYS_UWORD32 chars_to_read,                   SYS_BOOL *eof_detected){    return (tr_functions[serial_data_flow]->tr_ReadNBytes (                tr_functions[serial_data_flow]->device, buffer, chars_to_read, eof_detected));}SYS_UWORD32SER_tr_WriteNChars (int serial_data_flow,                    char *buffer,                    SYS_UWORD32 chars_to_write){    return (tr_functions[serial_data_flow]->tr_WriteNChars (                tr_functions[serial_data_flow]->device, buffer, chars_to_write));}SYS_UWORD32SER_tr_EncapsulateNChars (int serial_data_flow,                          char *buffer,                          SYS_UWORD32 chars_to_write){    return (tr_functions[serial_data_flow]->tr_EncapsulateNChars (                tr_functions[serial_data_flow]->device, buffer, chars_to_write));}SYS_UWORD32SER_tr_WriteNBytes (int serial_data_flow,                    SYS_UWORD8 *buffer,                    SYS_UWORD32 chars_to_write){    return (tr_functions[serial_data_flow]->tr_WriteNBytes (                tr_functions[serial_data_flow]->device, buffer, chars_to_write));}voidSER_tr_WriteChar (int serial_data_flow,                  char character){    tr_functions[serial_data_flow]->tr_WriteChar (                tr_functions[serial_data_flow]->device, character);}voidSER_tr_WriteString (int serial_data_flow,                    char *buffer){    tr_functions[serial_data_flow]->tr_WriteString (                tr_functions[serial_data_flow]->device, buffer);}SYS_BOOLSER_tr_EnterSleep (int serial_data_flow){    return (tr_functions[serial_data_flow]->tr_EnterSleep (                tr_functions[serial_data_flow]->device));}voidSER_tr_WakeUp (int serial_data_flow){    tr_functions[serial_data_flow]->tr_WakeUp (                tr_functions[serial_data_flow]->device);}/******************************************************************************* *

⌨️ 快捷键说明

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