Added RS232 library.
This commit is contained in:
parent
2e45e4b14d
commit
ab69652a72
4 changed files with 1515 additions and 0 deletions
38
rs232/Makefile
Normal file
38
rs232/Makefile
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# RS-232 Serial Library Makefile for DJGPP cross-compilation
|
||||||
|
|
||||||
|
DJGPP_PREFIX = $(HOME)/djgpp/djgpp
|
||||||
|
DJGPP_LIBPATH = $(HOME)/claude/windriver/tools/lib
|
||||||
|
CC = $(DJGPP_PREFIX)/bin/i586-pc-msdosdjgpp-gcc
|
||||||
|
AR = LD_LIBRARY_PATH=$(DJGPP_LIBPATH) $(DJGPP_PREFIX)/bin/i586-pc-msdosdjgpp-ar
|
||||||
|
RANLIB = LD_LIBRARY_PATH=$(DJGPP_LIBPATH) $(DJGPP_PREFIX)/bin/i586-pc-msdosdjgpp-ranlib
|
||||||
|
CFLAGS = -O2 -Wall -Wextra -march=i486 -mtune=i586
|
||||||
|
|
||||||
|
OBJDIR = ../obj/rs232
|
||||||
|
LIBDIR = ../lib
|
||||||
|
|
||||||
|
SRCS = rs232.c
|
||||||
|
OBJS = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
|
||||||
|
TARGET = $(LIBDIR)/librs232.a
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(OBJS) | $(LIBDIR)
|
||||||
|
$(AR) rcs $@ $(OBJS)
|
||||||
|
$(RANLIB) $@
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
$(LIBDIR):
|
||||||
|
mkdir -p $(LIBDIR)
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
$(OBJDIR)/rs232.o: rs232.c rs232.h
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJDIR) $(TARGET)
|
||||||
1388
rs232/rs232.c
Normal file
1388
rs232/rs232.c
Normal file
File diff suppressed because it is too large
Load diff
89
rs232/rs232.h
Normal file
89
rs232/rs232.h
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
// RS-232 Serial Port Library for DJGPP
|
||||||
|
// Ported from DOS Serial Library 1.4 by Karl Stenerud (MIT License)
|
||||||
|
//
|
||||||
|
// ISR-driven UART communication with ring buffers and flow control.
|
||||||
|
// Supports up to 4 simultaneous COM ports with auto-detected IRQ.
|
||||||
|
|
||||||
|
#ifndef RS232_H
|
||||||
|
#define RS232_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// COM Ports
|
||||||
|
#define RS232_COM1 0
|
||||||
|
#define RS232_COM2 1
|
||||||
|
#define RS232_COM3 2
|
||||||
|
#define RS232_COM4 3
|
||||||
|
|
||||||
|
// Handshaking Modes
|
||||||
|
#define RS232_HANDSHAKE_NONE 0
|
||||||
|
#define RS232_HANDSHAKE_XONXOFF 1
|
||||||
|
#define RS232_HANDSHAKE_RTSCTS 2
|
||||||
|
#define RS232_HANDSHAKE_DTRDSR 3
|
||||||
|
|
||||||
|
// Error Codes
|
||||||
|
#define RS232_SUCCESS 0
|
||||||
|
#define RS232_ERR_UNKNOWN -1
|
||||||
|
#define RS232_ERR_NOT_OPEN -2
|
||||||
|
#define RS232_ERR_ALREADY_OPEN -3
|
||||||
|
#define RS232_ERR_NO_UART -4
|
||||||
|
#define RS232_ERR_INVALID_PORT -5
|
||||||
|
#define RS232_ERR_INVALID_BASE -6
|
||||||
|
#define RS232_ERR_INVALID_IRQ -7
|
||||||
|
#define RS232_ERR_INVALID_BPS -8
|
||||||
|
#define RS232_ERR_INVALID_DATA -9
|
||||||
|
#define RS232_ERR_INVALID_PARITY -10
|
||||||
|
#define RS232_ERR_INVALID_STOP -11
|
||||||
|
#define RS232_ERR_INVALID_HANDSHAKE -12
|
||||||
|
#define RS232_ERR_INVALID_FIFO -13
|
||||||
|
#define RS232_ERR_NULL_PTR -14
|
||||||
|
#define RS232_ERR_IRQ_NOT_FOUND -15
|
||||||
|
#define RS232_ERR_LOCK_MEM -16
|
||||||
|
|
||||||
|
|
||||||
|
// Buffer management
|
||||||
|
int rs232ClearRxBuffer(int com);
|
||||||
|
int rs232ClearTxBuffer(int com);
|
||||||
|
|
||||||
|
// Open/close
|
||||||
|
int rs232Close(int com);
|
||||||
|
int rs232Open(int com, int32_t bps, int dataBits, char parity, int stopBits, int handshake);
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
int rs232GetBase(int com);
|
||||||
|
int32_t rs232GetBps(int com);
|
||||||
|
int rs232GetCts(int com);
|
||||||
|
int rs232GetData(int com);
|
||||||
|
int rs232GetDsr(int com);
|
||||||
|
int rs232GetDtr(int com);
|
||||||
|
int rs232GetHandshake(int com);
|
||||||
|
int rs232GetIrq(int com);
|
||||||
|
int rs232GetLsr(int com);
|
||||||
|
int rs232GetMcr(int com);
|
||||||
|
int rs232GetMsr(int com);
|
||||||
|
char rs232GetParity(int com);
|
||||||
|
int rs232GetRts(int com);
|
||||||
|
int rs232GetRxBuffered(int com);
|
||||||
|
int rs232GetStop(int com);
|
||||||
|
int rs232GetTxBuffered(int com);
|
||||||
|
|
||||||
|
// Read/write
|
||||||
|
int rs232Read(int com, char *data, int len);
|
||||||
|
int rs232Write(int com, const char *data, int len);
|
||||||
|
int rs232WriteBuf(int com, const char *data, int len);
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
int rs232Set(int com, int32_t bps, int dataBits, char parity, int stopBits, int handshake);
|
||||||
|
int rs232SetBase(int com, int base);
|
||||||
|
int rs232SetBps(int com, int32_t bps);
|
||||||
|
int rs232SetData(int com, int dataBits);
|
||||||
|
int rs232SetDtr(int com, int dtr);
|
||||||
|
int rs232SetFifoThreshold(int com, int threshold);
|
||||||
|
int rs232SetHandshake(int com, int handshake);
|
||||||
|
int rs232SetIrq(int com, int irq);
|
||||||
|
int rs232SetMcr(int com, int mcr);
|
||||||
|
int rs232SetParity(int com, char parity);
|
||||||
|
int rs232SetRts(int com, int rts);
|
||||||
|
int rs232SetStop(int com, int stopBits);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue