sci.c
来自「RTEMS (Real-Time Executive for Multiproc」· C语言 代码 · 共 1,681 行 · 第 1/4 页
C
1,681 行
// THIS IS ACTUALLY A BAD THING - SETTING LINE PARAMETERS HERE // IT SHOULD BE DONE THROUGH TCSETATTR() WHEN THE CONSOLE IS OPENED!!!// SciSetBaud(115200); // set the baud rate// SciSetBaud( 57600); // set the baud rate// SciSetBaud( 38400); // set the baud rate SciSetBaud( 19200); // set the baud rate// SciSetBaud( 9600); // set the baud rate SciSetParity(SCI_PARITY_NONE); // set no parity SciSetDataBits(SCI_8_DATA_BITS); // set 8 data bits SciEnableTransmitter(); // enable the xmitter SciEnableReceiver(); // enable the rcvr return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciPolledClose* Desc: close routine for the device driver, same for both* Inputs: major - device number* minor - device number* args - unused* Outputs: success/fail* Errors: none* Scope: public termios API****************************************************************************/signed32 SciPolledClose( signed32 major, signed32 minor, void *arg){ SciDisableAllInterrupts(); return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciPolledRead* Desc: polling based read routine for the uart* Inputs: minor - device number* Outputs: error or the character read* Errors: none* Scope: public API****************************************************************************/signed32 SciPolledRead( signed32 minor){ if ( minor != SCI_MINOR ) // check the minor dev num { return -1; // return error } if ( SciCharAvailable() ) // if a char is available { return SciReadCharNoWait(); // read the rx data register } return -1; // return error}/***************************************************************************** Func: SciPolledWrite* Desc: writes out characters in polled mode, waiting for the uart* check in console_open, but we only seem to use interrupt mode* Inputs: minor - device number* buf - points to the data* len - how many bytes* Outputs: error or number of bytes written* Errors: none* Scope: public termios API****************************************************************************/signed32 SciPolledWrite( signed32 minor, const char *buf, signed32 len){ signed32 written = 0; if ( minor != SCI_MINOR ) // check minor device num { return -1; } if ( SciOpened == DRIVER_OPENED ) // is the driver api open? { return -1; // toss the data } // send each byte in the string out the port while ( written < len ) { SciWriteCharWait(*buf++); // send a byte written++; // increment counter } return written; // return count}///////////////////////////////////////////////////////////////////////////////// SECTION 4// DEVICE DRIVER PUBLIC API ENTRY POINTS////////////////////////////////////////////////////////////////////////////////***************************************************************************** Func: SciInit* Desc: Initialize the lasers device driver and hardware* Inputs: major - the major device number which is assigned by rtems* minor - the minor device number which is undefined at this point* arg - ?????* Outputs: RTEMS_SUCCESSFUL* Errors: None.* Scope: public API****************************************************************************/rtems_device_driver SciInitialize ( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){// rtems_status_code status;//printk("%s\r\n", __FUNCTION__); // register the SCI device name for termios console i/o // this is done over in console.c which doesn't seem exactly right // but there were problems doing it here...// status = rtems_io_register_name( "/dev/sci", major, 0 );// if (status != RTEMS_SUCCESSFUL)// rtems_fatal_error_occurred(status); SciMajor = major; // save the rtems major number SciOpened = DRIVER_CLOSED; // initial state is closed // if you have an interrupt handler, install it here SciInited = 1; // set the inited flag return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciOpen* Desc: device driver open routine* you must open a device before you can anything else* only one process can have the device opened at a time* you could look at the task id to restrict access if you want* Inputs: major - the major device number assigned by rtems* minor - the minor device number assigned by us* arg - ?????* Outputs: see below* Errors: none* Scope: public API****************************************************************************/rtems_device_driver SciOpen ( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){//printk("%s major=%d minor=%d\r\n", __FUNCTION__,major,minor); if (SciInited == 0) // must be initialized first! { return RTEMS_NOT_CONFIGURED; } if (minor != SCI_MINOR) { return RTEMS_INVALID_NAME; // verify minor number } if (SciOpened == DRIVER_OPENED) { return RTEMS_RESOURCE_IN_USE; // already opened! } SciOpened = DRIVER_OPENED; // set the opened flag return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciClose* Desc: device driver close routine* the device must be opened before you can close it* the device must be closed before someone (else) can open it* Inputs: major - the major device number* minor - the minor device number* arg - ?????* Outputs: see below* Errors: none* Scope: public API****************************************************************************/rtems_device_driver SciClose ( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){//printk("%s major=%d minor=%d\r\n", __FUNCTION__,major,minor); if (minor != SCI_MINOR) { return RTEMS_INVALID_NAME; // check the minor number } if (SciOpened != DRIVER_OPENED) { return RTEMS_INCORRECT_STATE; // must be opened first } SciOpened = DRIVER_CLOSED; // set the flag return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciRead* Desc: device driver read routine* this function is not meaningful for the laser devices* Inputs: major - the major device number* minor - the minor device number* arg - read/write arguments* Outputs: see below* Errors: none* Scope: public API****************************************************************************/rtems_device_driver SciRead ( rtems_device_major_number major, rtems_device_minor_number minor, void *arg){ rtems_libio_rw_args_t *rw_args; // ptr to argument struct unsigned8 *buffer; unsigned16 length; rw_args = (rtems_libio_rw_args_t *) arg; // arguments to read() if (minor != SCI_MINOR) { return RTEMS_INVALID_NAME; // check the minor number } if (SciOpened == DRIVER_CLOSED) { return RTEMS_INCORRECT_STATE; // must be opened first } buffer = rw_args->buffer; // points to user's buffer length = rw_args->count; // how many bytes they want// *buffer = SciReadCharWait(); // wait for a character // if there isn't a character available, wait until one shows up // or the timeout period expires, which ever happens first if ( SciRcvBufCount == 0 ) // no chars { // wait for someone to wake me up... //rtems_task_wake_after(SciReadTimeout); } if ( SciRcvBufCount ) // any characters locally? { *buffer = SciRcvBufGetChar(); // get the character rw_args->bytes_moved = 1; // how many we actually read } return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciWrite* Desc: device driver write routine* this function is not meaningful for the laser devices* Inputs: major - the major device number* minor - the minor device number* arg - read/write arguments* Outputs: see below* Errors: non3* Scope: public API****************************************************************************/rtems_device_driver SciWrite ( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ rtems_libio_rw_args_t *rw_args; // ptr to argument struct unsigned8 *buffer; unsigned16 length; rw_args = (rtems_libio_rw_args_t *) arg; if (minor != SCI_MINOR) { return RTEMS_INVALID_NAME; // check the minor number } if (SciOpened == DRIVER_CLOSED) { return RTEMS_INCORRECT_STATE; // must be opened first } buffer = (unsigned8*)rw_args->buffer; // points to data length = rw_args->count; // how many bytes while (length--) { SciWriteCharWait(*buffer++); // send the bytes out } rw_args->bytes_moved = rw_args->count; // how many we wrote return RTEMS_SUCCESSFUL;}/***************************************************************************** Func: SciControl* Desc: device driver control routine* see below for an example of how to use the ioctl interface* Inputs: major - the major device number* minor - the minor device number* arg - io control args* Outputs: see below* Errors: none* Scope: public API****************************************************************************/rtems_device_driver SciControl ( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ rtems_libio_ioctl_args_t *args = arg; // rtems arg struct unsigned16 command; // the cmd to execute unsigned16 unused; // maybe later unsigned16 *ptr; // ptr to user data //printk("%s major=%d minor=%d\r\n", __FUNCTION__,major,minor); // do some sanity checking if (minor != SCI_MINOR) { return RTEMS_INVALID_NAME; // check the minor number } if (SciOpened == DRIVER_CLOSED) { return RTEMS_INCORRECT_STATE; // must be open first } if (args == 0) { return RTEMS_INVALID_ADDRESS; // must have args } args->ioctl_return = -1; // assume an error command = args->command; // get the command ptr = args->buffer; // this is an address unused = *ptr; // brightness if (command == SCI_SEND_BREAK) // process the command { SciSendBreak(); // send break char } args->ioctl_return = 0; // return status return RTEMS_SUCCESSFUL;}///////////////////////////////////////////////////////////////////////////////// SECTION 5
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?