switch to setup for Arduino Boards Manager

This commit is contained in:
Erik Tylek Kettenburg
2015-06-23 12:42:35 -07:00
parent bc55c9bb45
commit 6ca6b114d5
3581 changed files with 93 additions and 51 deletions

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