Retired old PIC stuff and unused libsig++

This commit is contained in:
2021-02-18 07:38:34 -05:00
parent f246310843
commit 7a36aea84a
127 changed files with 14 additions and 15444 deletions

14
daemons/README.txt Normal file
View File

@ -0,0 +1,14 @@
Daemons (Server processes)
include Link to common header files
Standard daemons
================
cand CAN data server using Linux-CAN with PCAN-USB
gpsd GPS daemon for serving GPS data
logd Logging daemon that supports multiple types of logs
rtcmd RTCM daemon used to forward corrections data
seriald Serial data relay/service
stdiod Stdio data relay/service
trackd GPS tracking service

File diff suppressed because it is too large Load Diff

View File

@ -1,230 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="FF4C62B1B7Ld5631800x620c" name="PIC-LIB" kpf_version="2">
<preference-set id="">
</preference-set>
<folder id="FF4C62EC1BL4e7719910x620c" name="Include">
<folder id="FF4C77E942L385e29ad0x620c" name="Memory">
<file url="atmel.h" id="FF4C64E59BL4d4121200x620c" name="atmel.h">
</file>
<file url="dataee.h" id="FF4C64E5C0L4395901a0x620c" name="dataee.h">
</file>
<file url="fram.h" id="FF4C64E5F8L2b5df16c0x620c" name="fram.h">
</file>
<file url="memio.h" id="FF4C64E637L4fc8a6740x620c" name="memio.h">
</file>
</folder>
<folder id="FF4C784142L66cf25a60x620c" name="Comm">
<file url="packet.h" id="FF4C64E649L5f39f8370x620c" name="packet.h">
</file>
<file url="serial.h" id="FF4C64E67EL7b9c33750x620c" name="serial.h">
</file>
<file url="spi.h" id="FF4C64E691L5c88a030x620c" name="spi.h">
</file>
<file url="i2c_bitbang.h" id="FF958D0688L7c7df81b0x195e" name="i2c_bitbang.h">
</file>
<file url="i2c_master.h" id="FF958D06C2L5e5c899e0x195e" name="i2c_master.h">
</file>
<file url="i2c_slave.h" id="FF958D06FFL2b6c9b8b0x195e" name="i2c_slave.h">
</file>
</folder>
<folder id="FF4C7902CFL436b69b30x620c" name="Library">
<file url="queue.h" id="FF4C64E66CL261ee7c80x620c" name="queue.h">
</file>
<file url="stack.h" id="FF4C64E6A6L2e9853880x620c" name="stack.h">
</file>
<file url="types.h" id="FF4C64E6CDL3bec167f0x620c" name="types.h">
</file>
<file url="picmath.h" id="1009ED908F5L2f438fa90x6a78" name="picmath.h">
</file>
</folder>
<folder id="FF4C7A1BEAL4a1be25c0x620c" name="Hardware">
<file url="analog.h" id="FF4C64E58FL1fc5ef6d0x620c" name="analog.h">
</file>
<file url="clock.h" id="FF4C64E5AALfca82870x620c" name="clock.h">
</file>
</folder>
<folder id="FF4C950F26L35c3c4170x620c" name="Base">
<file url="config.h" id="FF4C64E5B4L4f56fce00x620c" name="config.h">
</file>
<file url="system.h" id="FF4C64E6B9L615c29530x620c" name="system.h">
</file>
<file url="delay.h" id="FF4C64E5CEL7c62ba70x620c" name="delay.h">
</file>
<file url="timers.h" id="FF84C2D941L31f7359e0x6019" name="timers.h">
</file>
<file url="pwm.h" id="FF4C64E659L14d12c680x620c" name="pwm.h">
</file>
<file url="period.h" id="FF851670F6L128467220x6019" name="period.h">
</file>
<file url="portb.h" id="FF858753B4L1e9d7ce60x6019" name="portb.h">
</file>
</folder>
</folder>
<folder id="FF4C630D2DL12ff37450x620c" name="Build">
<file url="Makefile" id="FF4C6361BBL605ac1d60x620c" name="Makefile">
</file>
</folder>
<folder id="FF4C632E7AL6e13a8070x620c" name="Source">
<folder id="FF4C721896L82181b40x620c" name="Memory">
<file url="atmel.c" id="FF4C6607CEL488311140x620c" name="atmel.c">
</file>
<file url="dataee.c" id="FF4C66080CLed5c6660x620c" name="dataee.c">
</file>
<file url="fram.c" id="FF4C66085FL76ef39580x620c" name="fram.c">
</file>
<file url="memio.c" id="FF4C6609F4L1aca5e2e0x620c" name="memio.c">
</file>
</folder>
<folder id="FF4C74FE3EL4281f8070x620c" name="Library">
<file url="checksum.c" id="FF4C6607DEL25805df10x620c" name="checksum.c">
</file>
<file url="crc16.c" id="FF4C6607FBL756420040x620c" name="crc16.c">
</file>
<file url="queue.c" id="FF4C660ABAL2b64f11d0x620c" name="queue.c">
</file>
<file url="stack.c" id="FF4C660CD1L776465570x620c" name="stack.c">
</file>
<file url="crc8.c" id="1009B1BEB2CL47bfefb0x6a78" name="crc8.c">
</file>
</folder>
<folder id="FF4C75CD55L100031b50x620c" name="Base">
<file url="watchdog.c" id="FF4C660D1EL7ab4ada40x620c" name="watchdog.c">
</file>
<file url="system.c" id="FF4C660CF8L1ab34fac0x620c" name="system.c">
</file>
<file url="timers.c" id="FF84DDD906L17dd985b0x6019" name="timers.c">
</file>
<file url="adc.c" id="FF4C6607C0L20132bed0x620c" name="adc.c">
</file>
<file url="pwm.c" id="FF7B76D919L6535570d0x374c" name="pwm.c">
</file>
<file url="period.c" id="FF851A1B8DL67cd528b0x6019" name="period.c">
</file>
<file url="inter16.c" id="FF853C2218L51fc24c80x6019" name="inter16.c">
</file>
<file url="inter18.c" id="FF853C6321L1b2f30fb0x6019" name="inter18.c">
</file>
<file url="portb_0.c" id="FF8589F22EL190263170x6019" name="portb_0.c">
</file>
<file url="portb_12.c" id="FF8589F2B1Lb9f07f30x6019" name="portb_12.c">
</file>
<file url="portb_4567.c" id="FF8589F30AL25b02bc30x6019" name="portb_4567.c">
</file>
</folder>
<folder id="FF84DE7970L72b544a00x6019" name="Hardware">
<folder id="FF4C719E6CL1e030130x620c" name="Analog">
<file url="ad_max186.c" id="FF4C660773L5d15ff250x620c" name="ad_max186.c">
</file>
<file url="ad_max355.c" id="FF4C66077EL336ae9ec0x620c" name="ad_max355.c">
</file>
<file url="ad_mcp320x.c" id="FF4C660790L27bec93b0x620c" name="ad_mcp320x.c">
</file>
<file url="ad_mcp3301.c" id="FF4C6607B3L2dc7c3cc0x620c" name="ad_mcp3301.c">
</file>
</folder>
<folder id="FF4C72790AL6d1ad8070x620c" name="Clock">
<file url="clk_nju6355.c" id="FF4C6607EDL16aaf02f0x620c" name="clk_nju6355.c">
</file>
</folder>
</folder>
<folder id="FF84DF354BL2cc6bd3e0x6019" name="Comm">
<folder id="FF4C732442L4d13b43a0x620c" name="I2C">
<file url="i2c_master.c" id="FF7B8C8CFDL13ee3e190x374c" name="i2c_master.c">
</file>
<file url="i2c_bitbang.c" id="FF958C5C05L7dea34910x195e" name="i2c_bitbang.c">
</file>
<file url="i2c_slave.c" id="FF958C5C32L1141232c0x195e" name="i2c_slave.c">
</file>
</folder>
<folder id="FF4C706B28L29ad60920x620c" name="Serial">
<file url="ser_baud.c" id="FF4C660AD9L5695e83f0x620c" name="ser_baud.c">
</file>
<file url="ser_getn.c" id="FF4C660AF8L1fd59e410x620c" name="ser_getn.c">
</file>
<file url="ser_gets.c" id="FF4C660B17L4faef7630x620c" name="ser_gets.c">
</file>
<file url="ser_getw.c" id="FF4C660B36L3361fc8a0x620c" name="ser_getw.c">
</file>
<file url="ser_init.c" id="FF4C660B55L4e6037830x620c" name="ser_init.c">
</file>
<file url="ser_input.c" id="FF4C660B75L1b7e1b680x620c" name="ser_input.c">
</file>
<file url="ser_lnx.c" id="FF4C660B96Lfc9cf0e0x620c" name="ser_lnx.c">
</file>
<file url="ser_output.c" id="FF4C660BB7L6b98cf100x620c" name="ser_output.c">
</file>
<file url="ser_putn.c" id="FF4C660BD9L46e9efcf0x620c" name="ser_putn.c">
</file>
<file url="ser_puts.c" id="FF4C660BFDL497a5780x620c" name="ser_puts.c">
</file>
<file url="ser_putw.c" id="FF4C660C20La276dda0x620c" name="ser_putw.c">
</file>
<file url="ser_putx.c" id="FF4C660C42L3f3bd3b30x620c" name="ser_putx.c">
</file>
<file url="ser_win.c" id="FF4C660C66L36d0fcb50x620c" name="ser_win.c">
</file>
<file url="ser_xdump.c" id="FF4C660C89L386182600x620c" name="ser_xdump.c">
</file>
</folder>
<folder id="FF4C7581FAL3cb101ec0x620c" name="SPI">
<file url="spi.c" id="FF4C660CACL73d9be640x620c" name="spi.c">
</file>
</folder>
<folder id="FF4C73B87EL2b7dd53c0x620c" name="Packet">
<file url="pkt_int.c" id="FF4C660A0FL438199240x620c" name="pkt_int.c">
</file>
<file url="pkt_radio.c" id="FF4C660A2AL18f0b9340x620c" name="pkt_radio.c">
</file>
<file url="pkt_recv.c" id="FF4C660A45L25767d900x620c" name="pkt_recv.c">
</file>
<file url="pkt_recvs.c" id="FF4C660A64L46a08bd70x620c" name="pkt_recvs.c">
</file>
<file url="pkt_xmit.c" id="FF4C660A80L7f060f960x620c" name="pkt_xmit.c">
</file>
<file url="pkt_xmits.c" id="FF4C660A9CL5f8028370x620c" name="pkt_xmits.c">
</file>
</folder>
</folder>
<folder id="FF84E49EF2L4502272f0x6019" name="Linux">
<file url="ad_linux.c" id="FF4C660765L28896f730x620c" name="ad_linux.c">
</file>
<file url="emul.c" id="FF4C66084DL176af5c0x620c" name="emul.c">
</file>
<file url="emul.h" id="FF4C64E5DBL2e9d97490x620c" name="emul.h">
</file>
<file url="lin_timer.c" id="FF84F5B0A5L2b8198660x6019" name="lin_timer.c">
</file>
<file url="lin_period.c" id="FF8531C93EL37736ab40x6019" name="lin_period.c">
</file>
<file url="clk_linux.c" id="FF7B5C5FE4L6ded20740x374c" name="clk_linux.c">
</file>
</folder>
<folder id="1009EA245ECL56cc46f40x6a78" name="Math">
<file url="interpl.c" id="1009E9F0341L58b5c1a60x6a78" name="interpl.c">
</file>
<file url="interps.c" id="1009EA21298L1ff2b62f0x6a78" name="interps.c">
</file>
</folder>
<folder id="FF4C72BCEBL6fffa4860x620c" name="Delay">
<file url="dly_msec.c" id="FF4C66081BL1afe73ae0x620c" name="dly_msec.c">
</file>
<file url="dly_sec.c" id="FF4C66082CL2e93442b0x620c" name="dly_sec.c">
</file>
<file url="dly_usec.c" id="FF4C66083DL7e4b36e0x620c" name="dly_usec.c">
</file>
</folder>
</folder>
<file url="TODO" id="FF7B483239L767dbd2e0x374c" name="TODO">
</file>
<folder id="FF7B50AE9FL290ab24a0x374c" name="Tests">
<folder id="FF7B5123E0L7a8c30c20x374c" name="Memory">
<file url="atmeltest.c" id="FF7B50F7BCL416bcbb50x374c" name="atmeltest.c">
</file>
<file url="deetest.c" id="FF7B50F7D5L316a6ec30x374c" name="deetest.c">
</file>
<file url="framtest.c" id="FF7B50F7E0L4f44a4370x374c" name="framtest.c">
</file>
</folder>
</folder>
</project>

View File

@ -1,30 +0,0 @@
TODO
Message
-------
Messaging software
Local or remote messaging (queued per task)
Runs on PIC, Windows or Linux
Uses Packet for remote
Routing table (task id -> packet id)
Packet
------
Packet interrupt routine needs to timeout on packet.
Use Id high byte for
0=serial
1=SPI
2=I2C
3=...
other=socket
I2C
---
I2C API Rewrite/Update
Fix I2C Master
Fix Bitbanged timing
Chips
-----
Add links (for Doxygen) to chip manuals

View File

@ -1,93 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux A/D Emulation Driver
*----------------------------------------------------------------------------
* Linux Analog Drivers (hook into Comedi)
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "analog.h"
#include "delay.h"
#ifdef __linux__
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
static short sAnalogData[16] = { 0 };
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
// MAX186
void AdMax186Init( void )
{
}
WORD AdMax186Read( BYTE byChan )
{
return (WORD)sAnalogData[byChan&15]++;
}
// supports two MAX355 Muxes
void AdMax355Mux( BYTE c )
{
}
// MCP320X
void AdMcp320XInit( void )
{
}
WORD AdMcp320XRead( BYTE byChan )
{
return (WORD)sAnalogData[byChan&15]++;
}
// MCP3301
void AdMcp3301Init( void )
{
}
short AdMcp3301Read( void )
{
return sAnalogData[0]++;
}
#endif

View File

@ -1,152 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* MAX 186 A/D Chip
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "analog.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
// see spec as channel #s aren't same as select bits
#define AD_MUX(C) (((C)<<4)|0x8E)
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// table
#ifdef ANALOG_MAX186
static const BYTE byChTbl[8] = {
AD_MUX( 0 ),
AD_MUX( 4 ),
AD_MUX( 1 ),
AD_MUX( 5 ),
AD_MUX( 2 ),
AD_MUX( 6 ),
AD_MUX( 3 ),
AD_MUX( 7 )
};
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef ANALOG_MAX186
void AdMax186Init( void )
{
// disable
AD_CS = 1;
AD_CK_DIR = 1;
AD_DT_DIR = 1;
}
// output channel # to read
static void AdMax186Chan( BYTE x )
{
BYTE n = 8;
// kick mux & start conversion
x = byChTbl[x & 7]; // map
while ( n-- )
{
// bits out
if ( x & 0x80 )
AD_OUT = 1;
else
AD_OUT = 0;
x <<= 1;
// rising edge and hold
DelayNs0100();
AD_CK = 1;
DelayNs0200();
AD_CK = 0;
}
}
static WORD AdMax186Rd( void )
{
BYTE n = 16;
WORD w = 0;
while ( n-- )
{
// falling edge
AD_CK = 1;
DelayNs0200();
AD_CK = 0;
DelayNs0100();
// bits in
w <<= 1;
w |= AD_IN;
}
// return data
return w >> 4;
}
WORD AdMax186Read( BYTE chan )
{
WORD data;
// clock out, data in and select
AD_CK_DIR = 0;
AD_DT_DIR = 1;
AD_CS = 0;
// set channel
AdChan( chan );
DelayUsec( 10 );
// read data
data = AdMax186AdRd();
// deselect
AD_CS = 1;
AD_CK_DIR = 1;
AD_DT_DIR = 1;
return data;
}
#endif

View File

@ -1,91 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* MAX 255 A/D Multiplexor
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "analog.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef ADMUX_MAX355
// supports two MAX355 Muxes
void AdMax355Mux( BYTE c )
{
// call with channel number 0..7
// turn mux off
ADMUX_ENABLE0 = 0;
#ifdef ADMUX_ENABLE1
ADMUX_ENABLE1 = 0;
#endif
// wait to transition off
DelayNs0400();
// mux off
if ( c == 0xff )
return;
// select channel
ADMUX_A0 = ( c & 1 ) ? 1 : 0;
ADMUX_A1 = ( c & 2 ) ? 1 : 0;
// wait to switch
DelayNs0400();
#ifdef ADMUX_ENABLE1
if ( c & 4 )
ADMUX_ENABLE1 = 1; // 4..7
else
ADMUX_ENABLE0 = 1; // 0..3
#else
ADMUX_ENABLE0 = 1;
#endif
// wait to settle
DelayNs2000();
}
#endif

View File

@ -1,102 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Microchip MCP320X A/D Chip
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "analog.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#if defined(ANALOG_MCP3204) || defined(ANALOG_MCP3208)
void AdMcp320XInit( void )
{
AD_CK = 0;
AD_CS = 1;
}
// one channel
WORD AdMcp320XRead( BYTE byChan )
{
WORD wChan = byChan;
BYTE n = 10;
WORD wData = 0;
wChan &= 7; // mask address
wChan |= 0x18; // start bit, single ended mode
AD_CK = 0; // might have already been
AD_CS = 0; // select the chip
// send channel
while ( n-- )
{
AD_OUT = (wChan & 0x200) ? 1 : 0;
AD_CK = 1;
DelayUsec( 2 );
AD_CK = 0;
wChan <<= 1;
DelayUsec( 2 );
}
// read
n = 14;
while ( n-- )
{
wData << = 1;
AD_CK = 1;
wData |= AD_IN;
DelayNs0200();
AD_CK = 0;
DelayNs0100();
}
AD_CS = 1; // de-select the chip
return wData & 0xfff; // 12 bit mask
}
#endif

View File

@ -1,102 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Microchip MCP3301 A/D Chip
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "analog.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef ANALOG_MCP3301
void AdMcp3301Init( void )
{
AD_CK = 0;
AD_CS = 1;
}
// one channel
short AdMcp3301Read( void )
{
// returns signed a/d value, 12 bits plus sign bit.
// for MCP330X a/d on bit-bang SPI bus
BYTE n = 3;
WORD x = 0;
AD_CK = 0; // might have already been
AD_CS = 0; // select the chip
// convert, interrupts blocked here
while ( n-- )
{
AD_CK = 1;
DelayUsec( 5 );
AD_CK = 0;
DelayUsec( 5 );
}
// read
n = 13;
while ( n-- )
{
x << = 1;
AD_CK = 1;
x |= AD_DAT;
DelayNs0300();
AD_CK = 0;
DelayNs0200();
}
AD_CS = 1; // de-select the chip
// mask and sign extend
x &= 0x1fff;
if ( x & 0x1000 )
x |= 0xf000;
return (short) x;
}
#endif

View File

@ -1,112 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC A/D Interface
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include <stdlib.h>
#include <strings.h>
#include "system.h"
#include "analog.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
#ifdef __linux__
static WORD wAdcData[8] = { 0 };
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void AdInit( void )
{
#ifdef __linux__
bzero( wAdcData, sizeof(wAdcData) );
#else
ADON = 1;
ADFM = 1;
#if defined(_PIC18) && XTAL==40
ADCS2 = 1;
#endif
ADCS1 = 1;
ADCS0 = 0;
#endif
}
WORD AdRead( BYTE byCh )
{
#ifdef __linux__
return wAdcData[byCh&7]++;
#else
short_word data;
ADCON0 = ( byCh << 3 ) | 0b10000000;
#ifdef _PIC18
DelayUsec(13);
#else
DelayUsec(20);
#endif
#ifdef _PIC18
GODONE = 1;
while ( GODONE ) // wait for conversion complete
;
#else
ADGO = 1;
while ( ADGO ) // wait for conversion complete
;
#endif
data.b.h = ADRESH;
data.b.l = ADRESL;
return data.w;
#endif
}
#ifdef __linux__
void AdWrite( BYTE byCh, WORD wData )
{
wAdcData[byCh&7] = wData;
}
#endif

View File

@ -1,57 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC 10-bit A/D
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _ADC_H_
#define _ADC_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
// Internal Analog
extern void AdInit( void );
extern WORD AdRead( BYTE byCh );
extern void AdWrite( BYTE byCh, WORD wData );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,101 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Generic A/D Chip Interface
*----------------------------------------------------------------------------
* PIC 10-bit A/D
* Maxim 186, 188, 355
* Microchip MCP320X, MCP3301
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _ANALOG_H_
#define _ANALOG_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#ifdef ANALOG_MAX186
#define ANALOG_MODULE
#define AnalogInit() AdMax186Init()
#define AnalogRead(C) AdMax186Read(C)
#endif
#ifdef ANALOG_MCP320X
#define ANALOG_MODULE
#define AnalogInit() AdMcp320XInit()
#define AnalogRead(C) AdMcp320XRead(C)
#endif
#ifdef ANALOG_MCP3301
#define ANALOG_MODULE
#define AnalogInit() AdMcp3301Init()
#define AnalogRead(C) AdMcp3301Read()
#endif
#ifdef ADMUX_MAX355
#define AnalogMux(C) AdMax355Mux(C)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
// Internal Analog
extern void AdInit( void );
extern WORD AdRead( BYTE byCh );
extern void AdWrite( BYTE byCh, WORD wData );
// Analog Drivers
#ifdef ANALOG_MAX186
extern void AdMax186Init(void);
extern WORD AdMax186Read( BYTE byChan );
#endif
#ifdef ANALOG_MCP320X
extern void AdMcp320XInit( void );
extern WORD AdMcp320XRead( BYTE byChan );
#endif
#ifdef ANALOG_MCP3301
extern void AdMcp3301Init( void );
extern short AdMcp3301Read( void );
#endif
// Analog Multiplexors
#ifdef ADMUX_MAX355
extern void AdMax355Mux( BYTE byChan );
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,493 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Atmel Data Flash Driver
*----------------------------------------------------------------------------
* Atmel AT45DB041B, AT45DB081B, AT45DB161B Data Flash Driver
* SPI or Bitbanged
*****************************************************************************/
/****************************************************************************/
#include "system.h"
#include "delay.h"
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "atmel.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#if defined(ATMEL_MODULE) || defined(__linux__)
#ifdef __linux__
#define ATMEL_SIZE 1048510L
#define MEMORY_EMUL
#else
#define ATMEL_PAGE 264
#endif
#ifdef ATMEL_SIZE
#define MEMORY_SIZE ATMEL_SIZE
#endif
#define MEMORY_NAME "Atmel"
#define MEMORY_FILE "atmel.pic"
#ifdef MEMORY_DEBUG
#define MEMORY_ERROR
#define READ_PROTECT
#define WRITE_PROTECT
#endif
#define ATYPE DWORD
#include "memio.h"
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
// number of pages
const static WORD wAtmelSizes[16] = {
0,
0,
0,
0,
0,
0,
0,
2048, // AT45DB041B
0,
4096, // AT45DB081B
0,
0,
0,
8192, // AT45DB161B
0,
0
};
/*****************************************************************************
* static variables
*****************************************************************************/
LIBBANK static bit bAtmelBank = 0;
// current page
LIBBANK static bit bWritePending = 0;
LIBBANK static DWORD dwWriteAddr = 0L;
LIBBANK static DWORD dwNextPage = 0L;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
// templated
#include "memio.c"
/* Init *****************************************************************/
#ifdef MEMORY_EMUL
BYTE AtmelStatus( void )
{
return 0;
}
DWORD AtmelSize( void )
{
return MemGetSize();
}
#else
void DevInit( void )
{
#ifdef ATMEL_WP
ATMEL_WP = 0;
#endif
ATMEL_CS1 = 1;
#ifndef ATMEL_SPI
ATMEL_CLK = 0;
#endif
MemSetSize( AtmelSize() );
#ifdef ATMEL_SPI
// spi setup
SpiInit();
SpiWaitTime( 0 );
#endif
}
/* Internal *****************************************************************/
BYTE AtmelStatus( void )
{
BYTE c;
// start
ATMEL_CS1 = 0;
// status command and status read
DevWriteByte( 0, 0xD7 );
c = DevReadByte( 0 );
// end
ATMEL_CS1 = 1;
return c;
}
DWORD AtmelSize( void )
{
// status has id bits
BYTE c = AtmelStatus();
if ( c == 0xff )
return 0;
// map id bits to # of pages times page size
return (DWORD)wAtmelSizes[(c>>2) & 0x0f] * ATMEL_PAGE;
}
void AtmelWait( void )
{
// wait till ready
while ( ( AtmelStatus() & 0x80 ) == 0 )
CLRWDT();
}
/* Command *****************************************************************/
static void AtmelSendCommand( BYTE cd, DWORD dwAddr, BYTE n )
{
BYTE i;
WORD wSegment;
WORD wOffset;
// break up address into page segment and offset
wSegment = (dwAddr / ATMEL_PAGE) << 1; // 15 bit segment
wOffset = (dwAddr % ATMEL_PAGE); // 9 bit offset
#if ATMEL_PAGE > 256
wPage |= (wOffset>>8) & 1; // 9th bit to segment
#endif
// wait till ready
AtmelWait();
// start command
ATMEL_CS1 = 0;
// send command and 24 bit address
DevWriteByte( 0, cd );
DevWriteByte( 0, wSegment >> 8 );
DevWriteByte( 0, wSegment );
DevWriteByte( 0, wOffset );
for ( i = 0; i < n; i++ )
DevWriteByte( 0, 0 );
// may be followed by data
}
// page writing control
static void AtmelReadPage( DWORD dwAddr )
{
// Page to Buffer 1/2 (ignores offset)
AtmelSendCommand( bAtmelBank ? 0x55 : 0x53, dwAddr, 0 );
ATMEL_CS1 = 1; // end command
// write address
dwWriteAddr = dwAddr;
dwNextPage = (dwAddr / ATMEL_PAGE) * ATMEL_PAGE;
}
static void AtmelWritePage( void )
{
if ( !bWritePending )
return;
// Buffer 1/2 to Page w/ Erase (ignores offset)
AtmelSendCommand( bAtmelBank ? 0x86 : 0x83, dwWriteAddr, 0 );
bAtmelBank ^= 1; // switch buffers
ATMEL_CS1 = 1; // end command
bWritePending = 0;
}
static void AtmelWriteBuffer( DWORD dwAddr )
{
// Buffer 1 or 2 Write (ignores segment)
AtmelSendCommand( bAtmelBank ? 0x87 : 0x84, dwAddr, 0 );
// followed by data
}
void AtmelFlush( void )
{
AtmelWritePage();
#ifdef ATMEL_WP
ATMEL_WP = 0;
#endif
}
/* Write ****************************************************************/
static BYTE DevStartWrite( DWORD dwAddr, WORD nBytes )
{
#ifdef ATMEL_WP
// write protect first 64K
if ( dwAddr < 0x10000L )
ATMEL_WP = 1;
#endif
// flush pending write
AtmelWritePage();
// read page to buffer
AtmelReadPage( dwAddr );
// begin buffer write
AtmelWriteBuffer( dwAddr );
return 1;
}
static void DevStopWrite( void )
{
// end buffer write
ATMEL_CS1 = 1;
// check for end of page
if ( MemGetAddr() == dwNextPage )
AtmelWritePage();
}
static void DevWriteByte( DWORD dwAddr, BYTE byData )
{
// write page buffering
if ( dwAddr == dwNextPage )
{
AtmelWritePage();
AtmelReadPage( dwAddr );
}
#ifdef ATMEL_SPI
SpiWriteByte( byData );
#else
byte_bits x;
x.byte = byData;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b7;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b6;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b5;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b4;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b3;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b2;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b1;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
ATMEL_OUT = x.bits.b0;
ATMEL_CLK = 1;
#endif
// write pending only if anything actually written to buffer
bWritePending = 1;
}
/* Read *****************************************************************/
static BYTE DevStartRead( DWORD dwAddr, WORD nBytes )
{
// flush any pending writes
AtmelWritePage();
// Continuous Array Read
AtmelSendCommand( 0xE8, dwAddr, 4 );
return 1;
}
static void DevStopRead( void )
{
ATMEL_CS1 = 1;
}
static BYTE DevReadByte( DWORD dwAddr )
{
#ifdef ATMEL_SPI
return SpiReadByte();
#else
// fast
byte_bits x;
x.byte = 0;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b7 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b6 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b5 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b4 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b3 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b2 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b1 = ATMEL_IN;
ATMEL_CLK = 1;
ATMEL_CLK = 0;
x.bits.b0 = ATMEL_IN;
return x.byte;
#endif
}
#endif
// desired functions
MT_Init(Atmel)
MT_GetChecksum(Atmel)
MT_GetError(Atmel)
MT_ReadBlock(Atmel)
MT_ReadNext(Atmel)
MT_ReadBytes(Atmel)
MT_WriteBlock(Atmel)
MT_WriteNext(Atmel)
MT_WriteBytes(Atmel)
MT_ReadData(Atmel)
MT_WriteData(Atmel)
MT_ReadCSData(Atmel)
MT_WriteCSData(Atmel)
MT_SkipNext(Atmel)
MT_WriteFill(Atmel)
// additional functions
/* Peek/Poke ****************************************************************/
#ifdef ATMEL_DIRECT
BYTE AtmelReadByte( DWORD dwAddr )
{
BYTE byData = 0;
AtmelReadData( dwAddr, &byData, sizeof(BYTE) );
return byData;
}
WORD AtmelReadWord( DWORD dwAddr )
{
WORD wData = 0;
AtmelReadData( dwAddr, (BYTE*)&wData, sizeof(WORD) );
return wData;
}
DWORD AtmelReadDword( DWORD dwAddr )
{
DWORD dwData = 0;
AtmelReadData( dwAddr, (BYTE*)&dwData, sizeof(DWORD) );
return dwData;
}
void AtmelWriteByte( DWORD dwAddr, BYTE byData )
{
AtmelWriteData( dwAddr, (const BYTE *)&byData, sizeof(BYTE) );
}
void AtmelWriteWord( DWORD dwAddr, WORD wData )
{
AtmelWriteData( dwAddr, (const BYTE *)&wData, sizeof(WORD) );
}
void AtmelWriteDword( DWORD dwAddr, DWORD dwData )
{
AtmelWriteData( dwAddr, (const BYTE *)&dwData, sizeof(DWORD) );
}
#endif
/* Erase ********************************************************************/
#ifdef ATMEL_ERASE
void AtmelEraseBlock( DWORD a, DWORD l )
{
#ifdef MEMORY_EMUL
AtmelWriteFill( a, 0, l );
#else
l &= 0x00fff800;
while ( l )
{
AtmelWait();
AtmelSendCommand( 0x50, a, 0 );
ATMEL_CS1 = 1;
a += 0x800;
l -= 0x800;
}
#endif
}
void AtmelErasePage( DWORD a, DWORD l )
{
#ifdef MEMORY_EMUL
AtmelWriteFill( a, 0, l );
#else
l &= 0x00ffff00;
while ( l )
{
AtmelWait();
AtmelSendCommand( 0x81, a, 0 );
ATMEL_CS1 = 1;
a += 0x100;
l -= 0x100;
}
#endif
}
#endif
#endif

View File

@ -1,88 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Atmel Data Flash Chip
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _ATMEL_H_
#define _ATMEL_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "types.h"
#ifdef ATMEL_MODULE
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#define AtmelGetSize() AtmelSize()
#define AtmelReadNextByte() AtmelReadNext()
#define AtmelWriteNextByte(B) AtmelWriteNext(B)
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void AtmelInit( void );
extern BYTE AtmelStatus( void );
extern DWORD AtmelSize( void );
extern void AtmelFlush( void );
extern WORD AtmelReadBlock( DWORD dwAddr, WORD nBytes );
extern BYTE AtmelReadNext( void );
extern WORD AtmelReadBytes( BYTE *pbyData, WORD nBytes );
extern WORD AtmelReadData( DWORD dwAddr, BYTE * pbyData, WORD nBytes );
extern WORD AtmelWriteBlock( DWORD dwAddr, WORD nBytes );
extern void AtmelWriteNext( BYTE byData );
extern WORD AtmelWriteBytes( const BYTE *pbyData, WORD nBytes );
extern WORD AtmelWriteData( DWORD dwAddr, const BYTE *pbyData, WORD nBytes );
extern WORD AtmelWriteFill( DWORD dwAddr, BYTE byFill, WORD nBytes );
extern WORD AtmelReadCSData( DWORD dwAddr, BYTE *pbyData, WORD nBytes );
extern WORD AtmelWriteCSData( DWORD dwAddr, const BYTE *pbyData, WORD nBytes );
extern BYTE AtmelReadByte( DWORD dwAddr );
extern WORD AtmelReadWord( DWORD dwAddr );
extern DWORD AtmelReadDword( DWORD dwAddr );
extern void AtmelWriteByte( DWORD dwAddr, BYTE byData );
extern void AtmelWriteWord( DWORD dwAddr, WORD wData );
extern void AtmelWriteDword( DWORD dwAddr, DWORD dwData );
extern void AtmelEraseBlock( DWORD dwAddr, DWORD nBytes );
extern void AtmelErasePage( DWORD dwAddr, DWORD nBytes );
#ifdef __cpluscplus
}
#endif
#endif
#endif

Binary file not shown.

View File

@ -1,128 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Atmel Memory Test
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#ifdef __linux__
#include <stdio.h>
#endif
#include "atmel.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
BYTE byBuf1[256] = { 0 };
BYTE byBuf2[256] = { 0 };
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
int main()
{
int i;
// init
for ( i=0 ; i<sizeof(byBuf1) ; i++ )
byBuf1[i] = i;
AtmelInit();
printf( "Atmel size = %d bytes\n", AtmelSize() );
// simple test
if ( AtmelWriteData( 0, byBuf1, 128 ) == 128 )
{
if ( AtmelReadData( 0, byBuf2, 128 ) == 128 )
{
if ( memcmp( byBuf1, byBuf2, 128 ) == 0 )
puts( "Block I/O Passed" );
else
puts( "Block I/O Failed!" );
}
else
puts( "Block I/O Read Failed!" );
}
else
puts( "Block I/O Write Failed!" );
// checksum test
if ( AtmelWriteCSData( 128, byBuf1, 128 ) )
{
if ( AtmelReadCSData( 128, byBuf2, 128 ) == 128 )
{
if ( memcmp( byBuf1, byBuf2, 127 ) == 0 )
puts( "CS Block I/O Passed" );
else
puts( "CS Block I/O Failed!" );
}
else
puts( "CS Block I/O Read Failed!" );
}
else
puts( "CS Block I/O Write Failed!" );
// boundary check
if ( AtmelWriteData( AtmelSize()-50, byBuf1, 100 ) != 100 )
puts( "Block I/O Out of bounds failed like it should" );
else
puts( "Block I/O Out of bounds succeeded in failing!" );
// overwrite check
if ( AtmelWriteBlock( 512, 50 ) == 50 )
{
if ( AtmelWriteBytes( byBuf1, 51 ) == 50 )
puts( "Block I/O Overwrite terminated like it should" );
else
puts( "Block I/O Overrwrite succeeded in failing!" );
}
else
puts( "Block I/O Write block setup failed!" );
printf( "Error = %02x\n", AtmelGetError() );
#ifndef __linux__
for (;;)
;
#endif
return 0;
}

View File

@ -1,86 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux Clock Emulation Driver
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "clock.h"
#include "delay.h"
#include <time.h>
#ifdef __linux__
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void ClkNju6355Init( void )
{
}
void ClkNju6355Write( CLKBANK NJU6355Clock * pClk )
{
}
void ClkNju6355Read( CLKBANK NJU6355Clock * pClk )
{
// read time
time_t t;
struct tm *ptm;
time( &t );
ptm = localtime( &t );
// 52 bits
pClk->byYear = bin2bcd( ptm->tm_year - 100 );
pClk->byMonth = bin2bcd( ptm->tm_mon + 1 );
pClk->byDay = bin2bcd( ptm->tm_mday );
pClk->byWeekDay = ptm->tm_wday + 1;
pClk->byHour = bin2bcd( ptm->tm_hour );
pClk->byMinute = bin2bcd( ptm->tm_min );
pClk->bySecond = bin2bcd( ptm->tm_sec );
pClk->byHundredth = 0;
}
#endif

View File

@ -1,184 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* NJU 6355 Clock Driver
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "clock.h"
#include "delay.h"
#ifndef _PIC
#include <time.h>
#endif
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef CLOCK_NJU6355
void ClkNju6355Init( void )
{
// deselect
CLK_CE = 0;
// float all inputs
CLK_CK_DIR = 1;
CLK_CK = 1;
CLK_DT_DIR = 1;
CLK_DT = 1;
}
static void ClockWriteBits( BYTE x, BYTE n )
{
// push bits out LSB first
while ( n-- )
{
// low
CLK_CK = 0;
// data
CLK_DT = ( x & 1 ) ? 1 : 0;
x >>= 1;
// clock on rising edge
DelayNs0100(); // Twds
CLK_CK = 1;
DelayNs0100(); // Twdh
}
CLK_CK = 0;
}
void ClkNju6355Write( CLKBANK NJU6355Clock * pClk )
{
// all outputs
CLK_CK = 0;
CLK_DT = 0;
CLK_CK_DIR = 0;
CLK_DT_DIR = 0;
// select chip
CLK_IO = 1; // slow to rise
DelayNs0100(); // Tds
CLK_CE = 1;
DelayNs0500(); // Tcs
// 44 bits, write order
ClockWriteBits( pClk->byYear, 8 );
ClockWriteBits( pClk->byMonth, 8 );
ClockWriteBits( pClk->byDay, 8 );
ClockWriteBits( pClk->byWeekDay, 4 );
ClockWriteBits( pClk->byHour, 8 );
ClockWriteBits( pClk->byMinute, 8 );
// deselect chip
CLK_CE = 0;
CLK_IO = 0;
// float inputs
CLK_CK_DIR = 1;
CLK_DT_DIR = 1;
}
static BYTE ClockReadBits( BYTE n )
{
BYTE x = 0;
BYTE b = 1;
// pop bits in LSB first
while ( n-- )
{
// high
DelayNs0200();
CLK_CK = 1;
// read data (previous falling edge)
if ( CLK_DT )
x |= b;
b <<= 1;
// falling edge
#if XTAL == 40
DelayNs0200();
#endif
CLK_CK = 0;
DelayNs0200();
}
DelayNs0300();
CLK_CK = 1;
// returns BCD
return x;
}
void ClkNju6355Read( CLKBANK NJU6355Clock * pClk )
{
// clock out, data in
CLK_CK = 0;
CLK_CK_DIR = 0;
CLK_DT_DIR = 1;
// select chip
CLK_IO = 0;
DelayNs0100(); // Tds
CLK_CE = 1;
DelayNs0500(); // Tcs
// 52 bits
pClk->byYear = ClockReadBits( 8 ); // bad year means low voltage
pClk->byMonth = ClockReadBits( 8 );
pClk->byDay = ClockReadBits( 8 );
pClk->byWeekDay = ClockReadBits( 4 );
pClk->byHour = ClockReadBits( 8 );
pClk->byMinute = ClockReadBits( 8 );
pClk->bySecond = ClockReadBits( 8 );
// deselect chip
CLK_CE = 0;
// float inputs
CLK_CK_DIR = 1;
CLK_DT_DIR = 1;
}
#endif

View File

@ -1,93 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Generic Clock Chip Interface
*----------------------------------------------------------------------------
* NJU 6355
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _CLOCK_H_
#define _CLOCK_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#ifdef CLOCK_NJU6355
#define CLOCK_MODULE
// JRC NJU6355
#define SECOND 0
#define MINUTE 1
#define HOUR 2
#define WEEKDAY 3
#define DATE 4
#define MONTH 5
#define YEAR 6
#endif
/*****************************************************************************
* macros
*****************************************************************************/
#ifdef CLOCK_NJU6355
#define ClockInit() ClockNju6355Init()
#define ClockWrite(C) ClockNju6355Write(C)
#define ClockRead(C) ClockNju6355Read(C)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _GenericClock
{
BYTE byHundredth; // 100th second
BYTE bySecond; // 0-59
BYTE byMinute; // 0-59
BYTE byHour; // 0-23
BYTE byWeekDay; // 1-7
BYTE byDay; // 1-31
BYTE byMonth; // 1-12
BYTE byYear; // 0-99 starting from 2000
} GenericClock;
#ifdef CLOCK_NJU6355
typedef struct _GenericClock NJU6355Clock;
#endif
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CLOCK_NJU6355
extern void ClkNju6355Init( void );
extern void ClkNju6355Write( CLKBANK NJU6355Clock * pClk );
extern void ClkNju6355Read( CLKBANK NJU6355Clock * pClk );
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,137 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC C Library Custom Build Configuration
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _CONFIG_H_
#define _CONFIG_H_
/*****************************************************************************
* includes
*****************************************************************************/
//
// bump this number on each release of this library
//
#define PICLIB_VERSION 1
#define PICLIB_BUILD 1
/*****************************************************************************
* defines
*****************************************************************************/
// The following modules are always used
#define TIMER_MODULE // Interrupts for timers
#define SERIAL_MODULE // Should double check serial.h for port assignments
// The following modules are linked in if we use them
#define FLASH_MODULE // compile this in, so it's available
#define PACKET_MODULE // default, but should be compiled for app
#ifdef __linux__
//----------------------------------------------------------------------------
// Linux port
//----------------------------------------------------------------------------
#define XTAL 20L
#define LIBBANK
#define PKTBANK
#define SERBANK
#elif _PIC18
//----------------------------------------------------------------------------
// PIC-18 Port
//----------------------------------------------------------------------------
#ifndef XTAL
#define XTAL 40L
#endif
#define LIBBANK near
#define PKTBANK
#define SERBANK
#define PACKET_FILTER
#else
//----------------------------------------------------------------------------
// PIC-16 Port
//----------------------------------------------------------------------------
#ifndef XTAL
#define XTAL 20L
#endif
#define LIBBANK bank1
#define PKTBANK bank2
#define SERBANK bank2
#endif
//-----------------------------------------------------------------------------
// Defaults
//-----------------------------------------------------------------------------
#ifndef BAUD
#define BAUD 56700L // serial port
#endif
// timers
#define TIMER1_INT // fast timer
#define TIMER2_INT // msec timer
#ifdef _PIC18
#define SW_TIMERS 4
#else
#define SW_TIMERS 2
#endif
// counters
#define CCP1_PIN
#define CCP2_PIN
// portb i/o
#define RB0_PIN
#define RB1_PIN
#define RB2_PIN
#define RB4_PIN
#define RB5_PIN
#define RB6_PIN
#define RB7_PIN
//-----------------------------------------------------------------------------
// Dependencies
//-----------------------------------------------------------------------------
// timer 1 needed for period counting
#if (defined(CCP1_PIN) && defined(CCP2_PIN)) && !defined(TIMER1_INT)
#define TIMER1_INT
#endif
// timer 1 needed for pin interrupt time stamp
#if defined(RB0_PIN) && !defined(TIMER1_INT)
#define TIMER1_INT
#endif
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
#endif

View File

@ -1,229 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Data EE Driver
*----------------------------------------------------------------------------
* Low end PICs have FLASH, while high end PICs have EEPROM
* This does not access the program flash memory!
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "dataee.h"
/*****************************************************************************
* defines
*****************************************************************************/
// Linux emulation
#ifdef __linux__
#define MEMORY_EMUL
#endif
// default size
#ifndef EEPROM_SIZE
#define EEPROM_SIZE 256
#endif
#define MEMORY_NAME "DataEE"
#define MEMORY_FILE "dataee.pic"
#define MEMORY_SIZE EEPROM_SIZE
#ifdef MEMORY_DEBUG
#if EEPROM_SIZE > 256
#define READ_PROTECT
#endif
#define WRITE_COUNTING
#endif
#if EEPROM_SIZE <= 256
#define ATYPE BYTE
#define STYPE BYTE
#else
#define ATYPE WORD
#define STYPE BYTE
#endif
#include "memio.h"
/*****************************************************************************
* macros
*****************************************************************************/
#ifndef MEMORY_EMUL
// hardware i/o
#define DevStartRead(A,N) DevStart()
#define DevStopRead()
#define DevStartWrite(A,N) DevStart()
#define DevStopWrite()
// map byte i/o
#define DevReadByte(A) eeprom_read(A)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifndef MEMORY_EMUL
// device functions
static void DevInit( void )
{
MemSetSize( EEPROM_SIZE );
}
static BYTE DevStart( void )
{
#ifdef _PIC18
// access data eeprom
EEPGD = 0;
CFGS = 0;
#endif
return 1;
}
static void DevWriteByte( WORD wAddr, BYTE byData )
{
BYTE byComp;
BYTE nTries = 3;
while ( nTries-- )
{
// read
byComp = EEPROM_READ(wAddr);
// compare
if ( byData == byComp )
return;
// write
EEPROM_WRITE(wAddr,byData);
#ifdef WRITE_COUNTING
// bump write count
MemIncrCount();
#endif
}
#ifdef MEMORY_ERROR
// mark error
MemSetError( MEM_ERR_WRITE );
#endif
}
// special functions
#ifdef WRITE_COUNTING
void DataEERefresh( void )
{
WORD a = 0;
WORD n = EEPROM_SIZE;
BYTE d;
while ( n-- )
{
d = DevReadByte( a );
DevWriteByte( a++, d );
}
}
#endif
#endif
// templated
#include "memio.c"
// desired functions
MT_Init(DataEE)
MT_GetChecksum(DataEE)
MT_GetError(DataEE)
MT_ReadBlock(DataEE)
MT_ReadNext(DataEE)
MT_ReadBytes(DataEE)
MT_WriteBlock(DataEE)
MT_WriteNext(DataEE)
MT_WriteBytes(DataEE)
MT_ReadData(DataEE)
MT_WriteData(DataEE)
MT_ReadCSData(DataEE)
MT_WriteCSData(DataEE)
MT_SkipNext(DataEE)
MT_WriteFill(DataEE)
#ifdef WRITE_COUNTING
// additional functions
DWORD DataEEGetCount( void )
{
return MemGetCount();
}
void DataEESetCount( DWORD dwCount )
{
MemSetCount( dwCount );
}
#endif
#ifdef DATAEE_DIRECT
WORD DataEEReadWord( ATYPE wAddr )
{
short_word data;
data.b.l = DevReadByte( wAddr++ );
data.b.h = DevReadByte( wAddr );
return data.w;
}
void DataEEWriteWord( ATYPE wAddr, WORD wData )
{
DevWriteByte( wAddr++, wData );
DevWriteByte( wAddr, wData >> 8 );
}
DWORD DataEEReadDword( ATYPE wAddr )
{
long_dword data;
data.b.ll = DevReadByte( wAddr++ );
data.b.lh = DevReadByte( wAddr++ );
data.b.hl = DevReadByte( wAddr++ );
data.b.hh = DevReadByte( wAddr );
return data.dw;
}
void DataEEWriteDword( ATYPE wAddr, DWORD dwData )
{
DevWriteByte( wAddr++, dwData );
DevWriteByte( wAddr++, dwData >> 8 );
DevWriteByte( wAddr++, dwData >> 16 );
DevWriteByte( wAddr, dwData >> 24 );
}
#endif

View File

@ -1,98 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Data EEPROM
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _DATAEE_H_
#define _DATAEE_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "config.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#ifndef EEPROM_SIZE
#define EEPROM_SIZE 256
#endif
#if EEPROM_SIZE <= 256
#define ATYPE BYTE
#define STYPE BYTE
#else
#define ATYPE WORD
#define STYPE BYTE
#endif
/*****************************************************************************
* macros
*****************************************************************************/
#define DataEEGetSize() EEPROM_SIZE
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern STYPE DataEEReadBlock( ATYPE xAddr, BYTE nBytes );
extern STYPE DataEEWriteBlock( ATYPE xAddr, BYTE nBytes );
extern void DataEESkip( BYTE nBytes );
extern BYTE DataEEReadNext( void );
extern STYPE DataEEReadBytes( BYTE *pbyData, BYTE nBytes );
extern STYPE DataEEReadData( ATYPE xAddr, BYTE *pbyData, BYTE nBytes );
extern void DataEEWriteNext( BYTE byData );
extern STYPE DataEEWriteBytes( const BYTE *pbyData, BYTE nBytes );
extern STYPE DataEEWriteData( ATYPE xAddr, const BYTE *pbyData, BYTE nBytes );
extern STYPE DataEEWriteFill( ATYPE xAddr, BYTE byFill, BYTE nBytes );
extern STYPE DataEEReadCSData( ATYPE xAddr, BYTE *pbyData, BYTE nBytes );
extern STYPE DataEEWriteCSData( ATYPE xAddr, const BYTE *pbyData, BYTE nBytes );
extern WORD DataEEReadWord( ATYPE xAddr );
extern void DataEEWriteWord( ATYPE xAddr, WORD wData );
extern DWORD DataEEReadDword( ATYPE xAddr );
extern void DataEEWriteDword( ATYPE xAddr, DWORD dwData );
extern BYTE DataEEGetChecksum( void );
extern BYTE DataEEGetError( void );
extern DWORD DataEEGetCount( void );
extern void DataEESetCount( DWORD dwCount );
extern void DataEERefresh( void );
#ifdef __cpluscplus
}
#endif
#undef ATYPE
#undef STYPE
#endif

Binary file not shown.

View File

@ -1,113 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Data EE Test
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#ifdef __linux__
#include <stdio.h>
#endif
#include "dataee.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
BYTE byBuf1[256] = { 0 };
BYTE byBuf2[256] = { 0 };
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
int main()
{
int i;
// init
for ( i=0 ; i<sizeof(byBuf1) ; i++ )
byBuf1[i] = i;
DataEEInit();
// simple test
if ( DataEEWriteData( 0, byBuf1, 128 ) == 128 )
{
if ( DataEEReadData( 0, byBuf2, 128 ) == 128 )
{
if ( memcmp( byBuf1, byBuf2, 128 ) == 0 )
puts( "Block I/O Passed" );
else
puts( "Block I/O Failed!" );
}
else
puts( "Block I/O Read Failed!" );
}
else
puts( "Block I/O Write Failed!" );
// checksum test
if ( DataEEWriteCSData( 128, byBuf1, 128 ) )
{
if ( DataEEReadCSData( 128, byBuf2, 128 ) == 128 )
{
if ( memcmp( byBuf1, byBuf2, 127 ) == 0 )
puts( "CS Block I/O Passed" );
else
puts( "CS Block I/O Failed!" );
}
else
puts( "CS Block I/O Read Failed!" );
}
else
puts( "CS Block I/O Write Failed!" );
// boundary check
if ( DataEEWriteData( 192, byBuf1, 100 ) != 100 )
puts( "Block I/O Out of bounds failed like it should" );
else
puts( "Block I/O Out of bounds succeeded in failing!" );
#ifndef __linux__
for (;;)
;
#endif
return 0;
}

View File

