From 390bf9ad86db418872c7842bf042f9fea22ce476 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Sun, 24 Mar 2013 15:37:42 +0100 Subject: digital/beacon: add lol-v2 unitary tests programs --- digital/beacon/tests/bouttons/Makefile | 44 +++ digital/beacon/tests/bouttons/atmega1281.ld | 97 +++++++ digital/beacon/tests/bouttons/configuration.h | 330 ++++++++++++++++++++++ digital/beacon/tests/bouttons/debug_avr.c | 104 +++++++ digital/beacon/tests/bouttons/debug_avr.h | 46 +++ digital/beacon/tests/bouttons/led.c | 135 +++++++++ digital/beacon/tests/bouttons/led.h | 54 ++++ digital/beacon/tests/bouttons/main_avr.c | 94 ++++++ digital/beacon/tests/bouttons/network_specific.c | 47 +++ digital/beacon/tests/bouttons/network_specific.h | 42 +++ digital/beacon/tests/codewheel/Makefile | 44 +++ digital/beacon/tests/codewheel/atmega1281.ld | 97 +++++++ digital/beacon/tests/codewheel/codewheel.c | 146 ++++++++++ digital/beacon/tests/codewheel/codewheel.h | 81 ++++++ digital/beacon/tests/codewheel/configuration.h | 330 ++++++++++++++++++++++ digital/beacon/tests/codewheel/debug_avr.c | 110 ++++++++ digital/beacon/tests/codewheel/debug_avr.h | 46 +++ digital/beacon/tests/codewheel/led.c | 135 +++++++++ digital/beacon/tests/codewheel/led.h | 54 ++++ digital/beacon/tests/codewheel/main_avr.c | 64 +++++ digital/beacon/tests/codewheel/network_specific.c | 47 +++ digital/beacon/tests/codewheel/network_specific.h | 42 +++ digital/beacon/tests/laser/Makefile | 44 +++ digital/beacon/tests/laser/atmega1281.ld | 97 +++++++ digital/beacon/tests/laser/configuration.h | 330 ++++++++++++++++++++++ digital/beacon/tests/laser/debug_avr.c | 104 +++++++ digital/beacon/tests/laser/debug_avr.h | 46 +++ digital/beacon/tests/laser/led.c | 135 +++++++++ digital/beacon/tests/laser/led.h | 54 ++++ digital/beacon/tests/laser/main_avr.c | 75 +++++ digital/beacon/tests/laser/network_specific.c | 47 +++ digital/beacon/tests/laser/network_specific.h | 42 +++ digital/beacon/tests/motor/Makefile | 44 +++ digital/beacon/tests/motor/atmega1281.ld | 97 +++++++ digital/beacon/tests/motor/configuration.h | 330 ++++++++++++++++++++++ digital/beacon/tests/motor/debug_avr.c | 118 ++++++++ digital/beacon/tests/motor/debug_avr.h | 46 +++ digital/beacon/tests/motor/led.c | 135 +++++++++ digital/beacon/tests/motor/led.h | 54 ++++ digital/beacon/tests/motor/main_avr.c | 89 ++++++ digital/beacon/tests/motor/motor.c | 139 +++++++++ digital/beacon/tests/motor/motor.h | 75 +++++ digital/beacon/tests/motor/network_specific.c | 47 +++ digital/beacon/tests/motor/network_specific.h | 42 +++ digital/beacon/tests/servo/Makefile | 44 +++ digital/beacon/tests/servo/atmega1281.ld | 97 +++++++ digital/beacon/tests/servo/configuration.h | 330 ++++++++++++++++++++++ digital/beacon/tests/servo/debug_avr.c | 120 ++++++++ digital/beacon/tests/servo/debug_avr.h | 46 +++ digital/beacon/tests/servo/led.c | 135 +++++++++ digital/beacon/tests/servo/led.h | 54 ++++ digital/beacon/tests/servo/main_avr.c | 105 +++++++ digital/beacon/tests/servo/network_specific.c | 47 +++ digital/beacon/tests/servo/network_specific.h | 42 +++ 54 files changed, 5399 insertions(+) create mode 100644 digital/beacon/tests/bouttons/Makefile create mode 100644 digital/beacon/tests/bouttons/atmega1281.ld create mode 100644 digital/beacon/tests/bouttons/configuration.h create mode 100644 digital/beacon/tests/bouttons/debug_avr.c create mode 100644 digital/beacon/tests/bouttons/debug_avr.h create mode 100644 digital/beacon/tests/bouttons/led.c create mode 100644 digital/beacon/tests/bouttons/led.h create mode 100644 digital/beacon/tests/bouttons/main_avr.c create mode 100644 digital/beacon/tests/bouttons/network_specific.c create mode 100644 digital/beacon/tests/bouttons/network_specific.h create mode 100644 digital/beacon/tests/codewheel/Makefile create mode 100644 digital/beacon/tests/codewheel/atmega1281.ld create mode 100644 digital/beacon/tests/codewheel/codewheel.c create mode 100644 digital/beacon/tests/codewheel/codewheel.h create mode 100644 digital/beacon/tests/codewheel/configuration.h create mode 100644 digital/beacon/tests/codewheel/debug_avr.c create mode 100644 digital/beacon/tests/codewheel/debug_avr.h create mode 100644 digital/beacon/tests/codewheel/led.c create mode 100644 digital/beacon/tests/codewheel/led.h create mode 100644 digital/beacon/tests/codewheel/main_avr.c create mode 100644 digital/beacon/tests/codewheel/network_specific.c create mode 100644 digital/beacon/tests/codewheel/network_specific.h create mode 100644 digital/beacon/tests/laser/Makefile create mode 100644 digital/beacon/tests/laser/atmega1281.ld create mode 100644 digital/beacon/tests/laser/configuration.h create mode 100644 digital/beacon/tests/laser/debug_avr.c create mode 100644 digital/beacon/tests/laser/debug_avr.h create mode 100644 digital/beacon/tests/laser/led.c create mode 100644 digital/beacon/tests/laser/led.h create mode 100644 digital/beacon/tests/laser/main_avr.c create mode 100644 digital/beacon/tests/laser/network_specific.c create mode 100644 digital/beacon/tests/laser/network_specific.h create mode 100644 digital/beacon/tests/motor/Makefile create mode 100644 digital/beacon/tests/motor/atmega1281.ld create mode 100644 digital/beacon/tests/motor/configuration.h create mode 100644 digital/beacon/tests/motor/debug_avr.c create mode 100644 digital/beacon/tests/motor/debug_avr.h create mode 100644 digital/beacon/tests/motor/led.c create mode 100644 digital/beacon/tests/motor/led.h create mode 100644 digital/beacon/tests/motor/main_avr.c create mode 100644 digital/beacon/tests/motor/motor.c create mode 100644 digital/beacon/tests/motor/motor.h create mode 100644 digital/beacon/tests/motor/network_specific.c create mode 100644 digital/beacon/tests/motor/network_specific.h create mode 100644 digital/beacon/tests/servo/Makefile create mode 100644 digital/beacon/tests/servo/atmega1281.ld create mode 100644 digital/beacon/tests/servo/configuration.h create mode 100644 digital/beacon/tests/servo/debug_avr.c create mode 100644 digital/beacon/tests/servo/debug_avr.h create mode 100644 digital/beacon/tests/servo/led.c create mode 100644 digital/beacon/tests/servo/led.h create mode 100644 digital/beacon/tests/servo/main_avr.c create mode 100644 digital/beacon/tests/servo/network_specific.c create mode 100644 digital/beacon/tests/servo/network_specific.h (limited to 'digital') diff --git a/digital/beacon/tests/bouttons/Makefile b/digital/beacon/tests/bouttons/Makefile new file mode 100644 index 00000000..fbbab810 --- /dev/null +++ b/digital/beacon/tests/bouttons/Makefile @@ -0,0 +1,44 @@ +ifndef APB_REPO_PATH +$(error Please set your environment variable APB_REPO_PATH with the path where is installed your APB repository) +endif + + +# Simulator makefile part +BASE = $(APB_REPO_PATH)/digital/avr +# HOST_PROGS = beacon +# beacon_SOURCES = main_simu.c position.c formula.c recovery.c update.c trust.c +# MODULES = math/fixed utils +# AVR_MCU = atmega1281 +# OPTIMIZE = -O2 -lm -DSIMULATOR +# include $(BASE)/make/Makefile.gen + + +# Bitcloud makefile part +BITCLOUD_BASE = $(APB_REPO_PATH)/digital/zigbit/bitcloud +BITCLOUD_MAKEFILE = $(BITCLOUD_BASE)/makefiles +BITCLOUD_STACK = $(BITCLOUD_BASE)/stack +BITCLOUD_COMMON_SOURCES = $(APB_REPO_PATH)/digital/zigbit/common +PROJECT_BASE = $(APB_REPO_PATH)/digital/beacon/tests/bouttons + +CONFIG_NAME = All_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = All_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc + +DEV2 := 0 + +avr: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean BITCLOUD_PATH=$(BITCLOUD_STACK) + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) all APP_NAME=test_bouttons BITCLOUD_PATH=$(BITCLOUD_STACK) APB_AVR_PATH=$(BASE) PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_COMMON_SOURCES=$(BITCLOUD_COMMON_SOURCES) + +flash: + make avr + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -u + avrdude -c stk500v2 -P /dev/ttyUSB1 -p atmega1281 -B3 -U flash:w:obj/test_bouttons.hex + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -s 1 + +clean: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean APP_NAME=test_bouttons PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_PATH=$(BITCLOUD_STACK);\ + diff --git a/digital/beacon/tests/bouttons/atmega1281.ld b/digital/beacon/tests/bouttons/atmega1281.ld new file mode 100644 index 00000000..056e2cad --- /dev/null +++ b/digital/beacon/tests/bouttons/atmega1281.ld @@ -0,0 +1,97 @@ +OUTPUT_FORMAT("elf32-avr") +OUTPUT_ARCH(avr:5) + +MEMORY +{ + text (rx) : ORIGIN = 0x00000000, LENGTH = 128K + data (rw!x) : ORIGIN = 0x00800200, LENGTH = 8K - 500 /* leave 500 bytes for stack */ + eeprom (rw!x) : ORIGIN = 0x00810000, LENGTH = 4K +} + +SECTIONS +{ + .text : + { + PROVIDE(__text_start = .); + + *(.vectors) + KEEP(*(.vectors)) + + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + + *(.trampolines*) + *(.jumptables*) + *(.lowtext*) + + *(.init0) + KEEP (*(.init0)) + *(.init1) + KEEP (*(.init1)) + *(.init2) + KEEP (*(.init2)) + *(.init3) + KEEP (*(.init3)) + *(.init4) + KEEP (*(.init4)) + *(.init5) + KEEP (*(.init5)) + *(.init6) + KEEP (*(.init6)) + *(.init7) + KEEP (*(.init7)) + *(.init8) + KEEP (*(.init8)) + + *(.text.main) + KEEP (*(.text.main)) + *(.text) + *(.text.*) + + PROVIDE(__text_end = .); + } > text + + .data : AT (ADDR(.text) + SIZEOF(.text)) + { + PROVIDE(__data_start = .); + *(.data*) + *(.rodata*) + *(.gnu.linkonce.d*) + . = ALIGN(2); + PROVIDE(__data_end = .); + } > data + + .bss __data_end : + { + PROVIDE(__bss_start = .); + *(.bss*) + *(COMMON) + PROVIDE(__bss_end = .); + } > data + + .noinit __bss_end : + { + *(.noinit*) + PROVIDE(__heap_start = .); + } > data + + __stack_start = .; + + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + + .eeprom : + { + FILL(0xff) + BYTE(0xff) + . = . + LENGTH(eeprom)-1; + } > eeprom + + /DISCARD/ : + { + *(.init9) + *(.fini*) + } + +} diff --git a/digital/beacon/tests/bouttons/configuration.h b/digital/beacon/tests/bouttons/configuration.h new file mode 100644 index 00000000..834750b0 --- /dev/null +++ b/digital/beacon/tests/bouttons/configuration.h @@ -0,0 +1,330 @@ +#ifndef _CONFIGURATION_H_ +#define _CONFIGURATION_H_ + +#include "apsCommon.h" +#include +#include + +/*----------------------------------------------- */ +/* Disables board-specific peripherals support */ +/*----------------------------------------------- */ +#define APP_DISABLE_BSP 1 + +#define AC_FREQ 8000000 + +/* ----------------------------------------------------------- */ +/* USART CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define APP_INTERFACE_USART 0x01 +#define APP_INTERFACE_VCP 0x02 +#define APP_INTERFACE_SPI 0x03 +#define APP_INTERFACE_UART 0x04 +#define APP_INTERFACE_USBFIFO 0x05 +#define APP_USART_RX_BUFFER_SIZE 100 /* Receive buffer size for USART. */ +#define APP_USART_TX_BUFFER_SIZE 500 /* Transmit buffer size for USART */ +#define APP_INTERFACE APP_INTERFACE_USART /* Defines primary serial interface type to be used by application */ +#define APP_USART_CHANNEL USART_CHANNEL_0 /* Defines USART interface name to be used by application.*/ + +/* ----------------------------------------------------------- */ +/* TWI CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AC_BEACON_TWI_ADDRESS 10 /* TWI address */ +#define AC_TWI_DRIVER HARD /* Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_NO_INTERRUPT 0 /* Do not use interrupts. */ +#define AC_TWI_FREQ 100000 /* TWI frequency, should really be 100 kHz. */ +#define AC_TWI_SLAVE_ENABLE 1 /* Enable slave part. */ +#define AC_TWI_MASTER_ENABLE 0 /* Enable master part. */ +#define AC_TWI_SLAVE_POLLED 1 /* Use polled slave mode: received data is stored in a buffer which can be polled using twi_slave_poll. */ +#undef AC_TWI_SLAVE_RECV /* Slave reception callback to be defined by the user when not in polled mode. */ +#define AC_TWI_PULL_UP 0 /* Use internal pull up. */ +#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 /* Slave reception buffer size. */ +#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 32 /* Slave transmission buffer size. */ + + +/* ----------------------------------------------------------- */ +/* ZIGBEE CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AT25F2048 0x01 +#define AT45DB041 0x02 +#define AT25DF041A 0x03 + + + +#define APP_FRAGMENTATION 0 /* Enables or disables APS Fragmentation support. */ +#define APP_DETECT_LINK_FAILURE 1 /* Enable or disable link failure detection */ +#define APP_ENDPOINT 1 /* Endpoint will be useed */ +#define APP_PROFILE_ID 1 /* Profile Id will be used */ +#define APP_CLUSTER_ID 1 /* Cluster Id will be used */ +#define APP_JOINING_INDICATION_PERIOD 500L /* Period of blinking during starting network */ + + + +// 32-bit mask of channels to be scanned before network is started. Channels that +// should be used are marked with logical 1 at corresponding bit location. +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// Notes: +// 1. for small amount of enabled channels it is more convinient to specify list +// of channels in the form of '(1ul << 0x0b)' +// 2. For 900 MHz band you also need to specify channel page +// +// Value range: 32-bit values: +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// C-type: uint32_t +// Can be set: at any time before network start +#define CS_CHANNEL_MASK (1L<<0x0f) + + +// The parameter specifies the predefined extended PANID of the network to be +// formed (for the coordinator) or joined (for a router or an end device). For a +// router or an end device the parameter can equal 0 allowing them to join the +// first suitable network that they discover. +#define CS_EXT_PANID 0xAAAAAAAAAAAA1337LL + +// The maximum number of direct children that a given device (the coordinator or a +// router) can have. +// +// The parameter is only enabled for routers and the coordinator. An end device +// can not have children. If an actual number of children reaches a parameter's +// value, the node will have not been able to accept any more children joining the +// network. The parameter can be set to 0 on a router thus preventing it from +// accepting any children and can be help form a desired network topology. For +// example, if the parameter is set to 0 on all routers, then the coordinator will +// be the only device that can have children and the network will have star +// topology. +#define CS_MAX_CHILDREN_AMOUNT 8 + +// The maximum number of routers among the direct children of the device +// +// The parameter determines how many routers the device can have as children. Note +// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT - +// CS_MAX_CHILDREN_ROUTER_AMOUNT. +#define CS_MAX_CHILDREN_ROUTER_AMOUNT 0 + +// Network depht limits amount of hops that packet may travel in the network. +// Actual maximum number of hops is network depth multiplied by 2. +// +// The parameter determines the maximum depth of a network tree formed by +// child-parent relationships between nodes. +// +// While joining the network the node receives beacon responses from potential +// parents containing their actual network depth and declines those which show +// values not less than the maximum network depth on the joining device. A +// potential parent will also reject a beacon from the joining device and will not +// sent a response if the joining device shows the network depth greater than it is +// allowed on the potential parent. This logic is enabled if the parameter value is +// not greater than 15. If its value is greater than 15, then device does not +// perform any checkings of the network depth, neither when joining a network nor +// when accepting other nodes as children. This allows forming long chains of +// devices across considerable distances. +#define CS_MAX_NETWORK_DEPTH 1 + +// Maximum amount of records in the Neighbor Table. +// +// The parameter determines the size of the neighbor table which is used to store +// beacon responses from nearby devices. The parameter puts an upper bound over the +// amount of child devices possible for the node. +#define CS_NEIB_TABLE_SIZE 10 + +// Maximum amount of records in the network Route Table. +// +// The parameter sets the maximum number of records that can be kept in the NWK +// route table. The table is used by NWK to store information about established +// routes. Each table entry specifies the next-hop short address for a route from +// the current node to a given destination node. The table is being filled +// automatically during route discovery. An entry is added when a route is +// discovered. +#define CS_ROUTE_TABLE_SIZE 8 + +// The parameter specifies the TX power of the transceiver device, is measured in +// dBm(s). After the node has entered the network the value can only be changed via +// the ZDO_SetTxPowerReq() function. +// +// Value range: depends on the hardware. Transmit power must be in the range from +// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit +// power must be in the range from -11 to 11 dBm. +#define CS_RF_TX_POWER 3 + +//----------------------------------------------- +//STANDARD_SECURITY_MODE +//----------------------------------------------- +#ifdef STANDARD_SECURITY_MODE + // The parameter is used to determine the security type. + // + // Value range: 0,3 - for standard security; 1,2 - for high security. + // 0 - network key is preconfigured ; + // 1 - network join without master key, but with a trust center link key, which + // must be set via APS_SetLinkKey(); + // 2 - network join employs a master key, which must be set APS_SetMasterKey(); + // 3 - network key is no preconfigured, but rather received from the trust center + // in an unencrypted frame. (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #error APP_MAX_PACKET_SIZE must be less or equal to (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #endif +#else + #if APP_APS_PAYLOAD_SIZE > APS_MAX_ASDU_SIZE + #error APP_APS_PAYLOAD_SIZE must be less or equal to APS_MAX_ASDU_SIZE + #endif +#endif + + +// Common application state definition +typedef enum +{ + APP_INITIAL_STATE, // Initial state + APP_NETWORK_JOIN_REQUEST, + APP_NETWORK_JOINING_STATE, // Attempting join the network + APP_NETWORK_JOINED_STATE, // Successfully joined + APP_NETWORK_LEAVING_STATE, // Leaving from the network + APP_ERROR_STATE // Error state (runtime error occured) +} AppState_t; + +// Network data transmission state +typedef enum +{ + APP_DATA_TRANSMISSION_SENDING_STATE, // APS Data Request was not sent yet + APP_DATA_TRANSMISSION_BUSY_STATE, // APS Data Request was sent (confirm waiting) + APP_DATA_TRANSMISSION_WAIT_STATE, // Waiting a data block from USART + APP_DATA_TRANSMISSION_READY_STATE, // Ready to send new APS Data Request + APP_DATA_TRANSMISSION_STOP_STATE // Inter-frame delay +} AppDataTransmissionState_t; + + +#endif // _CONFIGURATION_H_ diff --git a/digital/beacon/tests/bouttons/debug_avr.c b/digital/beacon/tests/bouttons/debug_avr.c new file mode 100644 index 00000000..65403e20 --- /dev/null +++ b/digital/beacon/tests/bouttons/debug_avr.c @@ -0,0 +1,104 @@ +/* debug_avr.c */ +/* Beacon debug interface. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "debug_avr.h" +#include "reset.h" + +HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) +static HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task + +uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer +uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer + +uint8_t debug_network = 0; +uint8_t debug_network_enable = 0; + +/* This function initializes the USART interface for debugging on avr */ + void initSerialInterface(void) + { + appUsartDescriptor.tty = USART_CHANNEL; + appUsartDescriptor.mode = USART_MODE_ASYNC; + appUsartDescriptor.baudrate = USART_BAUDRATE_38400; + appUsartDescriptor.dataLength = USART_DATA8; + appUsartDescriptor.parity = USART_PARITY_EVEN; + appUsartDescriptor.stopbits = USART_STOPBIT_1; + appUsartDescriptor.rxBuffer = usartRxBuffer; + appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); + appUsartDescriptor.txBuffer = NULL; // use callback mode + appUsartDescriptor.txBufferLength = 0; + appUsartDescriptor.rxCallback = usartRXCallback; + appUsartDescriptor.txCallback = usartTXCallback; + appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; + OPEN_USART(&appUsartDescriptor); + } + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead) +{ + uint8_t rxBuffer; + + /* Read RX buffer from HAL */ + READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); + + switch(rxBuffer) + { + case 'd': + debug_start_stop_task(); + break; + /* Default */ + default : + uprintf(" ?? Unknown command ??\r\n"); + break; + } +} + +/* This function starts the debug task */ +void debug_start_stop_task(void) +{ + static bool debug_task_running = 0; + if(debug_task_running == 0) + { + debugTimer.interval = DEBUG_TASK_PERIOD; + debugTimer.mode = TIMER_REPEAT_MODE; + debugTimer.callback = debug_task; + HAL_StartAppTimer(&debugTimer); + debug_task_running = 1; + } + else + { + HAL_StopAppTimer(&debugTimer); + debug_task_running = 0; + } +} + +/* Debug task callback */ +void debug_task(void) +{ + uprintf("------------------------- debug TASK -------------------------\r\n"); +} diff --git a/digital/beacon/tests/bouttons/debug_avr.h b/digital/beacon/tests/bouttons/debug_avr.h new file mode 100644 index 00000000..488d8b16 --- /dev/null +++ b/digital/beacon/tests/bouttons/debug_avr.h @@ -0,0 +1,46 @@ +/* debug_avr.h */ +/* Macro for debug traces for avr target. {{{ + * + * Copyright (C) 2011 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _DEBUG_AVR_H +#define _DEBUG_AVR_H + +#include +#include "configuration.h" + +#define DEBUG_TASK_PERIOD 500L + +/* This function initializes the USART interface for debugging on avr */ +void initSerialInterface(void); + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead); + +/* This function starts the debug task */ +void debug_start_stop_task(void); + +/* Debug task callback */ +void debug_task(void); + +#endif diff --git a/digital/beacon/tests/bouttons/led.c b/digital/beacon/tests/bouttons/led.c new file mode 100644 index 00000000..0f82ba78 --- /dev/null +++ b/digital/beacon/tests/bouttons/led.c @@ -0,0 +1,135 @@ +/* led.c */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include "led.h" + +static HAL_AppTimer_t delayTimer; + + +/* This function display a combination of led according the the given state */ +void led_display_state(int state) +{ + switch(state) + { + case APP_INITIAL_STATE: + case APP_NETWORK_JOINING_STATE: + led_on(1); + led_off(2); + break; + case APP_NETWORK_JOINED_STATE: + led_on(1); + led_on(2); + default: + break; + } +} + + +/* This function initializes the leds*/ +void init_led(void) +{ + /*D5/D6/D7 are configured in output */ + DDRD = 0xE0; +} + +/* This function activates a specific led */ +void led_on(int number) +{ + switch(number) + { + case 1: + PORTD|=0x20; + break; + case 2: + PORTD|=0x40; + break; + case 3: + PORTD|=0x80; + break; + default: + break; + } +} + +/* This function deactivates a specific led*/ +void led_off(int number) +{ + switch(number) + { + case 1: + PORTD&=0xDF; + break; + case 2: + PORTD&=0xBF; + break; + case 3: + PORTD&=0x7F; + break; + default: + break; + } +} + +/* This function inverse the state of a specific led*/ +void led_inverse(int number) +{ + switch(number) + { + case 1: + PORTD^=0x20; + break; + case 2: + PORTD^=0x40; + break; + case 3: + PORTD^=0x80; + break; + default: + break; + } +} + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void) +{ + delayTimer.interval = APP_JOINING_INDICATION_PERIOD; + delayTimer.mode = TIMER_REPEAT_MODE; + delayTimer.callback = led_network_status_blink_callback; + HAL_StartAppTimer(&delayTimer); +} + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void) +{ + HAL_StopAppTimer(&delayTimer); + led_on(1); +} + +/* Led blink callback*/ +void led_network_status_blink_callback(void) +{ + led_inverse(1); +} diff --git a/digital/beacon/tests/bouttons/led.h b/digital/beacon/tests/bouttons/led.h new file mode 100644 index 00000000..d49196fe --- /dev/null +++ b/digital/beacon/tests/bouttons/led.h @@ -0,0 +1,54 @@ +/* led.h */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#ifndef _LED_H +#define _LED_H + +#define APP_JOINING_INDICATION_PERIOD 500L // Period of blinking during starting network + +/* This function initializes the leds*/ +void init_led(void); + +/* This function activates a specific led */ +void led_on(int number); + +/* This function deactivates a specific led*/ +void led_off(int number); + +/* This function inverse the state of a specific led*/ +void led_inverse(int number); + +/* This function display a combination of led according the the given state */ +void led_display_state(int state); + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void); + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void); + +/* Led blink callback*/ +void led_network_status_blink_callback(void); + +#endif diff --git a/digital/beacon/tests/bouttons/main_avr.c b/digital/beacon/tests/bouttons/main_avr.c new file mode 100644 index 00000000..3af9702e --- /dev/null +++ b/digital/beacon/tests/bouttons/main_avr.c @@ -0,0 +1,94 @@ +/* main_avr.c */ +/* Beacon State Machine & Main. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "led.h" + +static HAL_AppTimer_t bouttonsTimer; // TIMER descripor used by the DEBUG task + +void bouttons_task(void) +{ + if(!(PIND&0x08)) + { + uprintf("boutton 1\r\n"); + PORTD |= (1< +#include +#include + +#include "configuration.h" +#include "network.h" +#include "network_specific.h" +#include "print.h" +AppMessageBuffer_t zigbit_tx_buffer; + +extern APS_RegisterEndpointReq_t endpointParams; +extern APS_DataReq_t network_config; + + + + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void) +{ + +} diff --git a/digital/beacon/tests/bouttons/network_specific.h b/digital/beacon/tests/bouttons/network_specific.h new file mode 100644 index 00000000..c0cb5d6a --- /dev/null +++ b/digital/beacon/tests/bouttons/network_specific.h @@ -0,0 +1,42 @@ +/* network.h */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _NETWORK_SPECIFIC_H +#define _NETWORK_SPECIFIC_H + +#include +#include "network.h" + +#define NETWORK_ACTIVITY_LED 2 +#define PACKET_NUMBER 200 + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void); + +/* This function sends a specified buffer */ +uint8_t network_send_buffer_transfert_rate(uint8_t * buffer_in,uint16_t size); + +#endif diff --git a/digital/beacon/tests/codewheel/Makefile b/digital/beacon/tests/codewheel/Makefile new file mode 100644 index 00000000..7961431e --- /dev/null +++ b/digital/beacon/tests/codewheel/Makefile @@ -0,0 +1,44 @@ +ifndef APB_REPO_PATH +$(error Please set your environment variable APB_REPO_PATH with the path where is installed your APB repository) +endif + + +# Simulator makefile part +BASE = $(APB_REPO_PATH)/digital/avr +# HOST_PROGS = beacon +# beacon_SOURCES = main_simu.c position.c formula.c recovery.c update.c trust.c +# MODULES = math/fixed utils +# AVR_MCU = atmega1281 +# OPTIMIZE = -O2 -lm -DSIMULATOR +# include $(BASE)/make/Makefile.gen + + +# Bitcloud makefile part +BITCLOUD_BASE = $(APB_REPO_PATH)/digital/zigbit/bitcloud +BITCLOUD_MAKEFILE = $(BITCLOUD_BASE)/makefiles +BITCLOUD_STACK = $(BITCLOUD_BASE)/stack +BITCLOUD_COMMON_SOURCES = $(APB_REPO_PATH)/digital/zigbit/common +PROJECT_BASE = $(APB_REPO_PATH)/digital/beacon/tests/codewheel + +CONFIG_NAME = All_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = All_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc + +DEV2 := 0 + +avr: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean BITCLOUD_PATH=$(BITCLOUD_STACK) + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) all APP_NAME=test_codewheel BITCLOUD_PATH=$(BITCLOUD_STACK) APB_AVR_PATH=$(BASE) PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_COMMON_SOURCES=$(BITCLOUD_COMMON_SOURCES) + +flash: + make avr + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -u + avrdude -c stk500v2 -P /dev/ttyUSB1 -p atmega1281 -B3 -U flash:w:obj/test_codewheel.hex + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -s 1 + +clean: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean APP_NAME=test_codewheel PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_PATH=$(BITCLOUD_STACK);\ + diff --git a/digital/beacon/tests/codewheel/atmega1281.ld b/digital/beacon/tests/codewheel/atmega1281.ld new file mode 100644 index 00000000..056e2cad --- /dev/null +++ b/digital/beacon/tests/codewheel/atmega1281.ld @@ -0,0 +1,97 @@ +OUTPUT_FORMAT("elf32-avr") +OUTPUT_ARCH(avr:5) + +MEMORY +{ + text (rx) : ORIGIN = 0x00000000, LENGTH = 128K + data (rw!x) : ORIGIN = 0x00800200, LENGTH = 8K - 500 /* leave 500 bytes for stack */ + eeprom (rw!x) : ORIGIN = 0x00810000, LENGTH = 4K +} + +SECTIONS +{ + .text : + { + PROVIDE(__text_start = .); + + *(.vectors) + KEEP(*(.vectors)) + + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + + *(.trampolines*) + *(.jumptables*) + *(.lowtext*) + + *(.init0) + KEEP (*(.init0)) + *(.init1) + KEEP (*(.init1)) + *(.init2) + KEEP (*(.init2)) + *(.init3) + KEEP (*(.init3)) + *(.init4) + KEEP (*(.init4)) + *(.init5) + KEEP (*(.init5)) + *(.init6) + KEEP (*(.init6)) + *(.init7) + KEEP (*(.init7)) + *(.init8) + KEEP (*(.init8)) + + *(.text.main) + KEEP (*(.text.main)) + *(.text) + *(.text.*) + + PROVIDE(__text_end = .); + } > text + + .data : AT (ADDR(.text) + SIZEOF(.text)) + { + PROVIDE(__data_start = .); + *(.data*) + *(.rodata*) + *(.gnu.linkonce.d*) + . = ALIGN(2); + PROVIDE(__data_end = .); + } > data + + .bss __data_end : + { + PROVIDE(__bss_start = .); + *(.bss*) + *(COMMON) + PROVIDE(__bss_end = .); + } > data + + .noinit __bss_end : + { + *(.noinit*) + PROVIDE(__heap_start = .); + } > data + + __stack_start = .; + + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + + .eeprom : + { + FILL(0xff) + BYTE(0xff) + . = . + LENGTH(eeprom)-1; + } > eeprom + + /DISCARD/ : + { + *(.init9) + *(.fini*) + } + +} diff --git a/digital/beacon/tests/codewheel/codewheel.c b/digital/beacon/tests/codewheel/codewheel.c new file mode 100644 index 00000000..874a16a7 --- /dev/null +++ b/digital/beacon/tests/codewheel/codewheel.c @@ -0,0 +1,146 @@ +/* codewheel.c */ +/* Codewheel sensors management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include +#include "print.h" +#include "codewheel.h" + +codewheel_s codewheel; +static HAL_AppTimer_t codewheelTimer; + +/* This function initializes the codewheel optical sensors and associated interrupt */ +void codewheel_init(void) +{ + /* Set codewheel state*/ + codewheel_set_state(CODEWHEEL_INIT); + + /* activated pull up on E6 */ + PORTE = 0x40; + + /* Select external clock on rising edge for timer 3 */ + TCCR3B |= (1< +#include + +/*----------------------------------------------- */ +/* Disables board-specific peripherals support */ +/*----------------------------------------------- */ +#define APP_DISABLE_BSP 1 + +#define AC_FREQ 8000000 + +/* ----------------------------------------------------------- */ +/* USART CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define APP_INTERFACE_USART 0x01 +#define APP_INTERFACE_VCP 0x02 +#define APP_INTERFACE_SPI 0x03 +#define APP_INTERFACE_UART 0x04 +#define APP_INTERFACE_USBFIFO 0x05 +#define APP_USART_RX_BUFFER_SIZE 100 /* Receive buffer size for USART. */ +#define APP_USART_TX_BUFFER_SIZE 500 /* Transmit buffer size for USART */ +#define APP_INTERFACE APP_INTERFACE_USART /* Defines primary serial interface type to be used by application */ +#define APP_USART_CHANNEL USART_CHANNEL_0 /* Defines USART interface name to be used by application.*/ + +/* ----------------------------------------------------------- */ +/* TWI CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AC_BEACON_TWI_ADDRESS 10 /* TWI address */ +#define AC_TWI_DRIVER HARD /* Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_NO_INTERRUPT 0 /* Do not use interrupts. */ +#define AC_TWI_FREQ 100000 /* TWI frequency, should really be 100 kHz. */ +#define AC_TWI_SLAVE_ENABLE 1 /* Enable slave part. */ +#define AC_TWI_MASTER_ENABLE 0 /* Enable master part. */ +#define AC_TWI_SLAVE_POLLED 1 /* Use polled slave mode: received data is stored in a buffer which can be polled using twi_slave_poll. */ +#undef AC_TWI_SLAVE_RECV /* Slave reception callback to be defined by the user when not in polled mode. */ +#define AC_TWI_PULL_UP 0 /* Use internal pull up. */ +#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 /* Slave reception buffer size. */ +#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 32 /* Slave transmission buffer size. */ + + +/* ----------------------------------------------------------- */ +/* ZIGBEE CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AT25F2048 0x01 +#define AT45DB041 0x02 +#define AT25DF041A 0x03 + + + +#define APP_FRAGMENTATION 0 /* Enables or disables APS Fragmentation support. */ +#define APP_DETECT_LINK_FAILURE 1 /* Enable or disable link failure detection */ +#define APP_ENDPOINT 1 /* Endpoint will be useed */ +#define APP_PROFILE_ID 1 /* Profile Id will be used */ +#define APP_CLUSTER_ID 1 /* Cluster Id will be used */ +#define APP_JOINING_INDICATION_PERIOD 500L /* Period of blinking during starting network */ + + + +// 32-bit mask of channels to be scanned before network is started. Channels that +// should be used are marked with logical 1 at corresponding bit location. +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// Notes: +// 1. for small amount of enabled channels it is more convinient to specify list +// of channels in the form of '(1ul << 0x0b)' +// 2. For 900 MHz band you also need to specify channel page +// +// Value range: 32-bit values: +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// C-type: uint32_t +// Can be set: at any time before network start +#define CS_CHANNEL_MASK (1L<<0x0f) + + +// The parameter specifies the predefined extended PANID of the network to be +// formed (for the coordinator) or joined (for a router or an end device). For a +// router or an end device the parameter can equal 0 allowing them to join the +// first suitable network that they discover. +#define CS_EXT_PANID 0xAAAAAAAAAAAA1337LL + +// The maximum number of direct children that a given device (the coordinator or a +// router) can have. +// +// The parameter is only enabled for routers and the coordinator. An end device +// can not have children. If an actual number of children reaches a parameter's +// value, the node will have not been able to accept any more children joining the +// network. The parameter can be set to 0 on a router thus preventing it from +// accepting any children and can be help form a desired network topology. For +// example, if the parameter is set to 0 on all routers, then the coordinator will +// be the only device that can have children and the network will have star +// topology. +#define CS_MAX_CHILDREN_AMOUNT 8 + +// The maximum number of routers among the direct children of the device +// +// The parameter determines how many routers the device can have as children. Note +// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT - +// CS_MAX_CHILDREN_ROUTER_AMOUNT. +#define CS_MAX_CHILDREN_ROUTER_AMOUNT 0 + +// Network depht limits amount of hops that packet may travel in the network. +// Actual maximum number of hops is network depth multiplied by 2. +// +// The parameter determines the maximum depth of a network tree formed by +// child-parent relationships between nodes. +// +// While joining the network the node receives beacon responses from potential +// parents containing their actual network depth and declines those which show +// values not less than the maximum network depth on the joining device. A +// potential parent will also reject a beacon from the joining device and will not +// sent a response if the joining device shows the network depth greater than it is +// allowed on the potential parent. This logic is enabled if the parameter value is +// not greater than 15. If its value is greater than 15, then device does not +// perform any checkings of the network depth, neither when joining a network nor +// when accepting other nodes as children. This allows forming long chains of +// devices across considerable distances. +#define CS_MAX_NETWORK_DEPTH 1 + +// Maximum amount of records in the Neighbor Table. +// +// The parameter determines the size of the neighbor table which is used to store +// beacon responses from nearby devices. The parameter puts an upper bound over the +// amount of child devices possible for the node. +#define CS_NEIB_TABLE_SIZE 10 + +// Maximum amount of records in the network Route Table. +// +// The parameter sets the maximum number of records that can be kept in the NWK +// route table. The table is used by NWK to store information about established +// routes. Each table entry specifies the next-hop short address for a route from +// the current node to a given destination node. The table is being filled +// automatically during route discovery. An entry is added when a route is +// discovered. +#define CS_ROUTE_TABLE_SIZE 8 + +// The parameter specifies the TX power of the transceiver device, is measured in +// dBm(s). After the node has entered the network the value can only be changed via +// the ZDO_SetTxPowerReq() function. +// +// Value range: depends on the hardware. Transmit power must be in the range from +// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit +// power must be in the range from -11 to 11 dBm. +#define CS_RF_TX_POWER 3 + +//----------------------------------------------- +//STANDARD_SECURITY_MODE +//----------------------------------------------- +#ifdef STANDARD_SECURITY_MODE + // The parameter is used to determine the security type. + // + // Value range: 0,3 - for standard security; 1,2 - for high security. + // 0 - network key is preconfigured ; + // 1 - network join without master key, but with a trust center link key, which + // must be set via APS_SetLinkKey(); + // 2 - network join employs a master key, which must be set APS_SetMasterKey(); + // 3 - network key is no preconfigured, but rather received from the trust center + // in an unencrypted frame. (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #error APP_MAX_PACKET_SIZE must be less or equal to (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #endif +#else + #if APP_APS_PAYLOAD_SIZE > APS_MAX_ASDU_SIZE + #error APP_APS_PAYLOAD_SIZE must be less or equal to APS_MAX_ASDU_SIZE + #endif +#endif + + +// Common application state definition +typedef enum +{ + APP_INITIAL_STATE, // Initial state + APP_NETWORK_JOIN_REQUEST, + APP_NETWORK_JOINING_STATE, // Attempting join the network + APP_NETWORK_JOINED_STATE, // Successfully joined + APP_NETWORK_LEAVING_STATE, // Leaving from the network + APP_ERROR_STATE // Error state (runtime error occured) +} AppState_t; + +// Network data transmission state +typedef enum +{ + APP_DATA_TRANSMISSION_SENDING_STATE, // APS Data Request was not sent yet + APP_DATA_TRANSMISSION_BUSY_STATE, // APS Data Request was sent (confirm waiting) + APP_DATA_TRANSMISSION_WAIT_STATE, // Waiting a data block from USART + APP_DATA_TRANSMISSION_READY_STATE, // Ready to send new APS Data Request + APP_DATA_TRANSMISSION_STOP_STATE // Inter-frame delay +} AppDataTransmissionState_t; + + +#endif // _CONFIGURATION_H_ diff --git a/digital/beacon/tests/codewheel/debug_avr.c b/digital/beacon/tests/codewheel/debug_avr.c new file mode 100644 index 00000000..75420019 --- /dev/null +++ b/digital/beacon/tests/codewheel/debug_avr.c @@ -0,0 +1,110 @@ +/* debug_avr.c */ +/* Beacon debug interface. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "debug_avr.h" +#include "codewheel.h" +#include "reset.h" + +HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) +static HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task + +uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer +uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer + +uint8_t debug_network = 0; +uint8_t debug_network_enable = 0; + +/* This function initializes the USART interface for debugging on avr */ + void initSerialInterface(void) + { + appUsartDescriptor.tty = USART_CHANNEL; + appUsartDescriptor.mode = USART_MODE_ASYNC; + appUsartDescriptor.baudrate = USART_BAUDRATE_38400; + appUsartDescriptor.dataLength = USART_DATA8; + appUsartDescriptor.parity = USART_PARITY_EVEN; + appUsartDescriptor.stopbits = USART_STOPBIT_1; + appUsartDescriptor.rxBuffer = usartRxBuffer; + appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); + appUsartDescriptor.txBuffer = NULL; // use callback mode + appUsartDescriptor.txBufferLength = 0; + appUsartDescriptor.rxCallback = usartRXCallback; + appUsartDescriptor.txCallback = usartTXCallback; + appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; + OPEN_USART(&appUsartDescriptor); + } + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead) +{ + uint8_t rxBuffer; + + /* Read RX buffer from HAL */ + READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); + + switch(rxBuffer) + { + case 'd': + debug_start_stop_task(); + break; + case 'z': + codewheel_reset(); + break; + /* Default */ + default : + uprintf(" ?? Unknown command ??\r\n"); + break; + } +} + +/* This function starts the debug task */ +void debug_start_stop_task(void) +{ + static bool debug_task_running = 0; + if(debug_task_running == 0) + { + debugTimer.interval = DEBUG_TASK_PERIOD; + debugTimer.mode = TIMER_REPEAT_MODE; + debugTimer.callback = debug_task; + HAL_StartAppTimer(&debugTimer); + debug_task_running = 1; + } + else + { + HAL_StopAppTimer(&debugTimer); + debug_task_running = 0; + } +} + +/* Debug task callback */ +void debug_task(void) +{ + uprintf("------------------------- debug TASK -------------------------\r\n"); + uprintf("## Codewheel\r\n"); + uprintf("State = %d - Raw = %d - Degree = %f\r\n",codewheel_get_state(),codewheel_get_value(),codewheel_convert_angle_raw2degrees(codewheel_get_value())); +} diff --git a/digital/beacon/tests/codewheel/debug_avr.h b/digital/beacon/tests/codewheel/debug_avr.h new file mode 100644 index 00000000..488d8b16 --- /dev/null +++ b/digital/beacon/tests/codewheel/debug_avr.h @@ -0,0 +1,46 @@ +/* debug_avr.h */ +/* Macro for debug traces for avr target. {{{ + * + * Copyright (C) 2011 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _DEBUG_AVR_H +#define _DEBUG_AVR_H + +#include +#include "configuration.h" + +#define DEBUG_TASK_PERIOD 500L + +/* This function initializes the USART interface for debugging on avr */ +void initSerialInterface(void); + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead); + +/* This function starts the debug task */ +void debug_start_stop_task(void); + +/* Debug task callback */ +void debug_task(void); + +#endif diff --git a/digital/beacon/tests/codewheel/led.c b/digital/beacon/tests/codewheel/led.c new file mode 100644 index 00000000..0f82ba78 --- /dev/null +++ b/digital/beacon/tests/codewheel/led.c @@ -0,0 +1,135 @@ +/* led.c */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include "led.h" + +static HAL_AppTimer_t delayTimer; + + +/* This function display a combination of led according the the given state */ +void led_display_state(int state) +{ + switch(state) + { + case APP_INITIAL_STATE: + case APP_NETWORK_JOINING_STATE: + led_on(1); + led_off(2); + break; + case APP_NETWORK_JOINED_STATE: + led_on(1); + led_on(2); + default: + break; + } +} + + +/* This function initializes the leds*/ +void init_led(void) +{ + /*D5/D6/D7 are configured in output */ + DDRD = 0xE0; +} + +/* This function activates a specific led */ +void led_on(int number) +{ + switch(number) + { + case 1: + PORTD|=0x20; + break; + case 2: + PORTD|=0x40; + break; + case 3: + PORTD|=0x80; + break; + default: + break; + } +} + +/* This function deactivates a specific led*/ +void led_off(int number) +{ + switch(number) + { + case 1: + PORTD&=0xDF; + break; + case 2: + PORTD&=0xBF; + break; + case 3: + PORTD&=0x7F; + break; + default: + break; + } +} + +/* This function inverse the state of a specific led*/ +void led_inverse(int number) +{ + switch(number) + { + case 1: + PORTD^=0x20; + break; + case 2: + PORTD^=0x40; + break; + case 3: + PORTD^=0x80; + break; + default: + break; + } +} + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void) +{ + delayTimer.interval = APP_JOINING_INDICATION_PERIOD; + delayTimer.mode = TIMER_REPEAT_MODE; + delayTimer.callback = led_network_status_blink_callback; + HAL_StartAppTimer(&delayTimer); +} + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void) +{ + HAL_StopAppTimer(&delayTimer); + led_on(1); +} + +/* Led blink callback*/ +void led_network_status_blink_callback(void) +{ + led_inverse(1); +} diff --git a/digital/beacon/tests/codewheel/led.h b/digital/beacon/tests/codewheel/led.h new file mode 100644 index 00000000..d49196fe --- /dev/null +++ b/digital/beacon/tests/codewheel/led.h @@ -0,0 +1,54 @@ +/* led.h */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#ifndef _LED_H +#define _LED_H + +#define APP_JOINING_INDICATION_PERIOD 500L // Period of blinking during starting network + +/* This function initializes the leds*/ +void init_led(void); + +/* This function activates a specific led */ +void led_on(int number); + +/* This function deactivates a specific led*/ +void led_off(int number); + +/* This function inverse the state of a specific led*/ +void led_inverse(int number); + +/* This function display a combination of led according the the given state */ +void led_display_state(int state); + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void); + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void); + +/* Led blink callback*/ +void led_network_status_blink_callback(void); + +#endif diff --git a/digital/beacon/tests/codewheel/main_avr.c b/digital/beacon/tests/codewheel/main_avr.c new file mode 100644 index 00000000..bf7bce4b --- /dev/null +++ b/digital/beacon/tests/codewheel/main_avr.c @@ -0,0 +1,64 @@ +/* main_avr.c */ +/* Beacon State Machine & Main. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include "configuration.h" +#include "codewheel.h" +#include "print.h" +#include "led.h" + + +void APL_TaskHandler(void) +{ + static int init_done = 0; + + if(init_done == 0) + { + /* Init Led */ + init_led(); + + /* Init Serial Interface for debug */ + initSerialInterface(); + + codewheel_init(); + + init_done = 1; + + uprintf("test_codewheel : init done\r\n"); + } + SYS_PostTask(APL_TASK_ID); +} + +int main(void) +{ + SYS_SysInit(); + for(;;) + { + SYS_RunTask(); + } +} + + diff --git a/digital/beacon/tests/codewheel/network_specific.c b/digital/beacon/tests/codewheel/network_specific.c new file mode 100644 index 00000000..2e46483e --- /dev/null +++ b/digital/beacon/tests/codewheel/network_specific.c @@ -0,0 +1,47 @@ +/* network.c */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include + +#include "configuration.h" +#include "network.h" +#include "network_specific.h" +#include "print.h" +AppMessageBuffer_t zigbit_tx_buffer; + +extern APS_RegisterEndpointReq_t endpointParams; +extern APS_DataReq_t network_config; + + + + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void) +{ + +} diff --git a/digital/beacon/tests/codewheel/network_specific.h b/digital/beacon/tests/codewheel/network_specific.h new file mode 100644 index 00000000..c0cb5d6a --- /dev/null +++ b/digital/beacon/tests/codewheel/network_specific.h @@ -0,0 +1,42 @@ +/* network.h */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _NETWORK_SPECIFIC_H +#define _NETWORK_SPECIFIC_H + +#include +#include "network.h" + +#define NETWORK_ACTIVITY_LED 2 +#define PACKET_NUMBER 200 + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void); + +/* This function sends a specified buffer */ +uint8_t network_send_buffer_transfert_rate(uint8_t * buffer_in,uint16_t size); + +#endif diff --git a/digital/beacon/tests/laser/Makefile b/digital/beacon/tests/laser/Makefile new file mode 100644 index 00000000..1df424b5 --- /dev/null +++ b/digital/beacon/tests/laser/Makefile @@ -0,0 +1,44 @@ +ifndef APB_REPO_PATH +$(error Please set your environment variable APB_REPO_PATH with the path where is installed your APB repository) +endif + + +# Simulator makefile part +BASE = $(APB_REPO_PATH)/digital/avr +# HOST_PROGS = beacon +# beacon_SOURCES = main_simu.c position.c formula.c recovery.c update.c trust.c +# MODULES = math/fixed utils +# AVR_MCU = atmega1281 +# OPTIMIZE = -O2 -lm -DSIMULATOR +# include $(BASE)/make/Makefile.gen + + +# Bitcloud makefile part +BITCLOUD_BASE = $(APB_REPO_PATH)/digital/zigbit/bitcloud +BITCLOUD_MAKEFILE = $(BITCLOUD_BASE)/makefiles +BITCLOUD_STACK = $(BITCLOUD_BASE)/stack +BITCLOUD_COMMON_SOURCES = $(APB_REPO_PATH)/digital/zigbit/common +PROJECT_BASE = $(APB_REPO_PATH)/digital/beacon/tests/laser + +CONFIG_NAME = All_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = All_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc + +DEV2 := 0 + +avr: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean BITCLOUD_PATH=$(BITCLOUD_STACK) + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) all APP_NAME=test_laser BITCLOUD_PATH=$(BITCLOUD_STACK) APB_AVR_PATH=$(BASE) PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_COMMON_SOURCES=$(BITCLOUD_COMMON_SOURCES) + +flash: + make avr + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -u + avrdude -c stk500v2 -P /dev/ttyUSB1 -p atmega1281 -B3 -U flash:w:obj/test_laser.hex + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -s 1 + +clean: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean APP_NAME=test_laser PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_PATH=$(BITCLOUD_STACK);\ + diff --git a/digital/beacon/tests/laser/atmega1281.ld b/digital/beacon/tests/laser/atmega1281.ld new file mode 100644 index 00000000..056e2cad --- /dev/null +++ b/digital/beacon/tests/laser/atmega1281.ld @@ -0,0 +1,97 @@ +OUTPUT_FORMAT("elf32-avr") +OUTPUT_ARCH(avr:5) + +MEMORY +{ + text (rx) : ORIGIN = 0x00000000, LENGTH = 128K + data (rw!x) : ORIGIN = 0x00800200, LENGTH = 8K - 500 /* leave 500 bytes for stack */ + eeprom (rw!x) : ORIGIN = 0x00810000, LENGTH = 4K +} + +SECTIONS +{ + .text : + { + PROVIDE(__text_start = .); + + *(.vectors) + KEEP(*(.vectors)) + + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + + *(.trampolines*) + *(.jumptables*) + *(.lowtext*) + + *(.init0) + KEEP (*(.init0)) + *(.init1) + KEEP (*(.init1)) + *(.init2) + KEEP (*(.init2)) + *(.init3) + KEEP (*(.init3)) + *(.init4) + KEEP (*(.init4)) + *(.init5) + KEEP (*(.init5)) + *(.init6) + KEEP (*(.init6)) + *(.init7) + KEEP (*(.init7)) + *(.init8) + KEEP (*(.init8)) + + *(.text.main) + KEEP (*(.text.main)) + *(.text) + *(.text.*) + + PROVIDE(__text_end = .); + } > text + + .data : AT (ADDR(.text) + SIZEOF(.text)) + { + PROVIDE(__data_start = .); + *(.data*) + *(.rodata*) + *(.gnu.linkonce.d*) + . = ALIGN(2); + PROVIDE(__data_end = .); + } > data + + .bss __data_end : + { + PROVIDE(__bss_start = .); + *(.bss*) + *(COMMON) + PROVIDE(__bss_end = .); + } > data + + .noinit __bss_end : + { + *(.noinit*) + PROVIDE(__heap_start = .); + } > data + + __stack_start = .; + + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + + .eeprom : + { + FILL(0xff) + BYTE(0xff) + . = . + LENGTH(eeprom)-1; + } > eeprom + + /DISCARD/ : + { + *(.init9) + *(.fini*) + } + +} diff --git a/digital/beacon/tests/laser/configuration.h b/digital/beacon/tests/laser/configuration.h new file mode 100644 index 00000000..834750b0 --- /dev/null +++ b/digital/beacon/tests/laser/configuration.h @@ -0,0 +1,330 @@ +#ifndef _CONFIGURATION_H_ +#define _CONFIGURATION_H_ + +#include "apsCommon.h" +#include +#include + +/*----------------------------------------------- */ +/* Disables board-specific peripherals support */ +/*----------------------------------------------- */ +#define APP_DISABLE_BSP 1 + +#define AC_FREQ 8000000 + +/* ----------------------------------------------------------- */ +/* USART CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define APP_INTERFACE_USART 0x01 +#define APP_INTERFACE_VCP 0x02 +#define APP_INTERFACE_SPI 0x03 +#define APP_INTERFACE_UART 0x04 +#define APP_INTERFACE_USBFIFO 0x05 +#define APP_USART_RX_BUFFER_SIZE 100 /* Receive buffer size for USART. */ +#define APP_USART_TX_BUFFER_SIZE 500 /* Transmit buffer size for USART */ +#define APP_INTERFACE APP_INTERFACE_USART /* Defines primary serial interface type to be used by application */ +#define APP_USART_CHANNEL USART_CHANNEL_0 /* Defines USART interface name to be used by application.*/ + +/* ----------------------------------------------------------- */ +/* TWI CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AC_BEACON_TWI_ADDRESS 10 /* TWI address */ +#define AC_TWI_DRIVER HARD /* Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_NO_INTERRUPT 0 /* Do not use interrupts. */ +#define AC_TWI_FREQ 100000 /* TWI frequency, should really be 100 kHz. */ +#define AC_TWI_SLAVE_ENABLE 1 /* Enable slave part. */ +#define AC_TWI_MASTER_ENABLE 0 /* Enable master part. */ +#define AC_TWI_SLAVE_POLLED 1 /* Use polled slave mode: received data is stored in a buffer which can be polled using twi_slave_poll. */ +#undef AC_TWI_SLAVE_RECV /* Slave reception callback to be defined by the user when not in polled mode. */ +#define AC_TWI_PULL_UP 0 /* Use internal pull up. */ +#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 /* Slave reception buffer size. */ +#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 32 /* Slave transmission buffer size. */ + + +/* ----------------------------------------------------------- */ +/* ZIGBEE CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AT25F2048 0x01 +#define AT45DB041 0x02 +#define AT25DF041A 0x03 + + + +#define APP_FRAGMENTATION 0 /* Enables or disables APS Fragmentation support. */ +#define APP_DETECT_LINK_FAILURE 1 /* Enable or disable link failure detection */ +#define APP_ENDPOINT 1 /* Endpoint will be useed */ +#define APP_PROFILE_ID 1 /* Profile Id will be used */ +#define APP_CLUSTER_ID 1 /* Cluster Id will be used */ +#define APP_JOINING_INDICATION_PERIOD 500L /* Period of blinking during starting network */ + + + +// 32-bit mask of channels to be scanned before network is started. Channels that +// should be used are marked with logical 1 at corresponding bit location. +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// Notes: +// 1. for small amount of enabled channels it is more convinient to specify list +// of channels in the form of '(1ul << 0x0b)' +// 2. For 900 MHz band you also need to specify channel page +// +// Value range: 32-bit values: +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// C-type: uint32_t +// Can be set: at any time before network start +#define CS_CHANNEL_MASK (1L<<0x0f) + + +// The parameter specifies the predefined extended PANID of the network to be +// formed (for the coordinator) or joined (for a router or an end device). For a +// router or an end device the parameter can equal 0 allowing them to join the +// first suitable network that they discover. +#define CS_EXT_PANID 0xAAAAAAAAAAAA1337LL + +// The maximum number of direct children that a given device (the coordinator or a +// router) can have. +// +// The parameter is only enabled for routers and the coordinator. An end device +// can not have children. If an actual number of children reaches a parameter's +// value, the node will have not been able to accept any more children joining the +// network. The parameter can be set to 0 on a router thus preventing it from +// accepting any children and can be help form a desired network topology. For +// example, if the parameter is set to 0 on all routers, then the coordinator will +// be the only device that can have children and the network will have star +// topology. +#define CS_MAX_CHILDREN_AMOUNT 8 + +// The maximum number of routers among the direct children of the device +// +// The parameter determines how many routers the device can have as children. Note +// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT - +// CS_MAX_CHILDREN_ROUTER_AMOUNT. +#define CS_MAX_CHILDREN_ROUTER_AMOUNT 0 + +// Network depht limits amount of hops that packet may travel in the network. +// Actual maximum number of hops is network depth multiplied by 2. +// +// The parameter determines the maximum depth of a network tree formed by +// child-parent relationships between nodes. +// +// While joining the network the node receives beacon responses from potential +// parents containing their actual network depth and declines those which show +// values not less than the maximum network depth on the joining device. A +// potential parent will also reject a beacon from the joining device and will not +// sent a response if the joining device shows the network depth greater than it is +// allowed on the potential parent. This logic is enabled if the parameter value is +// not greater than 15. If its value is greater than 15, then device does not +// perform any checkings of the network depth, neither when joining a network nor +// when accepting other nodes as children. This allows forming long chains of +// devices across considerable distances. +#define CS_MAX_NETWORK_DEPTH 1 + +// Maximum amount of records in the Neighbor Table. +// +// The parameter determines the size of the neighbor table which is used to store +// beacon responses from nearby devices. The parameter puts an upper bound over the +// amount of child devices possible for the node. +#define CS_NEIB_TABLE_SIZE 10 + +// Maximum amount of records in the network Route Table. +// +// The parameter sets the maximum number of records that can be kept in the NWK +// route table. The table is used by NWK to store information about established +// routes. Each table entry specifies the next-hop short address for a route from +// the current node to a given destination node. The table is being filled +// automatically during route discovery. An entry is added when a route is +// discovered. +#define CS_ROUTE_TABLE_SIZE 8 + +// The parameter specifies the TX power of the transceiver device, is measured in +// dBm(s). After the node has entered the network the value can only be changed via +// the ZDO_SetTxPowerReq() function. +// +// Value range: depends on the hardware. Transmit power must be in the range from +// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit +// power must be in the range from -11 to 11 dBm. +#define CS_RF_TX_POWER 3 + +//----------------------------------------------- +//STANDARD_SECURITY_MODE +//----------------------------------------------- +#ifdef STANDARD_SECURITY_MODE + // The parameter is used to determine the security type. + // + // Value range: 0,3 - for standard security; 1,2 - for high security. + // 0 - network key is preconfigured ; + // 1 - network join without master key, but with a trust center link key, which + // must be set via APS_SetLinkKey(); + // 2 - network join employs a master key, which must be set APS_SetMasterKey(); + // 3 - network key is no preconfigured, but rather received from the trust center + // in an unencrypted frame. (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #error APP_MAX_PACKET_SIZE must be less or equal to (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #endif +#else + #if APP_APS_PAYLOAD_SIZE > APS_MAX_ASDU_SIZE + #error APP_APS_PAYLOAD_SIZE must be less or equal to APS_MAX_ASDU_SIZE + #endif +#endif + + +// Common application state definition +typedef enum +{ + APP_INITIAL_STATE, // Initial state + APP_NETWORK_JOIN_REQUEST, + APP_NETWORK_JOINING_STATE, // Attempting join the network + APP_NETWORK_JOINED_STATE, // Successfully joined + APP_NETWORK_LEAVING_STATE, // Leaving from the network + APP_ERROR_STATE // Error state (runtime error occured) +} AppState_t; + +// Network data transmission state +typedef enum +{ + APP_DATA_TRANSMISSION_SENDING_STATE, // APS Data Request was not sent yet + APP_DATA_TRANSMISSION_BUSY_STATE, // APS Data Request was sent (confirm waiting) + APP_DATA_TRANSMISSION_WAIT_STATE, // Waiting a data block from USART + APP_DATA_TRANSMISSION_READY_STATE, // Ready to send new APS Data Request + APP_DATA_TRANSMISSION_STOP_STATE // Inter-frame delay +} AppDataTransmissionState_t; + + +#endif // _CONFIGURATION_H_ diff --git a/digital/beacon/tests/laser/debug_avr.c b/digital/beacon/tests/laser/debug_avr.c new file mode 100644 index 00000000..65403e20 --- /dev/null +++ b/digital/beacon/tests/laser/debug_avr.c @@ -0,0 +1,104 @@ +/* debug_avr.c */ +/* Beacon debug interface. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "debug_avr.h" +#include "reset.h" + +HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) +static HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task + +uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer +uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer + +uint8_t debug_network = 0; +uint8_t debug_network_enable = 0; + +/* This function initializes the USART interface for debugging on avr */ + void initSerialInterface(void) + { + appUsartDescriptor.tty = USART_CHANNEL; + appUsartDescriptor.mode = USART_MODE_ASYNC; + appUsartDescriptor.baudrate = USART_BAUDRATE_38400; + appUsartDescriptor.dataLength = USART_DATA8; + appUsartDescriptor.parity = USART_PARITY_EVEN; + appUsartDescriptor.stopbits = USART_STOPBIT_1; + appUsartDescriptor.rxBuffer = usartRxBuffer; + appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); + appUsartDescriptor.txBuffer = NULL; // use callback mode + appUsartDescriptor.txBufferLength = 0; + appUsartDescriptor.rxCallback = usartRXCallback; + appUsartDescriptor.txCallback = usartTXCallback; + appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; + OPEN_USART(&appUsartDescriptor); + } + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead) +{ + uint8_t rxBuffer; + + /* Read RX buffer from HAL */ + READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); + + switch(rxBuffer) + { + case 'd': + debug_start_stop_task(); + break; + /* Default */ + default : + uprintf(" ?? Unknown command ??\r\n"); + break; + } +} + +/* This function starts the debug task */ +void debug_start_stop_task(void) +{ + static bool debug_task_running = 0; + if(debug_task_running == 0) + { + debugTimer.interval = DEBUG_TASK_PERIOD; + debugTimer.mode = TIMER_REPEAT_MODE; + debugTimer.callback = debug_task; + HAL_StartAppTimer(&debugTimer); + debug_task_running = 1; + } + else + { + HAL_StopAppTimer(&debugTimer); + debug_task_running = 0; + } +} + +/* Debug task callback */ +void debug_task(void) +{ + uprintf("------------------------- debug TASK -------------------------\r\n"); +} diff --git a/digital/beacon/tests/laser/debug_avr.h b/digital/beacon/tests/laser/debug_avr.h new file mode 100644 index 00000000..488d8b16 --- /dev/null +++ b/digital/beacon/tests/laser/debug_avr.h @@ -0,0 +1,46 @@ +/* debug_avr.h */ +/* Macro for debug traces for avr target. {{{ + * + * Copyright (C) 2011 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _DEBUG_AVR_H +#define _DEBUG_AVR_H + +#include +#include "configuration.h" + +#define DEBUG_TASK_PERIOD 500L + +/* This function initializes the USART interface for debugging on avr */ +void initSerialInterface(void); + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead); + +/* This function starts the debug task */ +void debug_start_stop_task(void); + +/* Debug task callback */ +void debug_task(void); + +#endif diff --git a/digital/beacon/tests/laser/led.c b/digital/beacon/tests/laser/led.c new file mode 100644 index 00000000..0f82ba78 --- /dev/null +++ b/digital/beacon/tests/laser/led.c @@ -0,0 +1,135 @@ +/* led.c */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include "led.h" + +static HAL_AppTimer_t delayTimer; + + +/* This function display a combination of led according the the given state */ +void led_display_state(int state) +{ + switch(state) + { + case APP_INITIAL_STATE: + case APP_NETWORK_JOINING_STATE: + led_on(1); + led_off(2); + break; + case APP_NETWORK_JOINED_STATE: + led_on(1); + led_on(2); + default: + break; + } +} + + +/* This function initializes the leds*/ +void init_led(void) +{ + /*D5/D6/D7 are configured in output */ + DDRD = 0xE0; +} + +/* This function activates a specific led */ +void led_on(int number) +{ + switch(number) + { + case 1: + PORTD|=0x20; + break; + case 2: + PORTD|=0x40; + break; + case 3: + PORTD|=0x80; + break; + default: + break; + } +} + +/* This function deactivates a specific led*/ +void led_off(int number) +{ + switch(number) + { + case 1: + PORTD&=0xDF; + break; + case 2: + PORTD&=0xBF; + break; + case 3: + PORTD&=0x7F; + break; + default: + break; + } +} + +/* This function inverse the state of a specific led*/ +void led_inverse(int number) +{ + switch(number) + { + case 1: + PORTD^=0x20; + break; + case 2: + PORTD^=0x40; + break; + case 3: + PORTD^=0x80; + break; + default: + break; + } +} + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void) +{ + delayTimer.interval = APP_JOINING_INDICATION_PERIOD; + delayTimer.mode = TIMER_REPEAT_MODE; + delayTimer.callback = led_network_status_blink_callback; + HAL_StartAppTimer(&delayTimer); +} + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void) +{ + HAL_StopAppTimer(&delayTimer); + led_on(1); +} + +/* Led blink callback*/ +void led_network_status_blink_callback(void) +{ + led_inverse(1); +} diff --git a/digital/beacon/tests/laser/led.h b/digital/beacon/tests/laser/led.h new file mode 100644 index 00000000..d49196fe --- /dev/null +++ b/digital/beacon/tests/laser/led.h @@ -0,0 +1,54 @@ +/* led.h */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#ifndef _LED_H +#define _LED_H + +#define APP_JOINING_INDICATION_PERIOD 500L // Period of blinking during starting network + +/* This function initializes the leds*/ +void init_led(void); + +/* This function activates a specific led */ +void led_on(int number); + +/* This function deactivates a specific led*/ +void led_off(int number); + +/* This function inverse the state of a specific led*/ +void led_inverse(int number); + +/* This function display a combination of led according the the given state */ +void led_display_state(int state); + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void); + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void); + +/* Led blink callback*/ +void led_network_status_blink_callback(void); + +#endif diff --git a/digital/beacon/tests/laser/main_avr.c b/digital/beacon/tests/laser/main_avr.c new file mode 100644 index 00000000..e313fa60 --- /dev/null +++ b/digital/beacon/tests/laser/main_avr.c @@ -0,0 +1,75 @@ +/* main_avr.c */ +/* Beacon State Machine & Main. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "led.h" + +static HAL_AppTimer_t laserTimer; // TIMER descripor used by the DEBUG task + +void laser_task(void) +{ + uprintf("PINE = 0x%x\r\n",PINE); +} + +void APL_TaskHandler(void) +{ + static int init_done = 0; + if(init_done == 0) + { + /* Init Led */ + init_led(); + + /* Init Serial Interface for debug */ + initSerialInterface(); + + + DDRE = 0x00; + + + laserTimer.interval = 400L; + laserTimer.mode = TIMER_REPEAT_MODE; + laserTimer.callback = laser_task; + HAL_StartAppTimer(&laserTimer); + + init_done = 1; + uprintf("test_laser : init done\r\n"); + } + SYS_PostTask(APL_TASK_ID); +} + +int main(void) +{ + SYS_SysInit(); + for(;;) + { + SYS_RunTask(); + } +} + + diff --git a/digital/beacon/tests/laser/network_specific.c b/digital/beacon/tests/laser/network_specific.c new file mode 100644 index 00000000..2e46483e --- /dev/null +++ b/digital/beacon/tests/laser/network_specific.c @@ -0,0 +1,47 @@ +/* network.c */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include + +#include "configuration.h" +#include "network.h" +#include "network_specific.h" +#include "print.h" +AppMessageBuffer_t zigbit_tx_buffer; + +extern APS_RegisterEndpointReq_t endpointParams; +extern APS_DataReq_t network_config; + + + + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void) +{ + +} diff --git a/digital/beacon/tests/laser/network_specific.h b/digital/beacon/tests/laser/network_specific.h new file mode 100644 index 00000000..c0cb5d6a --- /dev/null +++ b/digital/beacon/tests/laser/network_specific.h @@ -0,0 +1,42 @@ +/* network.h */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _NETWORK_SPECIFIC_H +#define _NETWORK_SPECIFIC_H + +#include +#include "network.h" + +#define NETWORK_ACTIVITY_LED 2 +#define PACKET_NUMBER 200 + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void); + +/* This function sends a specified buffer */ +uint8_t network_send_buffer_transfert_rate(uint8_t * buffer_in,uint16_t size); + +#endif diff --git a/digital/beacon/tests/motor/Makefile b/digital/beacon/tests/motor/Makefile new file mode 100644 index 00000000..bcf8f808 --- /dev/null +++ b/digital/beacon/tests/motor/Makefile @@ -0,0 +1,44 @@ +ifndef APB_REPO_PATH +$(error Please set your environment variable APB_REPO_PATH with the path where is installed your APB repository) +endif + + +# Simulator makefile part +BASE = $(APB_REPO_PATH)/digital/avr +# HOST_PROGS = beacon +# beacon_SOURCES = main_simu.c position.c formula.c recovery.c update.c trust.c +# MODULES = math/fixed utils +# AVR_MCU = atmega1281 +# OPTIMIZE = -O2 -lm -DSIMULATOR +# include $(BASE)/make/Makefile.gen + + +# Bitcloud makefile part +BITCLOUD_BASE = $(APB_REPO_PATH)/digital/zigbit/bitcloud +BITCLOUD_MAKEFILE = $(BITCLOUD_BASE)/makefiles +BITCLOUD_STACK = $(BITCLOUD_BASE)/stack +BITCLOUD_COMMON_SOURCES = $(APB_REPO_PATH)/digital/zigbit/common +PROJECT_BASE = $(APB_REPO_PATH)/digital/beacon/tests/motor + +CONFIG_NAME = All_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = All_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc + +DEV2 := 0 + +avr: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean BITCLOUD_PATH=$(BITCLOUD_STACK) + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) all APP_NAME=test_motor BITCLOUD_PATH=$(BITCLOUD_STACK) APB_AVR_PATH=$(BASE) PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_COMMON_SOURCES=$(BITCLOUD_COMMON_SOURCES) + +flash: + make avr + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -u + avrdude -c stk500v2 -P /dev/ttyUSB1 -p atmega1281 -B3 -U flash:w:obj/test_motor.hex + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -s 1 + +clean: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean APP_NAME=test_motor PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_PATH=$(BITCLOUD_STACK);\ + diff --git a/digital/beacon/tests/motor/atmega1281.ld b/digital/beacon/tests/motor/atmega1281.ld new file mode 100644 index 00000000..056e2cad --- /dev/null +++ b/digital/beacon/tests/motor/atmega1281.ld @@ -0,0 +1,97 @@ +OUTPUT_FORMAT("elf32-avr") +OUTPUT_ARCH(avr:5) + +MEMORY +{ + text (rx) : ORIGIN = 0x00000000, LENGTH = 128K + data (rw!x) : ORIGIN = 0x00800200, LENGTH = 8K - 500 /* leave 500 bytes for stack */ + eeprom (rw!x) : ORIGIN = 0x00810000, LENGTH = 4K +} + +SECTIONS +{ + .text : + { + PROVIDE(__text_start = .); + + *(.vectors) + KEEP(*(.vectors)) + + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + + *(.trampolines*) + *(.jumptables*) + *(.lowtext*) + + *(.init0) + KEEP (*(.init0)) + *(.init1) + KEEP (*(.init1)) + *(.init2) + KEEP (*(.init2)) + *(.init3) + KEEP (*(.init3)) + *(.init4) + KEEP (*(.init4)) + *(.init5) + KEEP (*(.init5)) + *(.init6) + KEEP (*(.init6)) + *(.init7) + KEEP (*(.init7)) + *(.init8) + KEEP (*(.init8)) + + *(.text.main) + KEEP (*(.text.main)) + *(.text) + *(.text.*) + + PROVIDE(__text_end = .); + } > text + + .data : AT (ADDR(.text) + SIZEOF(.text)) + { + PROVIDE(__data_start = .); + *(.data*) + *(.rodata*) + *(.gnu.linkonce.d*) + . = ALIGN(2); + PROVIDE(__data_end = .); + } > data + + .bss __data_end : + { + PROVIDE(__bss_start = .); + *(.bss*) + *(COMMON) + PROVIDE(__bss_end = .); + } > data + + .noinit __bss_end : + { + *(.noinit*) + PROVIDE(__heap_start = .); + } > data + + __stack_start = .; + + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + + .eeprom : + { + FILL(0xff) + BYTE(0xff) + . = . + LENGTH(eeprom)-1; + } > eeprom + + /DISCARD/ : + { + *(.init9) + *(.fini*) + } + +} diff --git a/digital/beacon/tests/motor/configuration.h b/digital/beacon/tests/motor/configuration.h new file mode 100644 index 00000000..834750b0 --- /dev/null +++ b/digital/beacon/tests/motor/configuration.h @@ -0,0 +1,330 @@ +#ifndef _CONFIGURATION_H_ +#define _CONFIGURATION_H_ + +#include "apsCommon.h" +#include +#include + +/*----------------------------------------------- */ +/* Disables board-specific peripherals support */ +/*----------------------------------------------- */ +#define APP_DISABLE_BSP 1 + +#define AC_FREQ 8000000 + +/* ----------------------------------------------------------- */ +/* USART CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define APP_INTERFACE_USART 0x01 +#define APP_INTERFACE_VCP 0x02 +#define APP_INTERFACE_SPI 0x03 +#define APP_INTERFACE_UART 0x04 +#define APP_INTERFACE_USBFIFO 0x05 +#define APP_USART_RX_BUFFER_SIZE 100 /* Receive buffer size for USART. */ +#define APP_USART_TX_BUFFER_SIZE 500 /* Transmit buffer size for USART */ +#define APP_INTERFACE APP_INTERFACE_USART /* Defines primary serial interface type to be used by application */ +#define APP_USART_CHANNEL USART_CHANNEL_0 /* Defines USART interface name to be used by application.*/ + +/* ----------------------------------------------------------- */ +/* TWI CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AC_BEACON_TWI_ADDRESS 10 /* TWI address */ +#define AC_TWI_DRIVER HARD /* Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_NO_INTERRUPT 0 /* Do not use interrupts. */ +#define AC_TWI_FREQ 100000 /* TWI frequency, should really be 100 kHz. */ +#define AC_TWI_SLAVE_ENABLE 1 /* Enable slave part. */ +#define AC_TWI_MASTER_ENABLE 0 /* Enable master part. */ +#define AC_TWI_SLAVE_POLLED 1 /* Use polled slave mode: received data is stored in a buffer which can be polled using twi_slave_poll. */ +#undef AC_TWI_SLAVE_RECV /* Slave reception callback to be defined by the user when not in polled mode. */ +#define AC_TWI_PULL_UP 0 /* Use internal pull up. */ +#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 /* Slave reception buffer size. */ +#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 32 /* Slave transmission buffer size. */ + + +/* ----------------------------------------------------------- */ +/* ZIGBEE CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AT25F2048 0x01 +#define AT45DB041 0x02 +#define AT25DF041A 0x03 + + + +#define APP_FRAGMENTATION 0 /* Enables or disables APS Fragmentation support. */ +#define APP_DETECT_LINK_FAILURE 1 /* Enable or disable link failure detection */ +#define APP_ENDPOINT 1 /* Endpoint will be useed */ +#define APP_PROFILE_ID 1 /* Profile Id will be used */ +#define APP_CLUSTER_ID 1 /* Cluster Id will be used */ +#define APP_JOINING_INDICATION_PERIOD 500L /* Period of blinking during starting network */ + + + +// 32-bit mask of channels to be scanned before network is started. Channels that +// should be used are marked with logical 1 at corresponding bit location. +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// Notes: +// 1. for small amount of enabled channels it is more convinient to specify list +// of channels in the form of '(1ul << 0x0b)' +// 2. For 900 MHz band you also need to specify channel page +// +// Value range: 32-bit values: +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// C-type: uint32_t +// Can be set: at any time before network start +#define CS_CHANNEL_MASK (1L<<0x0f) + + +// The parameter specifies the predefined extended PANID of the network to be +// formed (for the coordinator) or joined (for a router or an end device). For a +// router or an end device the parameter can equal 0 allowing them to join the +// first suitable network that they discover. +#define CS_EXT_PANID 0xAAAAAAAAAAAA1337LL + +// The maximum number of direct children that a given device (the coordinator or a +// router) can have. +// +// The parameter is only enabled for routers and the coordinator. An end device +// can not have children. If an actual number of children reaches a parameter's +// value, the node will have not been able to accept any more children joining the +// network. The parameter can be set to 0 on a router thus preventing it from +// accepting any children and can be help form a desired network topology. For +// example, if the parameter is set to 0 on all routers, then the coordinator will +// be the only device that can have children and the network will have star +// topology. +#define CS_MAX_CHILDREN_AMOUNT 8 + +// The maximum number of routers among the direct children of the device +// +// The parameter determines how many routers the device can have as children. Note +// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT - +// CS_MAX_CHILDREN_ROUTER_AMOUNT. +#define CS_MAX_CHILDREN_ROUTER_AMOUNT 0 + +// Network depht limits amount of hops that packet may travel in the network. +// Actual maximum number of hops is network depth multiplied by 2. +// +// The parameter determines the maximum depth of a network tree formed by +// child-parent relationships between nodes. +// +// While joining the network the node receives beacon responses from potential +// parents containing their actual network depth and declines those which show +// values not less than the maximum network depth on the joining device. A +// potential parent will also reject a beacon from the joining device and will not +// sent a response if the joining device shows the network depth greater than it is +// allowed on the potential parent. This logic is enabled if the parameter value is +// not greater than 15. If its value is greater than 15, then device does not +// perform any checkings of the network depth, neither when joining a network nor +// when accepting other nodes as children. This allows forming long chains of +// devices across considerable distances. +#define CS_MAX_NETWORK_DEPTH 1 + +// Maximum amount of records in the Neighbor Table. +// +// The parameter determines the size of the neighbor table which is used to store +// beacon responses from nearby devices. The parameter puts an upper bound over the +// amount of child devices possible for the node. +#define CS_NEIB_TABLE_SIZE 10 + +// Maximum amount of records in the network Route Table. +// +// The parameter sets the maximum number of records that can be kept in the NWK +// route table. The table is used by NWK to store information about established +// routes. Each table entry specifies the next-hop short address for a route from +// the current node to a given destination node. The table is being filled +// automatically during route discovery. An entry is added when a route is +// discovered. +#define CS_ROUTE_TABLE_SIZE 8 + +// The parameter specifies the TX power of the transceiver device, is measured in +// dBm(s). After the node has entered the network the value can only be changed via +// the ZDO_SetTxPowerReq() function. +// +// Value range: depends on the hardware. Transmit power must be in the range from +// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit +// power must be in the range from -11 to 11 dBm. +#define CS_RF_TX_POWER 3 + +//----------------------------------------------- +//STANDARD_SECURITY_MODE +//----------------------------------------------- +#ifdef STANDARD_SECURITY_MODE + // The parameter is used to determine the security type. + // + // Value range: 0,3 - for standard security; 1,2 - for high security. + // 0 - network key is preconfigured ; + // 1 - network join without master key, but with a trust center link key, which + // must be set via APS_SetLinkKey(); + // 2 - network join employs a master key, which must be set APS_SetMasterKey(); + // 3 - network key is no preconfigured, but rather received from the trust center + // in an unencrypted frame. (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #error APP_MAX_PACKET_SIZE must be less or equal to (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #endif +#else + #if APP_APS_PAYLOAD_SIZE > APS_MAX_ASDU_SIZE + #error APP_APS_PAYLOAD_SIZE must be less or equal to APS_MAX_ASDU_SIZE + #endif +#endif + + +// Common application state definition +typedef enum +{ + APP_INITIAL_STATE, // Initial state + APP_NETWORK_JOIN_REQUEST, + APP_NETWORK_JOINING_STATE, // Attempting join the network + APP_NETWORK_JOINED_STATE, // Successfully joined + APP_NETWORK_LEAVING_STATE, // Leaving from the network + APP_ERROR_STATE // Error state (runtime error occured) +} AppState_t; + +// Network data transmission state +typedef enum +{ + APP_DATA_TRANSMISSION_SENDING_STATE, // APS Data Request was not sent yet + APP_DATA_TRANSMISSION_BUSY_STATE, // APS Data Request was sent (confirm waiting) + APP_DATA_TRANSMISSION_WAIT_STATE, // Waiting a data block from USART + APP_DATA_TRANSMISSION_READY_STATE, // Ready to send new APS Data Request + APP_DATA_TRANSMISSION_STOP_STATE // Inter-frame delay +} AppDataTransmissionState_t; + + +#endif // _CONFIGURATION_H_ diff --git a/digital/beacon/tests/motor/debug_avr.c b/digital/beacon/tests/motor/debug_avr.c new file mode 100644 index 00000000..6bd07d6b --- /dev/null +++ b/digital/beacon/tests/motor/debug_avr.c @@ -0,0 +1,118 @@ +/* debug_avr.c */ +/* Beacon debug interface. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "debug_avr.h" +#include "motor.h" +#include "reset.h" + +HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) +static HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task + +uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer +uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer + +uint8_t debug_network = 0; +uint8_t debug_network_enable = 0; + +/* This function initializes the USART interface for debugging on avr */ + void initSerialInterface(void) + { + appUsartDescriptor.tty = USART_CHANNEL; + appUsartDescriptor.mode = USART_MODE_ASYNC; + appUsartDescriptor.baudrate = USART_BAUDRATE_38400; + appUsartDescriptor.dataLength = USART_DATA8; + appUsartDescriptor.parity = USART_PARITY_EVEN; + appUsartDescriptor.stopbits = USART_STOPBIT_1; + appUsartDescriptor.rxBuffer = usartRxBuffer; + appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); + appUsartDescriptor.txBuffer = NULL; // use callback mode + appUsartDescriptor.txBufferLength = 0; + appUsartDescriptor.rxCallback = usartRXCallback; + appUsartDescriptor.txCallback = usartTXCallback; + appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; + OPEN_USART(&appUsartDescriptor); + } + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead) +{ + uint8_t rxBuffer; + + /* Read RX buffer from HAL */ + READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); + + switch(rxBuffer) + { + case 'd': + debug_start_stop_task(); + break; + case 't': + motor_start_stop_control(); + break; + case 'w': + motor_set_speed(motor_get_target_speed()+1); + uprintf("target speed = %d\r\n",motor_get_target_speed()); + break; + case 'x': + motor_set_speed(motor_get_target_speed()-1); + uprintf("target speed = %d\r\n",motor_get_target_speed()); + break; + /* Default */ + default : + uprintf(" ?? Unknown command ??\r\n"); + break; + } +} + +/* This function starts the debug task */ +void debug_start_stop_task(void) +{ + static bool debug_task_running = 0; + if(debug_task_running == 0) + { + debugTimer.interval = DEBUG_TASK_PERIOD; + debugTimer.mode = TIMER_REPEAT_MODE; + debugTimer.callback = debug_task; + HAL_StartAppTimer(&debugTimer); + debug_task_running = 1; + } + else + { + HAL_StopAppTimer(&debugTimer); + debug_task_running = 0; + } +} + +/* Debug task callback */ +void debug_task(void) +{ + uprintf("------------------------- debug TASK -------------------------\r\n"); + uprintf("## Motor\r\n"); + uprintf("State : %d ---- speed = %d\r\n",motor_get_state(),OCR0A); +} diff --git a/digital/beacon/tests/motor/debug_avr.h b/digital/beacon/tests/motor/debug_avr.h new file mode 100644 index 00000000..488d8b16 --- /dev/null +++ b/digital/beacon/tests/motor/debug_avr.h @@ -0,0 +1,46 @@ +/* debug_avr.h */ +/* Macro for debug traces for avr target. {{{ + * + * Copyright (C) 2011 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _DEBUG_AVR_H +#define _DEBUG_AVR_H + +#include +#include "configuration.h" + +#define DEBUG_TASK_PERIOD 500L + +/* This function initializes the USART interface for debugging on avr */ +void initSerialInterface(void); + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead); + +/* This function starts the debug task */ +void debug_start_stop_task(void); + +/* Debug task callback */ +void debug_task(void); + +#endif diff --git a/digital/beacon/tests/motor/led.c b/digital/beacon/tests/motor/led.c new file mode 100644 index 00000000..0f82ba78 --- /dev/null +++ b/digital/beacon/tests/motor/led.c @@ -0,0 +1,135 @@ +/* led.c */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include "led.h" + +static HAL_AppTimer_t delayTimer; + + +/* This function display a combination of led according the the given state */ +void led_display_state(int state) +{ + switch(state) + { + case APP_INITIAL_STATE: + case APP_NETWORK_JOINING_STATE: + led_on(1); + led_off(2); + break; + case APP_NETWORK_JOINED_STATE: + led_on(1); + led_on(2); + default: + break; + } +} + + +/* This function initializes the leds*/ +void init_led(void) +{ + /*D5/D6/D7 are configured in output */ + DDRD = 0xE0; +} + +/* This function activates a specific led */ +void led_on(int number) +{ + switch(number) + { + case 1: + PORTD|=0x20; + break; + case 2: + PORTD|=0x40; + break; + case 3: + PORTD|=0x80; + break; + default: + break; + } +} + +/* This function deactivates a specific led*/ +void led_off(int number) +{ + switch(number) + { + case 1: + PORTD&=0xDF; + break; + case 2: + PORTD&=0xBF; + break; + case 3: + PORTD&=0x7F; + break; + default: + break; + } +} + +/* This function inverse the state of a specific led*/ +void led_inverse(int number) +{ + switch(number) + { + case 1: + PORTD^=0x20; + break; + case 2: + PORTD^=0x40; + break; + case 3: + PORTD^=0x80; + break; + default: + break; + } +} + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void) +{ + delayTimer.interval = APP_JOINING_INDICATION_PERIOD; + delayTimer.mode = TIMER_REPEAT_MODE; + delayTimer.callback = led_network_status_blink_callback; + HAL_StartAppTimer(&delayTimer); +} + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void) +{ + HAL_StopAppTimer(&delayTimer); + led_on(1); +} + +/* Led blink callback*/ +void led_network_status_blink_callback(void) +{ + led_inverse(1); +} diff --git a/digital/beacon/tests/motor/led.h b/digital/beacon/tests/motor/led.h new file mode 100644 index 00000000..d49196fe --- /dev/null +++ b/digital/beacon/tests/motor/led.h @@ -0,0 +1,54 @@ +/* led.h */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#ifndef _LED_H +#define _LED_H + +#define APP_JOINING_INDICATION_PERIOD 500L // Period of blinking during starting network + +/* This function initializes the leds*/ +void init_led(void); + +/* This function activates a specific led */ +void led_on(int number); + +/* This function deactivates a specific led*/ +void led_off(int number); + +/* This function inverse the state of a specific led*/ +void led_inverse(int number); + +/* This function display a combination of led according the the given state */ +void led_display_state(int state); + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void); + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void); + +/* Led blink callback*/ +void led_network_status_blink_callback(void); + +#endif diff --git a/digital/beacon/tests/motor/main_avr.c b/digital/beacon/tests/motor/main_avr.c new file mode 100644 index 00000000..84a8f2f6 --- /dev/null +++ b/digital/beacon/tests/motor/main_avr.c @@ -0,0 +1,89 @@ +/* main_avr.c */ +/* Beacon State Machine & Main. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include +#include "configuration.h" +#include "motor.h" +#include "print.h" +#include "led.h" + +uint8_t motor_value = 0; +uint8_t motor_sense = 1; +static HAL_AppTimer_t motorTimer; // TIMER descripor used by the DEBUG task + + +void motor_task(void) +{ + if(motor_value == MOTOR_SPEED_MAX) + { + motor_sense = -1; + uprintf("up\r\n"); + } + else if(motor_value == MOTOR_SPEED_MIN) + { + uprintf("down\r\n"); + motor_sense = 1; + } + + motor_value = motor_value + motor_sense; + motor_set_speed(motor_value); +} + +void APL_TaskHandler(void) +{ + static int init_done = 0; + if(init_done == 0) + { + /* Init Led */ + init_led(); + + /* Init Serial Interface for debug */ + initSerialInterface(); + + motor_init(); + + init_done = 1; + + motorTimer.interval = 50L; + motorTimer.mode = TIMER_REPEAT_MODE; + motorTimer.callback = motor_task; + HAL_StartAppTimer(&motorTimer); + uprintf("test_motor : init done\r\n"); + } + SYS_PostTask(APL_TASK_ID); +} + +int main(void) +{ + SYS_SysInit(); + for(;;) + { + SYS_RunTask(); + } +} + + diff --git a/digital/beacon/tests/motor/motor.c b/digital/beacon/tests/motor/motor.c new file mode 100644 index 00000000..e8eae9f4 --- /dev/null +++ b/digital/beacon/tests/motor/motor.c @@ -0,0 +1,139 @@ +/* motor.c */ +/* Motor control. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include "print.h" +#include "motor.h" + +motor_s motor; + +/* This function initializes the motor control output */ +void motor_init(void) +{ + /* Select ouptut */ + DDRB |= (1<= MOTOR_SPEED_MAX) + OCR0A = MOTOR_SPEED_MAX; + else if(value <= MOTOR_SPEED_STOP) + OCR0A = MOTOR_SPEED_STOP; + else + OCR0A = value; +} + +/* This function returns the motor speed in raw format */ +uint8_t motor_get_speed_raw() +{ + return OCR0A; +} + +/* This function returns the motor state */ +TMotor_state motor_get_state(void) +{ + if(OCR0A > MOTOR_SPEED_MIN) + return MOTOR_IN_ROTATION; + else + return MOTOR_STOPPED; +} + +/* This function starts or stops the motor according to the current state */ +void motor_start_stop_control(void) +{ + if(motor_get_state() == MOTOR_IN_ROTATION) + { + motor_stop(); + } + else + { + motor_start(); + } +} + +/* This function sets the target speed */ +void motor_set_target_speed(uint8_t value) +{ + motor.target_speed = value; +} + +/* This function returns the target speed */ +uint8_t motor_get_target_speed() +{ + return motor.target_speed; +} + +/* This function control the motor speed accroding to target speed requested */ +void motor_control_speed(uint16_t time) +{ + int16_t diff = 0; + int16_t correction = 0; + + diff = motor_get_target_speed() - time; + + if(diff > 15) + correction = motor_get_speed_raw() - 5; + else if (diff < -15) + correction = motor_get_speed_raw() + 5; + else + correction = motor_get_speed_raw(); + + motor_set_speed(correction); + +} + +ISR(TIMER0_COMPA_vect) +{ +} \ No newline at end of file diff --git a/digital/beacon/tests/motor/motor.h b/digital/beacon/tests/motor/motor.h new file mode 100644 index 00000000..f1393d87 --- /dev/null +++ b/digital/beacon/tests/motor/motor.h @@ -0,0 +1,75 @@ +/* motor.h */ +/* Motor control. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _MOTOR_H +#define _MOTOR_H + +#define MOTOR_TARGET_SPEED_INIT 0 +#define MOTOR_SPEED_STOP 0 +#define MOTOR_SPEED_MIN 0 +#define MOTOR_SPEED_MAX 140 + +typedef struct +{ + uint16_t target_speed; +} motor_s; + +typedef enum +{ + MOTOR_STOPPED, + MOTOR_IN_ROTATION +} TMotor_state; + +/* This function initializes the motor control output */ +void motor_init(void); + +/* This function starts the motor rotation */ +void motor_start(void); + +/* This function stops the motor rotation */ +void motor_stop(void); + +/* This function sets the motor speed */ +void motor_set_speed(uint8_t value); + +/* This function returns the motor speed in raw format */ +uint8_t motor_get_speed_raw(); + +/* This function returns the motor state */ +TMotor_state motor_get_state(void); + +/* This function starts or stops the motor according to the current state */ +void motor_start_stop_control(void); + +/* This function sets the target speed */ +void motor_set_target_speed(uint8_t value); + +/* This function returns the target speed */ +uint8_t motor_get_target_speed(); + +/* This function control the motor speed accroding to target speed requested */ +void motor_control_speed(uint16_t time); + +#endif diff --git a/digital/beacon/tests/motor/network_specific.c b/digital/beacon/tests/motor/network_specific.c new file mode 100644 index 00000000..2e46483e --- /dev/null +++ b/digital/beacon/tests/motor/network_specific.c @@ -0,0 +1,47 @@ +/* network.c */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include + +#include "configuration.h" +#include "network.h" +#include "network_specific.h" +#include "print.h" +AppMessageBuffer_t zigbit_tx_buffer; + +extern APS_RegisterEndpointReq_t endpointParams; +extern APS_DataReq_t network_config; + + + + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void) +{ + +} diff --git a/digital/beacon/tests/motor/network_specific.h b/digital/beacon/tests/motor/network_specific.h new file mode 100644 index 00000000..c0cb5d6a --- /dev/null +++ b/digital/beacon/tests/motor/network_specific.h @@ -0,0 +1,42 @@ +/* network.h */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _NETWORK_SPECIFIC_H +#define _NETWORK_SPECIFIC_H + +#include +#include "network.h" + +#define NETWORK_ACTIVITY_LED 2 +#define PACKET_NUMBER 200 + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void); + +/* This function sends a specified buffer */ +uint8_t network_send_buffer_transfert_rate(uint8_t * buffer_in,uint16_t size); + +#endif diff --git a/digital/beacon/tests/servo/Makefile b/digital/beacon/tests/servo/Makefile new file mode 100644 index 00000000..8d05cad1 --- /dev/null +++ b/digital/beacon/tests/servo/Makefile @@ -0,0 +1,44 @@ +ifndef APB_REPO_PATH +$(error Please set your environment variable APB_REPO_PATH with the path where is installed your APB repository) +endif + + +# Simulator makefile part +BASE = $(APB_REPO_PATH)/digital/avr +# HOST_PROGS = beacon +# beacon_SOURCES = main_simu.c position.c formula.c recovery.c update.c trust.c +# MODULES = math/fixed utils +# AVR_MCU = atmega1281 +# OPTIMIZE = -O2 -lm -DSIMULATOR +# include $(BASE)/make/Makefile.gen + + +# Bitcloud makefile part +BITCLOUD_BASE = $(APB_REPO_PATH)/digital/zigbit/bitcloud +BITCLOUD_MAKEFILE = $(BITCLOUD_BASE)/makefiles +BITCLOUD_STACK = $(BITCLOUD_BASE)/stack +BITCLOUD_COMMON_SOURCES = $(APB_REPO_PATH)/digital/zigbit/common +PROJECT_BASE = $(APB_REPO_PATH)/digital/beacon/tests/servo + +CONFIG_NAME = All_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = All_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Coordinator_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc +#CONFIG_NAME = Router_Sec_ZigBit_Atmega1281_Rf230_8Mhz_Gcc + +DEV2 := 0 + +avr: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean BITCLOUD_PATH=$(BITCLOUD_STACK) + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) all APP_NAME=test_servo BITCLOUD_PATH=$(BITCLOUD_STACK) APB_AVR_PATH=$(BASE) PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_COMMON_SOURCES=$(BITCLOUD_COMMON_SOURCES) + +flash: + make avr + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -u + avrdude -c stk500v2 -P /dev/ttyUSB1 -p atmega1281 -B3 -U flash:w:obj/test_servo.hex + $(APB_REPO_PATH)/digital/dev2/tools/dev2ctl.py -s 1 + +clean: + $(MAKE) -C $(BITCLOUD_MAKEFILE) -f Makefile_$(CONFIG_NAME) clean APP_NAME=test_servo PROJECT_BASE=$(PROJECT_BASE) BITCLOUD_PATH=$(BITCLOUD_STACK);\ + diff --git a/digital/beacon/tests/servo/atmega1281.ld b/digital/beacon/tests/servo/atmega1281.ld new file mode 100644 index 00000000..056e2cad --- /dev/null +++ b/digital/beacon/tests/servo/atmega1281.ld @@ -0,0 +1,97 @@ +OUTPUT_FORMAT("elf32-avr") +OUTPUT_ARCH(avr:5) + +MEMORY +{ + text (rx) : ORIGIN = 0x00000000, LENGTH = 128K + data (rw!x) : ORIGIN = 0x00800200, LENGTH = 8K - 500 /* leave 500 bytes for stack */ + eeprom (rw!x) : ORIGIN = 0x00810000, LENGTH = 4K +} + +SECTIONS +{ + .text : + { + PROVIDE(__text_start = .); + + *(.vectors) + KEEP(*(.vectors)) + + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + + *(.trampolines*) + *(.jumptables*) + *(.lowtext*) + + *(.init0) + KEEP (*(.init0)) + *(.init1) + KEEP (*(.init1)) + *(.init2) + KEEP (*(.init2)) + *(.init3) + KEEP (*(.init3)) + *(.init4) + KEEP (*(.init4)) + *(.init5) + KEEP (*(.init5)) + *(.init6) + KEEP (*(.init6)) + *(.init7) + KEEP (*(.init7)) + *(.init8) + KEEP (*(.init8)) + + *(.text.main) + KEEP (*(.text.main)) + *(.text) + *(.text.*) + + PROVIDE(__text_end = .); + } > text + + .data : AT (ADDR(.text) + SIZEOF(.text)) + { + PROVIDE(__data_start = .); + *(.data*) + *(.rodata*) + *(.gnu.linkonce.d*) + . = ALIGN(2); + PROVIDE(__data_end = .); + } > data + + .bss __data_end : + { + PROVIDE(__bss_start = .); + *(.bss*) + *(COMMON) + PROVIDE(__bss_end = .); + } > data + + .noinit __bss_end : + { + *(.noinit*) + PROVIDE(__heap_start = .); + } > data + + __stack_start = .; + + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + + .eeprom : + { + FILL(0xff) + BYTE(0xff) + . = . + LENGTH(eeprom)-1; + } > eeprom + + /DISCARD/ : + { + *(.init9) + *(.fini*) + } + +} diff --git a/digital/beacon/tests/servo/configuration.h b/digital/beacon/tests/servo/configuration.h new file mode 100644 index 00000000..834750b0 --- /dev/null +++ b/digital/beacon/tests/servo/configuration.h @@ -0,0 +1,330 @@ +#ifndef _CONFIGURATION_H_ +#define _CONFIGURATION_H_ + +#include "apsCommon.h" +#include +#include + +/*----------------------------------------------- */ +/* Disables board-specific peripherals support */ +/*----------------------------------------------- */ +#define APP_DISABLE_BSP 1 + +#define AC_FREQ 8000000 + +/* ----------------------------------------------------------- */ +/* USART CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define APP_INTERFACE_USART 0x01 +#define APP_INTERFACE_VCP 0x02 +#define APP_INTERFACE_SPI 0x03 +#define APP_INTERFACE_UART 0x04 +#define APP_INTERFACE_USBFIFO 0x05 +#define APP_USART_RX_BUFFER_SIZE 100 /* Receive buffer size for USART. */ +#define APP_USART_TX_BUFFER_SIZE 500 /* Transmit buffer size for USART */ +#define APP_INTERFACE APP_INTERFACE_USART /* Defines primary serial interface type to be used by application */ +#define APP_USART_CHANNEL USART_CHANNEL_0 /* Defines USART interface name to be used by application.*/ + +/* ----------------------------------------------------------- */ +/* TWI CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AC_BEACON_TWI_ADDRESS 10 /* TWI address */ +#define AC_TWI_DRIVER HARD /* Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_NO_INTERRUPT 0 /* Do not use interrupts. */ +#define AC_TWI_FREQ 100000 /* TWI frequency, should really be 100 kHz. */ +#define AC_TWI_SLAVE_ENABLE 1 /* Enable slave part. */ +#define AC_TWI_MASTER_ENABLE 0 /* Enable master part. */ +#define AC_TWI_SLAVE_POLLED 1 /* Use polled slave mode: received data is stored in a buffer which can be polled using twi_slave_poll. */ +#undef AC_TWI_SLAVE_RECV /* Slave reception callback to be defined by the user when not in polled mode. */ +#define AC_TWI_PULL_UP 0 /* Use internal pull up. */ +#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 /* Slave reception buffer size. */ +#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 32 /* Slave transmission buffer size. */ + + +/* ----------------------------------------------------------- */ +/* ZIGBEE CONFIGURATION */ +/* ----------------------------------------------------------- */ +#define AT25F2048 0x01 +#define AT45DB041 0x02 +#define AT25DF041A 0x03 + + + +#define APP_FRAGMENTATION 0 /* Enables or disables APS Fragmentation support. */ +#define APP_DETECT_LINK_FAILURE 1 /* Enable or disable link failure detection */ +#define APP_ENDPOINT 1 /* Endpoint will be useed */ +#define APP_PROFILE_ID 1 /* Profile Id will be used */ +#define APP_CLUSTER_ID 1 /* Cluster Id will be used */ +#define APP_JOINING_INDICATION_PERIOD 500L /* Period of blinking during starting network */ + + + +// 32-bit mask of channels to be scanned before network is started. Channels that +// should be used are marked with logical 1 at corresponding bit location. +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// Notes: +// 1. for small amount of enabled channels it is more convinient to specify list +// of channels in the form of '(1ul << 0x0b)' +// 2. For 900 MHz band you also need to specify channel page +// +// Value range: 32-bit values: +// Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a +// Valid channel numbers for 900 MHz band are 0x00 - 0x0a +// +// C-type: uint32_t +// Can be set: at any time before network start +#define CS_CHANNEL_MASK (1L<<0x0f) + + +// The parameter specifies the predefined extended PANID of the network to be +// formed (for the coordinator) or joined (for a router or an end device). For a +// router or an end device the parameter can equal 0 allowing them to join the +// first suitable network that they discover. +#define CS_EXT_PANID 0xAAAAAAAAAAAA1337LL + +// The maximum number of direct children that a given device (the coordinator or a +// router) can have. +// +// The parameter is only enabled for routers and the coordinator. An end device +// can not have children. If an actual number of children reaches a parameter's +// value, the node will have not been able to accept any more children joining the +// network. The parameter can be set to 0 on a router thus preventing it from +// accepting any children and can be help form a desired network topology. For +// example, if the parameter is set to 0 on all routers, then the coordinator will +// be the only device that can have children and the network will have star +// topology. +#define CS_MAX_CHILDREN_AMOUNT 8 + +// The maximum number of routers among the direct children of the device +// +// The parameter determines how many routers the device can have as children. Note +// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT - +// CS_MAX_CHILDREN_ROUTER_AMOUNT. +#define CS_MAX_CHILDREN_ROUTER_AMOUNT 0 + +// Network depht limits amount of hops that packet may travel in the network. +// Actual maximum number of hops is network depth multiplied by 2. +// +// The parameter determines the maximum depth of a network tree formed by +// child-parent relationships between nodes. +// +// While joining the network the node receives beacon responses from potential +// parents containing their actual network depth and declines those which show +// values not less than the maximum network depth on the joining device. A +// potential parent will also reject a beacon from the joining device and will not +// sent a response if the joining device shows the network depth greater than it is +// allowed on the potential parent. This logic is enabled if the parameter value is +// not greater than 15. If its value is greater than 15, then device does not +// perform any checkings of the network depth, neither when joining a network nor +// when accepting other nodes as children. This allows forming long chains of +// devices across considerable distances. +#define CS_MAX_NETWORK_DEPTH 1 + +// Maximum amount of records in the Neighbor Table. +// +// The parameter determines the size of the neighbor table which is used to store +// beacon responses from nearby devices. The parameter puts an upper bound over the +// amount of child devices possible for the node. +#define CS_NEIB_TABLE_SIZE 10 + +// Maximum amount of records in the network Route Table. +// +// The parameter sets the maximum number of records that can be kept in the NWK +// route table. The table is used by NWK to store information about established +// routes. Each table entry specifies the next-hop short address for a route from +// the current node to a given destination node. The table is being filled +// automatically during route discovery. An entry is added when a route is +// discovered. +#define CS_ROUTE_TABLE_SIZE 8 + +// The parameter specifies the TX power of the transceiver device, is measured in +// dBm(s). After the node has entered the network the value can only be changed via +// the ZDO_SetTxPowerReq() function. +// +// Value range: depends on the hardware. Transmit power must be in the range from +// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit +// power must be in the range from -11 to 11 dBm. +#define CS_RF_TX_POWER 3 + +//----------------------------------------------- +//STANDARD_SECURITY_MODE +//----------------------------------------------- +#ifdef STANDARD_SECURITY_MODE + // The parameter is used to determine the security type. + // + // Value range: 0,3 - for standard security; 1,2 - for high security. + // 0 - network key is preconfigured ; + // 1 - network join without master key, but with a trust center link key, which + // must be set via APS_SetLinkKey(); + // 2 - network join employs a master key, which must be set APS_SetMasterKey(); + // 3 - network key is no preconfigured, but rather received from the trust center + // in an unencrypted frame. (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #error APP_MAX_PACKET_SIZE must be less or equal to (CS_APS_MAX_BLOCKS_AMOUNT * APS_MAX_ASDU_SIZE) + #endif +#else + #if APP_APS_PAYLOAD_SIZE > APS_MAX_ASDU_SIZE + #error APP_APS_PAYLOAD_SIZE must be less or equal to APS_MAX_ASDU_SIZE + #endif +#endif + + +// Common application state definition +typedef enum +{ + APP_INITIAL_STATE, // Initial state + APP_NETWORK_JOIN_REQUEST, + APP_NETWORK_JOINING_STATE, // Attempting join the network + APP_NETWORK_JOINED_STATE, // Successfully joined + APP_NETWORK_LEAVING_STATE, // Leaving from the network + APP_ERROR_STATE // Error state (runtime error occured) +} AppState_t; + +// Network data transmission state +typedef enum +{ + APP_DATA_TRANSMISSION_SENDING_STATE, // APS Data Request was not sent yet + APP_DATA_TRANSMISSION_BUSY_STATE, // APS Data Request was sent (confirm waiting) + APP_DATA_TRANSMISSION_WAIT_STATE, // Waiting a data block from USART + APP_DATA_TRANSMISSION_READY_STATE, // Ready to send new APS Data Request + APP_DATA_TRANSMISSION_STOP_STATE // Inter-frame delay +} AppDataTransmissionState_t; + + +#endif // _CONFIGURATION_H_ diff --git a/digital/beacon/tests/servo/debug_avr.c b/digital/beacon/tests/servo/debug_avr.c new file mode 100644 index 00000000..11a857ea --- /dev/null +++ b/digital/beacon/tests/servo/debug_avr.c @@ -0,0 +1,120 @@ +/* debug_avr.c */ +/* Beacon debug interface. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "debug_avr.h" +#include "reset.h" + +HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) +static HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task + +uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer +uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer + +uint8_t debug_network = 0; +uint8_t debug_network_enable = 0; + +/* This function initializes the USART interface for debugging on avr */ + void initSerialInterface(void) + { + appUsartDescriptor.tty = USART_CHANNEL; + appUsartDescriptor.mode = USART_MODE_ASYNC; + appUsartDescriptor.baudrate = USART_BAUDRATE_38400; + appUsartDescriptor.dataLength = USART_DATA8; + appUsartDescriptor.parity = USART_PARITY_EVEN; + appUsartDescriptor.stopbits = USART_STOPBIT_1; + appUsartDescriptor.rxBuffer = usartRxBuffer; + appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); + appUsartDescriptor.txBuffer = NULL; // use callback mode + appUsartDescriptor.txBufferLength = 0; + appUsartDescriptor.rxCallback = usartRXCallback; + appUsartDescriptor.txCallback = usartTXCallback; + appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; + OPEN_USART(&appUsartDescriptor); + } + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead) +{ + uint8_t rxBuffer; + + /* Read RX buffer from HAL */ + READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); + + switch(rxBuffer) + { + case 'd': + debug_start_stop_task(); + break; + case 'o': + /* Increase servo 1 angle */ + uprintf("SERVO_1 = %d\r\n",OCR1A++); + break; + case 'l': + /* Decrease servo 1 angle */ + uprintf("SERVO_1 = %d\r\n",OCR1A--); + break; + case 'p': + /* Increase servo 2 angle */ + uprintf("SERVO_2 = %d\r\n",OCR1B++); + break; + case 'm': + /* Decrease servo 2 angle */ + uprintf("SERVO_2 = %d\r\n",OCR1B--); + break; + /* Default */ + default : + uprintf(" ?? Unknown command ??\r\n"); + break; + } +} + +/* This function starts the debug task */ +void debug_start_stop_task(void) +{ + static bool debug_task_running = 0; + if(debug_task_running == 0) + { + debugTimer.interval = DEBUG_TASK_PERIOD; + debugTimer.mode = TIMER_REPEAT_MODE; + debugTimer.callback = debug_task; + HAL_StartAppTimer(&debugTimer); + debug_task_running = 1; + } + else + { + HAL_StopAppTimer(&debugTimer); + debug_task_running = 0; + } +} + +/* Debug task callback */ +void debug_task(void) +{ + uprintf("------------------------- debug TASK -------------------------\r\n"); +} diff --git a/digital/beacon/tests/servo/debug_avr.h b/digital/beacon/tests/servo/debug_avr.h new file mode 100644 index 00000000..488d8b16 --- /dev/null +++ b/digital/beacon/tests/servo/debug_avr.h @@ -0,0 +1,46 @@ +/* debug_avr.h */ +/* Macro for debug traces for avr target. {{{ + * + * Copyright (C) 2011 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _DEBUG_AVR_H +#define _DEBUG_AVR_H + +#include +#include "configuration.h" + +#define DEBUG_TASK_PERIOD 500L + +/* This function initializes the USART interface for debugging on avr */ +void initSerialInterface(void); + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead); + +/* This function starts the debug task */ +void debug_start_stop_task(void); + +/* Debug task callback */ +void debug_task(void); + +#endif diff --git a/digital/beacon/tests/servo/led.c b/digital/beacon/tests/servo/led.c new file mode 100644 index 00000000..0f82ba78 --- /dev/null +++ b/digital/beacon/tests/servo/led.c @@ -0,0 +1,135 @@ +/* led.c */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include "led.h" + +static HAL_AppTimer_t delayTimer; + + +/* This function display a combination of led according the the given state */ +void led_display_state(int state) +{ + switch(state) + { + case APP_INITIAL_STATE: + case APP_NETWORK_JOINING_STATE: + led_on(1); + led_off(2); + break; + case APP_NETWORK_JOINED_STATE: + led_on(1); + led_on(2); + default: + break; + } +} + + +/* This function initializes the leds*/ +void init_led(void) +{ + /*D5/D6/D7 are configured in output */ + DDRD = 0xE0; +} + +/* This function activates a specific led */ +void led_on(int number) +{ + switch(number) + { + case 1: + PORTD|=0x20; + break; + case 2: + PORTD|=0x40; + break; + case 3: + PORTD|=0x80; + break; + default: + break; + } +} + +/* This function deactivates a specific led*/ +void led_off(int number) +{ + switch(number) + { + case 1: + PORTD&=0xDF; + break; + case 2: + PORTD&=0xBF; + break; + case 3: + PORTD&=0x7F; + break; + default: + break; + } +} + +/* This function inverse the state of a specific led*/ +void led_inverse(int number) +{ + switch(number) + { + case 1: + PORTD^=0x20; + break; + case 2: + PORTD^=0x40; + break; + case 3: + PORTD^=0x80; + break; + default: + break; + } +} + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void) +{ + delayTimer.interval = APP_JOINING_INDICATION_PERIOD; + delayTimer.mode = TIMER_REPEAT_MODE; + delayTimer.callback = led_network_status_blink_callback; + HAL_StartAppTimer(&delayTimer); +} + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void) +{ + HAL_StopAppTimer(&delayTimer); + led_on(1); +} + +/* Led blink callback*/ +void led_network_status_blink_callback(void) +{ + led_inverse(1); +} diff --git a/digital/beacon/tests/servo/led.h b/digital/beacon/tests/servo/led.h new file mode 100644 index 00000000..d49196fe --- /dev/null +++ b/digital/beacon/tests/servo/led.h @@ -0,0 +1,54 @@ +/* led.h */ +/* Led management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#ifndef _LED_H +#define _LED_H + +#define APP_JOINING_INDICATION_PERIOD 500L // Period of blinking during starting network + +/* This function initializes the leds*/ +void init_led(void); + +/* This function activates a specific led */ +void led_on(int number); + +/* This function deactivates a specific led*/ +void led_off(int number); + +/* This function inverse the state of a specific led*/ +void led_inverse(int number); + +/* This function display a combination of led according the the given state */ +void led_display_state(int state); + +/* This function enables the timer used by the network blink status led */ +void led_start_blink(void); + +/* This function disables the timer used by the network blink status led */ +void led_stop_blink(void); + +/* Led blink callback*/ +void led_network_status_blink_callback(void); + +#endif diff --git a/digital/beacon/tests/servo/main_avr.c b/digital/beacon/tests/servo/main_avr.c new file mode 100644 index 00000000..722b1434 --- /dev/null +++ b/digital/beacon/tests/servo/main_avr.c @@ -0,0 +1,105 @@ +/* main_avr.c */ +/* Beacon State Machine & Main. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#include +#include +#include +#include "configuration.h" +#include "print.h" +#include "led.h" + +uint8_t sense = 1; + +static HAL_AppTimer_t testTimer; + +void test_task(void) +{ + +} + +void APL_TaskHandler(void) +{ + static int init_done = 0; + if(init_done == 0) + { + /* Init Led */ + init_led(); + + /* Init Serial Interface for debug */ + initSerialInterface(); + + //Fpwm = f_IO / (prescaler * (1 + TOP)) = 7200 Hz. */ + OCR1B = 150; + OCR1A = 150; + + + /* Fast PWM 10bits with TOP=0x03FF */ + TCCR1A |= (1< +#include +#include + +#include "configuration.h" +#include "network.h" +#include "network_specific.h" +#include "print.h" +AppMessageBuffer_t zigbit_tx_buffer; + +extern APS_RegisterEndpointReq_t endpointParams; +extern APS_DataReq_t network_config; + + + + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void) +{ + +} diff --git a/digital/beacon/tests/servo/network_specific.h b/digital/beacon/tests/servo/network_specific.h new file mode 100644 index 00000000..c0cb5d6a --- /dev/null +++ b/digital/beacon/tests/servo/network_specific.h @@ -0,0 +1,42 @@ +/* network.h */ +/* Beacon network management. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _NETWORK_SPECIFIC_H +#define _NETWORK_SPECIFIC_H + +#include +#include "network.h" + +#define NETWORK_ACTIVITY_LED 2 +#define PACKET_NUMBER 200 + + +/* Specific callback after data packet sent */ +void network_specific_DataConfcallback(void); + +/* This function sends a specified buffer */ +uint8_t network_send_buffer_transfert_rate(uint8_t * buffer_in,uint16_t size); + +#endif -- cgit v1.2.3