Loading [MathJax]/extensions/tex2jax.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
console.h File Reference
#include <sys/spinlock.h>
Include dependency graph for console.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Console
 

Macros

#define KEY_F1   0xF1
 
#define KEY_F2   0xF2
 
#define KEY_F3   0XF3
 
#define KEY_F4   0xF4
 
#define KEY_F5   0xF5
 
#define KEY_F6   0xF6
 
#define KEY_F7   0xF7
 
#define KEY_F8   0xF8
 
#define KEY_F9   0xF9
 
#define KEY_F10   0xFA
 
#define KEY_F11   0xFB
 
#define KEY_F12   0XFC
 
#define CONSOLE_KEYBUF_MAXLEN   256
 

Typedefs

typedef struct Console Console
 

Functions

void Console_Init ()
 
char Console_Getc ()
 
void Console_Gets (char *str, size_t n)
 
void Console_Putc (char ch)
 
void Console_Puts (const char *str)
 
void Console_EnqueueKey (char key)
 

Data Structure Documentation

◆ Console

struct Console

Definition at line 22 of file console.h.

Collaboration diagram for Console:
[legend]
Data Fields
char keyBuf[CONSOLE_KEYBUF_MAXLEN]
Spinlock keyLock
int lastKey
int nextKey

Macro Definition Documentation

◆ CONSOLE_KEYBUF_MAXLEN

#define CONSOLE_KEYBUF_MAXLEN   256

Definition at line 20 of file console.h.

◆ KEY_F1

#define KEY_F1   0xF1

Definition at line 7 of file console.h.

◆ KEY_F10

#define KEY_F10   0xFA

Definition at line 16 of file console.h.

◆ KEY_F11

#define KEY_F11   0xFB

Definition at line 17 of file console.h.

◆ KEY_F12

#define KEY_F12   0XFC

Definition at line 18 of file console.h.

◆ KEY_F2

#define KEY_F2   0xF2

Definition at line 8 of file console.h.

◆ KEY_F3

#define KEY_F3   0XF3

Definition at line 9 of file console.h.

◆ KEY_F4

#define KEY_F4   0xF4

Definition at line 10 of file console.h.

◆ KEY_F5

#define KEY_F5   0xF5

Definition at line 11 of file console.h.

◆ KEY_F6

#define KEY_F6   0xF6

Definition at line 12 of file console.h.

◆ KEY_F7

#define KEY_F7   0xF7

Definition at line 13 of file console.h.

◆ KEY_F8

#define KEY_F8   0xF8

Definition at line 14 of file console.h.

◆ KEY_F9

#define KEY_F9   0xF9

Definition at line 15 of file console.h.

Typedef Documentation

◆ Console

typedef struct Console Console

Function Documentation

◆ Console_EnqueueKey()

void Console_EnqueueKey ( char  key)

Definition at line 75 of file console.c.

76{
80 return;
81 }
85}
Console consoles
Definition: console.c:15
char keyBuf[CONSOLE_KEYBUF_MAXLEN]
Definition: console.h:26
Spinlock keyLock
Definition: console.h:27
int lastKey
Definition: console.h:25
#define CONSOLE_KEYBUF_MAXLEN
Definition: console.h:20
void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock)
Definition: spinlock.c:109
void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock)
Definition: spinlock.c:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Console_Getc()

char Console_Getc ( )

Definition at line 47 of file console.c.

48{
49 while (1) {
52 char key = consoles.keyBuf[consoles.nextKey];
55 return key;
56 }
58
59 // Support serial debugging if interrupts are disabled
60 if (Serial_HasData()) {
61 char key = Serial_Getc();
62 switch (key) {
63 case '\r':
64 return '\n';
65 case 0x7f:
66 return '\b';
67 default:
68 return key;
69 }
70 }
71 }
72}
int nextKey
Definition: console.h:24
bool Serial_HasData()
Definition: sercons.c:73
char Serial_Getc()
Definition: sercons.c:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Console_Gets()

void Console_Gets ( char *  str,
size_t  n 
)

Definition at line 88 of file console.c.

89{
90 int i;
91
92 for (i = 0; i < (n - 1); i++)
93 {
94 char ch = Console_Getc();
95 if (ch == '\b') {
96 if (i > 0) {
97 Console_Putc(ch);
98 i--;
99 }
100 i--;
101 continue;
102 }
103 if (ch == '\n') {
104 Console_Putc('\n');
105 str[i] = '\0';
106 return;
107 }
108 if (ch == '\r') {
109 Console_Putc('\n');
110 str[i] = '\0';
111 return;
112 }
113 if (ch == '\t') {
114 Console_Putc('\t');
115 str[i] = '\t';
116 continue;
117 }
118 if (ch < 0x20)
119 {
120 // Unprintable character
121 continue;
122 }
123 Console_Putc(ch);
124 str[i] = ch;
125 }
126
127 str[i+1] = '\0';
128}
void Console_Putc(char ch)
Definition: console.c:131
char Console_Getc()
Definition: console.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Console_Init()

void Console_Init ( )

Definition at line 22 of file console.c.

23{
24 VGA_Init();
27
28 Console_Puts("Castor Operating System\n");
29
31
32 Spinlock_Init(&consoles.keyLock, "Console Keyboard Lock", SPINLOCK_TYPE_NORMAL);
33 consoles.nextKey = 0;
34 consoles.lastKey = 0;
35}
void Console_Puts(const char *str)
Definition: console.c:141
Spinlock consoleLock
Definition: console.c:14
void DebugConsole_Init()
Definition: debugcons.c:13
void Serial_Init(void)
Definition: sercons.c:40
#define SPINLOCK_TYPE_NORMAL
Definition: spinlock.h:12
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
Definition: spinlock.c:43
void VGA_Init(void)
Definition: vgacons.c:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Console_Putc()

void Console_Putc ( char  ch)

Definition at line 131 of file console.c.

132{
134 VGA_Putc(ch);
135 Serial_Putc(ch);
138}
void DebugConsole_Putc(short c)
Definition: debugcons.c:17
void Serial_Putc(char ch)
Definition: sercons.c:87
void VGA_Putc(short c)
Definition: vgacons.c:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Console_Puts()

void Console_Puts ( const char *  str)

Definition at line 141 of file console.c.

142{
144 VGA_Puts(str);
145 Serial_Puts(str);
148}
void DebugConsole_Puts(const char *str)
Definition: debugcons.c:22
void Serial_Puts(const char *str)
Definition: sercons.c:102
void VGA_Puts(const char *str)
Definition: vgacons.c:157
Here is the call graph for this function:
Here is the caller graph for this function: