btstack/eZ430-RF2560/example/led_counter.c

81 lines
1.7 KiB
C

//*****************************************************************************
//
// led_counter demo - uses the BTstack run loop to blink an LED
//
//*****************************************************************************
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <msp430x54x.h>
#include "hal_board.h"
#include "hal_compat.h"
#include "hal_usb.h"
#include "btstack_memory.h"
#include <btstack/run_loop.h>
#include "btstack-config.h"
#define HEARTBEAT_PERIOD_MS 1000
static void heartbeat_handler(struct timer *ts){
// increment counter
static int counter = 0;
char lineBuffer[30];
sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter);
printf(lineBuffer);
// toggle LED
LED_PORT_OUT = LED_PORT_OUT ^ LED_2;
run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
run_loop_add_timer(ts);
}
// main
int main(void)
{
// stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
//Initialize clock and peripherals
halBoardInit();
halBoardStartXT1();
halBoardSetSystemClock(SYSCLK_16MHZ);
// init debug UART
halUsbInit();
// init LEDs
LED_PORT_OUT |= LED_1 | LED_2;
LED_PORT_DIR |= LED_1 | LED_2;
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
// set one-shot timer
timer_source_t heartbeat;
heartbeat.process = &heartbeat_handler;
run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
run_loop_add_timer(&heartbeat);
printf("Run...\n\r");
// ready - enable irq used in h4 task
__enable_interrupt();
// turn on!
// go!
run_loop_execute();
// happy compiler!
return 0;
}