diff --git a/.directory b/.directory new file mode 100644 index 00000000..156022d6 --- /dev/null +++ b/.directory @@ -0,0 +1,6 @@ +[Dolphin] +Timestamp=2014,5,12,14,1,15 +Version=3 + +[Settings] +HiddenFilesShown=true diff --git a/README.md b/README.md index c0e71c09..dc8fa315 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ +MSP-RF24 +=============== + +Source code for a remote controller using a msp430g2553 and a nrf24l01 from nordic, + +* [Original Repo.](http://maniacbug.github.com/RF24) +* [LIBEMB Repo.](https://github.com/wendlers/libemb/tree/msp430-port) +This library was precompiled and is included in this project just for the serial communication task. +Some changes were done in order to allow serial compatibilty for every msp430 clock freqencies. (Most recent commit already has this change). + + # Arduino driver for nRF24L01 2.4GHz Wireless Transceiver Design Goals: This library is designed to be... diff --git a/examples/GettingStarted/GettingStarted.pde b/examples/GettingStarted/GettingStarted.pde deleted file mode 100644 index bf1851ac..00000000 --- a/examples/GettingStarted/GettingStarted.pde +++ /dev/null @@ -1,227 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example for Getting Started with nRF24L01+ radios. - * - * This is an example of how to use the RF24 class. Write this sketch to two - * different nodes. Put one of the nodes into 'transmit' mode by connecting - * with the serial monitor and sending a 'T'. The ping node sends the current - * time to the pong node, which responds by sending the value back. The ping - * node can then see how long the whole cycle took. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// -// Topology -// - -// Radio pipe addresses for the 2 nodes to communicate. -const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. -// - -// The various roles supported by this sketch -typedef enum { role_ping_out = 1, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role = role_pong_back; - -void setup(void) -{ - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/GettingStarted/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // optionally, increase the delay between retries & # of retries - radio.setRetries(15,15); - - // optionally, reduce the payload size. seems to - // improve reliability - //radio.setPayloadSize(8); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens two pipes for these two nodes to communicate - // back and forth. - // Open 'our' pipe for writing - // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - - //if ( role == role_ping_out ) - { - //radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - //else - { - //radio.openWritingPipe(pipes[1]); - //radio.openReadingPipe(1,pipes[0]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - bool ok = radio.write( &time, sizeof(unsigned long) ); - - if (ok) - printf("ok..."); - else - printf("failed.\n\r"); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout (250ms) - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 200 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\n\r"); - } - else - { - // Grab the response, compare, and send to debugging spew - unsigned long got_time; - radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); - } - - // Try again 1s later - delay(1000); - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - - if ( role == role_pong_back ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got payload %lu...",got_time); - - // Delay just a little bit to let the other unit - // make the transition to receiver - delay(20); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); - printf("Sent response.\n\r"); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } - } - - // - // Change roles - // - - if ( Serial.available() ) - { - char c = toupper(Serial.read()); - if ( c == 'T' && role == role_pong_back ) - { - printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); - - // Become the primary transmitter (ping out) - role = role_ping_out; - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - else if ( c == 'R' && role == role_ping_out ) - { - printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); - - // Become the primary receiver (pong back) - role = role_pong_back; - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1,pipes[0]); - } - } -} -// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/examples/GettingStarted/Jamfile b/examples/GettingStarted/Jamfile deleted file mode 100644 index 9a5f2c47..00000000 --- a/examples/GettingStarted/Jamfile +++ /dev/null @@ -1,210 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = SPI RF24 ; - -# (2) Board Information - -UPLOAD_PROTOCOL ?= arduino ; -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 += 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 ; -} diff --git a/examples/GettingStarted/printf.h b/examples/GettingStarted/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/GettingStarted/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/led_remote/Jamfile b/examples/led_remote/Jamfile deleted file mode 100644 index 901f8da8..00000000 --- a/examples/led_remote/Jamfile +++ /dev/null @@ -1,206 +0,0 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; - -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; - -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; - -# Host-specific overrides for locations -if $(OS) = MACOSX -{ -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; -} - -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; -ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; -SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; - -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; - -# Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; - -# 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) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; - -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; - -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; - -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; - -rule GitVersion -{ - Always $(<) ; - Depends all : $(<) ; -} - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/led_remote/led_remote.pde b/examples/led_remote/led_remote.pde deleted file mode 100644 index 80e29557..00000000 --- a/examples/led_remote/led_remote.pde +++ /dev/null @@ -1,255 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example LED Remote - * - * This is an example of how to use the RF24 class to control a remote - * bank of LED's using buttons on a remote control. - * - * On the 'remote', connect any number of buttons or switches from - * an arduino pin to ground. Update 'button_pins' to reflect the - * pins used. - * - * On the 'led' board, connect the same number of LED's from an - * arduino pin to a resistor to ground. Update 'led_pins' to reflect - * the pins used. Also connect a separate pin to ground and change - * the 'role_pin'. This tells the sketch it's running on the LED board. - * - * Every time the buttons change on the remote, the entire state of - * buttons is send to the led board, which displays the state. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver -// Leave open to be the 'remote' transmitter -const int role_pin = A4; - -// Pins on the remote for buttons -const uint8_t button_pins[] = { 2,3,4,5,6,7 }; -const uint8_t num_button_pins = sizeof(button_pins); - -// Pins on the LED board for LED's -const uint8_t led_pins[] = { 2,3,4,5,6,7 }; -const uint8_t num_led_pins = sizeof(led_pins); - -// -// Topology -// - -// Single radio pipe address for the 2 nodes to communicate. -const uint64_t pipe = 0xE8E8F0F0E1LL; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes in this -// system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_remote = 1, role_led } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Remote", "LED Board"}; - -// The role of the current running sketch -role_e role; - -// -// Payload -// - -uint8_t button_states[num_button_pins]; -uint8_t led_states[num_led_pins]; - -// -// Setup -// - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_remote; - else - role = role_led; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/led_remote/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens a single pipes for these two nodes to communicate - // back and forth. One listens on it, the other talks to it. - - if ( role == role_remote ) - { - radio.openWritingPipe(pipe); - } - else - { - radio.openReadingPipe(1,pipe); - } - - // - // Start listening - // - - if ( role == role_led ) - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); - - // - // Set up buttons / LED's - // - - // Set pull-up resistors for all buttons - if ( role == role_remote ) - { - int i = num_button_pins; - while(i--) - { - pinMode(button_pins[i],INPUT); - digitalWrite(button_pins[i],HIGH); - } - } - - // Turn LED's ON until we start getting keys - if ( role == role_led ) - { - int i = num_led_pins; - while(i--) - { - pinMode(led_pins[i],OUTPUT); - led_states[i] = HIGH; - digitalWrite(led_pins[i],led_states[i]); - } - } - -} - -// -// Loop -// - -void loop(void) -{ - // - // Remote role. If the state of any button has changed, send the whole state of - // all buttons. - // - - if ( role == role_remote ) - { - // Get the current state of buttons, and - // Test if the current state is different from the last state we sent - int i = num_button_pins; - bool different = false; - while(i--) - { - uint8_t state = ! digitalRead(button_pins[i]); - if ( state != button_states[i] ) - { - different = true; - button_states[i] = state; - } - } - - // Send the state of the buttons to the LED board - if ( different ) - { - printf("Now sending..."); - bool ok = radio.write( button_states, num_button_pins ); - if (ok) - printf("ok\n\r"); - else - printf("failed\n\r"); - } - - // Try again in a short while - delay(20); - } - - // - // LED role. Receive the state of all buttons, and reflect that in the LEDs - // - - if ( role == role_led ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( button_states, num_button_pins ); - - // Spew it - printf("Got buttons\n\r"); - - // For each button, if the button now on, then toggle the LED - int i = num_led_pins; - while(i--) - { - if ( button_states[i] ) - { - led_states[i] ^= HIGH; - digitalWrite(led_pins[i],led_states[i]); - } - } - } - } - } -} -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/led_remote/printf.h b/examples/led_remote/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/led_remote/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/nordic_fob/Jamfile b/examples/nordic_fob/Jamfile deleted file mode 100644 index ec519f7c..00000000 --- a/examples/nordic_fob/Jamfile +++ /dev/null @@ -1,219 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = RF24 SPI ; -PROJECT_DIRS = $(PWD) ; - -# (2) Board Information - -UPLOAD_PROTOCOL ?= stk500v1 ; -UPLOAD_SPEED ?= 115200 ; -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 ; -AR = $(AVR_BIN)/avr-ar rcs ; -RANLIB = ; -OBJCOPY = $(AVR_BIN)/avr-objcopy ; -AVRDUDE = $(AVR_BIN)/avrdude ; - -# Flags - -DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -OPTIM = -Os ; -CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -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 = $(PROJECT_DIRS) $(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 Library -{ - LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; - Objects $(>) ; -} - -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 -} - -rule Arduino -{ - LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; - Main $(<) : $(>) ; - LinkLibraries $(<) : libs core ; - Hex $(<:B).hex : $(<) ; - for _p in $(PORTS) - { - Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; - } -} - -# -# Targets -# - -# Grab everything from the core directory -Library core : [ 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 -Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; - -# Main output executable -Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; diff --git a/examples/nordic_fob/nordic_fob.pde b/examples/nordic_fob/nordic_fob.pde deleted file mode 100644 index 5a316a0f..00000000 --- a/examples/nordic_fob/nordic_fob.pde +++ /dev/null @@ -1,142 +0,0 @@ -/* - Copyright (C) 2012 J. Coliz - - 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. - */ - -/** - * Example Nordic FOB Receiver - * - * This is an example of how to use the RF24 class to receive signals from the - * Sparkfun Nordic FOB. Thanks to Kirk Mower for providing test hardware. - * - * See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/ - */ - -#include -#include -#include "nRF24L01.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// -// Payload -// - -struct payload_t -{ - uint8_t buttons; - uint16_t id; - uint8_t empty; -}; - -const char* button_names[] = { "Up", "Down", "Left", "Right", "Center" }; -const int num_buttons = 5; - -// -// Forward declarations -// - -uint16_t flip_endian(uint16_t in); - -// -// Setup -// - -void setup(void) -{ - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\r\nRF24/examples/nordic_fob/\r\n"); - - // - // Setup and configure rf radio according to the built-in parameters - // of the FOB. - // - - radio.begin(); - radio.setChannel(2); - radio.setPayloadSize(4); - radio.setAutoAck(false); - radio.setCRCLength(RF24_CRC_8); - radio.openReadingPipe(1,0xE7E7E7E7E7LL); - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -// -// Loop -// - -void loop(void) -{ - // - // Receive each packet, dump it out - // - - // if there is data ready - if ( radio.available() ) - { - // Get the packet from the radio - payload_t payload; - radio.read( &payload, sizeof(payload) ); - - // Print the ID of this message. Note that the message - // is sent 'big-endian', so we have to flip it. - printf("#%05u Buttons ",flip_endian(payload.id)); - - // Print the name of each button - int i = num_buttons; - while (i--) - { - if ( ! ( payload.buttons & _BV(i) ) ) - { - printf("%s ",button_names[i]); - } - } - - // If no buttons, print None - if ( payload.buttons == _BV(num_buttons) - 1 ) - printf("None"); - - printf("\r\n"); - } -} - -// -// Helper functions -// - -// Change a big-endian word into a little-endian -uint16_t flip_endian(uint16_t in) -{ - uint16_t low = in >> 8; - uint16_t high = in << 8; - - return high | low; -} - -// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/examples/nordic_fob/printf.h b/examples/nordic_fob/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/nordic_fob/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/pingpair/Jamfile b/examples/pingpair/Jamfile deleted file mode 100644 index 18244ec8..00000000 --- a/examples/pingpair/Jamfile +++ /dev/null @@ -1,219 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = SPI RF24 ; -PROJECT_DIRS = $(PWD) ; - -# (2) Board Information - -UPLOAD_PROTOCOL ?= arduino ; -UPLOAD_SPEED ?= 115200 ; -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 ; -AR = $(AVR_BIN)/avr-ar rcs ; -RANLIB = ; -OBJCOPY = $(AVR_BIN)/avr-objcopy ; -AVRDUDE ?= $(AVR_BIN)/avrdude ; - -# Flags - -DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -OPTIM = -Os ; -CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -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 = $(PROJECT_DIRS) $(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 Library -{ - LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; - Objects $(>) ; -} - -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 -} - -rule Arduino -{ - LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; - Main $(<) : $(>) ; - LinkLibraries $(<) : core libs ; - Hex $(<:B).hex : $(<) ; - for _p in $(PORTS) - { - Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; - } -} - -# -# Targets -# - -# Grab everything from the core directory -Library core : [ 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 -Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; - -# Main output executable -Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; diff --git a/examples/pingpair/pingpair.pde b/examples/pingpair/pingpair.pde deleted file mode 100644 index 3a57a679..00000000 --- a/examples/pingpair/pingpair.pde +++ /dev/null @@ -1,220 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example RF Radio Ping Pair - * - * This is an example of how to use the RF24 class. Write this sketch to two different nodes, - * connect the role_pin to ground on one. The ping node sends the current time to the pong node, - * which responds by sending the value back. The ping node can then see how long the whole cycle - * took. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const int role_pin = 7; - -// -// Topology -// - -// Radio pipe addresses for the 2 nodes to communicate. -const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_ping_out = 1, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role; - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( ! digitalRead(role_pin) ) - role = role_ping_out; - else - role = role_pong_back; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/pingpair/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // optionally, increase the delay between retries & # of retries - radio.setRetries(15,15); - - // optionally, reduce the payload size. seems to - // improve reliability - radio.setPayloadSize(8); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens two pipes for these two nodes to communicate - // back and forth. - // Open 'our' pipe for writing - // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - - if ( role == role_ping_out ) - { - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - else - { - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1,pipes[0]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - bool ok = radio.write( &time, sizeof(unsigned long) ); - - if (ok) - printf("ok..."); - else - printf("failed.\n\r"); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout (250ms) - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 200 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\n\r"); - } - else - { - // Grab the response, compare, and send to debugging spew - unsigned long got_time; - radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); - } - - // Try again 1s later - delay(1000); - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - - if ( role == role_pong_back ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got payload %lu...",got_time); - - // Delay just a little bit to let the other unit - // make the transition to receiver - delay(20); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); - printf("Sent response.\n\r"); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } - } -} -// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair/printf.h b/examples/pingpair/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/pingpair/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/pingpair_dyn/Jamfile b/examples/pingpair_dyn/Jamfile deleted file mode 100644 index 901f8da8..00000000 --- a/examples/pingpair_dyn/Jamfile +++ /dev/null @@ -1,206 +0,0 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; - -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; - -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; - -# Host-specific overrides for locations -if $(OS) = MACOSX -{ -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; -} - -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; -ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; -SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; - -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; - -# Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; - -# 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) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; - -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; - -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; - -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; - -rule GitVersion -{ - Always $(<) ; - Depends all : $(<) ; -} - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/pingpair_dyn/pingpair_dyn.pde b/examples/pingpair_dyn/pingpair_dyn.pde deleted file mode 100644 index 7108f3bf..00000000 --- a/examples/pingpair_dyn/pingpair_dyn.pde +++ /dev/null @@ -1,232 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example using Dynamic Payloads - * - * This is an example of how to use payloads of a varying (dynamic) size. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const int role_pin = 7; - -// -// Topology -// - -// Radio pipe addresses for the 2 nodes to communicate. -const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_ping_out = 1, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role; - -// -// Payload -// - -const int min_payload_size = 4; -const int max_payload_size = 32; -const int payload_size_increments_by = 2; -int next_payload_size = min_payload_size; - -char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_ping_out; - else - role = role_pong_back; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/pingpair_dyn/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // enable dynamic payloads - radio.enableDynamicPayloads(); - - // optionally, increase the delay between retries & # of retries - radio.setRetries(15,15); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens two pipes for these two nodes to communicate - // back and forth. - // Open 'our' pipe for writing - // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - - if ( role == role_ping_out ) - { - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - else - { - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1,pipes[0]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - // The payload will always be the same, what will change is how much of it we send. - static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012"; - - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - printf("Now sending length %i...",next_payload_size); - radio.write( send_payload, next_payload_size ); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 500 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\n\r"); - } - else - { - // Grab the response, compare, and send to debugging spew - uint8_t len = radio.getDynamicPayloadSize(); - radio.read( receive_payload, len ); - - // Put a zero at the end for easy printing - receive_payload[len] = 0; - - // Spew it - printf("Got response size=%i value=%s\n\r",len,receive_payload); - } - - // Update size for next time. - next_payload_size += payload_size_increments_by; - if ( next_payload_size > max_payload_size ) - next_payload_size = min_payload_size; - - // Try again 1s later - delay(1000); - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - - if ( role == role_pong_back ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - uint8_t len; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - len = radio.getDynamicPayloadSize(); - done = radio.read( receive_payload, len ); - - // Put a zero at the end for easy printing - receive_payload[len] = 0; - - // Spew it - printf("Got payload size=%i value=%s\n\r",len,receive_payload); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Send the final one back. - radio.write( receive_payload, len ); - printf("Sent response.\n\r"); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } - } -} -// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair_dyn/printf.h b/examples/pingpair_dyn/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/pingpair_dyn/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/pingpair_irq/Jamfile b/examples/pingpair_irq/Jamfile deleted file mode 100644 index 97237bc8..00000000 --- a/examples/pingpair_irq/Jamfile +++ /dev/null @@ -1,219 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = SPI RF24 ; -PROJECT_DIRS = $(PWD) ; - -# (2) Board Information - -UPLOAD_PROTOCOL ?= arduino ; -UPLOAD_SPEED ?= 115200 ; -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 ; -AR = $(AVR_BIN)/avr-ar rcs ; -RANLIB = ; -OBJCOPY = $(AVR_BIN)/avr-objcopy ; -AVRDUDE ?= $(AVR_BIN)/avrdude ; - -# Flags - -DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -OPTIM = -Os ; -CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -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 = $(PROJECT_DIRS) $(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 Library -{ - LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; - Objects $(>) ; -} - -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 -} - -rule Arduino -{ - LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; - Main $(<) : $(>) ; - LinkLibraries $(<) : core libs ; - Hex $(<:B).hex : $(<) ; - for _p in $(PORTS) - { - Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; - } -} - -# -# Targets -# - -# Grab everything from the core directory -Library core : [ 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 -Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; - -# Main output executable -Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; diff --git a/examples/pingpair_irq/pingpair_irq.pde b/examples/pingpair_irq/pingpair_irq.pde deleted file mode 100644 index 47084a1f..00000000 --- a/examples/pingpair_irq/pingpair_irq.pde +++ /dev/null @@ -1,216 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example of using interrupts - * - * This is an example of how to user interrupts to interact with the radio. - * It builds on the pingpair_pl example, and uses ack payloads. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(8,9); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const short role_pin = 7; - -// -// Topology -// - -// Single radio pipe address for the 2 nodes to communicate. -const uint64_t pipe = 0xE8E8F0F0E1LL; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes in this -// system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_sender = 1, role_receiver } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; - -// The role of the current running sketch -role_e role; - -// Interrupt handler, check the radio because we got an IRQ -void check_radio(void); - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_sender; - else - role = role_receiver; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/pingpair_irq/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // We will be using the Ack Payload feature, so please enable it - radio.enableAckPayload(); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens a single pipe for these two nodes to communicate - // back and forth. One listens on it, the other talks to it. - - if ( role == role_sender ) - { - radio.openWritingPipe(pipe); - } - else - { - radio.openReadingPipe(1,pipe); - } - - // - // Start listening - // - - if ( role == role_receiver ) - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); - - // - // Attach interrupt handler to interrupt #0 (using pin 2) - // on BOTH the sender and receiver - // - - attachInterrupt(0, check_radio, FALLING); -} - -static uint32_t message_count = 0; - -void loop(void) -{ - // - // Sender role. Repeatedly send the current time - // - - if (role == role_sender) - { - // Take the time, and send it. - unsigned long time = millis(); - printf("Now sending %lu\n\r",time); - radio.startWrite( &time, sizeof(unsigned long) ); - - // Try again soon - delay(2000); - } - - // - // Receiver role: Does nothing! All the work is in IRQ - // - -} - -void check_radio(void) -{ - // What happened? - bool tx,fail,rx; - radio.whatHappened(tx,fail,rx); - - // Have we successfully transmitted? - if ( tx ) - { - if ( role == role_sender ) - printf("Send:OK\n\r"); - - if ( role == role_receiver ) - printf("Ack Payload:Sent\n\r"); - } - - // Have we failed to transmit? - if ( fail ) - { - if ( role == role_sender ) - printf("Send:Failed\n\r"); - - if ( role == role_receiver ) - printf("Ack Payload:Failed\n\r"); - } - - // Transmitter can power down for now, because - // the transmission is done. - if ( ( tx || fail ) && ( role == role_sender ) ) - radio.powerDown(); - - // Did we receive a message? - if ( rx ) - { - // If we're the sender, we've received an ack payload - if ( role == role_sender ) - { - radio.read(&message_count,sizeof(message_count)); - printf("Ack:%lu\n\r",message_count); - } - - // If we're the receiver, we've received a time message - if ( role == role_receiver ) - { - // Get this payload and dump it - static unsigned long got_time; - radio.read( &got_time, sizeof(got_time) ); - printf("Got payload %lu\n\r",got_time); - - // Add an ack packet for the next time around. This is a simple - // packet counter - radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); - ++message_count; - } - } -} - -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair_irq/printf.h b/examples/pingpair_irq/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/pingpair_irq/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/pingpair_maple/Jamfile b/examples/pingpair_maple/Jamfile deleted file mode 100644 index 798096cc..00000000 --- a/examples/pingpair_maple/Jamfile +++ /dev/null @@ -1,182 +0,0 @@ -MCU = cortex-m3 ; -CHIP = STM32F103ZE ; -BOARD = maple_native ; - -#CHIP = at91sam3u4 ; -#BOARD = sam3u-ek ; - -if ! $(TOOLSET) -{ - TOOLSET = devkit ; - Echo "Assuming TOOLSET=devkit" ; -} - -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- ; -} -else if $(TOOLSET) = ports -{ - TOOLS_PATH = /opt/local/bin ; - TOOLS_ARCH = arm-none-eabi- ; -} - -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 ; - -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 -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 ; - -MAPLE_DIR = $(HOME)/Source/SAM3U/libmaple ; -MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ; -MAPLE_SUBDIRS = wirish wirish/comm wirish/boards libmaple libmaple/usb libmaple/usb/usb_lib ; - -SKETCH_DIR = $(HOME)/Source/Arduino ; -SKETCH_LIBS = RF24 ; - -MODULE_DIRS = . $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) $(SKETCH_DIR)/libraries/$(SKETCH_LIBS) ; -HDRS = $(MODULE_DIRS) ; -LOCATE_TARGET = out/$(TOOLSET) ; -LOCATE_SOURCE = $(LOCATE_TARGET) ; - -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 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 $(<) : $(>) ; - } -} - -rule Upload -{ - Depends up : $(<) ; - NotFile up ; - Always $(<) ; - Always up ; -} - -actions Upload -{ - $(DFU) $(DFUFLAGS) -D $(<) -} - -# 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 -{ - MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; - Objects $(>) ; -} - -# Modules -MODULES = [ GLOB $(MODULE_DIRS) : *.pde *.c *.cpp *.S ] ; - -# Main output executable -MAIN = $(PWD:B).elf ; - -# Linker script -LINK_DIR = $(MAPLE_DIR)/support/ld ; -LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ; - -# Bring in the map and link script -LINKFLAGS += -Wl,-Map=$(LOCATE_TARGET)/$(MAIN:B).map -T$(LINKSCRIPT) -L$(LINK_DIR) ; - -Main $(MAIN) : $(MODULES) ; -Binary $(MAIN:B).bin : $(MAIN) ; -Upload $(MAIN:B).bin ; diff --git a/examples/pingpair_maple/main.cpp b/examples/pingpair_maple/main.cpp deleted file mode 100644 index b4f976d3..00000000 --- a/examples/pingpair_maple/main.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#ifdef MAPLE_IDE - -#include -#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; -} - -/** - * Re-entrant version of _write. Yagarto and Devkit now use - * the re-entrant newlib, so these get called instead of the - * non_r versions. - */ -extern "C" int _write_r (void*, int file, char * ptr, int len) -{ - return _write( file, ptr, 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 diff --git a/examples/pingpair_maple/pingpair_maple.pde b/examples/pingpair_maple/pingpair_maple.pde deleted file mode 100644 index 2d3925b7..00000000 --- a/examples/pingpair_maple/pingpair_maple.pde +++ /dev/null @@ -1,242 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example RF Radio Ping Pair ... for Maple - * - * This is an example of how to use the RF24 class. Write this sketch to two different nodes, - * connect the role_pin to ground on one. The ping node sends the current time to the pong node, - * which responds by sending the value back. The ping node can then see how long the whole cycle - * took. - */ - -#include "WProgram.h" -#include -#include "nRF24L01.h" -#include "RF24.h" - -// -// Maple specific setup. Other than this section, the sketch is the same on Maple as on -// Arduino -// - -#ifdef MAPLE_IDE - -// External startup function -extern void board_start(const char* program_name); - -// Use SPI #2. -HardwareSPI SPI(2); - -#else -#define board_startup printf -#define toggleLED(x) (x) -#endif - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 7 & 6 -// (This works for the Getting Started board plugged into the -// Maple Native backwards.) - -RF24 radio(7,6); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const int role_pin = 10; - -// -// Topology -// - -// Radio pipe addresses for the 2 nodes to communicate. -const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_ping_out = 1, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role; - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_ping_out; - else - role = role_pong_back; - - // - // Print preamble - // - - board_start("\n\rRF24/examples/pingpair/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // optionally, increase the delay between retries & # of retries - radio.setRetries(15,15); - - // optionally, reduce the payload size. seems to - // improve reliability - radio.setPayloadSize(8); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens two pipes for these two nodes to communicate - // back and forth. - // Open 'our' pipe for writing - // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - - if ( role == role_ping_out ) - { - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - else - { - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1,pipes[0]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - toggleLED(); - - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - bool ok = radio.write( &time, sizeof(unsigned long) ); - - if (ok) - printf("ok...\r\n"); - else - printf("failed.\r\n"); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout (250ms) - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 200 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\r\n"); - } - else - { - // Grab the response, compare, and send to debugging spew - unsigned long got_time; - radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got response %lu, round-trip delay: %lu\r\n",got_time,millis()-got_time); - } - - toggleLED(); - - // Try again 1s later - delay(1000); - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - - if ( role == role_pong_back ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got payload %lu...",got_time); - - // Delay just a little bit to let the other unit - // make the transition to receiver - delay(20); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); - printf("Sent response.\r\n"); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } - } -} -// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair_pl/Jamfile b/examples/pingpair_pl/Jamfile deleted file mode 100644 index 901f8da8..00000000 --- a/examples/pingpair_pl/Jamfile +++ /dev/null @@ -1,206 +0,0 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; - -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; - -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; - -# Host-specific overrides for locations -if $(OS) = MACOSX -{ -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; -} - -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; -ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; -SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; - -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; - -# Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; - -# 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) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; - -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; - -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; - -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; - -rule GitVersion -{ - Always $(<) ; - Depends all : $(<) ; -} - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/pingpair_pl/pingpair_pl.pde b/examples/pingpair_pl/pingpair_pl.pde deleted file mode 100644 index 70aed6e5..00000000 --- a/examples/pingpair_pl/pingpair_pl.pde +++ /dev/null @@ -1,180 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example of using Ack Payloads - * - * This is an example of how to do two-way communication without changing - * transmit/receive modes. Here, a payload is set to the transmitter within - * the Ack packet of each transmission. Note that the payload is set BEFORE - * the sender's message arrives. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const short role_pin = 7; - -// -// Topology -// - -// Single radio pipe address for the 2 nodes to communicate. -const uint64_t pipe = 0xE8E8F0F0E1LL; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes in this -// system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_sender = 1, role_receiver } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; - -// The role of the current running sketch -role_e role; - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_sender; - else - role = role_receiver; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/pingpair_pl/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // We will be using the Ack Payload feature, so please enable it - radio.enableAckPayload(); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens a single pipes for these two nodes to communicate - // back and forth. One listens on it, the other talks to it. - - if ( role == role_sender ) - { - radio.openWritingPipe(pipe); - } - else - { - radio.openReadingPipe(1,pipe); - } - - // - // Start listening - // - - if ( role == role_receiver ) - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -void loop(void) -{ - static uint32_t message_count = 0; - - // - // Sender role. Repeatedly send the current time - // - - if (role == role_sender) - { - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - - if ( radio.isAckPayloadAvailable() ) - { - radio.read(&message_count,sizeof(message_count)); - printf("Ack: [%lu] ",message_count); - } - printf("OK\n\r"); - - // Try again soon - delay(2000); - } - - // - // Receiver role. Receive each packet, dump it out, add ack payload for next time - // - - if ( role == role_receiver ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - static unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got payload %lu\n",got_time); - } - - // Add an ack packet for the next time around. This is a simple - // packet counter - radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); - ++message_count; - } - } -} -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair_pl/printf.h b/examples/pingpair_pl/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/pingpair_pl/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/pingpair_sleepy/Jamfile b/examples/pingpair_sleepy/Jamfile deleted file mode 100644 index 901f8da8..00000000 --- a/examples/pingpair_sleepy/Jamfile +++ /dev/null @@ -1,206 +0,0 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; - -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; - -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; - -# Host-specific overrides for locations -if $(OS) = MACOSX -{ -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; -} - -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; -ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; -SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; - -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; - -# Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; - -# 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) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; - -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; - -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; - -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; - -rule GitVersion -{ - Always $(<) ; - Depends all : $(<) ; -} - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/pingpair_sleepy/pingpair_sleepy.pde b/examples/pingpair_sleepy/pingpair_sleepy.pde deleted file mode 100644 index 49daa693..00000000 --- a/examples/pingpair_sleepy/pingpair_sleepy.pde +++ /dev/null @@ -1,288 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example RF Radio Ping Pair which Sleeps between Sends - * - * This is an example of how to use the RF24 class to create a battery- - * efficient system. It is just like the pingpair.pde example, but the - * ping node powers down the radio and sleeps the MCU after every - * ping/pong cycle. - * - * As with the pingpair.pde example, write this sketch to two different nodes, - * connect the role_pin to ground on one. The ping node sends the current - * time to the pong node, which responds by sending the value back. The ping - * node can then see how long the whole cycle took. - */ - -#include -#include -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const int role_pin = 7; - -// -// Topology -// - -// Radio pipe addresses for the 2 nodes to communicate. -const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_ping_out = 1, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role; - -// -// Sleep declarations -// - -typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s } wdt_prescalar_e; - -void setup_watchdog(uint8_t prescalar); -void do_sleep(void); - -const short sleep_cycles_per_transmission = 4; -volatile short sleep_cycles_remaining = sleep_cycles_per_transmission; - -// -// Normal operation -// - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_ping_out; - else - role = role_pong_back; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/pingpair_sleepy/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Prepare sleep parameters - // - - // Only the ping out role sleeps. Wake up every 4s to send a ping - if ( role == role_ping_out ) - setup_watchdog(wdt_1s); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens two pipes for these two nodes to communicate - // back and forth. - // Open 'our' pipe for writing - // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - - if ( role == role_ping_out ) - { - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - else - { - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1,pipes[0]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout (250ms) - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 250 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\n\r"); - } - else - { - // Grab the response, compare, and send to debugging spew - unsigned long got_time; - radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); - } - - // - // Shut down the system - // - - // Experiment with some delay here to see if it has an effect - delay(500); - - // Power down the radio. Note that the radio will get powered back up - // on the next write() call. - radio.powerDown(); - - // Sleep the MCU. The watchdog timer will awaken in a short while, and - // continue execution here. - while( sleep_cycles_remaining ) - do_sleep(); - - sleep_cycles_remaining = sleep_cycles_per_transmission; - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - // This is untouched from the pingpair example. - // - - if ( role == role_pong_back ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it. Include our time, because the ping_out millis counter is unreliable - // due to it sleeping - printf("Got payload %lu @ %lu...",got_time,millis()); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); - printf("Sent response.\n\r"); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } - } -} - -// -// Sleep helpers -// - -// 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms -// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec - -void setup_watchdog(uint8_t prescalar) -{ - prescalar = min(9,prescalar); - uint8_t wdtcsr = prescalar & 7; - if ( prescalar & 8 ) - wdtcsr |= _BV(WDP3); - - MCUSR &= ~_BV(WDRF); - WDTCSR = _BV(WDCE) | _BV(WDE); - WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); -} - -ISR(WDT_vect) -{ - --sleep_cycles_remaining; -} - -void do_sleep(void) -{ - set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here - sleep_enable(); - - sleep_mode(); // System sleeps here - - sleep_disable(); // System continues execution here when watchdog timed out -} - -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair_sleepy/printf.h b/examples/pingpair_sleepy/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/pingpair_sleepy/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/scanner/Jamfile b/examples/scanner/Jamfile deleted file mode 100644 index 1bf541e6..00000000 --- a/examples/scanner/Jamfile +++ /dev/null @@ -1,210 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = SPI RF24 ; - -# (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 += 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 ; -} diff --git a/examples/scanner/output/core.a b/examples/scanner/output/core.a deleted file mode 100644 index 6ae105d9..00000000 Binary files a/examples/scanner/output/core.a and /dev/null differ diff --git a/examples/scanner/output/scanner.cpp b/examples/scanner/output/scanner.cpp deleted file mode 100644 index 5eb1627a..00000000 --- a/examples/scanner/output/scanner.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include -#line 1 "scanner.pde" - -/* - Copyright (C) 2011 James Coliz, Jr. - - 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. - */ - -/** - * Channel scanner - * - * Example to detect interference on the various channels available. - * This is a good diagnostic tool to check whether you're picking a - * good channel for your application. - * - * Inspired by cpixip. - * See http://arduino.cc/forum/index.php/topic,54795.0.html - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 8 & 9 - -RF24 radio(8,9); - -// -// Channel info -// - -const short num_channels = 128; -short values[num_channels]; - -// -// Setup -// - -void setup(void) -{ - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/scanner/\n\r"); - - // - // Setup and configure rf radio - // - - radio.begin(); - radio.setAutoAck(false); - - // Get into standby mode - radio.startListening(); - radio.stopListening(); - - // Print out header, high then low digit - int i = 0; - while ( i < num_channels ) - { - printf("%x",i>>4); - ++i; - } - printf("\n\r"); - i = 0; - while ( i < num_channels ) - { - printf("%x",i&0xf); - ++i; - } - printf("\n\r"); -} - -// -// Loop -// - -const short num_reps = 100; - -void loop(void) -{ - // Clear measurement values - memset(values,0,num_channels); - - // Scan all channels num_reps times - int rep_counter = num_reps; - while (rep_counter--) - { - int i = num_channels; - while (i--) - { - // Select this channel - radio.setChannel(i); - - // Listen for a little - radio.startListening(); - delayMicroseconds(128); - radio.stopListening(); - - // Did we get a carrier? - if ( radio.testCarrier() ) - ++values[i]; - } - } - - // Print out channel measurements, clamped to a single hex digit - int i = 0; - while ( i < num_channels ) - { - printf("%x",min(0xf,values[i]&0xf)); - ++i; - } - printf("\n\r"); -} - - -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/scanner/output/scanner.elf b/examples/scanner/output/scanner.elf deleted file mode 100755 index 5e0f4b15..00000000 Binary files a/examples/scanner/output/scanner.elf and /dev/null differ diff --git a/examples/scanner/output/scanner.hex b/examples/scanner/output/scanner.hex deleted file mode 100644 index 00a3175e..00000000 --- a/examples/scanner/output/scanner.hex +++ /dev/null @@ -1,325 +0,0 @@ -:100000000C9463000C948B000C948B000C948B006C -:100010000C948B000C948B000C948B000C948B0034 -:100020000C948B000C948B000C948B000C948B0024 -:100030000C948B000C948B000C948B000C948B0014 -:100040000C948F050C948B000C9423060C948B005D -:100050000C948B000C948B000C948B000C948B00F4 -:100060000C948B000C948B000000000024002700EF -:100070002A0000000000250028002B0000000000DE -:1000800023002600290004040404040404040202DA -:100090000202020203030303030301020408102007 -:1000A0004080010204081020010204081020000012 -:1000B0000007000201000003040600000000000029 -:1000C000000090043B0711241FBECFEFD8E0DEBF35 -:1000D000CDBF11E0A0E0B1E0E6EFF3E102C0059092 -:1000E0000D92AA33B107D9F712E0AAE3B1E001C03B -:1000F0001D92A13FB107E1F710E0C6ECD0E004C0CB -:100100002297FE010E94F509C23CD107C9F70E945F -:100110001C060C94F9090C9400000F931F93CF93C5 -:10012000DF938C01EB01009731F46115710519F42F -:1001300020E030E038C081E090E06EE070E00E94A6 -:10014000CB02FC019C01009771F180E8838320972A -:1001500071F0D387C28781E883838091E702909111 -:10016000E802892B21F4F093E802E093E7020115FD -:100170001105C9F011870087838182608383809194 -:10018000E9029091EA02892B71F4F093EA02E0937C -:10019000E9028091EB029091EC02892B21F4F0931B -:1001A000EC02E093EB02C901DF91CF911F910F9117 -:1001B0000895A0E0B0E0EFEDF0E00C94CC09FE0172 -:1001C0003596619171918091E9029091EA02AF01B7 -:1001D0000E94EE002096E2E00C94E809ABE0B0E06B -:1001E000E4EFF0E00C94BC093C012B015A01FC0146 -:1001F00017821682838181FD03C06FEF7FEFC6C136 -:100200009AE0892E1E010894211C311CF3012381E0 -:10021000F20123FD859123FF81912F01882309F4A9 -:10022000B2C1853239F423FD859123FF81912F01DD -:10023000853229F490E0B3010E940604E7CF982F9D -:10024000FF24EE249924FFE1FF15D0F09B3269F0E2 -:100250009C3228F4903259F0933291F40EC09D32C2 -:1002600049F0903369F441E024C052E0F52A84E07B -:10027000F82A28C098E0F92A25C0E0E1FE2A22C029 -:10028000F7FC29C0892F80538A3070F4F6FE05C030 -:10029000989C902C1124980E15C0E89CE02C1124F9 -:1002A000E80EF0E2FF2A0EC09E3229F4F6FC6BC184 -:1002B00040E4F42A07C09C3619F450E8F52A02C03D -:1002C000983649F4F20123FD959123FF91912F0176 -:1002D000992309F0B8CF892F8554833018F08052C4 -:1002E000833038F444E050E0A40EB51E5FE3598338 -:1002F0000FC0933631F0933779F0933509F056C03B -:1003000020C0F5018081898342E050E0A40EB51E33 -:10031000610101E010E012C0F501C080D180F6FC5F -:1003200003C06FEF7FEF02C0692D70E042E050E044 -:10033000A40EB51EC6010E94FB038C015FE7F522E7 -:1003400014C0F501C080D180F6FC03C06FEF7FEFD1 -:1003500002C0692D70E042E050E0A40EB51EC60157 -:100360000E94E9038C0150E8F52AF3FE07C01AC089 -:1003700080E290E0B3010E940604EA948E2D90E0A2 -:1003800008171907A8F30EC0F601F7FC8591F7FED0 -:1003900081916F0190E0B3010E940604E110EA949C -:1003A000015010400115110579F7EAC0943611F09B -:1003B000993669F5F7FE08C0F50120813181428147 -:1003C000538184E090E00AC0F501808191819C0115 -:1003D000442737FD4095542F82E090E0A80EB91EC7 -:1003E0009FE6F92257FF09C0509540953095219519 -:1003F0003F4F4F4F5F4FE0E8FE2ACA01B901A1010C -:100400002AE030E00E943204D82ED21840C095373E -:1004100029F41F2D1F7E2AE030E01DC01F2D197FFB -:100420009F3661F0903720F4983509F0ACC00FC0CA -:10043000903739F0983709F0A6C004C028E030E0C2 -:100440000AC0106114FD146020E130E004C014FD06 -:10045000166020E132E017FF08C0F501608171816C -:100460008281938144E050E008C0F5018081918150 -:10047000BC0180E090E042E050E0A40EB51EA10176 -:100480000E943204D82ED2188FE7F82EF122F6FE01 -:100490000BC05EEFF522D91438F4F4FE07C0F2FC6D -:1004A00005C08FEEF82202C01D2D01C0192DF4FEEB -:1004B0000DC0FE01ED0DF11D8081803319F499EE20 -:1004C000F92208C01F5FF2FE05C003C08F2D867899 -:1004D00009F01F5F0F2DF3FC14C0F0FE0FC01E15B6 -:1004E00010F09D2C0BC09D2C9E0C911A1E2D06C049 -:1004F00080E290E0B3010E9406041F5F1E15C0F366 -:1005000004C01E1510F4E11A01C0EE2404FF0FC050 -:1005100080E390E0B3010E94060402FF1DC001FDCC -:1005200003C088E790E00EC088E590E00BC0802F04 -:10053000867891F001FF02C08BE201C080E2F7FCF7 -:100540008DE290E0B3010E94060406C080E390E0D3 -:10055000B3010E9406049A94D914C0F3DA94F1010D -:10056000ED0DF11D808190E0B3010E940604DD20B5 -:10057000A9F706C080E290E0B3010E940604EA9465 -:10058000EE20C1F743CEF30166817781CB012B9634 -:10059000E2E10C94D8090F931F93CF93DF93689FE8 -:1005A0008001699F100D789F100D1124C8010E94D1 -:1005B000E702EC01009729F060E070E0A8010E94DA -:1005C000F403CE01DF91CF911F910F910895CF9346 -:1005D000DF93BC018230910510F462E070E0A091DD -:1005E000EF02B091F002ED01E0E0F0E040E050E019 -:1005F00021C0888199818617970769F48A819B8138 -:10060000309719F09383828304C09093F002809313 -:10061000EF02FE0134C06817790738F4411551051F -:1006200019F08417950708F4AC01FE018A819B81BB -:100630009C01E9012097E9F641155105A9F1CA018C -:10064000861B970B049708F4BA01E0E0F0E02AC09B -:100650008D919C91119784179507F9F4641775078C -:1006600081F412968D919C911397309719F0938392 -:10067000828304C09093F0028093EF02FD013296D2 -:100680004CC0CA01861B970BFD01E80FF91F61934F -:10069000719302978D939C9340C0FD018281938159 -:1006A0009C01D9011097A1F68091ED029091EE0284 -:1006B000892B41F480912301909124019093EE02C3 -:1006C0008093ED024091250150912601411551057D -:1006D00041F44DB75EB78091210190912201481BF2 -:1006E000590B2091ED023091EE02CA01821B930B4F -:1006F0008617970780F0AB014E5F5F4F8417950711 -:1007000050F0420F531F5093EE024093ED02F90157 -:100710006193719302C0E0E0F0E0CF01DF91CF91EF -:100720000895CF93DF93009709F450C0EC0122970E -:100730001B821A82A091EF02B091F002109709F18A -:1007400040E050E0AC17BD0708F1BB83AA83FE016F -:1007500021913191E20FF31FAE17BF0779F48D910C -:100760009C911197280F391F2E5F3F4F39832883A3 -:1007700012968D919C9113979B838A834115510505 -:1007800071F4D093F002C093EF0220C012968D91C5 -:100790009C911397AD01009711F0DC01D3CFFA01C2 -:1007A000D383C28321913191E20FF31FCE17DF076C -:1007B00069F488819981280F391F2E5F3F4FFA0114 -:1007C000318320838A819B8193838283DF91CF91C0 -:1007D0000895FC010590615070400110D8F7809594 -:1007E00090958E0F9F1F0895DC0101C06D934150BD -:1007F0005040E0F70895FC016150704001900110F5 -:10080000D8F7809590958E0F9F1F08950F931F9393 -:10081000CF93DF938C01EB018B8181FF1BC082FFA3 -:100820000DC02E813F818C819D812817390764F48A -:10083000E881F9810193F983E88306C0E885F985A9 -:10084000802F0995892B31F48E819F8101969F839A -:100850008E8302C00FEF1FEFC801DF91CF911F9170 -:100860000F910895FA01AA27283051F1203181F122 -:10087000E8946F936E7F6E5F7F4F8F4F9F4FAF4FA8 -:10088000B1E03ED0B4E03CD0670F781F891F9A1FBB -:10089000A11D680F791F8A1F911DA11D6A0F711D6F -:1008A000811D911DA11D20D009F468943F912AE07B -:1008B000269F11243019305D3193DEF6CF01089563 -:1008C000462F4770405D4193B3E00FD0C9F7F6CF94 -:1008D000462F4F70405D4A3318F0495D31FD40525C -:1008E000419302D0A9F7EACFB4E0A69597958795F2 -:1008F00077956795BA95C9F70097610571050895D1 -:100900009B01AC010A2E069457954795379527957C -:10091000BA95C9F7620F731F841F951FA01D089514 -:100920008AE391E068E049E00E9475070895FF922C -:100930000F931F93CF93DF9380E8E7E4F1E0DF01AB -:100940001D928A95E9F704E610E021C08AE391E060 -:100950006F2D0E94F2078AE391E00E94840880E8EC -:1009600090E00E94D7058AE391E00E947C078AE329 -:1009700091E00E944608882329F088819981019698 -:10098000998388832297FA94BFEFFB16F9F60150FA -:100990001040EFEF0F3F1E0729F0C5E4D2E08FE7CC -:1009A000F82ED4CFC7E4D1E000E011E000D000D0B1 -:1009B000ADB7BEB712961C930E931197899199917A -:1009C0008F70907014969C938E9313970E94D90009 -:1009D0000F900F900F900F90B2E0C734DB0731F704 -:1009E00000D083E091E0EDB7FEB7928381830E944F -:1009F000D9000F900F90DF91CF911F910F91FF9031 -:100A0000089580E895E060E070E00E948D00089510 -:100A10000F931F93CF93DF9384ED92E040E051EE6C -:100A200060E070E00E9454060E94010500D086E05C -:100A300091E0EDB7FEB7928381830E94D9000F90B9 -:100A40000F908AE391E00E944B088AE391E060E016 -:100A50000E94E8078AE391E00E9484088AE391E01B -:100A60000E947C07C0E0D0E000E011E000D000D0A0 -:100A7000EDB7FEB712830183CE0124E095958795EB -:100A80002A95E1F7948383830E94D90021960F90E1 -:100A90000F900F900F90C038D10541F700D083E040 -:100AA00091E0EDB7FEB7928381830E94D900C0E048 -:100AB000D0E00F900F9000D000D0EDB7FEB70183CB -:100AC0001283CE018F709070948383830E94D9002B -:100AD00021960F900F900F900F90C038D10559F7C5 -:100AE00000D083E091E0EDB7FEB7928381830E944E -:100AF000D9000F900F90DF91CF911F910F91089522 -:100B00000F931F93082F84ED92E0602F0E94280717 -:100B1000112707FD1095C8011F910F9108951F928D -:100B20000F920FB60F9211242F933F938F939F93A1 -:100B3000AF93BF9380914B0290914C02A0914D02D4 -:100B4000B0914E0230914F020196A11DB11D232F8D -:100B50002D5F2D3720F02D570196A11DB11D20933B -:100B60004F0280934B0290934C02A0934D02B0939E -:100B70004E028091470290914802A0914902B091A3 -:100B80004A020196A11DB11D80934702909348022D -:100B9000A0934902B0934A02BF91AF919F918F9168 -:100BA0003F912F910F900FBE0F901F9018950197B6 -:100BB00039F0880F991F880F991F02970197F1F755 -:100BC0000895789484B5826084BD84B5816084BDC5 -:100BD00085B5826085BD85B5816085BDEEE6F0E0B6 -:100BE000808181608083E1E8F0E010828081826012 -:100BF0008083808181608083E0E8F0E08081816093 -:100C00008083E1EBF0E0808184608083E0EBF0E0C2 -:100C1000808181608083EAE7F0E080818460808366 -:100C20008081826080838081816080838081806810 -:100C300080831092C10008950E94E1050E9408057A -:100C40000E949704FDCF1F920F920FB60F921124AE -:100C50002F933F934F938F939F93EF93FF934091E5 -:100C6000C600E091D002F091D10231969F012F771A -:100C7000307031978091D2029091D30228173907B2 -:100C800039F0E05BFD4F40833093D1022093D002D6 -:100C9000FF91EF919F918F914F913F912F910F90E5 -:100CA0000FBE0F901F901895AF92BF92DF92EF92F8 -:100CB000FF920F931F93CF93DF93EC017A018B0187 -:100CC000DD24403081EE580780E0680780E0780737 -:100CD00011F0DD24D39491E0A92EB12CE885F9859B -:100CE000DD2069F0C5010A8802C0880F991F0A94A7 -:100CF000E2F7808360E079E08DE390E005C0108248 -:100D000060E874E88EE190E0A80197010E949A09DA -:100D10002150304040405040569547953795279593 -:100D200080E12030380720F0DD2011F0DD24D6CF1F -:100D3000EC81FD813083EE81FF812083EA85FB8594 -:100D4000208141E050E0CA010E8402C0880F991F43 -:100D50000A94E2F7282B2083EA85FB852081CA01CB -:100D60000F8402C0880F991F0A94E2F7282B208372 -:100D7000EA85FB858081088802C0440F551F0A94CC -:100D8000E2F7842B8083DF91CF911F910F91FF9029 -:100D9000EF90DF90BF90AF900895DC011296ED9137 -:100DA000FC911397E058FF4F2191319180819181FF -:100DB000281B390B2F773070C9010895DC0112967A -:100DC000ED91FC911397EE57FF4F20813181929165 -:100DD0008291E058F0408217930719F42FEF3FEF0C -:100DE00005C0E20FF31F8081282F30E0C90108956C -:100DF000DC011296ED91FC911397DF01AE57BF4FC6 -:100E00002D913C911197E058FF4F80819181E058DE -:100E1000F0408217930719F42FEF3FEF0BC0E20F5A -:100E2000F31F80812F5F3F4F2F7730702D933C93BE -:100E3000282F30E0C9010895DC011296ED91FC9154 -:100E40001397EE57FF4F808191819293829308957B -:100E5000FC01A085B18521898C9190E0022E02C011 -:100E6000959587950A94E2F780FFF6CF0484F5857F -:100E7000E02D608308958BE291E09093D5028093FA -:100E8000D40280E592E09093D7028093D60285EC5D -:100E900090E09093D9028093D80284EC90E09093F4 -:100EA000DB028093DA0280EC90E09093DD02809385 -:100EB000DC0281EC90E09093DF028093DE0286EC0E -:100EC00090E09093E1028093E00284E08093E2025C -:100ED00083E08093E30287E08093E40285E08093DF -:100EE000E50281E08093E6020895FC01608341837E -:100EF00080E2828313820895FC01808160E00E9479 -:100F0000CD080895FF920F931F938C01F62E80E079 -:100F10000E94650985E00E946A09F80181816F2DB0 -:100F20000E94CD081F910F91FF9008951F93CF93BA -:100F3000DF93EC0160E070E00E94820781EE8EBDDD -:100F40000DB407FEFDCF1EB5CE0161E070E00E943A -:100F50008207812FDF91CF911F9108951F93CF9327 -:100F6000DF93EC0160E070E00E94820782EE8EBDAC -:100F70000DB407FEFDCF1EB5CE0161E070E00E940A -:100F80008207812FDF91CF911F9108950F931F93B7 -:100F9000CF93DF93EC01162F042F60E070E00E94E6 -:100FA00082071F7110621EBD0DB407FEFDCF1EB576 -:100FB0000EBD0DB407FEFDCF8EB5CE0161E070E031 -:100FC0000E948207812FDF91CF911F910F91089589 -:100FD000662319F061E04FE302C061E040E00E9447 -:100FE000C6070895462F603808F04FE765E00E9475 -:100FF000C6070895EF92FF920F931F93CF93DF934D -:101000007C01162FEA01022F60E070E00E94820747 -:101010001F7110621EBD0DB407FEFDCF1EB508C0C6 -:1010200088818EBD0DB407FEFDCF21968EB501508F -:101030000023B1F7C70161E070E00E948207812FB1 -:10104000DF91CF911F910F91FF90EF9008951F9323 -:10105000CF93DF93EC01162F60E070E00E948207CF -:101060001F711EBD0DB407FEFDCF8EB58FEF8EBD77 -:101070000DB407FEFDCF1EB5CE0161E070E00E9409 -:101080008207812FDF91CF911F91089569E00E941F -:101090002708817008950F931F938C01FC018081B4 -:1010A00061E00E94A708F801818161E00E94A70821 -:1010B000F801808160E00E94CD08C80161E070E025 -:1010C0000E9482070E947B0981E00E945C0980E007 -:1010D0000E94650985E00E946A09C80164E04FEF3B -:1010E0000E94C607C80167E040E70E94C607C80122 -:1010F0000E94AE07C8010E949607C80161E00E94E5 -:10110000F2071F910F9108950F931F938C0160E0D8 -:101110004BE00E94C607C80167E040E70E94C6078F -:10112000A8014B5F5F4FC8016AE025E00E94FA0703 -:10113000C8010E94AE07F801808161E00E94CD08DD -:1011400082E890E00E94D7051F910F910895482FE3 -:1011500050E0CA0186569F4FFC0124914A575F4FC9 -:10116000FA0184918823C1F0E82FF0E0EE0FFF1F11 -:10117000E859FF4FA591B491662341F49FB7F894C5 -:101180008C91209582238C939FBF08959FB7F894EC -:101190008C91822B8C939FBF0895482F50E0CA01F9 -:1011A00082559F4FFC012491CA0186569F4FFC0136 -:1011B00034914A575F4FFA019491992309F444C03E -:1011C000222351F1233071F0243028F42130A1F092 -:1011D000223011F514C02630B1F02730C1F0243090 -:1011E000D9F404C0809180008F7703C08091800083 -:1011F0008F7D8093800010C084B58F7702C084B546 -:101200008F7D84BD09C08091B0008F7703C080912D -:10121000B0008F7D8093B000E92FF0E0EE0FFF1F4C -:10122000EE58FF4FA591B491662341F49FB7F8940F -:101230008C91309583238C939FBF08959FB7F8942A -:101240008C91832B8C939FBF08950F931F93CF9303 -:10125000DF938C01EB0109C02196D801ED91FC913F -:101260000190F081E02DC801099568816623A1F7FE -:10127000DF91CF911F910F910895EF92FF920F93FD -:101280001F93CF93DF938C017B01EA010CC0D70140 -:101290006D917D01D801ED91FC910190F081E02DDF -:1012A000C80109952197209791F7DF91CF911F9160 -:1012B0000F91FF90EF900895882319F48CB5806208 -:1012C00002C08CB58F7D8CBD08959CB5937F982B03 -:1012D0009CBD08952CB5382F33702C7F322B3CBD2C -:1012E0002DB590E0959587959595879581702E7F82 -:1012F000822B8DBD08958DE061E00E94A7088BE0F0 -:1013000061E00E94A7088AE061E00E94A7088DE0E2 -:1013100060E00E94CD088BE060E00E94CD088AE08A -:1013200061E00E94CD088CB580618CBD8CB5806475 -:101330008CBD0895A1E21A2EAA1BBB1BFD010DC096 -:10134000AA1FBB1FEE1FFF1FA217B307E407F50775 -:1013500020F0A21BB30BE40BF50B661F771F881F51 -:10136000991F1A9469F760957095809590959B01E7 -:10137000AC01BD01CF0108952F923F924F925F9231 -:101380006F927F928F929F92AF92BF92CF92DF9295 -:10139000EF92FF920F931F93CF93DF93CDB7DEB7FA -:1013A000CA1BDB0B0FB6F894DEBF0FBECDBF09948E -:1013B0002A88398848885F846E847D848C849B84E5 -:1013C000AA84B984C884DF80EE80FD800C811B81F3 -:1013D000AA81B981CE0FD11D0FB6F894DEBF0FBE22 -:1013E000CDBFED010895EE0FFF1F0590F491E02DA4 -:0613F0000994F894FFCF00 -:1013F6002578000A0D000A0D524632342F657861B1 -:101406006D706C65732F7363616E6E65722F0A0D56 -:10141600002000F102000000000000280725093D19 -:0A14260009CD06F806DE061C0700DB -:00000001FF diff --git a/examples/scanner/printf.h b/examples/scanner/printf.h deleted file mode 100644 index 66f64384..00000000 --- a/examples/scanner/printf.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ diff --git a/examples/scanner/scanner.pde b/examples/scanner/scanner.pde deleted file mode 100644 index 1a43d728..00000000 --- a/examples/scanner/scanner.pde +++ /dev/null @@ -1,124 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Channel scanner - * - * Example to detect interference on the various channels available. - * This is a good diagnostic tool to check whether you're picking a - * good channel for your application. - * - * Inspired by cpixip. - * See http://arduino.cc/forum/index.php/topic,54795.0.html - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// -// Channel info -// - -const uint8_t num_channels = 128; -uint8_t values[num_channels]; - -// -// Setup -// - -void setup(void) -{ - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/scanner/\n\r"); - - // - // Setup and configure rf radio - // - - radio.begin(); - radio.setAutoAck(false); - - // Get into standby mode - radio.startListening(); - radio.stopListening(); - - // Print out header, high then low digit - int i = 0; - while ( i < num_channels ) - { - printf("%x",i>>4); - ++i; - } - printf("\n\r"); - i = 0; - while ( i < num_channels ) - { - printf("%x",i&0xf); - ++i; - } - printf("\n\r"); -} - -// -// Loop -// - -const int num_reps = 100; - -void loop(void) -{ - // Clear measurement values - memset(values,0,sizeof(values)); - - // Scan all channels num_reps times - int rep_counter = num_reps; - while (rep_counter--) - { - int i = num_channels; - while (i--) - { - // Select this channel - radio.setChannel(i); - - // Listen for a little - radio.startListening(); - delayMicroseconds(128); - radio.stopListening(); - - // Did we get a carrier? - if ( radio.testCarrier() ) - ++values[i]; - } - } - - // Print out channel measurements, clamped to a single hex digit - int i = 0; - while ( i < num_channels ) - { - printf("%x",min(0xf,values[i]&0xf)); - ++i; - } - printf("\n\r"); -} - -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/examples/starping/Jamfile b/examples/starping/Jamfile deleted file mode 100644 index de9b1f67..00000000 --- a/examples/starping/Jamfile +++ /dev/null @@ -1,206 +0,0 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = EEPROM SPI RF24 ; - -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; - -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; - -# Host-specific overrides for locations -if $(OS) = MACOSX -{ -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; -} - -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; -ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; -SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; - -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; - -# Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; - -# 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) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; - -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; - -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; - -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; - -rule GitVersion -{ - Always $(<) ; - Depends all : $(<) ; -} - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/starping/printf.h b/examples/starping/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/examples/starping/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/examples/starping/starping.pde b/examples/starping/starping.pde deleted file mode 100644 index 4813a779..00000000 --- a/examples/starping/starping.pde +++ /dev/null @@ -1,293 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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. - */ - -/** - * Example RF Radio Ping Star Group - * - * This sketch is a more complex example of using the RF24 library for Arduino. - * Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the - * role_pin low, and the others will be 'ping transmit' units. The ping units - * unit will send out the value of millis() once a second. The pong unit will - * respond back with a copy of the value. Each ping unit can get that response - * back, and determine how long the whole cycle took. - * - * This example requires a bit more complexity to determine which unit is which. - * The pong receiver is identified by having its role_pin tied to ground. - * The ping senders are further differentiated by a byte in eeprom. - */ - -#include -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 - -RF24 radio(9,10); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'pong' receiver. -const int role_pin = 7; - -// -// Topology -// - -// Radio pipe addresses for the nodes to communicate. Only ping nodes need -// dedicated pipes in this topology. Each ping node has a talking pipe -// that it will ping into, and a listening pipe that it will listen for -// the pong. The pong node listens on all the ping node talking pipes -// and sends the pong back on the sending node's specific listening pipe. - -const uint64_t talking_pipes[5] = { 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL, 0xF0F0F0F0B4LL, 0xF0F0F0F0A5LL, 0xF0F0F0F096LL }; -const uint64_t listening_pipes[5] = { 0x3A3A3A3AD2LL, 0x3A3A3A3AC3LL, 0x3A3A3A3AB4LL, 0x3A3A3A3AA5LL, 0x3A3A3A3A96LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_invalid = 0, role_ping_out, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role; - -// -// Address management -// - -// Where in EEPROM is the address stored? -const uint8_t address_at_eeprom_location = 0; - -// What is our address (SRAM cache of the address from EEPROM) -// Note that zero is an INVALID address. The pong back unit takes address -// 1, and the rest are 2-6 -uint8_t node_address; - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_ping_out; - else - role = role_pong_back; - - // - // Address - // - - if ( role == role_pong_back ) - node_address = 1; - else - { - // Read the address from EEPROM - uint8_t reading = EEPROM.read(address_at_eeprom_location); - - // If it is in a valid range for node addresses, it is our - // address. - if ( reading >= 2 && reading <= 6 ) - node_address = reading; - - // Otherwise, it is invalid, so set our address AND ROLE to 'invalid' - else - { - node_address = 0; - role = role_invalid; - } - } - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/starping/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - printf("ADDRESS: %i\n\r",node_address); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // - // Open pipes to other nodes for communication - // - - // The pong node listens on all the ping node talking pipes - // and sends the pong back on the sending node's specific listening pipe. - if ( role == role_pong_back ) - { - radio.openReadingPipe(1,talking_pipes[0]); - radio.openReadingPipe(2,talking_pipes[1]); - radio.openReadingPipe(3,talking_pipes[2]); - radio.openReadingPipe(4,talking_pipes[3]); - radio.openReadingPipe(5,talking_pipes[4]); - } - - // Each ping node has a talking pipe that it will ping into, and a listening - // pipe that it will listen for the pong. - if ( role == role_ping_out ) - { - // Write on our talking pipe - radio.openWritingPipe(talking_pipes[node_address-2]); - // Listen on our listening pipe - radio.openReadingPipe(1,listening_pipes[node_address-2]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); - - // - // Prompt the user to assign a node address if we don't have one - // - - if ( role == role_invalid ) - { - printf("\n\r*** NO NODE ADDRESS ASSIGNED *** Send 1 through 6 to assign an address\n\r"); - } -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout (250ms) - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 250 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\n\r"); - } - else - { - // Grab the response, compare, and send to debugging spew - unsigned long got_time; - radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); - } - - // Try again 1s later - delay(1000); - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - - if ( role == role_pong_back ) - { - // if there is data ready - uint8_t pipe_num; - if ( radio.available(&pipe_num) ) - { - // Dump the payloads until we've gotten everything - unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got payload %lu from node %i...",got_time,pipe_num+1); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Open the correct pipe for writing - radio.openWritingPipe(listening_pipes[pipe_num-1]); - - // Retain the low 2 bytes to identify the pipe for the spew - uint16_t pipe_id = listening_pipes[pipe_num-1] & 0xffff; - - // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); - printf("Sent response to %04x.\n\r",pipe_id); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } - } - - // - // Listen for serial input, which is how we set the address - // - if (Serial.available()) - { - // If the character on serial input is in a valid range... - char c = Serial.read(); - if ( c >= '1' && c <= '6' ) - { - // It is our address - EEPROM.write(address_at_eeprom_location,c-'0'); - - // And we are done right now (no easy way to soft reset) - printf("\n\rManually reset address to: %c\n\rPress RESET to continue!",c); - while(1) ; - } - } -} -// vim:ai:ci sts=2 sw=2 ft=cpp diff --git a/flash.cpp b/flash.cpp new file mode 100755 index 00000000..e4835372 --- /dev/null +++ b/flash.cpp @@ -0,0 +1,61 @@ +/* + * flash.cpp + * + * Created on: Jun 10, 2013 + * Author: joao + */ +#include +#include "flash.h" + +void flash_init(void) +{ + FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator +} + +void write_SegC (unsigned char values[], uint8_t dim) +{ + char *Flash_ptr; // Flash pointer + unsigned int i; + + Flash_ptr = (char *) 0x1040; // Initialize Flash pointer + FCTL1 = FWKEY + ERASE; // Set Erase bit + FCTL3 = FWKEY; // Clear Lock bit + *Flash_ptr = 0; // Dummy write to erase Flash segment + + FCTL1 = FWKEY + WRT; // Set WRT bit for write operation + + for (i=0; i<64; i++) + { + if(i < dim) + { + *Flash_ptr++ = values[i]; // Write value to flash + } + else + { + *Flash_ptr++ = 0; + } + } + + FCTL1 = FWKEY; // Clear WRT bit + FCTL3 = FWKEY + LOCK; // Set LOCK bit +} + +void read_SegC (unsigned char values[], uint8_t dim, uint8_t offset) +{ + char *Flash_ptr; // Flash pointer + unsigned int i; + + if(64 - offset - dim > 0) + { + Flash_ptr = (char *) (0x1040 + offset); // Initialize Flash pointer + FCTL1 = FWKEY + ERASE; // Set Erase bit + FCTL3 = FWKEY; // Clear Lock bit + + for (i=0; i + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __CONIO_H_ +#define __CONIO_H_ + +/** + * Print a character to the console. + * + * @param[in] c character to print + */ +void cio_printc(char c); + +/** + * Print a string to the console. + * + * @param[in] *line string to print + */ +void cio_print(char *line); + +/** + * Print an integer to the console. + * + * @param[in] n number to print + */ +void cio_printi(int n); + +/** + * Print a number in binary to the console. + * + * @param[in] n number to print + * @param[in] size number of bits to use + */ +void cio_printb(int n, int size); + +/** + * Print a formated string. The following formt specifiers could + * be used in the format string: + *
+ * String			%s
+ * Char          	%c
+ * Integer       	%i
+ * Unsigned      	%u
+ * Long          	%l
+ * unsigned long 	%n
+ * heX          	%x
+ * 
+ * @param[in] *format the format string + * @param[in] ... the values to put into the format string + */ +void cio_printf(char *format, ...); + +/** + * Read a character form the console. + * + * @return character read from the console + */ +char cio_getc(); + +#endif diff --git a/include/libemb/nrf24l01/nrf24l01.h b/include/libemb/nrf24l01/nrf24l01.h new file mode 100755 index 00000000..cf079f58 --- /dev/null +++ b/include/libemb/nrf24l01/nrf24l01.h @@ -0,0 +1,261 @@ +/* + * This file is part of the libemb project. + * + * Copyright (C) 2011 Stefan Wendler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __NRF24L01_H_ +#define __NRF24L01_H_ + +#include "nrf24l01_hw.h" +#include "nrf24l01_regs.h" + +/** + * Maximum payload size the NRF is able to send in bytes. + */ +#define NRF_MAX_PAYLOAD 32 + +/** + * Primery mode TX + */ +#define NRF_MODE_PTX 0 + +/** + * Primery mode RX + */ +#define NRF_MODE_PRX 1 + +/** + * Retry delay for auto retransmit 250us + */ +#define NRF_RT_DELAY_250 0 + +/** + * Retry delay for auto retransmit 500us + */ +#define NRF_RT_DELAY_500 1 + +/** + * Retry delay for auto retransmit 750us + */ +#define NRF_RT_DELAY_750 2 + +/** + * Retry delay for auto retransmit 1000us + */ +#define NRF_RT_DELAY_1000 3 + +/** + * Retry delay for auto retransmit 1250us + */ +#define NRF_RT_DELAY_1250 4 + +/** + * Retry delay for auto retransmit 1500us + */ +#define NRF_RT_DELAY_1500 5 + +/** + * Retry delay for auto retransmit 1750us + */ +#define NRF_RT_DELAY_1750 6 + +/** + * Retry delay for auto retransmit 2000us + */ +#define NRF_RT_DELAY_2000 7 + +/** + * Retry delay for auto retransmit 2250us + */ +#define NRF_RT_DELAY_2250 8 + +/** + * Retry delay for auto retransmit 2500us + */ +#define NRF_RT_DELAY_2500 9 + +/** + * Retry delay for auto retransmit 2750us + */ +#define NRF_RT_DELAY_2750 10 + +/** + * Retry delay for auto retransmit 3000us + */ +#define NRF_RT_DELAY_3000 11 + +/** + * Retry delay for auto retransmit 3250us + */ +#define NRF_RT_DELAY_3250 12 + +/** + * Retry delay for auto retransmit 3500us + */ +#define NRF_RT_DELAY_3500 13 + +/** + * Retry delay for auto retransmit 3750us + */ +#define NRF_RT_DELAY_3750 14 + +/** + * Retry delay for auto retransmit 4000us + */ +#define NRF_RT_DELAY_4000 15 + +/** + * Error code for max retry reached + */ +#define NRF_ERR_MAX_RT (-1) + +/** + * Error code for TX buffer full + */ +#define NRF_ERR_TX_FULL (-2) + +/** + * Error code for RX buffer full + */ +#define NRF_ERR_RX_FULL (-3) + +/** + * Definition of payload send through the device. + */ +typedef struct { + + /** + * Payload size in bytes (must not exceed NRF_MAX_PAYLOAD]). + */ + unsigned char size; + + /** + * The payload. + */ + unsigned char data[NRF_MAX_PAYLOAD]; +} nrf_payload; + +/** + * Read contents of a register form the nRF24l01. + * + * @param[in] reg register to read (see NRF_REG_* form nrf24l01_regs.h) + * @param[out] *buf the value(s) read from the register + * @return number of bytes read from the register + */ +int nrf_read_reg(unsigned char reg, nrf_reg_buf *buf); + +/** + * Write contents of a register to the nRF24l01. + * + * @param[in] reg register to write (see NRF_REG_* form nrf24l01_regs.h) + * @param[in] *buf the value(s) to write the register + * @return number of bytes written to the register + */ +int nrf_write_reg(unsigned char reg, nrf_reg_buf *buf); + +/** + * Send payload non-blocking through the nRF24l01. + * + * @param[in] *payload the payload to send + * @return number of bytes sent or NRF_ERR_TX_FULL if TX buffer is full + * or NRF_ERR_MAX_RT if auto ACK with retry was enabled and + * payload was not delivered after configured retrys + */ +int nrf_send(nrf_payload *payload); + +/** + * Send payload blocking through the nRF24l01. + * + * @param[in] *payload the payload to send + * @return number of bytes sent or NRF_ERR_TX_FULL if TX buffer is full + * or NRF_ERR_MAX_RT if auto ACK with retry was enabled and + * payload was not delivered after configured retrys + */ +int nrf_send_blocking(nrf_payload *payload); + +/** + * Receive payload non-blocking from nRF24l01. + * + * @param *payload the payload received, "size" member of payload + * must be set to correct payload size (as configured for nRF) + * @return number of bytes received or NRF_ERR_RX_FULL when RX buffer is full +d + */ +int nrf_receive(nrf_payload *payload); + +/** + * Receive payload blocking from nRF24l01. + * + * @param *payload the payload received, "size" member of payload + * must be set to correct payload size (as configured for nRF) + * @return number of bytes received or NRF_ERR_RX_FULL when RX buffer is full + */ +int nrf_receive_blocking(nrf_payload *payload); + +/** + * Set ACK payload for a given pipe to be sent back in ESB mode with ACK-payload. + * + * @param[in] *payload ACK payload to send back on next RX + * @return number of bytes sent + */ +int nrf_write_ack_pl(nrf_payload *payload, unsigned char pipe); + +/** + * Read ACK payload received as response to the last TX request (only ESB mode with + * ACK-payload enabled). + * + * @param[out] *payload ACK payload received + * @return number of bytes received + */ +int nrf_read_ack_pl(nrf_payload *payload); + +/** + * Preset configuration to configure the nRF24l01 into SB (Shock Burst) mode. + * + * @param[in] mode primery device mode: NRF_MODE_PRX for RX, or NRF_MODE_PTX for TX + * @param[in] rf_ch RF channel to use + * @param[in] pw payload width in bytes (must not exceed NRF_MAX_PAYLOAD) + * @param[in] *addr Address to use for TX and RX on pipe 0 + */ +void nrf_preset_sb(unsigned char mode, unsigned char rf_ch, unsigned char pw, nrf_reg_buf *addr); + +/** + * Preset configuration to configure the nRF24l01 into ESB (Enhenced Shock Burst) mode. + * + * @param[in] mode primery device mode: NRF_MODE_PRX for RX, or NRF_MODE_PTX for TX + * @param[in] rf_ch RF channel to use + * @param[in] pw payload width in bytes (must not exceed NRF_MAX_PAYLOAD) + * @param[in] rert number of retrys for receiving ACK + * @param[in] delay delay to wait before next retry (one of NRF_RT_DELAY_*) + * @param[in] *addr Address to use for TX and RX on pipe 0 + */ +void nrf_preset_esb(unsigned char mode, unsigned char rf_ch, unsigned char pw, unsigned char retr, unsigned char delay, nrf_reg_buf *addr); + +/** + * Preset configuration to configure the nRF24l01 into ESB (Enhenced Shock Burst) mode with + * enabled ACL payload. + * + * @param[in] mode primery device mode: NRF_MODE_PRX for RX, or NRF_MODE_PTX for TX + * @param[in] rf_ch RF channel to use + * @param[in] pw payload width in bytes (must not exceed NRF_MAX_PAYLOAD) + * @param[in] rert number of retrys for receiving ACK + * @param[in] delay delay to wait before next retry (one of NRF_RT_DELAY_*) + * @param[in] *addr Address to use for TX and RX on pipe 0 + */ +void nrf_preset_esbpl(unsigned char mode, unsigned char rf_ch, unsigned char pw, unsigned char retr, unsigned char delay, nrf_reg_buf *addr); + +#endif diff --git a/include/libemb/nrf24l01/nrf24l01_hw.h b/include/libemb/nrf24l01/nrf24l01_hw.h new file mode 100755 index 00000000..5c29eef3 --- /dev/null +++ b/include/libemb/nrf24l01/nrf24l01_hw.h @@ -0,0 +1,46 @@ +/* + * This file is part of the libemb project. + * + * Copyright (C) 2011 Stefan Wendler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __NRF24L01HW_H_ +#define __NRF24L01HW_H_ + +/** + * Initialize HW interface (SPI) to nRF24l01. + */ +void nrf_init(void); + +/** + * Drive CS high. + */ +void nrf_spi_csh(void); + +/** + * Drive CS low. + */ +void nrf_spi_csl(void); + +/** + * Write-/Read one byte of data to/from the nRF through the SPI bus. + * + * @param[in] data byte to send + * @return byte received + */ +unsigned char nrf_spi_xfer_byte(unsigned char data); + +#endif diff --git a/include/libemb/nrf24l01/nrf24l01_regs.h b/include/libemb/nrf24l01/nrf24l01_regs.h new file mode 100755 index 00000000..df4c4b13 --- /dev/null +++ b/include/libemb/nrf24l01/nrf24l01_regs.h @@ -0,0 +1,349 @@ +/* + * This file is part of the libemb project. + * + * Copyright (C) 2011 Stefan Wendler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __NRF24L01REGS_H_ +#define __NRF24L01REGS_H_ + +/* + * Setting this to 1 enables compilation of meta information + * for the registers. Meta information contains readable register + * names which could be used for debugging or displaying. + *

+ * NOTE: Use "-DNRF_REG_DEF_META" compiler switch from makefile + * is the preferred way to set this flag. + */ +// #define NRF_REG_DEF_META 1 + +/** + * Maximum number of bytes needed to store register information (largest + * block of data to be read from nNRF is the address register with 5 bytes). + */ +#define NRF_MAX_REG_BUF 5 + +/* + * NRF2041 Registers + */ + +#define NRF_REG_CONFIG 0x00 +#define NRF_REG_EN_AA 0x01 +#define NRF_REG_EN_RXADDR 0x02 +#define NRF_REG_SETUP_AW 0x03 +#define NRF_REG_SETUP_RETR 0x04 +#define NRF_REG_RF_CH 0x05 +#define NRF_REG_RF_SETUP 0x06 +#define NRF_REG_STATUS 0x07 +#define NRF_REG_OBSERVE_TX 0x08 +#define NRF_REG_CD 0x09 +#define NRF_REG_RX_ADDR_P0 0x0A +#define NRF_REG_RX_ADDR_P1 0x0B +#define NRF_REG_RX_ADDR_P2 0x0C +#define NRF_REG_RX_ADDR_P3 0x0D +#define NRF_REG_RX_ADDR_P4 0x0E +#define NRF_REG_RX_ADDR_P5 0x1F +#define NRF_REG_TX_ADDR 0x10 +#define NRF_REG_RX_PW_P0 0x11 +#define NRF_REG_RX_PW_P1 0x12 +#define NRF_REG_RX_PW_P2 0x13 +#define NRF_REG_RX_PW_P3 0x14 +#define NRF_REG_RX_PW_P4 0x15 +#define NRF_REG_RX_PW_P5 0x16 +#define NRF_REG_FIFO_STATUS 0x17 +// N/A 0x18 +// N/A 0x19 +// N/A 0x1A +// N/A 0x1B +#define NRF_REG_DYNPD 0x1C +#define NRF_REG_FEATURE 0x1D + +/* + * NRF2401 Register Fields + */ + +// CONFIG +#define NRF_REGF_PRIM_RX 0 +#define NRF_REGF_PWR_UP 1 +#define NRF_REGF_CRCO 2 +#define NRF_REGF_EN_CRC 3 +#define NRF_REGF_MASK_MAX_RT 4 +#define NRF_REGF_MASK_TX_DS 5 +#define NRF_REGF_MASK_RX_DR 6 + +// EN_AA +#define NRF_REGF_ENAA_P0 0 +#define NRF_REGF_ENAA_P1 1 +#define NRF_REGF_ENAA_P2 2 +#define NRF_REGF_ENAA_P3 3 +#define NRF_REGF_ENAA_P4 4 +#define NRF_REGF_ENAA_P5 5 + +// EN_RXADDR +#define NRF_REGF_ERX_P0 0 +#define NRF_REGF_ERX_P1 1 +#define NRF_REGF_ERX_P2 2 +#define NRF_REGF_ERX_P3 3 +#define NRF_REGF_ERX_P4 4 +#define NRF_REGF_ERX_P5 5 + +// SETUP_AW +#define NRF_REGF_AW 0 + +// SETUP_RETR +#define NRF_REGF_ARC 0 +#define NRF_REGF_ARD 1 + +// RF_CH +#define NRF_REGF_RF_CH 0 + +// RF_SETUP +#define NRF_REGF_LNA_HCURR 0 +#define NRF_REGF_RF_PWR 1 +#define NRF_REGF_RF_DR 2 +#define NRF_REGF_PLL_LOCK 3 + +// STATUS +#define NRF_REGF_TX_FULL 0 +#define NRF_REGF_RX_P_NO 1 +#define NRF_REGF_MAX_RT 2 +#define NRF_REGF_TX_DS 3 +#define NRF_REGF_RX_DR 4 + +// OBSERVE_TX +#define NRF_REGF_ARC_CNT 0 +#define NRF_REGF_PLOS_CNT 1 + +// CD +#define NRF_REGF_CD 0 + +// ADDR +#define NRF_REGF_ADDR_A 0 +#define NRF_REGF_ADDR_B 1 +#define NRF_REGF_ADDR_C 2 +#define NRF_REGF_ADDR_D 3 +#define NRF_REGF_ADDR_E 4 + +// RX_PW +#define NRF_REGF_PW 0 + +// FIFO_STATUS +#define NRF_REGF_FIFO_RX_EMPTY 0 +#define NRF_REGF_FIFO_RX_FULL 1 +#define NRF_REGF_FIFO_TX_EMPTY 4 +#define NRF_REGF_FIFO_TX_FULL 5 +#define NRF_REGF_FIFO_TX_REUSE 6 + +// DYNPD +#define NRF_REGF_DPL_P0 0 +#define NRF_REGF_DPL_P1 1 +#define NRF_REGF_DPL_P2 2 +#define NRF_REGF_DPL_P3 3 +#define NRF_REGF_DPL_P4 4 +#define NRF_REGF_DPL_P5 5 + +// FEATURE +#define NRF_REGF_EN_DYN_ACK 0 +#define NRF_REGF_EN_ACK_PAY 1 +#define NRF_REGF_EN_DPL 2 + +/** + * Defines how many bits make up a certain value in the register. + */ +typedef struct { +#ifdef NRF_REG_DEF_META + /** + * If META is enabled, the readable name for the bit fiels. + */ + char *name; +#endif + /** + * Number of bits which make up that field. + */ + unsigned char size; +#ifdef NRF_REG_DEF_META + /** + * Defines if the bit field is read-/writable. If set to 1, + * it means read+write access is allowd, otherwise only read + * access is possible to that field. + */ + unsigned char rw; +#endif +} nrf_reg_bits; + +typedef struct { + unsigned char count; + nrf_reg_bits data[]; +} nrf_reg_fields; + +/** + * Definitoin of a register. + */ +typedef struct { +#ifdef NRF_REG_DEF_META + /** + * If META is enabled, the readable name for the register. + */ + char *name; +#endif + /** + * Size of the register in bytes. + */ + unsigned char size; + + /** + * Array of bit-fields which make up this register. + */ + nrf_reg_fields *fields; +} nrf_reg; + +/** + * Definition of all available registers on the nRF24l01. + */ +typedef struct { + /** + * Number of registers in the "data" array. + */ + unsigned char count; + + /** + * Array with registers on the nRF24l01. + */ + nrf_reg data[]; +} nrf_regs; + +/** + * Buffer used to store the data for reading/writing a register. + */ +typedef struct { + /** + * Number of bytes to read/write from/to the + * "data" array. + */ + unsigned char size; + + /** + * The data to read/write to/from the register. + */ + unsigned char data[NRF_MAX_REG_BUF]; +} nrf_reg_buf; + +/** + * Fields of the CONFIG register. + */ +extern nrf_reg_fields nrf_reg_config_fields; + +/** + * Fields of the ENAA register. + */ +extern nrf_reg_fields nrf_reg_enaa_fields; + +/** + * Fields of the EN_RXADDR register. + */ +extern nrf_reg_fields nrf_reg_enrxaddr_fields; + +/** + * Fields of the SETUP_AW register. + */ +extern nrf_reg_fields nrf_reg_setupaw_fields; + +/** + * Fields of the SETUP_RETR register. + */ +extern nrf_reg_fields nrf_reg_setupretr_fields; + +/** + * Fields of the RF_CH register. + */ +extern nrf_reg_fields nrf_reg_rfch_fields; + +/** + * Fields of the RF_SETUP register. + */ +extern nrf_reg_fields nrf_reg_rfsetup_fields; + +/** + * Fields of the STATUS register. + */ +extern nrf_reg_fields nrf_reg_status_fields; + +/** + * Fields of the OBSERVE_TX register. + */ +extern nrf_reg_fields nrf_reg_observetx_fields; + +/** + * Fields of the CD register. + */ +extern nrf_reg_fields nrf_reg_cd_fields; + +/** + * Fields of the ADDR register. + */ +extern nrf_reg_fields nrf_reg_addr_fields; + +/** + * Fields of the RX_PW register. + */ +extern nrf_reg_fields nrf_reg_rxpw_fields; + +/** + * Fields of the FIFO_STAT register. + */ +extern nrf_reg_fields nrf_reg_fifostat_fields; + +/** + * Fields of the DYNPD register. + */ +extern nrf_reg_fields nrf_reg_dynpd_fields; + +/** + * Fields of the FEATURE register. + */ +extern nrf_reg_fields nrf_reg_feature_fields; + +/** + * Complete register definition for the nNRF24l01. + */ +extern nrf_regs nrf_reg_def; + +/** + * Extract the value of a given field for a given register out of the + * given buffer and return it. The buffer has to be read by nrf_read_reg + * first. + * + * @param[in] reg the register definition to use for extracting (one of NRF_REG_*) + * @param[in] regf the field definition to use for extracting (one of NRF_REGF_*) + * @param[in] *buf the buffer containing the content of the register + * @return the value extracted for the field + */ +unsigned char nrf_get_reg_field(unsigned char reg, unsigned char regf, nrf_reg_buf *buf); + +/** + * Write a value to a given field for a given register into the + * given buffer. The buffer has to be read by nrf_read_reg + * first, and written back by nrf_write_reg. + * + * @param[in] reg the register definition to use for extracting (one of NRF_REG_*) + * @param[in] regf the field definition to use for extracting (one of NRF_REGF_*) + * @param[out] *buf the buffer to write the field value to + * @param[in] value the value to write to the field + * @return the value extracted for the field + */ +void nrf_set_reg_field(unsigned char reg, unsigned char regf, nrf_reg_buf *buf, unsigned char value); + +#endif diff --git a/include/libemb/serial/serial.h b/include/libemb/serial/serial.h new file mode 100755 index 00000000..bcbfc972 --- /dev/null +++ b/include/libemb/serial/serial.h @@ -0,0 +1,59 @@ +/* + * This file is part of the libemb project. + * + * Copyright (C) 2011 Stefan Wendler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __SERIAL_H_ +#define __SERIAL_H_ + +/** + * Initialize the default USART with the given baudrate. + * + * @param[in] baudrate the baudrate of the USART + */ +void serial_init(unsigned int baudrate); + +/** + * Send a byte non-blocking through the default USART. + * + * @param[in] data byte to send + */ +void serial_send(unsigned char data); + +/** + * Send a byte blocking through the default USART. + * + * @param[in] data byte to send + */ +void serial_send_blocking(unsigned char data); + +/** + * Receive a byte non-blocking from the default USART (makes + * only sense when used in an ISR). + * + * @return byte received + */ +unsigned char serial_recv(); + +/** + * Receive a byte blocking from the default USART. + * + * @return byte received + */ +unsigned char serial_recv_blocking(); + +#endif diff --git a/include/libemb/serial/serial_rb.h b/include/libemb/serial/serial_rb.h new file mode 100755 index 00000000..30191559 --- /dev/null +++ b/include/libemb/serial/serial_rb.h @@ -0,0 +1,107 @@ +/* + * This file is part of the libemb project. + * + * Copyright (C) 2011 Stefan Wendler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _SERIALRB_H_ +#define _SERIALRB_H_ + +/** + * Type of elements to be enqued in the ringbuffer. + */ +#define SERIAL_RB_Q unsigned char + +/** + * Definiton of a ringbuffer. + */ +typedef struct { + /** + * Pointer to the memory where the buffer resides. + */ + SERIAL_RB_Q *buffer; + + /** + * Pointer to the current read position within the buffer. + */ + SERIAL_RB_Q *read; + + /** + * Pointer to the current write position within the buffer. + */ + SERIAL_RB_Q *write; + + /** + * Max. number of elements that fit into buffer (buffer size). + */ + unsigned short elements; + + /** + * Number of elements currently queued in the buffer. + */ + unsigned short entries; +} serial_rb; + +/** + * Return the number of free elements in a given buffer. + * + * @return number of free elements in the buffer + */ +unsigned short serial_rb_free(serial_rb *rb); + +/** + * Check if given buffer is full (out of free elements). + * + * @return 1 if full, 0 otherwise + */ +int serial_rb_full(serial_rb *rb); + +/** + * Check if given buffer is empty. + * + * @return 1 if empty, 0 otherwise + */ +int serial_rb_empty(serial_rb *rb); + +/** + * Initialize a given ringbuffer by assigning the given buffer with the number + * of given elements. + * + * @param *rb the ringbuffer to initialize + * @param[in] *buffer the buffer to assign to this rb (must be allocated!) + * @param[in] elements number of elements which could be stored in buffer + */ +void serial_rb_init(serial_rb *rb, SERIAL_RB_Q *buffer, unsigned short elements); + +/** + * Write a given element to a given buffer. Check if buffer has space left + * before adding a new element with {@link serial_rb_full). + * + * @param *rb the ringbuffer to initialize + * @param[in] element the element to add + */ +void serial_rb_write(serial_rb *rb, SERIAL_RB_Q element); + +/** + * Read element from a given buffer. Check if buffer has elements stored + * before reading with {@link serial_rb_empty). + * + * @param *rb the ringbuffer to initialize + * @param[in] element the element to add + */ +SERIAL_RB_Q serial_rb_read(serial_rb *rb); + +#endif // _SERIALRB_H_ diff --git a/include/libemb/shell/shell.h b/include/libemb/shell/shell.h new file mode 100755 index 00000000..4d7473df --- /dev/null +++ b/include/libemb/shell/shell.h @@ -0,0 +1,173 @@ +/* + * This file is part of the libemb project. + * + * Copyright (C) 2011 Stefan Wendler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __SHELL_H_ +#define __SHELL_H_ + +/** + * max number of character for a command line passed to the shell + */ +#define SHELL_MAX_CMD_LINE 90 + +/** + * max number of arguments passed with one command to the shell + */ +#define SHELL_MAX_ARGS 5 + +/** + * max number of character for a single argument form a command line passed to the shell + */ +#define SHELL_MAX_ARG_LEN 15 + +/** + * return code given when processing of a command line was OK + */ +#define SHELL_PROCESS_OK 0 + +/** + * ERROR maximum number of arguments was reached + */ +#define SHELL_PROCESS_ERR_ARGS_MAX 0xfff0 + +/** + * ERROR maximum number of chars for an argument was reached + */ +#define SHELL_PROCESS_ERR_ARGS_LEN 0xfff1 + +/** + * ERROR unknown command + */ +#define SHELL_PROCESS_ERR_CMD_UNKN 0xfff2 + +/** + * Single command argument + */ +typedef struct { + /** + * Value representing the argument + */ + char val[SHELL_MAX_ARG_LEN]; +} shell_cmd_arg; + +/** + * All arguments from a single command line + */ +typedef struct { + /** + * Number of arguments + */ + unsigned char count; + + /** + * The arguments + */ + shell_cmd_arg args[SHELL_MAX_ARGS]; +} shell_cmd_args; + +/** + * Definition of a single shell command + */ +typedef struct { + /** + * Name of the command + */ + const char *cmd; + + /** + * Description of the command + */ + const char *desc; + + /** + * Functino called when executing the commmand + */ + int (*func)(shell_cmd_args *args); +} shell_cmd; + +/** + * All shell commands knwon by the shell + */ +typedef struct { + /** + * Number of commands + */ + unsigned char count; + + /** + * The commands + */ + shell_cmd cmds[]; +} shell_cmds; + +/** + * Return the length of a given string. + * + * @param[in] str string for which to calculate the length + * @return length of str + */ +int shell_str_len(char *str); + +/** + * Comapre str1 with given length len1 to str2 with given length len2. + * + * @param[in] str1 first string + * @param[in] str2 second string + * @param[in] len1 length of first string + * @param[in] len2 length of second string + * @return 0 if str1 euqals str2, 1 if len1 != len2, 2 if str1 != str2 + */ +int shell_str_cmp(char *str1, char *str2, int len1, int len2); + +/** + * Parse the integer value from str and return it. + * + * @param[in] str from which to parse the integer value. + * @return the integer value of str + */ +int shell_parse_int(char *str); + +/** + * Process a command line string given in cmd_line against the + * commands given by cmds. If the command form cmd_line matches + * against a command string defined in cmds, the function callback + * for that command is executet. + *
+ * Note: the arguments form the command line are passed to the command + * function, but the command function is responsible for checkeing the arguemts. + * + * @param[in] *cmds pointer to shell commands structure + * @param[in] *cmd_line pointer to command line string + * @return SHELL_PROCESS_OK if command and arguments where understood, + * SHELL_PROCESS_ERR_ARGS_MAX if to many arguments are given, + * SHELL_PROCESS_ERR_ARGS_LEN if an argument string was too long, + * SHELL_PROCESS_ERR_CMD_UNK if the command was unknown + */ +int shell_process_cmds(shell_cmds *cmds, char *cmd_line); + +/** + * Process a command line. For details see {@link shell_process_cmds}. + * This method has to be implemented by a specific shell. The implementation + * must pass a valid {@link shell_cmds} struct to {@link shell_process_cmds}. + * + * @param[in] *cmd_line see {@link shell_process_cmds} + * @return see {@link shell_process_cmds} + */ +int shell_process(char *cmd_line); + +#endif diff --git a/lib/libconio.a b/lib/libconio.a new file mode 100755 index 00000000..8e91c359 Binary files /dev/null and b/lib/libconio.a differ diff --git a/lib/libnrf24l01.a b/lib/libnrf24l01.a new file mode 100755 index 00000000..ca499583 Binary files /dev/null and b/lib/libnrf24l01.a differ diff --git a/lib/libnrf24l01_meta.a b/lib/libnrf24l01_meta.a new file mode 100755 index 00000000..6a6c741d Binary files /dev/null and b/lib/libnrf24l01_meta.a differ diff --git a/lib/libserial.a b/lib/libserial.a new file mode 100755 index 00000000..5862ddd4 Binary files /dev/null and b/lib/libserial.a differ diff --git a/lib/libshell.a b/lib/libshell.a new file mode 100755 index 00000000..97a7c178 Binary files /dev/null and b/lib/libshell.a differ diff --git a/main.cpp b/main.cpp new file mode 100755 index 00000000..4a2bce79 --- /dev/null +++ b/main.cpp @@ -0,0 +1,126 @@ +/* + * main.cpp + * + * Created on: May 6, 2013 + * Author: joao + */ + + +#include "rf24/RF24.h" +#include +#include "remote_defines.h" +#include "flash.h" +#include + +extern "C" +{ +#include "conio/conio.h" +#include "serial/serial.h" +#include "timer_msp.h" +} + +#define BLINK_RED_LED P2OUT ^= BIT1; + + +unsigned long int last_blink_millis = 0; + +typedef struct +{ + uint8_t var1; + uint8_t var2; + uint8_t var3; + uint8_t var4; + +}payload; + +payload var; + +// main loop +int main(void) +{ + WDTCTL = WDTPW + WDTHOLD; + + BCSCTL1 = CALBC1_8MHZ; // Set DCO to 1MHz + DCOCTL = CALDCO_8MHZ; + + uint32_t last_millis = 0; + + P2DIR |= BIT1 + BIT0; +// +// serial_init(9600); + + default_timer(); + __bis_SR_register(GIE); + + RF24 radio = RF24(); + + var.var1 = 20; + + + while(millis() < 1000); + + // Radio pipe addresses for the 2 nodes to communicate. + const uint64_t pipes[] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; + + // Setup and configure rf radio + radio.begin(); + + // optionally, increase the delay between retries & # of retries + radio.setRetries(15,1); + + // optionally, reduce the payload size. seems to + // improve reliability + radio.setPayloadSize(sizeof(payload)); + + radio.setDataRate(RF24_250KBPS); + + radio.setChannel(100); + radio.setPALevel(RF24_PA_LOW); + + // Open pipes to other nodes for communication + radio.openWritingPipe(pipes[0]); + radio.openReadingPipe(1,pipes[1]); + + + + // Start listening + radio.startListening(); + + // Dump the configuration of the rf unit for debugging + radio.printDetails(); + + uint32_t dif = 0; + var.var3 = dif/10; + + //radio.setPALevel(RF24_PA_MAX); + while(1) + { + + + if( millis()- last_millis > 100) + { + last_millis = millis(); + BLINK_RED_LED; + + radio.startListening(); + radio.stopListening(); + + var.var2 = last_millis / 1000; + + + radio.write(&var, sizeof(payload)); + + dif = (millis()- last_millis) / 10; + var.var3 = dif; + + } + + } + + + + return 0; + + +} + diff --git a/remote_defines.h b/remote_defines.h new file mode 100755 index 00000000..d96e3e7b --- /dev/null +++ b/remote_defines.h @@ -0,0 +1,47 @@ +/* + * remote_defines.h + * + * Created on: May 9, 2013 + * Author: joao + */ + +#ifndef REMOTE_DEFINES_H_ +#define REMOTE_DEFINES_H_ + +#define COM_DRV_ZERO 690 +#define COM_DRV_FRONT 784 +#define COM_DRV_REAR 598 +#define COM_SERVO_ZERO 645 +#define COM_SERVO_RIGHT 733 +#define COM_SERVO_LEFT 537 +#define ADC_TH 10 + +#define DRV_ZERO 0 +#define DRV_REAR -99 +#define DRV_FRONT 99 + +#define ADC_ANALOG_LEFT 3 +#define ADC_ANALOG_RIGHT 0 + +#define SEND_MSG_TIME 80 + +#define ASK_BIT 0x10 + +typedef struct ROSpberryRemote +{ + int16_t linear; + int16_t steer; + uint8_t buttons; + +}RC_remote; + + +typedef struct Analog_properties +{ + int max; + int min; + int center; + int deadzone; +}Analog; + +#endif /* REMOTE_DEFINES_H_ */ diff --git a/RF24.cpp b/rf24/RF24.cpp similarity index 90% rename from RF24.cpp rename to rf24/RF24.cpp index 9471583d..68d3668e 100644 --- a/RF24.cpp +++ b/rf24/RF24.cpp @@ -10,6 +10,13 @@ #include "RF24_config.h" #include "RF24.h" +extern "C" { +#include "spi.h" +} + +#define LOW 0 +#define HIGH 1 + /****************************************************************************/ void RF24::csn(int mode) @@ -18,19 +25,23 @@ void RF24::csn(int mode) // If we assume 2Mbs data rate and 16Mhz clock, a // divider of 4 is the minimum we want. // CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz -#ifdef ARDUINO - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); - SPI.setClockDivider(SPI_CLOCK_DIV4); -#endif - digitalWrite(csn_pin,mode); + //TODO: change speed if necessary + + if (mode) + spi_cs_high(); + else + spi_cs_low(); + } /****************************************************************************/ void RF24::ce(int level) { - digitalWrite(ce_pin,level); + if(level) + spi_ce_high(); + else + spi_ce_low(); } /****************************************************************************/ @@ -40,9 +51,9 @@ uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len) uint8_t status; csn(LOW); - status = SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) ); + status = spi_transferByte( R_REGISTER | ( REGISTER_MASK & reg ) ); while ( len-- ) - *buf++ = SPI.transfer(0xff); + *buf++ = spi_transferByte(0xff); csn(HIGH); @@ -54,8 +65,8 @@ uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len) uint8_t RF24::read_register(uint8_t reg) { csn(LOW); - SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) ); - uint8_t result = SPI.transfer(0xff); + spi_transferByte( R_REGISTER | ( REGISTER_MASK & reg ) ); + uint8_t result = spi_transferByte(0xff); csn(HIGH); return result; @@ -68,9 +79,9 @@ uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len) uint8_t status; csn(LOW); - status = SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) ); + status = spi_transferByte( W_REGISTER | ( REGISTER_MASK & reg ) ); while ( len-- ) - SPI.transfer(*buf++); + spi_transferByte(*buf++); csn(HIGH); @@ -86,8 +97,8 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value) IF_SERIAL_DEBUG(printf_P(PSTR("write_register(%02x,%02x)\r\n"),reg,value)); csn(LOW); - status = SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) ); - SPI.transfer(value); + status = spi_transferByte( W_REGISTER | ( REGISTER_MASK & reg ) ); + spi_transferByte(value); csn(HIGH); return status; @@ -107,11 +118,11 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len) //printf("[Writing %u bytes %u blanks]",data_len,blank_len); csn(LOW); - status = SPI.transfer( W_TX_PAYLOAD ); + status = spi_transferByte( W_TX_PAYLOAD ); while ( data_len-- ) - SPI.transfer(*current++); + spi_transferByte(*current++); while ( blank_len-- ) - SPI.transfer(0); + spi_transferByte(0); csn(HIGH); return status; @@ -130,11 +141,11 @@ uint8_t RF24::read_payload(void* buf, uint8_t len) //printf("[Reading %u bytes %u blanks]",data_len,blank_len); csn(LOW); - status = SPI.transfer( R_RX_PAYLOAD ); + status = spi_transferByte( R_RX_PAYLOAD ); while ( data_len-- ) - *current++ = SPI.transfer(0xff); + *current++ = spi_transferByte(0xff); while ( blank_len-- ) - SPI.transfer(0xff); + spi_transferByte(0xff); csn(HIGH); return status; @@ -147,7 +158,7 @@ uint8_t RF24::flush_rx(void) uint8_t status; csn(LOW); - status = SPI.transfer( FLUSH_RX ); + status = spi_transferByte( FLUSH_RX ); csn(HIGH); return status; @@ -160,7 +171,7 @@ uint8_t RF24::flush_tx(void) uint8_t status; csn(LOW); - status = SPI.transfer( FLUSH_TX ); + status = spi_transferByte( FLUSH_TX ); csn(HIGH); return status; @@ -173,7 +184,7 @@ uint8_t RF24::get_status(void) uint8_t status; csn(LOW); - status = SPI.transfer( NOP ); + status = spi_transferByte( NOP ); csn(HIGH); return status; @@ -188,7 +199,7 @@ void RF24::print_status(uint8_t status) (status & _BV(RX_DR))?1:0, (status & _BV(TX_DS))?1:0, (status & _BV(MAX_RT))?1:0, - ((status >> RX_P_NO) & B111), + ((status >> RX_P_NO) & 0b111), (status & _BV(TX_FULL))?1:0 ); } @@ -199,8 +210,8 @@ void RF24::print_observe_tx(uint8_t value) { printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"), value, - (value >> PLOS_CNT) & B1111, - (value >> ARC_CNT) & B1111 + (value >> PLOS_CNT) & 0b1111, + (value >> ARC_CNT) & 0b1111 ); } @@ -238,8 +249,8 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty) /****************************************************************************/ -RF24::RF24(uint8_t _cepin, uint8_t _cspin): - ce_pin(_cepin), csn_pin(_cspin), wide_band(true), p_variant(false), +RF24::RF24(): + wide_band(true), p_variant(false), payload_size(32), ack_payload_available(false), dynamic_payloads_enabled(false), pipe0_reading_address(0) { @@ -322,22 +333,18 @@ void RF24::printDetails(void) print_byte_register(PSTR("CONFIG"),CONFIG); print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2); - printf_P(PSTR("Data Rate\t = %S\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()])); - printf_P(PSTR("Model\t\t = %S\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()])); - printf_P(PSTR("CRC Length\t = %S\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()])); - printf_P(PSTR("PA Power\t = %S\r\n"),pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()])); + printf_P(PSTR("Data Rate\t = %s\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()])); + printf_P(PSTR("Model\t\t = %s\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()])); + printf_P(PSTR("CRC Length\t = %s\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()])); + printf_P(PSTR("PA Power\t = %s\r\n"),pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()])); } /****************************************************************************/ void RF24::begin(void) { - // Initialize pins - pinMode(ce_pin,OUTPUT); - pinMode(csn_pin,OUTPUT); - - // Initialize SPI bus - SPI.begin(); + // Initialize SPI bus , CS and CE pins + spi_init(1000000,8); ce(LOW); csn(HIGH); @@ -353,7 +360,7 @@ void RF24::begin(void) // Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier // WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet // sizes must never be used. See documentation for a more complete explanation. - write_register(SETUP_RETR,(B0100 << ARD) | (B1111 << ARC)); + write_register(SETUP_RETR,(0b0100 << ARD) | (0b1111 << ARC)); // Restore our default PA level setPALevel( RF24_PA_MAX ) ; @@ -526,8 +533,8 @@ uint8_t RF24::getDynamicPayloadSize(void) uint8_t result = 0; csn(LOW); - SPI.transfer( R_RX_PL_WID ); - result = SPI.transfer(0xff); + spi_transferByte( R_RX_PL_WID ); + result = spi_transferByte(0xff); csn(HIGH); return result; @@ -555,7 +562,7 @@ bool RF24::available(uint8_t* pipe_num) { // If the caller wants the pipe number, include that if ( pipe_num ) - *pipe_num = ( status >> RX_P_NO ) & B111; + *pipe_num = ( status >> RX_P_NO ) & 0b111; // Clear the status bit @@ -639,17 +646,17 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address) if (child <= 6) { // For pipes 2-5, only write the LSB - if ( child < 2 ) - write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast(&address), 5); - else - write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast(&address), 1); + if ( child < 2 ) + write_register(child_pipe[child], reinterpret_cast(&address), 5); + else + write_register(child_pipe[child], reinterpret_cast(&address), 1); - write_register(pgm_read_byte(&child_payload_size[child]),payload_size); + write_register(child_payload_size[child],payload_size); - // Note it would be more efficient to set all of the bits for all open - // pipes at once. However, I thought it would make the calling code - // more simple to do it this way. - write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child]))); + // Note it would be more efficient to set all of the bits for all open + // pipes at once. However, I thought it would make the calling code + // more simple to do it this way. + write_register(EN_RXADDR,read_register(EN_RXADDR) | (1<(buf); csn(LOW); - SPI.transfer( W_ACK_PAYLOAD | ( pipe & B111 ) ); + spi_transferByte( W_ACK_PAYLOAD | ( pipe & 0b111 ) ); const uint8_t max_payload_size = 32; uint8_t data_len = min(len,max_payload_size); while ( data_len-- ) - SPI.transfer(*current++); + spi_transferByte(*current++); csn(HIGH); } @@ -753,7 +760,7 @@ bool RF24::isPVariant(void) void RF24::setAutoAck(bool enable) { if ( enable ) - write_register(EN_AA, B111111); + write_register(EN_AA, 0b111111); else write_register(EN_AA, 0); } diff --git a/RF24.h b/rf24/RF24.h similarity index 98% rename from RF24.h rename to rf24/RF24.h index 18914f09..ff4b8561 100644 --- a/RF24.h +++ b/rf24/RF24.h @@ -15,7 +15,7 @@ #ifndef __RF24_H__ #define __RF24_H__ -#include +#include /** * Power Amplifier level. @@ -229,13 +229,10 @@ class RF24 /** * Constructor * - * Creates a new instance of this driver. Before using, you create an instance - * and send in the unique pins that this chip is connected to. + * Creates a new instance of this driver. Before using, you create an instance. * - * @param _cepin The pin attached to Chip Enable on the RF module - * @param _cspin The pin attached to Chip Select */ - RF24(uint8_t _cepin, uint8_t _cspin); + RF24(); /** * Begin operation of the chip diff --git a/RF24_config.h b/rf24/RF24_config.h similarity index 57% rename from RF24_config.h rename to rf24/RF24_config.h index fc7397fb..4ff19fbd 100644 --- a/RF24_config.h +++ b/rf24/RF24_config.h @@ -10,22 +10,32 @@ #ifndef __RF24_CONFIG_H__ #define __RF24_CONFIG_H__ -#if ARDUINO < 100 -#include -#else -#include -#endif - #include // Stuff that is normally provided by Arduino #ifdef ARDUINO #include +#if ARDUINO < 100 +#include +#else +#include +#endif +#elif defined(MSP430) +#include +extern "C"{ +#include "conio/conio.h" +#include "timer_msp.h" +} +#include +#include +#include +//extern HardwareSPI SPI; +#define _BV(x) (1<<(x)) #else #include #include #include -extern HardwareSPI SPI; +//extern HardwareSPI SPI; #define _BV(x) (1<<(x)) #endif @@ -50,6 +60,29 @@ extern HardwareSPI SPI; #ifdef ARDUINO #include #define PRIPSTR "%S" +#elif defined(STELLARIS) +extern "C"{ +#include "utils/uartstdio.h" +extern uint32_t millis(); +#define printf_P UARTprintf +} +typedef uint16_t prog_uint16_t; +#define PSTR(x) (x) +#define strlen_P strlen +#define PROGMEM +#define pgm_read_word(p) (*(p)) +#define PRIPSTR "%s" + +#elif defined(MSP430) + +//extern unsigned long int millis(); +#define PSTR(x) (x) //ver isto +#define strlen_P strlen +#define printf_P cio_printf +#define PROGMEM +#define pgm_read_word(p) (*(p)) +#define PRIPSTR "%s" + #else typedef char const char; typedef uint16_t prog_uint16_t; @@ -61,5 +94,19 @@ typedef uint16_t prog_uint16_t; #define PRIPSTR "%s" #endif +#ifndef ARDUINO + +#define max(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; }) + +#define min(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + +#endif + #endif // __RF24_CONFIG_H__ // vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/nRF24L01.h b/rf24/nRF24L01.h similarity index 100% rename from nRF24L01.h rename to rf24/nRF24L01.h diff --git a/rf24/spi-msp430.c b/rf24/spi-msp430.c new file mode 100755 index 00000000..65510e23 --- /dev/null +++ b/rf24/spi-msp430.c @@ -0,0 +1,91 @@ +/* + * spi.c + * + * Created on: Apr 21, 2013 + * Author: bgouveia + */ + +#include + +#include "spi.h" +#include "spi_msp430.h" + + + + + +void spi_init(unsigned long bitrate,unsigned long datawidth){ + //SSI + + + UCB0CTL1 = UCSWRST; + + CS_DIR |= CS_PIN; + CS_PORT |= CS_PIN; + CE_DIR |= CE_PIN; + CE_PORT|= CE_PIN; + + IRQ_DIR &= ~IRQ_PIN; + + + P1SEL |= SOMI_PIN + SIMO_PIN + SCLK_PIN; + P1SEL2 |= SOMI_PIN + SIMO_PIN + SCLK_PIN; + + // 3-pin, 8-bit SPI master + UCB0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; + UCB0CTL1 |= UCSSEL_2; // SMCLK + + UCB0CTL1 &= ~UCSWRST; + + +} + +void spi_cs_low() +{ + CS_PORT &= ~CS_PIN; + +} + +void spi_cs_high() +{ + CS_PORT |= CS_PIN; +} + +void spi_ce_low() +{ + CE_PORT &= ~CE_PIN; + +} + +void spi_ce_high() +{ + CE_PORT |= CE_PIN; +} + + +uint8_t spi_transferByte(uint8_t data) +{ + + UCB0TXBUF = data; + + // wait for TX + while (!(IFG2 & UCB0TXIFG)); + + return UCB0RXBUF; + +} + +/*void delay(unsigned long msec) +{ + while(msec--) + { + __delay_cycles(1000); + } +} +void delayMicroseconds(unsigned long usec) +{ + while(usec--) + { + __delay_cycles(1); + } +}*/ diff --git a/rf24/spi.h b/rf24/spi.h new file mode 100755 index 00000000..8f114c78 --- /dev/null +++ b/rf24/spi.h @@ -0,0 +1,26 @@ +/* + * spi.h + * + * Created on: Apr 21, 2013 + * Author: bgouveia + */ + +#ifndef SPI_H_ +#define SPI_H_ + +#include + +void spi_init(unsigned long bitrate,unsigned long datawidth); +uint8_t spi_transferByte(uint8_t data); + +void spi_cs_low(); +void spi_cs_high(); + +void spi_ce_low(); +void spi_ce_high(); + +void delay(unsigned long msec); +void delayMicroseconds(unsigned long usec); + + +#endif /* SPI_H_ */ diff --git a/rf24/spi_msp430.h b/rf24/spi_msp430.h new file mode 100755 index 00000000..46ba141f --- /dev/null +++ b/rf24/spi_msp430.h @@ -0,0 +1,35 @@ +/* + * spi_msp430.h + * + * Created on: May 29, 2013 + * Author: joao + */ + +#ifndef SPI_MSP430_H_ +#define SPI_MSP430_H_ + +#include + +//#define CS_PIN_BASE P1OUT +#define CS_PORT P2OUT +#define CS_DIR P2DIR +#define CS_PIN BIT2 + +#define SIMO_PIN BIT7 +#define SOMI_PIN BIT6 +#define SCLK_PIN BIT5 + +//#define CE_PIN_BASE P1OUT +#define CE_PIN BIT3 +#define CE_PORT P2OUT +#define CE_DIR P2DIR + +#define IRQ_PIN BIT3 +#define IRQ_PORT P1OUT +#define IRQ_DIR P1DIR + +#define POWER_DIR P1DIR +#define POWER_PORT P1OUT +#define POWER_PIN BIT1 + +#endif /* SPI_MSP430_H_ */ diff --git a/tests/README b/tests/README deleted file mode 100644 index 43ceaf54..00000000 --- a/tests/README +++ /dev/null @@ -1,7 +0,0 @@ -The sketches in this directory are intended to be checkin tests. -No code should be pushed to github without these tests passing. - -See "runtests.sh" script inside each sketch dir. This script is fully compatible with -git bisest. - -Note that this requires python and py-serial diff --git a/tests/native/Jamfile b/tests/native/Jamfile deleted file mode 100644 index 10d0336c..00000000 --- a/tests/native/Jamfile +++ /dev/null @@ -1,300 +0,0 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = RF24 ; - -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; - -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; - -# Host-specific overrides for locations -if $(OS) = MACOSX -{ -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; -} - -# Where is everything? -ARDUINO_VERSION ?= 22 ; -SKETCH_DIR = $(HOME)/Source/Arduino ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; -ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; -SKETCH_LIB = $(SKETCH_DIR)/libraries ; -AVR_AS = $(AVR_TOOLS_PATH)/avr-as ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; - -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H HAL=1 ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -ASFLAGS = -mmcu=$(MCU) ; -CFLAGS = -Os -Wall -Wextra $(ASFLAGS) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; - -# Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; -HDRS += [ GLOB $(HDRS) : utility ] ; - -# 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 ] ; - -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; - -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; - -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; - -rule GitVersion -{ - Always $(<) ; - Depends all : $(<) ; -} - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -# GitVersion version.h ; - -rule AvrAsm -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrAsm -{ - $(AVR_AS) $(ASFLAGS) -o $(<) $(>) -} - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule AvrAsmFromC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrAsmFromC++ -{ - $(AVR_CXX) -S -fverbose-asm -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .S : AvrAsm $(<) : $(>) ; - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - -# -# Native -# - -OUT_DIR_NATIVE = out_native ; -OUT_NATIVE = $(OUT_DIR_NATIVE)/$(PROJECT_NAME) ; -NATIVE_CORE = $(SKETCH_DIR)/hardware/native ; -HDRS = $(NATIVE_CORE) $(HDRS) ; -NATIVE_CORE_MODULES = [ GLOB $(NATIVE_CORE) : *.c *.cpp ] ; -NATIVE_MODULES = ; -DEFINES += NATIVE ; - -rule NativePde -{ - local _CPP = $(OUT_DIR_NATIVE)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - C++ $(<) : $(_CPP) ; -} - -rule UserObject -{ - switch $(>) - { - case *.pde : NativePde $(<) : $(>) ; - } -} - -rule Objects -{ - for _I in $(<) - { - local _O = $(OUT_DIR_NATIVE)/$(_I:B).o ; - Object $(_O) : $(_I) ; - } -} - -rule Main -{ - MainFromObjects $(<) : $(OUT_DIR_NATIVE)/$(>:B).o ; - Objects $(>) ; -} - -actions C++ -{ - c++ -c -o $(<) $(CCHDRS) $(CCDEFS) $(>) -} - -actions Link -{ - c++ -o $(<) $(>) -} - - - -MkDir $(OUT_DIR_NATIVE) ; -Depends $(OUT_NATIVE) : $(OUT_DIR_NATIVE) ; -Main $(OUT_NATIVE) : $(NATIVE_CORE_MODULES) $(NATIVE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; - -Depends native : $(OUT_NATIVE) ; - diff --git a/tests/native/pingpair_irq.pde b/tests/native/pingpair_irq.pde deleted file mode 100644 index 99c2cdf9..00000000 --- a/tests/native/pingpair_irq.pde +++ /dev/null @@ -1,223 +0,0 @@ -/* - Copyright (C) 2011 James Coliz, Jr. - - 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. - */ - -/** - * Interrupt-driven test for native target - * - * This example is the friendliest for the native target because it doesn't do - * any polling. Made a slight change to call done() at the end of setup. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 8 & 9 - -RF24 radio(8,9); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const short role_pin = 7; - -// -// Topology -// - -// Single radio pipe address for the 2 nodes to communicate. -const uint64_t pipe = 0xE8E8F0F0E1LL; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes in this -// system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_sender = 1, role_receiver } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; - -// The role of the current running sketch -role_e role; - -// Interrupt handler, check the radio because we got an IRQ -void check_radio(void); - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_sender; - else - role = role_receiver; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/examples/pingpair_irq/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // We will be using the Ack Payload feature, so please enable it - radio.enableAckPayload(); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens a single pipe for these two nodes to communicate - // back and forth. One listens on it, the other talks to it. - - if ( role == role_sender ) - { - radio.openWritingPipe(pipe); - } - else - { - radio.openReadingPipe(1,pipe); - } - - // - // Start listening - // - - if ( role == role_receiver ) - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); - - // - // Attach interrupt handler to interrupt #0 (using pin 2) - // on BOTH the sender and receiver - // - - attachInterrupt(0, check_radio, FALLING); - - // - // On the native target, this is as far as we get - // -#if NATIVE - done(); -#endif -} - -static uint32_t message_count = 0; - -void loop(void) -{ - // - // Sender role. Repeatedly send the current time - // - - if (role == role_sender) - { - // Take the time, and send it. - unsigned long time = millis(); - printf("Now sending %lu\n\r",time); - radio.startWrite( &time, sizeof(unsigned long) ); - - // Try again soon - delay(2000); - } - - // - // Receiver role: Does nothing! All the work is in IRQ - // - -} - -void check_radio(void) -{ - // What happened? - bool tx,fail,rx; - radio.whatHappened(tx,fail,rx); - - // Have we successfully transmitted? - if ( tx ) - { - if ( role == role_sender ) - printf("Send:OK\n\r"); - - if ( role == role_receiver ) - printf("Ack Payload:Sent\n\r"); - } - - // Have we failed to transmit? - if ( fail ) - { - if ( role == role_sender ) - printf("Send:Failed\n\r"); - - if ( role == role_receiver ) - printf("Ack Payload:Failed\n\r"); - } - - // Transmitter can power down for now, because - // the transmission is done. - if ( ( tx || fail ) && ( role == role_sender ) ) - radio.powerDown(); - - // Did we receive a message? - if ( rx ) - { - // If we're the sender, we've received an ack payload - if ( role == role_sender ) - { - radio.read(&message_count,sizeof(message_count)); - printf("Ack:%lu\n\r",(unsigned long)message_count); - } - - // If we're the receiver, we've received a time message - if ( role == role_receiver ) - { - // Get this payload and dump it - static unsigned long got_time; - radio.read( &got_time, sizeof(got_time) ); - printf("Got payload %lu\n\r",got_time); - - // Add an ack packet for the next time around. This is a simple - // packet counter - radio.writeAckPayload( 1, &message_count, sizeof(message_count) ); - ++message_count; - } - } -} - -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/tests/native/printf.h b/tests/native/printf.h deleted file mode 100644 index df6c46ae..00000000 --- a/tests/native/printf.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (C) 2011 James Coliz, Jr. - - 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__ - -#include "WProgram.h" - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#endif // __PRINTF_H__ diff --git a/tests/pingpair_blocking/Jamfile b/tests/pingpair_blocking/Jamfile deleted file mode 100644 index 18244ec8..00000000 --- a/tests/pingpair_blocking/Jamfile +++ /dev/null @@ -1,219 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = SPI RF24 ; -PROJECT_DIRS = $(PWD) ; - -# (2) Board Information - -UPLOAD_PROTOCOL ?= arduino ; -UPLOAD_SPEED ?= 115200 ; -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 ; -AR = $(AVR_BIN)/avr-ar rcs ; -RANLIB = ; -OBJCOPY = $(AVR_BIN)/avr-objcopy ; -AVRDUDE ?= $(AVR_BIN)/avrdude ; - -# Flags - -DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -OPTIM = -Os ; -CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -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 = $(PROJECT_DIRS) $(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 Library -{ - LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; - Objects $(>) ; -} - -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 -} - -rule Arduino -{ - LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; - Main $(<) : $(>) ; - LinkLibraries $(<) : core libs ; - Hex $(<:B).hex : $(<) ; - for _p in $(PORTS) - { - Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; - } -} - -# -# Targets -# - -# Grab everything from the core directory -Library core : [ 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 -Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; - -# Main output executable -Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; diff --git a/tests/pingpair_blocking/pingpair_blocking.pde b/tests/pingpair_blocking/pingpair_blocking.pde deleted file mode 100644 index 1501d37c..00000000 --- a/tests/pingpair_blocking/pingpair_blocking.pde +++ /dev/null @@ -1,273 +0,0 @@ -/* - Copyright (C) 2011 James Coliz, Jr. - - 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. - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Test version of RF24, exposes some protected interface -// - -class RF24Test: public RF24 -{ -public: RF24Test(int a, int b): RF24(a,b) {} -}; - - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 8 & 9 - -RF24Test radio(8,9); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const int role_pin = 7; - -// -// Topology -// - -// Radio pipe addresses for the 2 nodes to communicate. -const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes -// in this system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_ping_out = 1, role_pong_back } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; - -// The role of the current running sketch -role_e role; - -// -// Test state -// - -bool done; //*< Are we done with the test? */ -bool passed; //*< Have we passed the test? */ -bool notified; //*< Have we notified the user we're done? */ -const int num_needed = 10; //*< How many success/failures until we're done? */ -int receives_remaining = num_needed; //*< How many ack packets until we declare victory? */ -int failures_remaining = num_needed; //*< How many more failed sends until we declare failure? */ -const int interval = 100; //*< ms to wait between sends */ - -char configuration = '1'; //*< Configuration key, one char sent in by the test framework to tell us how to configure, this is the default */ - -void one_ok(void) -{ - // Have we received enough yet? - if ( ! --receives_remaining ) - { - done = true; - passed = true; - } -} - -void one_failed(void) -{ - // Have we failed enough yet? - if ( ! --failures_remaining ) - { - done = true; - passed = false; - } -} - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_ping_out; - else - role = role_pong_back; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/tests/pingpair_blocking/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // get test config - // - - printf("+READY press any key to start\n\r\n\r"); - - while (! Serial.available() ) {} - configuration = Serial.read(); - printf("Configuration\t = %c\n\r",configuration); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens two pipes for these two nodes to communicate - // back and forth. - // Open 'our' pipe for writing - // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) - - if ( role == role_ping_out ) - { - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1,pipes[1]); - } - else - { - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1,pipes[0]); - } - - // - // Start listening - // - - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); - - if ( role == role_pong_back ) - printf("\n\r+OK "); -} - -void loop(void) -{ - // - // Ping out role. Repeatedly send the current time - // - - if (role == role_ping_out) - { - // First, stop listening so we can talk. - radio.stopListening(); - - // Take the time, and send it. This will block until complete - unsigned long time = millis(); - printf("Now sending %lu...",time); - radio.write( &time, sizeof(unsigned long) ); - - // Now, continue listening - radio.startListening(); - - // Wait here until we get a response, or timeout (250ms) - unsigned long started_waiting_at = millis(); - bool timeout = false; - while ( ! radio.available() && ! timeout ) - if (millis() - started_waiting_at > 200 ) - timeout = true; - - // Describe the results - if ( timeout ) - { - printf("Failed, response timed out.\n\r"); - one_failed(); - } - else - { - // Grab the response, compare, and send to debugging spew - unsigned long got_time; - radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); - one_ok(); - } - - // Try again later - delay(250); - } - - // - // Pong back role. Receive each packet, dump it out, and send it back - // - - if ( role == role_pong_back ) - { - // if there is data ready - if ( radio.available() ) - { - // Dump the payloads until we've gotten everything - unsigned long got_time; - bool done = false; - while (!done) - { - // Fetch the payload, and see if this was the last one. - done = radio.read( &got_time, sizeof(unsigned long) ); - - // Spew it - printf("Got payload %lu...",got_time); - - // Delay just a little bit to let the other unit - // make the transition to receiver - delay(20); - } - - // First, stop listening so we can talk - radio.stopListening(); - - // Send the final one back. - radio.write( &got_time, sizeof(unsigned long) ); - printf("Sent response.\n\r"); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - - } - } - - // - // Stop the test if we're done and report results - // - if ( done && ! notified ) - { - notified = true; - - printf("\n\r+OK "); - if ( passed ) - printf("PASS\n\r\n\r"); - else - printf("FAIL\n\r\n\r"); - } -} -// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/tests/pingpair_blocking/printf.h b/tests/pingpair_blocking/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/tests/pingpair_blocking/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/tests/pingpair_blocking/runtest.py b/tests/pingpair_blocking/runtest.py deleted file mode 100755 index 0772f950..00000000 --- a/tests/pingpair_blocking/runtest.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -import sys,serial - -def read_until(token): - while 1: - line = ser.readline(None) - sys.stdout.write(line) - - if (line.startswith(token)): - break - return line - - -ser = serial.Serial(sys.argv[1], 57600, timeout=5, dsrdtr=False, rtscts=False) - -read_until("+READY") -ser.write(sys.argv[2]) - -line = read_until("+OK") -ser.close() -if (line.find("PASS") != -1): - sys.exit(0) -else: - sys.exit(1) diff --git a/tests/pingpair_blocking/runtests.sh b/tests/pingpair_blocking/runtests.sh deleted file mode 100755 index e1064487..00000000 --- a/tests/pingpair_blocking/runtests.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# Connect u0 to receiver, u1 to sender - -jam u0 u1 && expect test.ex diff --git a/tests/pingpair_blocking/test.ex b/tests/pingpair_blocking/test.ex deleted file mode 100755 index ea992add..00000000 --- a/tests/pingpair_blocking/test.ex +++ /dev/null @@ -1,11 +0,0 @@ -#/usr/bin/expect - -set timeout 100 -spawn picocom -b 57600 /dev/ttyUSB0 -expect "+READY" -send "1" -expect "+OK" -spawn picocom -b 57600 /dev/ttyUSB1 -expect "+READY" -send "1" -expect "+OK" diff --git a/tests/pingpair_test/Jamfile b/tests/pingpair_test/Jamfile deleted file mode 100644 index 18244ec8..00000000 --- a/tests/pingpair_test/Jamfile +++ /dev/null @@ -1,219 +0,0 @@ -# (1) Project Information - -PROJECT_LIBS = SPI RF24 ; -PROJECT_DIRS = $(PWD) ; - -# (2) Board Information - -UPLOAD_PROTOCOL ?= arduino ; -UPLOAD_SPEED ?= 115200 ; -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 ; -AR = $(AVR_BIN)/avr-ar rcs ; -RANLIB = ; -OBJCOPY = $(AVR_BIN)/avr-objcopy ; -AVRDUDE ?= $(AVR_BIN)/avrdude ; - -# Flags - -DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -OPTIM = -Os ; -CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -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 = $(PROJECT_DIRS) $(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 Library -{ - LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ; - Objects $(>) ; -} - -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 -} - -rule Arduino -{ - LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ; - Main $(<) : $(>) ; - LinkLibraries $(<) : core libs ; - Hex $(<:B).hex : $(<) ; - for _p in $(PORTS) - { - Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ; - } -} - -# -# Targets -# - -# Grab everything from the core directory -Library core : [ 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 -Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; - -# Main output executable -Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ; diff --git a/tests/pingpair_test/pingpair_test.pde b/tests/pingpair_test/pingpair_test.pde deleted file mode 100644 index 6acbf51d..00000000 --- a/tests/pingpair_test/pingpair_test.pde +++ /dev/null @@ -1,435 +0,0 @@ -/* - Copyright (C) 2011 James Coliz, Jr. - - 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. - */ - -/** - * Full test on single RF pair - * - * This sketches uses as many RF24 methods as possible in a single test. - * - * To operate: - * Upload this sketch on two nodes, each with IRQ -> pin 2 - * One node needs pin 7 -> GND, the other NC. That's the receiving node - * Monitor the sending node's serial output - * Look for "+OK PASS" or "+OK FAIL" - */ - -#include -#include "nRF24L01.h" -#include "RF24.h" -#include "printf.h" - -// -// Hardware configuration -// - -// Set up nRF24L01 radio on SPI bus plus pins 8 & 9 - -RF24 radio(8,9); - -// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver -// Leave open to be the 'ping' transmitter -const short role_pin = 7; - -// -// Topology -// - -// Single radio pipe address for the 2 nodes to communicate. -const uint64_t pipe = 0xE8E8F0F0E1LL; - -// -// Role management -// -// Set up role. This sketch uses the same software for all the nodes in this -// system. Doing so greatly simplifies testing. The hardware itself specifies -// which node it is. -// -// This is done through the role_pin -// - -// The various roles supported by this sketch -typedef enum { role_sender = 1, role_receiver } role_e; - -// The debug-friendly names of those roles -const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"}; - -// The role of the current running sketch -role_e role; - -// Interrupt handler, check the radio because we got an IRQ -void check_radio(void); - -// -// Payload -// - -const int min_payload_size = 4; -const int max_payload_size = 32; -int payload_size_increments_by = 2; -int next_payload_size = min_payload_size; - -char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char - -// -// Test state -// - -bool done; //*< Are we done with the test? */ -bool passed; //*< Have we passed the test? */ -bool notified; //*< Have we notified the user we're done? */ -const int num_needed = 10; //*< How many success/failures until we're done? */ -int receives_remaining = num_needed; //*< How many ack packets until we declare victory? */ -int failures_remaining = num_needed; //*< How many more failed sends until we declare failure? */ -const int interval = 100; //*< ms to wait between sends */ - -char configuration = '1'; //*< Configuration key, one char sent in by the test framework to tell us how to configure, this is the default */ - -uint8_t pipe_number = 1; // Which pipe to send on. - -void one_ok(void) -{ - // Have we received enough yet? - if ( ! --receives_remaining ) - { - done = true; - passed = true; - } -} - -void one_failed(void) -{ - // Have we failed enough yet? - if ( ! --failures_remaining ) - { - done = true; - passed = false; - } -} - -// -// Setup -// - -void setup(void) -{ - // - // Role - // - - // set up the role pin - pinMode(role_pin, INPUT); - digitalWrite(role_pin,HIGH); - delay(20); // Just to get a solid reading on the role pin - - // read the address pin, establish our role - if ( digitalRead(role_pin) ) - role = role_sender; - else - role = role_receiver; - - // - // Print preamble - // - - Serial.begin(57600); - printf_begin(); - printf("\n\rRF24/tests/pingpair_test/\n\r"); - printf("ROLE: %s\n\r",role_friendly_name[role]); - - // - // Read configuration from serial - // - // It would be a much better test if this program could accept configuration - // from the serial port. Then it would be possible to run the same test under - // lots of different circumstances. - // - // The idea is that we will print "+READY" at this point. The python script - // will wait for it, and then send down a configuration script that we - // execute here and then run with. - // - // The test controller will need to configure the receiver first, then go run - // the test on the sender. - // - - printf("+READY press any key to start\n\r\n\r"); - - while (! Serial.available() ) {} - configuration = Serial.read(); - printf("Configuration\t = %c\n\r",configuration); - - // - // Setup and configure rf radio - // - - radio.begin(); - - // We will be using the Ack Payload feature, so please enable it - radio.enableAckPayload(); - - // Config 2 is special radio config - if (configuration=='2') - { - radio.setCRCLength(RF24_CRC_8); - radio.setDataRate(RF24_250KBPS); - radio.setChannel(10); - } - else - { - //Otherwise, default radio config - - // Optional: Increase CRC length for improved reliability - radio.setCRCLength(RF24_CRC_16); - - // Optional: Decrease data rate for improved reliability - radio.setDataRate(RF24_1MBPS); - - // Optional: Pick a high channel - radio.setChannel(90); - } - - // Config 3 is static payloads only - if (configuration == '3') - { - next_payload_size = 16; - payload_size_increments_by = 0; - radio.setPayloadSize(next_payload_size); - } - else - { - // enable dynamic payloads - radio.enableDynamicPayloads(); - } - - // Config 4 tests out a higher pipe ## - if (configuration == '4' && role == role_sender) - { - // Set top 4 bytes of the address in pipe 1 - radio.openReadingPipe(1,pipe & 0xFFFFFFFF00ULL); - - // indicate the pipe to use - pipe_number = 5; - } - else if ( role == role_sender ) - { - radio.openReadingPipe(5,0); - } - - // - // Open pipes to other nodes for communication - // - - // This simple sketch opens a single pipe for these two nodes to communicate - // back and forth. One listens on it, the other talks to it. - - if ( role == role_sender ) - { - radio.openWritingPipe(pipe); - } - else - { - radio.openReadingPipe(pipe_number,pipe); - } - - // - // Start listening - // - - if ( role == role_receiver ) - radio.startListening(); - - // - // Dump the configuration of the rf unit for debugging - // - - radio.printDetails(); - - // - // Attach interrupt handler to interrupt #0 (using pin 2) - // on BOTH the sender and receiver - // - - attachInterrupt(0, check_radio, FALLING); - - if ( role == role_receiver ) - printf("\n\r+OK "); -} - -// -// Print buffer -// -// Printing from the interrupt handler is a bad idea, so we print from there -// to this intermediate buffer -// - -char prbuf[1000]; -char *prbuf_end = prbuf + sizeof(prbuf); -char *prbuf_in = prbuf; -char *prbuf_out = prbuf; - -// -// Loop -// - -static uint32_t message_count = 0; -static uint32_t last_message_count = 0; - -void loop(void) -{ - // - // Sender role. Repeatedly send the current time - // - - if (role == role_sender && !done) - { - // The payload will always be the same, what will change is how much of it we send. - static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012"; - - // First, stop listening so we can talk. - radio.stopListening(); - - // Send it. This will block until complete - printf("\n\rNow sending length %i...",next_payload_size); - radio.startWrite( send_payload, next_payload_size ); - - // Update size for next time. - next_payload_size += payload_size_increments_by; - if ( next_payload_size > max_payload_size ) - next_payload_size = min_payload_size; - - // Try again soon - delay(interval); - - // Timeout if we have not received anything back ever - if ( ! last_message_count && millis() > interval * 100 ) - { - printf("No responses received. Are interrupts connected??\n\r"); - done = true; - } - } - - // - // Receiver role: Does nothing! All the work is in IRQ - // - - // - // Spew print buffer - // - - size_t write_length = prbuf_in - prbuf_out; - if ( write_length ) - { - Serial.write(reinterpret_cast(prbuf_out),write_length); - prbuf_out += write_length; - } - - // - // Stop the test if we're done and report results - // - if ( done && ! notified ) - { - notified = true; - - printf("\n\r+OK "); - if ( passed ) - printf("PASS\n\r\n\r"); - else - printf("FAIL\n\r\n\r"); - } - -} - -void check_radio(void) -{ - // What happened? - bool tx,fail,rx; - radio.whatHappened(tx,fail,rx); - - // Have we successfully transmitted? - if ( tx ) - { - if ( role == role_sender ) - prbuf_in += sprintf(prbuf_in,"Send:OK "); - - if ( role == role_receiver ) - prbuf_in += sprintf(prbuf_in,"Ack Payload:Sent\n\r"); - } - - // Have we failed to transmit? - if ( fail ) - { - if ( role == role_sender ) - { - prbuf_in += sprintf(prbuf_in,"Send:Failed "); - - // log status of this line - one_failed(); - } - - if ( role == role_receiver ) - prbuf_in += sprintf(prbuf_in,"Ack Payload:Failed\n\r"); - } - - // Transmitter can power down for now, because - // the transmission is done. - if ( ( tx || fail ) && ( role == role_sender ) ) - radio.powerDown(); - - // Did we receive a message? - if ( rx ) - { - // If we're the sender, we've received an ack payload - if ( role == role_sender ) - { - radio.read(&message_count,sizeof(message_count)); - prbuf_in += sprintf(prbuf_in,"Ack:%lu ",message_count); - - // is this ack what we were expecting? to account - // for failures, we simply want to make sure we get a - // DIFFERENT ack every time. - if ( ( message_count != last_message_count ) || ( configuration=='3' && message_count == 16 ) ) - { - prbuf_in += sprintf(prbuf_in,"OK "); - one_ok(); - } - else - { - prbuf_in += sprintf(prbuf_in,"FAILED "); - one_failed(); - } - last_message_count = message_count; - } - - // If we're the receiver, we've received a time message - if ( role == role_receiver ) - { - // Get this payload and dump it - size_t len = max_payload_size; - memset(receive_payload,0,max_payload_size); - - if ( configuration == '3' ) - len = next_payload_size; - else - len = radio.getDynamicPayloadSize(); - - radio.read( receive_payload, len ); - - // Put a zero at the end for easy printing - receive_payload[len] = 0; - - // Spew it - prbuf_in += sprintf(prbuf_in,"Recv size=%i val=%s len=%u\n\r",len,receive_payload,strlen(receive_payload)); - - // Add an ack packet for the next time around. - // Here we will report back how many bytes we got this time. - radio.writeAckPayload( pipe_number, &len, sizeof(len) ); - ++message_count; - } - } -} - -// vim:ai:cin:sts=2 sw=2 ft=cpp diff --git a/tests/pingpair_test/printf.h b/tests/pingpair_test/printf.h deleted file mode 100644 index b2efd56b..00000000 --- a/tests/pingpair_test/printf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2011 J. Coliz - - 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__ - -#ifdef ARDUINO - -int serial_putc( char c, FILE * ) -{ - Serial.write( c ); - - return c; -} - -void printf_begin(void) -{ - fdevopen( &serial_putc, 0 ); -} - -#else -#error This example is only for use on Arduino. -#endif // ARDUINO - -#endif // __PRINTF_H__ diff --git a/tests/pingpair_test/runtest.py b/tests/pingpair_test/runtest.py deleted file mode 100755 index 45fb65ce..00000000 --- a/tests/pingpair_test/runtest.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/opt/local/bin/python - -import sys,serial - -def read_until(token): - while 1: - line = ser.readline(None,"\r") - sys.stdout.write(line) - - if (line.startswith(token)): - break - return line - - -ser = serial.Serial(sys.argv[1], 57600, timeout=5, dsrdtr=False, rtscts=False) - -read_until("+READY") -ser.write(sys.argv[2]) - -line = read_until("+OK") -ser.close() -if (line.find("PASS") != -1): - sys.exit(0) -else: - sys.exit(1) diff --git a/tests/pingpair_test/runtests.sh b/tests/pingpair_test/runtests.sh deleted file mode 100755 index 4d02310b..00000000 --- a/tests/pingpair_test/runtests.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# Connect u0 to receiver, u0 to sender -# WARNING: Test config 2 only works with PLUS units. - -jam u0 u1 && expect test.ex 1 -sleep 1 -stty 57600 raw ignbrk hup < /dev/ttyUSB0 -sleep 1 -stty 57600 raw ignbrk hup < /dev/ttyUSB1 -expect test.ex 2 -sleep 1 -stty 57600 raw ignbrk hup < /dev/ttyUSB0 -sleep 1 -stty 57600 raw ignbrk hup < /dev/ttyUSB1 -expect test.ex 3 -sleep 1 -stty 57600 raw ignbrk hup < /dev/ttyUSB0 -sleep 1 -stty 57600 raw ignbrk hup < /dev/ttyUSB1 -expect test.ex 4 diff --git a/tests/pingpair_test/test.ex b/tests/pingpair_test/test.ex deleted file mode 100755 index a14ffef0..00000000 --- a/tests/pingpair_test/test.ex +++ /dev/null @@ -1,11 +0,0 @@ -#/usr/bin/expect - -set timeout 100 -spawn picocom -b 57600 /dev/ttyUSB0 -expect "+READY" -send [lindex $argv 0] -expect "+OK" -spawn picocom -b 57600 /dev/ttyUSB1 -expect "+READY" -send [lindex $argv 0] -expect "+OK" diff --git a/timer_msp.c b/timer_msp.c new file mode 100755 index 00000000..9f15db8e --- /dev/null +++ b/timer_msp.c @@ -0,0 +1,80 @@ +/* + * timer_msp.c + * + * Created on: 30 de Dez de 2012 + * Author: Asus + */ + +#include "timer_msp.h" +#include "msp430g2553.h" + +struct timer_msp timer0; + +void default_timer(void) +{ + timer0.s = 0; + timer0.ms = 0; + + if(BCSCTL1 == CALBC1_1MHZ ) + { + timer0.millis_var = 1000; + } + else if(BCSCTL1 == CALBC1_8MHZ) + { + timer0.millis_var = 8000; + } + else if(BCSCTL1 == CALBC1_12MHZ) + { + timer0.millis_var = 12000; + } + else if(BCSCTL1 == CALBC1_16MHZ) + { + timer0.millis_var = 16000; + } + + CCR0 = timer0.millis_var; + TACTL = TASSEL_2 + MC_1; + CCTL0 = CCIE; // CCR0 interrupt enabled +} + + + +unsigned long int millis(void) +{ + return(timer0.ms + timer0.s*1000L); +} + +#ifdef DELAY_MSP430 +void delay(unsigned long msec) +{ + while(msec--) + { + __delay_cycles(1000); + } +} +void delayMicroseconds(unsigned long usec) +{ + while(usec--) + { + __delay_cycles(1); + } +} +#endif + +//=========================================================================== +// Timer A0 interrupt service routine +#pragma vector=TIMER0_A0_VECTOR +__interrupt void Timer_A (void) +{ + timer0.ms++; + + + if(timer0.ms >= 1000) + { + timer0.s += 1; + timer0.ms -= 1000; + + } + //__bic_SR_register_on_exit(CPUOFF); + +} diff --git a/timer_msp.h b/timer_msp.h new file mode 100755 index 00000000..b452c1d9 --- /dev/null +++ b/timer_msp.h @@ -0,0 +1,28 @@ +/* + * timer_msp.h + * + * Created on: 30 de Dez de 2012 + * Author: Asus + */ + +#ifndef TIMER_MSP_H_ +#define TIMER_MSP_H_ + +struct timer_msp +{ + unsigned long int ms; + unsigned long int s; + unsigned int millis_var; +}; + +void default_timer(void); +unsigned long int millis(void); + +#ifndef DELAY_MSP430 +void delay(unsigned long msec); +void delayMicroseconds(unsigned long usec); +#endif + +extern struct timer_msp timer0; + +#endif /* TIMER_MSP_H_ */