LoIO.c File Reference

Serial I/O API for Robolocust control program running on iRobot Create Command Module. More...

#include "LoIO.h"
#include "LoTimer.h"
#include "LoOpenInterface.h"
#include <avr/io.h>
#include <avr/interrupt.h>
Include dependency graph for LoIO.c:

Go to the source code of this file.

Functions

void lo_init_comm ()
 Set up the serial port.
void lo_reset_baud (int baud_rate)
 Reset communication speed on both Create robot and Command Module.
void lo_clear_buffers (void)
 Flush the RX and TX buffers.
void lo_tx (char byte)
 Transmit a byte over the serial port.
unsigned char lo_rx (char *buf, unsigned char n, unsigned int timeout)
char lo_rx1 (unsigned int timeout)
void lo_io_to_usb ()
void lo_io_to_create ()
char lo_io_error ()

Variables

static char g_io_error

Detailed Description

Serial I/O API for Robolocust control program running on iRobot Create Command Module.

This file defines the functions for serial port I/O needed by the Robolocust iRobot Create Command Module control program.

Definition in file LoIO.c.


Function Documentation

void lo_clear_buffers ( void   ) 

Flush the RX and TX buffers.

Definition at line 144 of file LoIO.c.

void lo_init_comm ( void   ) 

Set up the serial port.

Definition at line 67 of file LoIO.c.

char lo_io_error ( void   ) 

Retrieve current I/O status. After each I/O operation, clients should use this function to check for errors.

Definition at line 241 of file LoIO.c.

Referenced by lo_sensors().

void lo_io_to_usb ( void   ) 

Since the Command Module has only one USART, it needs to be switched between talking to the USB port and the iRobot Create's serial port.

Usually, the low-level Robolocust control program that runs on the command module will listen for incoming high-level motor commands over the USB port. But every time it needs to actually execute one of those commands, it will have to switch the USART to talk to the Create's serial port and then back again to continue listening to the higher layers of the Robolocust controller.

These functions switch the USART between the Command Module's USB port and the Create's serial port.

Definition at line 224 of file LoIO.c.

References lo_wait().

void lo_reset_baud ( int  baud_rate  ) 

Reset communication speed on both Create robot and Command Module.

Definition at line 75 of file LoIO.c.

References lo_tx(), lo_wait(), and LOBOT_OI_CMD_BAUD.

unsigned char lo_rx ( char *  buf,
unsigned char  n,
unsigned int  timeout 
)

Receive the specified number of bytes over the serial port, waiting a maximum number of milliseconds before giving up. If the timeout is zero, wait forever for the data to come in.

The function returns the number of bytes successfully read.

Clients should setup a large enough buffer to accommodate the amount of data they require and check the return value before using the data in the buffer. If the number of bytes read is less than the number requested, clients can query the I/O error to see what went wrong.

NOTE: Since we're using 8-bit integers, only a maximum of 255 bytes can be retrieved at one time. For the purposes of this control program, that number is more than enough.

Definition at line 182 of file LoIO.c.

References lo_setup_timer(), and lo_timer_is_running().

Referenced by lo_backup(), lo_rx1(), lo_sensors(), and lo_spin().

char lo_rx1 ( unsigned int  timeout  ) 

Receive a single byte over the serial port, waiting a maximum number of milliseconds before giving up. If the timeout is zero, wait forever for the data byte to come in.

Clients should check the I/O error flag before using the byte returned by this function.

Definition at line 215 of file LoIO.c.

References lo_rx().

void lo_tx ( char  byte  ) 
Generated on Sun May 8 08:42:49 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3