File indexing completed on 2025-05-11 08:24:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifdef HAVE_CONFIG_H
0036 #include "config.h"
0037 #endif
0038
0039 #include "tmacros.h"
0040 #include <rtems/libio.h>
0041 #include <stdlib.h>
0042 #include <termios.h>
0043 #include <rtems/termiostypes.h>
0044 #include <rtems/dumpbuf.h>
0045 #include "termios_testdriver_polled.h"
0046
0047
0048 int termios_test_driver_inbyte_nonblocking(int port);
0049 void termios_test_driver_outbyte_polled(int port, char ch);
0050 ssize_t termios_test_driver_write_support(
0051 int minor,
0052 const char *buf,
0053 size_t len
0054 );
0055 int termios_test_driver_set_attributes(
0056 int minor,
0057 const struct termios *t
0058 );
0059
0060 #define TX_MAX 1024
0061 uint8_t Tx_Buffer[TX_MAX];
0062 int Tx_Index = 0;
0063
0064 void termios_test_driver_dump_tx(const char *c)
0065 {
0066 printf( "%s %d characters\n", c, Tx_Index );
0067 rtems_print_buffer( Tx_Buffer, Tx_Index );
0068 Tx_Index = 0;
0069 }
0070
0071 const uint8_t *Rx_Buffer;
0072 int Rx_Index;
0073 int Rx_Length;
0074 bool Rx_FirstTime = true;
0075
0076 void termios_test_driver_set_rx(
0077 const void *p,
0078 size_t len
0079 )
0080 {
0081 Rx_Buffer = p;
0082 Rx_Length = len;
0083 Rx_Index = 0;
0084 }
0085
0086 int termios_test_driver_inbyte_nonblocking( int port )
0087 {
0088 if ( Rx_FirstTime == true ) {
0089 Rx_FirstTime = false;
0090 return -1;
0091 }
0092 if ( Rx_Index >= Rx_Length )
0093 return -1;
0094 return Rx_Buffer[ Rx_Index++ ];
0095 }
0096
0097 void termios_test_driver_outbyte_polled(
0098 int port,
0099 char ch
0100 )
0101 {
0102 Tx_Buffer[Tx_Index++] = (uint8_t) ch;
0103 }
0104
0105 ssize_t termios_test_driver_write_support (int minor, const char *buf, size_t len)
0106 {
0107 size_t nwrite = 0;
0108
0109 while (nwrite < len) {
0110 termios_test_driver_outbyte_polled( minor, *buf++ );
0111 nwrite++;
0112 }
0113 return nwrite;
0114 }
0115
0116
0117
0118
0119
0120 int termios_test_driver_set_attributes(
0121 int minor,
0122 const struct termios *t
0123 )
0124 {
0125 return 0;
0126 }
0127
0128
0129
0130
0131 rtems_device_driver termios_test_driver_initialize(
0132 rtems_device_major_number major,
0133 rtems_device_minor_number minor,
0134 void *arg
0135 )
0136 {
0137 rtems_termios_initialize();
0138
0139
0140
0141
0142 (void) rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 );
0143
0144 return RTEMS_SUCCESSFUL;
0145 }
0146
0147 rtems_device_driver termios_test_driver_open(
0148 rtems_device_major_number major,
0149 rtems_device_minor_number minor,
0150 void * arg
0151 )
0152 {
0153 rtems_status_code sc;
0154 static const rtems_termios_callbacks Callbacks = {
0155 NULL,
0156 NULL,
0157 termios_test_driver_inbyte_nonblocking,
0158 termios_test_driver_write_support,
0159 termios_test_driver_set_attributes,
0160 NULL,
0161 NULL,
0162 TERMIOS_POLLED
0163 };
0164
0165 if ( minor > 2 ) {
0166 puts( "ERROR - Termios_testdriver - only 1 minor supported" );
0167 rtems_test_exit(0);
0168 }
0169
0170 sc = rtems_termios_open (major, minor, arg, &Callbacks);
0171 directive_failed( sc, "termios open" );
0172
0173 return RTEMS_SUCCESSFUL;
0174 }
0175
0176 rtems_device_driver termios_test_driver_close(
0177 rtems_device_major_number major,
0178 rtems_device_minor_number minor,
0179 void * arg
0180 )
0181 {
0182 return rtems_termios_close (arg);
0183 }
0184
0185 rtems_device_driver termios_test_driver_read(
0186 rtems_device_major_number major,
0187 rtems_device_minor_number minor,
0188 void * arg
0189 )
0190 {
0191 return rtems_termios_read (arg);
0192 }
0193
0194 rtems_device_driver termios_test_driver_write(
0195 rtems_device_major_number major,
0196 rtems_device_minor_number minor,
0197 void * arg
0198 )
0199 {
0200 return rtems_termios_write (arg);
0201 }
0202
0203 rtems_device_driver termios_test_driver_control(
0204 rtems_device_major_number major,
0205 rtems_device_minor_number minor,
0206 void * arg
0207 )
0208 {
0209 return rtems_termios_ioctl (arg);
0210 }