|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
| 2 | + * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
3 | 3 | *
|
4 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a
|
5 | 5 | * copy of this software and associated documentation files (the "Software"),
|
|
52 | 52 | #include "hci_vs.h"
|
53 | 53 |
|
54 | 54 | /* Number of WSF buffer pools */
|
55 |
| -#define WSF_BUF_POOLS 4 |
| 55 | +#define WSF_BUF_POOLS 5 |
56 | 56 |
|
57 | 57 | /*! Free memory for pool buffers. */
|
58 |
| -static uint8_t mainBufMem[768]; |
| 58 | +static uint8_t mainBufMem[1040]; |
59 | 59 |
|
60 | 60 | /*! Default pool descriptor. */
|
61 | 61 | static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
|
62 | 62 | {
|
63 | 63 | { 16, 8 },
|
64 | 64 | { 32, 4 },
|
65 | 65 | { 64, 2 },
|
66 |
| - { 128, 2 } |
| 66 | + { 128, 2 }, |
| 67 | + { 272, 1 } |
67 | 68 | };
|
68 | 69 |
|
| 70 | +/* Store the Event signalling */ |
| 71 | +bool isEventsSignaled = false; |
| 72 | + |
69 | 73 | /*! WSF handler ID */
|
70 | 74 | wsfHandlerId_t maximHandlerId;
|
71 | 75 | static volatile int reset_complete;
|
72 | 76 |
|
| 77 | +#ifdef BLE_HCI_UART |
| 78 | +static DigitalIn _rts(BT_CTS); |
| 79 | +static DigitalIn _cts(BT_RTS); |
| 80 | +static DigitalIn _clk(BT_CLK); |
| 81 | +static DigitalOut _shutdown(BT_RST, 0); |
| 82 | +static Serial _uart(BT_TX, BT_RX, 115200); |
| 83 | +#else |
73 | 84 | /* Current mbed SPI API does not support HW slave selects. Configured in HCI driver. */
|
74 | 85 | static DigitalOut _csn(HCI_CSN, 1);
|
75 | 86 | static SPI _spi(HCI_MOSI, HCI_MISO, HCI_SCK, HCI_CSN);
|
76 | 87 | static DigitalOut _rst(HCI_RST, 0);
|
77 | 88 | static InterruptIn _irq(HCI_IRQ);
|
| 89 | +#endif |
78 | 90 |
|
79 | 91 | /**
|
80 | 92 | * The singleton which represents the MaximBLE transport for the BLE.
|
81 | 93 | */
|
82 | 94 | static MaximBLE deviceInstance;
|
83 | 95 |
|
| 96 | +extern "C" { |
| 97 | + |
| 98 | +/* |
| 99 | + * This function will signal to the user code by calling signalEventsToProcess. |
| 100 | + * It is registered and called into the Wsf Stack. |
| 101 | + */ |
| 102 | +void wsf_mbed_ble_signal_event(void) |
| 103 | +{ |
| 104 | + if (isEventsSignaled == false) { |
| 105 | + isEventsSignaled = true; |
| 106 | + deviceInstance.signalEventsToProcess(::BLE::DEFAULT_INSTANCE); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +} |
| 111 | + |
84 | 112 | /**
|
85 | 113 | * BLE-API requires an implementation of the following function in order to
|
86 | 114 | * obtain its transport handle.
|
@@ -240,16 +268,20 @@ ble_error_t MaximBLE::init(BLE::InstanceID_t instanceID, FunctionPointerWithCont
|
240 | 268 | maximHandlerId = WsfOsSetNextHandler(maximHandler);
|
241 | 269 |
|
242 | 270 | /* init HCI */
|
| 271 | +#ifdef BLE_HCI_UART |
| 272 | + hciDrvInit(BT_TX, BT_RST, BT_CLK); |
| 273 | +#else |
243 | 274 | _irq.disable_irq();
|
244 | 275 | _irq.rise(hciDrvIsr);
|
245 | 276 | _irq.fall(NULL);
|
246 | 277 | hciDrvInit(HCI_CSN, HCI_RST, HCI_IRQ);
|
| 278 | +#endif |
247 | 279 |
|
248 | 280 | /* Register for stack callbacks */
|
249 | 281 | DmRegister(DmCback);
|
250 | 282 | DmConnRegister(DM_CLIENT_ID_APP, DmCback);
|
251 | 283 | AttConnRegister(AppServerConnCback);
|
252 |
| - |
| 284 | + |
253 | 285 | /* Reset the device */
|
254 | 286 | reset_complete = 0;
|
255 | 287 | DmDevReset();
|
@@ -301,12 +333,15 @@ void MaximBLE::waitForEvent(void)
|
301 | 333 |
|
302 | 334 | void MaximBLE::processEvents()
|
303 | 335 | {
|
304 |
| - callDispatcher(); |
| 336 | + if (isEventsSignaled) { |
| 337 | + isEventsSignaled = false; |
| 338 | + callDispatcher(); |
| 339 | + } |
305 | 340 | }
|
306 | 341 |
|
307 | 342 | void MaximBLE::timeoutCallback(void)
|
308 | 343 | {
|
309 |
| - // do nothing. just an interrupt for wake up. |
| 344 | + wsf_mbed_ble_signal_event(); |
310 | 345 | }
|
311 | 346 |
|
312 | 347 | void MaximBLE::callDispatcher(void)
|
|
0 commit comments