mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Initial Arduino IDE based on Processing.
This commit is contained in:
21
build/shared/lib/avrlib/rsl/CVS/Entries
Normal file
21
build/shared/lib/avrlib/rsl/CVS/Entries
Normal file
@ -0,0 +1,21 @@
|
||||
/avrcore.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/avrcore.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/edp.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/edp.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/edpaddr.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/edpdebug.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/edpdebug.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/edpdefs.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/erp.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/erp.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/input.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/input.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/mitelgps.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/mitelgps.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/radiolinx.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/radiolinx.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/radiot96.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/radiot96.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/satmb.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
/satmb.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
|
||||
D
|
1
build/shared/lib/avrlib/rsl/CVS/Repository
Normal file
1
build/shared/lib/avrlib/rsl/CVS/Repository
Normal file
@ -0,0 +1 @@
|
||||
Arduino/wiringlite/avrlib/rsl
|
1
build/shared/lib/avrlib/rsl/CVS/Root
Normal file
1
build/shared/lib/avrlib/rsl/CVS/Root
Normal file
@ -0,0 +1 @@
|
||||
:ext:mbanzi@cvs.arduino.berlios.de:/cvsroot/arduino
|
102
build/shared/lib/avrlib/rsl/avrcore.c
Executable file
102
build/shared/lib/avrlib/rsl/avrcore.c
Executable file
@ -0,0 +1,102 @@
|
||||
/*! \file avrcore.c \brief AVR-Core Board Driver Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'avrcore.c'
|
||||
// Title : AVR-Core Board Driver Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2004
|
||||
// Created : 2004.10.1
|
||||
// Revised : 2004.10.1
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
|
||||
#include <avr/signal.h> // include "signal" names (interrupt names)
|
||||
#include <avr/interrupt.h> // include interrupt support
|
||||
|
||||
#include "global.h" // include our global settings
|
||||
#include "avrcore.h"
|
||||
|
||||
// globals
|
||||
u08 AvrcoreLatch;
|
||||
|
||||
// functions
|
||||
void avrcoreInit(void)
|
||||
{
|
||||
// initialize ports to input with pullup
|
||||
// (this is done to avoid contentions and input-pin oscillation)
|
||||
outb(DDRA, 0x00);
|
||||
outb(DDRB, 0x00);
|
||||
outb(DDRC, 0x00);
|
||||
outb(DDRD, 0x00);
|
||||
outb(DDRE, 0x00);
|
||||
outb(DDRF, 0x00);
|
||||
outb(PORTA, 0xFF);
|
||||
outb(PORTB, 0xFF);
|
||||
outb(PORTC, 0xFF);
|
||||
outb(PORTD, 0xFF);
|
||||
outb(PORTE, 0xFF);
|
||||
outb(PORTF, 0xFF);
|
||||
// turn on RAM interface
|
||||
sbi(MCUCR, SRE);
|
||||
// initialize RAM page
|
||||
avrcoreSetRamPage(0);
|
||||
// initialize LEDs
|
||||
avrcoreSetLeds(0);
|
||||
// set serial power to on by default
|
||||
avrcoreSetSerialPortPower(1);
|
||||
}
|
||||
|
||||
void avrcoreSetRamPage(u08 page)
|
||||
{
|
||||
// update latch state
|
||||
AvrcoreLatch &= ~AVRCORELATCH_ADDRMASK;
|
||||
AvrcoreLatch |= page & AVRCORELATCH_ADDRMASK;
|
||||
// write new latch state to latch
|
||||
AVRCORELATCH = AvrcoreLatch;
|
||||
}
|
||||
|
||||
void avrcoreSetLeds(u08 leds)
|
||||
{
|
||||
// NOTE: LEDs are negative-logic (active-low)
|
||||
// update latch state
|
||||
AvrcoreLatch |= AVRCORELATCH_LEDMASK;
|
||||
AvrcoreLatch &= ~(leds<<4);
|
||||
// write new latch state to latch
|
||||
AVRCORELATCH = AvrcoreLatch;
|
||||
}
|
||||
|
||||
void avrcoreSetLedsOn(u08 leds)
|
||||
{
|
||||
// NOTE: LEDs are negative-logic (active-low)
|
||||
// update latch state to turn on inidicated leds
|
||||
AvrcoreLatch &= ~(leds<<4);
|
||||
// write new latch state to latch
|
||||
AVRCORELATCH = AvrcoreLatch;
|
||||
}
|
||||
|
||||
void avrcoreSetLedsOff(u08 leds)
|
||||
{
|
||||
// NOTE: LEDs are negative-logic (active-low)
|
||||
// update latch state to turn off inidicated leds
|
||||
AvrcoreLatch |= (leds<<4);
|
||||
// write new latch state to latch
|
||||
AVRCORELATCH = AvrcoreLatch;
|
||||
}
|
||||
|
||||
void avrcoreSetSerialPortPower(u08 on)
|
||||
{
|
||||
// this function simply manipulates LED3/power control
|
||||
if(on)
|
||||
AvrcoreLatch &= ~(0x80);
|
||||
else
|
||||
AvrcoreLatch |= (0x80);
|
||||
// write new latch state to latch
|
||||
AVRCORELATCH = AvrcoreLatch;
|
||||
}
|
60
build/shared/lib/avrlib/rsl/avrcore.h
Executable file
60
build/shared/lib/avrlib/rsl/avrcore.h
Executable file
@ -0,0 +1,60 @@
|
||||
/*! \file avrcore.h \brief AVR-Core Board Driver Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'avrcore.h'
|
||||
// Title : AVR-Core Board Driver Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2004
|
||||
// Created : 2004.10.1
|
||||
// Revised : 2004.10.1
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef AVRCORE_H
|
||||
#define AVRCORE_H
|
||||
|
||||
// defines and typedefs
|
||||
#define AVRCORELATCH (*((unsigned char*)0x4000))
|
||||
#define AVRCORELATCH_ADDRMASK 0x0F
|
||||
#define AVRCORELATCH_LEDMASK 0xF0
|
||||
|
||||
// functions
|
||||
|
||||
//! Initialize AVRCore hardware
|
||||
void avrcoreInit(void);
|
||||
|
||||
//! Set the current external RAM page
|
||||
// The AVRCore on-board external RAM is typically 512KBytes.
|
||||
// The RAM is memory-mapped into the 32KByte address space from
|
||||
// 0x8000-0xFFFF, and must therefore be accessed in pages (32KB chunks).
|
||||
// Use this function to select which of the 16 (0-15) 32KByte pages
|
||||
// you wish to access.
|
||||
void avrcoreSetRamPage(u08 page);
|
||||
|
||||
//! Set the state of the four LEDs on AVRCore
|
||||
// leds bit0 => LED1 (0=off, 1=on)
|
||||
// leds bit1 => LED2 (0=off, 1=on)
|
||||
// leds bit2 => LED3 (0=off, 1=on)
|
||||
// leds bit3 => LED4 (0=off, 1=on)
|
||||
void avrcoreSetLeds(u08 leds);
|
||||
|
||||
//! Turn on selected LEDs
|
||||
// '0' bit = no change
|
||||
// '1' bit = turn on
|
||||
void avrcoreSetLedsOn(u08 leds);
|
||||
|
||||
//! Turn off selected LEDs
|
||||
// '0' bit = no change
|
||||
// '1' bit = turn off
|
||||
void avrcoreSetLedsOff(u08 leds);
|
||||
|
||||
//! Set on/off power setting of AVRCore serial port
|
||||
// (0=off, 1=on)
|
||||
void avrcoreSetSerialPortPower(u08 on);
|
||||
|
||||
#endif
|
495
build/shared/lib/avrlib/rsl/edp.c
Executable file
495
build/shared/lib/avrlib/rsl/edp.c
Executable file
@ -0,0 +1,495 @@
|
||||
/*! \file edp.c \brief Emerald Data Protocol System. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'edp.c'
|
||||
// Title : Emerald Data Protocol System
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.07.01
|
||||
// Revised : 2003.07.21
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
|
||||
#include <avr/signal.h> // include "signal" names (interrupt names)
|
||||
#include <avr/interrupt.h> // include interrupt support
|
||||
#include <avr/pgmspace.h> // include program-space support
|
||||
|
||||
#include "global.h" // include our global settings
|
||||
#include "i2c.h" // include I2C support
|
||||
#include "rprintf.h" // include printf function library
|
||||
|
||||
#include "edp.h"
|
||||
|
||||
// globals
|
||||
// EDP master/command: response code and reply buffer
|
||||
u08 EdpCommandResponseCode;
|
||||
//u08 EdpCommandReplyLength;
|
||||
u08 EdpCommandReplyBuffer[EDP_REPLY_BUFFER_SIZE];
|
||||
u08 EdpCommandReplyChecksum;
|
||||
// EDP slave: response code and reply buffer
|
||||
u08 EdpSlaveResponseCode;
|
||||
u08 EdpSlaveReplyLength;
|
||||
u08 EdpSlaveReplyBuffer[EDP_REPLY_BUFFER_SIZE];
|
||||
// EDP slave request handler function pointer
|
||||
EdpSlaveHandlerFuncType edpSlaveHandlerFunc;
|
||||
|
||||
// functions
|
||||
void edpInit(void)
|
||||
{
|
||||
// initialize i2c interface and function library
|
||||
i2cInit();
|
||||
// set i2c bit rate to 30KHz
|
||||
i2cSetBitrate(30);
|
||||
// set the Slave Receive Handler function
|
||||
// (this function will run whenever a master somewhere else on the bus
|
||||
// writes data to us as a slave)
|
||||
i2cSetSlaveReceiveHandler( edpSlaveReceiveService );
|
||||
// set the Slave Transmit Handler function
|
||||
// (this function will run whenever a master somewhere else on the bus
|
||||
// attempts to read data from us as a slave)
|
||||
i2cSetSlaveTransmitHandler( edpSlaveTransmitService );
|
||||
}
|
||||
|
||||
void edpSetSlaveHandler(EdpSlaveHandlerFuncType edpSlaveHandlerFunction)
|
||||
{
|
||||
edpSlaveHandlerFunc = edpSlaveHandlerFunction;
|
||||
}
|
||||
|
||||
// ************ EDP Master operations ************
|
||||
u08 edpSendCommand(u08 deviceAddr, u08 cmdLength, EdpCommand* edpCommand)
|
||||
{
|
||||
EdpReply* edpCommandReply = (EdpReply*)EdpCommandReplyBuffer;
|
||||
u08* sendData;
|
||||
u08* replyData;
|
||||
u08 replyLength;
|
||||
u08 checksum;
|
||||
|
||||
// initialize response variables
|
||||
edpCommandReply->Length = 0;
|
||||
EdpCommandReplyChecksum = 0;
|
||||
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("\r\nBegin EdpSendCommand, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// disable TWI interrupt
|
||||
cbi(TWCR, TWIE);
|
||||
|
||||
// clear TWI interface
|
||||
//outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK));
|
||||
|
||||
// send start condition
|
||||
i2cSendStart();
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Start, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// send device address with write
|
||||
i2cSendByte( (deviceAddr&0xFE) );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Device Address+Write, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// check if device is present and live
|
||||
if( i2cGetStatus() != TW_MT_SLA_ACK)
|
||||
{
|
||||
// device did not ACK it's address, command will not continue
|
||||
// transmit stop condition
|
||||
// leave with TWEA on for slave receiving
|
||||
i2cSendStop();
|
||||
while( !(inb(TWCR) & BV(TWSTO)) );
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("No Device!, Sent Stop, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
// enable TWI interrupt
|
||||
sbi(TWCR, TWIE);
|
||||
// return error
|
||||
return EDP_COMMAND_NODEV;
|
||||
}
|
||||
|
||||
// send data
|
||||
sendData = (u08*)edpCommand;
|
||||
checksum = 0;
|
||||
while(cmdLength)
|
||||
{
|
||||
i2cSendByte( *sendData );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Data, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
checksum += *sendData++;
|
||||
cmdLength--;
|
||||
}
|
||||
|
||||
// send the checksum
|
||||
i2cSendByte( ~checksum );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Checksum, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// send repeated start condition
|
||||
i2cSendStart();
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Repeated Start, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// send device address with read
|
||||
i2cSendByte( deviceAddr|0x01 );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Device Address+Read, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// read response code, return NACK
|
||||
i2cReceiveByte(FALSE);
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Read Data, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
EdpCommandResponseCode = i2cGetReceivedByte();
|
||||
|
||||
if(EdpCommandResponseCode==EDP_RESP_DATA_REPLY)
|
||||
{
|
||||
// a data reply is being sent
|
||||
|
||||
// send repeated start condition
|
||||
i2cSendStart();
|
||||
i2cWaitForComplete();
|
||||
|
||||
// send device address with read
|
||||
i2cSendByte( deviceAddr|0x01 );
|
||||
i2cWaitForComplete();
|
||||
|
||||
// get length, return ACK
|
||||
i2cReceiveByte(TRUE);
|
||||
i2cWaitForComplete();
|
||||
edpCommandReply->Length = i2cGetReceivedByte();
|
||||
// set temp variables
|
||||
replyLength = edpCommandReply->Length;
|
||||
replyData = edpCommandReply->Data;
|
||||
|
||||
// get data, return ACKs
|
||||
// preset checksum with the datalength byte
|
||||
checksum = replyLength;
|
||||
while(replyLength > 1)
|
||||
{
|
||||
i2cReceiveByte(TRUE); // receive data byte and return ACK
|
||||
i2cWaitForComplete();
|
||||
*replyData = i2cGetReceivedByte();
|
||||
checksum += *replyData++;
|
||||
replyLength--;
|
||||
}
|
||||
|
||||
// get last data (actually the checksum), return NACK (last-byte signal)
|
||||
i2cReceiveByte(FALSE);
|
||||
i2cWaitForComplete();
|
||||
*replyData = i2cGetReceivedByte();
|
||||
// add received checksum+1 to our checksum, the result should be zero
|
||||
checksum += (*replyData) + 1;
|
||||
// save the reply checksum
|
||||
EdpCommandReplyChecksum = checksum;
|
||||
}
|
||||
|
||||
// transmit stop condition
|
||||
// leave with TWEA on for slave receiving
|
||||
i2cSendStop();
|
||||
while( !(inb(TWCR) & BV(TWSTO)) );
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Stop, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// enable TWI interrupt
|
||||
sbi(TWCR, TWIE);
|
||||
|
||||
return EDP_COMMAND_OK;
|
||||
}
|
||||
|
||||
// get the response code and reply from last command
|
||||
u08 edpGetCommandReply(u08* responseCode, EdpReply** edpReply)
|
||||
{
|
||||
u08 retval=EDP_REPLY_OK;
|
||||
|
||||
// get the response code from last command
|
||||
*responseCode = EdpCommandResponseCode;
|
||||
// get the reply from last command
|
||||
*edpReply = (EdpReply*)EdpCommandReplyBuffer;
|
||||
|
||||
// check response code
|
||||
if(EdpCommandResponseCode == EDP_RESP_DATA_REPLY)
|
||||
{
|
||||
// there was a reply, check the checksum
|
||||
// if it's non-zero, data corruption is present
|
||||
if(EdpCommandReplyChecksum)
|
||||
retval = EDP_REPLY_BADCHKSUM;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
u08 edpSendCommand(u08 deviceAddr, u08 sendLength, u08* sendData)
|
||||
{
|
||||
u08* replyData = EdpCommandReplyBuffer;
|
||||
u08 replyLength;
|
||||
u08 checksum;
|
||||
|
||||
// initialize response variables
|
||||
EdpCommandReplyLength = 0;
|
||||
EdpCommandReplyChecksum = 0;
|
||||
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("\r\nBegin EdpSendCommand, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// disable TWI interrupt
|
||||
cbi(TWCR, TWIE);
|
||||
|
||||
// clear TWI interface
|
||||
//outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK));
|
||||
|
||||
// send start condition
|
||||
i2cSendStart();
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Start, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// send device address with write
|
||||
i2cSendByte( (deviceAddr&0xFE) );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Device Address+Write, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// check if device is present and live
|
||||
if( i2cGetStatus() != TW_MT_SLA_ACK)
|
||||
{
|
||||
// device did not ACK it's address, command will not continue
|
||||
// transmit stop condition
|
||||
// leave with TWEA on for slave receiving
|
||||
i2cSendStop();
|
||||
while( !(inb(TWCR) & BV(TWSTO)) );
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("No Device!, Sent Stop, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
// enable TWI interrupt
|
||||
sbi(TWCR, TWIE);
|
||||
// return error
|
||||
return EDP_COMMAND_NODEV;
|
||||
}
|
||||
|
||||
// send data
|
||||
checksum = 0;
|
||||
while(sendLength)
|
||||
{
|
||||
i2cSendByte( *sendData );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Data, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
checksum += *sendData++;
|
||||
sendLength--;
|
||||
}
|
||||
|
||||
// send the checksum
|
||||
i2cSendByte( ~checksum );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Checksum, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// send repeated start condition
|
||||
i2cSendStart();
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Repeated Start, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// send device address with read
|
||||
i2cSendByte( deviceAddr|0x01 );
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Device Address+Read, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// read response code, return NACK
|
||||
i2cReceiveByte(FALSE);
|
||||
i2cWaitForComplete();
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Read Data, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
EdpCommandResponseCode = i2cGetReceivedByte();
|
||||
|
||||
if(EdpCommandResponseCode==EDP_RESP_DATA_REPLY)
|
||||
{
|
||||
// a data reply is being sent
|
||||
|
||||
// send repeated start condition
|
||||
i2cSendStart();
|
||||
i2cWaitForComplete();
|
||||
|
||||
// send device address with read
|
||||
i2cSendByte( deviceAddr|0x01 );
|
||||
i2cWaitForComplete();
|
||||
|
||||
// get length, return ACK
|
||||
i2cReceiveByte(TRUE);
|
||||
i2cWaitForComplete();
|
||||
replyLength = i2cGetReceivedByte();
|
||||
EdpCommandReplyLength = replyLength;
|
||||
|
||||
// get data, return ACKs
|
||||
// preset checksum with the datalength byte
|
||||
checksum = replyLength;
|
||||
while(replyLength > 1)
|
||||
{
|
||||
i2cReceiveByte(TRUE); // receive data byte and return ACK
|
||||
i2cWaitForComplete();
|
||||
*replyData = i2cGetReceivedByte();
|
||||
checksum += *replyData++;
|
||||
replyLength--;
|
||||
}
|
||||
|
||||
// get last data (actually the checksum), return NACK (last-byte signal)
|
||||
i2cReceiveByte(FALSE);
|
||||
i2cWaitForComplete();
|
||||
*replyData = i2cGetReceivedByte();
|
||||
// add received checksum+1 to our checksum, the result should be zero
|
||||
checksum += (*replyData) + 1;
|
||||
// save the reply checksum
|
||||
EdpCommandReplyChecksum = checksum;
|
||||
}
|
||||
|
||||
// transmit stop condition
|
||||
// leave with TWEA on for slave receiving
|
||||
i2cSendStop();
|
||||
while( !(inb(TWCR) & BV(TWSTO)) );
|
||||
#ifdef EDP_DEBUG
|
||||
rprintf("Sent Stop, TWSR:0x%x\r\n",inb(TWSR));
|
||||
#endif
|
||||
|
||||
// enable TWI interrupt
|
||||
sbi(TWCR, TWIE);
|
||||
|
||||
return EDP_COMMAND_OK;
|
||||
}
|
||||
|
||||
u08 edpGetCommandReply(u08* responseCode, u08* replyLength, u08** replyData)
|
||||
{
|
||||
u08 retval=EDP_REPLY_OK;
|
||||
|
||||
// get the response code and reply data from last command
|
||||
*responseCode = EdpCommandResponseCode;
|
||||
// get the reply length from last command
|
||||
*replyLength = EdpCommandReplyLength;
|
||||
// get the reply data from last command
|
||||
*replyData = EdpCommandReplyBuffer;
|
||||
|
||||
// check response code
|
||||
if(EdpCommandResponseCode == EDP_RESP_DATA_REPLY)
|
||||
{
|
||||
// there was a reply, check the checksum
|
||||
// if it's non-zero, data corruption is present
|
||||
if(EdpCommandReplyChecksum)
|
||||
retval = EDP_REPLY_BADCHKSUM;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
*/
|
||||
|
||||
// ************ EDP Slave operations ************
|
||||
|
||||
// this function will run when a master somewhere else on the bus
|
||||
// addresses us and wishes to write data to us
|
||||
void edpSlaveReceiveService(u08 receiveDataLength, u08* receiveData)
|
||||
{
|
||||
u08 i,checksum;
|
||||
|
||||
// initialize the reply length from this command
|
||||
EdpSlaveReplyLength = 0;
|
||||
// verify the checksum
|
||||
// initialize the checksum with 1
|
||||
checksum = 0x01;
|
||||
// sum all the data in the packet and the data's checksum
|
||||
for(i=0; i<receiveDataLength; i++)
|
||||
{
|
||||
checksum += receiveData[i];
|
||||
}
|
||||
// if the checksum is non-zero, then the data is corrupt
|
||||
if(checksum)
|
||||
{
|
||||
// set reply code
|
||||
// [FIX] which should it be?
|
||||
EdpSlaveResponseCode = EDP_RESP_DATA_CHK_ERROR;
|
||||
//EdpSlaveResponseCode = EDP_RESP_CMD_CHK_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
// make an EDP command pointer to the received I2C data
|
||||
EdpCommand* edpCommand = (EdpCommand*)receiveData;
|
||||
|
||||
// if a slave handler is defined
|
||||
if(edpSlaveHandlerFunc)
|
||||
{
|
||||
// then use it
|
||||
EdpSlaveResponseCode = edpSlaveHandlerFunc(
|
||||
receiveDataLength, edpCommand,
|
||||
EDP_REPLY_BUFFER_SIZE, (EdpReply*)EdpSlaveReplyBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise reply with unknown command
|
||||
EdpSlaveResponseCode = EDP_RESP_UNKWN_CMD;
|
||||
}
|
||||
}
|
||||
|
||||
// this function will run when a master somewhere else on the bus
|
||||
// addresses us and wishes to read data from us
|
||||
u08 edpSlaveTransmitService(u08 transmitDataLengthMax, u08* transmitData)
|
||||
{
|
||||
u08 i;
|
||||
u08 checksum;
|
||||
u08 transmitDataLength = 0;
|
||||
|
||||
EdpReply* edpReply = (EdpReply*)EdpSlaveReplyBuffer;
|
||||
|
||||
if(EdpSlaveResponseCode)
|
||||
{
|
||||
// reply code is non-zero, we must send it
|
||||
*transmitData = EdpSlaveResponseCode;
|
||||
transmitDataLength = 1;
|
||||
// reset the reply code to flag that we've sent it
|
||||
EdpSlaveResponseCode = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reply code already sent, now send data (if any)
|
||||
// copy length of reply to transmit buffer (+1 for checksum)
|
||||
*transmitData++ = edpReply->Length+1;
|
||||
// initialize checksum
|
||||
checksum = edpReply->Length+1;
|
||||
// copy reply buffer to the transmit buffer
|
||||
for(i=0; i<edpReply->Length; i++)
|
||||
{
|
||||
*transmitData++ = edpReply->Data[i];
|
||||
checksum += edpReply->Data[i];
|
||||
}
|
||||
// copy checksum to transmit buffer
|
||||
*transmitData++ = ~checksum;
|
||||
// set number of bytes to transmit
|
||||
transmitDataLength = edpReply->Length+2;
|
||||
}
|
||||
|
||||
// return number of bytes written to transmit buffer
|
||||
return transmitDataLength;
|
||||
}
|
68
build/shared/lib/avrlib/rsl/edp.h
Executable file
68
build/shared/lib/avrlib/rsl/edp.h
Executable file
@ -0,0 +1,68 @@
|
||||
/*! \file edp.h \brief Emerald Data Protocol System. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'edp.h'
|
||||
// Title : Emerald Data Protocol System
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.07.01
|
||||
// Revised : 2003.07.21
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef EDP_H
|
||||
#define EDP_H
|
||||
|
||||
#include "edpdefs.h"
|
||||
|
||||
// defines
|
||||
//#define EDP_DEBUG
|
||||
// edp reply buffer size
|
||||
#ifndef EDP_REPLY_BUFFER_SIZE
|
||||
#define EDP_REPLY_BUFFER_SIZE 128
|
||||
#endif
|
||||
// edpSendCommand return values
|
||||
#define EDP_COMMAND_OK 0
|
||||
#define EDP_COMMAND_NODEV 1
|
||||
// edpGetCommandReply return values
|
||||
#define EDP_REPLY_OK 0
|
||||
#define EDP_REPLY_BADCHKSUM 1
|
||||
|
||||
// structs and typedefs
|
||||
typedef struct
|
||||
{
|
||||
u08 SrcAddr;
|
||||
u08 Command;
|
||||
u08 Data[];
|
||||
} EdpCommand;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u08 Length;
|
||||
u08 Data[];
|
||||
} EdpReply;
|
||||
|
||||
// typedefs
|
||||
typedef u08 (*EdpSlaveHandlerFuncType)(u08 edpCmdLength, EdpCommand* edpCmd,
|
||||
u08 edpReplyLengthMax, EdpReply* edpReply);
|
||||
|
||||
// functions
|
||||
void edpInit(void);
|
||||
void edpSetSlaveHandler(EdpSlaveHandlerFuncType edpSlaveHandlerFunction);
|
||||
|
||||
// ************ EDP Master operations ************
|
||||
u08 edpSendCommand(u08 deviceAddr, u08 cmdLength, EdpCommand* edpCommand);
|
||||
u08 edpGetCommandReply(u08* responseCode, EdpReply** edpReply);
|
||||
//u08 edpSendCommand(u08 deviceAddr, u08 sendLength, u08* sendData);
|
||||
//u08 edpGetCommandReply(u08* responseCode, u08* replyLength, u08** replyData);
|
||||
|
||||
// ************ EDP Slave operations ************
|
||||
void edpSlaveReceiveService(u08 receiveDataLength, u08* receiveData);
|
||||
u08 edpSlaveTransmitService(u08 transmitDataLengthMax, u08* transmitData);
|
||||
|
||||
#endif
|
75
build/shared/lib/avrlib/rsl/edpaddr.h
Executable file
75
build/shared/lib/avrlib/rsl/edpaddr.h
Executable file
@ -0,0 +1,75 @@
|
||||
/*! \file edpaddr.h \brief Emerald Satellite EDP/I2C Bus Addresses. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'edpaddr.h'
|
||||
// Title : Emerald Satellite EDP/I2C Bus Addresses
|
||||
// Author : Bryan Palmintier & Pascal Stang - Copyright (C) 2003
|
||||
// Created : 09/08/2003 by PS
|
||||
// Revised : 11/10/2003 by BP
|
||||
// Version : 0.9
|
||||
// Target MCU : Any
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef EDPADDR_H
|
||||
#define EDPADDR_H
|
||||
|
||||
// The 8 bits of an EDP address byte breakdown as follows:
|
||||
// b0: R/W bit (1=read, 0=write)
|
||||
// b1-4: subsystem address (16 availible)
|
||||
// b5-7: satellite network mask (up to 7 unique networks with 1 reserved by I2C)
|
||||
// The ground station is a special case which uses 1110xxxx
|
||||
#define EDPNET_MASK 0xE0 // mask for satellite/ground networks
|
||||
#define EDPADDR_MASK 0x1E // mask for subsystem addresses
|
||||
|
||||
// Satellite network addresses
|
||||
#define EDPNET_SAT_A 0x00 // EM-1
|
||||
#define EDPNET_SAT_B 0x20 // EM-2
|
||||
#define EDPNET_SAT_C 0x40 // EM-3
|
||||
#define EDPNET_SAT_D 0x60 // EM-4
|
||||
#define EDPNET_SAT_E 0x80 // OK-1
|
||||
#define EDPNET_SAT_F 0xA0 // OK-2
|
||||
#define EDPNET_SAT_G 0xC0
|
||||
|
||||
// Ground Station network address
|
||||
// NOTE: all devices on this network must maintain b4=0
|
||||
// or risk problems with 10bit I2C addressing
|
||||
#define EDPNET_GROUND 0xE0
|
||||
|
||||
// Test subsystem address
|
||||
// Note: it is OK to use these susbsystem addresses with the EDPADDR_GROUND mask
|
||||
#define EDPADDR_TEST 0x02 // generic test address (LEDs etc)
|
||||
#define EDPADDR_GROUND 0x04 // address for ground testing
|
||||
|
||||
// Subsystem addresses
|
||||
// "Core" subsystems, those found on all satellites, DO NOT EDIT
|
||||
// Note: it is OK to use these subsystem addresses with the EDPADDR_GROUND mask
|
||||
#define EDPADDR_COMM 0x06
|
||||
#define EDPADDR_DALMAST 0x08
|
||||
#define EDPADDR_SCHED 0x0A
|
||||
#define EDPADDR_EXPSYS 0x0C
|
||||
#define EDPADDR_ISCOMM 0x0E
|
||||
|
||||
// "Common" subsystems, those found on many satellites, DO NOT EDIT
|
||||
// Note: it is NOT OK to use these subsystem addresses with the EDPADDR_GROUND mask
|
||||
#define EDPADDR_GPS 0x10
|
||||
#define EDPADDR_TORQUER 0x12
|
||||
#define EDPADDR_MECH 0x14
|
||||
|
||||
// Mission Specific subsystems, EDIT AS NEEDED
|
||||
// Note: it is NOT OK to use these subsystem addresses with the EDPADDR_GROUND mask
|
||||
#define EDPADDR_ODDSS 0x16
|
||||
#define EDPADDR_ULTRAWB 0x18
|
||||
#define EDPADDR_TETHER 0x1A
|
||||
|
||||
|
||||
// As part of the I2C protocol 000000000 is reserved for general calls and
|
||||
// all 1111xxxx are reserved for 10 bit addressing
|
||||
#define EDPADDR_RESERVED_GENCALL 0x00 // reserved by I2C for general call address
|
||||
#define EDPADDR_RESERVED_10BIT 0xF0 // reserved by I2C for 10bit addressing
|
||||
|
||||
#endif
|
191
build/shared/lib/avrlib/rsl/edpdebug.c
Executable file
191
build/shared/lib/avrlib/rsl/edpdebug.c
Executable file
@ -0,0 +1,191 @@
|
||||
/*! \file edpdebug.c \brief Emerald Data Protocol Debug Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'edpdebug.c'
|
||||
// Title : Emerald Data Protocol Debug Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.09.20
|
||||
// Revised : 2003.09.20
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
|
||||
#include <avr/signal.h> // include "signal" names (interrupt names)
|
||||
#include <avr/interrupt.h> // include interrupt support
|
||||
#include <avr/pgmspace.h> // include program-space support
|
||||
|
||||
#include "global.h" // include our global settings
|
||||
#include "rprintf.h" // include printf function library
|
||||
#include "debug.h" // include debug helper library
|
||||
#include "input.h" // include user-input functions
|
||||
|
||||
#include "edp.h"
|
||||
#include "edpdebug.h"
|
||||
|
||||
// globals
|
||||
|
||||
// functions
|
||||
|
||||
void edpDisplayCommand(u08 length, EdpCommand* edpCommand)
|
||||
{
|
||||
// print source and command char
|
||||
rprintf("EDP SrcAddr: 0x%x Cmd: 0x%x '%c'\r\n",
|
||||
edpCommand->SrcAddr,
|
||||
edpCommand->Command, edpCommand->Command);
|
||||
if(length-2)
|
||||
{
|
||||
// print data
|
||||
rprintf("Data:\r\n");
|
||||
debugPrintHexTable(length-2, edpCommand->Data);
|
||||
}
|
||||
}
|
||||
|
||||
void edpDisplayReply(u08 response, EdpReply* edpReply)
|
||||
{
|
||||
u08 i;
|
||||
u08 checksum;
|
||||
|
||||
// display response
|
||||
rprintf("EDP Response: 0x%x '%c'\r\n",response,response);
|
||||
|
||||
// if data was received
|
||||
if(response==EDP_RESP_DATA_REPLY)
|
||||
{
|
||||
// do checksum on reply
|
||||
checksum = edpReply->Length;
|
||||
for(i=0; i<(edpReply->Length-1); i++)
|
||||
{
|
||||
checksum += edpReply->Data[i];
|
||||
}
|
||||
checksum = ~checksum;
|
||||
// print message
|
||||
rprintf("EDP Reply: ");
|
||||
// show data received
|
||||
rprintf("Length: 0x%x ",edpReply->Length);
|
||||
rprintf("RxChksum=0x%x MyChksum=0x%x",edpReply->Data[edpReply->Length-1], checksum);
|
||||
rprintfCRLF();
|
||||
rprintf("Data:\r\n");
|
||||
debugPrintHexTable((edpReply->Length-1), edpReply->Data);
|
||||
rprintfCRLF();
|
||||
}
|
||||
}
|
||||
/*
|
||||
void edpDisplayReplyOld(u08 response, u08 replyLength, u08* replyData)
|
||||
{
|
||||
u08 i;
|
||||
u08 checksum;
|
||||
|
||||
// display response
|
||||
rprintf("EDP Response: 0x%x '%c'\r\n",response,response);
|
||||
|
||||
// if data was received
|
||||
if(response==EDP_RESP_DATA_REPLY)
|
||||
{
|
||||
// do checksum on reply
|
||||
checksum = replyLength;
|
||||
for(i=0; i<(replyLength-1); i++)
|
||||
{
|
||||
checksum += replyData[i];
|
||||
}
|
||||
checksum = ~checksum;
|
||||
// print message
|
||||
rprintf("EDP Reply: ");
|
||||
// show data received
|
||||
rprintf("Length: 0x%x ",replyLength);
|
||||
rprintf("RxChksum=0x%x MyChksum=0x%x",replyData[replyLength-1], checksum);
|
||||
rprintfCRLF();
|
||||
rprintf("Data:\r\n");
|
||||
debugPrintHexTable((replyLength-1), replyData);
|
||||
rprintfCRLF();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
u08 edpComposeCommand(u08 srcEdpAddr, u08* cmdBuffer)
|
||||
{
|
||||
u08 string[80];
|
||||
u08 len;
|
||||
u08 i;
|
||||
|
||||
// instructions
|
||||
rprintfProgStrM("Enter EDP Command, format [c][p1][p2][p3]...[pN]\r\n");
|
||||
rprintfProgStrM("[c] is command char, [px] parameters in 2-digit hex\r\n");
|
||||
|
||||
// get user input
|
||||
rprintfProgStrM("EDP Command>");
|
||||
len = inputString(0x0D, 80, string);
|
||||
rprintfCRLF();
|
||||
|
||||
// check for null user input
|
||||
if(!len)
|
||||
{
|
||||
rprintfProgStrM("ERROR: No command\r\n");
|
||||
// return immediately with zero command length
|
||||
return 0;
|
||||
}
|
||||
|
||||
// prepare command
|
||||
cmdBuffer[0] = srcEdpAddr;
|
||||
cmdBuffer[1] = string[0];
|
||||
for(i=0; i<len/2; i++)
|
||||
{
|
||||
cmdBuffer[i+2] = asciiHexToByte(&string[1+(i*2)]);
|
||||
}
|
||||
|
||||
// return command length
|
||||
return 2+(len/2);
|
||||
}
|
||||
|
||||
void edpRunCommand(u08 destEdpAddr, u08 cmdLength, u08* cmdBuffer)
|
||||
{
|
||||
u08 response;
|
||||
EdpReply* edpReply;
|
||||
|
||||
u08 retval;
|
||||
|
||||
EdpCommand* edpCommand = (EdpCommand*)cmdBuffer;
|
||||
|
||||
// send command
|
||||
rprintf("Sending Command: 0x%x '%c' ->",edpCommand->Command,edpCommand->Command);
|
||||
retval = edpSendCommand(destEdpAddr, cmdLength, edpCommand);
|
||||
// handle result values
|
||||
if(retval == EDP_COMMAND_OK)
|
||||
{
|
||||
// command sent successfully
|
||||
rprintfProgStrM("Send Success!\r\n");
|
||||
}
|
||||
else if(retval == EDP_COMMAND_NODEV)
|
||||
{
|
||||
// device did not exist
|
||||
rprintfProgStrM("Send Failed->NO DEVICE!\r\n");
|
||||
rprintf("No EDP device could be contacted at address 0x%x.\r\n", destEdpAddr);
|
||||
rprintfProgStrM("The device may be busy or not responding.\r\n");
|
||||
rprintfProgStrM("Check target device and I2C bus cabling.\r\n");
|
||||
// return immediately
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// other error
|
||||
rprintfProgStrM("Send Failed->Unspecified Error!\r\n");
|
||||
// return immediately
|
||||
return;
|
||||
}
|
||||
|
||||
// get the reply, if any, from the command
|
||||
retval = edpGetCommandReply(&response, &edpReply);
|
||||
// handle result values
|
||||
if(retval == EDP_REPLY_BADCHKSUM)
|
||||
{
|
||||
rprintf("**** Reply has bad checksum ****\r\n");
|
||||
}
|
||||
// display the reply
|
||||
edpDisplayReply(response, edpReply);
|
||||
}
|
32
build/shared/lib/avrlib/rsl/edpdebug.h
Executable file
32
build/shared/lib/avrlib/rsl/edpdebug.h
Executable file
@ -0,0 +1,32 @@
|
||||
/*! \file edpdebug.h \brief Emerald Data Protocol Debug Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'edpdebug.h'
|
||||
// Title : Emerald Data Protocol Debug Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.09.20
|
||||
// Revised : 2003.09.20
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef EDPDEBUG_H
|
||||
#define EDPDEBUG_H
|
||||
|
||||
#include "edp.h"
|
||||
|
||||
// functions
|
||||
u08 edpComposeCommand(u08 srcEdpAddr, u08* cmdBuffer);
|
||||
void edpRunCommand(u08 destEdpAddr, u08 cmdLength, u08* cmdBuffer);
|
||||
|
||||
// display functions
|
||||
void edpDisplayCommand(u08 length, EdpCommand* edpCommand);
|
||||
void edpDisplayReply(u08 response, EdpReply* edpReply);
|
||||
//void edpDisplayReplyOld(u08 response, u08 replyLength, u08* replyData);
|
||||
|
||||
#endif
|
82
build/shared/lib/avrlib/rsl/edpdefs.h
Executable file
82
build/shared/lib/avrlib/rsl/edpdefs.h
Executable file
@ -0,0 +1,82 @@
|
||||
/*! \file edpdefs.h \brief Emerald Data Protocol Defines and Constants. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'edpdefs.h'
|
||||
// Title : Emerald Data Protocol Defines and Constants
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 09/08/2003
|
||||
// Revised : 09/08/2003
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef EDPDEFS_H
|
||||
#define EDPDEFS_H
|
||||
|
||||
// **** Constant Definitions *****
|
||||
// ---- Message Size, etc ----
|
||||
// Standard defines for various message format parameters
|
||||
#define I2C_MAX_COMMAND_LENGTH 127 // [param1]...[param127] (does not include Command, From
|
||||
// or Chk) Note that this an absolute maximum,
|
||||
// subsystems/nodes are free to set lower maximum lengths
|
||||
// For versions pre rev5, this was fixed at 5.
|
||||
#define I2C_MAX_DATA_PACKET_LENGTH 127 // Raw Data: [data1]...[data126][Chk] (includes Chk for
|
||||
|
||||
|
||||
// ---- Communication OK (value all uppercase ('A'-'Z')
|
||||
#define EDP_RESP_ACK 'A' // indicates the command (to_send) was sent but has no return value.
|
||||
#define EDP_RESP_DATA_REPLY 'R' // command valid and has return, examine reply and length for details
|
||||
|
||||
// ---- Communication Error (values all lowercase ('a'-'z'))
|
||||
#define EDP_RESP_UNKWN_CMD 'u' // given command is unrecognized by the subsystem at that address
|
||||
#define EDP_RESP_CMD_CHK_ERROR 'c' // checksum error sending command
|
||||
#define EDP_RESP_DATA_CHK_ERROR 'd' // checksum error receiving data
|
||||
#define EDP_RESP_SEQUENCE_ERROR 's' // read/write out of order
|
||||
#define EDP_RESP_READ_BEFORE_WRITE 'b' // requested read before writting associated Command
|
||||
#define EDP_RESP_TOO_LONG 'l' // The command sent exceeds the maximum command length for node
|
||||
#define EDP_RESP_TOO_FEW_PARAMS 'p' // The command sent has too few parameters
|
||||
#define EDP_RESP_INCORRECT_PARAM 'i' // Parameters are incorrect (but there are the right number)
|
||||
#define EDP_RESP_BUSY 'b' // The subsystem is still alive, but too busy to reply (AVOID USING)
|
||||
#define EDP_RESP_NOT_ALLOWED 'n' // The command is recognized, but not allowed in the current
|
||||
// operating mode. Try another command, or try again later
|
||||
#define EDP_RESP_OTHER_ERROR 'e' // unspecified EDP/I2C error
|
||||
|
||||
// ---- Check Sum ----
|
||||
/* The Checksum that is used is a rolling 8-bit sum from the [From] to the last parameter byte of a command
|
||||
packet and from the [Length] to the last data byte of a Data packet. This sum is then 1-complemented
|
||||
(~, not) and passed as [Chk]. This prevents a series of 0x00 replys from passing the correct check sum.
|
||||
Because of the inversion, a packet with all zeros should have a checksum of 0xFF.
|
||||
|
||||
The other nice feature of this checksum, is that no matter what the data is, if you add the checksum
|
||||
([Chk]) to the final sum, you should get 0xFF.
|
||||
|
||||
To make it even cleaner, you can start the rolling checksum at 0x01 such that when you add in all of the
|
||||
data bytes and the [Chk] byte, you get 0x00. This effectively makes the whole operation a twos complement
|
||||
*/
|
||||
#define EDP_CHECKSUM_INIT 0x01
|
||||
|
||||
// -------- Reserved I2C commands ---------
|
||||
// Define a short list of reserved commands. Subsystems can choose whether or
|
||||
// not to implement these commands, but if they are implemented, they must
|
||||
// function as described below.
|
||||
|
||||
//Reserved Commands
|
||||
#define EDP_CMD_SET_TIME ':' //0x3A Set the subsystem time, realtime.h format
|
||||
#define EDP_CMD_RESERVED_1 ';' //0x3B Reserved for future command
|
||||
#define EDP_CMD_ROM_WRITE '<' //0x3C Write to program ROM (uploadable code)
|
||||
#define EDP_CMD_RESERVED_2 '=' //0x3D Reserved for future command
|
||||
#define EDP_CMD_MEM_READ '>' //0x3E Read from program ROM (check program)
|
||||
#define EDP_CMD_HELP '?' //0x3F Return human readable help string(s)
|
||||
#define EDP_CMD_STATUS '@' //0x40 Get subsystem status
|
||||
|
||||
|
||||
#define I2C_DATA_CONTINUE_MASK 0x80 // If MSB of length is set, then the data continues beyond
|
||||
// this data packet
|
||||
|
||||
|
||||
#endif
|
129
build/shared/lib/avrlib/rsl/erp.c
Executable file
129
build/shared/lib/avrlib/rsl/erp.c
Executable file
@ -0,0 +1,129 @@
|
||||
/*! \file erp.c \brief Emerald Radio Protocol System. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'erp.c'
|
||||
// Title : Emerald Radio Protocol System
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.09.10
|
||||
// Revised : 2003.09.10
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include "global.h" // include our global settings
|
||||
#include "debug.h" // include debug function library
|
||||
#include "rprintf.h" // include printf function library
|
||||
|
||||
#include "erp.h"
|
||||
#include "edpdebug.h"
|
||||
|
||||
// globals
|
||||
|
||||
// functions
|
||||
void erpDisplayHeader(ErpPacket* erpPacket)
|
||||
{
|
||||
// show ERP packet header
|
||||
rprintf("ERP Header: Callsign=");
|
||||
rprintfStrLen(erpPacket->CallSign,0,CALLSIGN_FIELD_LEN);
|
||||
rprintf(", Trg=0x%x, Src=0x%x, Seq#=%d, Type=",
|
||||
erpPacket->ToAddress,
|
||||
erpPacket->FromAddress,
|
||||
erpPacket->SequenceNum);
|
||||
// try to decode packet type
|
||||
switch(erpPacket->Type)
|
||||
{
|
||||
case ERP_ECHO: rprintf("ECHO"); break;
|
||||
case ERP_ECHOREPLY: rprintf("ECHOREPLY"); break;
|
||||
case ERP_TEST: rprintf("TEST"); break;
|
||||
case ERP_EDPCOMMAND: rprintf("EDPCOMMAND"); break;
|
||||
case ERP_EDPREPLY: rprintf("EDPREPLY"); break;
|
||||
case ERP_EDPREPLYNODEV: rprintf("EDPREPLYNODEV"); break;
|
||||
default: rprintf("0x%x", erpPacket->Type); break;
|
||||
}
|
||||
rprintfCRLF();
|
||||
}
|
||||
|
||||
void erpDisplayPacket(ErpPacket* erpPacket, u08 pktLength)
|
||||
{
|
||||
u08 i;
|
||||
u08 flag;
|
||||
|
||||
// show ERP packet header
|
||||
erpDisplayHeader(erpPacket);
|
||||
|
||||
// dump complete raw packet data
|
||||
if(pktLength)
|
||||
{
|
||||
// check if all characters are printable
|
||||
flag = TRUE;
|
||||
for(i=0; i<pktLength; i++)
|
||||
{
|
||||
if( ((u08*)erpPacket)[i] < 0x20 ) flag = FALSE;
|
||||
}
|
||||
|
||||
// print packet data
|
||||
rprintf("Data:\r\n");
|
||||
if(flag)
|
||||
{
|
||||
// print as string
|
||||
rprintfStrLen(((u08*)erpPacket), 0, pktLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
// print as hex
|
||||
debugPrintHexTable(pktLength, ((u08*)erpPacket));
|
||||
}
|
||||
rprintfCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
void erpDisplayEdpCommand(u08 length, ErpEdpCommand* erpEdpCommand)
|
||||
{
|
||||
// print ERP-specific fields
|
||||
rprintf("EDP DestAddr: 0x%x\r\n", erpEdpCommand->EdpDestAddr);
|
||||
// print embedded EDP command
|
||||
edpDisplayCommand(length-1, &erpEdpCommand->EdpCommand);
|
||||
}
|
||||
|
||||
void erpDisplayEdpReply(u08 length, ErpEdpReply* erpEdpReply)
|
||||
{
|
||||
// print embedded EDP reply
|
||||
edpDisplayReply(erpEdpReply->EdpResponse, &erpEdpReply->EdpReply);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void ErpPacketCreate(u08 targetI2cAddr, u08 pktType, u08 datalength, u08* data)
|
||||
{
|
||||
// make packet structure in TxPacket memory
|
||||
struct ErpPacket* erpPacket
|
||||
= (struct ErpPacket*)TxPacket;
|
||||
|
||||
// prepare Emerald packet header
|
||||
memcpy(erpPacket->CallSign, MYCALLSIGN, CALLSIGN_FIELD_LEN);
|
||||
erpPacket->ToAddress = targetI2cAddr;
|
||||
erpPacket->FromAddress = LocalI2cAddr;
|
||||
erpPacket->SequenceNum = SequenceNum++;
|
||||
erpPacket->Type = pktType;
|
||||
// copy data
|
||||
for(i=0; i<datalength; i++)
|
||||
{
|
||||
erpPacket->Data[i] = *data++;
|
||||
}
|
||||
}
|
||||
|
||||
void ErpPacketTx(void)
|
||||
{
|
||||
// STX/ETX header
|
||||
u08 stxetxStatus = 0x5A;
|
||||
u08 stxetxType = 0xA5;
|
||||
rprintf("Sending Packet: Status: 0x%x Type: 0x%x\r\n", stxetxStatus, stxetxType);
|
||||
radioSend(stxetxStatus, stxetxType, EMRADIOHEADER_LEN+(len/2), packet);
|
||||
}
|
||||
*/
|
66
build/shared/lib/avrlib/rsl/erp.h
Executable file
66
build/shared/lib/avrlib/rsl/erp.h
Executable file
@ -0,0 +1,66 @@
|
||||
/*! \file erp.h \brief Emerald Radio Protocol System. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'erp.h'
|
||||
// Title : Emerald Radio Protocol System
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.09.10
|
||||
// Revised : 2003.09.10
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef ERP_H
|
||||
#define ERP_H
|
||||
|
||||
#include "edp.h"
|
||||
|
||||
// defines and typedefs
|
||||
// Packet Types (tentative)
|
||||
#define ERP_ECHO 0x01
|
||||
#define ERP_ECHOREPLY 0x02
|
||||
#define ERP_TEST 0x03
|
||||
#define ERP_EDPCOMMAND 0x10
|
||||
#define ERP_EDPREPLY 0x11
|
||||
#define ERP_EDPREPLYNODEV 0x12
|
||||
|
||||
#define CALLSIGN_FIELD_LEN 6
|
||||
|
||||
// structures and typedefs
|
||||
typedef struct
|
||||
{
|
||||
u08 CallSign[6];
|
||||
u08 ToAddress;
|
||||
u08 FromAddress;
|
||||
u08 SequenceNum;
|
||||
u08 Type;
|
||||
u08 Data[];
|
||||
} ErpPacket;
|
||||
#define ERP_HEADER_LEN 10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u08 EdpDestAddr;
|
||||
EdpCommand EdpCommand;
|
||||
} ErpEdpCommand;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u08 EdpResponse;
|
||||
EdpReply EdpReply;
|
||||
} ErpEdpReply;
|
||||
|
||||
|
||||
// functions
|
||||
// ERP display
|
||||
void erpDisplayHeader(ErpPacket* erpPacket);
|
||||
void erpDisplayPacket(ErpPacket* erpPacket, u08 pktLength);
|
||||
void erpDisplayEdpCommand(u08 length, ErpEdpCommand* erpEdpCommand);
|
||||
void erpDisplayEdpReply(u08 length, ErpEdpReply* erpEdpReply);
|
||||
|
||||
#endif
|
91
build/shared/lib/avrlib/rsl/input.c
Executable file
91
build/shared/lib/avrlib/rsl/input.c
Executable file
@ -0,0 +1,91 @@
|
||||
/*! \file input.c \brief User-Input Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'input.c'
|
||||
// Title : User-Input Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.09.11
|
||||
// Revised : 2003.09.11
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include "global.h" // include our global settings
|
||||
#ifdef __AVR_ATmega128__
|
||||
#include "uart2.h"
|
||||
#else
|
||||
#include "uart.h"
|
||||
#endif
|
||||
#include "rprintf.h" // include printf function library
|
||||
|
||||
#include "input.h"
|
||||
|
||||
// globals
|
||||
|
||||
// functions
|
||||
u08 inputString(u08 termChar, u08 termLen, u08* data)
|
||||
{
|
||||
u08 s=0;
|
||||
u08 length=0;
|
||||
|
||||
while(length < termLen)
|
||||
{
|
||||
// get input
|
||||
#ifdef __AVR_ATmega128__
|
||||
while(!uartReceiveByte(1,&s));
|
||||
#else
|
||||
while(!uartReceiveByte(&s));
|
||||
#endif
|
||||
|
||||
// handle special characters
|
||||
if(s == 0x08) // backspace
|
||||
{
|
||||
if(length > 0)
|
||||
{
|
||||
// echo backspace-space-backspace
|
||||
rprintfChar(0x08);
|
||||
rprintfChar(' ');
|
||||
rprintfChar(0x08);
|
||||
length--;
|
||||
}
|
||||
}
|
||||
else if(s == termChar) // termination character
|
||||
{
|
||||
// save null-termination
|
||||
data[length] = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// echo character
|
||||
rprintfChar(s);
|
||||
// save character
|
||||
data[length++] = s;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
u08 asciiHexToByte(u08* string)
|
||||
{
|
||||
// convert 2-byte hex string to byte
|
||||
return (asciiHexToNibble(string[0])<<4) + asciiHexToNibble(string[1]);
|
||||
}
|
||||
|
||||
u08 asciiHexToNibble(u08 character)
|
||||
{
|
||||
// convert 1-byte hex ascii character to nibble
|
||||
if((character >= 0x30) && (character <= 0x39))
|
||||
return character-0x30;
|
||||
else if((character >= 'A') && (character <= 'F'))
|
||||
return character-'A'+10;
|
||||
else if((character >= 'a') && (character <= 'f'))
|
||||
return character-'a'+10;
|
||||
else return 0;
|
||||
}
|
28
build/shared/lib/avrlib/rsl/input.h
Executable file
28
build/shared/lib/avrlib/rsl/input.h
Executable file
@ -0,0 +1,28 @@
|
||||
/*! \file input.h \brief User-Input Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'input.h'
|
||||
// Title : User-Input Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 2003.09.11
|
||||
// Revised : 2003.09.11
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
// defines and typedefs
|
||||
|
||||
// functions
|
||||
u08 inputString(u08 termChar, u08 termLen, u08* data);
|
||||
u08 asciiHexToByte(u08* string);
|
||||
u08 asciiHexToNibble(u08 character);
|
||||
|
||||
#endif
|
288
build/shared/lib/avrlib/rsl/mitelgps.c
Executable file
288
build/shared/lib/avrlib/rsl/mitelgps.c
Executable file
@ -0,0 +1,288 @@
|
||||
/*! \file .c \brief Mitel GPS STX/ETX driver function library. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'mitelgps.c'
|
||||
// Title : Mitel GPS STX/ETX driver function library
|
||||
// Author : Pascal Stang - Copyright (C) 2002
|
||||
// Created : 2003.04.11
|
||||
// Revised : 2003.08.26
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// NOTE: This code is currently below version 1.0, and therefore is considered
|
||||
// to be lacking in some functionality or documentation, or may not be fully
|
||||
// tested. Nonetheless, you can expect most functions to work.
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef WIN32
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "global.h"
|
||||
#include "buffer.h"
|
||||
#include "rprintf.h"
|
||||
#include "uart2.h"
|
||||
#include "gps.h"
|
||||
|
||||
#include "mitelgps.h"
|
||||
|
||||
// Program ROM constants
|
||||
|
||||
// Global variables
|
||||
// external GPS information structure/repository (in gps.h/gps.c)
|
||||
extern GpsInfoType GpsInfo;
|
||||
// packet processing buffer
|
||||
u08 MitelGpsPacket[MITELGPS_BUFFERSIZE];
|
||||
// debug flag
|
||||
u08 debug;
|
||||
#define MITELGPS_DEBUG_PKTPARSE 0x01
|
||||
#define MITELGPS_DEBUG_EXTRACT 0x02
|
||||
// function pointer to single byte output routine
|
||||
static void (*TxByteFunc)(unsigned char c);
|
||||
|
||||
void mitelgpsInit(void (*txbytefunc)(unsigned char c))
|
||||
{
|
||||
// set transmit function
|
||||
// (this function will be used for all SendPacket commands)
|
||||
TxByteFunc = txbytefunc;
|
||||
// set debug status
|
||||
debug = 0;
|
||||
}
|
||||
|
||||
void mitelgpsSendPacket(u08* data, u08 dataLength)
|
||||
{
|
||||
u08 i;
|
||||
u08 dataIdx = 0;
|
||||
u08 checksum = 0;
|
||||
|
||||
// start of packet
|
||||
MitelGpsPacket[dataIdx++] = STX;
|
||||
// add packet type and packet data
|
||||
for(i=0; i<dataLength; i++)
|
||||
{
|
||||
checksum ^= MitelGpsPacket[dataIdx];
|
||||
MitelGpsPacket[dataIdx++] = *data++;
|
||||
}
|
||||
// checksum
|
||||
convertIntToAsciiHex(checksum, &MitelGpsPacket[dataIdx], 2);
|
||||
dataIdx += 2;
|
||||
// end of packet
|
||||
MitelGpsPacket[dataIdx++] = ETX;
|
||||
|
||||
// send it
|
||||
for(i=0; i<dataIdx; i++)
|
||||
TxByteFunc(MitelGpsPacket[i]);
|
||||
}
|
||||
|
||||
u08 mitelgpsProcess(cBuffer* rxBuffer)
|
||||
{
|
||||
u08 foundpacket = FALSE;
|
||||
u08 startFlag = FALSE;
|
||||
u08 checksum = 0;
|
||||
u08 packetType;
|
||||
u16 i,j;
|
||||
|
||||
// process the receive buffer
|
||||
// go through buffer looking for packets
|
||||
while(rxBuffer->datalength > 1)
|
||||
{
|
||||
// look for a start of Mitel GPS STX/ETX packet
|
||||
if(bufferGetAtIndex(rxBuffer,0) == STX)
|
||||
{
|
||||
// found start
|
||||
startFlag = TRUE;
|
||||
// done looking for start
|
||||
break;
|
||||
}
|
||||
else
|
||||
// not STX, dump character from buffer
|
||||
bufferGetFromFront(rxBuffer);
|
||||
}
|
||||
|
||||
// if we detected a start, look for end of packet
|
||||
if(startFlag)
|
||||
{
|
||||
for(i=1; i<(rxBuffer->datalength); i++)
|
||||
{
|
||||
// check for end of Mitel GPS STX/ETX packet
|
||||
if(bufferGetAtIndex(rxBuffer,i) == ETX)
|
||||
{
|
||||
// have a packet end
|
||||
// dump initial STX
|
||||
bufferGetFromFront(rxBuffer);
|
||||
// copy data to MitelGpsPacket
|
||||
for(j=0; j<(i-1); j++)
|
||||
{
|
||||
MitelGpsPacket[j] = bufferGetFromFront(rxBuffer);
|
||||
checksum ^= MitelGpsPacket[j];
|
||||
}
|
||||
// null-terminate copied string
|
||||
MitelGpsPacket[j] = 0;
|
||||
// dump ending ETX
|
||||
bufferGetFromFront(rxBuffer);
|
||||
|
||||
// verify checksum
|
||||
// undo checksum summing of the checksum itself
|
||||
checksum ^= MitelGpsPacket[j-2];
|
||||
checksum ^= MitelGpsPacket[j-1];
|
||||
if( checksum == convertAsciiHexToInt(&MitelGpsPacket[j-2], 2) )
|
||||
{
|
||||
// found a good packet
|
||||
if(debug & MITELGPS_DEBUG_PKTPARSE)
|
||||
{
|
||||
rprintf("Rx Mitel GPS packet type: %c%c%c len: %d\r\n",
|
||||
MitelGpsPacket[0], MitelGpsPacket[1], MitelGpsPacket[2], j);
|
||||
rprintfStr(MitelGpsPacket);
|
||||
rprintfCRLF();
|
||||
}
|
||||
// done with this processing session
|
||||
foundpacket = TRUE;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(debug & MITELGPS_DEBUG_PKTPARSE)
|
||||
{
|
||||
rprintf("Rx Mitel GPS packet type: %c%c%c len: %d Bad Checksum Rcvd: 0x%c%c Calc: 0x%x\r\n",
|
||||
MitelGpsPacket[0], MitelGpsPacket[1], MitelGpsPacket[2], j, MitelGpsPacket[j-2], MitelGpsPacket[j-1], checksum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle and direct the received packet
|
||||
if(foundpacket)
|
||||
{
|
||||
// switch on the packet type
|
||||
packetType = convertAsciiHexToInt(&MitelGpsPacket[1], 2);
|
||||
switch( packetType )
|
||||
{
|
||||
case MITELTYPE_NAVDATAGND: mitelgpsProcessNAVDATAGND(MitelGpsPacket); break;
|
||||
case MITELTYPE_CHNLSTATGND: mitelgpsProcessCHNLSTATGND(MitelGpsPacket); break;
|
||||
case MITELTYPE_NAVDATA: mitelgpsProcessNAVDATA(MitelGpsPacket); break;
|
||||
case MITELTYPE_RAWDATA: mitelgpsProcessRAWDATA(MitelGpsPacket); break;
|
||||
case MITELTYPE_CHNLSTAT: mitelgpsProcessCHNLSTAT(MitelGpsPacket); break;
|
||||
case MITELTYPE_RELNAVECEF: break;
|
||||
case MITELTYPE_RELNAVRTN: break;
|
||||
default:
|
||||
if(debug & MITELGPS_DEBUG_PKTPARSE)
|
||||
rprintf("Unhandled Mitel GPS packet type: 0x%x\r\n", packetType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return foundpacket;
|
||||
}
|
||||
|
||||
void mitelgpsProcessNAVDATAGND(u08* packet)
|
||||
{
|
||||
// process "F00" report packets - Navigation Data (Ground)
|
||||
char* endptr;
|
||||
|
||||
if(debug & MITELGPS_DEBUG_EXTRACT)
|
||||
{
|
||||
rprintf("MITELGPS: ");
|
||||
rprintfStr(packet);
|
||||
rprintfCRLF();
|
||||
}
|
||||
|
||||
// start parsing just after "F00"
|
||||
// get latitude [sdd.dddddd]
|
||||
GpsInfo.PosLLA.lat.f = strtod(&packet[3], &endptr);
|
||||
// get longitude [sddd.dddddd]
|
||||
GpsInfo.PosLLA.lon.f = strtod(&packet[3+10], &endptr);
|
||||
// get altitude [sxxxxxx.x]
|
||||
GpsInfo.PosLLA.alt.f = strtod(&packet[3+10+11], &endptr);
|
||||
// get speed [sxxx.xx]
|
||||
GpsInfo.VelHS.speed.f = strtod(&packet[3+10+11+9], &endptr);
|
||||
// get heading [ddd]
|
||||
GpsInfo.VelHS.heading.f = strtod(&packet[3+10+11+9+7], &endptr);
|
||||
|
||||
// get # of SVs tracked [xx]
|
||||
GpsInfo.numSVs = atoi(&packet[3+10+11+9+7+5+7+5+5+5]);
|
||||
}
|
||||
|
||||
void mitelgpsProcessCHNLSTATGND(u08* packet)
|
||||
{
|
||||
// process "F03" report packets - Channel Status (Ground)
|
||||
}
|
||||
|
||||
void mitelgpsProcessNAVDATA(u08* packet)
|
||||
{
|
||||
// process "F40" report packets - Navigation Data
|
||||
char* endptr;
|
||||
|
||||
// start parsing just after "F40"
|
||||
// get gps week number [xxxx]=4
|
||||
GpsInfo.WeekNum = atoi(&packet[3]);
|
||||
// get gps time of week [xxxxxx.xxxxx]=12
|
||||
GpsInfo.TimeOfWeek.f = strtod(&packet[3+4], &endptr);
|
||||
// gps-utc time difference? [xx]=2
|
||||
// get ECEF X [sxxxxxxxx.xx]=12
|
||||
GpsInfo.PosECEF.x.f = strtod(&packet[3+4+12+2], &endptr);
|
||||
// get ECEF Y [sxxxxxxxx.xx]=12
|
||||
GpsInfo.PosECEF.y.f = strtod(&packet[3+4+12+2+12], &endptr);
|
||||
// get ECEF Z [sxxxxxxxx.xx]=12
|
||||
GpsInfo.PosECEF.z.f = strtod(&packet[3+4+12+2+12+12], &endptr);
|
||||
// get ECEF vX [sxxxxxxxx.xx]=12
|
||||
GpsInfo.VelECEF.x.f = strtod(&packet[3+4+12+2+12+12+12], &endptr);
|
||||
// get ECEF vY [sxxxxxxxx.xx]=12
|
||||
GpsInfo.VelECEF.y.f = strtod(&packet[3+4+12+2+12+12+12+12], &endptr);
|
||||
// get ECEF vZ [sxxxxxxxx.xx]=12
|
||||
GpsInfo.VelECEF.z.f = strtod(&packet[3+4+12+2+12+12+12+12+12], &endptr);
|
||||
}
|
||||
|
||||
void mitelgpsProcessRAWDATA(u08* packet)
|
||||
{
|
||||
// process "F42" report packets - Pseudorange, carrier phase, doppler
|
||||
}
|
||||
|
||||
void mitelgpsProcessCHNLSTAT(u08* packet)
|
||||
{
|
||||
// process "F43" report packets - Channel Status
|
||||
}
|
||||
|
||||
// data conversions
|
||||
u32 convertAsciiHexToInt(u08* string, u08 numdigits)
|
||||
{
|
||||
u08 i;
|
||||
u32 num = 0;
|
||||
|
||||
for(i=0; i<numdigits; i++)
|
||||
{
|
||||
// shift number up
|
||||
num = num<<4;
|
||||
// decode hex digit
|
||||
if(string[i] >= 'a')
|
||||
num |= string[i]-'a'+10;
|
||||
else if(string[i] >= 'A')
|
||||
num |= string[i]-'A'+10;
|
||||
else
|
||||
num |= string[i]-'0';
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
void convertIntToAsciiHex(u32 num, u08* string, u08 numdigits)
|
||||
{
|
||||
u08 i;
|
||||
|
||||
for(i=0; i<numdigits; i++)
|
||||
{
|
||||
if((num & 0x0000000F) < 10)
|
||||
string[numdigits-1-i] = (num & 0x0000000F)+'0';
|
||||
else
|
||||
string[numdigits-1-i] = (num & 0x0000000F)+'A'-10;
|
||||
// next digit
|
||||
num = num>>4;
|
||||
}
|
||||
}
|
62
build/shared/lib/avrlib/rsl/mitelgps.h
Executable file
62
build/shared/lib/avrlib/rsl/mitelgps.h
Executable file
@ -0,0 +1,62 @@
|
||||
/*! \file mitelgps.c \brief Mitel GPS STX/ETX driver function library. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'mitelgps.h'
|
||||
// Title : Mitel GPS STX/ETX driver function library
|
||||
// Author : Pascal Stang - Copyright (C) 2002
|
||||
// Created : 2003.04.11
|
||||
// Revised : 2003.06.08
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// NOTE: This code is currently below version 1.0, and therefore is considered
|
||||
// to be lacking in some functionality or documentation, or may not be fully
|
||||
// tested. Nonetheless, you can expect most functions to work.
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef MITELGPS_H
|
||||
#define MITELGPS_H
|
||||
|
||||
#include "global.h"
|
||||
|
||||
// constants/macros/typdefs
|
||||
// packet buffer size (must be able to contain biggest packet)
|
||||
#define MITELGPS_BUFFERSIZE 0x0400
|
||||
|
||||
// packet delimiters
|
||||
#define STX 0x02
|
||||
#define ETX 0x03
|
||||
|
||||
// report packet types
|
||||
#define MITELTYPE_NAVDATAGND 0x00
|
||||
#define MITELTYPE_CHNLSTATGND 0x03
|
||||
#define MITELTYPE_NAVDATA 0x40
|
||||
#define MITELTYPE_RAWDATA 0x42
|
||||
#define MITELTYPE_CHNLSTAT 0x43
|
||||
#define MITELTYPE_RELNAVECEF 0x45
|
||||
#define MITELTYPE_RELNAVRTN 0x46
|
||||
|
||||
// functions
|
||||
void mitelgpsInit(void (*txbytefunc)(unsigned char c));
|
||||
void mitelgpsSendPacket(u08* data, u08 dataLength);
|
||||
u08 mitelgpsProcess(cBuffer* rxBuffer);
|
||||
|
||||
// packet processing functions
|
||||
void mitelgpsProcessNAVDATAGND(u08* packet);
|
||||
void mitelgpsProcessCHNLSTATGND(u08* packet);
|
||||
void mitelgpsProcessNAVDATA(u08* packet);
|
||||
void mitelgpsProcessRAWDATA(u08* packet);
|
||||
void mitelgpsProcessCHNLSTAT(u08* packet);
|
||||
|
||||
// data conversions (these functions should move somewhere else)
|
||||
u32 convertAsciiHexToInt(u08* string, u08 numdigits);
|
||||
void convertIntToAsciiHex(u32 num, u08* string, u08 numdigits);
|
||||
|
||||
|
||||
|
||||
#endif
|
53
build/shared/lib/avrlib/rsl/radiolinx.c
Executable file
53
build/shared/lib/avrlib/rsl/radiolinx.c
Executable file
@ -0,0 +1,53 @@
|
||||
/*! \file radiolinx.c \brief Linx Radio Driver. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'radiolinx.c'
|
||||
// Title : Linx Radio Driver
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 09/01/2003
|
||||
// Revised : 09/03/2003
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
|
||||
#include <avr/signal.h> // include "signal" names (interrupt names)
|
||||
#include <avr/interrupt.h> // include interrupt support
|
||||
|
||||
#include "global.h" // include our global settings
|
||||
#include "buffer.h" // include buffer support
|
||||
#include "uartsw.h" // include software UART driver
|
||||
#include "stxetx.h" // include STX/ETX protocol library
|
||||
|
||||
#include "radiolinx.h"
|
||||
|
||||
// global variables
|
||||
|
||||
// functions
|
||||
void radioInit(void)
|
||||
{
|
||||
// Initialize radio interface
|
||||
// Since this radio creates a special serial interface,
|
||||
// we initialize it here.
|
||||
uartswInit();
|
||||
// set baud rate of comm
|
||||
uartswSetBaudRate(4800);
|
||||
// initialize stxetx to use the software UART for sending data
|
||||
stxetxInit(uartswSendByte);
|
||||
}
|
||||
|
||||
void radioSend(u08 status, u08 type, u08 datalength, u08* dataptr)
|
||||
{
|
||||
stxetxSend(status, type, datalength, dataptr);
|
||||
}
|
||||
|
||||
cBuffer* radioGetRxBuffer(void)
|
||||
{
|
||||
return uartswGetRxBuffer();
|
||||
}
|
26
build/shared/lib/avrlib/rsl/radiolinx.h
Executable file
26
build/shared/lib/avrlib/rsl/radiolinx.h
Executable file
@ -0,0 +1,26 @@
|
||||
/*! \file radiolinx.h \brief Linx Radio Driver. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'radiolinx.h'
|
||||
// Title : Linx Radio Driver
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 09/01/2003
|
||||
// Revised : 09/03/2003
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef RADIOLINX_H
|
||||
#define RADIOLINX_H
|
||||
|
||||
// functions
|
||||
void radioInit(void);
|
||||
void radioSend(u08 status, u08 type, u08 datalength, u08* dataptr);
|
||||
cBuffer* radioGetRxBuffer(void);
|
||||
|
||||
#endif
|
68
build/shared/lib/avrlib/rsl/radiot96.c
Executable file
68
build/shared/lib/avrlib/rsl/radiot96.c
Executable file
@ -0,0 +1,68 @@
|
||||
/*! \file radiot96.c \brief DataRadio T96-SR Radio Driver. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'radiot96.c'
|
||||
// Title : DataRadio T96-SR Radio Driver
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 09/01/2003
|
||||
// Revised : 09/03/2003
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
|
||||
#include <avr/signal.h> // include "signal" names (interrupt names)
|
||||
#include <avr/interrupt.h> // include interrupt support
|
||||
|
||||
#include "global.h" // include our global settings
|
||||
#include "buffer.h" // include buffer support
|
||||
#include "timer128.h" // include timer function library
|
||||
#include "uart2.h" // include software UART driver
|
||||
#include "stxetx.h" // include STX/ETX protocol library
|
||||
#include "radiot96.h"
|
||||
|
||||
// global variables
|
||||
|
||||
// functions
|
||||
void radioInit(void)
|
||||
{
|
||||
// Initialize radio interface
|
||||
// set baud rate of comm
|
||||
uartSetBaudRate(COMM_UART, 19200);
|
||||
// initialize stxetx to use the UART for sending data
|
||||
#if COMM_UART == 0
|
||||
stxetxInit(uart0SendByte);
|
||||
#else
|
||||
stxetxInit(uart1SendByte);
|
||||
#endif
|
||||
// prepare PTT
|
||||
cbi(RADIO_PTT_PORT, RADIO_PTT_PIN);
|
||||
sbi(RADIO_PTT_DDR, RADIO_PTT_PIN);
|
||||
}
|
||||
|
||||
void radioPTT(u08 pttFlag)
|
||||
{
|
||||
if(pttFlag)
|
||||
sbi(RADIO_PTT_PORT, RADIO_PTT_PIN);
|
||||
else
|
||||
cbi(RADIO_PTT_PORT, RADIO_PTT_PIN);
|
||||
}
|
||||
|
||||
void radioSend(u08 status, u08 type, u08 datalength, u08* dataptr)
|
||||
{
|
||||
radioPTT(TRUE);
|
||||
timerPause(RADIO_PPT_DELAYMS);
|
||||
stxetxSend(status, type, datalength, dataptr);
|
||||
radioPTT(FALSE);
|
||||
}
|
||||
|
||||
cBuffer* radioGetRxBuffer(void)
|
||||
{
|
||||
return uartGetRxBuffer(COMM_UART);
|
||||
}
|
35
build/shared/lib/avrlib/rsl/radiot96.h
Executable file
35
build/shared/lib/avrlib/rsl/radiot96.h
Executable file
@ -0,0 +1,35 @@
|
||||
/*! \file radiot96.h \brief DataRadio T96-SR Radio Driver. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'radiot96.h'
|
||||
// Title : DataRadio T96-SR Radio Driver
|
||||
// Author : Pascal Stang - Copyright (C) 2003
|
||||
// Created : 09/01/2003
|
||||
// Revised : 09/03/2003
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef RADIOT96_H
|
||||
#define RADIOT96_H
|
||||
|
||||
// Radio PTT
|
||||
#define RADIO_PTT_DDR DDRD
|
||||
#define RADIO_PTT_PORT PORTD
|
||||
#define RADIO_PTT_PIN PD7
|
||||
|
||||
#define RADIO_PPT_DELAYMS 100
|
||||
|
||||
#define COMM_UART 1
|
||||
|
||||
// functions
|
||||
void radioInit(void);
|
||||
void radioSend(u08 status, u08 type, u08 datalength, u08* dataptr);
|
||||
cBuffer* radioGetRxBuffer(void);
|
||||
|
||||
#endif
|
152
build/shared/lib/avrlib/rsl/satmb.c
Executable file
152
build/shared/lib/avrlib/rsl/satmb.c
Executable file
@ -0,0 +1,152 @@
|
||||
/*! \file satmb.c \brief Satellite Motherboard Driver Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'satmb.c'
|
||||
// Title : Satellite Motherboard Driver Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2004
|
||||
// Created : 2004.10.13
|
||||
// Revised : 2004.10.13
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//----- Include Files ---------------------------------------------------------
|
||||
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
|
||||
#include <avr/signal.h> // include "signal" names (interrupt names)
|
||||
#include <avr/interrupt.h> // include interrupt support
|
||||
|
||||
#include "global.h" // include our global settings
|
||||
#include "dallas.h"
|
||||
#include "ds2450.h"
|
||||
#include "satmb.h"
|
||||
#include "dallasids.h"
|
||||
|
||||
// globals
|
||||
|
||||
// functions
|
||||
void satmbInit(void)
|
||||
{
|
||||
// preset serial port power to on
|
||||
satmbSetSerialPortPower(1);
|
||||
}
|
||||
|
||||
void satmbSetSerialPortPower(u08 on)
|
||||
{
|
||||
// set I/O control line to output
|
||||
sbi(SATMB_SER_PWR_DDR, SATMB_SER_PWR_PIN);
|
||||
// set serial port power state
|
||||
if(on)
|
||||
sbi(SATMB_SER_PWR_PORT, SATMB_SER_PWR_PIN);
|
||||
else
|
||||
cbi(SATMB_SER_PWR_PORT, SATMB_SER_PWR_PIN);
|
||||
}
|
||||
|
||||
void satmbSerialRtsCtsInit(void)
|
||||
{
|
||||
// initialize RTS/CTS lines for operation
|
||||
// RTS is input, set pullup
|
||||
cbi(SATMB_SER_RTS_DDR, SATMB_SER_RTS_PIN);
|
||||
sbi(SATMB_SER_RTS_PORT, SATMB_SER_RTS_PIN);
|
||||
// CTS is output, init low
|
||||
sbi(SATMB_SER_CTS_DDR, SATMB_SER_CTS_PIN);
|
||||
cbi(SATMB_SER_CTS_PORT, SATMB_SER_CTS_PIN);
|
||||
}
|
||||
|
||||
u08 satmbSerialRtsCheck(void)
|
||||
{
|
||||
if(inb(SATMB_SER_RTS_PORTIN) & (1<<SATMB_SER_RTS_PIN))
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void satmbSerialCtsSet(u08 state)
|
||||
{
|
||||
if(state)
|
||||
sbi(SATMB_SER_CTS_PORT, SATMB_SER_CTS_PIN);
|
||||
else
|
||||
cbi(SATMB_SER_CTS_PORT, SATMB_SER_CTS_PIN);
|
||||
}
|
||||
|
||||
u16 satmbV1GetCurrent(DallasSubsysId* targetSubsysId)
|
||||
{
|
||||
u16 value;
|
||||
// setup A/D for 5V 16-bit conversion
|
||||
ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
|
||||
// read current-level A/D
|
||||
ds2450StartAndResult(&targetSubsysId->S, 'A', &value);
|
||||
// calculate milliamp value
|
||||
// ma = 1000*(((value/65536)*5.12V)/(50*R))
|
||||
// for R=0.47/2 ohms
|
||||
// return result
|
||||
return value/150;
|
||||
}
|
||||
|
||||
u16 satmbV2GetCurrent(DallasSubsysId* targetSubsysId)
|
||||
{
|
||||
u16 value;
|
||||
// setup A/D for 5V 16-bit conversion
|
||||
ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
|
||||
// read current-level A/D
|
||||
ds2450StartAndResult(&targetSubsysId->S, 'C', &value);
|
||||
// calculate milliamp value
|
||||
// ma = 1000*(((value/65536)*5.12V)/(50*R))
|
||||
// for R=0.1/2 ohms
|
||||
// return result
|
||||
return value/32;
|
||||
}
|
||||
|
||||
u08 satmbV1GetOverCurrent(DallasSubsysId* targetSubsysId)
|
||||
{
|
||||
u16 value;
|
||||
// setup A/D for 5V 16-bit conversion
|
||||
ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
|
||||
// read overcurrent state A/D
|
||||
ds2450StartAndResult(&targetSubsysId->S, 'B', &value);
|
||||
// return result
|
||||
return (value>0x8000);
|
||||
}
|
||||
|
||||
u08 satmbV2GetOverCurrent(DallasSubsysId* targetSubsysId)
|
||||
{
|
||||
u16 value;
|
||||
// setup A/D for 5V 16-bit conversion
|
||||
ds2450SetupAll(&targetSubsysId->S, 16, DS2450_RANGE_5V);
|
||||
// read overcurrent state A/D
|
||||
ds2450StartAndResult(&targetSubsysId->S, 'D', &value);
|
||||
// return result
|
||||
return (value>0x8000);
|
||||
}
|
||||
|
||||
void satmbV1SetPowerState(DallasSubsysId* targetSubsysId, u08 state)
|
||||
{
|
||||
satmbSetPowerState(&targetSubsysId->V1, state);
|
||||
}
|
||||
|
||||
void satmbV2SetPowerState(DallasSubsysId* targetSubsysId, u08 state)
|
||||
{
|
||||
satmbSetPowerState(&targetSubsysId->V2, state);
|
||||
}
|
||||
|
||||
void satmbSetPowerState(dallas_rom_id_T* targetRomId, u08 state)
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
// reset overcurrent flag
|
||||
ds2450DigitalOut(targetRomId, 'B', DIGOUT_LOW);
|
||||
ds2450DigitalOut(targetRomId, 'B', DIGOUT_OC);
|
||||
// assert enable
|
||||
ds2450DigitalOut(targetRomId, 'A', DIGOUT_LOW);
|
||||
}
|
||||
// pulse clock line
|
||||
ds2450DigitalOut(targetRomId, 'C', DIGOUT_OC);
|
||||
ds2450DigitalOut(targetRomId, 'C', DIGOUT_LOW);
|
||||
ds2450DigitalOut(targetRomId, 'C', DIGOUT_OC);
|
||||
// release enable
|
||||
ds2450DigitalOut(targetRomId, 'A', DIGOUT_OC);
|
||||
}
|
113
build/shared/lib/avrlib/rsl/satmb.h
Executable file
113
build/shared/lib/avrlib/rsl/satmb.h
Executable file
@ -0,0 +1,113 @@
|
||||
/*! \file satmb.h \brief Satellite Motherboard Driver Functions. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'satmb.h'
|
||||
// Title : Satellite Motherboard Driver Functions
|
||||
// Author : Pascal Stang - Copyright (C) 2004
|
||||
// Created : 2004.10.13
|
||||
// Revised : 2004.10.13
|
||||
// Version : 0.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef SATMB_H
|
||||
#define SATMB_H
|
||||
|
||||
#include "dallas.h"
|
||||
#include "dallasids.h"
|
||||
|
||||
|
||||
// defines and typedefs
|
||||
|
||||
// SAT-MB serial port control
|
||||
// CTS is an output signal
|
||||
#define SATMB_SER_CTS_PORT PORTB
|
||||
#define SATMB_SER_CTS_DDR DDRB
|
||||
#define SATMB_SER_CTS_PORTIN PINB
|
||||
#define SATMB_SER_CTS_PIN PB5
|
||||
// RTS is an input signal
|
||||
#define SATMB_SER_RTS_PORT PORTB
|
||||
#define SATMB_SER_RTS_DDR DDRB
|
||||
#define SATMB_SER_RTS_PORTIN PINB
|
||||
#define SATMB_SER_RTS_PIN PB6
|
||||
// Serial Port Power Control (set low to turn off)
|
||||
#define SATMB_SER_PWR_PORT PORTD
|
||||
#define SATMB_SER_PWR_DDR DDRD
|
||||
#define SATMB_SER_PWR_PORTIN PIND
|
||||
#define SATMB_SER_PWR_PIN PD5
|
||||
|
||||
// SAT-MB Linx Radio Transceiver
|
||||
// Non-UART RX line (receive)
|
||||
#define SATMB_LINX_IO_RX_PORT PORTD
|
||||
#define SATMB_LINX_IO_RX_DDR DDRD
|
||||
#define SATMB_LINX_IO_RX_PORTIN PIND
|
||||
#define SATMB_LINX_IO_RX_PIN PD4
|
||||
// Non-UART TX line (transmit)
|
||||
#define SATMB_LINX_IO_TX_PORT PORTB
|
||||
#define SATMB_LINX_IO_TX_DDR DDRB
|
||||
#define SATMB_LINX_IO_TX_PORTIN PINB
|
||||
#define SATMB_LINX_IO_TX_PIN PB7
|
||||
// Linx Radio Power Control (set low to turn off)
|
||||
#define SATMB_LINX_PWR_PORT PORTD
|
||||
#define SATMB_LINX_PWR_DDR DDRD
|
||||
#define SATMB_LINX_PWR_PORTIN PIND
|
||||
#define SATMB_LINX_PWR_PIN PD5
|
||||
// Radio Receive Signal Strength Indicator (RSSI)
|
||||
// this is an analog output
|
||||
#define SATMB_LINX_RSSI_PORT PORTF
|
||||
#define SATMB_LINX_RSSI_DDR DDRF
|
||||
#define SATMB_LINX_RSSI_PORTIN PINF
|
||||
#define SATMB_LINX_RSSI_PIN PF7
|
||||
|
||||
// SAT-MB Direct Dallas Bus Driver
|
||||
// Dallas Line Pin
|
||||
#define SATMB_DALLAS_LINE_PORT PORTE
|
||||
#define SATMB_DALLAS_LINE_DDR DDRE
|
||||
#define SATMB_DALLAS_LINE_PORTIN PINE
|
||||
#define SATMB_DALLAS_LINE_PIN PE7
|
||||
// Dallas OC-Tx Pin
|
||||
#define SATMB_DALLAS_TX_PORT PORTE
|
||||
#define SATMB_DALLAS_TX_DDR DDRE
|
||||
#define SATMB_DALLAS_TX_PORTIN PINE
|
||||
#define SATMB_DALLAS_TX_PIN PE3
|
||||
// Dallas Strong-Pullup Pin
|
||||
#define SATMB_DALLAS_SPU_PORT PORTE
|
||||
#define SATMB_DALLAS_SPU_DDR DDRE
|
||||
#define SATMB_DALLAS_SPU_PORTIN PINE
|
||||
#define SATMB_DALLAS_SPU_PIN PE4
|
||||
|
||||
// functions
|
||||
|
||||
//! Initializes SAT-MB hardware
|
||||
void satmbInit(void);
|
||||
|
||||
//! Controls power to the SAT-MB serial port
|
||||
// TRUE = on
|
||||
// FALSE = off
|
||||
void satmbSetSerialPortPower(u08 on);
|
||||
|
||||
//! Initializes the SAT-MB serial port RTS/CTS lines
|
||||
void satmbSerialRtsCtsInit(void);
|
||||
|
||||
//! Returns the current state of the SAT-MB serial port RTS line
|
||||
u08 satmbSerialRtsCheck(void);
|
||||
|
||||
//! Sets the current state of the SAT-MB serial port CTS line
|
||||
void satmbSerialCtsSet(u08 state);
|
||||
|
||||
// Power control commands (dallas bus)
|
||||
u16 satmbV1GetCurrent(DallasSubsysId* targetSubsysId);
|
||||
u16 satmbV2GetCurrent(DallasSubsysId* targetSubsysId);
|
||||
u08 satmbV1GetOverCurrent(DallasSubsysId* targetSubsysId);
|
||||
u08 satmbV2GetOverCurrent(DallasSubsysId* targetSubsysId);
|
||||
void satmbV1SetPowerState(DallasSubsysId* targetSubsysId, u08 state);
|
||||
void satmbV2SetPower(DallasSubsysId* targetSubsysId, u08 state);
|
||||
|
||||
void satmbSetPowerState(dallas_rom_id_T* targetRomId, u08 state);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user