Skip to content
Snippets Groups Projects
Verified Commit f0a9fd42 authored by schneider's avatar schneider Committed by rahix
Browse files

chore(ble): Apply code style

parent 0f26c9f3
Branches
Tags
No related merge requests found
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
* *
* Reason: we need to correctly implement AppHandleNumericComparison * Reason: we need to correctly implement AppHandleNumericComparison
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include <string.h> #include <string.h>
#include "wsf_types.h" #include "wsf_types.h"
#include "wsf_msg.h" #include "wsf_msg.h"
...@@ -418,3 +420,4 @@ void AppUpdatePrivacyMode(appDbHdl_t hdl) ...@@ -418,3 +420,4 @@ void AppUpdatePrivacyMode(appDbHdl_t hdl)
} }
} }
} }
/* clang-format on */
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
* *
* Reason: we need to implement persistent storage for pairings * Reason: we need to implement persistent storage for pairings
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include <string.h> #include <string.h>
#include "wsf_types.h" #include "wsf_types.h"
#include "wsf_assert.h" #include "wsf_assert.h"
...@@ -708,3 +710,4 @@ void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao) ...@@ -708,3 +710,4 @@ void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao)
{ {
((appDbRec_t *)hdl)->peerRpao = peerRpao; ((appDbRec_t *)hdl)->peerRpao = peerRpao;
} }
/* clang-format on */
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
* Reason: has several user interactions which we likley have to implement * Reason: has several user interactions which we likley have to implement
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
/************************************************************************************************** /**************************************************************************************************
Global Variables Global Variables
**************************************************************************************************/ **************************************************************************************************/
...@@ -330,3 +332,4 @@ void AppUiBtnTest(uint8_t btn) ...@@ -330,3 +332,4 @@ void AppUiBtnTest(uint8_t btn)
} }
} }
/* clang-format on */
#include "wsf_types.h" #include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h" #include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h" #include "wsf_trace.h"
#include "app_ui.h"
#include "ble_api.h" #include "ble_api.h"
#include "hci_vs.h" #include "hci_vs.h"
#include "att_defs.h"
#include "util/bstream.h"
#include "att_api.h" #include "att_api.h"
#include "modules/modules.h"
#include "fs_util.h" #include "fs_util.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "timers.h" #include "timers.h"
...@@ -21,8 +13,6 @@ ...@@ -21,8 +13,6 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
/* Size of buffer for stdio functions */
#define WSF_BUF_POOLS 6 #define WSF_BUF_POOLS 6
#define WSF_BUF_SIZE 0x1048 #define WSF_BUF_SIZE 0x1048
...@@ -34,6 +24,7 @@ uint32_t SystemHeapStart; ...@@ -34,6 +24,7 @@ uint32_t SystemHeapStart;
static TaskHandle_t ble_task_id = NULL; static TaskHandle_t ble_task_id = NULL;
/*! Default pool descriptor. */ /*! Default pool descriptor. */
/* clang-format off */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ {
{ 16, 8 }, { 16, 8 },
...@@ -43,6 +34,11 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = ...@@ -43,6 +34,11 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ 256, 4 }, { 256, 4 },
{ 512, 4 } { 512, 4 }
}; };
/* clang-format on */
static StaticTimer_t x;
static TimerHandle_t timerWakeup = NULL;
static int lasttick = 0;
/*! \brief Stack initialization for app. */ /*! \brief Stack initialization for app. */
extern void StackInit(void); extern void StackInit(void);
...@@ -52,30 +48,21 @@ extern void bleuart_init(void); ...@@ -52,30 +48,21 @@ extern void bleuart_init(void);
/*************************************************************************************************/ /*************************************************************************************************/
void PalSysAssertTrap(void) void PalSysAssertTrap(void)
{ {
while(1) {} while (1) {
}
} }
/*************************************************************************************************/ /*************************************************************************************************/
static bool_t myTrace(const uint8_t *pBuf, uint32_t len) static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{ {
extern uint8_t wsfCsNesting; extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0) if (wsfCsNesting == 0) {
{
fwrite(pBuf, len, 1, stdout); fwrite(pBuf, len, 1, stdout);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
/*************************************************************************************************/
/*!
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/ /*************************************************************************************************/
static void WsfInit(void) static void WsfInit(void)
{ {
...@@ -92,6 +79,7 @@ static void WsfInit(void) ...@@ -92,6 +79,7 @@ static void WsfInit(void)
WsfTraceRegisterHandler(myTrace); WsfTraceRegisterHandler(myTrace);
WsfTraceEnable(TRUE); WsfTraceEnable(TRUE);
} }
/*************************************************************************************************/
/* TODO: We need a source of MACs */ /* TODO: We need a source of MACs */
static void setAddress(void) static void setAddress(void)
{ {
...@@ -110,15 +98,16 @@ static void setAddress(void) ...@@ -110,15 +98,16 @@ static void setAddress(void)
bdAddr[5] = a; bdAddr[5] = a;
} }
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]); printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
bdAddr[5],
bdAddr[4],
bdAddr[3],
bdAddr[2],
bdAddr[1],
bdAddr[0]);
HciVsSetBdAddr(bdAddr); HciVsSetBdAddr(bdAddr);
} }
/*************************************************************************************************/
static StaticTimer_t x;
TimerHandle_t timerWakeup = NULL;
int lasttick = 0;
bool schedule_needed = false;
static void vTimerCallback(xTimerHandle pxTimer) static void vTimerCallback(xTimerHandle pxTimer)
{ {
//printf("wake\n"); //printf("wake\n");
...@@ -128,7 +117,7 @@ static void vTimerCallback(xTimerHandle pxTimer) ...@@ -128,7 +117,7 @@ static void vTimerCallback(xTimerHandle pxTimer)
lasttick = tick; lasttick = tick;
//printf("done\n"); //printf("done\n");
} }
/*************************************************************************************************/
static void notify(void) static void notify(void)
{ {
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
...@@ -139,7 +128,7 @@ static void notify(void) ...@@ -139,7 +128,7 @@ static void notify(void)
xTaskNotifyGive(ble_task_id); xTaskNotifyGive(ble_task_id);
} }
} }
/*************************************************************************************************/
void WsfTimerNotify(void) void WsfTimerNotify(void)
{ {
//printf("WsfTimerNotify\n"); //printf("WsfTimerNotify\n");
...@@ -147,13 +136,13 @@ void WsfTimerNotify(void) ...@@ -147,13 +136,13 @@ void WsfTimerNotify(void)
// xTimerChangePeriodFromISR exists // xTimerChangePeriodFromISR exists
notify(); notify();
} }
/*************************************************************************************************/
void wsf_ble_signal_event(void) void wsf_ble_signal_event(void)
{ {
//printf("wsf_ble_signal_event\n"); //printf("wsf_ble_signal_event\n");
notify(); notify();
} }
/*************************************************************************************************/
static void scheduleTimer(void) static void scheduleTimer(void)
{ {
bool_t timerRunning; bool_t timerRunning;
...@@ -166,7 +155,11 @@ static void scheduleTimer(void) ...@@ -166,7 +155,11 @@ static void scheduleTimer(void)
//printf("time_to_next_expire = %d\n", time_to_next_expire); //printf("time_to_next_expire = %d\n", time_to_next_expire);
//printf("change period\n"); //printf("change period\n");
if (timerWakeup != NULL) { if (timerWakeup != NULL) {
xTimerChangePeriod(timerWakeup, pdMS_TO_TICKS(time_to_next_expire), 0); xTimerChangePeriod(
timerWakeup,
pdMS_TO_TICKS(time_to_next_expire),
0
);
//printf("insert done\n"); //printf("insert done\n");
} else { } else {
printf("could not create timer\n"); printf("could not create timer\n");
...@@ -175,10 +168,10 @@ static void scheduleTimer(void) ...@@ -175,10 +168,10 @@ static void scheduleTimer(void)
printf("No timer running\n"); printf("No timer running\n");
} }
} }
/*************************************************************************************************/
void vBleTask(void *pvParameters)
static void ble_init(void)
{ {
ble_task_id = xTaskGetCurrentTaskHandle();
WsfInit(); WsfInit();
StackInit(); StackInit();
setAddress(); setAddress();
...@@ -199,13 +192,8 @@ static void ble_init(void) ...@@ -199,13 +192,8 @@ static void ble_init(void)
pdMS_TO_TICKS(1), /* period/time */ pdMS_TO_TICKS(1), /* period/time */
pdFALSE, /* auto reload */ pdFALSE, /* auto reload */
NULL, /* timer ID */ NULL, /* timer ID */
vTimerCallback, &x); /* callback */ vTimerCallback,
} &x); /* callback */
void vBleTask(void*pvParameters)
{
ble_task_id = xTaskGetCurrentTaskHandle();
ble_init();
while (1) { while (1) {
ulTaskNotifyTake(pdTRUE, portTICK_PERIOD_MS * 1000); ulTaskNotifyTake(pdTRUE, portTICK_PERIOD_MS * 1000);
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
* Fit -> Ble * Fit -> Ble
* FIT -> BLE * FIT -> BLE
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include <string.h> #include <string.h>
#include "wsf_types.h" #include "wsf_types.h"
#include "util/bstream.h" #include "util/bstream.h"
...@@ -508,3 +510,4 @@ void BleStart(void) ...@@ -508,3 +510,4 @@ void BleStart(void)
/* Reset the device */ /* Reset the device */
DmDevReset(); DmDevReset();
} }
/* clang-format on */
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
* Many components are related to the role of the device. Different components need to be * Many components are related to the role of the device. Different components need to be
* initialized for central and peripheral roles. * initialized for central and peripheral roles.
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "wsf_types.h" #include "wsf_types.h"
...@@ -184,3 +186,4 @@ void StackInit(void) ...@@ -184,3 +186,4 @@ void StackInit(void)
/*TODO card10: Probably want to adjust this */ /*TODO card10: Probably want to adjust this */
HciSetMaxRxAclLen(100); HciSetMaxRxAclLen(100);
} }
/* clang-format off */
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
/* card10: /* card10:
* copied from lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_core.c * copied from lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_core.c
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include "wsf_types.h" #include "wsf_types.h"
#include "att_api.h" #include "att_api.h"
#include "att_uuid.h" #include "att_uuid.h"
...@@ -344,3 +346,4 @@ void SvcCoreGapAddRpaoCh(void) ...@@ -344,3 +346,4 @@ void SvcCoreGapAddRpaoCh(void)
svcGapGroup.endHandle = GAP_RPAO_HDL; svcGapGroup.endHandle = GAP_RPAO_HDL;
} }
} }
/* clang-format on */
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
* *
* Contains adaptions for the card10 (e.g. manufacturer name) * Contains adaptions for the card10 (e.g. manufacturer name)
*/ */
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include "wsf_types.h" #include "wsf_types.h"
#include "att_api.h" #include "att_api.h"
#include "wsf_assert.h" #include "wsf_assert.h"
...@@ -331,3 +333,4 @@ void SvcDisRemoveGroup(void) ...@@ -331,3 +333,4 @@ void SvcDisRemoveGroup(void)
{ {
AttsRemoveGroup(DIS_START_HDL); AttsRemoveGroup(DIS_START_HDL);
} }
/* clang-format on */
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#define UART_START_HDL 0x800 /*!< \brief Service start handle. */ #define UART_START_HDL 0x800 /*!< \brief Service start handle. */
#define UART_END_HDL (UART_MAX_HDL - 1) /*!< \brief Service end handle. */ #define UART_END_HDL (UART_MAX_HDL - 1) /*!< \brief Service end handle. */
...@@ -20,9 +19,7 @@ ...@@ -20,9 +19,7 @@
**************************************************************************************************/ **************************************************************************************************/
/*! \brief UART Service Handles */ /*! \brief UART Service Handles */
enum enum { UART_SVC_HDL = UART_START_HDL, /*!< \brief UART service declaration */
{
UART_SVC_HDL = UART_START_HDL, /*!< \brief UART service declaration */
UART_RX_CH_HDL, /*!< \brief UART rx characteristic */ UART_RX_CH_HDL, /*!< \brief UART rx characteristic */
UART_RX_HDL, /*!< \brief UART rx value */ UART_RX_HDL, /*!< \brief UART rx value */
UART_TX_CH_HDL, /*!< \brief UART tx characteristic */ UART_TX_CH_HDL, /*!< \brief UART tx characteristic */
...@@ -42,8 +39,6 @@ static const uint8_t uartTxCh[] = {ATT_PROP_READ | ATT_PROP_NOTIFY, UINT16_TO_BY ...@@ -42,8 +39,6 @@ static const uint8_t uartTxCh[] = {ATT_PROP_READ | ATT_PROP_NOTIFY, UINT16_TO_BY
const uint8_t attUartTxChUuid[] = {0x9E,0xCA,0xDC,0x24,0x0E,0xE5, 0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x03,0x00,0x40,0x6E}; const uint8_t attUartTxChUuid[] = {0x9E,0xCA,0xDC,0x24,0x0E,0xE5, 0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x03,0x00,0x40,0x6E};
/* clang-format on */ /* clang-format on */
static void *SvcUARTAddGroupDyn(void) static void *SvcUARTAddGroupDyn(void)
{ {
void *pSHdl; void *pSHdl;
...@@ -52,23 +47,24 @@ static void *SvcUARTAddGroupDyn(void) ...@@ -52,23 +47,24 @@ static void *SvcUARTAddGroupDyn(void)
/* Create the service */ /* Create the service */
pSHdl = AttsDynCreateGroup(UART_START_HDL, UART_END_HDL); pSHdl = AttsDynCreateGroup(UART_START_HDL, UART_END_HDL);
if (pSHdl != NULL) if (pSHdl != NULL) {
{ /* clang-format off */
/* Primary service */ /* Primary service */
AttsDynAddAttrConst(pSHdl, attPrimSvcUuid, UARTSvc, sizeof(UARTSvc), 0, ATTS_PERMIT_READ); AttsDynAddAttrConst( pSHdl, attPrimSvcUuid, UARTSvc, sizeof(UARTSvc),
0, ATTS_PERMIT_READ);
/* UART rx characteristic */ /* UART rx characteristic */
AttsDynAddAttrConst(pSHdl, attChUuid, uartRxCh, sizeof(uartRxCh), 0, ATTS_PERMIT_READ); AttsDynAddAttrConst( pSHdl, attChUuid, uartRxCh, sizeof(uartRxCh),
0, ATTS_PERMIT_READ);
// XXX: attUartRxChUuid is 16 bytes but nothing says so.... // XXX: attUartRxChUuid is 16 bytes but nothing says so....
/* UART rx value */ /* UART rx value */
// XXX: not sure if max value of 128 is fine... // XXX: not sure if max value of 128 is fine...
AttsDynAddAttr( pSHdl, attUartRxChUuid, NULL, 0, 128, AttsDynAddAttr( pSHdl, attUartRxChUuid, NULL, 0, 128,
ATTS_SET_WRITE_CBACK | ATTS_SET_VARIABLE_LEN, ATTS_PERMIT_WRITE); ATTS_SET_WRITE_CBACK | ATTS_SET_VARIABLE_LEN, ATTS_PERMIT_WRITE);
/* UART tx characteristic */ /* UART tx characteristic */
AttsDynAddAttrConst(pSHdl, attChUuid, uartTxCh, sizeof(uartTxCh), 0, ATTS_PERMIT_READ); AttsDynAddAttrConst( pSHdl, attChUuid, uartTxCh, sizeof(uartTxCh),
0, ATTS_PERMIT_READ);
/* UART tx value */ /* UART tx value */
/* TODO: do we need ATTS_SET_READ_CBACK ? */ /* TODO: do we need ATTS_SET_READ_CBACK ? */
AttsDynAddAttr( pSHdl, attUartTxChUuid, NULL, 0, sizeof(uint8_t), AttsDynAddAttr( pSHdl, attUartTxChUuid, NULL, 0, sizeof(uint8_t),
...@@ -76,6 +72,7 @@ static void *SvcUARTAddGroupDyn(void) ...@@ -76,6 +72,7 @@ static void *SvcUARTAddGroupDyn(void)
/* UART tx CCC descriptor */ /* UART tx CCC descriptor */
AttsDynAddAttr( pSHdl, attCliChCfgUuid, initCcc, sizeof(uint16_t), sizeof(uint16_t), AttsDynAddAttr( pSHdl, attCliChCfgUuid, initCcc, sizeof(uint16_t), sizeof(uint16_t),
ATTS_SET_CCC, ATTS_PERMIT_READ | ATTS_PERMIT_WRITE); ATTS_SET_CCC, ATTS_PERMIT_READ | ATTS_PERMIT_WRITE);
/* clang-format on */
} }
return pSHdl; return pSHdl;
...@@ -83,17 +80,26 @@ static void *SvcUARTAddGroupDyn(void) ...@@ -83,17 +80,26 @@ static void *SvcUARTAddGroupDyn(void)
dmConnId_t active_connection = 0; dmConnId_t active_connection = 0;
static uint8_t UARTReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, static uint8_t UARTReadCback(
uint16_t offset, attsAttr_t *pAttr) dmConnId_t connId,
{ uint16_t handle,
uint8_t operation,
uint16_t offset,
attsAttr_t *pAttr
) {
printf("read callback\n"); printf("read callback\n");
return ATT_SUCCESS; return ATT_SUCCESS;
} }
static uint8_t UARTWriteCback(dmConnId_t connId, uint16_t handle, uint8_t operation, static uint8_t UARTWriteCback(
uint16_t offset, uint16_t len, uint8_t *pValue, dmConnId_t connId,
attsAttr_t *pAttr) uint16_t handle,
{ uint8_t operation,
uint16_t offset,
uint16_t len,
uint8_t *pValue,
attsAttr_t *pAttr
) {
active_connection = connId; active_connection = connId;
//printf("UARTWriteCback %d: ", len); //printf("UARTWriteCback %d: ", len);
...@@ -126,9 +132,14 @@ void ble_uart_write(uint8_t *pValue, uint8_t len) ...@@ -126,9 +132,14 @@ void ble_uart_write(uint8_t *pValue, uint8_t len)
ble_uart_buf_tx_fill++; ble_uart_buf_tx_fill++;
} else if (pValue[i] == '\r' || pValue[i] == '\n') { } else if (pValue[i] == '\r' || pValue[i] == '\n') {
if (ble_uart_buf_tx_fill > 0) { if (ble_uart_buf_tx_fill > 0) {
AttsSetAttr(UART_TX_HDL, ble_uart_buf_tx_fill, ble_uart_tx_buf); AttsSetAttr(
UART_TX_HDL,
ble_uart_buf_tx_fill,
ble_uart_tx_buf
);
if (active_connection) { if (active_connection) {
int x = xTaskGetTickCount() - ble_uart_lasttick; int x = xTaskGetTickCount() -
ble_uart_lasttick;
if (x < 100) { if (x < 100) {
// Ugly hack if we already send something recently. // Ugly hack if we already send something recently.
// TODO: figure out how fast we can send or use indications // TODO: figure out how fast we can send or use indications
...@@ -140,7 +151,12 @@ void ble_uart_write(uint8_t *pValue, uint8_t len) ...@@ -140,7 +151,12 @@ void ble_uart_write(uint8_t *pValue, uint8_t len)
// printf("%02x ", ble_uart_tx_buf[j]); // printf("%02x ", ble_uart_tx_buf[j]);
//} //}
//printf("\n"); //printf("\n");
AttsHandleValueNtf(active_connection, UART_TX_HDL, ble_uart_buf_tx_fill, ble_uart_tx_buf); AttsHandleValueNtf(
active_connection,
UART_TX_HDL,
ble_uart_buf_tx_fill,
ble_uart_tx_buf
);
ble_uart_lasttick = xTaskGetTickCount(); ble_uart_lasttick = xTaskGetTickCount();
} }
ble_uart_buf_tx_fill = 0; ble_uart_buf_tx_fill = 0;
...@@ -157,4 +173,3 @@ void bleuart_init(void) ...@@ -157,4 +173,3 @@ void bleuart_init(void)
AttsDynRegister(pSHdl, UARTReadCback, UARTWriteCback); AttsDynRegister(pSHdl, UARTReadCback, UARTWriteCback);
//AttsDynRegister(pSHdl, NULL, UARTWriteCback); //AttsDynRegister(pSHdl, NULL, UARTWriteCback);
} }
...@@ -112,9 +112,8 @@ int main(void) ...@@ -112,9 +112,8 @@ int main(void)
configMINIMAL_STACK_SIZE * 10, configMINIMAL_STACK_SIZE * 10,
NULL, NULL,
tskIDLE_PRIORITY + 1, tskIDLE_PRIORITY + 1,
NULL NULL) != pdPASS) {
) != pdPASS) { LOG_CRIT("startup", "Failed to create %s task!", "BLE");
printf("Failed to create BLE task!\n");
abort(); abort();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment