pic_serial.h File Reference

Interrupt driven fifo serial support. More...

#include "pic_utils.h"
#include "config.h"
Include dependency graph for pic_serial.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define BRGH_HIGH_SPEED   1
#define BRGH_LOW_SPEED   0
#define serial_handle_rx_isr()   if (pir1.RCIF) { serial_rx_isr(); clear_bit( pir1, RCIF ); }
#define serial_handle_tx_isr()   if (pir1.TXIF) { serial_tx_isr(); }
#define serial_print_debug(string, variable)   serial_print_str(string); serial_print_int(variable); serial_print_nl();

Functions

uns8 serial_getc (void)
 Retrieve a character from the serial port.
void serial_print_int (uns16 i)
 Print a 16 bit number to the serial port.
void serial_print_int_hex (uns8 i)
 Print an 8 bit number in hex to the serial port.
void serial_print_int_hex_16bit (uns16 i)
 Print a 16 bit number in hex to the serial port.
void serial_print_nl ()
 Print a newline.
void serial_print_spc ()
 Print a space.
void serial_print_str (rom char *str)
 Print a rom string out to the serial port.
void serial_print_str (char *str)
 Print a string out to the serial port.
void serial_print_var (char *str, uns16 i)
void serial_putc (uns8 c)
 Transmit a single character.
uns8 serial_rx_avail ()
 Tests if the serial rx fifo has a character available.
void serial_rx_isr ()
 Serial receive interrupt service routine.
void serial_setup (uns8 req_spbrg)
 Configure the pic for serial communicaitons.
uns8 serial_tx_empty ()
 Tests if the serial tx fifo is empty.
void serial_tx_full ()
 Tests if the serial tx fifo is full.
void serial_tx_isr ()
 Serial transmit interrupt service routine.

Detailed Description

Put the following into your config.h

define SERIAL_TX_BUFFER_SIZE 20 define SERIAL_RX_BUFFER_SIZE 4

Use this define if you want fine-grained control of what happens in the serial port define SERIAL_DEBUG_ON

Use this define if you are debugging in the IDE simulator and don't want it to hang waiting for serial interrupts that will never come... define SERIAL_IDE_DEBUG

Use thie define if you want to drop a character if the TX buffer is full, rather than the default behaviour, which is to wait until the TX buffer has a spare spot. define SERIAL_DISCARD_ON_TX_FULL_DURING_INT

Put the following in your ISR

serial_handle_tx_isr(); serial_handle_rx_isr();

Put the following in your system setup routine

serial_setup(uns8/16 req_spbrg);

Definition in file pic_serial.h.


Define Documentation

#define BRGH_HIGH_SPEED   1

Definition at line 338 of file pic_serial.h.

#define BRGH_LOW_SPEED   0

Definition at line 339 of file pic_serial.h.

 
#define serial_handle_rx_isr (  )     if (pir1.RCIF) { serial_rx_isr(); clear_bit( pir1, RCIF ); }

include in your ISR

Definition at line 90 of file pic_serial.h.

 
#define serial_handle_tx_isr (  )     if (pir1.TXIF) { serial_tx_isr(); }

include in your ISR

Definition at line 87 of file pic_serial.h.

Referenced by serial_putc().

#define serial_print_debug ( string,
variable   )     serial_print_str(string); serial_print_int(variable); serial_print_nl();

Definition at line 93 of file pic_serial.h.


Function Documentation

uns8 serial_getc ( void   ) 

Retrieve character from the serial port. Note that if there is nothing in the fifo, this function will wait until a character is received - and this will never happen if interrupts are turned off when this is called! So, be careful not to call getc during a critical section or during an ISR unless* you're sure there's something in the fifo. You can do this by calling the serial_rx_avail() routine. In any other situation, you can call getc() and happily wait for a character to arrive.

Definition at line 276 of file pic_serial.c.

References end_crit_sec, rx_buffer, rx_end, rx_start, start_crit_sec, and uns8.

Referenced by term_process().

Here is the caller graph for this function:

void serial_print_int ( uns16  i  ) 
void serial_print_int_hex ( uns8  i  ) 

Print a 8 bit unsigned number in hex to the serial port

Parameters:
i 8 bit number to be printed

Definition at line 343 of file pic_serial.c.

References bin2Hex(), and serial_putc().

Referenced by ar1000_tune(), draw_print_buffer(), mrf24j40_handle_isr(), mrf24j40_set_extended_address(), pic_rf_init(), pkt_print_packet(), serial_print_int_hex_16bit(), usb_handle_class_ctrl_write_callback(), usb_handle_class_request_callback(), usb_handle_reset(), usb_handle_standard_request(), usb_handle_transaction(), wpan_data_received_callback(), wpan_print_address(), and wpan_print_mac_command().

Here is the call graph for this function:

Here is the caller graph for this function:

void serial_print_int_hex_16bit ( uns16  i  ) 

Print a 16 bit unsigned number in hex to the serial port

Parameters:
i 16 bit number to be printed

Definition at line 350 of file pic_serial.c.

References serial_print_int_hex().

Referenced by usb_handle_transaction(), and wpan_print_address().

Here is the call graph for this function:

Here is the caller graph for this function:

void serial_print_nl (  ) 

Print a new line out the serial port - if you do this often, this routine can be used to save a couple of instructions. Always helps!

Definition at line 361 of file pic_serial.c.

References serial_putc().

Referenced by ar1000_seek_more(), drv_print_buffer(), its1_controller_init(), its1_device_process(), mrf24j40_active_channel_scan(), mrf24j40_handle_isr(), mrf24j40_set_extended_address(), ms5540_calc_temp_and_pressure(), ms5540_init(), pic_rf_transmit(), serial_print_var(), and wpan_data_received_callback().

Here is the call graph for this function:

Here is the caller graph for this function:

void serial_print_spc (  ) 

Print a space out the serial port - if you do this often, this routine can be used to save a couple of instructions. Always helps!

Definition at line 356 of file pic_serial.c.

References serial_putc().

Referenced by drv_print_buffer(), ms5540_init(), pkt_print_packet(), pkt_process_tx_queue(), and usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void serial_print_str ( rom char *  str  ) 

Send a null terminated rom string out the serial port

Parameters:
str the rom string to be sent

Definition at line 310 of file pic_serial.c.

References serial_putc(), and uns8.

Here is the call graph for this function:

void serial_print_str ( char *  str  ) 
void serial_print_var ( char *  str,
uns16  i 
)

Definition at line 365 of file pic_serial.c.

References serial_print_int(), serial_print_nl(), and serial_print_str().

Referenced by its1_controller_init(), and its1_device_process().

Here is the call graph for this function:

Here is the caller graph for this function:

void serial_putc ( uns8  c  ) 

Sends a single character out the serial connection. It is sent straight out if possible, otherwise put into the fifo. Note that if you fill the fifo while interrupts are off (eg, in an interrupt routine or a critical section) then this routine will hang the pic, since it's waiting for an interrupt to clear the fifo, which never comes... The moral is to keep your fifo big enough or don't send too much while interrupts are off (eg, in an interrupt response routine). Of course, you *can* send things in an ISR - just don't fill the fifo up.

Parameters:
c the character to transmit

Definition at line 172 of file pic_serial.c.

References kill_interrupts, serial_handle_tx_isr, tx_buffer, tx_end, tx_start, and uns8.

Referenced by cat4016_write_data(), draw_print_buffer(), mrf24j40_receive(), mrf24j40_receive_callback(), mrf24j40_set_extended_address(), pkt_process_rf_data(), serial_print_int(), serial_print_int_hex(), serial_print_nl(), serial_print_spc(), serial_print_str(), term_process(), usb_cdc_handle_tx(), usb_handle_class_ctrl_write_callback(), usb_handle_class_request_callback(), usb_handle_transaction(), usb_prime_ep0_out_e(), usb_prime_ep0_out_o(), usb_send_data(), wpan_data_received_callback(), wpan_print_address(), and wpan_print_mac_command().

Here is the caller graph for this function:

uns8 serial_rx_avail (  ) 

Tests to see if the serial receive fifo has a character available. Useful to call before getc() if interrupts are not enabled in that section of code.

Returns:
true (non zero) if there are one or more characters waiting in the fifo queue, false (zero) otherwise

Definition at line 371 of file pic_serial.c.

References rx_end, and rx_start.

Referenced by term_process().

Here is the caller graph for this function:

void serial_rx_isr (  ) 

This routine needs to be called from your interrupt() routine when the receive hardware interrupt occurs in order to put received bytes into the fifo buffer.

Definition at line 236 of file pic_serial.c.

References rx_buffer, rx_end, rx_start, and uns8.

void serial_setup ( uns8  req_spbrg  ) 

Configures the pic and gets ready for interrupt-driven serial communications. Includes setting the tris bits appropriately, and getting the baud rate generator set up. After calling this you can immediately start sending and receiving bytes.

Parameters:
brgh See sprg defines earlier in pic_serial.h

Definition at line 77 of file pic_serial.c.

Referenced by usb_handle_class_ctrl_write_callback().

Here is the caller graph for this function:

uns8 serial_tx_empty (  ) 

Tests to see if the serial transmit fifo is empty.

Returns:
true (non zero) if tx fifo is empty, false (zero) otherwise

Definition at line 372 of file pic_serial.c.

References tx_end, and tx_start.

Referenced by usb_handle_class_ctrl_write_callback().

Here is the caller graph for this function:

void serial_tx_full (  ) 

Tests to see if the serial transmit fifo is full.

Returns:
true (non zero) if tx fifo is full, false (zero) otherwise
void serial_tx_isr (  ) 

serial_load_tx

This routine needs to be called from your interrupt() routine when the transmit hardware interrupt occurs in order to send bytes that are waiting in the fifo buffer.

Definition at line 216 of file pic_serial.c.

References tx_buffer, tx_end, tx_start, and uns8.

Referenced by usb_handle_class_ctrl_write_callback().

Here is the caller graph for this function:


Generated on Wed Dec 8 13:47:40 2010 for Pic Pack by  doxygen 1.6.1