Compare commits
2 Commits
5ae907ca5a
...
8b0354b709
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b0354b709 | ||
|
|
91d7affc23 |
@@ -40,10 +40,13 @@ char Serial::readReg(RegisterIndex reg) {
|
||||
}
|
||||
|
||||
int Serial::write(char out) {
|
||||
// TODO: Implement
|
||||
if(readReg(LINE_STATUS_REGISTER) & TRANSMITTER_EMPTY){
|
||||
writeReg(TRANSMIT_BUFFER_REGISTER, out);
|
||||
return out;
|
||||
}
|
||||
return -1;
|
||||
//TODO fix behavior when \r\n ist actually sent
|
||||
if(out == '\n')
|
||||
write('\r');
|
||||
|
||||
if(readReg(LINE_STATUS_REGISTER) & TRANSMITTER_EMPTY){
|
||||
writeReg(TRANSMIT_BUFFER_REGISTER, out);
|
||||
return out;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -5,55 +5,18 @@ SerialStream::SerialStream(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
||||
StopBits stop_bits, Parity parity)
|
||||
:Serial(port, baud_rate, data_bits, stop_bits, parity) {}
|
||||
|
||||
SerialStream kout = SerialStream();
|
||||
|
||||
void SerialStream::flush() {
|
||||
print(buffer, strlen(buffer));
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/3440726/what-is-the-proper-way-of-implementing-a-good-itoa-function
|
||||
// Yet, another good itoa implementation
|
||||
// returns: the length of the number string
|
||||
int itoa(int value, char *sp, int radix)
|
||||
{
|
||||
char tmp[16];// be careful with the length of the buffer
|
||||
char *tp = tmp;
|
||||
int i;
|
||||
unsigned v;
|
||||
|
||||
int sign = (radix == 10 && value < 0);
|
||||
if (sign)
|
||||
v = -value;
|
||||
else
|
||||
v = (unsigned)value;
|
||||
|
||||
while (v || tp == tmp)
|
||||
{
|
||||
i = v % radix;
|
||||
v /= radix;
|
||||
if (i < 10)
|
||||
*tp++ = i+'0';
|
||||
else
|
||||
*tp++ = i + 'a' - 10;
|
||||
}
|
||||
|
||||
int len = tp - tmp;
|
||||
|
||||
if (sign)
|
||||
{
|
||||
*sp++ = '-';
|
||||
len++;
|
||||
}
|
||||
|
||||
while (tp > tmp)
|
||||
*sp++ = *--tp;
|
||||
|
||||
return len;
|
||||
print(kout.buffer, kout.pos);
|
||||
kout.pos = 0;
|
||||
}
|
||||
|
||||
void SerialStream::setForeground(Color c) {
|
||||
write(0x1b);
|
||||
write('[');
|
||||
write('3');
|
||||
write(c + 0x30);
|
||||
kout << 30+c;
|
||||
flush();
|
||||
write('m');
|
||||
}
|
||||
|
||||
@@ -79,10 +42,13 @@ void SerialStream::reset() {
|
||||
|
||||
void SerialStream::setPos(int x, int y) {
|
||||
//char out[] = {0x1b, '[', 0, 0, ';', 0, 0, 'H', 0};
|
||||
*this << 0x1b;
|
||||
*this << '[';
|
||||
*this << dec << x;
|
||||
*this << ';' << y << 'H' << endl;
|
||||
//*this << 0x1b;
|
||||
write(0x1b);
|
||||
kout << '[';
|
||||
kout << dec << x;
|
||||
kout << ';';
|
||||
kout << dec << y;
|
||||
kout << 'H';
|
||||
flush();
|
||||
//itoa(x, &out[2], 10);
|
||||
//itoa(y, &out[5], 10);
|
||||
|
||||
@@ -141,3 +141,6 @@ class SerialStream : public OutputStream, public Serial {
|
||||
*/
|
||||
void print(char* str, int length);
|
||||
};
|
||||
|
||||
extern SerialStream kout;
|
||||
|
||||
|
||||
@@ -15,7 +15,4 @@ TextStream::TextStream(unsigned from_col,
|
||||
void TextStream::flush() {
|
||||
print(buffer,pos);
|
||||
pos = 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
18
main.cc
18
main.cc
@@ -49,7 +49,23 @@ extern "C" int main() {
|
||||
ss.setBackground(SerialStream::CYAN);
|
||||
ss.print("test", 4);
|
||||
ss.setPos(10, 10);
|
||||
ss.print("test", 4);
|
||||
ss.print("test\n", 5);
|
||||
ss.setBackground(SerialStream::BLACK);
|
||||
|
||||
kout << "Test <stream result> -> <expected>" << endl;
|
||||
kout << "bool: " << true << " -> true" << endl;
|
||||
kout << "zero: " << 0 << " -> 0" << endl;
|
||||
kout << "binary: " << bin << 42 << dec << " -> 0b101010" << endl;
|
||||
kout << "octal: " << oct << 42 << dec << " -> 052" << endl;
|
||||
kout << "hex: " << hex << 42 << dec << " -> 0x2a" << endl;
|
||||
kout << "uint64_t max: " << ~((uint64_t)0) << " -> 18446744073709551615" << endl;
|
||||
kout << "int64_t max: " << ~(1ll<<63) << " -> 9223372036854775807" << endl;
|
||||
kout << "int64_t min: " << (1ll<<63) << " -> -9223372036854775808" << endl;
|
||||
kout << "some int64_t: " << (-1234567890123456789) << " -> -1234567890123456789" << endl;
|
||||
kout << "some int64_t: " << (1234567890123456789) << " -> 1234567890123456789" << endl;
|
||||
kout << "pointer: " << reinterpret_cast<void*>(1994473406541717165ull)
|
||||
<< " -> 0x1badcafefee1dead" << endl;
|
||||
kout << "smiley: " << static_cast<char>(1) << endl;
|
||||
|
||||
/* Start application processors
|
||||
* To avoid unexpected behaviour, make sure that interrupts are not
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#include "stringbuffer.h"
|
||||
|
||||
void Stringbuffer::put(char c) { (void)c; }
|
||||
void Stringbuffer::put(char c) {
|
||||
buffer[pos++] = c;
|
||||
if(pos > 80)
|
||||
flush();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ kvm: all
|
||||
|
||||
# Execute Qemu with activated GDB stub and directly connect GDB to the spawned Qemu.
|
||||
gdb: all
|
||||
${VERBOSE} $(GDB) "$(DBGKERNEL)" \
|
||||
${VERBOSE} cgdb -d $(GDB) "$(DBGKERNEL)" \
|
||||
-ex "set arch $(DBGARCH)" \
|
||||
-ex "target remote | exec $(QEMU) -gdb stdio $(QEMUKERNEL) -smp $(QEMUCPUS) -S $(QEMUFLAGS) $(DBGFLAGS)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user