Initial import of support files for all Digistump boards - Digispark, Pro, DigiX - including libraries, examples, tools, and other support files for the Arduino IDE

This commit is contained in:
Erik Tylek Kettenburg
2014-12-19 08:45:50 -08:00
parent 97abdbf157
commit 7e7473a2d6
3567 changed files with 722870 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
This is the 'receiver' for the unit tests. Run it on a node which
is NOT under test.
TODO
Send finder request needs a re-think. It needs to be re-implemented as a Tictocs::Timer, so it
doesn't block the loop().
I could also make Tictocs objects which monitor the RF24network and pull off messages that are just
for them. Likewise, the network can raise a signal when there is a new message. Although I would not
want to put that into the library for fear of adding a dependency.
so the finder needs to maintain state
- Waiting: Waiting for a finder request
- Sending: In the midst of looping through children
Needs to have some delay between each send. So the finder has a timer component.
Also... Reset should also reset the internal copy of the sync data. Sync may need a 'reset' method.

View File

@@ -0,0 +1,29 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
// STL headers
// C headers
// Framework headers
// Library headers
#include <RF24.h>
#include <RF24Network.h>
// Project headers
// This component's header
#include <Globals.h>
#include "WProgram.h"
/****************************************************************************/
HardwareSPI SPI(2);
// Radio on Maple Native w/ Getting Started board
RF24 radio(7,6);
RF24Network network(radio);
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,36 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#ifndef __GLOBALS_H__
#define __GLOBALS_H__
// STL headers
// C headers
// Framework headers
// Library headers
// Project headers
class RF24;
class RF24Network;
extern RF24 radio;
extern RF24Network network;
/**
* Example for how classes should be declared
*/
class Template
{
private:
protected:
public:
};
#endif // __GLOBALS_H__
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,12 @@
SubDir TOP ;
# Set up output directories
LOCATE_TARGET = $(SEARCH_SOURCE)/out/$(TOOLSET) ;
LOCATE_SOURCE = $(LOCATE_TARGET) ;
# Pull in local libraries
SKETCH_LIBS += RF24Network RF24 ;
HDRS += $(HOME)/Source/Arduino/libraries/$(SKETCH_LIBS) ;
# Main output executable
Maple $(SEARCH_SOURCE:B).elf : [ GLOB $(SEARCH_SOURCE) $(HOME)/Source/Arduino/libraries/$(SKETCH_LIBS) : $(MODULE_EXT) ] ;

View File

@@ -0,0 +1,251 @@
MCU = cortex-m3 ;
CHIP = STM32F103ZE ;
BOARD = maple_native ;
#CHIP = at91sam3u4 ;
#BOARD = sam3u-ek ;
if ! $(TOOLSET)
{
TOOLSET = mix ;
Echo "Assuming TOOLSET=mix" ;
}
else if $(TOOLSET) = cs
{
TOOLS_PATH = /opt/cs/arm/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
else if $(TOOLSET) = yagarto
{
TOOLS_PATH = ~/Source/yagarto-4.6.2/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
if $(TOOLSET) = yagarto-install
{
TOOLS_PATH = ~/Source/yagarto/install/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
else if $(TOOLSET) = devkit
{
TOOLS_PATH = /opt/devkitARM/bin ;
TOOLS_ARCH = arm-eabi- ;
}
else if $(TOOLSET) = maple
{
TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ;
TOOLS_ARCH = arm-none-eabi- ;
LINK_DIR = /opt/Maple/Resources/Java/hardware/leaflabs/cores/maple ;
MAPLE_DIR = /opt/Maple/Resources/Java/hardware/leaflabs/cores/maple ;
MAPLE_SUBDIRS = . ;
}
else if $(TOOLSET) = mix
{
TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ;
TOOLS_ARCH = arm-none-eabi- ;
LINKFLAGS += --print-gc-sections ;
}
else if $(TOOLSET) = ports
{
TOOLS_PATH = /opt/local/bin ;
TOOLS_ARCH = arm-none-eabi- ;
}
# Tool locations
CC = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc ;
C++ = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ;
AS = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc -c ;
LINK = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ;
OBJCOPY = $(TOOLS_PATH)/$(TOOLS_ARCH)objcopy ;
DFU = dfu-util ;
# Flags
DEFINES += VECT_TAB_FLASH BOARD_$(BOARD) MCU_$(CHIP) ERROR_LED_PORT=GPIOC ERROR_LED_PIN=15 STM32_HIGH_DENSITY MAPLE_IDE ;
OPTIM = -Os ;
MFLAGS = cpu=$(MCU) thumb arch=armv7-m ;
CCFLAGS = -Wall -Wno-strict-aliasing -Wno-format -m$(MFLAGS) -g -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections ;
C++FLAGS = $(CCFLAGS) -fno-rtti -fno-exceptions ;
LINKFLAGS += -m$(MFLAGS) -Xlinker --gc-sections ;
DFUFLAGS = -a1 -d 0x1eaf:0x0003 -R ;
# Directories
MAPLE_DIR ?= /opt/libmaple ;
MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ;
MAPLE_SUBDIRS ?= libmaple libmaple/usb libmaple/usb/usb_lib wirish wirish/comm wirish/boards ;
SKETCH_DIR = $(HOME)/Source/Maple ;
CORE_DIRS = $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS)/utility ;
HDRS = $(CORE_DIRS) ;
# Modules
MODULE_EXT = *.c *.cpp *.S *.pde *.ino *.test ;
CORE_MODULES = [ GLOB $(CORE_DIRS) : $(MODULE_EXT) ] ;
# Unit test framework
CXXTEST_DIR = $(HOME)/Source/cxxtest ;
CXXTEST_GEN = $(CXXTEST_DIR)/bin/cxxtestgen ;
HDRS += $(CXXTEST_DIR) ;
# Linker script
LINK_DIR ?= $(MAPLE_DIR)/support/ld ;
LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ;
LINKFLAGS += -T$(LINKSCRIPT) -L$(LINK_DIR) ;
rule Pde
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_SOURCE) ;
Clean clean : $(<) ;
}
if ( $(ARDUINO_VERSION) < 100 )
{
ARDUINO_H = WProgram.h ;
}
else
{
ARDUINO_H = Arduino.h ;
}
actions Pde
{
echo "#include <$(ARDUINO_H)>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule C++Pde
{
local _CPP = $(>:B).cpp ;
Pde $(_CPP) : $(>) ;
C++ $(<) : $(_CPP) ;
}
rule TestSuite
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_SOURCE) ;
Clean clean : $(<) ;
}
actions TestSuite
{
$(CXXTEST_GEN) --part $(>) > $(<)
}
rule TestRoot
{
MakeLocate $(<) : $(LOCATE_SOURCE) ;
}
actions TestRoot
{
$(CXXTEST_GEN) --root --error-printer > $(<)
}
rule C++TestSuite
{
local _CPP = $(>:B).cpp ;
TestSuite $(_CPP) : $(>) ;
C++ $(<) : $(_CPP) ;
}
rule Hex
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions Hex
{
$(OBJCOPY) -O ihex $(>) $(<)
}
rule Binary
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
Depends binary : $(<) ;
Clean clean : $(<) ;
}
actions Binary
{
$(OBJCOPY) -O binary $(>) $(<)
}
rule UserObject
{
switch $(>:S)
{
case .S : As $(<) : $(>) ;
case .ino : C++Pde $(<) : $(>) ;
case .pde : C++Pde $(<) : $(>) ;
case .test : C++TestSuite $(<) : $(>) ;
}
}
rule Upload
{
Depends up : $(<) ;
NotFile up ;
Always $(<) ;
}
actions Upload
{
$(MAPLE_DIR)/support/scripts/reset.py
sleep 1
$(DFU) $(DFUFLAGS) -D $(<)
sleep 5
}
rule Login
{
MakeLocate $(<) : $(LOCATE_TARGET) ;
Always $(<) ;
}
actions Login
{
ls > $(<)
screen $(>)
}
# Override base objects rule, so all output can go in the output dir
rule Objects
{
local _i ;
for _i in [ FGristFiles $(<) ]
{
local _b = $(_i:B)$(SUFOBJ) ;
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
Object $(_o) : $(_i) ;
Depends obj : $(_o) ;
}
}
# Override base main rule, so all output can go in the output dir
rule Main
{
# Bring in the map
LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ;
MakeLocate $(<) ;
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
Objects $(>) ;
}
rule Maple
{
Main $(<) : $(>) $(CORE_MODULES) ;
Binary $(<:B).bin : $(<) ;
Upload $(<:B).bin ;
Login login : /dev/tty.usbmodemfa441 ;
}

View File

@@ -0,0 +1,145 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
// STL headers
#include <vector>
#include <string>
#include <iostream>
// C headers
#include <stdlib.h>
// Framework headers
// Library headers
#include <cxxtest/TestSuite.h>
// Project headers
#include <RF24Network.h>
#include <RF24.h>
// This component's header
#include <Sync.h>
#include "WProgram.h"
#include "Globals.h"
using namespace std;
class PingTestSuite: public CxxTest::TestSuite
{
public:
// 'Delay' but update the network for a bit
void net_delay(unsigned long amount)
{
unsigned long start = millis();
while ( millis() - start < amount )
{
network.update();
#if 0
// Is there anything ready for us?
if ( network.available() )
{
// If so, take a look at it
RF24NetworkHeader header;
network.read(header,0,0);
cout << millis() << ": net_delay got " << header.type << " from " << header.from_node << "\r\n";
}
#endif
}
}
void setUp()
{
// Reset remote to initial state
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'R' /*Reset*/);
network.write(header,0,0);
// Wait a bit for the message to take
net_delay(50);
}
void tearDown()
{
net_delay(100);
//cout << "\r\n Complete. Press any key \r\n";
//SerialUSB.read();
}
void testNothing()
{
cout << "\r\n STARTING " << __FUNCTION__ << "\r\n";
}
void testPing()
{
cout << "\r\n STARTING " << __FUNCTION__ << "\r\n";
// Send an echo ping to the other unit
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'E' /*Echo*/);
uint32_t testval = 0x12345678, gotval = 0;
network.write(header,&testval,sizeof(testval));
const unsigned long timeout = 1000;
unsigned long sent_at = millis();
while ( millis() - sent_at < timeout && ! gotval )
{
net_delay(100);
// Is there anything ready for us?
if ( network.available() )
{
// If so, take a look at it
RF24NetworkHeader header;
network.peek(header);
switch (header.type)
{
case 'E':
network.read(header,&gotval,sizeof(gotval));
break;
default:
// Anything else is unexpected, and ergo a test failure
network.read(header,0,0);
gotval = -1;
break;
};
}
}
TS_ASSERT_EQUALS( gotval, testval );
}
void testFinder()
{
cout << "\r\n STARTING " << __FUNCTION__ << "\r\n";
// Send a child finder to the other unit
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'F' /*Echo*/);
uint32_t testval = 0x12345678, gotval = 0;
network.write(header,&testval,sizeof(testval));
const unsigned long timeout = 3000;
unsigned long sent_at = millis();
while ( millis() - sent_at < timeout ) // && ! gotval )
{
network.update();
// Is there anything ready for us?
if ( network.available() )
{
// If so, take a look at it
RF24NetworkHeader header;
network.peek(header);
network.read(header,&gotval,sizeof(gotval));
cout << millis() << ": FINDER " << header.type << " from " << header.from_node << " " << hex << gotval << dec << "\r\n";
}
}
TS_ASSERT_EQUALS( gotval, testval );
}
};
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,12 @@
These unit tests only work on Maple. This test runs on a Maple,
as node #00. One other node is expected on node #01, running the
"unit_rx" sketch, which runs on Arduino.
In the future, it would be interesting to write a test which enumerated
the entire tree. Each node could implement a "child finder", where it
sends a message to each child. Upon receiving the message, each child
sends the message out to ITS children, AND sends a "Hello" to the base node.
This requires a 'F' finder request. For the response, we can re-use
the 'E' echo response. The 'E' echo system presumes that the base is
the requestor and the RX nodes are the responder.

View File

@@ -0,0 +1,123 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
// STL headers
#include <vector>
#include <string>
#include <iostream>
// C headers
#include <stdlib.h>
// Framework headers
// Library headers
#include <cxxtest/TestSuite.h>
// Project headers
#include <RF24Network.h>
#include <RF24.h>
// This component's header
#include <Sync.h>
#include "WProgram.h"
#include "Globals.h"
using namespace std;
class SyncTestSuite: public CxxTest::TestSuite
{
struct sync_data_t
{
uint16_t first;
uint16_t second;
sync_data_t(void): first(1), second(2) {}
};
sync_data_t* p_sync_data;
Sync* pSync;
public:
// 'Delay' but update the network for a bit
void net_delay(unsigned long amount)
{
unsigned long start = millis();
while ( millis() - start < amount )
{
pSync->update();
// Is there anything ready for us?
if ( network.available() )
{
// If so, take a look at it
RF24NetworkHeader header;
network.read(header,0,0);
cout << millis() << ": net_delay got " << header.type << " from " << header.from_node << "\r\n";
}
}
}
void setUp()
{
pSync = new Sync(network);
pSync->begin(/* other node*/ 1);
p_sync_data = new(sync_data_t);
// Reset remote to initial state
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'R' /*Reset*/);
network.write(header,0,0);
// Wait a bit for the message to take
net_delay(200);
}
void tearDown()
{
net_delay(100);
//cout << "\r\n Complete. Press any key \r\n";
//SerialUSB.read();
delete p_sync_data;
delete pSync;
}
void testNoUpdate( void )
{
cout << "\r\n STARTING " << __FUNCTION__ << "\r\n";
pSync->register_me(*p_sync_data);
int i = 10;
while (i--)
pSync->update();
TS_ASSERT_EQUALS(p_sync_data->first,1);
}
void testSync( void )
{
cout << "\r\n STARTING " << __FUNCTION__ << "\r\n";
pSync->register_me(*p_sync_data);
int i = 10;
while (i--)
pSync->update();
const uint16_t testval = 10;
p_sync_data->first = testval;
// wait a little while. During this time, the 'first' value will be propagated
// out to the other unit, it will set the value onto 'second', and it should get
// propagated back.
const unsigned long interval = 1000;
unsigned long sent_at = millis();
while ( millis() - sent_at < interval && p_sync_data->second != testval )
pSync->update();
TS_ASSERT_EQUALS(p_sync_data->second,testval);
}
};
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,77 @@
#ifdef MAPLE_IDE
#include <stdio.h>
#include "wirish.h"
extern void setup(void);
extern void loop(void);
void board_start(const char* program_name)
{
// Set up the LED to steady on
pinMode(BOARD_LED_PIN, OUTPUT);
digitalWrite(BOARD_LED_PIN, HIGH);
// Setup the button as input
pinMode(BOARD_BUTTON_PIN, INPUT);
digitalWrite(BOARD_BUTTON_PIN, HIGH);
SerialUSB.begin();
SerialUSB.println("Press BUT");
// Wait for button press
while ( !isButtonPressed() )
{
}
SerialUSB.println("Welcome!");
SerialUSB.println(program_name);
int i = 11;
while (i--)
{
toggleLED();
delay(50);
}
}
/**
* Custom version of _write, which will print to the USB.
* In order to use it you MUST ADD __attribute__((weak))
* to _write in libmaple/syscalls.c
*/
extern "C" int _write(int file, char * ptr, int len)
{
if ( (file != 1) && (file != 2) )
return 0;
else
SerialUSB.write(ptr,len);
return len;
}
__attribute__((constructor)) __attribute__ ((weak)) void premain()
{
init();
}
__attribute__((weak)) void setup(void)
{
board_start("No program defined");
}
__attribute__((weak)) void loop(void)
{
}
__attribute__((weak)) int main(void)
{
setup();
while (true)
{
loop();
}
return 0;
}
#endif // ifdef MAPLE_IDE
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,43 @@
#include <stdio.h>
#ifndef CXXTEST_RUNNING
#define CXXTEST_RUNNING
#endif
#define _CXXTEST_HAVE_STD
#define _CXXTEST_LONGLONG long long
#include <cxxtest/TestListener.h>
#include <cxxtest/TestTracker.h>
#include <cxxtest/TestRunner.h>
#include <cxxtest/RealDescriptions.h>
#include <cxxtest/TestMain.h>
#include <cxxtest/ErrorPrinter.h>
#include <cxxtest/Root.cpp>
#include <RF24Network_config.h>
#include <RF24Network.h>
#include <RF24.h>
extern void board_start(const char*);
extern RF24Network network;
extern RF24 radio;
int main( void )
{
CxxTest::ErrorPrinter tmp;
while(1)
{
board_start(__FILE__);
SPI.begin();
radio.begin();
network.begin(/* channel */100,/* this node */0);
CxxTest::Main<CxxTest::ErrorPrinter>( tmp, 0, NULL );
printf("Tests complete. Restarting...\r\n");
}
}
const char* CxxTest::RealWorldDescription::_worldName = "cxxtest";
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,129 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
// STL headers
// C headers
// Framework headers
// Library headers
#include "RF24Network.h"
// Project headers
// This component's header
#include <Finder.h>
extern RF24Network network;
// Message buffer space
static uint8_t message[32];
/****************************************************************************/
Finder::Finder(void): this_node(0), state(state_waiting),
last_sent(millis()-interval), child_increment(-1)
{
}
/****************************************************************************/
void Finder::begin(uint16_t _this_node)
{
this_node = _this_node;
if ( ! ( this_node & 07000 ) )
{
// Figure out the address of the first child. e.g. if our node is 045, our
// first child is 0145. So we need to shift 01 up enough places to be the
// highest digit
child_increment = 01;
uint16_t temp = this_node;
while ( temp )
{
child_increment <<= 3;
temp >>= 3;
}
}
printf_P(PSTR("%lu: Node %o increment %o\r\n"),millis(),this_node,child_increment);
}
/****************************************************************************/
void Finder::update(void)
{
// Check the network for traffic
// If we got a new finder request, launch!
if ( network.available() )
{
RF24NetworkHeader header;
network.peek(header);
if ( header.type == 'F' )
{
network.read(header,message,sizeof(message));
uint16_t from = header.from_node;
printf_P(PSTR("%lu: APP Received FINDER request from %o\r\n"),millis(),from);
if ( state == state_sending )
{
printf_P(PSTR("%lu: APP ERROR, already sending a finder request\r\n"),millis());
}
else if ( child_increment == 0xffff )
{
printf_P(PSTR("%lu: APP This app has no children, done.\r\n"),millis());
last_sent = millis() - interval;
state = state_done;
goto finish;
}
else
{
last_sent = millis() - interval;
to_node = this_node + child_increment;
state = state_sending;
goto finish;
}
}
}
// If we're working but not ready, continue
if ( state != state_waiting && millis() - last_sent <= interval )
return;
// If we're working, send!
if ( state == state_sending )
{
RF24NetworkHeader header(to_node,'F');
/*bool ok = */ network.write(header,message,sizeof(message));
last_sent = millis();
to_node += child_increment;
// Done?
if ( to_node > this_node + 5 * child_increment )
{
state = state_done;
goto finish;
}
}
// If we're now done, send the final 'E' back
if ( state == state_done )
{
// Send an 'E' Echo response back to the BASE
RF24NetworkHeader header(00,'E');
network.write(header,message,sizeof(message));
state = state_waiting;
goto finish;
}
finish:
return;
}
/****************************************************************************/
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,42 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#ifndef __FINDER_H__
#define __FINDER_H__
// STL headers
// C headers
// Framework headers
#include <Arduino.h>
// Library headers
// Project headers
/**
* Manage a child-finder request
*/
class Finder
{
private:
uint16_t this_node;
enum state_e { state_none = 0, state_waiting, state_sending, state_done, state_invalid };
state_e state;
static const unsigned long interval = 50;
unsigned long last_sent;
uint16_t to_node;
uint16_t child_increment;
protected:
public:
Finder(void);
void begin(uint16_t);
void update(void);
};
#endif // __FINDER_H__
// vim:cin:ai:sts=2 sw=2 ft=cpp

View File

@@ -0,0 +1,210 @@
# (1) Project Information
PROJECT_LIBS = SPI RF24 RF24Network ;
# (2) Board Information
UPLOAD_PROTOCOL ?= stk500v1 ;
UPLOAD_SPEED ?= 57600 ;
MCU ?= atmega328p ;
F_CPU ?= 16000000 ;
CORE ?= arduino ;
VARIANT ?= standard ;
ARDUINO_VERSION ?= 100 ;
# (3) USB Ports
PORTS = p4 p6 p9 u0 u1 u2 ;
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
PORT_p4 = /dev/tty.usbserial-A40081RP ;
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
PORT_u0 = /dev/ttyUSB0 ;
PORT_u1 = /dev/ttyUSB1 ;
PORT_u2 = /dev/ttyUSB2 ;
# (4) Location of AVR tools
#
# This configuration assumes using avr-tools that were obtained separate from the Arduino
# distribution.
if $(OS) = MACOSX
{
AVR_BIN = /usr/local/avrtools/bin ;
AVR_ETC = /usr/local/avrtools/etc ;
AVR_INCLUDE = /usr/local/avrtools/include ;
}
else
{
AVR_BIN = /usr/bin ;
AVR_INCLUDE = /usr/lib/avr/include ;
AVR_ETC = /etc ;
}
# (5) Directories where Arduino core and libraries are located
ARDUINO_DIR ?= /opt/Arduino ;
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
#
# --------------------------------------------------
# Below this line usually never needs to be modified
#
# Tool locations
CC = $(AVR_BIN)/avr-gcc ;
C++ = $(AVR_BIN)/avr-g++ ;
LINK = $(AVR_BIN)/avr-gcc ;
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
AVRDUDE = $(AVR_BIN)/avrdude ;
# Flags
DEFINES += NODE=$(NODE) F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
OPTIM = -Os ;
CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
# Search everywhere for headers
HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
# Output locations
LOCATE_TARGET = $(F_CPU) ;
LOCATE_SOURCE = $(F_CPU) ;
#
# Custom rules
#
rule GitVersion
{
Always $(<) ;
Depends all : $(<) ;
}
actions GitVersion
{
echo "const char program_version[] = \"\\" > $(<)
git log -1 --pretty=format:%h >> $(<)
echo "\";" >> $(<)
}
GitVersion version.h ;
rule Pde
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_SOURCE) ;
Clean clean : $(<) ;
}
if ( $(ARDUINO_VERSION) < 100 )
{
ARDUINO_H = WProgram.h ;
}
else
{
ARDUINO_H = Arduino.h ;
}
actions Pde
{
echo "#include <$(ARDUINO_H)>" > $(<)
echo "#line 1 \"$(>)\"" >> $(<)
cat $(>) >> $(<)
}
rule C++Pde
{
local _CPP = $(>:B).cpp ;
Pde $(_CPP) : $(>) ;
C++ $(<) : $(_CPP) ;
}
rule UserObject
{
switch $(>:S)
{
case .ino : C++Pde $(<) : $(>) ;
case .pde : C++Pde $(<) : $(>) ;
}
}
rule Objects
{
local _i ;
for _i in [ FGristFiles $(<) ]
{
local _b = $(_i:B)$(SUFOBJ) ;
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
Object $(_o) : $(_i) ;
Depends obj : $(_o) ;
}
}
rule Main
{
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
Objects $(>) ;
}
rule Hex
{
Depends $(<) : $(>) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
Depends hex : $(<) ;
Clean clean : $(<) ;
}
actions Hex
{
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
}
rule Upload
{
Depends $(1) : $(2) ;
Depends $(2) : $(3) ;
NotFile $(1) ;
Always $(1) ;
Always $(2) ;
UploadAction $(2) : $(3) ;
}
actions UploadAction
{
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
}
#
# Targets
#
# Grab everything from the core directory
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
# can specify specific modules to pick up in PROJECT_MODULES
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
# Grab everything from the current dir
PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ;
# Main output executable
MAIN = $(PWD:B).elf ;
Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
Hex $(MAIN:B).hex : $(MAIN) ;
# Upload targets
for _p in $(PORTS)
{
Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ;
}

View File

@@ -0,0 +1,19 @@
This is the 'receiver' for the unit tests. Run it on a node which
is NOT under test.
TODO
Send finder request needs a re-think. It needs to be re-implemented as a Tictocs::Timer, so it
doesn't block the loop().
I could also make Tictocs objects which monitor the RF24network and pull off messages that are just
for them. Likewise, the network can raise a signal when there is a new message. Although I would not
want to put that into the library for fear of adding a dependency.
so the finder needs to maintain state
- Waiting: Waiting for a finder request
- Sending: In the midst of looping through children
Needs to have some delay between each send. So the finder has a timer component.
Also... Reset should also reset the internal copy of the sync data. Sync may need a 'reset' method.

View File

@@ -0,0 +1,31 @@
/*
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/**
* @file printf.h
*
* Setup necessary to direct stdout to the Arduino Serial library, which
* enables 'printf'
*/
#ifndef __PRINTF_H__
#define __PRINTF_H__
int serial_putc( char c, FILE * )
{
Serial.write( c );
return c;
}
void printf_begin(void)
{
fdevopen( &serial_putc, 0 );
}
#endif // __PRINTF_H__

View File

@@ -0,0 +1,135 @@
/*
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/**
* Receiver for unit tests.
*/
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Sync.h>
#include "Finder.h"
#include "printf.h"
// nRF24L01(+) radio attached to SPI and pins 8 & 9
RF24 radio(8,9);
// Network uses that radio
RF24Network network(radio);
// Syncronizer
Sync sync(network);
// Address of our node
#if NODE > 0
const uint16_t this_node = NODE;
#else
const uint16_t this_node = 1;
#endif
// Address of the other node
const uint16_t other_node = 0;
// Data to be synchronized
struct sync_data_t
{
uint16_t first;
uint16_t second;
sync_data_t(void): first(1), second(2) {}
};
sync_data_t sync_data;
// Old value of 'first'
uint16_t old_first;
// Message buffer space
uint8_t message[32];
void send_finder_request(void);
void net_delay(unsigned long amount);
Finder finder;
void setup(void)
{
Serial.begin(57600);
Serial.println("RF24Network/test/unit_rx/");
printf_begin();
SPI.begin();
radio.begin();
network.begin(/*channel*/ 100, /*node address*/ this_node);
finder.begin(this_node);
sync.register_me(sync_data);
old_first = sync_data.first;
}
void loop(void)
{
// Pump the network regularly
sync.update();
// Stay on the lookout for finder messages
finder.update();
// Have the values changed?
if ( old_first != sync_data.first )
{
printf_P(PSTR("%lu: APP Updated first to %u\n\r"),millis(),sync_data.first);
// Move the first value over to the second
sync_data.second = sync_data.first;
// And remember the change for next time
old_first = sync_data.first;
}
// Are there any messages for us?
while ( network.available() )
{
uint16_t from;
// If so, take a look at it
RF24NetworkHeader header;
network.peek(header);
// Dispatch the message to the correct handler.
switch (header.type)
{
// Reset to initial state
case 'R':
network.read(header,0,0);
printf_P(PSTR("%lu: APP Reset to initial state\n\r"),millis());
sync_data = sync_data_t();
old_first = sync_data.first;
sync.reset();
break;
// Echo back to the sender.
case 'E':
network.read(header,message,sizeof(message));
from = header.from_node;
printf_P(PSTR("%lu: APP Received ECHO request from %o\n\r"),millis(),from);
network.write(header = RF24NetworkHeader(from,'E'),message,sizeof(message));
break;
// Unrecognized message type
default:
printf_P(PSTR("*** WARNING *** Unknown message type %c\n\r"),header.type);
network.read(header,0,0);
break;
};
}
}
// vim:ai:cin:sts=2 sw=2 ft=cpp