@ -1,225 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Delay functions for PIC-16/18 at 20/40 Mhz
*----------------------------------------------------------------------------
* Make sure this code is compiled with optimization -O -Zg4
*
* Note accuracy issues below XTAL=16 MHz.
* At or above this the loop is exactly 1 micro-second per iteration.
* The 20MHz version is correct down to 2 micro-seconds.
*
* Sample delay routines from HI-TECH were pretty sucky
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _DELAY_H_
#define _DELAY_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#ifdef __linux__
#include <unistd.h>
#endif
/*****************************************************************************
* defines
*****************************************************************************/
#ifdef __linux__
//-----------------------------------------------------------------------------
// Delays mapped to sleep functions
//-----------------------------------------------------------------------------
#define DelayInit()
#define DelayUsec(C) usleep(C)
#define DelayMsec(C) usleep((C)*1000)
#define DelaySec(C) sleep(C)
#else
//-----------------------------------------------------------------------------
// Microsecond delay routine
//-----------------------------------------------------------------------------
#if XTAL == 20
// PIC-18 20Mhz
#define DelayUs(x) { \
_dcnt = x; \
while(--_dcnt) { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
} \
}
#elif XTAL == 40
// PIC-18 40Mhz
#define DelayUs(x) { \
_dcnt = x; \
while(--_dcnt) { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
} \
}
#endif
#endif
/*****************************************************************************
* macros
*****************************************************************************/
#ifndef __linux__
//-----------------------------------------------------------------------------
// Fixed Delays
//-----------------------------------------------------------------------------
#ifdef XTAL == 20
// 20Mhz PIC-16 or PIC-18
#define DelayNs0100() { \
asm("nop"); \
}
#define DelayNs0200() { \
asm("nop"); \
}
#define DelayNs0300() { \
asm("nop"); \
asm("nop"); \
}
#define DelayNs0400() { \
asm("nop"); \
asm("nop"); \
}
#define DelayNs0500() { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
}
#define DelayNs1000() { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
}
#elif XTAL == 40
// PIC-18 40Mhz
#define DelayNs0100() { \
asm("nop"); \
}
#define DelayNs0200() { \
asm("nop"); \
asm("nop"); \
}
#define DelayNs0300() { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
}
#define DelayNs0400() { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
}
#define DelayNs0500() { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
}
#define DelayNs1000() { \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
asm("nop"); \
}
#endif
// Nanosecond delays
#define DelayNs1500() { \
DelayNs0500(); \
DelayNs1000(); \
}
#define DelayNs2000() { \
DelayNs1000(); \
DelayNs1000(); \
}
#define DelayNs3000() { \
DelayNs2000(); \
DelayNs1000(); \
}
#define DelayNs4000() { \
DelayNs2000(); \
DelayNs2000(); \
}
#define DelayNs5000() { \
DelayNs2000(); \
DelayNs2000(); \
DelayNs1000(); \
}
// Microsecond delays
#define DelayUs1() DelayNs1000()
#define DelayUs2() DelayNs2000()
#define DelayUs3() DelayNs3000()
#define DelayUs4() DelayNs4000()
#define DelayUs5() DelayNs5000()
#define DelayUs10() { \
DelayUs5(); \
DelayUs5(); \
}
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
#ifndef __linux__
extern LIBBANK volatile BYTE _dcnt;
#endif
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __linux__
extern void DelayInit( void ); // Timer #0 init
// library delay routines
extern void DelayUsec( BYTE byCount ); // short delays up to 50usec
extern void DelayUsecW( WORD wCount ); // longer delays over 5usec
extern void DelayMsec( WORD wCount );
extern void DelaySec( WORD wCount );
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,70 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Millisecond Delay
*----------------------------------------------------------------------------
* 200nsec instruction cycle at 20Mhz, 100nsec at 40Mhz
* You have to examine the asm output to count the instructions
* Make sure this code is compiled with optimization -O -Zg4
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void DelayMsec( WORD n )
{
while ( n-- )
{
#ifdef _PIC18
DelayUsecW( 1000 );
#else
DelayUsec( 250 );
DelayUsec( 250 );
DelayUsec( 250 );
DelayUsec( 250 );
#endif
CLRWDT();
}
}

View File

@ -1,58 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Second Delay Routine
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void DelaySec( WORD n )
{
while ( n-- )
DelayMsec( 1000 );
}

View File

@ -1,113 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Microsecond Delay Routine using Timer 0
*----------------------------------------------------------------------------
* 200nsec instruction cycle at 20Mhz, 100nsec at 40Mhz
* You have to examine the asm output to count the instructions
* Make sure this code is compiled with optimization -O -Zg4
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// used by DelayUs() macro
LIBBANK volatile BYTE _dcnt = 0;
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void DelayInit( void )
{
// timer #0 as counter, 2 nsec counts (5 per usec)
#ifdef _PIC18
#if XTAL==40
T0CON = 0b10000000; // prescalar = 2
#else
T0CON = 0b10001000; // no prescalar
#endif
#else
OPTION = 0b10000000;
#endif
}
// short delays up to 255 usec
void DelayUsec( BYTE n )
{
// clear counter
#ifdef _PIC18
TMR0H = 0;
TMR0L = 0;
#else
TMR0 = 0;
#endif
// # ticks per usec
n--; // calling overhead
n *= 5;
// wait till count reaches
#ifdef _PIC18
while ( TMR0L < n )
;
#else
while ( TMR0 < n )
;
#endif
}
// longer delays up to 10000 usec (10 msec)
#ifdef _PIC18
void DelayUsecW( WORD n )
{
// clear counter
TMR0H = 0;
TMR0L = 0;
// 5 ticks per usec
n--; // calling overhead
n *= 5;
// wait till count reaches
while ( TMR0 < n )
;
}
#endif

View File

@ -1,54 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux Digital I/O Emulation Driver
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "emul.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
byte_bits bbDigdir[8];
byte_bits bbDigio[8];
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/

View File

@ -1,169 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux PIC Emulation
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _EMUL_H_
#define _EMUL_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
// macros
#define _port_byte(A) bbDigio[A].byte
#define _port_bit(A,B) bbDigio[A].bits.b(B)
#define _port_dirbyte(A) bbDigdir[A].byte
#define _port_dirbit(A,D) bbDigdir[A].bits.b(D)
//
// emulation
#define PORTA _port_byte(0)
#define RA0 _port_bit(0,0)
#define RA1 _port_bit(0,1)
#define RA2 _port_bit(0,2)
#define RA3 _port_bit(0,3)
#define RA4 _port_bit(0,4)
#define RA5 _port_bit(0,5)
#define RA6 _port_bit(0,6)
#define RA7 _port_bit(0,7)
#define PORTB _port_byte(1)
#define RB0 _port_bit(1,0)
#define RB1 _port_bit(1,1)
#define RB2 _port_bit(1,2)
#define RB3 _port_bit(1,3)
#define RB4 _port_bit(1,4)
#define RB5 _port_bit(1,5)
#define RB6 _port_bit(1,6)
#define RB7 _port_bit(1,7)
#define PORTC _port_byte(2)
#define RC0 _port_bit(2,0)
#define RC1 _port_bit(2,1)
#define RC2 _port_bit(2,2)
#define RC3 _port_bit(2,3)
#define RC4 _port_bit(2,4)
#define RC5 _port_bit(2,5)
#define RC6 _port_bit(2,6)
#define RC7 _port_bit(2,7)
#define PORTD _port_byte(3)
#define RD0 _port_bit(3,0)
#define RD1 _port_bit(3,1)
#define RD2 _port_bit(3,2)
#define RD3 _port_bit(3,3)
#define RD4 _port_bit(3,4)
#define RD5 _port_bit(3,5)
#define RD6 _port_bit(3,6)
#define RD7 _port_bit(3,7)
#define PORTE _port_byte(4)
#define RE0 _port_bit(4,0)
#define RE1 _port_bit(4,1)
#define RE2 _port_bit(4,2)
#define RE3 _port_bit(4,3)
#define RE4 _port_bit(4,4)
#define RE5 _port_bit(4,5)
#define RE6 _port_bit(4,6)
#define RE7 _port_bit(4,7)
#define TRISA _port_dirbyte(0)
#define TRISA0 _port_dirbit(0,0)
#define TRISA1 _port_dirbit(0,1)
#define TRISA2 _port_dirbit(0,2)
#define TRISA3 _port_dirbit(0,3)
#define TRISA4 _port_dirbit(0,4)
#define TRISA5 _port_dirbit(0,5)
#define TRISA6 _port_dirbit(0,6)
#define TRISA7 _port_dirbit(0,7)
#define TRISB _port_dirbyte(1)
#define TRISB0 _port_dirbit(1,0)
#define TRISB1 _port_dirbit(1,1)
#define TRISB2 _port_dirbit(1,2)
#define TRISB3 _port_dirbit(1,3)
#define TRISB4 _port_dirbit(1,4)
#define TRISB5 _port_dirbit(1,5)
#define TRISB6 _port_dirbit(1,6)
#define TRISB7 _port_dirbit(1,7)
#define TRISC _port_dirbyte(2)
#define TRISC0 _port_dirbit(2,0)
#define TRISC1 _port_dirbit(2,1)
#define TRISC2 _port_dirbit(2,2)
#define TRISC3 _port_dirbit(2,3)
#define TRISC4 _port_dirbit(2,4)
#define TRISC5 _port_dirbit(2,5)
#define TRISC6 _port_dirbit(2,6)
#define TRISC7 _port_dirbit(2,7)
#define TRISD _port_dirbyte(3)
#define TRISD0 _port_dirbit(3,0)
#define TRISD1 _port_dirbit(3,1)
#define TRISD2 _port_dirbit(3,2)
#define TRISD3 _port_dirbit(3,3)
#define TRISD4 _port_dirbit(3,4)
#define TRISD5 _port_dirbit(3,5)
#define TRISD6 _port_dirbit(3,6)
#define TRISD7 _port_dirbit(3,7)
#define TRISE _port_dirbyte(4)
#define TRISE0 _port_dirbit(4,0)
#define TRISE1 _port_dirbit(4,1)
#define TRISE2 _port_dirbit(4,2)
#define TRISE3 _port_dirbit(4,3)
#define TRISE4 _port_dirbit(4,4)
#define TRISE5 _port_dirbit(4,5)
#define TRISE6 _port_dirbit(4,6)
#define TRISE7 _port_dirbit(4,7)
#define TO 1
#define BOR 1
#define RI 1
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
extern byte_bits bbDigdir[8];
extern byte_bits bbDigio[8];
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,260 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* FRAM Chip Driver
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "fram.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#if defined(FRAM_MODULE) || defined(__linux__)
#ifdef __linux__
#define FRAM_SIZE 8192
#undef FRAM_SCL
// Linux I2C driver?
#define MEMORY_EMUL
#endif
#ifdef FRAM_SIZE
#define MEMORY_SIZE FRAM_SIZE
#endif
#define MEMORY_FILE "fram.pic"
#define MEMORY_NAME "Fram"
#ifdef MEMORY_DEBUG
#define MEMORY_ERROR // track errors
#define READ_PROTECT
#define WRITE_PROTECT
#endif
#include "memio.h"
#ifdef FRAM_SCL
// internalize the module for I2C bit banged I/O
#define I2C_INTERNAL
#define I2C_MODULE
#endif
#ifdef I2C_INTERNAL
// port definitions from project.h
#define SCL FRAM_SCL
#define SCL_DIR FRAM_SCL_DIR
#define SDA FRAM_SDA
#define SDA_DIR FRAM_SDA_DIR
// include the C modules directly
// adjusted timings
#define I2C_TM_PUT_FUDGE 0
#define I2C_TM_START_SU 1
#define I2C_TM_START_HD 1
#define I2C_TM_SCL_LOW 0
#define I2C_TM_SCL_HIGH 0
#define I2C_TM_DATA_SU 0
#define I2C_TM_DATA_HD 0
#define I2C_TM_SCL_TO_DATA 0 // SCL low to data valid
#define I2C_TM_STOP_SU 1
#define I2C_TM_STOP_HD 0
#define I2C_TM_BUS_FREE 1
#define I2C_TM_SCL_TMO 0 // clock time out
#include "i2c_master.h"
#include "i2c_bitbang.c"
#else
//#include "i2c_master.h"
#endif
/*****************************************************************************
* macros
*****************************************************************************/
#ifndef MEMORY_EMUL
#define DevStopRead() i2c_StopRead()
#define DevStopWrite() i2c_StopWrite()
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
// templated
#include "memio.c"
/* Init *****************************************************************/
// special functions
DWORD FramSize( void )
{
#ifdef FRAM_SIZE
return FRAM_SIZE;
#else
BYTE byZero, byTest, byCount;
WORD wAddr;
// already sized?
if ( MemGetSize() )
return MemGetSize();
wAddr = 0; // establish test byte addr
byZero = FramReadByte(wAddr); // store test byte
FramWriteByte(wAddr, 0); // establish test byte value
byCount=0;
while (FramReadByte(0) == 0)
{
if (++byCount > 1)
FramWriteByte(wAddr, byTest); // restore real byte
wAddr += 8192; // increment address 8K
byTest = FramReadByte(wAddr); // store real byte
FramWriteByte(wAddr, byCount); // write real/test byte
}
FramWriteByte(0, byZero); // restore test byte
return (DWORD)wAddr;
#endif
}
/* I/O ******************************************************************/
#ifndef MEMORY_EMUL
// device functions
static BYTE FramWriteAddr( WORD wAddr )
{
// setup up for write
BYTE byCtl = ROM | ((wAddr & 0x8000) >> 14);
i2c_WriteTo( byCtl );
i2c_PutByte( wAddr >> 8 );
i2c_PutByte( wAddr );
return byCtl;
}
static void DevInit( void )
{
#ifdef I2C_INTERNAL
I2C_init();
#endif
MemSetSize( FramSize() );
}
static BYTE DevStartRead( WORD wAddr, WORD nBytes )
{
i2c_ReadFrom( FramWriteAddr( wAddr ) );
return 1;
}
static BYTE DevReadByte( WORD wAddr )
{
return i2c_GetByte( MemGetLen() > 0 ? I2C_MORE : I2C_LAST );
}
static BYTE DevStartWrite( WORD wAddr, WORD nBytes )
{
FramWriteAddr( wAddr );
return 1;
}
static void DevWriteByte( WORD wAddr, BYTE byData )
{
i2c_PutByte( byData );
}
#endif
// desired functions
MT_Init(Fram)
MT_GetChecksum(Fram)
MT_GetError(Fram)
MT_ReadBlock(Fram)
MT_ReadNext(Fram)
MT_ReadBytes(Fram)
MT_WriteBlock(Fram)
MT_WriteNext(Fram)
MT_WriteBytes(Fram)
MT_ReadData(Fram)
MT_WriteData(Fram)
MT_ReadCSData(Fram)
MT_WriteCSData(Fram)
MT_SkipNext(Fram)
MT_WriteFill(Fram)
// additional functions
#ifdef FRAM_DIRECT
BYTE FramReadByte( WORD wAddr )
{
BYTE byData = 0;
FramReadData( wAddr, &byData, sizeof(BYTE) );
return byData;
}
WORD FramReadWord( WORD wAddr )
{
WORD wData = 0;
FramReadData( wAddr, (BYTE*)&wData, sizeof(WORD) );
return wData;
}
DWORD FramReadDword( WORD wAddr )
{
DWORD dwData = 0;
FramReadData( wAddr, (BYTE*)&dwData, sizeof(DWORD) );
return dwData;
}
void FramWriteByte( WORD wAddr, BYTE byData )
{
FramWriteData( wAddr, (const BYTE *)&byData, sizeof(BYTE) );
}
void FramWriteWord( WORD wAddr, WORD wData )
{
FramWriteData( wAddr, (const BYTE *)&wData, sizeof(WORD) );
}
void FramWriteDword( WORD wAddr, DWORD dwData )
{
FramWriteData( wAddr, (const BYTE *)&dwData, sizeof(DWORD) );
}
#endif
#endif

View File

@ -1,84 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* FRAM Chip Interface
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _FRAM_H_
#define _FRAM_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "config.h"
#include "types.h"
#ifdef FRAM_MODULE
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#define FramGetSize() FramSize()
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void FramInit( void );
extern DWORD FramSize( void );
extern WORD FramReadBlock( WORD wAddr, WORD nBytes );
extern BYTE FramReadNext( void );
extern WORD FramReadBytes( BYTE *pbyData, WORD nBytes );
extern WORD FramReadData( WORD wAddr, BYTE *pbyData, WORD nBytes );
extern WORD FramWriteBlock( WORD wAddr, WORD nBytes );
extern void FramWriteNext( BYTE byData );
extern WORD FramWriteBytes( const BYTE *pbyData, WORD nBytes );
extern WORD FramWriteData( WORD wAddr, const BYTE *pbyData, WORD nBytes );
extern WORD FramWriteFill( WORD wAddr, BYTE byFill, WORD nBytes );
extern WORD FramReadCSData( WORD wAddr, BYTE *pbyData, WORD nBytes );
extern WORD FramWriteCSData( WORD wAddr, const BYTE *pbyData, WORD nBytes );
extern BYTE FramGetChecksum( void );
extern BYTE FramGetError( void );
extern BYTE FramReadByte( WORD wAddr );
extern WORD FramReadWord( WORD wAddr );
extern DWORD FramReadDword( WORD wAddr );
extern void FramWriteByte( WORD wAddr, BYTE byData );
extern void FramWriteWord( WORD wAddr, WORD wData );
extern void FramWriteDword( WORD wAddr, DWORD dwData );
#ifdef __cpluscplus
}
#endif
#endif
#endif

Binary file not shown.

View File

@ -1,128 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* FRAM Memory Test
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#ifdef __linux__
#include <stdio.h>
#endif
#include "fram.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
BYTE byBuf1[256] = { 0 };
BYTE byBuf2[256] = { 0 };
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
int main()
{
int i;
// init
for ( i=0 ; i<sizeof(byBuf1) ; i++ )
byBuf1[i] = i;
FramInit();
printf( "Fram size = %d bytes\n", FramSize() );
// simple test
if ( FramWriteData( 0, byBuf1, 128 ) == 128 )
{
if ( FramReadData( 0, byBuf2, 128 ) == 128 )
{
if ( memcmp( byBuf1, byBuf2, 128 ) == 0 )
puts( "Block I/O Passed" );
else
puts( "Block I/O Failed!" );
}
else
puts( "Block I/O Read Failed!" );
}
else
puts( "Block I/O Write Failed!" );
// checksum test
if ( FramWriteCSData( 128, byBuf1, 128 ) )
{
if ( FramReadCSData( 128, byBuf2, 128 ) == 128 )
{
if ( memcmp( byBuf1, byBuf2, 127 ) == 0 )
puts( "CS Block I/O Passed" );
else
puts( "CS Block I/O Failed!" );
}
else
puts( "CS Block I/O Read Failed!" );
}
else
puts( "CS Block I/O Write Failed!" );
// boundary check
if ( FramWriteData( FramSize()-50, byBuf1, 100 ) != 100 )
puts( "Block I/O Out of bounds failed like it should" );
else
puts( "Block I/O Out of bounds succeeded in failing!" );
// overwrite check
if ( FramWriteBlock( 512, 50 ) == 50 )
{
if ( FramWriteBytes( byBuf1, 51 ) == 50 )
puts( "Block I/O Overwrite terminated like it should" );
else
puts( "Block I/O Overrwrite succeeded in failing!" );
}
else
puts( "Block I/O Write block setup failed!" );
printf( "Error = %02x\n", FramGetError() );
#ifndef __linux__
for (;;)
;
#endif
return 0;
}

View File

@ -1,394 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC I2C Master, software bit-banged
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "i2c.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#if defined(I2C_MODULE) || defined(I2C_INTERNAL)
I2C_EXPORT void i2c_init( void )
{
// bit banged
SCL_DIR = I2C_INPUT;
SDA_DIR = I2C_INPUT;
SDA = 1;
SCL = 1;
}
I2C_EXPORT void i2c_Stop( void )
{
/* don't assume SCL is high on entry */
SDA_LOW(); /* ensure data is low first */
#if I2C_TM_DATA_SU>0
DelayUs( I2C_TM_DATA_SU );
#endif
SCL_HIGH(); /* float clock high */
#if I2C_TM_SCL_TMO>0
i2c_WaitForSCL(); /* wait for clock release */
#endif
#if I2C_TM_STOP_SU==1
DelayNs1000();
#elif I2C_TM_STOP_SU>1
DelayUs( I2C_TM_STOP_SU );
#endif
SDA_HIGH(); /* the low->high data transistion */
#if I2C_TM_STOP_HD>0
DelayUs( I2C_TM_STOP_HD ); /* bus free time before next start */
#endif
SDA_HIGH(); /* float data high */
#if I2C_TM_BUS_FREE>0
DelayUs( I2C_TM_BUS_FREE ); /* bus free time before next start */
#endif
return;
}
/*
* Send stop condition
* - data low-high while clock high
* add SCL_LOW so we get to a different pulse for stopping than the last of write par011001
*/
I2C_EXPORT void i2c_StopWrite( void )
{
/* don't assume SCL is high on entry */
#if I2C_TM_SCL_HIGH>0
DelayUs( I2C_TM_SCL_HIGH );
#endif
SCL_LOW();
#if I2C_TM_SCL_LOW>0
DelayUs( I2C_TM_SCL_LOW );
#endif
i2c_Stop();
return;
}
/*
* Send (re)start condition
* - ensure data is high then issue a start condition
* - see also i2c_Start() macro
*/
I2C_EXPORT void i2c_Restart( void )
{
SCL_HIGH(); /* clock pulse high - should already be */
#if I2C_TM_SCL_HIGH==1
DelayNs1000();
#elif I2C_TM_SCL_HIGH>1
DelayUs( I2C_TM_START_SU );
#endif
SDA_LOW(); /* the high->low transition */
#if I2C_TM_START_HD==1
DelayNs1000();
#elif I2C_TM_START_HD>1
DelayUs( I2C_TM_START_HD );
#endif
SCL_LOW();
return;
}
/*
* Send a byte to the slave
* - returns true on error
*/
I2C_EXPORT BYTE i2c_SendByte( BYTE byte )
{
BYTE n = 8;
while ( n-- )
{
SCL_LOW(); /* drive clock low */
/* data hold time = 0, send data now (DO NOT REMOVE BRACES!) */
if ( byte & 0x80 )
{
SDA_HIGH();
}
else
{
SDA_LOW();
}
#if I2C_TM_DATA_SU>0
DelayUs( I2C_TM_DATA_SU );
#endif
SCL_HIGH(); /* float clock high */
#if I2C_TM_SCL_TMO>0
if ( i2c_WaitForSCL() ) /* wait for clock release */
return TRUE; /* bus error */
#endif
#if I2C_TM_SCL_HIGH==1
DelayNs0400();
#elif I2C_TM_SCL_HIGH>0
DelayUs( I2C_TM_SCL_HIGH ); /* clock high time */
#endif
byte <<= 1;
}
return FALSE;
}
/*
* send an address and data direction to the slave
* - 7-bit address (lsb ignored)
* - direction (FALSE = write )
*/
I2C_EXPORT BYTE i2c_SendAddress( BYTE address, BYTE rw )
{
return i2c_SendByte( address | ( rw ? 1 : 0 ) );
}
/*
* Check for an acknowledge
* - returns ack or ~ack, or ERROR if a bus error
*/
I2C_EXPORT CHAR i2c_ReadAcknowledge( void )
{
BYTE ack;
SCL_LOW(); /* make clock is low */
DelayNs0500();
SDA_HIGH(); /* disable data line - listen for ack */
#if I2C_TM_SCL_TO_DATA>0
DelayUs( I2C_TM_SCL_TO_DATA ); /* SCL low to data out valid */
#endif
SCL_HIGH(); /* float clock high */
#if I2C_TM_DATA_SU>0
DelayUs( I2C_TM_DATA_SU );
#endif
ack = SDA; /* read the acknowledge */
/* wait for slave to release clock line after processing byte */
#if I2C_TM_SCL_TMO>0
if ( i2c_WaitForSCL() )
return I2C_ERROR;
#endif
return ack;
}
/*
* Read a byte from the slave
* - returns the byte, or I2C_ERROR if a bus error
*/
I2C_EXPORT int i2c_ReadByte( void )
{
BYTE n = 8;
BYTE byte = 0;
while ( n-- )
{
SCL_LOW(); /* drive clock low */
#if I2C_TM_SCL_LOW>0
DelayUs( I2C_TM_SCL_LOW ); /* min clock low period */
#endif
SDA_HIGH(); /* release data line */
SCL_HIGH(); /* float clock high */
#if I2C_TM_SCL_TMO>0
if ( i2c_WaitForSCL() )
return I2C_ERROR;
#endif
#if I2C_TM_SCL_HIGH>0
DelayUs( I2C_TM_SCL_HIGH );
#endif
byte <<= 1; /* read the next bit */
byte |= SDA;
}
return ( int ) byte;
}
/*
* Send an (~)acknowledge to the slave
* - status of I2C_LAST implies this is the last byte to be sent
*/
I2C_EXPORT void i2c_SendAcknowledge( BYTE status )
{
SCL_LOW();
if ( status & 0x01 )
{
SDA_LOW(); /* drive line low -> more to come */
}
else
{
SDA_HIGH();
}
#if I2C_TM_DATA_SU>0
DelayUs( I2C_TM_DATA_SU );
#endif
SCL_HIGH(); /* float clock high */
#if I2C_TM_SCL_HIGH>0
DelayUs( I2C_TM_SCL_HIGH );
#endif
return;
}
/*
* Send a byte to the slave and acknowledges the transfer
* - returns I2C_ERROR, ack or ~ack
*/
I2C_EXPORT CHAR i2c_PutByte( BYTE data )
{
if ( i2c_SendByte( data ) )
return I2C_ERROR;
return i2c_ReadAcknowledge(); /* returns ack, ~ack */
}
/*
* Get a byte from the slave and acknowledges the transfer
* - returns true on I2C_ERROR or byte
*/
I2C_EXPORT int i2c_GetByte( BYTE more )
{
int byte;
if ( ( byte = i2c_ReadByte() ) == I2C_ERROR )
return I2C_ERROR;
i2c_SendAcknowledge( more );
#if I2C_TM_PUT_FUDGE>0
DelayUs( I2C_TM_PUT_FUDGE );
#endif
return byte;
}
#ifdef I2C_STRING
/*
* Send an array of bytes to the slave and acknowledges the transfer
* - returns number of bytes not successfully transmitted
*/
I2C_EXPORT int i2c_PutString( const BYTE * str, BYTE length )
{
CHAR error;
while ( length )
{
if ( ( error = i2c_PutByte( *str++ ) ) == I2C_ERROR )
return -( int ) length; /* bus error */
else if ( error )
return ( int ) length; /* non acknowledge */
length--;
}
return FALSE; /* everything OK */
}
/*
* Reads number bytes from the slave, stores them at str and acknowledges the transfer
* - returns number of bytes not successfully read in
*/
I2C_EXPORT BYTE i2c_GetString( BYTE * str, BYTE number )
{
int byte;
while ( number )
{
if ( ( byte = i2c_GetByte( number - 1 ) ) == I2C_ERROR )
return number; /* bus error */
else
*str++ = ( BYTE ) byte;
number--;
}
return FALSE; /* everything OK */
}
#endif
/*
* Opens communication with a device at address. mode
* indicates I2C_READ or I2C_WRITE.
* - returns TRUE if address is not acknowledged
*/
I2C_EXPORT BYTE i2c_Open( BYTE address, BYTE mode )
{
i2c_Start();
i2c_SendAddress( address, mode );
if ( i2c_ReadAcknowledge() )
return TRUE;
return FALSE;
}
/*
* wait for the clock line to be released by slow slaves
* - returns TRUE if SCL was not released after the
* time out period.
* - returns FALSE if and when SCL released
*/
#if I2C_TM_SCL_TMO>0
I2C_EXPORT BYTE i2c_WaitForSCL( void )
{
/* SCL_DIR should be input here */
WORD d = I2C_TM_SCL_TMO;
while ( d-- )
{
if ( SCL )
return FALSE;
DelayNs1000();
}
return TRUE;
}
#endif
#endif

