Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:32

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2010.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <rtems.h>
0034 #include "test_driver.h"
0035 #include <rtems/libio.h>
0036 #include <rtems/devnull.h>
0037 /* 
0038  * The test driver routines are mostly derived from the null driver routines.
0039  */
0040 uint32_t   TEST_major;
0041 static char initialized;
0042 
0043 /*  testDriver_initialize
0044  *
0045  *  This routine is the test device driver init routine.
0046  *
0047  *  Input parameters:
0048  *    major - device major number
0049  *    minor - device minor number
0050  *    pargp - pointer to parameter block
0051  *
0052  *  Output parameters:
0053  *    rval       - RTEMS_SUCCESSFUL
0054  */
0055 rtems_device_driver testDriver_initialize(
0056   rtems_device_major_number major,
0057   rtems_device_minor_number minor RTEMS_UNUSED,
0058   void *pargp RTEMS_UNUSED
0059 )
0060 {
0061   rtems_device_driver status;
0062 
0063   if ( !initialized ) {
0064     initialized = 1;
0065 
0066     status = rtems_io_register_name(
0067       "/dev/test",
0068       major,
0069       (rtems_device_minor_number) 0
0070     );
0071 
0072     if (status != RTEMS_SUCCESSFUL)
0073       rtems_fatal_error_occurred(status);
0074 
0075     TEST_major = major;
0076   }
0077 
0078   return RTEMS_SUCCESSFUL;
0079 }
0080 
0081 /*  testDriver_open
0082  *
0083  *  This routine is the test device driver open routine.
0084  *
0085  *  Input parameters:
0086  *    major - device major number
0087  *    minor - device minor number
0088  *    pargb - pointer to open parameter block
0089  *
0090  *  Output parameters:
0091  *    rval       - RTEMS_SUCCESSFUL
0092  */
0093 rtems_device_driver testDriver_open(
0094   rtems_device_major_number major RTEMS_UNUSED,
0095   rtems_device_minor_number minor RTEMS_UNUSED,
0096   void *pargp RTEMS_UNUSED
0097 )
0098 {
0099   return RTEMS_SUCCESSFUL;
0100 }
0101 
0102 /*  testDriver_close
0103  *
0104  *  This routine is the test device driver close routine.
0105  *
0106  *  Input parameters:
0107  *    major - device major number
0108  *    minor - device minor number
0109  *    pargb - pointer to close parameter block
0110  *
0111  *  Output parameters:
0112  *    rval       - RTEMS_SUCCESSFUL
0113  */
0114 rtems_device_driver testDriver_close(
0115   rtems_device_major_number major RTEMS_UNUSED,
0116   rtems_device_minor_number minor RTEMS_UNUSED,
0117   void *pargp RTEMS_UNUSED
0118 )
0119 {
0120   return RTEMS_SUCCESSFUL;
0121 }
0122 
0123 /*  testDriver_read
0124  *
0125  *  This routine is the test device driver read routine.
0126  *
0127  *  Input parameters:
0128  *    major - device major number
0129  *    minor - device minor number
0130  *    pargp - pointer to read parameter block
0131  *
0132  *  Output parameters:
0133  *    rval       - RTEMS_SUCCESSFUL
0134  */
0135 rtems_device_driver testDriver_read(
0136   rtems_device_major_number major RTEMS_UNUSED,
0137   rtems_device_minor_number minor RTEMS_UNUSED,
0138   void *pargp
0139 )
0140 {
0141   rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) pargp;
0142 
0143   if ( rw_args ) {
0144     if( rw_args->count == 5 )
0145       rw_args->bytes_moved = 0;
0146     else {
0147       rw_args->bytes_moved = 0;
0148       return RTEMS_NOT_IMPLEMENTED;
0149     }
0150   }
0151   
0152   return RTEMS_SUCCESSFUL;
0153 }
0154 
0155 /*  testDriver_write
0156  *
0157  *  This routine is the test device driver write routine.
0158  *
0159  *  Input parameters:
0160  *    major - device major number
0161  *    minor - device minor number
0162  *    pargp - pointer to write parameter block
0163  *
0164  *  Output parameters:
0165  *    rval       - RTEMS_SUCCESSFUL
0166  */
0167 rtems_device_driver testDriver_write(
0168   rtems_device_major_number major RTEMS_UNUSED,
0169   rtems_device_minor_number minor RTEMS_UNUSED,
0170   void *pargp
0171 )
0172 {
0173   rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) pargp;
0174 
0175   if ( rw_args ) {
0176     if( rw_args->count == 5 )
0177       return null_write( 0, 0, pargp );
0178     else {
0179       rw_args->bytes_moved = 0;
0180       return RTEMS_NOT_IMPLEMENTED;
0181     }
0182   }
0183 
0184   return RTEMS_SUCCESSFUL;
0185 }
0186 
0187 /*  testDriver_control
0188  *
0189  *  This routine is the test device driver control routine.
0190  *
0191  *  Input parameters:
0192  *    major - device major number
0193  *    minor - device minor number
0194  *    pargp - pointer to cntrl parameter block
0195  *
0196  *  Output parameters:
0197  *    rval       - RTEMS_SUCCESSFUL
0198  */
0199 
0200 rtems_device_driver testDriver_control(
0201   rtems_device_major_number major RTEMS_UNUSED,
0202   rtems_device_minor_number minor RTEMS_UNUSED,
0203   void *pargp RTEMS_UNUSED
0204 )
0205 {
0206   return RTEMS_NOT_IMPLEMENTED;
0207 }