📄 sdc.c
字号:
ch = uart->rx_buffer[uart->rx_buffer_read++]; /* If read pointer is at end, wrap it around */ if (uart->rx_buffer_read == uart->sd_buffer_size) uart->rx_buffer_read = 0; /* Set the status to reflect removal of the character */ if (uart->rx_buffer_write == uart->rx_buffer_read) uart->rx_buffer_status = NU_BUFFER_EMPTY; else uart->rx_buffer_status = NU_BUFFER_DATA; } /* Return to user mode */ NU_USER_MODE_ISR(); return (ch); } /* endif mode */#ifdef NU_ENABLE_PPP else if (uart->communication_mode == MDM_TERMINAL_COMMUNICATION || uart->communication_mode == MDM_NETWORK_COMMUNICATION) /**************** Begin Port Specific Section **************/ ch = SD_INBYTE (uart->base_address + SD_DR_OFFSET); /* Return to user mode */ NU_USER_MODE_ISR(); return (ch); /**************** End Port Specific Section ****************/#endif /* NU_ENABLE_PPP */ /* Return to user mode */ NU_USER_MODE_ISR(); return (ch);}/***************************************************************************** FUNCTION * * SDC_Carrier * * DESCRIPTION * * This function checks for a carrier. * * INPUTS * * none * * OUTPUTS * * STATUS : The status of the detection. * ****************************************************************************/STATUS SDC_Carrier(SD_PORT *uart){ return (NU_TRUE);}/**************************************************************************** Note: All functions below this point are generic and should not require any changes to support other UARTS. ****************************************************************************//***************************************************************************** FUNCTION * * SDC_Put_String * * DESCRIPTION * * This writes a null-terminated string out to the serial port. * * INPUTS * * CHAR * : String to be written to the serial port. * SD_PORT * : Serial port to send the string to. * * OUTPUTS * * none * ****************************************************************************/VOID SDC_Put_String(CHAR *str, SD_PORT *uart){ NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE_ISR(); /* Grab the semaphore so that strings between threads do not get mixed. */ if (NU_Obtain_Semaphore(uart->sd_semaphore, NU_SUSPEND) == NU_SUCCESS) { /* Send out the string. */ for (; *str != 0; str++) SDC_Put_Char(*str, uart); /* Allow other threads to use this service. */ NU_Release_Semaphore (uart->sd_semaphore); } /* Return to user mode */ NU_USER_MODE_ISR();}/***************************************************************************** FUNCTION * * SDC_Data_Ready * * DESCRIPTION * * This function checks to see if there are any characters in the * receive buffer. A status value is returned indicating whether * characters are present in the receive buffer. * * INPUTS * * SD_PORT * : Serial port to check for data. * * OUTPUTS * * STATUS The status indicates the * presence of characters. * ****************************************************************************/STATUS SDC_Data_Ready(SD_PORT *port){ NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE_ISR(); /* Check the status. */ if((port->rx_buffer_status == NU_BUFFER_FULL) || (port->rx_buffer_status == NU_BUFFER_DATA)) { /* Return to user mode */ NU_USER_MODE_ISR(); return (NU_TRUE); } else { /* Return to user mode */ NU_USER_MODE_ISR(); return (NU_FALSE); }}/***************************************************************************** FUNCTION * * SDC_Change_Communication_Mode * * DESCRIPTION * * This function switches the serial port between terminal mode and * network mode. The mode affects how incoming characters are directed. * * INPUTS * * INT : The mode of operation desired. * * OUTPUTS * * none * ****************************************************************************/VOID SDC_Change_Communication_Mode(INT mode, SD_PORT *uart){ uart->communication_mode = mode;} /* SDC_Change_Communication_Mode *//***************************************************************************** FUNCTION * * SDC_Reset * * DESCRIPTION * * This function intializes the data variables associated with a UART * * INPUTS * * SD_PORT * : Serial port to reset * * OUTPUTS * * STATUS : Returns URT_SUCCESS if successful initialization, * else a negative value is returned. * ****************************************************************************/VOID SDC_Reset (SD_PORT *uart){ /* Ini the error counters */ uart->frame_errors = 0; uart->overrun_errors = 0; uart->parity_errors = 0; uart->busy_errors = 0; uart->general_errors = 0;}/**************************************************************************** FUNCTION * * URT_Init_Port * * DESCRIPTION * * This function intializes the data variables associated with a UART * * INPUTS * * SD_PORT * : Serial port to reset * * OUTPUTS * * STATUS : Returns URT_SUCCESS if successful initialization, * else a negative value is returned. * ****************************************************************************/#ifdef NU_ENABLE_PPPSTATUS URT_Init_Port(DV_DEVICE_ENTRY *device){ SD_PORT *uart; STATUS ret_status; /* Get a pointer to the UART layer of this device. */ uart = &((PPP_LAYER *) device->ppp_layer)->uart; /* Init the serial port, copy init parameters from the device structure. */ uart->com_port = device->dev_com_port; uart->baud_rate = device->dev_baud_rate; uart->data_bits = device->dev_data_bits; uart->stop_bits = device->dev_stop_bits; uart->parity = device->dev_parity; uart->data_mode = device->dev_data_mode; uart->vector = device->dev_vect; uart->driver_options = device->dev_driver_options; uart->communication_mode = MDM_TERMINAL_COMMUNICATION; uart->sd_buffer_size = (2 * (PPP_MTU + PPP_FCS_SIZE + PPP_MAX_PROTOCOL_SIZE + PPP_MAX_ADDR_CONTROL_SIZE)); /* Init the port */ ret_status = NU_SD_Init_Port (uart); if (ret_status == NU_SUCCESS) { /* Copy the vector back into the device entry just in case the UART driver changed it. */ device->dev_vect = uart->vector; } return (ret_status);}#endif /* NU_ENABLE_PPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -