From 5030dd799fb10556d8904e52baefc1d544723c66 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sun, 19 Apr 2015 22:26:59 +0200 Subject: [PATCH] extracted general led_counter --- example/embedded/Makefile.inc | 4 + .../embedded}/led_counter.c | 17 +-- platforms/ez430-rf2560/example/led_counter.c | 99 --------------- .../example/led_counter.c | 118 ------------------ 4 files changed, 7 insertions(+), 231 deletions(-) rename {platforms/msp430f5229lp-cc2564b/example => example/embedded}/led_counter.c (93%) delete mode 100644 platforms/ez430-rf2560/example/led_counter.c delete mode 100644 platforms/msp-exp430f5438-cc2564b/example/led_counter.c diff --git a/example/embedded/Makefile.inc b/example/embedded/Makefile.inc index 43ef843fa..7c7888b80 100644 --- a/example/embedded/Makefile.inc +++ b/example/embedded/Makefile.inc @@ -68,6 +68,7 @@ EXAMPLES = \ spp_and_le_counter \ spp_counter \ spp_streamer \ + led_counter \ EXAMPLES_USING_LE = \ ancs_client \ @@ -176,6 +177,9 @@ bnep_test: ${CORE_OBJ} ${COMMON_OBJ} bnep_test.c ble_client: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${SM_REAL} ble_client.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ +led_counter: ${CORE_OBJ} ${COMMON_OBJ} led_counter.c + ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ + clean: rm -f ${EXAMPLES} diff --git a/platforms/msp430f5229lp-cc2564b/example/led_counter.c b/example/embedded/led_counter.c similarity index 93% rename from platforms/msp430f5229lp-cc2564b/example/led_counter.c rename to example/embedded/led_counter.c index abd817511..adca6a3f6 100644 --- a/platforms/msp430f5229lp-cc2564b/example/led_counter.c +++ b/example/embedded/led_counter.c @@ -43,20 +43,9 @@ #include #include -#include -#include - -#include - -#include "hal_board.h" -#include "hal_compat.h" -#include "hal_usb.h" - -#include "btstack_memory.h" #include #include -#include "btstack-config.h" #define HEARTBEAT_PERIOD_MS 1000 @@ -72,7 +61,7 @@ static void heartbeat_handler(timer_source_t *ts){ // increment counter char lineBuffer[30]; sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter); - printf(lineBuffer); + puts(lineBuffer); // toggle LED hal_led_toggle(); @@ -90,10 +79,10 @@ static void timer_setup(){ int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ - printf("Run...\n\r"); - timer_setup(); + printf("Run...\n\r"); + return 0; } diff --git a/platforms/ez430-rf2560/example/led_counter.c b/platforms/ez430-rf2560/example/led_counter.c deleted file mode 100644 index e24470bb4..000000000 --- a/platforms/ez430-rf2560/example/led_counter.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2014 BlueKitchen GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the copyright holders nor the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * 4. Any redistribution, use, or modification is done solely for - * personal benefit and not for any commercial purpose or for - * monetary gain. - * - * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH 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 MATTHIAS - * RINGWALD 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. - * - * Please inquire about commercial licensing options at - * contact@bluekitchen-gmbh.com - * - */ - -// ***************************************************************************** -// -// led_counter demo - uses the BTstack run loop to blink an LED -// -// ***************************************************************************** - -#include -#include -#include -#include - -#include - -#include "hal_board.h" -#include "hal_compat.h" -#include "hal_usb.h" - -#include "btstack_memory.h" - -#include -#include -#include "btstack-config.h" - -#define HEARTBEAT_PERIOD_MS 1000 - -static int counter = 0; -static timer_source_t heartbeat; - -static void run_loop_register_timer(timer_source_t *timer, uint16_t period){ - run_loop_set_timer(timer, period); - run_loop_add_timer(timer); -} - -static void heartbeat_handler(timer_source_t *ts){ - // increment counter - char lineBuffer[30]; - sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter); - printf(lineBuffer); - - // toggle LED - hal_led_toggle(); - - // re-register timer - run_loop_register_timer(ts, HEARTBEAT_PERIOD_MS); -} - -static void timer_setup(){ - // set one-shot timer - heartbeat.process = &heartbeat_handler; - run_loop_register_timer(&heartbeat, HEARTBEAT_PERIOD_MS); -} - -int btstack_main(int argc, const char * argv[]); -int btstack_main(int argc, const char * argv[]){ - - timer_setup(); - - printf("Run...\n\r"); - - return 0; -} - diff --git a/platforms/msp-exp430f5438-cc2564b/example/led_counter.c b/platforms/msp-exp430f5438-cc2564b/example/led_counter.c deleted file mode 100644 index 0bd65ab17..000000000 --- a/platforms/msp-exp430f5438-cc2564b/example/led_counter.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2014 BlueKitchen GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the copyright holders nor the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * 4. Any redistribution, use, or modification is done solely for - * personal benefit and not for any commercial purpose or for - * monetary gain. - * - * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH 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 MATTHIAS - * RINGWALD 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. - * - * Please inquire about commercial licensing options at - * contact@bluekitchen-gmbh.com - * - */ - -// ***************************************************************************** -/* EXAMPLE_START(led_counter): UART and timer interrupt without Bluetooth - * - * @text The example uses the BTstack run loop to blink an LED. - * The example demonstrates how to setup hardware, initialize BTstack without - * Bluetooth, provide a periodic timer to toggle an LED and print number of - * toggles as a minimal BTstack test. - */ -// ***************************************************************************** - - - -#include -#include -#include -#include - -#include - -#include "hal_board.h" -#include "hal_compat.h" -#include "hal_usb.h" - -#include "btstack_memory.h" - -#include -#include -#include "btstack-config.h" - -#define HEARTBEAT_PERIOD_MS 1000 - -static int counter = 0; -static timer_source_t heartbeat; - -static void run_loop_register_timer(timer_source_t *timer, uint16_t period){ - run_loop_set_timer(timer, period); - run_loop_add_timer(timer); -} - -/* @section Periodic Timer Setup - * - * @text As timers in BTstack are single shot, - * the periodic counter is implemented by re-registering the timer source in the - * heartbeat handler callback function. Listing LEDToggler shows heartbeat handler - * adapted to periodically toggle an LED and print number of toggles. - */ - -/* LISTING_START(LEDToggler): Periodic counter */ -static void heartbeat_handler(timer_source_t *ts){ - // increment counter - char lineBuffer[30]; - sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter); - printf(lineBuffer); - - // toggle LED - hal_led_toggle(); - - // re-register timer - run_loop_register_timer(ts, HEARTBEAT_PERIOD_MS); -} -/* LISTING_END */ - -/* @section Turn On and Go - * - * @text Listing MainConfiguration shows main application code. - * It is called after hardware and BTstack configuration (memory, run loop and - * transport layer) by the platform main in - * \path{platforms/PLATFORM/src/main.c}. - */ - -/* LISTING_START(MainConfiguration): Setup heartbeat timer */ -int btstack_main(int argc, const char * argv[]); -int btstack_main(int argc, const char * argv[]){ - // set one-shot timer - heartbeat.process = &heartbeat_handler; - run_loop_register_timer(&heartbeat, HEARTBEAT_PERIOD_MS); - printf("Run...\n\r"); - return 0; -} -/* LISTING_END */ -/* EXAMPLE_END */ \ No newline at end of file