- added critical section - added interrupt global enable/disable - added console::getInstanveByName git-svn-id: http://moon:8086/svn/mips@76 a8ebac50-d88d-4704-bea3-6648445a41b3
125 lines
1.9 KiB
C
125 lines
1.9 KiB
C
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
#include <assert.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include "console.h"
|
|
|
|
extern con_if_t con_if;
|
|
|
|
// Funcs
|
|
con_if_entry_t const* con_getInterface(int file)
|
|
{
|
|
con_if_entry_t const *result = NULL;
|
|
int i;
|
|
for (i=0; i < con_if.length; i++)
|
|
{
|
|
if (file == con_if.con_if_entry[i].fd)
|
|
{
|
|
result = &con_if.con_if_entry[i];
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void const* con_getInstanceByName(char const *pName)
|
|
{
|
|
void const *result = NULL;
|
|
int i;
|
|
for (i=0; i < con_if.length; i++)
|
|
{
|
|
if (!strcmp(pName, con_if.con_if_entry[i].pName))
|
|
{
|
|
result = con_if.con_if_entry[i].pInst;
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int con_open(char const *pName)
|
|
{
|
|
int i;
|
|
assert(pName);
|
|
|
|
for (i=0; i < con_if.length; i++)
|
|
{
|
|
if (!strcmp(pName, con_if.con_if_entry->pName))
|
|
{
|
|
if (con_if.con_if_entry->openFunc)
|
|
{
|
|
con_if.con_if_entry->openFunc(&con_if.con_if_entry[i].pInst);
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int con_close(int fd)
|
|
{
|
|
|
|
}
|
|
|
|
void con_flush(int fd)
|
|
{
|
|
int c;
|
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
|
|
|
do
|
|
{
|
|
c = pIF->readchar(pIF->pInst);
|
|
|
|
} while(c > 0);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------
|
|
int readchar(int fd)
|
|
{
|
|
int c;
|
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
|
|
|
assert(pIF);
|
|
|
|
// busy read
|
|
do
|
|
{
|
|
c = pIF->readchar(pIF->pInst);
|
|
|
|
} while(c < 0);
|
|
|
|
return c;
|
|
}
|
|
|
|
void writechar(int fd, char c)
|
|
{
|
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
|
|
|
assert(pIF);
|
|
|
|
pIF->writechar(pIF->pInst, c);
|
|
|
|
}
|
|
|
|
void _putchar(int fd, char c)
|
|
{
|
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
|
|
|
assert(pIF);
|
|
if (c == 0x0A)
|
|
{
|
|
pIF->writechar(pIF->pInst, 0x0D);
|
|
}
|
|
pIF->writechar(pIF->pInst, c);
|
|
|
|
}
|
|
|
|
char _getchar()
|
|
{
|
|
return readchar(0);
|
|
}
|