started phase clock

started a phase clock code to send compressed acceleration data
and send it to the clock running somewhere else
fertito
Daniel Poelzleithner 13 years ago
parent 326a0636f3
commit 8533816ade

@ -138,4 +138,7 @@ extern volatile s_message_flags message;
// Global Variable section
// include firmware image
#include "../config.h"
#endif /*PROJECT_H_*/

@ -63,6 +63,10 @@
#include "acceleration.h"
#include "rfbsl.h"
#ifdef CONFIG_PHASE_CLOCK
#include "phase_clock.h"
#endif
// *************************************************************************************************
// Defines section
@ -215,8 +219,22 @@ const struct menu menu_L2_Battery =
FUNCTION(dummy), // sub menu function
FUNCTION(display_battery_V), // display function
FUNCTION(update_battery_voltage), // new display data
#ifndef CONFIG_PHASE_CLOCK
&menu_L2_Rf,
};
#else
&menu_L2_Phase,
};
// Line2 - ACC (acceleration data + button events via SimpliciTI)
const struct menu menu_L2_Phase =
{
FUNCTION(sx_phase), // direct function
FUNCTION(dummy), // sub menu function
FUNCTION(display_phase_clock), // display function
FUNCTION(update_time), // new display data
&menu_L2_Rf,
};
#endif
// Line2 - ACC (acceleration data + button events via SimpliciTI)
const struct menu menu_L2_Rf =
{

@ -84,6 +84,9 @@ extern const struct menu menu_L2_Date;
extern const struct menu menu_L2_Stopwatch;
extern const struct menu menu_L2_Battery;
extern const struct menu menu_L2_Rf;
#ifdef CONFIG_PHASE_CLOCK
extern const struct menu menu_L2_Phase;
#endif
extern const struct menu menu_L2_Ppt;
extern const struct menu menu_L2_Sync;
extern const struct menu menu_L2_CalDist;

@ -0,0 +1,295 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
// Copyright (C) 2010 Daniel Poelzleithner
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
// SimpliciTI functions.
// *************************************************************************************************
// *************************************************************************************************
// Include section
// system
#include "project.h"
#ifdef CONFIG_PHASE_CLOCK
// driver
#include <string.h>
#include "display.h"
#include "vti_as.h"
#include "ports.h"
#include "timer.h"
#include "radio.h"
// logic
#include "acceleration.h"
#include "rfsimpliciti.h"
//#include "bluerobin.h"
#include "simpliciti.h"
#include "phase_clock.h"
#include "date.h"
#include "alarm.h"
#include "temperature.h"
#include "vti_ps.h"
#include "altitude.h"
// *************************************************************************************************
// Prototypes section
void simpliciti_get_data_callback(void);
void start_simpliciti_sleep();
void start_simpliciti_sync(void);
// *************************************************************************************************
// Defines section
#define TEST
// Each packet index requires 2 bytes, so we can have 9 packet indizes in 18 bytes usable payload
#define BM_SYNC_BURST_PACKETS_IN_DATA (9u)
// *************************************************************************************************
// Global Variable section
struct SPhase sPhase;
// flag contains status information, trigger to send data and trigger to exit SimpliciTI
unsigned char phase_clock_flag;
// 4 data bytes to send
unsigned char phase_clock_data[SIMPLICITI_MAX_PAYLOAD_LENGTH];
// 4 byte device address overrides SimpliciTI end device address set in "smpl_config.dat"
unsigned char phase_clock_ed_address[4];
// Length of data
unsigned char phase_clock_payload_length;
// 1 = send one or more reply packets, 0 = no need to reply
//unsigned char simpliciti_reply;
unsigned char phase_clock_reply_count;
// 1 = send packets sequentially from burst_start to burst_end, 2 = send packets addressed by their index
//u8 burst_mode;
// Start and end index of packets to send out
//u16 burst_start, burst_end;
// Array containing requested packets
//u16 burst_packet[BM_SYNC_BURST_PACKETS_IN_DATA];
// Current packet index
//u8 burst_packet_index;
// *************************************************************************************************
// Extern section
extern void (*fptr_lcd_function_line1)(u8 line, u8 update);
// *************************************************************************************************
// @fn reset_rf
// @brief Reset SimpliciTI data.
// @param none
// @return none
// *************************************************************************************************
void reset_sleep(void)
{
// No connection
sPhase.mode = SLEEP_OFF;
// reset rf
reset_rf();
}
// *************************************************************************************************
// @fn sx_sleep
// @brief Start Sleep mode. Button DOWN connects/disconnects to access point.
// @param u8 line LINE2
// @return none
// *************************************************************************************************
void sx_phase(u8 line)
{
// Exit if battery voltage is too low for radio operation
if (sys.flag.low_battery) return;
// Exit if BlueRobin stack is active
#ifndef ELIMINATE_BLUEROBIN
if (is_bluerobin()) return;
#endif
// Start SimpliciTI in tx only mode
start_simpliciti_sleep();
}
inline u8 diff(u8 x1, u8 x2) {
u8 b1 = x1 - x2;
if(b1 > 128)
b1 = x2 - x1;
return b1;
}
// *************************************************************************************************
// @fn phase_clock_calcpoint
// @brief calculate one data point for the out buffer
// @param none
// @return none
// *************************************************************************************************
void phase_clock_calcpoint() {
u16 x,y,z,res = 0;
u8 i = 0;
for(i=1;i<SLEEP_BUFFER-1;i++) {
x += diff(sPhase.data[i-1][0], sPhase.data[i][0]);
y += diff(sPhase.data[i-1][1], sPhase.data[i][1]);
z += diff(sPhase.data[i-1][1], sPhase.data[i][1]);
}
// can't overflow when SLEEP_BUFFER is not larger then 171
res = x + y + z;
memcpy(&sPhase.out + sPhase.data_nr, &res, sizeof(u16));
// reset stack index
sPhase.data_nr += sizeof(u16);
}
// *************************************************************************************************
// @fn start_simpliciti_tx_only
// @brief Start SimpliciTI (tx only).
// @param simpliciti_state_t SIMPLICITI_ACCELERATION, SIMPLICITI_BUTTONS
// @return none
// *************************************************************************************************
void start_simpliciti_sleep()
{
// Display time in line 1
clear_line(LINE1);
fptr_lcd_function_line1(LINE1, DISPLAY_LINE_CLEAR);
display_time(LINE1, DISPLAY_LINE_UPDATE_FULL);
// Preset simpliciti_data with mode (key or mouse click) and clear other data bytes
simpliciti_data[0] = SIMPLICITI_PHASE_CLOCK_EVENTS;
/*
simpliciti_data[1] = 0;
simpliciti_data[2] = 0;
simpliciti_data[3] = 0;
*/
//memset(&simpliciti_data, 0, SIMPLICITI_MAX_PAYLOAD_LENGTH);
sPhase.data_nr = 0;
sPhase.out_nr = 0;
//memset(&simpliciti_data, 0, SIMPLICITI_MAX_PAYLOAD_LENGTH);
// Turn on beeper icon to show activity
display_symbol(LCD_ICON_BEEPER1, SEG_ON_BLINK_ON);
display_symbol(LCD_ICON_BEEPER2, SEG_ON_BLINK_ON);
display_symbol(LCD_ICON_BEEPER3, SEG_ON_BLINK_ON);
// Debounce button event
Timer0_A4_Delay(CONV_MS_TO_TICKS(BUTTONS_DEBOUNCE_TIME_OUT));
// Prepare radio for RF communication
open_radio();
// Set SimpliciTI mode
sRFsmpl.mode = SIMPLICITI_PHASE_CLOCK;
// Set SimpliciTI timeout to save battery power
//sRFsmpl.timeout = SIMPLICITI_TIMEOUT;
// Start SimpliciTI stack. Try to link to access point.
// Exit with timeout or by a button DOWN press.
if (simpliciti_link())
{
// Start acceleration sensor
as_start();
// Enter TX only routine. This will transfer button events and/or acceleration data to access point.
simpliciti_main_tx_only();
}
// Set SimpliciTI state to OFF
sRFsmpl.mode = SIMPLICITI_OFF;
// Stop acceleration sensor
as_stop();
// Powerdown radio
close_radio();
// Clear last button events
Timer0_A4_Delay(CONV_MS_TO_TICKS(BUTTONS_DEBOUNCE_TIME_OUT));
BUTTONS_IFG = 0x00;
button.all_flags = 0;
// Clear icons
display_symbol(LCD_ICON_BEEPER1, SEG_OFF_BLINK_OFF);
display_symbol(LCD_ICON_BEEPER2, SEG_OFF_BLINK_OFF);
display_symbol(LCD_ICON_BEEPER3, SEG_OFF_BLINK_OFF);
// Clean up line 1
clear_line(LINE1);
display_time(LINE1, DISPLAY_LINE_CLEAR);
// Force full display update
display.flag.full_update = 1;
}
// *************************************************************************************************
// @fn display_phase_clock
// @brief SimpliciTI display routine.
// @param u8 line LINE2
// u8 update DISPLAY_LINE_UPDATE_FULL
// @return none
// *************************************************************************************************
void display_phase_clock(u8 line, u8 update)
{
if (update == DISPLAY_LINE_UPDATE_FULL)
{
display_chars(LCD_SEG_L2_5_0, (u8 *)" SLEEP", SEG_ON);
}
}
// *************************************************************************************************
// @fn is_rf
// @brief Returns TRUE if SimpliciTI receiver is connected.
// @param none
// @return u8
// *************************************************************************************************
u8 is_sleep(void)
{
return (sPhase.mode != SLEEP_OFF);
}
#endif /*CONFIG_PHASE_CLOCK*/

@ -0,0 +1,133 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
#ifndef PHASE_CLOCK_H_
#ifdef CONFIG_PHASE_CLOCK
#define PHASE_CLOCK_H_
#include "rfsimpliciti.h"
#include "simpliciti.h"
// *************************************************************************************************
// Include section
// *************************************************************************************************
// Prototypes section
extern void reset_sleep(void);
extern void ping_clock(void);
extern void collcet_data(void);
extern void send_data(void);
extern void display_phase_clock(u8 line, u8 update);
extern void sx_phase(u8 line);
/*extern void sx_rf(u8 line);
extern void sx_ppt(u8 line);
extern void sx_sync(u8 line);
extern void display_rf(u8 line, u8 update);
extern void display_ppt(u8 line, u8 update);
extern void display_sync(u8 line, u8 update);
extern void send_smpl_data(u16 data);
extern u8 is_rf(void);
*/
extern void phase_clock_calcpoint();
// *************************************************************************************************
// Defines section
// SimpliciTI connection states
typedef enum
{
SLEEP_OFF = 0, // Not connected
SLEEP_CONNECTING, // connection in progress
SLEEP_CONNECTED, // connected to clock
} sleep_mode_t;
// collect n samples of data before tranmitting (saves energy)
#define SLEEP_BUFFER 30
#define SLEEP_COLLECT 1
// how often should a the clock be searched again
#define SEARCH_CLOCK (60*10)
// protocol is PREFIX + ID + PAYLOAD + CHECKSUM
#define SLEEP_ACC_PREFIX 0x82cf // prefix when transmitting acceleration data
#define SLEEP_TIME_PREFIX 0x82aa // prefix when setting the clock
#define PHASE_CLOCK_SEND_LENGTH (SIMPLICITI_MAX_PAYLOAD_LENGTH-2)
#define PHASE_CLOCK_BUFFER ((SIMPLICITI_MAX_PAYLOAD_LENGTH-2)/sizeof(u16))
// Button flags for SimpliciTI data
//#define SIMPLICITI_BUTTON_STAR (0x10)
//#define SIMPLICITI_BUTTON_NUM (0x20)
//#define SIMPLICITI_BUTTON_UP (0x30)
// SimpliciTI mode flag
//#define SIMPLICITI_MOUSE_EVENTS (0x01)
//#define SIMPLICITI_KEY_EVENTS (0x02)
// *************************************************************************************************
// Global Variable section
struct SPhase
{
// SIMPLICITI_OFF, SIMPLICITI_ACCELERATION, SIMPLICITI_BUTTONS
simpliciti_mode_t mode;
// clock to which the watch is paired
u16 clock_id;
// Timeout until clock will be searched again
u16 timeout;
// collected data
//
u8 data[SLEEP_BUFFER][3];
u8 data_nr;
u16 out[PHASE_CLOCK_BUFFER];
u8 out_nr;
};
extern struct SPhase sPhase;
//extern unsigned char simpliciti_flag;
// *************************************************************************************************
// Extern section
#endif /*CONFIG_PHASE_CLOCK*/
#endif /*RFSIMPLICITI_H_*/

@ -40,6 +40,7 @@
// Include section
// system
#include <string.h>
#include "project.h"
// driver
@ -64,6 +65,10 @@
#include "vti_ps.h"
#include "altitude.h"
#ifdef CONFIG_PHASE_CLOCK
#include "phase_clock.h"
#endif
// *************************************************************************************************
// Prototypes section
@ -354,6 +359,7 @@ u8 is_rf(void)
void simpliciti_get_ed_data_callback(void)
{
static u8 packet_counter = 0;
u8 i;
if (sRFsmpl.mode == SIMPLICITI_ACCELERATION)
{
@ -384,8 +390,46 @@ void simpliciti_get_ed_data_callback(void)
simpliciti_flag |= SIMPLICITI_TRIGGER_SEND_DATA;
}
}
}
else // transmit only button events
#ifdef CONFIG_PHASE_CLOCK
} else if (sRFsmpl.mode == SIMPLICITI_PHASE_CLOCK)
{
// Wait for next sample
Timer0_A4_Delay(CONV_MS_TO_TICKS(10));
// Read from sensor if DRDY pin indicates new data (set in PORT2 ISR)
if (request.flag.acceleration_measurement && ((AS_INT_IN & AS_INT_PIN) == AS_INT_PIN))
{
// Clear flag
request.flag.acceleration_measurement = 0;
// Get data from sensor
as_get_data(sAccel.xyz);
// push messured data onto the stack
if (sPhase.data_nr == SLEEP_BUFFER-1) {
phase_clock_calcpoint();
} else {
// copy current value onto the stack
memcpy(&sPhase.data[sPhase.data_nr][0], &sAccel.xyz, sizeof(u8)*3);
sPhase.data_nr++;
}
sPhase.out_nr += sizeof(u16);
if (sPhase.out_nr >= PHASE_CLOCK_SEND_LENGTH)
{
// Reset counter
sPhase.out_nr = 1;
// copy out buffer into the simplicti out buffer skip prefix
memcpy(&simpliciti_data+sizeof(u8), &sPhase.out, PHASE_CLOCK_SEND_LENGTH);
simpliciti_data[0] = SIMPLICITI_PHASE_CLOCK_EVENTS;
// Trigger packet sending
simpliciti_flag |= SIMPLICITI_TRIGGER_SEND_DATA;
}
}
#endif
} else // transmit only button events
{
// New button event is stored in data
if ((packet_counter == 0) && (simpliciti_data[0] & 0xF0) != 0)

@ -62,7 +62,10 @@ typedef enum
SIMPLICITI_OFF = 0, // Not connected
SIMPLICITI_ACCELERATION, // Transmitting acceleration data and button events
SIMPLICITI_BUTTONS, // Transmitting button events
SIMPLICITI_SYNC // Syncing
SIMPLICITI_SYNC, // Syncing
#ifdef CONFIG_PHASE_CLOCK
SIMPLICITI_PHASE_CLOCK, // Phase Clock is running
#endif
} simpliciti_mode_t;
// Stop SimpliciTI transmission after 60 minutes to save power
@ -76,7 +79,7 @@ typedef enum
// SimpliciTI mode flag
#define SIMPLICITI_MOUSE_EVENTS (0x01)
#define SIMPLICITI_KEY_EVENTS (0x02)
#define SIMPLICITI_PHASE_CLOCK_EVENTS (0x03)
// *************************************************************************************************
// Global Variable section

@ -17,7 +17,7 @@ CC_INCLUDE = -I$(PROJ_DIR)/ -I$(PROJ_DIR)/include/ -I$(PROJ_DIR)/driver/ -I$(PRO
CC_COPT = $(CC_CMACH) $(CC_DMACH) $(CC_DOPT) $(CC_INCLUDE)
LOGIC_SOURCE = logic/acceleration.c logic/alarm.c logic/altitude.c logic/battery.c logic/clock.c logic/date.c logic/menu.c logic/rfbsl.c logic/rfsimpliciti.c logic/stopwatch.c logic/temperature.c logic/test.c logic/user.c
LOGIC_SOURCE = logic/acceleration.c logic/alarm.c logic/altitude.c logic/battery.c logic/clock.c logic/date.c logic/menu.c logic/rfbsl.c logic/rfsimpliciti.c logic/stopwatch.c logic/temperature.c logic/test.c logic/user.c logic/phase_clock.c
LOGIC_O = $(addsuffix .o,$(basename $(LOGIC_SOURCE)))
@ -31,17 +31,21 @@ SIMPLICICTI_SOURCE = $(SIMPLICICTI_SOURCE_ODD) simpliciti/Components/bsp/bsp.c s
SIMPLICICTI_O = $(addsuffix .o,$(basename $(SIMPLICICTI_SOURCE)))
MAIN_SOURCE = even_in_range.o ezchronos.c intrinsics.c
MAIN_SOURCE = ezchronos.c intrinsics.c
MAIN_O = even_in_range.o ezchronos.o intrinsics.o
MAIN_O = ezchronos.o intrinsics.o
ALL_O = $(LOGIC_O) $(DRIVER_O) $(SIMPLICICTI_O) $(MAIN_O)
EXTRA_O = even_in_range.o
ALL_C = $(LOGIC_SOURCE) $(DRIVER_SOURCE) $(SIMPLICICTI_SOURCE) $(MAIN_SOURCE)
USE_CFLAGS = $(CFLAGS_PRODUCTION)
main: even_in_range $(ALL_O)
main: config.h even_in_range $(ALL_O) $(EXTRA_O) build
@echo "Compiling $@ for $(CPU)..."
$(CC) $(CC_CMACH) $(CFLAGS_PRODUCTION) -o $(BUILD_DIR)/eZChronos.elf $(ALL_O)
$(CC) $(CC_CMACH) $(CFLAGS_PRODUCTION) -o $(BUILD_DIR)/eZChronos.elf $(ALL_O) $(EXTRA_O)
@echo "Convert to TI Hex file"
$(PYTHON) tools/memory.py -i build/eZChronos.elf -o build/eZChronos.txt
@ -49,22 +53,35 @@ main: even_in_range $(ALL_O)
# @echo USE_CFLAGS = $(CFLAGS_DEBUG)
# call call_debug
$(ALL_O):
$(CC) $(CC_COPT) $(USE_CFLAGS) -c $(basename $@).c -o $@
#$(ALL_O): config.h project/project.h $(addsuffix .o,$(basename $@))
# $(CC) $(CC_COPT) $(USE_CFLAGS) -c $(basename $@).c -o $@
$(ALL_O): %.o: %.c config.h include/project.h
$(CC) $(CC_COPT) $(USE_CFLAGS) -c $< -o $@
# $(CC) -c $(CFLAGS) $< -o $@
debug: even_in_range $(ALL_O)
@echo "Assembling $@ for $(CPU)..."
USE_CFLAGS = $(CFLAGS_DEBUG)
$(CC) $(CC_CMACH) $(CFLAGS_DEBUG) -o $(BUILD_DIR)/eZChronos.dbg.elf $(ALL_O)
$(CC) $(CC_CMACH) $(CFLAGS_DEBUG) -o $(BUILD_DIR)/eZChronos.dbg.elf $(ALL_O) $(EXTRA_O)
even_in_range:
@echo "Assembling $@ in one step for $(CPU)..."
msp430-gcc -D_GNU_ASSEMBLER_ -x assembler-with-cpp -c even_in_range.s -o even_in_range.o
clean:
@echo "Removing files..."
rm -f $(ALL_O)
build:
mkdir build
config.h:
python tools/config.py
config:
python tools/config.py
#rm *.o $(BUILD_DIR)*

Loading…
Cancel
Save