Xyris  0.5
RS232 Namespace Reference

Functions

int vprintf (const char *fmt, va_list args)
 
int printf (const char *format,...)
 
void init (uint16_t com_id)
 
size_t read (char *buf, size_t count)
 
size_t write (const char *buf, size_t count)
 
int close ()
 

Function Documentation

◆ close()

int RS232::close ( )

Closes the serial input buffer and frees all of the data contained within.

Returns
int Returns 0 on success and -1 on error. Errno is set appropriately.

Definition at line 168 of file rs232.cpp.

169 {
170  return 0;
171 }

◆ init()

void RS232::init ( uint16_t  com_id)

Activates the RS232 serial driver.

Definition at line 112 of file rs232.cpp.

113 {
114  // Register the IRQ callback
115  rs_232_port_base = com_id;
116  uint8_t IRQ = 0x20 + (com_id == RS_232_COM1 ? RS_232_COM1_IRQ : RS_232_COM2_IRQ);
117  Interrupts::registerHandler(IRQ, callback);
118  // Write the port data to activate the device
119  // disable interrupts
120  writeByte(rs_232_port_base + RS_232_INTERRUPT_ENABLE_REG, 0x00);
121  writeByte(rs_232_port_base + RS_232_LINE_CONTROL_REG, 0x80);
122  writeByte(rs_232_port_base + RS_232_DATA_REG, 0x03);
123  writeByte(rs_232_port_base + RS_232_INTERRUPT_ENABLE_REG, 0x00);
124  writeByte(rs_232_port_base + RS_232_LINE_CONTROL_REG, 0x03);
125  writeByte(rs_232_port_base + RS_232_INTERRUPT_IDENTIFICATION_REG, 0xC7);
126  writeByte(rs_232_port_base + RS_232_MODEM_CONTROL_REG, 0x0B);
127  writeByte(rs_232_port_base + RS_232_LINE_CONTROL_REG, 0x00);
128  // re-enable interrupts
129  writeByte(rs_232_port_base + RS_232_INTERRUPT_ENABLE_REG, 0x01);
130 
133  "\033[93m\n"
134  " _ __ _ _____\n"
135  " | |/ /_ _______(_)____ _ _|__ /\n"
136  " | / / / / ___/ / ___/ | | / //_ <\n"
137  " / / /_/ / / / (__ ) | |/ /__/ /\n"
138  "/_/|_\\__, /_/ /_/____/ |___/____/\n"
139  " /____/\n"
140  "\n\033[0m"
141  "Xyris Serial Output Debugger\n\n");
142 }
+ Here is the call graph for this function:

◆ printf()

int RS232::printf ( const char *  format,
  ... 
)

Prints a formatted string to serial output.

Parameters
formatFormat string
...Arguments
Returns
int Number of characters printed

Definition at line 86 of file rs232.cpp.

87 {
88  va_list args;
89  int ret_val;
90 
91  va_start(args, format);
92  ret_val = vprintf(format, args);
93  va_end(args);
94  return ret_val;
95 }
+ Here is the call graph for this function:

◆ read()

size_t RS232::read ( char *  buf,
size_t  count 
)

Reads bytes from the serial buffer.

Parameters
bufBuffer to hold the serial input
countNumber of bytes to read
Returns
char* Returns the number of bytes read.

Definition at line 144 of file rs232.cpp.

145 {
146  size_t bytes = 0;
147  mutex_rs232.lock();
148  for (size_t idx = 0; idx < count && !ring.IsEmpty(); idx++) {
149  buf[idx] = ring.Dequeue();
150  bytes++;
151  }
152  mutex_rs232.unlock();
153  return bytes;
154 }
+ Here is the call graph for this function:

◆ vprintf()

int RS232::vprintf ( const char *  fmt,
va_list  args 
)

Prints a formatted string to serial output using a va_list of arguments.

Parameters
fmtFormat string
argsArguments list
Returns
int Number of characters printed

Definition at line 79 of file rs232.cpp.

80 {
81  int retval;
82  retval = printf_helper(fmt, args, vprintf_helper, NULL);
83  return retval;
84 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

size_t RS232::write ( const char *  buf,
size_t  count 
)

Write bytes to the serial device.

Parameters
bufBuffer containing bytes to write
countNumber of bytes to write
Returns
size_t Returns number of bytes written

Definition at line 156 of file rs232.cpp.

157 {
158  // Wait for previous transfer to complete
159  while (is_transmit_empty() == 0);
160  size_t bytes = 0;
161  for (size_t idx = 0; idx < count; idx++) {
162  writeByte(rs_232_port_base + RS_232_DATA_REG, buf[idx]);
163  bytes++;
164  }
165  return bytes;
166 }
+ Here is the call graph for this function:
Mutex::unlock
bool unlock()
Release the mutex.
Definition: Mutex.cpp:38
RS_232_MODEM_CONTROL_REG
#define RS_232_MODEM_CONTROL_REG
Definition: rs232.cpp:34
RS_232_COM1_IRQ
#define RS_232_COM1_IRQ
Definition: rs232.cpp:25
Interrupts::registerHandler
void registerHandler(uint8_t interrupt, InterruptHandler_t handler)
Definition: isr.cpp:98
Mutex::lock
bool lock()
Aquire the mutex.
Definition: Mutex.cpp:20
RS232::vprintf
int vprintf(const char *fmt, va_list args)
Prints a formatted string to serial output using a va_list of arguments.
Definition: rs232.cpp:79
RS_232_INTERRUPT_ENABLE_REG
#define RS_232_INTERRUPT_ENABLE_REG
Definition: rs232.cpp:31
RS_232_COM2_IRQ
#define RS_232_COM2_IRQ
Definition: rs232.cpp:27
Logger::addWriter
static bool addWriter(LogWriter writer)
Definition: Logger.cpp:119
RS_232_INTERRUPT_IDENTIFICATION_REG
#define RS_232_INTERRUPT_IDENTIFICATION_REG
Definition: rs232.cpp:32
Logger::Print
static void Print(const char *fmt,...)
Definition: Logger.cpp:111
RS_232_DATA_REG
#define RS_232_DATA_REG
Definition: rs232.cpp:30
writeByte
void writeByte(uint16_t port, uint8_t data)
Writes a byte (8 bits) to the CPU bus at a given port address.
Definition: ports.cpp:19
RS_232_COM1
#define RS_232_COM1
Definition: rs232.hpp:18
printf_helper
int printf_helper(const char *fmt, va_list args, printf_cb_fnptr_t fn, void *ptr)
Perform all printf operations on the format string using the provided argument list and uses the call...
Definition: printf.cpp:105
RS_232_LINE_CONTROL_REG
#define RS_232_LINE_CONTROL_REG
Definition: rs232.cpp:33