
#include <rtl_conf.h>
#if CONFIG_RT_MOUSEL
#include <rtl_posixio.h>
#include <errno.h>

//////////////////////////////////
//// POSIX TERMINAL FUNCTIONS ////
//////////////////////////////////

// RT_TTY_MAJOR defines the major number used by this device
#define RT_TTY_MAJOR 21

// This function can be implemented using a proccess running on user mode
// which read from keyboard

static ssize_t tty_read (struct rtl_file *file, char *buffer, size_t size, 
		         loff_t *s){
  
  int n, temp;
  for (n = 0; n < size; n++) {
//    temp = (char) rt_terminal_getchar ();
    if (temp == -1)
      return n;
    buffer [n] = temp;
  }
  return size;
}

static ssize_t tty_write (struct rtl_file *file, const char *buffer, 
		          size_t size, loff_t *s){
  return rt_terminal_putstring ((char *)buffer, size);  
}

static int tty_open (struct rtl_file *file){
  return 0;
}

static int tty_release (struct rtl_file *file){
  return 0;
}

static struct rtl_file_operations rtl_tty_fops = {
  NULL,
  tty_read,
  tty_write,
  NULL,
  NULL,
  tty_open,
  tty_release
};

/////////////////////////////////////////////////////

int init_rt_terminal(void){

  if (rtl_register_chrdev (RT_TTY_MAJOR, "rt_tty", &rtl_tty_fops)) {
    return -EIO;
  }

  return 0;
}

void cleanup_rt_terminal(void){
  rtl_unregister_chrdev(RT_TTY_MAJOR, "rt_tty");
}
#endif