View File

@ -1,52 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* I2C BitBang Master
*----------------------------------------------------------------------------
* Not very reliable
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _I2C_BITBANG_H_
#define _I2C_BITBANG_H_
/*****************************************************************************
* includes
*****************************************************************************/
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,265 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC I2C Master
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "flash.h"
#include "inter.h"
#include "i2c_slave.h"
/*****************************************************************************
* defines
*****************************************************************************/
#ifndef _PIC18
#define DA STAT_DA
#define RW STAT_RW
#define SSPCON1 SSPCON
#endif
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// RX
static volatile BYTE *pbyRxBuf = NULL; // pointer to buffer
static volatile BYTE *pbyRxPtr = NULL; // input pointer
static LIBBANK volatile BYTE byRxCount = 0;// input counter
static LIBBANK volatile BYTE byRxSize = 0; // size of buffer
static LIBBANK volatile BYTE byLastRxByte = 0;
// TX
static volatile BYTE *pbyTxBuf = NULL; // pointer to buffer
static volatile BYTE *pbyTxPtr = NULL; // output pointer
static LIBBANK volatile BYTE byTxCount = 0;// output counter
static LIBBANK volatile BYTE byTxSize = 0; // size of buffer
static LIBBANK volatile BYTE byTxMax = 0;
// misc
volatile LIBBANK BYTE byCheckSum = 0;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
/* c functions ---------------------------------------------------------*/
BYTE I2C_bufferSlave( BYTE byAddress )
{
// I2C init here
// need to double check this, MSSP port is different than old SSP port??
// sspstat was read only? - no action needed
//'do not try to clear sspcon 4 so as to enable clock stretching?
// 'bit0 of SSPADD is R/W, with 0=a write to this device
// need to set tris registers too
// need to enable interrupts
SSPIE = 0; // disable interrupt while configuring
TRISC |= 0b00011000; // make sure RC3 and RC4 are tristated
SSPCON1 = 0b00110110; // Configure SSP as I2C Slave and enable (with 7 bit address)
SSPCON2 = 0b10000001; // Enable rx broadcast and enable rx, clock stretching
SSPSTAT = 0; // set to normal I2C specifications
SSPADD = byAddress; // set node address
SSPIF = 0; // clear interrupt flag
SSPIE = 1; // enable SSP interrupt
#ifdef _PIC18
SSPIP = 1; // high priority
#endif
bI2CRxBusy = 0;
bI2CRxDone = 0;
bI2CTxBusy = 0;
bI2CTxDone = 0;
return TRUE;
}
BYTE I2C_setRxBuffer( BYTE *pbyBuf, BYTE maxBuf )
{
BYTE byRC = 1;
if ( bI2CRxBusy )
{
byRC = 0;
}
else
{
pbyRxBuf = pbyRxPtr = pbyBuf;
byRxSize = maxBuf;
byRxCount = 0;
bI2CRxBusy = 0;
bI2CRxDone = 0;
}
return byRC;
}
BYTE I2C_getRxCount( void )
{
return byRxCount;
}
BYTE I2C_setTxBuffer( BYTE *pbyBuf, BYTE maxBuf )
{
BYTE byRC = 1;
if ( bI2CTxBusy )
{
byRC = 0;
}
else
{
pbyTxBuf = pbyTxPtr = pbyBuf;
byTxSize = byTxMax = maxBuf;
byTxCount = 0;
bI2CTxBusy = 0;
bI2CTxDone = 0;
}
return byRC;
}
BYTE I2C_getTxCount( void )
{
return byTxCount;
}
// high priority communications interrupt
void I2C_buffer_handler( void )
{
// must be SSP interrupt
if ( !SSPIF )
return;
SSPOV = 0; // clear errors
CKP = 0;
if ( DA == 0 ) //sspstat data/addr bit
{
// previous checksum
byCheckSum = 0; // zap checksum
// we've got an address (just read from SSPBUF)
if ( RW ) // sspstat r/w bit
{
// read request, start transmit buffer
pbyTxPtr = pbyTxBuf;
byTxSize = byTxMax;
byTxCount = 0;
// send first byte
if ( byTxCount++ < byTxSize )
SSPBUF = byCheckSum = *pbyTxPtr++; // send first
else
SSPBUF = 0;
// busy till all sent
if ( byTxCount < byTxSize )
{
bI2CTxBusy = 1;
bI2CTxDone = 0;
}
else
{
bI2CTxBusy = 0;
bI2CTxDone = 1;
}
// cancels receive
bI2CRxBusy = 0;
bI2CRxDone = 1;
}
else
{
byLastRxByte = SSPBUF; // fetch the address
// write request, prep receive buffer
pbyRxPtr = pbyRxBuf;
byRxCount = 0;
bI2CRxBusy = 1;
bI2CRxDone = 0;
// cancels transmit
bI2CTxBusy = 0;
bI2CTxDone = 1;
}
}
else
{
if ( RW && bI2CTxBusy )
{
// master reading what we buffered
if ( byTxCount++ < byTxSize )
{
// put data, add to checksum
byCheckSum += *pbyTxPtr;
SSPBUF = *pbyTxPtr++;
}
else
{
// put checksum
SSPBUF = 256 - byCheckSum;
byCheckSum = 0;
}
// filled?
if ( byTxCount >= byTxSize )
{
bI2CTxBusy = 0;
bI2CTxDone = 1;
}
}
else if ( bI2CRxBusy )
{
// fetch the byte (ok even if sending)
byLastRxByte = SSPBUF;
// add to checksum
byCheckSum += byLastRxByte;
// slave reading the master
if ( byRxCount++ < byRxSize )
*pbyRxPtr++ = byLastRxByte; // get data
// filled?
if ( byRxCount >= byRxSize )
bI2CRxDone = 1;
// clean up
if ( bI2CRxDone )
bI2CRxBusy = 0;
}
}
CKP = 1; // we must release clock!
SSPIF = 0; // clear SSP interrupt flag
TRISC |= 0b00011000; // make sure RC3 and RC4 are tristated
// EK not required per datasheet but the dash needed this too.
}

View File

@ -1,51 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* I2C Hardware Master
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _I2C_MASTER_H_
#define _I2C_MASTER_H_
/*****************************************************************************
* includes
*****************************************************************************/
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,268 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC I2C Slave
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "i2c.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// RX
static volatile BYTE *pbyRxBuf = NULL; // pointer to buffer
static volatile BYTE *pbyRxPtr = NULL; // input pointer
static near volatile BYTE byRxCount = 0;// input counter
static near volatile BYTE byRxSize = 0; // size of buffer
static near volatile BYTE byLastRxByte = 0;
volatile bit bRxBusy = 0; // busy receiving
volatile bit bRxDone = 0; // set when full
// TX
static volatile BYTE *pbyTxBuf = NULL; // pointer to buffer
static volatile BYTE *pbyTxPtr = NULL; // output pointer
static near volatile BYTE byTxCount = 0;// output counter
static near volatile BYTE byTxSize = 0; // size of buffer
static near volatile BYTE byTxMax = 0;
volatile bit bTxBusy = 0; // busy sending
volatile bit bTxDone = 0; // set when done
// misc
static near BYTE byTmp = 0;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
/* c functions ---------------------------------------------------------*/
BYTE I2C_initSlave( BYTE byAddress )
{
// I2C init here
SSPIE = 0; // disable interrupt while configuring
TRISC |= 0b00011000; // make sure RC3 and RC4 are tristated
SSPCON1 = 0b00110110; // Configure SSP as I2C Slave and enable (with 7 bit address)
SSPCON2 = 0b10000001; // Enable rx broadcast and enable rx, clock stretching
SSPSTAT = 0; // set to normal I2C specifications
SSPADD = byAddress; // set node address
SSPIF = 0; // clear interrupt flag
SSPIE = 1; // enable SSP interrupt
SSPIP = 1; // high priority
bRxBusy = 0;
bRxDone = 0;
bTxBusy = 0;
bTxDone = 0;
return TRUE;
}
BYTE I2C_setRxBuffer( BYTE *pbyBuf, BYTE maxBuf )
{
BYTE byRC = 1;
if ( bRxBusy )
{
byRC = 0;
}
else
{
pbyRxBuf = pbyRxPtr = pbyBuf;
byRxSize = maxBuf;
byRxCount = 0;
bRxBusy = 0;
bRxDone = 0;
}
return byRC;
}
BYTE I2C_getRxCount( void )
{
return byRxCount;
}
void I2C_clrRxDone( void )
{
bRxDone = 0;
}
BYTE I2C_setTxBuffer( BYTE *pbyBuf, BYTE maxBuf )
{
BYTE byRC = 1;
if ( bTxBusy )
{
byRC = 0;
}
else
{
pbyTxBuf = pbyTxPtr = pbyBuf;
byTxSize = byTxMax = maxBuf;
byTxCount = 0;
bTxBusy = 0;
bTxDone = 0;
}
return byRC;
}
BYTE I2C_getTxCount( void )
{
return byTxCount;
}
void I2C_clrTxDone( void )
{
bTxDone = 0;
}
// high priority communications interrupt
void I2CSlaveHandler( void )
{
// must be SSP interrupt
if ( !SSPIF )
goto default_handler;
SSPOV = 0; // clear errors
CKP = 0;
if ( DA == 0 )
{
// we've got an address (just read from SSPBUF)
if ( RW )
{
pbyTxPtr = pbyTxBuf;
byTxSize = byTxMax;
byTxCount = 0;
// send first byte
if ( byTxCount++ < byTxSize )
SSPBUF = byCheckSum = *pbyTxPtr++; // send first
else
SSPBUF = 0;
// busy till all sent
if ( byTxCount < byTxSize )
{
bTxBusy = 1;
bTxDone = 0;
}
else
{
bTxBusy = 0;
bTxDone = 1;
}
// cancels receive
bRxBusy = 0;
bRxDone = 1;
}
else
{
byLastRxByte = SSPBUF; // fetch the address
// write request, prep receive buffer
pbyRxPtr = pbyRxBuf;
byRxCount = 0;
byCmdByte = 0;
byCfgByte = 0xff;
bRxBusy = 1;
bRxDone = 0;
// cancels transmit
bTxBusy = 0;
bTxDone = 1;
}
}
else
{
if ( RW && bTxBusy )
{
// generic transmit
if ( bTxCalib )
{
pbyTxPtr = (BYTE*)&ezCalib;
byTxSize = sizeof(ezCalib)+1;
bTxCalib = 0;
}
// master reading what we buffered
if ( byTxCount++ < byTxSize )
{
// put data, add to checksum
byCheckSum += *pbyTxPtr;
SSPBUF = *pbyTxPtr++;
}
else
{
// put checksum
SSPBUF = 256 - byCheckSum;
byCheckSum = 0;
}
// filled?
if ( byTxCount >= byTxSize )
{
bTxBusy = 0;
bTxDone = 1;
}
}
else if ( bRxBusy )
{
// fetch the byte (ok even if sending)
byLastRxByte = SSPBUF;
// add to checksum
byCheckSum += byLastRxByte;
// slave reading the master
if ( byRxCount++ < byRxSize )
*pbyRxPtr++ = byLastRxByte; // get data
// filled?
if ( byRxCount >= byRxSize )
bRxDone = 1;
// clean up
if ( bRxDone )
bRxBusy = 0;
}
}
CKP = 1; // we must release clock!
SSPIF = 0; // clear SSP interrupt flag
TRISC |= 0b00011000; // make sure RC3 and RC4 are tristated
}

View File

@ -1,51 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* I2C Hardware Slave
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _I2C_SLAVE_H_
#define _I2C_SLAVE_H_
/*****************************************************************************
* includes
*****************************************************************************/
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,231 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Generic 18F Interrupt Handler
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "timers.h"
#include "period.h"
#include "portb.h"
#include "serial.h"
#include "queue.h"
#if defined(INTER_MODULE) && !defined(_PIC18)
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
LIBBANK static volatile long_dword intTemp;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void InterruptInit( void )
{
#ifdef RB0_PIN
PortB0Init();
#endif
#if defined(RB4_PIN) || defined(RB5_PIN) || defined(RB6_PIN) || defined(RB7_PIN)
PortB4567Init();
#endif
#ifdef TIMER_MODULE
TimerInit();
#endif
#ifdef PERIOD_MODULE
PeriodInit();
#endif
PEIE = 1;
ei();
}
// 16F only
#ifndef INTER_HANDLER
void interrupt interrupt_handler( void )
{
// RB0 interrupt pin
if ( INTF )
{
g_bRb0Flag = 1;
g_stCount0.w.h = g_wTimer1High; // high first so can check for change
g_stCount0.b.lh = TMR1H;
g_stCount0.b.ll = TMR1L;
if ( g_stCount0.w.h != intTimerH || g_stCount0.b.lh != TMR1H )
{
g_stCount0.w.h = g_wTimer1High;
g_stCount0.b.lh = TMR1H;
g_stCount0.b.ll = TMR1L;
}
INTF = 0;
g_wCount0++;
}
// Timer1 overflow
#ifdef TIMER1_INT
if ( TMR1IF )
{
g_wTimer1High++;
TMR1IF = 0;
}
#endif
// Timer2 interrupt
#ifdef TIMER2_INT
if ( TMR2IF )
{
g_dwTimer2++;
TMR2IF = 0;
#ifdef SW_TIMERS
if ( g_wTimers2[0] )
g_wTimers2[0]--;
#if SW_TIMERS > 1
if ( g_wTimers2[1] )
g_wTimers2[1]--;
#endif
#if SW_TIMERS > 2
if ( g_wTimers2[2] )
g_wTimers2[2]--;
#endif
#if SW_TIMERS > 3
if ( g_wTimers2[3] )
g_wTimers2[3]--;
#endif
#endif
}
#endif
// RC2/CCP1 overflow
#ifdef CCP1_PIN
if ( CCP1IF )
{
s_dwLast1 = s_stNext1.dw; // keep last reading
s_stNext1.w.h = g_wTimer1High; // high first so can check for change
s_stNext1.b.lh = CCPR1H;
s_stNext1.b.ll = CCPR1L;
if ( s_stNext1.w.h != g_wTimer1High || s_stNext1.b.lh != CCPR1H )
{
s_stNext1.w.h = g_wTimer1High;
s_stNext1.b.lh = CCPR1H;
s_stNext1.b.ll = CCPR1L;
}
// keep this and last reading
s_dwSum1 += (s_stNext1.dw - s_dwLast1);
g_wPeriod1++;
CCP1IF = 0;
}
#endif
#ifdef CCP2_PIN
// RC1/CCP2 overflow
if ( CCP2IF )
{
s_dwLast2 = s_stNext2.dw; // keep last reading
s_stNext2.w.h = g_wTimer1High; // high first so can check for change
s_stNext2.b.lh = CCPR2H;
s_stNext2.b.ll = CCPR2L;
if ( s_stNext2.w.h != g_wTimer1High || s_stNext2.b.lh != CCPR2H )
{
s_stNext2.w.h = g_wTimer1High;
s_stNext2.b.lh = CCPR2H;
s_stNext2.b.ll = CCPR2L;
}
// keep this and last reading
s_dwSum2 += (s_stNext2.dw - s_dwLast2);
g_wPeriod2++;
CCP2IF = 0;
}
#endif
// Port B 4-7 Changed
if ( !RBIF )
return;
// read bits, measure width
#ifdef RB4_PIN
if ( g_bRb4Flag != RB4 )
{
// RB4 changed
if ( RB4 )
g_wRb4Low = TMR1 - g_wRb4Last; // pulse width low
else
g_wRb4High = TMR1 - g_wRb4Last; // pulse width high
g_wRb4Last = TMR1;
g_bRb4Flag = RB4;
}
#endif
#ifdef RB5_PIN
if ( g_bRb5Flag != RB5 )
{
// RB5 changed
if ( RB5 )
g_wRb5Low = TMR1 - g_wRb5Last; // pulse width low
else
g_wRb5High = TMR1 - g_wRb5Last; // pulse width high
g_wRb5Last = TMR1;
g_bRb5Flag = RB5;
}
#endif
#ifdef RB6_PIN
if ( g_bRb6Flag != RB6 )
{
// RB6 changed
if ( RB6 )
g_wRb6Low = TMR1 - g_wRb6Last; // pulse width low
else
g_wRb6High = TMR1 - g_wRb6Last; // pulse width high
g_wRb6Last = TMR1;
g_bRb6Flag = RB6;
}
#endif
#ifdef RB7_PIN
if ( g_bRb7Flag != RB7 )
{
// RB7 changed
if ( RB7 )
g_wRb7Low = TMR1 - g_wRb7Last; // pulse width low
else
g_wRb7High = TMR1 - g_wRb7Last; // pulse width high
g_wRb7Last = TMR1;
g_bRb7Flag = RB7;
}
RBIF = 0;
#endif
}
#endif
#endif

View File

@ -1,116 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Generic 18F Interrupt Handler
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "timers.h"
#include "period.h"
#include "portb.h"
#include "project.h"
#if defined(INTER_MODULE) && defined(_PIC18)
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
bit bPowerFail = 0;
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
// initialize interrupts
void InterruptInit( void )
{
#ifdef RB0_PIN
PortB0Init();
#endif
#if defined(RB1_PIN) || defined(RB2_PIN)
PortB12Init(); // app turns them on
#endif
#if defined(RB4_PIN) || defined(RB5_PIN) || defined(RB6_PIN) || defined(RB7_PIN)
PortB4567Init();
#endif
#ifdef TIMER_MODULE
TimerInit();
#endif
#ifdef PERIOD_MODULE
PeriodInit();
#endif
GIE = PEIE = 1;
ei();
}
// callable handler
void InterruptHandler( void )
{
// default handler
if ( LVDIE && LVDIF )
{
PowerfailHandler();
bPowerFail = 1;
LVDIF = 0;
return;
}
bPowerFail = 0;
// high priority only
#ifdef RB0_PIN
PortB0handler();
#endif
// low priority default
#if defined(RB1_PIN) || defined(RB2_PIN)
PortB12Handler();
#endif
#ifdef TIMER_MODULE
TimerHandler();
#endif
#ifdef PERIOD_MODULE
PeriodHandler();
#endif
#if defined(RB4_PIN) || defined(RB5_PIN) || defined(RB6_PIN) || defined(RB7_PIN)
PortB47Handler();
#endif
}
#endif

View File

@ -1,164 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux PIC Period Emulation
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "period.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// RC2/CCP1 flag, status and counters
#ifdef CCP1_PIN
volatile long_dword Period1;
LIBBANK volatile WORD wPeriod1 = 0;
extern LIBBANK volatile WORD wTimer1High;
#endif
#ifdef CCP2_PIN
// RC1/CCP2 flag, status and counters
volatile long_dword Period2;
LIBBANK volatile WORD wPeriod2 = 0;
#endif
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// RC2/CCP1 flag, status and counters
#ifdef CCP1_PIN
static LIBBANK volatile long_dword Next1; // current reading
static LIBBANK volatile DWORD dwLast1 = 0L; // last reading
static LIBBANK volatile DWORD dwSum1 = 0L;
static BYTE byDrop1 = 0xff;
static BYTE byZero1 = 0;
#endif
#ifdef CCP2_PIN
// RC1/CCP2 flag, status and counters
static LIBBANK volatile long_dword Next2; // current reading
static LIBBANK volatile DWORD dwLast2 = 0L; // last reading
static LIBBANK volatile DWORD dwSum2 = 0L;
static BYTE byDrop2 = 0xff;
static BYTE byZero2 = 0;
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PeriodInit( void )
{
wPeriod1 = 0;
wPeriod1 = 0;
}
void PeriodHandler( void )
{
}
void PeriodZero( BYTE byZ1, BYTE byZ2 )
{
byZero1 = byZ1;
byZero2 = byZ2;
}
BYTE PeriodRead( void )
{
BYTE byFlag = 0;
PeriodHandler();
#ifdef CCP1_PIN
if ( wPeriod1 )
{
// current reading minus last reading for period
// CCP1IE = 0;
Period1.dw = dwSum1 / wPeriod1;
dwSum1 = wPeriod1 = 0;
// CCP1IE = 1;
byFlag |= 1;
byDrop1 = 0;
}
else
{
// drop zero
if ( byDrop1 < byZero1 )
{
byDrop1++; // stopping
Period1.dw = 0;
}
else if ( byDrop1 == byZero1 )
{
// stopped
byDrop1++;
byFlag |= 1;
Period1.dw = 0x7FFFFFFF;
}
}
#endif
#ifdef CCP2_PIN
if ( wPeriod2 )
{
// current reading minus last reading for period
// CCP2IE = 0;
Period2.dw = dwSum2 / wPeriod2;
dwSum2 = wPeriod2 = 0;
// CCP2IE = 1;
byFlag |= 2;
byDrop2 = 0;
}
else
{
if ( byDrop2 < byZero2 )
{
byDrop2++; // stopping
Period2.dw = 0;
}
else if ( byDrop2 == byZero2 )
{
// stopped
byDrop2++;
byFlag |= 2;
Period2.dw = 0x7FFFFFFF;
}
}
#endif
return byFlag;
}

View File

@ -1,80 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux PIC Pin0 Emulation
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "inter.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// external interrupt pin (RB0), flag and counter
volatile bit intFlag = 0;
volatile long_parts intCount;
volatile WORD intCounter = 0L;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void init_pin0( void )
{
intFlag = 0;
intCount.LN = 0L;
intCounter = 0L;
}
void int0_pin_edge( BYTE byEdge )
{
}
// high priority only
void int0_pin_handler( void )
{
// RB0 interrupt pin
// if ( INT0IF )
// {
// intFlag = 1;
// intCount.LN = int_timer();
// intCounter++;
// }
}

View File

@ -1,92 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux PIC Emulation
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "inter.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
volatile bit int1Flag = 0;
volatile WORD int1Counter = 0L;
volatile bit int2Flag = 0;
volatile WORD int2Counter = 0L;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void init_pins( BYTE byPins )
{
if ( byPins & 1 )
{
int1Flag = 0;
int1Counter = 0L;
}
if ( byPins & 2 )
{
int2Flag = 0;
int2Counter = 0L;
}
}
void int_pins_edge( BYTE byEdge )
{
}
void intx_pin_handler( void )
{
// if ( INT1IF )
// {
// int1Flag = 1;
// int1Counter++;
// }
// if ( INT2IF )
// {
// int2Flag = 1;
// int2Counter++;
// }
}

View File

@ -1,81 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux PIC RB47 Emulation
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "inter.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// not good for long pulses
volatile bit bRb4;
volatile WORD int4High = 0L;
volatile WORD int4Low = 0L;
volatile WORD int4Last = 0L;
volatile bit bRb5;
volatile WORD int5High = 0L;
volatile WORD int5Low = 0L;
volatile WORD int5Last = 0L;
// not good for long pulses
volatile bit bRb6;
volatile WORD int6High = 0L;
volatile WORD int6Low = 0L;
volatile WORD int6Last = 0L;
volatile bit bRb7;
volatile WORD int7High = 0L;
volatile WORD int7Low = 0L;
volatile WORD int7Last = 0L;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void init_rb47( void )
{
}
// 18F callable
void int_rb47_handler( void )
{
}

View File

