00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <kernel.h> 00010 #include <device.h> 00011 #include <tty.h> 00012 #include <vararg.h> 00013 00020 devcall ttyOpen(device *pdev, va_list ap) 00021 { 00022 struct tty *ptty = NULL; 00023 int dvnum = 0; 00024 00025 /* Check if TTY is already open */ 00026 if (pdev->controlblk) 00027 { return OK; } 00028 00029 /* Allocate a tty */ 00030 ptty = (struct tty *)ttyAlloc(); 00031 00032 ASSERT(NULL != ptty); 00033 00034 /* Mutually link tty record with device table entry */ 00035 pdev->controlblk = (char *)ptty; 00036 ptty->tty_dev = pdev; 00037 00038 /* Initialize input buffer */ 00039 ptty->iflags = 0; 00040 ptty->istart = 0; 00041 ptty->icount = 0; 00042 00043 /* Initialize output flags */ 00044 ptty->oflags = 0; 00045 00046 /* Second arg should be device index for physical hardware */ 00047 dvnum = va_arg(ap, int); 00048 ASSERT(!isbaddev(dvnum)); 00049 00050 ptty->tty_phw = &devtab[dvnum]; 00051 00052 return OK; 00053 }