Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *
0005  * Copyright (C) 2024 Kevin Kirspel
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
0017  * 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 AUTHOR OR CONTRIBUTORS BE LIABLE
0020  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0021  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0022  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0023  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0024  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0025  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0026  * SUCH DAMAGE.
0027  */
0028 
0029 #include <bsp.h>
0030 #include <stdio.h>
0031 #include <rtems.h>
0032 #include <rtems/libio.h>
0033 #include <rtems/error.h>
0034 #include <stdlib.h>
0035 #include <string.h>
0036 #include <assert.h>
0037 #include <bsp/fatal.h>
0038 #include <bsp/irq.h>
0039 #include <bsp/niosv.h>
0040 
0041 #include <rtems/score/riscv-utility.h>
0042 
0043 /* Local Definitaions */
0044 /* Local Structures */
0045 /* Local Functions */
0046 static void status_led_turn_on( uint32_t index );
0047 static void status_led_turn_off( uint32_t index );
0048 /* Local Variables */
0049 
0050 /* status_led_initialize --
0051  *     This routine registers the status led device
0052  *
0053  * PARAMETERS:
0054  *     major - major led device number
0055  *     minor - minor led device number (not used)
0056  *     arg - device initialize argument
0057  *
0058  * RETURNS:
0059  *     RTEMS error code (RTEMS_SUCCESSFUL if device initialized successfuly)
0060  */
0061 rtems_device_driver status_led_initialize (
0062   rtems_device_major_number major,
0063   rtems_device_minor_number minor,
0064   void *arg
0065 )
0066 {
0067   /* Local Variables */
0068   rtems_status_code status;
0069 
0070   /*
0071    * Register the devices
0072    */
0073   status = rtems_io_register_name ("/dev/status_led", major, minor );
0074   assert( status == RTEMS_SUCCESSFUL );
0075 
0076   return RTEMS_SUCCESSFUL;
0077 }
0078 
0079 /* status_led_open --
0080  *     Open status led device.
0081  *
0082  * PARAMETERS:
0083  *     major - major device number for led devices
0084  *     minor - minor device number for led
0085  *     arg - device opening argument
0086  *
0087  * RETURNS:
0088  *     RTEMS error code
0089  */
0090 rtems_device_driver status_led_open (
0091   rtems_device_major_number major,
0092   rtems_device_minor_number minor,
0093   void *arg
0094 )
0095 {
0096   return RTEMS_SUCCESSFUL;
0097 }
0098 
0099 /* status_led_close --
0100  *     Close status led device.
0101  *
0102  * PARAMETERS:
0103  *     major - major device number for led devices
0104  *     minor - minor device number for led
0105  *     arg - device close argument
0106  *
0107  * RETURNS:
0108  *     RTEMS error code
0109  */
0110 rtems_device_driver status_led_close (
0111   rtems_device_major_number major,
0112   rtems_device_minor_number minor,
0113   void *arg
0114 )
0115 {
0116   return RTEMS_SUCCESSFUL;
0117 }
0118 
0119 /* status_led_read --
0120  *     Read from the status led device
0121  *
0122  * PARAMETERS:
0123  *     major - major device number for led devices
0124  *     minor - minor device number for led
0125  *     arg - device read argument
0126  *
0127  * RETURNS:
0128  *     RTEMS error code
0129  */
0130 rtems_device_driver status_led_read (
0131   rtems_device_major_number major,
0132   rtems_device_minor_number minor,
0133   void *arg
0134 )
0135 {
0136   return RTEMS_SUCCESSFUL;
0137 }
0138 
0139 /* status_led_write --
0140  *     Write to the status led device
0141  *
0142  * PARAMETERS:
0143  *     major - major device number for led devices
0144  *     minor - minor device number for led
0145  *     arg - device write argument
0146  *
0147  * RETURNS:
0148  *     RTEMS error code
0149  */
0150 rtems_device_driver status_led_write (
0151   rtems_device_major_number major,
0152   rtems_device_minor_number minor,
0153   void *arg
0154 )
0155 {
0156   return RTEMS_SUCCESSFUL;
0157 }
0158 
0159 /* status_led_control --
0160  *     Handle status led device I/O control (IOCTL)
0161  *
0162  * PARAMETERS:
0163  *     major - major device number for led devices
0164  *     minor - minor device number for led
0165  *     arg - device ioctl argument
0166  *
0167  * RETURNS:
0168  *     RTEMS error code
0169  */
0170 rtems_device_driver status_led_control (
0171   rtems_device_major_number major,
0172   rtems_device_minor_number minor,
0173   void *arg
0174 )
0175 {
0176   /* Local Varaibles */
0177   rtems_libio_ioctl_args_t *args = arg;
0178   status_led_control_t *ctrl;
0179 
0180   /* Get Data */
0181   ctrl = ( status_led_control_t * )args->buffer;
0182   args->ioctl_return = 0;
0183 
0184   /* Parse Command */
0185   switch( args->command )
0186   {
0187     case IOCTL_STATUS_LED_TURN_ON :
0188       status_led_turn_on(ctrl->led_mask);
0189       break;
0190     case IOCTL_STATUS_LED_TURN_OFF :
0191       status_led_turn_off(ctrl->led_mask);
0192       break;
0193     default :
0194       args->ioctl_return = -1;
0195       break;
0196   }
0197   /* OK */
0198   return RTEMS_SUCCESSFUL;
0199 }
0200 
0201 /* status_led_turn_on --
0202  *     Turns the LED on
0203  *
0204  * PARAMETERS:
0205  *
0206  * RETURNS:
0207  *
0208  */
0209 void status_led_turn_on( uint32_t mask )
0210 {
0211   LED_PIO_REGS->outclear = mask;
0212 }
0213 
0214 /* status_led_turn_off --
0215  *     Turns the LED on
0216  *
0217  * PARAMETERS:
0218  *
0219  * RETURNS:
0220  *
0221  */
0222 void status_led_turn_off( uint32_t mask )
0223 {
0224   LED_PIO_REGS->outset = mask;
0225 }