@ -1,114 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux Timer Emulation
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include <unistd.h>
#include <time.h>
#include "system.h"
#include "timers.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// Timer #1
volatile long_dword Timer1;
// Timer #2
volatile DWORD dwTimer2;
volatile WORD wTimers2[SW_TIMERS] = { 0 };
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// Timer #2
static DWORD dwLastClock = 0;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void TimerInit( void )
{
int i;
for ( i=0 ; i<4 ; i++ )
MsecTimerSet( i, 0 );
Timer1Clear();
Timer2Clr();
}
void TimerHandler( void )
{
DWORD dwMsec;
int i;
// timer
Timer1.dw = clock() * 625L / 1000L;
// clock
dwTimer2 = clock() / 1000L;
// every msec, decrement timers
if ( dwMsec = dwTimer2 - dwLastClock )
{
for ( i=0 ; i<4 ; i++ )
{
if ( wTimers2[i] )
wTimers2[i] -= dwMsec;
}
// save last reading
dwLastClock = dwTimer2;
}
}
void Timer1Clear( void )
{
Timer1.dw = 0L;
}
DWORD Timer1Read( void )
{
TimerHandler();
return Timer1.dw;
}

View File

@ -1,403 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux Memory Emulation Driver
*----------------------------------------------------------------------------
* Uses file for non-volatile storage.
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _MEMIO_C_
#define _MEMIO_C_
/*****************************************************************************
* includes
*****************************************************************************/
#ifdef MEMORY_EMUL
#include <stdio.h>
#include <memory.h>
#include <unistd.h>
#endif
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
#ifdef MEMORY_EMUL
static FILE *pDev = NULL; // block device or file
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef MEMORY_EMUL
static int EmulOpenFile( char *pszFile )
{
BYTE byData[1024];
int i, n;
if ( pDev )
return 1;
// check file existence
if ( access( pszFile, F_OK ) != 0 )
{
// create file if missing
if ( pDev = fopen( pszFile, "wb" ) )
{
// zap
memset( byData, 0, sizeof(byData) );
n = MemGetSize();
while ( n )
{
if ( n < sizeof(byData) )
i = n;
else
i = sizeof(byData);
fwrite( byData, 1, i, pDev );
n -= i;
}
fclose( pDev );
}
else
return 0;
}
// open file for reading/writing
if ( pDev = fopen( pszFile, "r+b" ) )
{
fseek( pDev, 0, SEEK_SET );
return 1;
}
return 0;
}
// close
static void EmulCloseFile( void )
{
if ( pDev )
fclose( pDev );
}
// init
static void DevInit( void )
{
EmulOpenFile( MEMORY_FILE );
MemSetSize( MEMORY_SIZE );
MemSetProtect(0);
}
// map byte i/o
static BYTE DevReadByte( ATYPE xAddr )
{
if ( pDev )
{
return fgetc( pDev );
}
return 0;
}
static void DevWriteByte( ATYPE xAddr, BYTE byData )
{
if ( pDev )
{
fputc( byData, pDev );
}
}
// hardware i/o
static STYPE DevStartRead( ATYPE xAddr, STYPE nBytes )
{
int n;
// create file
if ( pDev )
{
if ( fseek( pDev, xAddr, SEEK_SET ) == 0 )
return nBytes;
}
return 0;
}
static void DevStopRead( void )
{
if ( pDev )
fflush( pDev );
}
static STYPE DevStartWrite( ATYPE xAddr, STYPE nBytes )
{
// create file
if ( pDev )
{
if ( fseek( pDev, xAddr, SEEK_SET ) == 0 )
return nBytes;
}
return 0;
}
static void DevStopWrite( void )
{
if ( pDev )
fflush( pDev );
}
#endif
#define MT_Init(NAME) \
void NAME ## Init( void ) \
{ \
DevInit(); \
}
#define MT_GetChecksum(NAME) \
BYTE NAME ## GetChecksum( void ) \
{ \
return MemGetChecksum(); \
}
#define MT_GetError(NAME) \
BYTE NAME ## GetError( void ) \
{ \
return MemGetError(); \
}
#define MT_GetSize(NAME) \
ATYPE NAME ## GetSize( void ) \
{ \
return MemGetSize(); \
}
#define MT_ReadBlock(NAME) \
STYPE NAME ## ReadBlock( ATYPE wAddr, STYPE nBytes ) \
{ \
MemStopBlock(); \
\
if ( MemStartRead( wAddr, nBytes ) ) \
{ \
MemStartBlock( wAddr, nBytes ); \
MemClrChecksum(); \
return nBytes; \
} \
MemStartBlock( 0, 0 ); \
MemSetError( MEM_ERR_BOUNDARY ); \
return 0; \
}
#define MT_WriteBlock(NAME) \
STYPE NAME ## WriteBlock( ATYPE wAddr, STYPE nBytes ) \
{ \
MemStopBlock(); \
\
if ( MemStartWrite( wAddr, nBytes ) ) \
{ \
MemStartBlock( wAddr, nBytes ); \
MemClrChecksum(); \
return nBytes; \
} \
MemStartBlock( 0, 0 ); \
MemSetError( MEM_ERR_BOUNDARY ); \
return 0; \
}
#define MT_SkipNext(NAME) \
void NAME ## SkipNext( STYPE nBytes ) \
{ \
if ( MemBytesCheck( nBytes ) ) \
{ \
MemBlockBytes( nBytes ); \
} \
else \
MemSetError( MEM_ERR_OVERFLOW ); \
}
//
// The byte i/o work is done here
//
#define MT_ReadNext(NAME) \
BYTE NAME ## ReadNext( void ) \
{ \
BYTE byData; \
\
if ( MemDecrLen() ) \
{ \
byData = DevReadByte( MemGetAddr() ); \
MemIncrAddr(); \
MemAddChecksum( byData ); \
if ( !MemGetLen() ) \
MemStopRead(); \
return byData; \
} \
MemSetError( MEM_ERR_OVERFLOW ); \
return 0; \
}
#define MT_ReadBytes(NAME) \
STYPE NAME ## ReadBytes( BYTE *pbyData, STYPE nBytes ) \
{ \
STYPE nRead = 0; \
BYTE byData; \
\
if ( !MemBytesCheck( nBytes ) ) \
{ \
nBytes = MemGetLen(); \
MemSetError( MEM_ERR_OVERFLOW ); \
} \
nRead = nBytes; \
\
while ( nBytes-- ) \
{ \
byData = NAME ## ReadNext(); \
if ( pbyData ) \
*pbyData++ = byData; \
} \
\
return nRead; \
}
#define MT_WriteNext(NAME) \
void NAME ## WriteNext( BYTE byData ) \
{ \
if ( MemDecrLen() ) \
{ \
DevWriteByte( MemGetAddr(), byData ); \
MemIncrAddr();\
MemAddChecksum( byData ); \
if ( MemDoChecksum() && MemGetLen() == 1 ) \
{ \
MemDecrLen(); \
DevWriteByte( MemGetAddr(), 256 - MemGetChecksum() ); \
MemIncrAddr(); \
} \
if ( !MemGetLen() ) \
MemStopWrite(); \
return; \
} \
\
MemSetError( MEM_ERR_OVERFLOW ); \
}
#define MT_WriteBytes(NAME) \
STYPE NAME ## WriteBytes( const BYTE *pbyData, STYPE nBytes ) \
{ \
STYPE nWrite = 0; \
\
if ( !MemBytesCheck( nBytes ) ) \
{ \
nBytes = MemGetLen(); \
MemSetError( MEM_ERR_OVERFLOW ); \
} \
nWrite = nBytes; \
\
if ( pbyData ) \
{ \
while ( nBytes-- ) \
NAME ## WriteNext( *pbyData++ ); \
} \
else if ( MemDoChecksum() ) \
{ \
while ( --nBytes ) \
NAME ## ReadNext(); \
NAME ## WriteNext( 0 ); \
} \
\
return nWrite; \
}
//
// The data i/o work is done here
//
#define MT_ReadData(NAME) \
STYPE NAME ## ReadData( ATYPE wAddr, BYTE *pbyData, STYPE nBytes ) \
{ \
if ( NAME ## ReadBlock( wAddr, nBytes ) ) \
return NAME ## ReadBytes( pbyData, nBytes ); \
return 0; \
}
#define MT_WriteData(NAME) \
STYPE NAME ## WriteData( ATYPE wAddr, const BYTE *pbyData, STYPE nBytes ) \
{ \
if ( NAME ## WriteBlock( wAddr, nBytes ) ) \
{ \
MemDisChecksum(); \
return NAME ## WriteBytes( pbyData, nBytes ); \
} \
return 0; \
}
#define MT_ReadCSData(NAME) \
STYPE NAME ## ReadCSData( ATYPE wAddr, BYTE *pbyData, STYPE nBytes ) \
{ \
if ( NAME ## ReadData( wAddr, pbyData, nBytes ) ) \
{ \
if ( MemGetChecksum() == 0 ) \
return nBytes; \
return (STYPE)0xFFFFFFFF; \
} \
return 0; \
}
#define MT_WriteCSData(NAME) \
STYPE NAME ## WriteCSData( ATYPE wAddr, const BYTE *pbyData, STYPE nBytes ) \
{ \
if ( NAME ## WriteBlock( wAddr, nBytes ) ) \
{ \
MemEnaChecksum(); \
return NAME ## WriteBytes( pbyData, nBytes ); \
} \
return 0; \
}
#define MT_WriteFill(NAME) \
STYPE NAME ## WriteFill( ATYPE wAddr, BYTE byFill, STYPE nBytes ) \
{ \
int nWrite = nBytes; \
\
if ( NAME ## WriteBlock( wAddr, nBytes ) ) \
{ \
while ( MemDecrLen() ) \
{ \
DevWriteByte( MemGetAddr(), byFill ); \
MemIncrAddr(); \
} \
return nWrite; \
} \
return 0; \
}
#endif

View File

@ -1,179 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Internal Memory Interface Template
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _MEMORY_H_
#define _MEMORY_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#ifdef MEMORY_DEBUG
#define MEMORY_ERROR
#endif
// flags
#define MEM_DO_CHECKSUM 1
// error bits
#define MEM_ERR_BOUNDARY 1 // out of bounds block
#define MEM_ERR_UNDERFLOW 2 // didn't finish last block
#define MEM_ERR_OVERFLOW 4 // overflowed last block
#define MEM_ERR_CHECKSUM 8 // bad checksum
#define MEM_ERR_WRITE 16 // write failed
#define MEM_ERR_MEDIA 32 // removable media error
// default address and size types
#ifndef ATYPE
#define ATYPE WORD
#endif
#ifndef STYPE
#define STYPE WORD
#endif
/*****************************************************************************
* macros
*****************************************************************************/
#ifdef MEMORY_SIZE
#define MemSetSize(S)
#define MemGetSize() MEMORY_SIZE
#else
#define MemSetSize(S) MemCtrl.xMemSize=(S)
#define MemGetSize() MemCtrl.xMemSize
#endif
#ifdef READ_PROTECT
#define MemReadCheck(A,S) ((A)+(S)<=MemGetSize())
#define MemStartRead(A,S) (MemReadCheck(A,S) && DevStartRead(A,S))
#else
#define MemStartRead(A,S) DevStartRead(A,S)
#endif
#ifdef WRITE_PROTECT
#define MemSetProtect(A) MemCtrl.xMemProt=(A)
#define MemWriteCheck(A,S) ((A)>=MemCtrl.xMemProt)
#define MemStartWrite(A,S) (MemWriteCheck(A,S) && MemReadCheck(A,S) && DevStartWrite(A,S))
#else
#ifdef READ_PROTECT
#define MemStartWrite(A,S) (MemReadCheck(A,S) && DevStartWrite(A,S))
#else
#define MemStartWrite(A,S) DevStartWrite(A,S)
#endif
#endif
#ifndef MemSetProtect
#define MemSetProtect(A)
#endif
#define MemBytesCheck(N) ((N)<=MemCtrl.xBlockLen)
#define MemStartBlock(A,S) {MemCtrl.xBlockAddr=(A);MemCtrl.xBlockLen=(S);}
#ifdef MEMORY_ERROR
#define MemStopBlock() if(MemCtrl.xBlockLen)MemSetError(MEM_ERR_UNDERFLOW)
#define MemStopRead() {DevStopRead();MemStopBlock();}
#define MemStopWrite() {DevStopWrite();MemStopBlock();}
#else
#define MemStopBlock()
#define MemStopRead() DevStopRead()
#define MemStopWrite() DevStopWrite()
#endif
#define MemGetAddr() MemCtrl.xBlockAddr
#define MemGetLen() MemCtrl.xBlockLen
#define MemIncrAddr() MemCtrl.xBlockAddr++
#define MemDecrLen() MemCtrl.xBlockLen--
#define MemSetLen
#define MemBlockNext() {MemCtrl.xBlockAddr++;MemCtrl.xBlockLen--;}
#define MemBlockBytes(B) {MemCtrl.xBlockAddr+=(B);MemCtrl.xBlockLen-=(B);}
#define MemEnaChecksum() MemCtrl.byMemFlag|=MEM_DO_CHECKSUM
#define MemDisChecksum() MemCtrl.byMemFlag&=~MEM_DO_CHECKSUM
#define MemDoChecksum() (MemCtrl.byMemFlag & MEM_DO_CHECKSUM)
#define MemClrChecksum() MemCtrl.byCheckSum=0
#define MemAddChecksum(B) MemCtrl.byCheckSum+=(B)
#define MemGetChecksum() MemCtrl.byCheckSum
#ifdef MEMORY_ERROR
#define MemClrError() MemCtrl.byErrorFlag=0
#define MemSetError(E) MemCtrl.byErrorFlag|=(E)
#define MemGetError() MemCtrl.byErrorFlag
#else
#define MemClrError()
#define MemSetError(E)
#define MemGetError() 0
#endif
#ifdef WRITE_COUNTING
#define MemIncrCount() MemCtrl.dwWriteCount++
#define MemClearCount() MemCtrl.dwWriteCount=0
#define MemGetCount() MemCtrl.dwWriteCount
#define MemSetCount(C) MemCtrl.dwWriteCount=(C)
#else
#define MemIncrCount()
#define MemClearCount()
#define MemGetCount() 0
#define MemSetCount(C)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _MindCtrl {
ATYPE xBlockAddr; // start of current block
STYPE xBlockLen; // remaining length of current block
BYTE byMemFlag;
BYTE byCheckSum; // checksum of current block
#if defined(READ_PROTECT) && !defined(MEMORY_SIZE)
ATYPE xMemSize; // end read/write region (size)
#endif
#ifdef WRITE_PROTECT
ATYPE xMemProt; // begin write region
#endif
#ifdef MEMORY_ERROR
BYTE byErrorFlag; // last error
#endif
#ifdef WRITE_COUNTING
DWORD dwWriteCount; // write counts
#endif
} MindCtrl;
/*****************************************************************************
* global constants
*****************************************************************************/
// memory block control structure
static near MindCtrl MemCtrl = { 0 };
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,293 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Packet Interface
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _PACKET_H_
#define _PACKET_H_
/*****************************************************************************
* includes
*****************************************************************************/
#if defined (__linux__)
// Linux, for testing
#include <stdio.h>
#include <sys/types.h>
#ifndef BYTE
#define BYTE u_char
#define WORD u_short
#define UINT u_int
#define DWORD u_long
#endif
#define PKTBANK
#define DelayUs(X) usleep(X)
#define DelayMs(X) usleep((X)*1000)
#elif defined(_WINDOWS)
#define PKTBANK
#define DelayUs(X) _sleep((X)/1000)
#define DelayMs(X) _sleep(X)
#define usleep(X) _sleep((X)/1000)
#else
// PIC
#define PIC_PACKET
#include "system.h"
#include "types.h"
#include "serial.h"
#endif
/*****************************************************************************
* defines
*****************************************************************************/
//
// Packet Synchonization Header
//
#ifndef PACKET_SYNC_LENGTH
#define PACKET_SYNC_LENGTH 3 // minimum of 2, includes padding and sync char
#endif
#ifndef PACKET_SYNC_PAD
#define PACKET_SYNC_PAD 0xFF
#endif
#ifndef PACKET_SYNC_CHAR
#define PACKET_SYNC_CHAR 0x00
#endif
#ifndef PACKET_RECV_SYNC
#define PACKET_RECV_SYNC PACKET_SYNC_PAD
#endif
#ifndef PACKET_XMIT_SYNC
#define PACKET_XMIT_SYNC PACKET_SYNC_PAD
#endif
//
// Packet Identification (required with radio)
//
#if (defined(RADIO_BIDI) || defined(RADIO_UNI)) && !defined(PACKET_IDENT)
#define PACKET_IDENT // required for radio, packet ids
#undef PACKET_ID_SIZE
#undef PACKET_CK_SIZE
#define PACKET_ID_SIZE 2 // ID
#define PACKET_CK_SIZE 1 // CRC default?
#endif
//
// Packet Identification Size (defaults)
//
#ifndef PACKET_ID_SIZE
#define PACKET_ID_SIZE 2 // default
#endif
//
// Packet Flag
//
#define PACKET_FLAG_USER1 0x01
#define PACKET_FLAG_USER2 0x02
#define PACKET_FLAG_USER3 0x04
#define PACKET_FLAG_USER4 0x08
#define PACKET_FLAG_CRC 0x10
#define PACKET_FLAG_STREAM 0x80
//
// Packet Streaming Control
//
#ifdef PACKET_STREAM
#define PACKET_FL_SIZE 1
#ifdef PACKET_LARGE
#define PACKET_MAX_STREAM 0x8000
#else
#define PACKET_MAX_STREAM 0x80
#endif
#else
#define PACKET_FL_SIZE 0
#define PACKET_FLAG_STREAM 0x80
#define PACKET_MAX_STREAM 0x80
#endif
//
// Packet Buffer Size
//
#ifdef PACKET_LARGE
#define PACKET_BC_SIZE 2 // 32767 byte packets max (too big for normal apps)
#define PACKET_MAX_PACKET 0xffff
#else
#define PACKET_BC_SIZE 1 // 255 byte packets max
#define PACKET_MAX_PACKET 0xff
#endif
//
// Checksum/CRC Size
//
#ifndef PACKET_CK_SIZE
#define PACKET_CK_SIZE 1 // 1 = 8 bit checksum, 2 = 16 bit CRC
#endif
//
// serial errors included
//
#define PACKET_ERR_DEVICE -1
#define PACKET_ERR_TIMEOUT -2
#define PACKET_BAD_PACKET -3
#define PACKET_BAD_CHECKSUM -4
#define PACKET_BUF_TOOBIG -5
#define PACKET_BUF_OVERWRITE -6
#define PACKET_ERR_SEQUENCE -7
#define PACKET_ERR_STREAM -8
#define PACKET_ERR_NOISE -9
#define PACKET_ERR_ALIEN -10
//
// Character timeouts
//
#define TIMEOUT 50
//
// Serial Data Rate
//
#ifndef BAUD
#if defined(RADIO_BIDI)
#define BAUD 19200L
#elif defined(RADIO_UNI)
#define BAUD 38400L
#else
#define BAUD 57600L
#endif
#endif
#define PACKET_CHAR_TIME ((1000000L*10L)/BAUD) // usec time, 1 start, 8 bits, 1 stop
//
// Radio Packet Handling
//
#if defined(RADIO_UNI) && defined(RADIO_BIDI)
#error You cannot choose both unidirectional and bidirectional radio packet handling
#endif
#if defined(RADIO_UNI) || defined(RADIO_BIDI)
#define RADIO
#endif
// worst case (PC RX->TX, PIC TX->RX) wait timeout
#define PACKET_WAIT_TIME 5000L // time to wait for packet
// worst case (PC TX->RX, PIC RX->TX)
#define PACKET_SWITCH_TIME 8000L
#define RADIO_NOCHAR_TIME 5000L // PC xmit timeout (worst case)
#define PACKET_NOCHAR_TIME RADIO_NOCHAR_TIME
// padding needed to allow resync between consecutive packets
#define PACKET_RESYNC_LENGTH (PACKET_SYNC_LENGTH+1)
// padding needed which switching direction, plus sync chars
#define PACKET_HEADER_LENGTH ((PACKET_SWITCH_TIME/PACKET_CHAR_TIME)+PACKET_RESYNC_LENGTH+1)
#define PACKET_TRAILER_LENGTH 1 // sacrificed to TX->RX switch
// radio direction control
#define RADIO_DISABLE 0xff
#define RADIO_OFF 0 // no radio
#define RADIO_LISTEN 1
#define RADIO_TALK 2
#define RADIO_DIRECT 3 // direct connect override / no radio
//
// Packet Lengths (sync+id+flag+bc+checksum)
//
#define PACKET_LENGTH (PACKET_SYNC_LENGTH+PACKET_ID_SIZE+PACKET_FL_SIZE+PACKET_BC_SIZE+PACKET_CK_SIZE)
/*****************************************************************************
* macros
*****************************************************************************/
#ifdef SERIAL_RECV_BUFFER
// really can't do without it
#define PACKET_FILTER
#ifdef PACKET_IDENT
#define recvFilter(I) g_wPacketId=(I)
#else
#define recvFilter(I) g_wPacketId=0
#endif
#define recvAvail() g_byPacketAvail
#endif
#ifdef RADIO_BIDI
#define baudRadio(B) serial_baud(B)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
#ifdef PACKET_FILTER
extern PKTBANK WORD g_wPacketId;
extern PKTBANK BYTE g_byPacketAvail;
#endif
extern PKTBANK bit g_bPacketCRC;
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
// Radio Control
extern BYTE getRadio( void );
extern BYTE dirRadio( BYTE bXmit );
extern void noRadio( void );
// Misc Utility
extern BYTE doCheckSum( const BYTE *pbyData, BYTE nBytes );
// Port Control
extern void PacketInit( void );
extern void PacketHandler( void );
#ifndef PIC_PACKET
extern int openPort( int iCom, int iBaud );
extern int closePort( void );
#endif
// Receive Functions
extern int recvWait( UINT iWait );
extern int recvHeader( WORD *pwCheck, WORD *pwId, BYTE *pbyFlag );
extern int recvByte( WORD *pwCheck );
extern int recvData( WORD *pwCheck, PKTBANK BYTE *pbyData, WORD nBytes, WORD maxBytes );
extern int recvTrailer( WORD *pwCheck );
extern void recvClear( BYTE nBytes );
extern void recvFlush( void );
// Send Functions
extern void sendSynch( BYTE nBytes );
extern void sendPadding( BYTE nBytes );
extern void sendSpacing( BYTE nBytes );
extern void sendHeader( WORD *pwCheckSum, WORD wId, BYTE byFlag, WORD nBytes );
extern void sendByte( WORD *pwCheckSum, BYTE byByte );
extern void sendData( WORD *pwCheckSum, const BYTE *pbyData, WORD nBytes );
extern void sendTrailer( WORD *pwCheckSum );
extern void sendFlush( void );
// All in One
extern int recvPacket( WORD *pwId, PKTBANK BYTE *pbyData, BYTE *pbyFlag, WORD maxBytes ); // all in one
extern int sendPacket( WORD wId, const BYTE *pbyData, WORD nBytes ); // all in one
// Streaming Functions
extern int recvFinish( WORD nBytes );
extern int recvSequence( WORD *pwId, WORD *pwCheck, BYTE *pbySeq );
extern int recvStream( WORD wId, PKTBANK BYTE *pbyData, WORD nBytes );
extern int readStream( WORD wMyBoxId, void(*put)(BYTE c), WORD wBytes );
extern int sendStream( WORD wId, const BYTE *pbyData, WORD nBytes );
extern int writeStream( WORD wMyBoxId, BYTE(*get)(void), WORD wBytes );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,237 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Period Counters
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "period.h"
#include "timers.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// RC2/CCP1 flag, status and counters
#ifdef CCP1_PIN
volatile long_dword g_stPeriod1 = 0L;
LIBBANK volatile WORD g_wPeriod1 = 0;
extern LIBBANK volatile WORD g_wTimer1High;
#endif
#ifdef CCP2_PIN
// RC1/CCP2 flag, status and counters
volatile long_dword g_stPeriod2 = 0L;
LIBBANK volatile WORD g_wPeriod2 = 0;
#endif
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// RC2/CCP1 flag, status and counters
#ifdef CCP1_PIN
static LIBBANK volatile long_dword s_stNext1 = 0L; // current reading
static LIBBANK volatile DWORD s_dwLast1 = 0L; // last reading
static LIBBANK volatile DWORD s_dwSum1 = 0L;
static BYTE s_byDrop1 = 0xff;
static BYTE s_byZero1 = 0;
#endif
#ifdef CCP2_PIN
// RC1/CCP2 flag, status and counters
static LIBBANK volatile long_dword s_stNext2 = 0L; // current reading
static LIBBANK volatile DWORD s_dwLast2 = 0L; // last reading
static LIBBANK volatile DWORD s_dwSum2 = 0L;
static BYTE s_byDrop2 = 0xff;
static BYTE s_byZero2 = 0;
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PeriodInit( void )
{
#ifdef CCP1_PIN
RC2 = 0;
TRISC2 = 1;
CCP1IE = 1;
#ifdef _PIC18
CCP1IP = 0;
CCP1CON |= 0x80; // RD16
#endif
CCP1CON = 0b00000101; // default every rising edge
g_wPeriod1 = 0;
#endif
#ifdef CCP2_PIN
RC1 = 0;
TRISC1 = 1;
CCP2IE = 1;
#ifdef _PIC18
CCP2IP = 0;
CCP2CON |= 0x80; // 16 bit read/write
#endif
CCP2CON = 0b00000101; // default every rising edge
g_wPeriod2 = 0;
#endif
#ifdef _PIC18
// CCP1, CCP2 source
T3CCP1 = 0;
#if defined(_18F442) || defined(_18F452)
T3CCP2 = 0;
#endif
#endif
}
#ifdef _PIC18
void PeriodHandler( void )
{
// RC2/CCP1 overflow
#ifdef CCP1_PIN
if ( CCP1IF )
{
s_dwLast1 = s_stNext1.dw; // keep last reading
s_stNext1.w.h = g_wTimer1High; // high first so can check for change
s_stNext1.w.l = CCPR1;
if ( s_stNext1.w.h != g_wTimer1High || s_stNext1.b.lh != CCPR1H )
{
s_stNext1.w.h = g_wTimer1High;
s_stNext1.w.l = CCPR1;
}
// keep this and last reading
s_dwSum1 += (s_stNext1.dw - s_dwLast1);
g_wPeriod1++;
CCP1IF = 0;
}
#endif
#ifdef CCP2_PIN
// RC1/CCP2 overflow
if ( CCP2IF )
{
s_dwLast2 = s_stNext2.dw; // keep last reading
s_stNext2.w.h = g_wTimer1High; // high first so can check for change
s_stNext2.w.l = CCPR2;
if ( s_stNext2.w.h != g_wTimer1High || s_stNext2.b.lh != CCPR2H )
{
s_stNext2.w.h = g_wTimer1High;
s_stNext2.w.l = CCPR2;
}
// keep this and last reading
s_dwSum2 += (s_stNext2.dw - s_dwLast2);
g_wPeriod2++;
CCP2IF = 0;
}
#endif
}
#endif
void PeriodZero( BYTE byZero1, BYTE byZero2 )
{
#ifdef CCP1_PIN
s_byZero1 = byZero1;
#endif
#ifdef CCP2_PIN
s_byZero2 = byZero2;
#endif
}
BYTE PeriodRead( void )
{
BYTE byFlag = 0;
#ifdef CCP1_PIN
if ( g_wPeriod1 )
{
// current reading minus last reading for period
CCP1IE = 0;
g_stPeriod1.dw = s_dwSum1 / g_wPeriod1;
s_dwSum1 = g_wPeriod1 = 0;
CCP1IE = 1;
byFlag |= 1;
s_byDrop1 = 0;
}
else
{
// no reading available
if ( s_byDrop1 < s_byZero1 )
{
// drop zero
s_byDrop1++; // stopping
g_stPeriod1.dw = 0;
}
else if ( s_byDrop1 == s_byZero1 )
{
// stopped
s_byDrop1++;
byFlag |= 1;
g_stPeriod1.dw = 0x7FFFFFFF;
}
}
#endif
#ifdef CCP2_PIN
if ( g_wPeriod2 )
{
// current reading minus last reading for period
CCP2IE = 0;
g_stPeriod2.dw = s_dwSum2 / g_wPeriod2;
s_dwSum2 = g_wPeriod2 = 0;
CCP2IE = 1;
byFlag |= 2;
s_byDrop2 = 0;
}
else
{
// no reading available
if ( s_byDrop2 < s_byZero2 )
{
// drop zero
s_byDrop2++; // stopping
g_stPeriod2.dw = 0;
}
else if ( s_byDrop2 == s_byZero2 )
{
// stopped
s_byDrop2++;
byFlag |= 2;
g_stPeriod2.dw = 0x7FFFFFFF;
}
}
#endif
return byFlag;
}

View File

@ -1,83 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Period Counters
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _PERIOD_H_
#define _PERIOD_H_
/*****************************************************************************
* includes
*****************************************************************************/
// this is application specific
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
// CCP1/CCP2
#ifdef CCP1_PIN
#define Period1Cnt() g_wPeriod1
#define Period1Clr() g_wPeriod1=0
#define Period1Clear() g_stPeriod1.dw=0
#define Period1Read() g_stPeriod1.dw
#endif
#ifdef CCP2_PIN
#define Period2Cnt() g_wPeriod2
#define Period2Clr() g_wPeriod2=0
#define Period2Clear() g_stPeriod2.dw=0
#define Period2Read() g_stPeriod2.dw
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
#ifdef CCP1_PIN
LIBBANK extern volatile WORD g_wPeriod1;
extern volatile long_dword g_stPeriod1;
#endif
#ifdef CCP2_PIN
LIBBANK extern volatile WORD g_wPeriod2;
extern volatile long_dword g_stPeriod2;
#endif
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
// counters
extern void PeriodInit( void );
extern void PeriodHandler( void );
extern void PeriodClear( void );
extern BYTE PeriodRead( void );
extern void PeriodZero( BYTE byZero1, BYTE byZero2 );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,226 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Packet Serial Interrupt Handling
* Description
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
/*****************************************************************************
* defines
*****************************************************************************/
#include "system.h"
#include "serial.h"
#include "packet.h"
#include "queue.h"
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// queues used
extern SERBANK Queue g_qSerialRx;
extern SERBANK Queue g_qSerialTx;
// global packet control
PKTBANK WORD g_wPacketId = 0;
PKTBANK BYTE g_byPacketAvail = 0; // used by interrupt handler
PKTBANK bit g_bPacketCRC = 0;
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
// interrupt driven serial i/o
static LIBBANK volatile WORD s_wPcktId = 0;
static LIBBANK volatile BYTE s_byPcktCnt = 0;
static LIBBANK volatile BYTE s_byByteCnt = 0;
static LIBBANK volatile BYTE s_byCheckSum = 0;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PacketInit( void )
{
#if PACKET_CK_SIZE
g_bPacketCRC = 1;
#endif
}
void PacketHandler( void )
{
// temps
static LIBBANK BYTE byRx;
static LIBBANK BYTE byTx;
// RC6/TX
if ( TXIF )
{
// ready to xmit
byTx = _QueueCount( g_qSerialTx );
if ( byTx )
{
// output from queue
_QueueGet( g_qSerialTx, TXREG );
}
if ( byTx <= 1 )
{
// nothing left, disable
TXIE = 0;
}
}
// RC7/RX
if ( !RCIF )
return;
// check queue, lose a byte if necessary
while ( _QueueFull( g_qSerialRx ) )
_QueueGet( g_qSerialRx, byRx );
// read char
byRx = RCREG;
// depacketizer
if ( s_byByteCnt )
{
// data byte, last is checksum
if ( s_byByteCnt-- )
{
if ( s_byPcktCnt )
{
s_byPcktCnt++;
_QueuePut( g_qSerialRx, byRx );
s_byCheckSum += byRx;
}
}
// done with packet?
if ( s_byByteCnt == 0 )
{
if ( g_bPacketCRC == 1 )
{
g_byPacketAvail++; // defer CRC check
}
else if ( g_bPacketCRC == 0 && s_byCheckSum == 0 )
{
// signal good packet is available
g_byPacketAvail++;
}
else if ( s_byPcktCnt == _QueueSize( g_qSerialRx ) )
{
// eat bad packet
_QueueClear( g_qSerialRx );
}
s_byPcktCnt = 0;
}
}
else if ( s_byPcktCnt < 3 )
{
// look for sync chars
if ( byRx == PACKET_RECV_SYNC )
{
if ( s_byPcktCnt < PACKET_SYNC_LENGTH-1 )
s_byPcktCnt++;
}
else if ( byRx == PACKET_SYNC_CHAR )
{
if ( s_byPcktCnt == PACKET_SYNC_LENGTH-1 )
s_byPcktCnt++;
else
s_byPcktCnt = 0;
}
else
s_byPcktCnt = 0;
}
else
{
// reading packet
s_byPcktCnt++;
// got byte count?
#if PACKET_ID_SIZE >= 1
if ( s_byPcktCnt == 4 )
s_wPcktId = byRx;
else
#if PACKET_ID_SIZE == 2
if ( s_byPcktCnt == 5 )
s_wPcktId |= byRx << 8;
else
#endif
#endif
if ( s_byPcktCnt == PACKET_LENGTH-1 )
{
// bytes to slurp
s_byByteCnt = byRx + g_bPacketCRC ? 2 : 1; // got byte count + checksum
s_byCheckSum = 0;
// my packet?
#ifdef PACKET_IDENT
if ( g_wPacketId == 0 || g_wPacketId == s_wPcktId )
{
#endif
// dump header into queue
_QueuePut(g_qSerialRx, PACKET_RECV_SYNC);
_QueuePut(g_qSerialRx, PACKET_RECV_SYNC);
_QueuePut(g_qSerialRx, PACKET_SYNC_CHAR);
#if PACKET_ID_SIZE >= 1
_QueuePut( g_qSerialRx, s_wPcktId );
#endif
#if PACKET_ID_SIZE == 2
_QueuePut( g_qSerialRx, s_wPcktId >> 8 );
#endif
#if PACKET_FL_SIZE >= 1
_QueuePut( g_qSerialRx, s_byCheckSum );
#endif
_QueuePut( g_qSerialRx, byRx ); // bc
#ifdef PACKET_IDENT
}
else
s_byPcktCnt = 0; // ignore packet data
#endif
}
#if PACKET_FL_SIZE >= 1
else
{
s_byCheckSum = byRx; // tmp for flag byte
}
#endif
}
// doesn't handle overflow, so app had better have big buffer
if ( OERR )
{
// overrun error (lost data)
CREN = 0;
CREN = 1;
}
}

View File

@ -1,144 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Packet Radio Control
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "types.h"
#include "serial.h"
#include "packet.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
static BYTE s_byDir = RADIO_OFF; // radio status
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
BYTE getRadio( void )
{
return s_byDir;
}
BYTE dirRadio( BYTE byFlag )
{
#if defined(RXEN_RADIO) || defined(TXEN_RADIO)
// radio logic disabled
if ( s_byDir == RADIO_DISABLE )
return 0;
// direct connect?
#ifdef OVER_RADIO
if ( !OVER_RADIO )
byFlag = RADIO_DIRECT; // includes debug
#endif
// change direction only if necessary
if ( s_byDir == byFlag )
return 0;
// flush buffer
sendFlush();
// shut off radio
if ( byFlag == RADIO_OFF )
{
// shut it all off
serial_baud( 38400 );
#ifdef RXEN_RADIO
RXEN_RADIO = 0;
#endif
#ifdef TXEN_RADIO
TXEN_RADIO = 0;
#endif
}
else if ( byFlag == RADIO_LISTEN )
{
// flush, wait and switch
serial_baud( BAUD );
#ifdef TXEN_RADIO
TXEN_RADIO = 0;
#endif
#ifdef RXEN_RADIO
RXEN_RADIO = 1;
#endif
}
else if ( byFlag == RADIO_TALK )
{
// let's talk
serial_baud( BAUD );
#ifdef RXEN_RADIO
RXEN_RADIO = 0;
#endif
// switch
#ifdef TXEN_RADIO
TXEN_RADIO = 1;
#endif
}
else if ( byFlag == RADIO_DIRECT )
{
// bump speed
serial_baud( 115200 );
#ifdef RXEN_RADIO
RXEN_RADIO = 0;
#endif
#ifdef TXEN_RADIO
TXEN_RADIO = 0;
#endif
}
// ready to listen
recvFlush();
// remember radio state
s_byDir = byFlag;
return 1;
#else
return 0;
#endif
}
void noRadio( void )
{
s_byDir = RADIO_DISABLE;
}

View File

@ -1,297 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Packet Receive
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "types.h"
#include "serial.h"
#include "packet.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
///////////////////////////////////////////////////////////////////////////////
// de-Packetizer
///////////////////////////////////////////////////////////////////////////////
void recvClear( BYTE n )
{
// clear buffer till end of current packet
n++;
while ( n-- && getchavail() )
getch();
}
void recvFlush( void )
{
// flush queue
SerialClear();
}
int recvGet( BYTE n )
{
int c;
BYTE i;
UINT t;
DWORD v = 0;
for ( i = 0; i < n; i++ )
{
t = TIMEOUT;
if ( ( c = getchtimeout( &t ) ) < 0 )
return PACKET_ERR_TIMEOUT;
v |= ( c << ( i * 8 ) );
}
return v;
}
int recvWait( UINT iWait )
{
iWait /= 10;
// wait for a packet
while ( iWait-- )
{
if ( getchavail() > 0 )
return 1;
DelayUsec( 100 );
}
return 0;
}
int recvHeader( WORD *pwCheck, WORD *pwId, BYTE *pbyFlag )
{
int c = 0;
WORD n = 0;
UINT t;
// software timeouts
// check if line needs to turn around
if ( dirRadio( RADIO_LISTEN ) )
{
// generous wait for a packet
if ( !recvWait( PACKET_WAIT_TIME ) )
return PACKET_ERR_TIMEOUT;
}
else
{
// wait for next packet
if ( !recvWait( PACKET_WAIT_TIME/2 ) )
return PACKET_ERR_TIMEOUT;
}
// wait till synchronization string
while ( n < PACKET_SYNC_LENGTH )
{
t = TIMEOUT;
c = getchtimeout( &t );
if ( c == PACKET_RECV_SYNC )
{
if ( n < PACKET_SYNC_LENGTH - 1 )
n++;
}
else if ( c == PACKET_SYNC_CHAR )
{
if ( n == PACKET_SYNC_LENGTH - 1 )
n++;
else
n = 0;
}
else if ( c < 0 )
return c;
else
n = 0;
}
#ifdef PACKET_FILTER
// got it
if ( g_byPacketAvail )
g_byPacketAvail--;
#endif
// init checksum or CRC
*pwCheck = 0;
// id
*pwId = (WORD) recvGet( PACKET_ID_SIZE );
// flag byte
*pbyFlag = (BYTE) recvGet( PACKET_FL_SIZE );
// byte count
n = (WORD) recvGet( PACKET_BC_SIZE );
// check flag
if ( *pbyFlag )
{
// check control flag bits
if ( *pbyFlag & PACKET_FLAG_STREAM )
return n; // ignore rest of bits used for streaming counter
// check each flag
if ( *pbyFlag & PACKET_FLAG_CRC )
g_bPacketCRC = 1;
}
return n;
}
int recvByte( WORD *pwCheck )
{
UINT t = TIMEOUT;
int c;
if ( ( c = getchtimeout( &t ) ) < 0 )
return c;
if ( g_bPacketCRC )
*pwCheck = doCRC16( *pwCheck, c );
else
*pwCheck += (BYTE) c;
return (BYTE) c;
}
int recvData( WORD *pwCheck, PKTBANK BYTE * pbyData, WORD nBytes, WORD maxBytes )
{
WORD nRead = 0;
UINT t;
int c;
// read bytes
while ( nBytes-- )
{
// read
t = TIMEOUT;
c = getchtimeout( &t );
if ( c < 0 )
return c;
// store data away
if ( pbyData && ( nRead < maxBytes ) )
*pbyData++ = c;
// CRC or checksum
if ( g_bPacketCRC )
*pwCheck = doCRC16( *pwCheck, c );
else
*pwCheck += (BYTE) c;
// count
nRead++;
}
return nRead;
}
int recvTrailer( WORD *pwCheck )
{
UINT t = TIMEOUT;
WORD wCheck;
int c;
if ( ( c = getchtimeout( &t ) ) < 0 )
return c;
// CRC or checksum
if ( g_bPacketCRC )
{
// low byte
wCheck = c;
// high byte
if ( ( c = getchtimeout( &t ) ) < 0 )
return c;
wCheck |= (c << 8);
// compare CRCs
if ( *pwCheck != wCheck )
return 0;
}
else
{
// byte, masked
*pwCheck += (BYTE) c;
*pwCheck &= 0xff;
// good checksum is zero
if ( *pwCheck )
return 0;
}
return 1;
}
int recvPacket( WORD *pwId, PKTBANK BYTE *pbyPacket, BYTE *pbyFlag, WORD maxBytes )
{
WORD wCheck;
int nBytes;
// header
if ( ( nBytes = recvHeader( &wCheck, pwId, pbyFlag ) ) < 0 )
return nBytes;
// check
if ( nBytes > maxBytes )
return PACKET_BUF_TOOBIG;
// data
if ( ( nBytes = recvData( &wCheck, pbyPacket, (WORD)nBytes, (WORD)maxBytes ) ) < 0 )
return nBytes;
// checksum
if ( recvTrailer( &wCheck ) )
return nBytes;
return PACKET_BAD_CHECKSUM;
}
int recvFinish( WORD nBytes )
{
WORD wCheck;
recvData( &wCheck, NULL, nBytes, nBytes );
if ( recvTrailer( &wCheck ) )
return nBytes;
return PACKET_BAD_CHECKSUM;
}

View File

@ -1,203 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Streaming Packet Receive
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "serial.h"
#include "types.h"
#include "serial.h"
#include "packet.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
int recvSequence( WORD *pwId, WORD *pwCheck, BYTE *pwCheckSeq )
{
BYTE byFlag = 0;
int nBytes;
// get header
if ( ( nBytes = recvHeader( pwCheck, pwId, &byFlag ) ) < 0 )
return nBytes;
// check sequence number (last packet need not have flag)
if ( ( byFlag ^ *pwCheckSeq ) & 0x7f )
{
recvFinish( nBytes );
return PACKET_ERR_SEQUENCE;
}
// must be streaming packet
if ( !( byFlag & PACKET_FLAG_STREAM ) && nBytes == 0 )
{
recvFinish( nBytes );
return PACKET_ERR_STREAM;
}
// bump sequence
( *pwCheckSeq )++;
return nBytes;
}
int recvStream( WORD wBoxId, PKTBANK BYTE *pbyData, WORD nLen )
{
WORD wId;
WORD wCheck = 0;
BYTE bySeq = 0;
WORD nTotal = 0;
int nBytes = PACKET_ERR_TIMEOUT;
do
{
// get header
if ( ( nBytes = recvSequence( &wId, &wCheck, &bySeq ) ) < 0 )
return nBytes; // error
// check id
if ( wBoxId != wId )
{
// ignore
recvFinish( nBytes );
continue;
}
// to read
if ( nBytes > nLen )
{
recvFinish( nBytes );
// return PACKET_BUF_OVERWRITE;
continue;
}
// gobble the rest
if ( nLen == 0 )
pbyData = NULL;
// receive data
if ( recvData( &wCheck, pbyData, nBytes, nLen ) != nBytes )
{
recvTrailer( &wCheck );
return nBytes;
}
// checksum
if ( !recvTrailer( &wCheck ) )
return PACKET_BAD_CHECKSUM;
// next
if ( pbyData )
pbyData += nBytes;
nTotal += nBytes;
nLen -= nBytes;
// flag off
if ( !( bySeq & PACKET_FLAG_STREAM ) )
break;
}
while ( nBytes > 0 );
return nTotal;
}
int readStream( WORD wBoxId, void (*put)(BYTE), WORD nLen )
{
WORD wId;
WORD wCheck = 0;
BYTE bySeq = 0;
WORD nTotal = 0;
int nBytes = PACKET_ERR_TIMEOUT;
int n, c;
do
{
// get header
if ( ( nBytes = recvSequence( &wId, &wCheck, &bySeq ) ) < 0 )
return nBytes; // error
// check id
if ( wBoxId != wId )
{
// ignore
recvFinish( nBytes );
continue;
}
// to read
if ( nBytes > nLen )
{
recvFinish( nBytes );
// return PACKET_BUF_OVERWRITE;
continue;
}
// receive data
n = nBytes;
while ( n-- )
{
if ( ( c = recvByte( &wCheck ) ) >= 0 )
( *put ) ( c ); // call user's function
else
return c; // timeout
}
// checksum
if ( !recvTrailer( &wCheck ) )
return PACKET_BAD_CHECKSUM;
// next
nTotal += nBytes;
nLen -= nBytes;
// flag off
if ( !( bySeq & PACKET_FLAG_STREAM ) )
break;
}
while ( nBytes > 0 );
return nTotal;
}

View File

@ -1,191 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Packet Transmitter
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "types.h"
#include "serial.h"
#include "packet.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
///////////////////////////////////////////////////////////////////////////////
// Packetizer
///////////////////////////////////////////////////////////////////////////////
void sendPadding( BYTE nBytes )
{
// packet header for synchronization
while ( nBytes-- )
putch( PACKET_SYNC_PAD );
}
void sendSpacing( BYTE nBytes )
{
// inter packet spacing
while ( nBytes-- )
putch( PACKET_SYNC_CHAR );
}
void sendPut( int v, int n )
{
while ( n-- )
{
putch( v );
v >>= 8;
}
}
void sendSynch( BYTE nBytes )
{
// packet header for synchronization
while ( nBytes-- > PACKET_SYNC_LENGTH )
putch( PACKET_SYNC_PAD );
while ( nBytes-- )
putch( PACKET_XMIT_SYNC );
putch( PACKET_SYNC_CHAR );
}
void sendHeader( WORD *pwCheck, WORD wId, BYTE byFlag, WORD nBytes )
{
// check if line needs to turn around
// packet header for synchronization
// switch the radio
if ( getRadio() == RADIO_DIRECT )
sendSynch( PACKET_RESYNC_LENGTH ); // direct connection
else if ( dirRadio( RADIO_TALK ) )
sendSynch( PACKET_HEADER_LENGTH ); // padding for worst case TX->RX switch
else
sendSynch( PACKET_RESYNC_LENGTH );
// put id
sendPut( wId, PACKET_ID_SIZE );
// put flag
sendPut( byFlag, PACKET_FL_SIZE );
// send byte count
sendPut( nBytes, PACKET_BC_SIZE );
// init chksum
*pwCheck = 0;
}
void sendByte( WORD *pwCheck, BYTE byByte )
{
putch( byByte );
if ( *pwCheck )
{
// CRC or checksum
if ( g_bPacketCRC )
*pwCheck = doCRC16( *pwCheck, byByte );
else
*pwCheck += byByte;
}
}
void sendData( WORD *pwCheck, const BYTE *pbyData, WORD nBytes )
{
// output data and compute checksum
while ( nBytes-- )
{
// CRC or checksum
if ( g_bPacketCRC )
*pwCheck = doCRC16( *pwCheck, *pbyData );
else
*pwCheck += *pbyData;
putch( *pbyData++ );
}
}
void sendTrailer( WORD *pwCheck )
{
// CRC or checksum
if ( g_bPacketCRC )
{
// CRC
putch( *pwCheck++ );
putch( *pwCheck );
}
else
{
// final checksum
*pwCheck = 256 - (BYTE)*pwCheck;
putch( *pwCheck );
}
// padding
if ( getRadio() == RADIO_TALK )
sendPadding( PACKET_TRAILER_LENGTH ); // PIC TX->RX switch may kill last char
sendFlush();
}
void sendFlush( void )
{
while ( !putchempty() )
CLRWDT();
}
int sendPacket( WORD wId, const BYTE *pbyPacket, WORD nBytes )
{
WORD wCheck = 0;
// header
sendHeader( &wCheck, wId, 0, (WORD)(pbyPacket ? nBytes : 0) );
// data
if ( pbyPacket && nBytes )
sendData( &wCheck, pbyPacket, nBytes );
// trailer
sendTrailer( &wCheck );
return nBytes;
}

View File

@ -1,133 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Streaming Packet Transmitter
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "types.h"
#include "serial.h"
#include "packet.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
int sendStream( WORD wId, const BYTE *pbyData, WORD nLen )
{
WORD wCheck;
BYTE bySeq = 0;
WORD nTotal = 0;
int nBytes;
while ( nLen > 0 )
{
// how much can I send?
nBytes = nLen;
if ( nBytes > PACKET_MAX_STREAM )
nBytes = PACKET_MAX_STREAM;
// last packet?
if ( nBytes == nLen )
bySeq &= ~PACKET_FLAG_STREAM;
else
bySeq |= PACKET_FLAG_STREAM;
// send data
sendHeader( &wCheck, wId, bySeq, nBytes );
sendData( &wCheck, pbyData, nBytes );
sendTrailer( &wCheck );
// next
pbyData += nBytes;
nTotal += nBytes;
nLen -= nBytes;
bySeq++; // bump sequence
}
return nTotal;
}
int writeStream( WORD wId, BYTE(*get)(void), WORD nLen )
{
WORD wCheck;
BYTE bySeq = 0;
WORD nTotal = 0;
BYTE byData;
int nBytes;
int n;
while ( nLen > 0 )
{
// how much can I send?
nBytes = nLen;
if ( nBytes > PACKET_MAX_STREAM )
nBytes = PACKET_MAX_STREAM;
// last packet?
if ( nBytes == nLen )
bySeq &= ~PACKET_FLAG_STREAM;
else
bySeq |= PACKET_FLAG_STREAM;
// send data
sendHeader( &wCheck, wId, bySeq, nBytes );
n = nBytes;
while ( n-- )
{
byData = ( *get ) ( );
sendByte( &wCheck, byData );
}
sendTrailer( &wCheck );
// next
nTotal += nBytes;
nLen -= nBytes;
bySeq++; // bump sequence
}
return nTotal;
}

View File

@ -1,150 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Port B
*----------------------------------------------------------------------------
* Int Pin 0 Interrupt
* Int Pin 1-2 Interrupt
* Int Pin 4-7 Change detect
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _PORTB_H_
#define _PORTB_H_
/*****************************************************************************
* includes
*****************************************************************************/
// this is application specific
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
// INT0
#ifdef RB0_PIN
#define PortB0Clr() g_bRb0Flag=0
#define PortB0Set() g_bRb0Flag=1
#define PortB0Get() g_bRb0Flag
#define PortB0Clear() g_wRb0Count0=0
#define PortB0Count() g_wRb0Count0
#define PortB0Read() g_stCount0.dw // timer #1 reading
#endif
// INT0-2
#ifdef _PIC18
#ifdef RB1_PIN
#define PortB1Clr() g_bRb1Flag=0
#define PortB1Set() g_bRb1Flag=1
#define PortB1Get() g_bRb1Flag
#define PortB1Clear() g_wRb1Count=0
#define PortB1Count() g_wRb1Count
#endif
#ifdef RB2_PIN
#define PortB2Clr() g_bRb2Flag=0
#define PortB2Set() g_bRb2Flag=1
#define PortB2Get() g_bRb2Flag
#define PortB2Clear() g_wRb2Count=0
#define PortB2Count() g_wRb2Count
#endif
#endif
#define PortB4567Flag() g_bRb4567Flag
#define PortB4567Clear() g_bRb4567Flag=0
#ifdef RB4_PIN
#define PortB4High() g_wRb4High
#define PortB4Low() g_wRb4Low
#endif
#ifdef RB5_PIN
#define PortB5High() g_wRb5High
#define PortB5Low() g_wRb5Low
#endif
#ifdef RB6_PIN
#define PortB6High() g_wRb6High
#define PortB6Low() g_wRb6Low
#endif
#ifdef RB7_PIN
#define PortB7High() g_wRb7High
#define PortB7Low() g_wRb7Low
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
#ifdef RB0_PIN
LIBBANK extern volatile bit g_bRb0Flag;
LIBBANK extern volatile long_dword g_stCount0;
LIBBANK extern volatile WORD g_wRb0Counter;
#endif
#ifdef RB1_PIN
LIBBANK extern volatile bit g_bRb1Flag;
LIBBANK extern volatile WORD g_wRb1Counter;
#endif
#ifdef RB2_PIN
LIBBANK extern volatile bit g_bRb2Flag;
LIBBANK extern volatile WORD g_wRb2Counter;
#endif
LIBBANK extern volatile bit g_bRb4567Flag;
#ifdef RB4_PIN
LIBBANK extern volatile bit g_bRb4Flag;
LIBBANK extern volatile WORD g_wRb4Low;
LIBBANK extern volatile WORD g_wRb4High;
#endif
#ifdef RB5_PIN
LIBBANK extern volatile bit g_bRb5Flag;
LIBBANK extern volatile WORD g_wRb5Low;
LIBBANK extern volatile WORD g_wRb5High;
#endif
#ifdef RB6_PIN
LIBBANK extern volatile bit g_bRb6Flag;
LIBBANK extern volatile WORD g_wRb6Low;
LIBBANK extern volatile WORD g_wRb7High;
#endif
#ifdef RB7_PIN
LIBBANK extern volatile bit g_bRb7Flag;
LIBBANK extern volatile WORD g_wRb7Low;
LIBBANK extern volatile WORD g_wRb7High;
#endif
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
// interrupt pins
extern void PortB0Init( void );
extern void PortB0Handler( void );
extern void PortB12Init( BYTE byPins );
extern void PortB12Handler( void );
extern void PortB4567Init( void );
extern void PortB4567Handler( void );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,111 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Port B Pin 0 Interrupt (INT0)
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "portb.h"
#ifdef RB0_PIN
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// external interrupt pin (RB0), flag and counter
LIBBANK volatile bit g_bRb0Flag = 0;
LIBBANK volatile long_dword g_stCount0;
LIBBANK volatile WORD g_wCount0 = 0L;
extern LIBBANK volatile WORD g_wTimer1High;
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PortB0Init( void )
{
RB0 = 0;
TRISB0 = 1; // input
#ifdef _PIC18
INT0IE = 1;
INTEDG0 = 1; // default rising
#else
INTE = 1;
INTEDG = 1; // default rising
#endif
g_bRb0Flag = 0;
g_stCount0.dw = 0L;
}
// high priority only
void PortB0Handler( void )
{
// RB0 interrupt pin
#ifdef _PIC18
if ( INT0IF )
#else
if ( INTF )
#endif
{
g_bRb0Flag = 1;
#ifdef _PIC18
g_stCount0.w.h = g_wTimer1High; // high first so can check for change
g_stCount0.w.l = TMR1;
#else
g_stCount0.w.h = g_wTimer1High; // high first so can check for change
g_stCount0.b.lh = TMR1H;
g_stCount0.b.ll = TMR1L;
if ( g_stCount0.w.h != g_wTimer1High || g_stCount0.b.lh != TMR1H )
{
g_stCount0.w.h = g_wTimer1High;
g_stCount0.b.lh = TMR1H;
g_stCount0.b.ll = TMR1L;
}
#endif
#ifdef _PIC18
INT0IF = 0;
#else
INTF = 0;
#endif
g_wCount0++;
}
}
#endif

View File

@ -1,113 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Port B Pins 1-2 Interrupt (INT1-2)
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "portb.h"
#if (defined(RB1_PIN) || defined(RB2_PIN)) && defined(_PIC18)
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
#ifdef RB1_PIN
LIBBANK volatile WORD g_wRb1Count = 0L;
#endif
#ifdef RB2_PIN
LIBBANK volatile WORD g_wRb2Count = 0L;
#endif
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PortB12Init( BYTE byPins )
{
#ifdef RB1_PIN
RB1 = 0;
if ( byPins & 1 )
{
TRISB1 = 1; // input
INT1IE = 1;
INT1IP = 0;
INTEDG1 = 1; // default rising
g_wRb1Count = 0L;
}
#endif
#ifdef RB2_PIN
RB2 = 0;
if ( byPins & 2 )
{
TRISB2 = 1; // input
INT2IE = 1;
INT2IP = 0;
INTEDG2 = 1; // default rising
g_wRb2Count = 0L;
}
#endif
}
void PortB12Edge( BYTE byEdge )
{
INTEDG1 = byEdge;
INTEDG2 = byEdge >> 1;
}
void PortB12Handler( void )
{
if ( INT1IF )
{
g_bRb1Flag = 1;
g_wRb1Count++;
INT1IF = 0;
}
if ( INT2IF )
{
g_bRb2Flag = 1;
g_wRb2Count++;
INT2IF = 0;
}
}
#endif

View File

@ -1,171 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Port B Pin 4-7 Change Detect
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "project.h"
#include "portb.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
LIBBANK volatile bit g_bRb4567Flag = 0;
// not good for long pulses
#ifdef RB4_PIN
LIBBANK volatile bit g_bRb4Flag = 0;
LIBBANK volatile WORD g_wRb4High = 0L;
LIBBANK volatile WORD g_wRb4Low = 0L;
LIBBANK volatile WORD g_wRb4Last = 0L;
#endif
#ifdef RB5_PIN
LIBBANK volatile bit g_bRb5Flag = 0;
LIBBANK volatile WORD g_wRb5High = 0L;
LIBBANK volatile WORD g_wRb5Low = 0L;
LIBBANK volatile WORD g_wRb5Last = 0L;
#endif
#ifdef RB6_PIN
// not good for long pulses
LIBBANK volatile bit g_bRb6Flag = 0;
LIBBANK volatile WORD g_wRb6High = 0L;
LIBBANK volatile WORD g_wRb6Low = 0L;
LIBBANK volatile WORD g_wRb6Last = 0L;
#endif
#ifdef RB7_PIN
LIBBANK volatile bit g_bRb7Flag = 0;
LIBBANK volatile WORD g_wRb7High = 0L;
LIBBANK volatile WORD g_wRb7Low = 0L;
LIBBANK volatile WORD g_wRb7Last = 0L;
#endif
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PortB4567Init( void )
{
#ifdef RB4_PIN
RB4 = 0;
g_bRb4Flag = RB4;
TRISC4 = 0;
#endif
#ifdef RB5_PIN
RB5 = 0;
g_bRb5Flag = RB5;
TRISC5 = 0;
#endif
#ifdef RB6_PIN
RB6 = 0;
g_bRb6Flag = RB6;
TRISC6 = 0;
#endif
#ifdef RB7_PIN
RB7 = 0;
g_bRb7Flag = RB7;
TRISC7 = 0;
#endif
RBIE = 1;
#ifdef _PIC18
RBIP = 0;
#endif
}
// 18F callable
#ifdef _PIC18
void PortB4567Handler( void )
{
if ( !RBIF )
return;
g_bRb4567Flag = 1;
// read bits, measure width
#ifdef RB4_PIN
if ( g_bRb4Flag != RB4 )
{
// RB4 changed
if ( RB4 )
g_wRb4Low = TMR1 - g_wRb4Last; // pulse width low
else
g_wRb4High = TMR1 - g_wRb4Last; // pulse width high
g_wRb4Last = TMR1;
g_bRb4Flag = RB4;
}
#endif
#ifdef RB5_PIN
if ( g_bRb5Flag != RB5 )
{
// RB5 changed
if ( RB5 )
g_wRb5Low = TMR1 - g_wRb5Last; // pulse width low
else
g_wRb5High = TMR1 - g_wRb5Last; // pulse width high
g_wRb5Last = TMR1;
g_bRb5Flag = RB5;
}
#endif
#ifdef RB6_PIN
if ( g_bRb6Flag != RB6 )
{
// RB6 changed
if ( RB6 )
g_wRb6Low = TMR1 - g_wRb6Last; // pulse width low
else
g_wRb6High = TMR1 - g_wRb6Last; // pulse width high
g_wRb6Last = TMR1;
g_bRb6Flag = RB6;
}
#endif
#ifdef RB7_PIN
if ( g_bRb7Flag != RB7 )
{
// RB7 changed
if ( RB7 )
g_wRb7Low = TMR1 - g_wRb7Last; // pulse width low
else
g_wRb7High = TMR1 - g_wRb7Last; // pulse width high
g_wRb7Last = TMR1;
g_bRb7Flag = RB7;
}
#endif
RBIF = 0;
}
#endif

View File

@ -1,51 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Project Header
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _PROJECT_H_
#define _PROJECT_H_
/*****************************************************************************
* includes
*****************************************************************************/
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,87 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PWM Output
*----------------------------------------------------------------------------
* Output PWM (8 bit resolution for now)
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "pwm.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PwmInit( void )
{
RC1 = RC2 = 0;
PR2 = 255; // max period
T2CON = 0b00000111; // 16:1 prescale
// PWM1
TRISC1 = 0;
CCPR1L = 0;
CCP1CON = 0b00001100;
// PMW2
TRISC2 = 0;
CCPR2L = 0;
CCP2CON = 0b00001100;
}
// duty cycle 0-PWM_DUTY_MAX (use macro)
void PwmOut( BYTE byPin, WORD wDuty )
{
// clip
if ( wDuty > PWM_DUTY_MAX )
wDuty = PWM_DUTY_MAX;
// allows custom rate for timer 2
if ( PR2 != 255 )
wDuty = wDuty * PR2 / PWM_DUTY_CYCLE;
// scale duty cycle
if ( byPin == 1 )
CCPR1L = wDuty;
if ( byPin == 2 )
CCPR2L = wDuty;
}

View File

@ -1,61 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PWM Output
*----------------------------------------------------------------------------
* PWM1
* PWM2
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _PWM_H_
#define _PWM_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#define PWM_DUTY_CYCLE 256
#define PWM_DUTY_MIN 0
#define PWM_DUTY_HALF (PWM_DUTY_CYCLE/2)
#define PWM_DUTY_MAX (PWM_DUTY_CYCLE-1)
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void PwmInit( void );
extern void PwmOut( BYTE pin, WORD duty );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1 +0,0 @@
../include/bytequeue.h

View File

@ -1,63 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Baud Rate
*----------------------------------------------------------------------------
* Serial port driver loop using USART, interrupt driven.
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "serial.h"
#include "delay.h"
#include "queue.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void SerialBaud( DWORD dwBaud )
{
#ifdef __linux__
openPort( closePort(), dwBaud );
#else
SPBRG = USART_GEN( dwBaud );
#endif
}

View File

@ -1,133 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Number Input
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
static DWORD getun_internal( BYTE echo )
{
DWORD n;
char c;
do
{
c = getch( );
if ( echo )
putch( c );
}
while ( c < '0' || c > '9' );
n = 0;
for ( ;; )
{
if ( c >= ( ( int ) '0' ) && c <= ( ( int ) '9' ) )
{
n *= 10;
n += c - '0';
}
else
break;
c = getch( );
if ( echo )
putch( c );
}
return n;
}
DWORD getun( void )
{
return ( getun_internal( 1 ) );
}
DWORD getunn( void )
{
return ( getun_internal( 0 ) );
}
static DWORD getuntimeout_internal( UINT * t, BYTE echo )
{
WORD n;
char c;
do
{
c = getchtimeout( t );
if ( echo )
putch( c );
}
while ( c < '0' || c > '9' );
n = 0;
for ( ;; )
{
if ( c >= ( ( int ) '0' ) && c <= ( ( int ) '9' ) )
{
n *= 10;
n += c - '0';
}
else
break;
c = getchtimeout( t );
if ( echo )
putch( c );
}
return n;
}
DWORD getuntimeout( UINT * t )
{
return getuntimeout_internal( t, 1 );
}
DWORD getunntimeout( UINT * t )
{
return getuntimeout_internal( t, 0 );
}

View File

@ -1,81 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial String Input
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef SERIAL_GET
int serial_get( BYTE *s, WORD n )
{
int r = n;
while ( n-- )
*s++ = getch();
return r;
}
#endif
int gets( char *s, short n )
{
char c;
int l = 0;
while ( (c = getch()) && n-- )
{
if ( c == '\r' )
{
putch( c );
putch( '\n' );
break;
}
*s++ = c;
l++;
}
return l;
}

View File

@ -1,72 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Input
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
WORD getword( )
{
short_word word;
word.b.l = getch();
word.b.h = getch();
return word.w;
}
DWORD getdword( )
{
long_dword dword;
dword.b.ll = getch();
dword.b.lh = getch();
dword.b.hl = getch();
dword.b.hh = getch();
return dword.dw;
}

View File

@ -1,154 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Initialization & Interrupt Handler
*----------------------------------------------------------------------------
* Serial port driver loop using USART, interrupt driven.
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "serial.h"
#include "delay.h"
#include "queue.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// interrupt driven serial i/o uses queues
SERBANK Queue g_qSerialRx = { 0, 0, 0, 0 };
SERBANK Queue g_qSerialTx = { 0, 0, 0, 0 };
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
static LIBBANK BYTE byRx = 0;
static LIBBANK BYTE byTx = 0;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void SerialInit( void )
{
// fix these
RC6 = 1;
RC7 = 1;
TRISC6 = 0;
TRISC7 = 1;
// baud rate
SerialBaud( BAUD );
// asynchronous serial
// recv, 8 bits, continuous
RCSTA = 0b10010000;
// xmit, 8 bits, high speed
TXSTA = 0b00100110;
CREN = 0;
CREN = 1;
}
void SerialAlloc( BYTE *pbyTx, BYTE nTx, BYTE *pbyRx, BYTE nRx )
{
QueueAlloc( &g_qSerialTx, pbyTx, nTx );
QueueAlloc( &g_qSerialRx, pbyRx, nRx );
if ( nTx )
{
RCIE = 1;
#ifdef _PIC18
RCIP = 1;
#endif
}
if ( nRx )
{
TXIE = 0; // turned on by putch()
#ifdef _PIC18
TXIP = 1;
#endif
}
RCIF = TXIF = 0;
}
void SerialClear( void )
{
CREN = 0;
CREN = 1;
QueueClear( &g_qSerialTx );
QueueClear( &g_qSerialRx );
getchflush();
}
void SerialHandler( void )
{
// RC7/RX
if ( RCIF )
{
// check queue, lose a byte if necessary
while ( _QueueFull( g_qSerialRx ) )
_QueueGet( g_qSerialRx, byRx );
// read char
byRx = RCREG;
_QueuePut( g_qSerialRx, byRx );
// doesn't handle overflow, so app had better have big buffer
if ( OERR )
{
// overrun error (lost data)
CREN = 0;
CREN = 1;
}
RCIF = 0;
}
// RC6/TX
if ( TXIF )
{
// ready to xmit
byTx = _QueueCount( g_qSerialTx );
if ( byTx )
{
// output from queue
_QueueGet( g_qSerialTx, TXREG );
byTx--;
}
if ( byTx == 0 )
{
// nothing left, disable
TXIE = 0;
}
TXIF = 0;
}
}

View File

@ -1,137 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Char/Byte Input
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "serial.h"
#include "delay.h"
#include "queue.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
extern SERBANK Queue g_qSerialRx;
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
BYTE getchavail( void )
{
if ( QueueSize( &g_qSerialRx ) )
return QueueCount( &g_qSerialRx );
return RCIF;
}
void getchflush( void )
{
char c;
if ( QueueSize( &g_qSerialRx ) )
{
QueueClear( &g_qSerialRx );
}
else
{
while ( RCIF )
c = RCREG;
}
CREN = 0;
CREN = 1;
}
int getch( void )
{
int c;
BYTE b;
// from buffer
if ( QueueSize( &g_qSerialRx ) )
{
while ( QueueCount( &g_qSerialRx ) == 0 )
CLRWDT();
QueueGet( &g_qSerialRx, &b );
c = b;
}
else
{
while ( !RCIF )
CLRWDT();
c = RCREG;
}
// check for errors
if ( FERR )
c = SER_ERR_FRAME;
else if ( OERR )
c = SER_ERR_OVERRUN;
if ( c < 0 )
{
CREN = 0;
CREN = 1;
}
return c;
}
int getchtimeout( UINT * t )
{
WORD d = *t * 100;
if ( QueueSize( &g_qSerialRx ) )
{
while ( d-- )
{
if ( QueueCount( &g_qSerialRx ) )
return getch();
}
}
else
{
while ( d-- )
{
if ( RCIF )
return getch();
DelayUsec( 10 );
*t = d / 10;
}
}
return SER_ERR_TIMEOUT;
}

View File

@ -1,243 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Linux Serial Driver
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
#if defined(__linux__)
/*****************************************************************************
* includes
*****************************************************************************/
// Linux
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <asm/ioctls.h>
#include <termios.h>
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
static int port = -1;
static int fd = -1;
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
// defaults to stdio for debugging purposes until serial port is opened
// Better to use select() in the at the app level when reading serial port
int openPort( int iPort, int iBaud )
{
struct termios oldtio, newtio;
char tty[255];
// old port
if ( iPort < 0 )
iPort = port;
else
port = iPort;
if ( iPort < 0 )
return -1;
// device name
sprintf( tty, "/dev/ttyS%d", iPort - 1 );
fd = open( tty, O_RDWR | O_NOCTTY );
if ( fd < 0 )
{
perror( tty );
return -1;
}
// termios
tcgetattr( fd, &oldtio ); /* save current serial port settings */
bzero( &newtio, sizeof(newtio) ); /* clear struct for new port settings */
// no handshake, 8N1, local
newtio.c_cflag = CS8 | CLOCAL | CREAD;
// speed
switch ( iBaud )
{
case 9600:
newtio.c_cflag |= B9600;
break;
case 19200:
newtio.c_cflag |= B19200;
break;
case 38400:
newtio.c_cflag |= B38400;
break;
case 57600:
newtio.c_cflag |= B57600;
break;
case 115200:
newtio.c_cflag |= B115200;
break;
default:
close( fd );
return -1;
}
// raw mode, no special character processing
newtio.c_iflag = 0;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
// timing
newtio.c_cc[VMIN] = 1; // 1 char at a time
newtio.c_cc[VTIME] = 1; // 100msec timeout
// set it
tcflush( fd, TCIFLUSH );
tcsetattr( fd, TCSANOW, &newtio );
// return handle
return fd;
}
int closePort( void )
{
if ( fd >= 0 )
close( fd );
else
port = -1;
fd = -1;
return port;
}
int getchavail( void )
{
int n = 0;
if ( fd < 0 )
{
if ( feof( stdin ) == 0 )
return 1;
return -1;
}
ioctl( fd, FIONREAD, &n );
return n;
}
int getchflush( void )
{
if ( fd < 0 )
return fd;
tcflush( fd, TCIFLUSH );
return 0;
}
int getch( void )
{
char c = 0;
if ( fd < 0 )
return getchar();
while ( read( fd, &c, 1 ) < 1 )
;
return c;
}
int getchtimeout( int *t )
{
char c = 0;
if ( fd < 0 )
return getchar();
// ignore timeout
if ( read( fd, &c, 1 ) == 1 )
return c;
return -2;
}
void putch( int i )
{
char c = i;
if ( fd < 0 )
{
putchar( c );
return;
}
// not particularly efficient
write( fd, &c, 1 );
}
BYTE putchempty( void )
{
if ( fd < 0 )
{
fflush( stdout );
return 1;
}
// flush it
tcflush( fd, TCOFLUSH );
tcdrain( fd );
return 1;
}
void putchflush( void )
{
if ( fd < 0 )
{
fflush( stdout );
return;
}
// flush it
tcflush( fd, TCOFLUSH );
tcdrain( fd );
}
#endif

View File

@ -1,106 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Char/Byte Output
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "serial.h"
#include "delay.h"
#include "queue.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
extern SERBANK Queue g_qSerialTx;
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
BYTE putchempty( void )
{
if ( QueueSize( &g_qSerialTx ) )
{
if ( QueueCount( &g_qSerialTx ) )
return 0;
}
return TRMT;
}
void putchflush( void )
{
if ( QueueSize( &g_qSerialTx ) )
{
while ( QueueCount( &g_qSerialTx ) )
CLRWDT();
QueueClear( &g_qSerialTx );
}
else
{
while ( !TRMT )
CLRWDT();
}
}
// put character
void putch( char c )
{
// buffer
if ( QueueSize( &g_qSerialTx ) )
{
if ( TXIE )
{
// interrupts are running, store in buffer
while ( QueueFull( &g_qSerialTx ) )
CLRWDT();
QueuePut( &g_qSerialTx, (BYTE*)&c );
return;
}
QueueClear( &g_qSerialTx );
TXIE = 1; // enable interrupt
}
// put char
while ( !TXIF )
CLRWDT();
TXREG = c;
}

View File

@ -1,88 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Number Output
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
// warning, only does 8 digits
void putun( DWORD l )
{
BYTE i = 0;
DWORD o = 0;
while ( l )
{
o <<= 4;
o |= ( l % 10 );
l /= 10;
i++;
}
if ( i == 0 )
i++;
while ( i-- )
{
putch( (o & 0xf) + '0' );
o >>= 4;
}
putch( ' ' );
}
void putn( long n )
{
if ( n < 0 )
{
putch( '-' );
n = -n;
}
putun( n );
}

View File

@ -1,87 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial String Output
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#ifdef __linux__
#define putch(C) putchar(C)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
#ifdef SERIAL_PUTS
int serial_puts( const BYTE *s, WORD n )
{
int r = n;
while ( n-- )
putch( *s++ );
return r;
}
#endif
int puts( const char *s )
{
char c;
int n = 0;
while ( c = *s++ )
{
if ( c == '\n' )
{
putch( '\r' );
n++;
}
putch( c );
n++;
}
putch( '\r' );
putch( '\n' );
return n+2;
}

View File

@ -1,66 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Output
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void putword( WORD i )
{
putch( i );
putch( i >> 8 );
}
void putdword( DWORD i )
{
putch( i );
putch( i >> 8 );
putch( i >> 16 );
putch( i >> 24 );
}

View File

@ -1,83 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Hex Output
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void puthex( DWORD l, BYTE s )
{
BYTE d;
while ( s )
{
s -= 4;
d = ( l >> s ) & 0x0f;
if ( d < 10 )
putch( d + 0x30 );
else
putch( d - 10 + 0x41 );
}
putch( ' ' );
}
void putbx( BYTE b )
{
puthex( b, 8 );
}
void putwx( WORD w )
{
puthex( w, 16 );
}
void putdwx( DWORD l )
{
puthex( l, 32 );
}

View File

@ -1,296 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Windows Serial Emulation Driver
*----------------------------------------------------------------------------
* Win32 API serial communications
*****************************************************************************/
#if defined(_WINDOWS)
/*****************************************************************************
* includes
*****************************************************************************/
// Windows
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "wtypes.h"
#ifdef USB_FTDI
// USB instead of serial
#include "FTD2XX.h"
#endif
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
#ifdef USB_FTDI
static FT_HANDLE m_ftHandle;
static FT_DEVICE m_ftDevice;
static DWORD m_dwDeviceId = 0;
#else
static HANDLE hComm = NULL;
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
int openPort( int iPort, int iBaud )
{
#ifdef USB_FTDI
// default USB device
if ( FT_OpenEx( "DLP-USB232M", FT_OPEN_BY_DESCRIPTION, &m_ftHandle ) == FT_OK )
{
// DLP/FTDI D2XX unprogrammed, probably a virtual communications port (VCP)
}
#ifdef CORSA_USB_RADIO
else if ( FT_OpenEx( "Corsa-USB232M-Radio", FT_OPEN_BY_DESCRIPTION, &m_ftHandle ) == FT_OK )
{
// Corsa EZ-Logger, by description
}
#endif
else
return 0;
// set speed, if standard or custom
if ( iBaud == 1200 || iBaud == 2400 || iBaud == 4800 || iBaud == 9600 ||
iBaud == 19200 || iBaud == 38400 || iBaud == 57600 || iBaud == 115200 )
{
// use default divisors
if ( FT_SetBaudRate( m_ftHandle, iBaud ) != FT_OK )
{
FT_Close( m_ftHandle );
return 0;
}
}
else
{
// note that I ignored the fractional portion (for now)
if ( FT_SetDivisor( m_ftHandle, 3000000 / iBaud ) != FT_OK )
{
FT_Close( m_ftHandle );
return 0;
}
}
// setup
if ( FT_ResetDevice( m_ftHandle ) != FT_OK ||
FT_SetDataCharacteristics( m_ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE ) != FT_OK ||
FT_SetFlowControl( m_ftHandle, FT_FLOW_NONE, 0, 0 ) != FT_OK ||
FT_SetChars( m_ftHandle, 0, 0, 0, 0 ) != FT_OK ||
FT_SetTimeouts( m_ftHandle, 100, 0 ) != FT_OK )
{
FT_Close( m_ftHandle );
return 0;
}
return 1;
#else
char szPort[256];
COMMTIMEOUTS timeouts;
DCB dcb;
// comm port name
sprintf( szPort, "COM%d", iPort );
// open
hComm = CreateFile( szPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0 );
if ( hComm == INVALID_HANDLE_VALUE )
{
hComm = 0;
return -1;
}
// control
FillMemory( &dcb, sizeof( dcb ), 0 );
dcb.DCBlength = sizeof( dcb );
sprintf( szPort, "%d,n,8,1", iBaud );
if ( !BuildCommDCB( szPort, &dcb ) )
{
CloseHandle( hComm );
hComm = 0;
return -1;
}
// handshake
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
if ( !SetCommState( hComm, &dcb ) )
{
CloseHandle( hComm );
hComm = 0;
return -1;
}
// the first two don't help at all, so don't set them!
memset( &timeouts, 0, sizeof( timeouts ) );
timeouts.ReadIntervalTimeout = 0; // between chars (no char time)
timeouts.ReadTotalTimeoutMultiplier = 0; // * #chars to read
timeouts.ReadTotalTimeoutConstant = 500; // wait time till something arrives
if ( !SetCommTimeouts( hComm, &timeouts ) )
{
CloseHandle( hComm );
hComm = 0;
return -1;
}
// generous buffering
SetupComm( hComm, 16384, 16384 );
// done
return iPort;
#endif
}
int closePort( void )
{
#ifdef USB_FTDI
if ( m_ftHandle )
{
FT_Close( m_ftHandle );
m_ftHandle = 0;
}
return 0;
#else
if ( hComm )
{
return CloseHandle( hComm );
hComm = 0;
}
return 0;
#endif
}
int getchavail( void )
{
#ifdef USB_FTDI
DWORD dwAvail = 0;
if ( FT_GetQueueStatus( m_ftHandle, &dwAvail ) == FT_OK )
return ( int ) dwAvail;
return 0;
#else
COMSTAT comStat;
DWORD dwErrors;
// weird
if ( !ClearCommError( hComm, &dwErrors, &comStat ) )
return -1;
return comStat.cbInQue;
#endif
}
int getch( void )
{
DWORD dwRead = 0;
BYTE c = 0;
#ifdef USB_FTDI
if ( FT_Read( m_ftHandle, &c, 1, &dwRead ) == FT_OK )
{
if ( dwRead == 1 )
return c;
}
#else
if ( ReadFile( hComm, &c, 1, &dwRead, NULL ) )
{
if ( dwRead == 1 )
return c;
}
#endif
return -2;
}
void getchflush( void )
{
#ifdef USB_FTDI
FT_Purge( m_ftHandle, FT_PURGE_RX );
#else
int i, n = 0;
while ( (i = getchavail()) > 0 )
{
n += i;
while ( i-- )
getch();
}
#endif
}
int getchtimeout( int *t )
{
BYTE c = 0;
DWORD dwRead = 0;
#ifdef USB_FTDI
if ( FT_Read( m_ftHandle, &c, 1, &dwRead ) == FT_OK )
{
if ( dwRead == 1 )
return c;
}
#else
if ( ReadFile( hComm, &c, 1, &dwRead, NULL ) )
{
if ( dwRead == 1 )
return c;
}
#endif
return -2;
}
void putch( int c )
{
DWORD dwWrite = 0;
#ifdef USB_FTDI
FT_Write( m_ftHandle, &byData, 1, &dwWrite );
#else
WriteFile( hComm, &c, 1, &dwWrite, NULL );
#endif
}
BYTE putchempty( void )
{
#ifdef USB_FTDI
if ( FT_Purge( m_ftHandle, FT_PURGE_TX ) == FT_OK )
return 1;
return 0;
#else
// flush
FlushFileBuffers( hComm );
return 1;
#endif
}
#endif

View File

@ -1,87 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Serial Hex Dump
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "serial.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void hexdump( DWORD dwAddr, const BYTE *pbyData, WORD nBytes )
{
WORD n;
BYTE i;
BYTE c;
while ( nBytes )
{
puthex( dwAddr, 32 );
n = 16;
if ( nBytes < n )
n = nBytes;
// hex
for ( i = 0; i < n; i++ )
puthex( *( pbyData + i ), 8 );
// string
for ( i = 0; i < n; i++ )
{
c = *( pbyData + i );
if ( 0x20 <= c && c < 0x7f )
putch( c );
else
putch( '.' );
}
putnl();
dwAddr += 16;
pbyData += 16;
nBytes -= n;
}
}

View File

@ -1,136 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Serial I/O Interface
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _SERIAL_H_
#define _SERIAL_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#ifndef BAUD
#define BAUD 57600
#endif
// some of these may not apply w/ -DSERIAL_LOOP
#define SER_ERR_DEVICE (-1)
#define SER_ERR_TIMEOUT (-2)
#define SER_ERR_OVERRUN (-3)
#define SER_ERR_FRAME (-4)
#define SER_NO_DATA (-5)
/*****************************************************************************
* macros
*****************************************************************************/
// rate generation
#define USART_GEN(B) ((((byXtal*1000000L)/(B))/16L)-1)
#define USART_RATE USART_GEN(BAUD)
#define hexchar(c) ((c >= (int)'0' && c <= (int)'9') || \
(c >= (int)'A' && c <= (int)'F') || (c >= (int)'a' && c <= (int)'f'))
#define putnl() puts("\n")
#define putlf() putch('\f')
#define putbl() putch(' ')
#define putline(s) puts(s);putnl()
// memory i/o style semantics
#define SerialReadByte() getch()
#define SerialWriteByte(B) putch(B)
#define SerialReadBlock(B,N) serial_get(B,N)
#define SerialWriteBlock(B,N) serial_put(B,N)
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void SerialIdle( void ); // user supplied serial idle routine
extern void SerialInit( void );
extern void SerialBaud( DWORD dwBaud );
extern void SerialClear( void );
extern void SerialAlloc( BYTE *pbyTx, BYTE nTx, BYTE *pbyRx, BYTE nRx );
// interrupt
extern void SerialHandler( void );
extern BYTE getchavail( void );
extern void getchflush( void );
extern BYTE putchempty( void );
extern void putchflush( void );
extern void putch( char c );
extern BYTE gethook( void ); // nonzero if cable plugged in
#ifndef _STDIO_H_
extern int getch( void ); // <0 error
#endif
extern int getchtimeout( UINT * t ); // <0 error
// primitive data i/o
#define putint(I) putword(I)
extern void putword( WORD i );
#define putlint(L) putdword(L)
extern void putdword( DWORD i );
#define getint() getword()
extern WORD getword( void );
#define getlint() getdword()
extern DWORD getdword( void );
// string i/o
extern int puts( const char *s );
extern int serial_put( const BYTE *s, WORD n );
extern void puthex( DWORD l, BYTE s );
extern void putbx( BYTE n );
extern void putwx( WORD b );
extern void putdwx( DWORD n );
extern void putun( DWORD n );
extern void putn( long n );
extern int serial_get( const BYTE *s, WORD n );
extern DWORD getx( void );
extern DWORD getun( void );
extern DWORD getuntimeout( UINT * t );
extern DWORD getunn( void ); // no echo
extern DWORD getunntimeout( UINT * t ); // no echo
extern void hexdump( DWORD dwAddr, const BYTE * pbyData, WORD nBytes );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,145 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* SPI Polled Hardware I/O
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "spi.h"
#include "delay.h"
#include "queue.h"
/*****************************************************************************
* defines
*****************************************************************************/
// master
#ifdef SPI_FAST
#define SPI_SSPCON 0b00100001
#ifndef SPI_WAIT
#define SPI_WAIT 9
#endif
#else
#define SPI_SSPCON 0b00100010
#ifndef SPI_WAIT
#define SPI_WAIT 18
#endif
#endif
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
static LIBBANK BYTE bySpiWait = SPI_WAIT;
#ifdef SPI_DEBUG
static LIBBANK BYTE cSpiLastXmit = 0;
static LIBBANK BYTE cSpiThisXmit = 0;
#endif
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void SpiInit( void )
{
// init
RC3 = RC4 = RC5 = 0;
// fix these
TRISC3 = 0;
TRISC4 = 1;
TRISC5 = 0;
SSPSTAT = 0;
#ifdef _PIC18
SSPCON1 = SPI_SSPCON;
#else
SSPCON = SPI_SSPCON;
#endif
}
void SpiWaitTime( BYTE byUsec )
{
bySpiWait = byUsec;
}
BYTE SpiXferByte( BYTE byOut )
{
BYTE byIn;
// send byte
SSPBUF = byOut;
while ( WCOL )
{
// xmit collision
WCOL = 0;
SSPBUF = byOut;
}
// recv byte
#ifdef _PIC18
while ( !BF )
;
#else
while ( !(SSPSTAT & 1) )
;
#endif
byIn = SSPBUF;
#ifdef SPI_DEBUG
cSpiLastXmit = byIn;
if ( cSpiLastXmit != cSpiNextXmit )
SPI_DEBUG = 1;
else
SPI_DEBUG = 0;
cSpiNextXmit = byOut;
#endif
if ( bySpiWait )
DelayUsec( bySpiWait ); // be patient
return byIn;
}
void SpiReadData( BYTE *pbyData, BYTE nBytes )
{
while ( nBytes-- )
*pbyData++ = SpiXferByte( 0 );
}
void SpiWriteData( const BYTE *pbyData, BYTE nBytes )
{
while ( nBytes-- )
SpiXferByte( *pbyData++ );
}

View File

@ -1,70 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC SPI Interface
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _SPI_H_
#define _SPI_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "queue.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
#ifdef _PIC18
#define SSPCON SSPCON1
#define STAT_RW RW
#define STAT_DA DA
#endif
/*****************************************************************************
* macros
*****************************************************************************/
#define SpiReadByte() SpiXferByte(0)
#define SpiWriteByte(B) SpiXferByte(B)
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void SpiInit( void );
extern void SpiWaitTime( BYTE byUsec );
extern BYTE SpiXferByte( BYTE byOut );
extern void SpiReadData( BYTE *pbyData, BYTE nBytes );
extern void SpiWriteData( const BYTE *pbyData, BYTE nBytes );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1 +0,0 @@
../include/bytestack.h

View File

@ -1,156 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Board Support Initialization
* Description
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include <sys.h>
#include "system.h"
#include "delay.h"
#include "analog.h"
#include "clock.h"
// user's project
#include "project.h"
// hardware
#include "timers.h"
#ifdef PERIOD_MODULE
#include "period.h"
#endif
#ifdef PWM_MODULE
#include "pwm.h"
#endif
// communications
#ifdef I2C_MODULE
#include "i2c.h"
#endif
#ifdef SPI_MODULE
#include "spi.h"
#endif
#ifdef SERIAL_MODULE
#include "serial.h"
#endif
// mass storage
#ifdef ATMEL_MODULE
#include "atmel.h"
#endif
#ifdef FRAM_MODULE
#include "fram.h"
#endif
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
const BYTE byXtal = XTAL;
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void SystemInit( void )
{
di();
// low voltage detect
#ifdef _PIC18
LVDIF = 0;
LVDCON = 0b00011101; // 4.2V
while ( LVDIF )
;
LVDIF = 0;
#endif
// init delay (timer 0)
DelayInit();
// Application's hardware initializations
BoardInit();
// the following inits may alter the app's inits
AdInit();
#ifdef ANALOG_MODULE
AnalogInit();
#endif
#ifdef CLOCK_MODULE
ClockInit();
#endif
#ifdef I2C_MODULE
I2CInit();
#endif
#ifdef SPI_MODULE
SpiInit();
#endif
#ifdef SERIAL_MODULE
SerialInit();
#endif
TimerInit();
#ifdef PERIOD_MODULE
PeriodInit();
#endif
#ifdef PWM_MODULE
PwmInit();
#endif
// Memory devices
#ifdef ATMEL_MODULE
AtmelInit();
#endif
#ifdef FRAM_MODULE
FramInit();
#endif
// application takes care of watchdog
CLRWDT();
// persistent across reset
persist_check(1);
// interrupts
#ifdef INTER_MODULE
InterruptInit();
#endif
}

View File

@ -1,76 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Initialization & Runtime
*----------------------------------------------------------------------------
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _SYSTEM_H_
#define _SYSTEM_H_
/*****************************************************************************
* includes
*****************************************************************************/
#ifdef __linux__
#include "emul.h"
#elif defined(_PIC18)
#include <pic18.h>
#else
#include <pic.h>
#endif
#include "types.h"
// this works out the nitty gritty
#include "config.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#define getXtalFreq() byXtal
#define inPowerFail() bPowerFail
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
extern const BYTE byXtal;
/*****************************************************************************
* global variables
*****************************************************************************/
extern bit bPowerFail;
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void BoardInit( void ); // system specific initialization
extern void SystemInit( void ); // calls board_init and library inits
extern void InterruptInit( void ); // interrupt inits
extern void WatchdogInit( void ); // turn on watchdog
extern void InterruptHandler( void );
extern void PowerfailHandler( void );
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1,187 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Timers
*----------------------------------------------------------------------------
* Timer #1 - Fast clock counter
* Timer #2 - 1 msec software timer
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "timers.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// Timer #1
#ifdef TIMER1_INT
volatile long_dword g_stTimer1 = { 0 };
LIBBANK volatile WORD g_wTimer1High = 0;
#endif
// Timer 2, used for time stamping and msec timing
#ifdef TIMER2_INT
LIBBANK volatile DWORD g_dwTimer2 = 0L;
LIBBANK volatile WORD g_wTimers2[SW_TIMERS] = { 0 };
#endif
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void TimerInit( void )
{
// Timer 1 setup
#ifdef TIMER1_INT
TMR1IE = 1;
#ifdef _PIC18
T1CON = 0b10110001; // 16 bit read of Timer 1
TMR1IP = 0; // low priority
#else
T1CON = 0b00110001;
#endif
PIR1 = 0;
PIR2 = 0;
TMR1L = 0;
TMR1H = 0;
g_wTimer1High = 0;
g_stTimer1.dw = 0L;
#endif
// Timer 2 setup
#ifdef TIMER2_INT
TMR2IE = 1;
#ifdef _PIC18
TMR2IP = 0;
#endif
#if XTAL==40
// pre 1:4, post 1:10 (100us..1ms period)
T2CON = 0b10000101 | ( (10-1) << 3 );
PR2 = 250;
#else
// pre 1:4, post 1:5 (1ms period)
T2CON = 0b00100101;
PR2 = 250;
#endif
TMR2 = 0;
g_dwTimer2 = 0L;
#endif
}
#ifdef _PIC18
void TimerHandler( void )
{
// Timer1 overflow
#ifdef TIMER1_INT
if ( TMR1IF )
{
g_wTimer1High++;
TMR1IF = 0;
}
#endif
// Timer2 interrupt
#ifdef TIMER2_INT
if ( TMR2IF )
{
g_dwTimer2++;
TMR2IF = 0;
#ifdef SW_TIMERS
if ( g_wTimers2[0] )
g_wTimers2[0]--;
#if SW_TIMERS > 1
if ( g_wTimers2[1] )
g_wTimers2[1]--;
#endif
#if SW_TIMERS > 2
if ( g_wTimers2[2] )
g_wTimers2[2]--;
#endif
#if SW_TIMERS > 3
if ( g_wTimers2[3] )
g_wTimers2[3]--;
#endif
#endif
}
#endif
}
#endif
void Timer1Clear( void )
{
#ifdef TIMER1_INT
g_wTimer1High = 0;
TMR1ON = 0;
#ifdef _PIC18
TMR1 = 0;
#else
TMR1H = 0;
TMR1L = 0;
#endif
TMR1ON = 1;
g_stTimer1.dw = 0L;
#endif
}
DWORD Timer1Read( void )
{
#ifdef TIMER1_INT
#ifdef _PIC18
g_stTimer1.w.h = g_wTimer1High; // high first so can check for change
g_stTimer1.w.l = TMR1;
if ( g_stTimer1.w.h != g_wTimer1High )
{
g_stTimer1.w.h = g_wTimer1High;
g_stTimer1.w.l = TMR1;
}
#else
g_stTimer1.w.h = g_wTimer1High; // high first so can check for change
g_stTimer1.b.lh = TMR1H;
g_stTimer1.b.ll = TMR1L;
if ( g_stTimer1.w.h != g_wTimer1High || g_stTimer1.b.lh != TMR1H )
{
g_stTimer1.w.h = g_wTimer1High;
g_stTimer1.b.lh = TMR1H;
g_stTimer1.b.ll = TMR1L;
}
#endif
return g_stTimer1.dw;
#else
return 0L;
#endif
}

View File

@ -1,112 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PIC Timer Interface
*----------------------------------------------------------------------------
* Timer #0 - Used by delay routines (dly_usec.c)
* Timer #1 - Fast clock counter
* Timer #2 - 1 msec software timer
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _TIMERS_H_
#define _TIMERS_H_
/*****************************************************************************
* includes
*****************************************************************************/
// this is application specific
#include "system.h"
#include "types.h"
/*****************************************************************************
* defines
*****************************************************************************/
// Timer #1: 1:8 prescale, Fosc/4 (625000/sec @ 20Mhz, 1250000/sec @ 40Mhz)
#define COUNTER_SEC_TICKS ((XTAL*1000000L)/32L)
#define COUNTER_MSEC_TICKS (COUNTER_SEC_TICKS/1000L)
// Timer #2
#ifndef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC 1000L
#endif
/*****************************************************************************
* macros
*****************************************************************************/
// Timer #1
#ifdef TIMER1_INT
#define Timer1Rd() g_stTimer1.dw
#define Timer1Clr() g_stTimer1.dw=0
#define Timer1Set(V) g_stTimer1.dw=(V)
#define Timer1Ticks() COUNTER_SEC_TICKS
#endif
// Timer #2 (millisecond)
#ifdef TIMER2_INT
#define Timer2Rd() g_dwTimer2
#define Timer2Clr() g_dwTimer2=0
#define Timer2Set(V) g_dwTimer2=(V)
#endif
#ifdef TIMER2_INT
#define clock() g_dwTimer2
#ifdef SW_TIMERS
#define MsecTimerGet(i) g_wTimers2[i]
#define MsecTimerSet(i,d) g_wTimers2[i]=(d)
#endif
#else
#define clock() (Timer1Rd()/COUNTER_MSEC_TICKS)
#endif
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
// Timer #1
#ifdef TIMER1_INT
extern volatile long_dword g_stTimer1;
#endif
// Timer #2
#ifdef TIMER2_INT
LIBBANK extern volatile DWORD g_dwTimer2;
#ifdef SW_TIMERS
LIBBANK extern volatile WORD g_wTimers2[SW_TIMERS];
#endif
#endif
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern void TimerInit( void );
extern void TimerHandler( void );
// timer #1
extern void Timer1Clear( void );
extern DWORD Timer1Read( void );
// timer #2
#ifdef __cpluscplus
}
#endif
#endif

View File

@ -1 +0,0 @@
../include/embtypes.h

View File

@ -1,61 +0,0 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Watchdog Initialization
*----------------------------------------------------------------------------
* Details
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void WatchdogInit( void )
{
// watchdog rate programming?
#ifdef _PIC18
SWDTEN = 1; // unless already programmed in config
#else
OPTION |= 0b00000100;
#endif
}

View File

@ -1,80 +0,0 @@
//****************************************************************************
// Copyright (C) 2007
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "AnalogInputChannel.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
AnalogInputChannel::AnalogInputChannel()
{
}
AnalogInputChannel::AnalogInputChannel(const AnalogInputChannel &copy)
{
}
AnalogInputChannel::~AnalogInputChannel()
{
}
AnalogInputChannel& AnalogInputChannel::operator=(const AnalogInputChannel &rhs)
{
return *this;
}
double AnalogInputChannel::ReadEu( void )
{
long raw;
double data;
raw = ReadRaw();
Raw2Eu( &raw, &data, 1 );
return data;
}

View File

@ -1,62 +0,0 @@
//****************************************************************************
// Copyright (C) 2009
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __AnalogInputChannel__
#define __AnalogInputChannel__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
#include "InputChannel.h"
#include "RawType.h"
#include "VoltType.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class AnalogInputChannel : public InputChannel, public VoltType {
// public data
public:
// protected data
// private data
private:
// static data
// public methods
public:
// constructors
AnalogInputChannel();
AnalogInputChannel(const AnalogInputChannel &copy);
// destructor
virtual ~AnalogInputChannel();
// operators
AnalogInputChannel &operator=(const AnalogInputChannel &rhs);
// public methods
// virtual functions
virtual double ReadEu( void );
// static methods
// private methods
private:
};
#endif

View File

@ -1,78 +0,0 @@
//****************************************************************************
// Copyright (C) 2007
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "AnalogOutputChannel.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
AnalogOutputChannel::AnalogOutputChannel()
{
}
AnalogOutputChannel::AnalogOutputChannel(const AnalogOutputChannel &copy)
{
}
AnalogOutputChannel::~AnalogOutputChannel()
{
}
AnalogOutputChannel& AnalogOutputChannel::operator=(const AnalogOutputChannel &rhs)
{
return *this;
}
void AnalogOutputChannel::WriteEu( double eu )
{
long raw;
Eu2Raw( &eu, &raw, 1 );
WriteRaw( raw );
}

View File

@ -1,62 +0,0 @@
//****************************************************************************
// Copyright (C) 2009
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __AnalogOutputChannel__
#define __AnalogOutputChannel__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
#include "OutputChannel.h"
#include "RawType.h"
#include "VoltType.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class AnalogOutputChannel : public OutputChannel, public VoltType {
// public data
public:
// protected data
// private data
private:
// static data
// public methods
public:
// constructors
AnalogOutputChannel();
AnalogOutputChannel(const AnalogOutputChannel &copy);
// destructor
virtual ~AnalogOutputChannel();
// operators
AnalogOutputChannel &operator=(const AnalogOutputChannel &rhs);
// public methods
// virtual functions
virtual void WriteEu( double eu );
// static methods
// private methods
private:
};
#endif

View File

@ -1,77 +0,0 @@
//****************************************************************************
// Copyright (C) 2007
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "BaseChannel.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
BaseChannel::BaseChannel()
{
Channel = 0;
Resolution = 0;
}
BaseChannel::BaseChannel(const BaseChannel &copy)
{
Channel = copy.Channel;
Resolution = copy.Resolution;
}
BaseChannel::~BaseChannel()
{
}
BaseChannel& BaseChannel::operator=(const BaseChannel &rhs)
{
this->Channel = rhs.Channel;
this->Resolution = rhs.Resolution;
return *this;
}

View File

@ -1,70 +0,0 @@
//****************************************************************************
// Copyright (C) 2009
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __BaseChannel__
#define __BaseChannel__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
#include "Comedi.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class BaseChannel {
// public data
public:
// protected data
protected:
int Device;
int SubDevice;
int Channel;
int Resolution; // 8, 12, 16, 24, 32 bits
// private data
private:
// static data
// public methods
public:
// constructors
BaseChannel();
BaseChannel(const BaseChannel &copy);
// destructor
virtual ~BaseChannel();
// operators
BaseChannel &operator=(const BaseChannel &rhs);
// public methods
void SetDevice( int dev, int sub=0, int chan=0 ) {Device=dev;SubDevice=sub;Channel=chan;};
comedi_t *GetDevice(void) { return Comedi::GetDevice(Device); };
void SetChannel( int chan ) { Channel = chan; };
int GetChannel( void ) { return Channel; };
void SetResolution( int bits ) { Resolution = bits; };
int GetResolution( void ) { return Resolution; };
// virtual functions
// static methods
// private methods
private:
};
#endif

