Overview   API Reference  

serial_con.hpp

00001 #if !defined(__SERIAL_CON_HPP__)
00002 #define __SERIAL_CON_HPP__
00003 
00004 //
00005 // local includes
00006 //
00007 #include "serial_driver.hpp"
00008 #include "con_terminal.hpp"
00009 
00013 struct serial_con : public serial_driver, public con_terminal
00014 {
00015     static const int BUFFER_SIZE = 256;
00016 
00017   protected:
00018     char buffer[BUFFER_SIZE+1], *ptr;
00019 
00020   public:
00021     inline serial_con(const color_t fgcolor=DEFAULT_FGCOLOR, const color_t bgcolor=DEFAULT_BGCOLOR,
00022                       const rect_t &margins=((rect_t){x: 0, y: 0, w: 0, h: 0}))
00023         : con_terminal(fgcolor, bgcolor, margins), ptr(buffer)
00024     {
00025         if (!is_open()) log::error("%s: disabled\n", name());
00026     }
00027 
00028     //
00029     // serial_driver: override name, reset & write
00030     //
00031     virtual inline const char *name(void) const
00032     {
00033         return L4VMM_DRIVER" CON serial";
00034     }
00035 
00036     virtual inline int reset(void)
00037     {
00038         return con_terminal::reset();
00039     }
00040 
00041     virtual inline int write(uint8_t c)
00042     {
00043         //
00044         // linux printk prints \r\n at the end of a line, so skip \r.
00045         //     do not print it. otherwise the line is lost.
00046         //
00047         if (c == '\r') return 0;
00048 
00049         //
00050         // cache until a newline appears or the buffer overflows.
00051         //
00052         *ptr++=c;
00053         return ((c == '\n') || (ptr - buffer > BUFFER_SIZE)) ? do_print() : 0;
00054     }
00055 
00056   private:
00057     inline int do_print(void)
00058     {
00059         *ptr=0;
00060         return print(ptr=buffer);
00061     }
00062 };
00063 
00064 #endif
00065 
00066 // ***** end of source ***** //
00067 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008