pic24_stdio_uart.c File Reference

#include "pic24_all.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define SERIAL_BREAK_CR
#define SERIAL_BREAK_NL
#define _LIBC_FUNCTION   __attribute__((__weak__, __section__(".libc")))
#define SUCCESS   0
#define FAIL   -1
#define CHAR_ACCESS   0x4000
#define DATA_ACCESS   0x8000
#define READ_ACCESS   0x0
#define WRITE_ACCESS   0x1
#define READ_WRITE_ACCESS   0x2
#define ACCESS_RW_MASK   0x3
#define ACCESS_SET_OPEN   DATA_ACCESS
#define DEFAULT_BAUDRATE1   DEFAULT_BAUDRATE
#define DEFAULT_BAUDRATE2   DEFAULT_BAUDRATE
#define DEFAULT_BAUDRATE3   DEFAULT_BAUDRATE
#define DEFAULT_BAUDRATE4   DEFAULT_BAUDRATE
#define MAX_ALLOWED_HANDLES   (NUM_UART_MODS+3)
#define RANGECK_HANDLE(xxhandlexx)   ((xxhandlexx >= 0) && (xxhandlexx < MAX_ALLOWED_HANDLES))

Enumerations

enum  ALLOWED_HANDLES {
  HANDLE_STDIN = 0, HANDLE_STDOUT = 1, HANDLE_STDERR = 2, HANDLE_UART1,
  HANDLE_UART2, HANDLE_UART3, HANDLE_UART4
}

Functions

static int16 stdioOpen (void)
int _LIBC_FUNCTION open (const char *name, int access, int mode)
int _LIBC_FUNCTION read (int handle, void *buffer, unsigned int len)
int _LIBC_FUNCTION write (int handle, void *buffer, unsigned int len)
int _LIBC_FUNCTION close (int handle)
long _LIBC_FUNCTION lseek (int handle, long offset, int origin)

Variables

struct {
   void(*   pfnv_outChar )()
   uint8(*   pfn_inChar )()
   uint16   u16_read_access
   uint16   u16_write_access
FILES [MAX_ALLOWED_HANDLES]


Detailed Description

STDIO UART support functions
This file provided courtesy of David Weaver who has given permission for it to be included in the code archive.
Provides standard I/O functions compatible with our single character library functions. See chap10/reverse_string_stdio.c or chap10/stdio_test.c for examples using scanf().
See libc documentation for definitions of open(), close(), read(), write(), and lseek(). Exceptions and limitations imposed by this implementation are documented here.
Use of stdio functions is memory intensive especially for floating point!
fopen() access specifiers work as docummented in libc. Translation mode may be set seperately for reading and writing as in example 1. If using read+write access, remember to seek during transitions from write to read and read to write. Use fseek() or rewind(). See example 2.
Example 1:
     file1 = fopen("uart1", "r"); // uart1 open for reading text using file1
     file2 = fopen("uart1", "wb"); // uart1 open for writing binary using file2
     fprintf(file2, "Enter string:\n"); // binary - no "\n" substituion allowed - see open()
     fscanf(file1, "%s", buffer);
Example 2:
     file3 = fopen("uart1", "r+"); // uart1 open for reading and writing text using file3
     fseek(file3, 0, SEEK_END);  // move to end of file for output - or use rewind()
     fprintf(file3, "Enter string:\n"); // text - may substitute for "\n" - see open()
     fseek(file3, 0, SEEK_SET);  // move to start of file for input - or use rewind()
     fscanf(file3, "%s", buffer);

Definition in file pic24_stdio_uart.c.


Function Documentation

int _LIBC_FUNCTION close ( int  handle  ) 

Stub required by fclose().

Parameters:
handle not used.
Returns:
SUCCESS.

Definition at line 373 of file pic24_stdio_uart.c.

long _LIBC_FUNCTION lseek ( int  handle,
long  offset,
int  origin 
)

Stub required by rewind() and fseek().

Parameters:
handle not used.
offset not used.
origin not used.
Returns:
SUCCESS.

Definition at line 386 of file pic24_stdio_uart.c.

int _LIBC_FUNCTION open ( const char *  name,
int  access,
int  mode 
)

Initiate I/O on UART specified by name

Parameters:
name of file (UART) to open. Limited to "stdin", "stdout", "stderr", "uart1", "uart2", "uart3", and "uart4".
UART number specified by __C30_UART is reserved and can only be opened as stdin, stdout, and stderr.
access is a bit field. Default, 0x0, is for binary read. Set it to include 0x4000 for character translation mode:
input - possible break on '\r' and '\n' - See SERIAL_BREAK_NL and SERIAL_BREAK_CR.
output - possible substitutions for '\n' - See SERIAL_EOL_CR and SERIAL_EOL_CR_LF.
If desired, OR it with 0x1 for write, or 0x2 for read and write.
mode not used
Returns:
handle or FAIL.

Definition at line 216 of file pic24_stdio_uart.c.

int _LIBC_FUNCTION read ( int  handle,
void *  buffer,
unsigned int  len 
)

Input len characters from UART specified for handle to buffer. Uses mode specified via open(). If handle is for stdin, calls open() with character translation read access as needed.

Parameters:
handle specifies UART to read from.
buffer storage for read characters.
len maximum number of characters to read.
Returns:
number of charaters in buffer or FAIL.

Definition at line 297 of file pic24_stdio_uart.c.

static int16 stdioOpen ( void   )  [static]

Check __C30_UART for the UART to use. If set to 1, for example, then set up stdin, stdout, and stderr for UART1 and call configUART1() if not currently enabled.

Returns:
SUCCESS or FAIL.

Definition at line 143 of file pic24_stdio_uart.c.

int _LIBC_FUNCTION write ( int  handle,
void *  buffer,
unsigned int  len 
)

Output len characters from buffer to UART specified for handle. Uses mode specified via open(). If handle is for stdout or stderr, calls open() with character translation write access as needed.

Parameters:
handle specifies UART to write to.
buffer contains characters to write.
len number of characters to write.
Returns:
number of charaters written from buffer or FAIL.

Definition at line 336 of file pic24_stdio_uart.c.


Generated on Mon Oct 18 07:40:48 2010 for Python-on-a-chip by  doxygen 1.5.9