1- #include < stdint.h>
2- #include < stdbool.h>
3-
4- #ifdef __cplusplus
5- extern " C"
6- {
7- #endif
8-
9- #include " wsf_types.h"
10- #include " wsf_trace.h"
11- #include " wsf_buf.h"
12-
13- #include " hci_handler.h"
14- #include " dm_handler.h"
15- #include " l2c_handler.h"
16- #include " att_handler.h"
17- #include " smp_handler.h"
18- #include " l2c_api.h"
19- #include " att_api.h"
20- #include " smp_api.h"
21- #include " app_api.h"
22- #include " hci_core.h"
23- #include " hci_drv.h"
24- #include " hci_drv_apollo.h"
25- #include " hci_drv_apollo3.h"
26-
27- #include " am_mcu_apollo.h"
28- #include " am_util.h"
29-
30- #include " nus_api.h"
31- #include " app_ui.h"
32-
33- #include " wsf_msg.h"
34-
35- #ifdef __cplusplus
36- }
37- #endif
38-
39- #define DEBUG
40- #define SERIAL_PORT Serial
41- #define DEBUG_UART_BUF_LEN 256
42-
43- // ****************************************
44- //
45- // Debug print functions
46- //
47- // ****************************************
48- extern " C" void debug_print (const char * f, const char * F, uint16_t L){
49- SERIAL_PORT.printf (" fm: %s, file: %s, line: %d\n " , f, F, L);
50- }
51-
52- extern " C" void debug_printf (char * fmt, ...){
53- #ifdef DEBUG
54- char debug_buffer [DEBUG_UART_BUF_LEN];
55- va_list args;
56- va_start (args, fmt);
57- vsnprintf (debug_buffer, DEBUG_UART_BUF_LEN, (const char *)fmt, args);
58- va_end (args);
59-
60- SERIAL_PORT.print (debug_buffer);
61- #endif // DEBUG
62- }
63-
64-
65- // ****************************************
66- //
67- // C-callable led functions
68- //
69- // ****************************************
70- extern void set_led_high ( void ){
71- digitalWrite (LED_BUILTIN, HIGH);
72- }
73-
74- extern void set_led_low ( void ){
75- digitalWrite (LED_BUILTIN, LOW);
76- }
77-
78- // *****************************************************************************
79- //
80- // Forward declarations.
81- //
82- // *****************************************************************************
83- void exactle_stack_init (void );
84- void scheduler_timer_init (void );
85- void update_scheduler_timers (void );
86- void set_next_wakeup (void );
87- void button_handler (wsfEventMask_t event, wsfMsgHdr_t *pMsg);
88- extern void AppUiBtnTest (uint8_t btn);
1+ #include " BLE_example.h"
892
903
914// *****************************************************************************
@@ -151,6 +64,8 @@ static wsfBufPoolDesc_t g_psPoolDescriptors[WSF_BUF_POOLS] =
15164uint32_t g_ui32LastTime = 0 ;
15265extern " C" void radio_timer_handler (void );
15366
67+
68+
15469// *****************************************************************************
15570//
15671// Initialization for the ExactLE stack.
@@ -441,63 +356,40 @@ extern "C" void am_ble_isr(void){
441356}
442357
443358
444- void setup () {
445- // put your setup code here, to run once:
446-
447- #ifdef DEBUG
448- SERIAL_PORT.begin (115200 );
449- delay (1000 );
450- SERIAL_PORT.printf (" Apollo3 Arduino BLE Example. Compiled: %s\n " , __TIME__);
451- #endif
452-
453- pinMode (LED_BUILTIN, OUTPUT);
454- set_led_low ();
455-
456- //
457- // Boot the radio.
458- //
459- HciDrvRadioBoot (0 );
460-
461- //
462- // Initialize the main ExactLE stack.
463- //
464- exactle_stack_init ();
465-
466- //
467- // Start the "Nus" profile.
468- //
469- NusStart ();
470-
471- while (TRUE )
472- {
473- // debug_print(__func__, __FILE__, __LINE__);
474-
475- //
476- // Calculate the elapsed time from our free-running timer, and update
477- // the software timers in the WSF scheduler.
478- //
479- update_scheduler_timers ();
480- wsfOsDispatcher ();
481-
482- //
483- // Enable an interrupt to wake us up next time we have a scheduled event.
484- //
485- set_next_wakeup ();
486-
487- am_hal_interrupt_master_disable ();
488-
489- //
490- // Check to see if the WSF routines are ready to go to sleep.
491- //
492- if ( wsfOsReadyToSleep () )
493- {
494- am_hal_sysctrl_sleep (AM_HAL_SYSCTRL_SLEEP_DEEP);
495- }
496- am_hal_interrupt_master_enable ();
497- }
359+
360+
361+ // ****************************************
362+ //
363+ // Debug print functions
364+ //
365+ // ****************************************
366+ #define DEBUG_UART_BUF_LEN 256
367+
368+ extern " C" void debug_print (const char * f, const char * F, uint16_t L){
369+ SERIAL_PORT.printf (" fm: %s, file: %s, line: %d\n " , f, F, L);
498370}
499371
500- void loop () {
501- // put your main code here, to run repeatedly:
372+ extern " C" void debug_printf (char * fmt, ...){
373+ #ifdef DEBUG
374+ char debug_buffer [DEBUG_UART_BUF_LEN];
375+ va_list args;
376+ va_start (args, fmt);
377+ vsnprintf (debug_buffer, DEBUG_UART_BUF_LEN, (const char *)fmt, args);
378+ va_end (args);
502379
380+ SERIAL_PORT.print (debug_buffer);
381+ #endif // DEBUG
503382}
383+
384+ // ****************************************
385+ //
386+ // C-callable led functions
387+ //
388+ // ****************************************
389+ extern void set_led_high ( void ){
390+ digitalWrite (LED_BUILTIN, HIGH);
391+ }
392+
393+ extern void set_led_low ( void ){
394+ digitalWrite (LED_BUILTIN, LOW);
395+ }
0 commit comments