📄 serialswitch_core.c
字号:
* SER_UartSleepStatus * * Purpose: This function checks if both UARTs are ready to enter Deep Sleep. * * Parameters: In : none * Out: none * * Return: 0 : Deep Sleep is not possible. * >= 1 : Deep Sleep is possible. * ******************************************************************************/SYS_BOOLSER_UartSleepStatus (void){ t_uart *uart; int uart_id; SYS_BOOL status; /* * Check first if the sleep timer is active or if a Dynamic Switch is * being processed. A return is used to simplify the code. */ if (uart_sleep_timer_enabled) return (0); /* * Check if both UARTs are ready to enter Deep Sleep. */ status = 1; uart_id = 0; while ((uart_id < NUMBER_OF_TR_UART) && (status)) { uart = &(int_uart[uart_id]); /* * Check if the specified UART is actually used. */ if (uart->device_used) { /* * Check if the specified UART is used by a Trace or * by a Fax & Data flow. */ if (uart->flow_type == TRACE_FLOW) status = SER_tr_EnterSleep (uart->flow_id); else status = 0; if (status) { /* * The specified UART is now set up for Deep Sleep. */ uart->deep_sleep_set_up = 1; } } uart_id++; } /* * Check if Deep Sleep is finally possible. * If not revert eventual Deep Sleep settings. */ if (!status) { for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { uart = &(int_uart[uart_id]); /* * If the specified used UART has already been set up for * Deep Sleep, revert these settings. */ if ((uart->device_used) && (uart->deep_sleep_set_up)) { /* * Check if the specified UART is used by a Trace or * by a Fax & Data flow. * Bluetooth HCI can not yet handled Deep Sleep Mode. */ if (uart->flow_type == TRACE_FLOW) SER_tr_WakeUp (uart->flow_id); uart->deep_sleep_set_up = 0; } } } return (status);}/******************************************************************************* * * SER_WakeUpUarts * * Purpose: This function wakes up used UARTs after Deep Sleep. * * Parameters: In : none * Out: none * * Return: none * ******************************************************************************/voidSER_WakeUpUarts (void){ t_uart *uart; int uart_id; if (uart_sleep_timer_enabled) start_uart_sleep_timer (); for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { uart = &(int_uart[uart_id]); /* * Check if the specified UART is actually used, and has not yet * been waked up. */ if ((uart->device_used) && (uart->deep_sleep_set_up)) { /* * Check if the specified UART is used by a Trace or * by a Fax & Data flow. * Bluetooth HCI can not yet handled Deep Sleep Mode. */ if (uart->flow_type == TRACE_FLOW) SER_tr_WakeUp (uart->flow_id); /* * The specified UART is no more set up for Deep Sleep. */ uart->deep_sleep_set_up = 0; } }}/******************************************************************************* * * SER_restart_uart_sleep_timer * * Purpose : Resets and restarts the sleep timer each time some characters are * received. * * Arguments: In : none * Out: none * * Returns : none * ******************************************************************************/voidSER_restart_uart_sleep_timer (void){ /* * First disable the timer. */ (void) NU_Control_Timer (&uart_sleep_timer, NU_DISABLE_TIMER); /* * Then start again this timer for a new period. */ start_uart_sleep_timer ();}/******************************************************************************* * * SER_activate_timer_hisr * * Purpose : Activates the timer HISR to reset and restart the sleep timer * each time some characters are received. * * Arguments: In : none * Out: none * * Returns : none * ******************************************************************************/voidSER_activate_timer_hisr (void){ (void) NU_Activate_HISR (&timer_hisr_ctrl_block);}#if ((CHIPSET == 2) || (CHIPSET == 3))/******************************************************************************* * * SER_uart_handler * * Purpose : UART interrupt handler. * * Arguments: In : none * Out: none * * Returns : none * ******************************************************************************/voidSER_uart_handler (void){ SYS_UWORD8 interrupt_status; t_uart *uart; int uart_id; SYS_BOOL it_identified; it_identified = 0; /* * Check first for a wake-up interrupt. */ uart_id = 0; while ((uart_id < NUMBER_OF_TR_UART) && (!it_identified)) { uart = &(int_uart[uart_id]); interrupt_status = READ_UART_REGISTER (uart, SSR); if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ it_identified = 1; uart_sleep_timer_enabled = 1; DISABLE_WAKE_UP_INTERRUPT (uart); } uart_id++; } /* * If no wake-up interrupt has been detected, check then systematically * both UARTs for other interrupt causes. */ if (!it_identified) { for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { uart = &(int_uart[uart_id]); interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; if (!(interrupt_status & IT_NOT_PENDING)) { it_identified = 1; (*(uart->interrupt_handler)) (uart_id, interrupt_status); } else { if ((uart_id == UA_UART_1) && (!it_identified)) uart_spurious_interrupts++; } } }}#elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12))/******************************************************************************* * * SER_uart_modem_handler * * Purpose : UART MODEM interrupt handler. * * Arguments: In : none * Out: none * * Returns : none * ******************************************************************************/voidSER_uart_modem_handler (void){ SYS_UWORD8 interrupt_status; t_uart *uart; SYS_BOOL it_wakeup_identified; it_wakeup_identified = 0; uart = &(int_uart[UA_UART_1]); /* * Check first for a wake-up interrupt. */ interrupt_status = READ_UART_REGISTER (uart, SSR); if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ it_wakeup_identified = 1; uart_sleep_timer_enabled = 1; DISABLE_WAKE_UP_INTERRUPT (uart); } /* * If no wake-up interrupt has been detected, check UART for other * interrupt causes. */ if (!it_wakeup_identified) { interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; if (!(interrupt_status & IT_NOT_PENDING)) (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status); else uart_modem_spurious_interrupts++; }}/******************************************************************************* * * SER_uart_irda_handler * * Purpose : UART IrDA interrupt handler. * * Arguments: In : none * Out: none * * Returns : none * ******************************************************************************/voidSER_uart_irda_handler (void){ SYS_UWORD8 interrupt_status; t_uart *uart; SYS_BOOL it_wakeup_identified; it_wakeup_identified = 0; uart = &(int_uart[UA_UART_0]); /* * Check first for a wake-up interrupt. */ interrupt_status = READ_UART_REGISTER (uart, SSR); if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ it_wakeup_identified = 1; uart_sleep_timer_enabled = 1; DISABLE_WAKE_UP_INTERRUPT (uart); } /* * If no wake-up interrupt has been detected, check UART for other * interrupt causes. */ if (!it_wakeup_identified) { interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; if (!(interrupt_status & IT_NOT_PENDING)) (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status); else uart_irda_spurious_interrupts++; }}#endif#if (CHIPSET == 12) /******************************************************************************* * * SER_uart_modem2_handler * * Purpose : UART IrDA interrupt handler. * * Arguments: In : none * Out: none * * Returns : none * ******************************************************************************/ void SER_uart_modem2_handler (void) { SYS_UWORD8 interrupt_status; t_uart *uart; SYS_BOOL it_wakeup_identified; it_wakeup_identified = 0; uart = &(int_uart[UA_UART_2]); /* * Check first for a wake-up interrupt. */ interrupt_status = READ_UART_REGISTER (uart, SSR); if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ it_wakeup_identified = 1; uart_sleep_timer_enabled = 1; DISABLE_WAKE_UP_INTERRUPT (uart); } /* * If no wake-up interrupt has been detected, check UART for other * interrupt causes. */ if (!it_wakeup_identified) { interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; if (!(interrupt_status & IT_NOT_PENDING)) (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status); else uart_modem2_spurious_interrupts++; } }#endif/* * Temporary functions. */voidUT_Init (int device_id, int baudrate, void (callback_function (void))){ SER_tr_Init (SER_PROTOCOL_STACK, baudrate, callback_function);}SYS_UWORD32UT_ReadNChars (int device_id, char *buffer, SYS_UWORD32 chars_to_read){ return (SER_tr_ReadNChars (SER_PROTOCOL_STACK, buffer, chars_to_read));}SYS_UWORD32UT_WriteNChars (int device_id, char *buffer, SYS_UWORD32 chars_to_write){ return (SER_tr_WriteNChars (SER_PROTOCOL_STACK, buffer, chars_to_write));}voidUT_WriteChar (int device_id, char character){ SER_tr_WriteChar (SER_PROTOCOL_STACK, character);}voidUT_WriteString (int device_id, char *buffer){ SER_tr_WriteString (SER_PROTOCOL_STACK, buffer);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -