#include "pic_utils.h"
#include "config.h"
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(); } |
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_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 (bit req_brgh, 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. |
Ian Harris 2007 imharris [at] gmail.com
Released under the "do whatever you like with this but if it breaks, you get to keep both pieces" license.
Definition in file pic_serial.h.
#define BRGH_HIGH_SPEED 1 |
Definition at line 274 of file pic_serial.h.
#define BRGH_LOW_SPEED 0 |
Definition at line 275 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 53 of file pic_serial.h.
#define serial_handle_tx_isr | ( | ) | if (pir1.TXIF) { serial_tx_isr(); } |
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 231 of file pic_serial.c.
References end_crit_sec, rx_buffer, rx_end, rx_start, start_crit_sec, and uns8.
void serial_print_int | ( | uns16 | i | ) |
Print a 16 bit unsigned number in decimal to the serial port
i | the 16 bit number to be printed |
Definition at line 277 of file pic_serial.c.
References serial_putc(), and uns8.
Referenced by pic_rf_transmit(), pkt_process_rf_data(), pkt_process_tx_queue(), pkt_queue_packet(), pkt_send_payload(), usb_ep_data_out_callback(), usb_handle_class_request(), usb_handle_ctrl_read_class(), usb_handle_ctrl_write_class(), usb_handle_standard_request(), and usb_handle_transaction().
void serial_print_int_hex | ( | uns8 | i | ) |
Print a 8 bit unsigned number in hex to the serial port
i | 8 bit number to be printed |
Definition at line 298 of file pic_serial.c.
References bin2Hex(), and serial_putc().
Referenced by pic_rf_init(), pkt_print_packet(), serial_print_int_hex_16bit(), usb_handle_class_request(), usb_handle_ctrl_write_class(), usb_handle_reset(), usb_handle_standard_request(), and usb_handle_transaction().
void serial_print_int_hex_16bit | ( | uns16 | i | ) |
Print a 16 bit unsigned number in hex to the serial port
i | 16 bit number to be printed |
Definition at line 305 of file pic_serial.c.
References serial_print_int_hex().
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 316 of file pic_serial.c.
References serial_putc().
Referenced by pic_rf_transmit().
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 311 of file pic_serial.c.
References serial_putc().
Referenced by pkt_print_packet(), pkt_process_tx_queue(), and usb_handle_transaction().
void serial_print_str | ( | rom char * | str | ) |
Send a null terminated rom string out the serial port
str | the rom string to be sent |
Definition at line 265 of file pic_serial.c.
References serial_putc(), and uns8.
void serial_print_str | ( | char * | str | ) |
Send a null terminated string out the serial port
str | the string to be sent |
Definition at line 253 of file pic_serial.c.
References serial_putc(), and uns8.
Referenced by pic_rf_init(), pic_rf_transmit(), pkt_print_packet(), pkt_process_rf_data(), pkt_process_tx_queue(), pkt_queue_packet(), pkt_send_packet(), pkt_send_payload(), usb_configure_endpoints(), usb_ep_data_out_callback(), usb_handle_class_request(), usb_handle_ctrl_read_class(), usb_handle_ctrl_write_class(), usb_handle_reset(), usb_handle_stall(), usb_handle_standard_request(), usb_handle_transaction(), and usb_send_data().
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.
c | the character to transmit |
Definition at line 127 of file pic_serial.c.
References kill_interrupts, serial_handle_tx_isr, tx_buffer, tx_end, tx_start, and uns8.
Referenced by pkt_process_rf_data(), serial_print_int(), serial_print_int_hex(), serial_print_nl(), serial_print_spc(), serial_print_str(), usb_handle_transaction(), usb_prime_ep0_out(), and usb_send_data().
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.
Definition at line 322 of file pic_serial.c.
void serial_rx_isr | ( | ) |
void serial_setup | ( | bit | req_brgh, | |
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.
brgh | refer to your pic documentation | |
spbrg | refer to your pic documentation |
Definition at line 57 of file pic_serial.c.
References kill_interrupts.
uns8 serial_tx_empty | ( | ) |
Tests to see if the serial transmit fifo is empty.
Definition at line 323 of file pic_serial.c.
void serial_tx_full | ( | ) |
Tests to see if the serial transmit fifo is full.
void serial_tx_isr | ( | ) |