View File

@ -1,62 +0,0 @@
//****************************************************************************
// Copyright (C) 2007
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "BaseDevice.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
BaseDevice::BaseDevice()
{
}
BaseDevice::~BaseDevice()
{
}

View File

@ -1,54 +0,0 @@
//****************************************************************************
// Copyright (C) 2009
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __BaseDevice__
#define __BaseDevice__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class BaseDevice {
// public data
public:
std::string Name;
// protected data
// private data
private:
// static data
// public methods
public:
// constructors
BaseDevice();
// destructor
virtual ~BaseDevice();
// public methods
// virtual functions
// static methods
// private methods
private:
};
#endif

View File

@ -1,75 +0,0 @@
//****************************************************************************
// Copyright (C) 2007
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "BaseSignal.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
BaseSignal::BaseSignal()
{
}
BaseSignal::BaseSignal(const BaseSignal &copy)
{
Name = copy.Name;
Units = copy.Units;
}
BaseSignal::~BaseSignal()
{
}
BaseSignal& BaseSignal::operator=(const BaseSignal &rhs)
{
this->Name = rhs.Name;
this->Units = rhs.Units;
return *this;
}

View File

@ -1,59 +0,0 @@
//****************************************************************************
// Copyright (C) 2009
// ProbeStar Telematics
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __BaseSignal__
#define __BaseSignal__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
// based on .dbc data
/* c class definitions ******************************************************/
class BaseSignal {
// public data
public:
std::string Name; // Signal Name
std::string Units; // Signal Units
// private data
private:
// static data
// public methods
public:
// constructors
BaseSignal();
BaseSignal(const BaseSignal &BaseSignal);
// destructor
virtual ~BaseSignal();
// operators
BaseSignal &operator=(const BaseSignal &rhs);
// virtual functions
// public methods
// static methods
// private methods
private:
};
#endif

Some files were not shown because too many files have changed in this diff Show More