Merge branch 'master' into develop

This commit is contained in:
hathach committed 2020-03-12 21:38:52 +07:00
commit fd0b115f42
111 files changed
+41426 -15297

No files matched your search

+2 -3
View File
@@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
arduino-platform: ['feather52832', 'feather52840', 'feather52840sense', 'cplaynrf52840', 'itsybitsy52840', 'cluenrf52840' ]
arduino-platform: ['cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840']
runs-on: ubuntu-latest
@@ -52,8 +52,7 @@ jobs:
rm -r $HOME/$BSP_PATH/*
ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION
# Install library dependency
arduino-cli lib install "Adafruit GFX Library" "Adafruit SSD1306" "Adafruit ILI9341" "Adafruit HX8357 Library" "Adafruit EPD"
arduino-cli lib install "Adafruit nRFCrypto" "Adafruit Circuit Playground" "Adafruit NeoPixel" "Adafruit NeoMatrix" "MIDI Library" "Firmata"
arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit nRFCrypto" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "Firmata" "MIDI Library" "SdFat - Adafruit Fork"
- name: Build examples
run: python3 tools/build_all.py ${{ matrix.arduino-platform }}
+4
View File
@@ -16,3 +16,7 @@
.DS_Store
*.swp
/Output
# Ignore local overrides of platform.txt and boards.txt,
/boards.local.txt
/platform.local.txt
+3 -2
View File
@@ -4,17 +4,18 @@
This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series:
- Adafruit CLUE nRF52840
- [Adafruit CLUE nRF52840](https://www.adafruit.com/product/4500)
- [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333)
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
- Adafruit Feather nRF52840 Sense
- [Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
- [Adafruit ItsyBitsy nRF52840 Express](https://www.adafruit.com/product/4481)
- Adafruit Metro nRF52840 Express
Following boards are also included but are not officially supported:
- [Nordic nRF52840DK PCA10056](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK)
- [Particle Xenon](https://store.particle.io/products/xenon)
## BSP Installation
+79 -15
View File
@@ -40,11 +40,13 @@ feather52832.build.f_cpu=64000000
feather52832.build.board=NRF52832_FEATHER
feather52832.build.core=nRF5
feather52832.build.variant=feather_nrf52832
feather52840.build.usb_manufacturer="Adafruit LLC"
feather52840.build.usb_product="Feather nRF52832"
feather52832.build.extra_flags=-DNRF52832_XXAA -DNRF52
feather52832.build.ldscript=nrf52832_s132_v6.ld
# SofDevice Menu
feather52832.menu.softdevice.s132v6=0.3.0 SoftDevice s132 6.1.1
feather52832.menu.softdevice.s132v6=0.3.2 SoftDevice s132 6.1.1
feather52832.menu.softdevice.s132v6.build.sd_name=s132
feather52832.menu.softdevice.s132v6.build.sd_version=6.1.1
feather52832.menu.softdevice.s132v6.build.sd_fwid=0x00B7
@@ -97,7 +99,7 @@ feather52840.build.vid=0x239A
feather52840.build.pid=0x8029
# SofDevice Menu
feather52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
feather52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
feather52840.menu.softdevice.s140v6.build.sd_name=s140
feather52840.menu.softdevice.s140v6.build.sd_version=6.1.1
feather52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -144,14 +146,14 @@ feather52840sense.build.board=NRF52840_FEATHER_SENSE
feather52840sense.build.core=nRF5
feather52840sense.build.variant=feather_nrf52840_sense
feather52840sense.build.usb_manufacturer="Adafruit LLC"
feather52840sense.build.usb_product="Feather Bluefruit Sense"
feather52840sense.build.usb_product="Feather nRF52840 Sense"
feather52840sense.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
feather52840sense.build.ldscript=nrf52840_s140_v6.ld
feather52840sense.build.vid=0x239A
feather52840sense.build.pid=0x8087
# SofDevice Menu
feather52840sense.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
feather52840sense.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
feather52840sense.menu.softdevice.s140v6.build.sd_name=s140
feather52840sense.menu.softdevice.s140v6.build.sd_version=6.1.1
feather52840sense.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -167,9 +169,9 @@ feather52840sense.menu.debug.l3=Level 3 (Segger SystemView)
feather52840sense.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
# ----------------------------------
# ---------------------------------------------
# Bluefruit ItsyBitsy nRF52840 Express
# ----------------------------------
# ---------------------------------------------
itsybitsy52840.name=Adafruit ItsyBitsy nRF52840 Express
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
@@ -251,14 +253,14 @@ cplaynrf52840.build.board=NRF52840_CIRCUITPLAY
cplaynrf52840.build.core=nRF5
cplaynrf52840.build.variant=circuitplayground_nrf52840
cplaynrf52840.build.usb_manufacturer="Adafruit LLC"
cplaynrf52840.build.usb_product="Adafruit Circuit Playground Bluefruit"
cplaynrf52840.build.usb_product="Circuit Playground Bluefruit"
cplaynrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
cplaynrf52840.build.ldscript=nrf52840_s140_v6.ld
cplaynrf52840.build.vid=0x239A
cplaynrf52840.build.pid=0x8045
# SofDevice Menu
cplaynrf52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
cplaynrf52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
cplaynrf52840.menu.softdevice.s140v6.build.sd_name=s140
cplaynrf52840.menu.softdevice.s140v6.build.sd_version=6.1.1
cplaynrf52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -305,14 +307,14 @@ cluenrf52840.build.board=NRF52840_CLUE
cluenrf52840.build.core=nRF5
cluenrf52840.build.variant=clue_nrf52840
cluenrf52840.build.usb_manufacturer="Adafruit LLC"
cluenrf52840.build.usb_product="Adafruit Clue"
cluenrf52840.build.usb_product="CLUE"
cluenrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
cluenrf52840.build.ldscript=nrf52840_s140_v6.ld
cluenrf52840.build.vid=0x239A
cluenrf52840.build.pid=0x8071
# SofDevice Menu
cluenrf52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
cluenrf52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
cluenrf52840.menu.softdevice.s140v6.build.sd_name=s140
cluenrf52840.menu.softdevice.s140v6.build.sd_version=6.1.1
cluenrf52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -365,7 +367,7 @@ metro52840.build.vid=0x239A
metro52840.build.pid=0x803F
# SofDevice Menu
metro52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
metro52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
metro52840.menu.softdevice.s140v6.build.sd_name=s140
metro52840.menu.softdevice.s140v6.build.sd_version=6.1.1
metro52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -380,6 +382,16 @@ metro52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
metro52840.menu.debug.l3=Level 3 (Segger SystemView)
metro52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
# -------------------------------------------------------
#
# Boards that aren't made by Adafruit
#
# -------------------------------------------------------
# ----------------------------------
# Nordic nRF52840DK (PCA10056)
# ----------------------------------
@@ -408,7 +420,7 @@ pca10056.build.vid=0x239A
pca10056.build.pid=0x8029
# SofDevice Menu
pca10056.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
pca10056.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
pca10056.menu.softdevice.s140v6.build.sd_name=s140
pca10056.menu.softdevice.s140v6.build.sd_version=6.1.1
pca10056.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -424,7 +436,60 @@ pca10056.menu.debug.l3=Level 3 (Segger SystemView)
pca10056.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
# ----------------------------------
# Raytac MDBT50Q – RX
# Particle Xenon
# ----------------------------------
particle_xenon.name=Particle Xenon
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
particle_xenon.vid.0=0x239A
particle_xenon.pid.0=0x8029
particle_xenon.vid.1=0x239A
particle_xenon.pid.1=0x0029
particle_xenon.vid.2=0x239A
particle_xenon.pid.2=0x002A
particle_xenon.vid.3=0x239A
particle_xenon.pid.3=0x802A
# Upload
particle_xenon.bootloader.tool=bootburn
particle_xenon.upload.tool=nrfutil
particle_xenon.upload.protocol=nrfutil
particle_xenon.upload.use_1200bps_touch=true
particle_xenon.upload.wait_for_upload_port=true
particle_xenon.upload.maximum_size=815104
particle_xenon.upload.maximum_data_size=248832
# Build
particle_xenon.build.mcu=cortex-m4
particle_xenon.build.f_cpu=64000000
particle_xenon.build.board=PARTICLE_XENON
particle_xenon.build.core=nRF5
particle_xenon.build.variant=particle_xenon
particle_xenon.build.usb_manufacturer="Particle Industries"
particle_xenon.build.usb_product="Particle Xenon"
particle_xenon.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
particle_xenon.build.ldscript=nrf52840_s140_v6.ld
particle_xenon.build.vid=0x239A
particle_xenon.build.pid=0x8029
# SofDevice Menu
particle_xenon.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
particle_xenon.menu.softdevice.s140v6.build.sd_name=s140
particle_xenon.menu.softdevice.s140v6.build.sd_version=6.1.1
particle_xenon.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
particle_xenon.menu.debug.l0=Level 0 (Release)
particle_xenon.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
particle_xenon.menu.debug.l1=Level 1 (Error Message)
particle_xenon.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
particle_xenon.menu.debug.l2=Level 2 (Full Debug)
particle_xenon.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
particle_xenon.menu.debug.l3=Level 3 (Segger SystemView)
particle_xenon.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
# ----------------------------------
# Raytac MDBT50Q - RX
# ----------------------------------
mdbt50qrx.name=Raytac MDBT50Q-RX Dongle
@@ -461,7 +526,7 @@ mdbt50qrx.build.vid=0x239A
mdbt50qrx.build.pid=0x8029
# SofDevice Menu
mdbt50qrx.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
mdbt50qrx.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
mdbt50qrx.menu.softdevice.s140v6.build.sd_name=s140
mdbt50qrx.menu.softdevice.s140v6.build.sd_version=6.1.1
mdbt50qrx.menu.softdevice.s140v6.build.sd_fwid=0x00B6
@@ -475,4 +540,3 @@ mdbt50qrx.menu.debug.l2=Level 2 (Full Debug)
mdbt50qrx.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
mdbt50qrx.menu.debug.l3=Level 3 (Segger SystemView)
mdbt50qrx.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
+28
View File
@@ -1,5 +1,33 @@
# Adafruit nRF52 Arduino Core Changelog
## 0.19.0 - 2020.03.12
- Add BLECharacteristic::isFixedLen()
- Enhance and add new Playground sensor services
- Quaternion
- Sound
- Color
- Proximity
- Gesture
- Fix sporadic hangup when stopping notifies, thanks to @FariSoftware PR #444
- Rename image_upload sketch to image_transfer
- Update bluefruit_playground sketch to work with CPB, CLUE and Sense
- Upgrade SystemView to v3.10, thanks to @henrygab PR #437
- Fix D13 LED_BUILTIN for Feather Sense
- Skip waiting for Serial in some examples, force wait for Serial when Debug is enabled
- Update bootloader binary from 0.3.0 to 0.3.2
## 0.18.5 - 2020.02.19
- Add macro `SPI_32MHZ_INTERFACE` to variant to select SPI or SPI1 to use 32mhz SPIM3
- Add PIN_BUZZER to variants with built-in speaker
- Enhance Particle Xenon support, PR #435 thanks to @outlandnish and @jaswope
- Rename cplay_ble.ino to bluefruit_playground.ino
- Use USB_PRODUCT string for default bledis model
- Increase attr table size for 840 to from 0xC00 to 0x1000
- Add more Adafruit sensor service: Gyro, Magento, Humid, Baro
- Upadte `image_upload.ino` to support CLUE with built-in TFT
## 0.18.0 - 2020.02.03
- Add EXTERNAL_FLASH_USE_QSPI to all variants that has on-board flash
+1 -1
View File
@@ -225,7 +225,7 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
do
{
size_t remaining = size - sent;
size_t txSize = min(remaining, SERIAL_BUFFER_SIZE);
size_t txSize = min(remaining, (size_t)SERIAL_BUFFER_SIZE);
xSemaphoreTake(_mutex, portMAX_DELAY);
+1
View File
@@ -145,6 +145,7 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
#define PRTNT_HEAP() if (CFG_DEBUG == 3) PRINTF("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\n" , __FUNCTION__, __LINE__, (float) (x) )
#define PRINT_HEX(x) \
do {\
@@ -156,6 +156,10 @@ extern "C" {
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#endif
#ifndef INCLUDE_pxTaskGetStackStart
#define INCLUDE_pxTaskGetStackStart 0
#endif
#ifndef INCLUDE_eTaskGetState
#define INCLUDE_eTaskGetState 0
#endif
@@ -392,6 +396,22 @@ extern "C" {
#define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )
#endif
#ifndef traceREADDED_TASK_TO_READY_STATE
#define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB )
#endif
#ifndef traceMOVED_TASK_TO_DELAYED_LIST
#define traceMOVED_TASK_TO_DELAYED_LIST()
#endif
#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST
#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST()
#endif
#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST
#define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB )
#endif
#ifndef traceQUEUE_CREATE
#define traceQUEUE_CREATE( pxNewQueue )
#endif
@@ -636,6 +656,18 @@ extern "C" {
#define traceTASK_NOTIFY_GIVE_FROM_ISR()
#endif
#ifndef traceISR_EXIT_TO_SCHEDULER
#define traceISR_EXIT_TO_SCHEDULER()
#endif
#ifndef traceISR_EXIT
#define traceISR_EXIT()
#endif
#ifndef traceISR_ENTER
#define traceISR_ENTER()
#endif
#ifndef traceSTREAM_BUFFER_CREATE_FAILED
#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )
#endif
+19
View File
@@ -1421,6 +1421,25 @@ TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*
*/
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
/**
* task.h
* <PRE>uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);</PRE>
*
* INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for
* this function to be available.
*
* Returns the start of the stack associated with xTask. That is,
* the highest stack memory address on architectures where the stack grows down
* from high memory, and the lowest memory address on architectures where the
* stack grows up from low memory.
*
* @param xTask Handle of the task associated with the stack returned.
* Set xTask to NULL to return the stack of the calling task.
*
* @return A pointer to the start of the stack.
*/
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION;
/* When using trace macros it is sometimes necessary to include task.h before
FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
so the following two prototypes will cause a compilation error. This can be
+36 -3
View File
@@ -239,6 +239,19 @@ count overflows. */
tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )
/*-----------------------------------------------------------*/
/*
* Place the task represented by pxTCB which has been in a ready list before
* into the appropriate ready list for the task.
* It is inserted at the end of the list.
*/
#define prvReaddTaskToReadyList( pxTCB ) \
traceREADDED_TASK_TO_READY_STATE( pxTCB ); \
taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \
vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \
tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )
/*-----------------------------------------------------------*/
/*
* Several functions take an TaskHandle_t parameter that can optionally be NULL,
* where NULL is used to indicate that the handle of the currently executing
@@ -1598,7 +1611,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
{
mtCOVERAGE_TEST_MARKER();
}
prvAddTaskToReadyList( pxTCB );
prvReaddTaskToReadyList( pxTCB );
}
else
{
@@ -1660,6 +1673,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
mtCOVERAGE_TEST_MARKER();
}
traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB);
vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) );
#if( configUSE_TASK_NOTIFICATIONS == 1 )
@@ -3671,6 +3685,20 @@ static void prvCheckTasksWaitingTermination( void )
#endif /* INCLUDE_uxTaskGetStackHighWaterMark */
/*-----------------------------------------------------------*/
#if (INCLUDE_pxTaskGetStackStart == 1)
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask)
{
TCB_t *pxTCB;
UBaseType_t uxReturn;
(void)uxReturn;
pxTCB = prvGetTCBFromHandle( xTask );
return ( uint8_t * ) pxTCB->pxStack;
}
#endif /* INCLUDE_pxTaskGetStackStart */
/*-----------------------------------------------------------*/
#if ( INCLUDE_vTaskDelete == 1 )
static void prvDeleteTCB( TCB_t *pxTCB )
@@ -3840,7 +3868,7 @@ TCB_t *pxTCB;
/* Inherit the priority before being moved into the new list. */
pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;
prvAddTaskToReadyList( pxMutexHolderTCB );
prvReaddTaskToReadyList( pxMutexHolderTCB );
}
else
{
@@ -3930,7 +3958,7 @@ TCB_t *pxTCB;
any other purpose if this task is running, and it must be
running to give back the mutex. */
listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
prvAddTaskToReadyList( pxTCB );
prvReaddTaskToReadyList( pxTCB );
/* Return true to indicate that a context switch is required.
This is only actually required in the corner case whereby
@@ -4943,6 +4971,7 @@ const TickType_t xConstTickCount = xTickCount;
/* Add the task to the suspended task list instead of a delayed task
list to ensure it is not woken by a timing event. It will block
indefinitely. */
traceMOVED_TASK_TO_SUSPENDED_LIST(pxCurrentTCB);
vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) );
}
else
@@ -4959,12 +4988,14 @@ const TickType_t xConstTickCount = xTickCount;
{
/* Wake time has overflowed. Place this item in the overflow
list. */
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
}
else
{
/* The wake time has not overflowed, so the current block list
is used. */
traceMOVED_TASK_TO_DELAYED_LIST();
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
/* If the task entering the blocked state was placed at the
@@ -4994,11 +5025,13 @@ const TickType_t xConstTickCount = xTickCount;
if( xTimeToWake < xConstTickCount )
{
/* Wake time has overflowed. Place this item in the overflow list. */
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
}
else
{
/* The wake time has not overflowed, so the current block list is used. */
traceMOVED_TASK_TO_DELAYED_LIST();
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
/* If the task entering the blocked state was placed at the head of the
@@ -54,6 +54,7 @@
void xPortSysTickHandler( void )
{
traceISR_ENTER();
#if configUSE_TICKLESS_IDLE == 1
nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0);
#endif
@@ -89,11 +90,16 @@ void xPortSysTickHandler( void )
/* Increment the RTOS tick as usual which checks if there is a need for rescheduling */
if ( switch_req != pdFALSE )
{
traceISR_EXIT_TO_SCHEDULER();
/* A context switch is required. Context switching is performed in
the PendSV interrupt. Pend the PendSV interrupt. */
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
__SEV();
}
else
{
traceISR_EXIT();
}
portCLEAR_INTERRUPT_MASK_FROM_ISR( isrstate );
}
@@ -97,7 +97,14 @@ typedef unsigned long UBaseType_t;
__ISB(); \
}while (0)
#define portEND_SWITCHING_ISR( xSwitchRequired ) if ( (xSwitchRequired) != pdFALSE ) portYIELD()
#define portEND_SWITCHING_ISR( xSwitchRequired ) do { \
if( xSwitchRequired != pdFALSE ) { \
traceISR_EXIT_TO_SCHEDULER(); \
portYIELD(); \
} else { \
traceISR_EXIT(); \
} \
} while (0)
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
/*-----------------------------------------------------------*/
+10 -4
View File
@@ -44,13 +44,19 @@ static void loop_task(void* arg)
{
(void) arg;
#if CFG_DEBUG
// If Serial is not begin(), call it to avoid hard fault
Serial.begin(115200);
// Wait for Serial connection in debug mode
while ( !Serial ) yield();
dbgPrintVersion();
#endif
setup();
#if CFG_DEBUG
// If Serial is not begin(), call it to avoid hard fault
if ( !Serial ) Serial.begin(115200);
dbgPrintVersion();
// dbgMemInfo();
Bluefruit_printInfo();
#endif
+7 -24
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,17 +42,10 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
----------------------------------------------------------------------
File : Global.h
Purpose : Global types
In case your application already has a Global.h, you should
merge the files. In order to use Segger code, the types
U8, U16, U32, I8, I16, I32 need to be defined in Global.h;
additional definitions do not hurt.
---------------------------END-OF-HEADER------------------------------
-------------------------- END-OF-HEADER -----------------------------
*/
#ifndef GLOBAL_H // Guard against multiple inclusion
+70 -38
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,7 +42,7 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
@@ -60,7 +50,7 @@ File : SEGGER_RTT_Conf.h
Purpose : Implementation of SEGGER real-time transfer (RTT) which
allows real-time communication on targets which support
debugger memory accesses while the CPU is running.
Revision: $Rev: 12706 $
Revision: $Rev: 17066 $
*/
@@ -77,18 +67,31 @@ Revision: $Rev: 12706 $
*
**********************************************************************
*/
#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
#endif
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
#endif
#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
#ifndef BUFFER_SIZE_UP
#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
#endif
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
#ifndef BUFFER_SIZE_DOWN
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
#endif
#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
#endif
#define USE_RTT_ASM (0) // Use assembler version of SEGGER_RTT.c when 1
#ifndef SEGGER_RTT_MODE_DEFAULT
#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
#endif
#define RTT_USE_ASM (0) // defaults to 1, results in link error ... undefined references to `SEGGER_RTT_ASM_WriteSkipNoLock`
/*********************************************************************
*
@@ -102,7 +105,9 @@ Revision: $Rev: 12706 $
* This is may be required with memory access restrictions,
* such as on Cortex-A devices with MMU.
*/
#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
#ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP
#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
#endif
//
// Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
//
@@ -124,20 +129,21 @@ Revision: $Rev: 12706 $
// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
// or define SEGGER_RTT_LOCK() to completely disable interrupts.
//
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (2 << 5) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
#endif
/*********************************************************************
*
* RTT lock configuration for SEGGER Embedded Studio,
* Rowley CrossStudio and GCC
*/
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
#if (defined __ARM_ARCH_6M__) || (defined __ARM_ARCH_8M_BASE__)
#if (defined(__SES_ARM) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM)
#if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
__asm volatile ("mrs %0, primask \n\t" \
"mov r1, $1 \n\t" \
"movs r1, $1 \n\t" \
"msr primask, r1 \n\t" \
: "=r" (LockState) \
: \
@@ -150,8 +156,7 @@ Revision: $Rev: 12706 $
: \
); \
}
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
@@ -195,9 +200,6 @@ Revision: $Rev: 12706 $
: "r0", "r1" \
); \
}
#else
#define SEGGER_RTT_LOCK()
#define SEGGER_RTT_UNLOCK()
#endif
#endif
@@ -308,14 +310,44 @@ Revision: $Rev: 12706 $
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
LockState = OS_GetBASEPRI(); \
OS_SetBASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
#define SEGGER_RTT_UNLOCK() OS_SetBASEPRI(LockState); \
#define SEGGER_RTT_UNLOCK() _set_interrupt_priority(LockState); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for CCRX
*/
#ifdef __RX
#define SEGGER_RTT_LOCK() { \
unsigned long LockState; \
LockState = get_psw() & 0x010000; \
clrpsw_i();
#define SEGGER_RTT_UNLOCK() set_psw(get_psw() | LockState); \
}
#endif
/*********************************************************************
*
* RTT lock configuration for embOS Simulation on Windows
* (Can also be used for generic RTT locking with embOS)
*/
#if defined(WIN32) || defined(SEGGER_RTT_LOCK_EMBOS)
void OS_SIM_EnterCriticalSection(void);
void OS_SIM_LeaveCriticalSection(void);
#define SEGGER_RTT_LOCK() { \
OS_SIM_EnterCriticalSection();
#define SEGGER_RTT_UNLOCK() OS_SIM_LeaveCriticalSection(); \
}
#endif
/*********************************************************************
*
* RTT lock configuration fallback
+61 -42
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,14 +42,14 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW_Conf.h
Purpose : SEGGER SystemView configuration.
Revision: $Rev: 12706 $
Revision: $Rev: 17066 $
*/
#ifndef SEGGER_SYSVIEW_CONF_H
@@ -82,13 +72,17 @@ Revision: $Rev: 12706 $
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__)
#if (defined __ARM_ARCH_6M__) || (defined __ARM_ARCH_8M_BASE__)
#define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
#define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
#endif
#elif defined(__ICCARM__)
#if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
#if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) \
|| (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__))
#define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0
#elif ((defined (__ARM7M__) && (__CORE__ == __ARM7M__)) || (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)))
#elif (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) \
|| (defined (__ARM7M__) && (__CORE__ == __ARM7M__)) \
|| (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) \
|| (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__))
#define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
#endif
#elif defined(__CC_ARM)
@@ -113,6 +107,10 @@ Revision: $Rev: 12706 $
#define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_OTHER
#endif
#ifndef SEGGER_SYSVIEW_ON_EVENT_RECORDED
#define SEGGER_SYSVIEW_ON_EVENT_RECORDED(NumBytes) // Needed for SystemView via non-J-Link Recorder. Macro to enable the UART or notify IP task.
#endif
/*********************************************************************
*
* Defines, configurable
@@ -123,50 +121,71 @@ Revision: $Rev: 12706 $
*
* SystemView buffer configuration
*/
#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE 1024 // Number of bytes that SystemView uses for the buffer.
#define SEGGER_SYSVIEW_RTT_CHANNEL 1 // The RTT channel that SystemView will use. 0: Auto selection
#ifndef SEGGER_SYSVIEW_RTT_BUFFER_SIZE
#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE 1024 // Number of bytes that SystemView uses for the buffer.
#endif
#define SEGGER_SYSVIEW_USE_STATIC_BUFFER 1 // Use a static buffer to generate events instead of a buffer on the stack
#ifndef SEGGER_SYSVIEW_RTT_CHANNEL
#define SEGGER_SYSVIEW_RTT_CHANNEL 1 // The RTT channel that SystemView will use. 0: Auto selection
#endif
#define SEGGER_SYSVIEW_POST_MORTEM_MODE 0 // 1: Enable post mortem analysis mode
#ifndef SEGGER_SYSVIEW_USE_STATIC_BUFFER
#define SEGGER_SYSVIEW_USE_STATIC_BUFFER 1 // Use a static buffer to generate events instead of a buffer on the stack
#endif
#ifndef SEGGER_SYSVIEW_POST_MORTEM_MODE
#define SEGGER_SYSVIEW_POST_MORTEM_MODE 0 // 1: Enable post mortem analysis mode
#endif
#ifndef SEGGER_SYSVIEW_CAN_RESTART
#define SEGGER_SYSVIEW_CAN_RESTART 1 // 1: Send the SystemView start sequence on every start command, not just on the first. Enables restart when SystemView Application disconnected unexpectedly.
#endif
/*********************************************************************
*
* SystemView timestamp configuration
*/
#if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3
#define SEGGER_SYSVIEW_GET_TIMESTAMP() (*(U32 *)(0xE0001004)) // Retrieve a system timestamp. Cortex-M cycle counter.
#define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by clock source
#else
#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() // Retrieve a system timestamp via user-defined function
#define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp()
#if !defined(SEGGER_SYSVIEW_GET_TIMESTAMP) && !defined(SEGGER_SYSVIEW_TIMESTAMP_BITS)
#if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3
#define SEGGER_SYSVIEW_GET_TIMESTAMP() (*(U32 *)(0xE0001004)) // Retrieve a system timestamp. Cortex-M cycle counter.
#define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by clock source
#else
#define SEGGER_SYSVIEW_GET_TIMESTAMP() SEGGER_SYSVIEW_X_GetTimestamp() // Retrieve a system timestamp via user-defined function
#define SEGGER_SYSVIEW_TIMESTAMP_BITS 32 // Define number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp()
#endif
#endif
/*********************************************************************
*
* SystemView Id configuration
*/
#define SEGGER_SYSVIEW_ID_BASE 0x10000000 // Default value for the lowest Id reported by the application. Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase(). (i.e. 0x20000000 when all Ids are an address in this RAM)
#define SEGGER_SYSVIEW_ID_SHIFT 2 // Number of bits to shift the Id to save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
#ifndef SEGGER_SYSVIEW_ID_BASE
#define SEGGER_SYSVIEW_ID_BASE 0x10000000 // Default value for the lowest Id reported by the application. Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase(). (i.e. 0x20000000 when all Ids are an address in this RAM)
#endif
#ifndef SEGGER_SYSVIEW_ID_SHIFT
#define SEGGER_SYSVIEW_ID_SHIFT 2 // Number of bits to shift the Id to save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
#endif
/*********************************************************************
*
* SystemView interrupt configuration
*/
#if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32 *)(0xE000ED04)) & 0x1FF) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[8:0] = active vector)
#elif SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM0
#if defined(__ICCARM__)
#if (__VER__ > 6100000)
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() (__get_IPSR()) // Workaround for IAR, which might do a byte-access to 0xE000ED04. Read IPSR instead.
#ifndef SEGGER_SYSVIEW_GET_INTERRUPT_ID
#if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x1FF) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[8:0] = active vector)
#elif SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM0
#if defined(__ICCARM__)
#if (__VER__ > 6010000)
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() (__get_IPSR()) // Workaround for IAR, which might do a byte-access to 0xE000ED04. Read IPSR instead.
#else
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x3F) // Older versions of IAR do not include __get_IPSR, but might also not optimize to byte-access.
#endif
#else
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32 *)(0xE000ED04)) & 0x3F) // Older versions of IAR do not include __get_IPSR, but might also not optimize to byte-access.
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x3F) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[5:0] = active vector)
#endif
#else
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32 *)(0xE000ED04)) & 0x3F) // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[5:0] = active vector)
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() // Get the currently active interrupt Id from the user-provided function.
#endif
#else
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID() SEGGER_SYSVIEW_X_GetInterruptId() // Get the currently active interrupt Id from the user-provided function.
#endif
#endif // SEGGER_SYSVIEW_CONF_H
@@ -1,9 +1,50 @@
/*********************************************************************
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
* *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER SystemView * Real-time application analysis *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 SEGGER Microcontroller 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. *
* *
**********************************************************************
* *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW_Config_FreeRTOS.c
+62 -43
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,19 +42,20 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
----------------------------------------------------------------------
File : SEGGER.h
Purpose : Global types etc & general purpose utility functions
Revision: $Rev: 18102 $
---------------------------END-OF-HEADER------------------------------
*/
#ifndef SEGGER_H // Guard against multiple inclusion
#define SEGGER_H
#include <stdarg.h>
#include <stdarg.h> // For va_list.
#include "Global.h" // Type definitions: U8, U16, U32, I8, I16, I32
#if defined(__cplusplus)
@@ -79,16 +70,21 @@ extern "C" { /* Make sure we have C-declarations in C++ programs */
*/
#ifndef INLINE
#ifdef _WIN32
#if (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__))
//
// Microsoft VC6 and newer.
// Force inlining without cost checking.
// Other known compilers.
//
#define INLINE __forceinline
#define INLINE inline
#else
#if (defined(__GNUC__))
#if (defined(_WIN32) && !defined(__clang__))
//
// Force inlining with GCC
// Microsoft VC6 and newer.
// Force inlining without cost checking.
//
#define INLINE __forceinline
#elif defined(__GNUC__) || defined(__clang__)
//
// Force inlining with GCC + clang
//
#define INLINE inline __attribute__((always_inline))
#elif (defined(__CC_ARM))
@@ -96,11 +92,6 @@ extern "C" { /* Make sure we have C-declarations in C++ programs */
// Force inlining with ARMCC (Keil)
//
#define INLINE __inline
#elif (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__))
//
// Other known compilers.
//
#define INLINE inline
#else
//
// Unknown compilers.
@@ -125,6 +116,11 @@ extern "C" { /* Make sure we have C-declarations in C++ programs */
#define SEGGER_USE_PARA(Para) (void)Para // This works for most compilers.
#endif
#define SEGGER_ADDR2PTR(Type, Addr) (/*lint -e(923) -e(9078)*/((Type*)((PTR_ADDR)(Addr)))) // Allow cast from address to pointer.
#define SEGGER_PTR2ADDR(p) (/*lint -e(923) -e(9078)*/((PTR_ADDR)(p))) // Allow cast from pointer to address.
#define SEGGER_PTR2PTR(Type, p) (/*lint -e(740) -e(826) -e(9079) -e(9087)*/((Type*)(p))) // Allow cast from one pointer type to another (ignore different size).
#define SEGGER_PTR_DISTANCE(p0, p1) (SEGGER_PTR2ADDR(p0) - SEGGER_PTR2ADDR(p1))
/*********************************************************************
*
* Defines
@@ -153,10 +149,10 @@ typedef struct {
} SEGGER_BUFFER_DESC;
typedef struct {
int CacheLineSize; // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size.
void (*pfDMB) (void); // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed.
void (*pfClean) (void *p, unsigned NumBytes); // Optional clean function for cached memory.
void (*pfInvalidate)(void *p, unsigned NumBytes); // Optional invalidate function for cached memory.
unsigned int CacheLineSize; // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size.
void (*pfDMB) (void); // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed.
void (*pfClean) (void *p, unsigned long NumBytes); // Optional clean function for cached memory.
void (*pfInvalidate)(void *p, unsigned long NumBytes); // Optional invalidate function for cached memory.
} SEGGER_CACHE_CONFIG;
typedef struct SEGGER_SNPRINTF_CONTEXT_struct SEGGER_SNPRINTF_CONTEXT;
@@ -181,6 +177,11 @@ typedef struct SEGGER_PRINTF_FORMATTER {
char Specifier; // Format specifier.
} SEGGER_PRINTF_FORMATTER;
typedef struct {
U32 (*pfGetHPTimestamp)(void); // Mandatory, pfGetHPTimestamp
int (*pfGetUID) (U8 abUID[16]); // Optional, pfGetUID
} SEGGER_BSP_API;
/*********************************************************************
*
* Utility functions
@@ -192,18 +193,19 @@ typedef struct SEGGER_PRINTF_FORMATTER {
// Memory operations.
//
void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes);
void SEGGER_memcpy (void* pDest, const void* pSrc, int NumBytes);
void SEGGER_memcpy (void* pDest, const void* pSrc, unsigned NumBytes);
void SEGGER_memxor (void* pDest, const void* pSrc, unsigned NumBytes);
//
// String functions.
//
int SEGGER_atoi (const char* s);
int SEGGER_isalnum (int c);
int SEGGER_isalpha (int c);
unsigned SEGGER_strlen (const char* s);
int SEGGER_tolower (int c);
int SEGGER_strcasecmp(const char* sText1, const char* sText2);
int SEGGER_atoi (const char* s);
int SEGGER_isalnum (int c);
int SEGGER_isalpha (int c);
unsigned SEGGER_strlen (const char* s);
int SEGGER_tolower (int c);
int SEGGER_strcasecmp (const char* sText1, const char* sText2);
int SEGGER_strncasecmp(const char *sText1, const char *sText2, unsigned Count);
//
// Buffer/printf related.
@@ -215,10 +217,27 @@ int SEGGER_snprintf (char* pBuffer, int BufferSize, const char* sFormat, ..
int SEGGER_vsnprintf (char* pBuffer, int BufferSize, const char* sFormat, va_list ParamList);
int SEGGER_vsnprintfEx (SEGGER_SNPRINTF_CONTEXT* pContext, const char* sFormat, va_list ParamList);
int SEGGER_PRINTF_AddFormatter (SEGGER_PRINTF_FORMATTER* pFormatter, SEGGER_pFormatter pfFormatter, char c);
void SEGGER_PRINTF_AddDoubleFormatter(void);
void SEGGER_PRINTF_AddIPFormatter (void);
void SEGGER_PRINTF_AddHTMLFormatter (void);
int SEGGER_PRINTF_AddFormatter (SEGGER_PRINTF_FORMATTER* pFormatter, SEGGER_pFormatter pfFormatter, char c);
void SEGGER_PRINTF_AddDoubleFormatter (void);
void SEGGER_PRINTF_AddIPFormatter (void);
void SEGGER_PRINTF_AddBLUEFormatter (void);
void SEGGER_PRINTF_AddCONNECTFormatter(void);
void SEGGER_PRINTF_AddSSLFormatter (void);
void SEGGER_PRINTF_AddSSHFormatter (void);
void SEGGER_PRINTF_AddHTMLFormatter (void);
//
// BSP abstraction API.
//
int SEGGER_BSP_GetUID (U8 abUID[16]);
int SEGGER_BSP_GetUID32(U32* pUID);
void SEGGER_BSP_SetAPI (const SEGGER_BSP_API* pAPI);
void SEGGER_BSP_SeedUID (void);
//
// Other API.
//
void SEGGER_VERSION_GetString(char acText[8], unsigned Version);
#if defined(__cplusplus)
} /* Make sure we have C-declarations in C++ programs */
+364 -120
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,7 +42,7 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
@@ -60,7 +50,7 @@ File : SEGGER_RTT.c
Purpose : Implementation of SEGGER real-time transfer (RTT) which
allows real-time communication on targets which support
debugger memory accesses while the CPU is running.
Revision: $Rev: 12706 $
Revision: $Rev: 17066 $
Additional information:
Type "int" is assumed to be 32-bits in size
@@ -140,6 +130,10 @@ Additional information:
#define STRLEN(a) strlen((a))
#endif
#ifndef STRCPY
#define STRCPY(pDest, pSrc, NumBytes) strcpy((pDest), (pSrc))
#endif
#ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP
#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0
#endif
@@ -256,7 +250,7 @@ SEGGER_RTT_PUT_CB_SECTION(SEGGER_RTT_CB_ALIGN(SEGGER_RTT_CB _SEGGER_RTT));
SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBuffer [BUFFER_SIZE_UP]));
SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[BUFFER_SIZE_DOWN]));
static char _ActiveTerminal;
static unsigned char _ActiveTerminal;
/*********************************************************************
*
@@ -308,8 +302,8 @@ static void _DoInit(void) {
// Copy Id string in three steps to make sure "SEGGER RTT" is not found
// in initializer memory (usually flash) by J-Link
//
strcpy(&p->acID[7], "RTT");
strcpy(&p->acID[0], "SEGGER");
STRCPY(&p->acID[7], "RTT", 9);
STRCPY(&p->acID[0], "SEGGER", 7);
p->acID[6] = ' ';
}
@@ -506,6 +500,105 @@ static unsigned _GetAvailWriteSpace(SEGGER_RTT_BUFFER_UP* pRing) {
*
**********************************************************************
*/
/*********************************************************************
*
* SEGGER_RTT_ReadUpBufferNoLock()
*
* Function description
* Reads characters from SEGGER real-time-terminal control block
* which have been previously stored by the application.
* Do not lock against interrupts and multiple access.
* Used to do the same operation that J-Link does, to transfer
* RTT data via other channels, such as TCP/IP or UART.
*
* Parameters
* BufferIndex Index of Up-buffer to be used.
* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-up-buffer to.
* BufferSize Size of the target application buffer.
*
* Return value
* Number of bytes that have been read.
*
* Additional information
* This function must not be called when J-Link might also do RTT.
*/
unsigned SEGGER_RTT_ReadUpBufferNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize) {
unsigned NumBytesRem;
unsigned NumBytesRead;
unsigned RdOff;
unsigned WrOff;
unsigned char* pBuffer;
SEGGER_RTT_BUFFER_UP* pRing;
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
const char* pSrc;
#endif
//
INIT();
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pBuffer = (unsigned char*)pData;
RdOff = pRing->RdOff;
WrOff = pRing->WrOff;
NumBytesRead = 0u;
//
// Read from current read position to wrap-around of buffer, first
//
if (RdOff > WrOff) {
NumBytesRem = pRing->SizeOfBuffer - RdOff;
NumBytesRem = MIN(NumBytesRem, BufferSize);
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
pSrc = pRing->pBuffer + RdOff;
NumBytesRead += NumBytesRem;
BufferSize -= NumBytesRem;
RdOff += NumBytesRem;
while (NumBytesRem--) {
*pBuffer++ = *pSrc++;
};
#else
SEGGER_RTT_MEMCPY(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
NumBytesRead += NumBytesRem;
pBuffer += NumBytesRem;
BufferSize -= NumBytesRem;
RdOff += NumBytesRem;
#endif
//
// Handle wrap-around of buffer
//
if (RdOff == pRing->SizeOfBuffer) {
RdOff = 0u;
}
}
//
// Read remaining items of buffer
//
NumBytesRem = WrOff - RdOff;
NumBytesRem = MIN(NumBytesRem, BufferSize);
if (NumBytesRem > 0u) {
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
pSrc = pRing->pBuffer + RdOff;
NumBytesRead += NumBytesRem;
BufferSize -= NumBytesRem;
RdOff += NumBytesRem;
while (NumBytesRem--) {
*pBuffer++ = *pSrc++;
};
#else
SEGGER_RTT_MEMCPY(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
NumBytesRead += NumBytesRem;
pBuffer += NumBytesRem;
BufferSize -= NumBytesRem;
RdOff += NumBytesRem;
#endif
}
//
// Update read offset of buffer
//
if (NumBytesRead) {
pRing->RdOff = RdOff;
}
//
return NumBytesRead;
}
/*********************************************************************
*
* SEGGER_RTT_ReadNoLock()
@@ -597,6 +690,47 @@ unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned Buffe
return NumBytesRead;
}
/*********************************************************************
*
* SEGGER_RTT_ReadUpBuffer
*
* Function description
* Reads characters from SEGGER real-time-terminal control block
* which have been previously stored by the application.
* Used to do the same operation that J-Link does, to transfer
* RTT data via other channels, such as TCP/IP or UART.
*
* Parameters
* BufferIndex Index of Up-buffer to be used.
* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-up-buffer to.
* BufferSize Size of the target application buffer.
*
* Return value
* Number of bytes that have been read.
*
* Additional information
* This function must not be called when J-Link might also do RTT.
* This function locks against all other RTT operations. I.e. during
* the read operation, writing is also locked.
* If only one consumer reads from the up buffer,
* call sEGGER_RTT_ReadUpBufferNoLock() instead.
*/
unsigned SEGGER_RTT_ReadUpBuffer(unsigned BufferIndex, void* pBuffer, unsigned BufferSize) {
unsigned NumBytesRead;
//
SEGGER_RTT_LOCK();
//
// Call the non-locking read function
//
NumBytesRead = SEGGER_RTT_ReadUpBufferNoLock(BufferIndex, pBuffer, BufferSize);
//
// Finish up.
//
SEGGER_RTT_UNLOCK();
//
return NumBytesRead;
}
/*********************************************************************
*
* SEGGER_RTT_Read
@@ -738,9 +872,12 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff
* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
* MUST be > 0!!!
* This is done for performance reasons, so no initial check has do be done.
*
* Return value
* Number of bytes which have been stored in the "Up"-buffer.
* 1: Data has been copied
* 0: No space, data has not been copied
*
* Notes
* (1) If there is not enough space in the "Up"-buffer, all data is dropped.
@@ -748,6 +885,7 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff
* and may only be called after RTT has been initialized.
* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
*/
#if (RTT_USE_ASM == 0)
unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
const char* pData;
SEGGER_RTT_BUFFER_UP* pRing;
@@ -755,118 +893,134 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
unsigned RdOff;
unsigned WrOff;
unsigned Rem;
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
char* pDst;
#endif
//
// Cases:
// 1) RdOff <= WrOff => Space until wrap-around is sufficient
// 2) RdOff <= WrOff => Space after wrap-around needed (copy in 2 chunks)
// 3) RdOff < WrOff => No space in buf
// 4) RdOff > WrOff => Space is sufficient
// 5) RdOff > WrOff => No space in buf
//
// 1) is the most common case for large buffers and assuming that J-Link reads the data fast enough
//
pData = (const char *)pBuffer;
//
// Get "to-host" ring buffer and copy some elements into local variables.
//
pRing = &_SEGGER_RTT.aUp[BufferIndex];
RdOff = pRing->RdOff;
WrOff = pRing->WrOff;
//
// Handle the most common cases fastest.
// Which is:
// RdOff <= WrOff -> Space until wrap around is free.
// AND
// WrOff + NumBytes < SizeOfBuffer -> No Wrap around necessary.
//
// OR
//
// RdOff > WrOff -> Space until RdOff - 1 is free.
// AND
// WrOff + NumBytes < RdOff -> Data fits into buffer
//
if (RdOff <= WrOff) {
//
// Get space until WrOff will be at wrap around.
//
Avail = pRing->SizeOfBuffer - 1u - WrOff ;
if (Avail >= NumBytes) {
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
pDst = pRing->pBuffer + WrOff;
WrOff += NumBytes;
while (NumBytes--) {
*pDst++ = *pData++;
};
pRing->WrOff = WrOff;
#else
SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
if (RdOff <= WrOff) { // Case 1), 2) or 3)
Avail = pRing->SizeOfBuffer - WrOff - 1u; // Space until wrap-around (assume 1 byte not usable for case that RdOff == 0)
if (Avail >= NumBytes) { // Case 1)?
CopyStraight:
memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
pRing->WrOff = WrOff + NumBytes;
#endif
return 1;
}
//
// If data did not fit into space until wrap around calculate complete space in buffer.
//
Avail += RdOff;
//
// If there is still no space for the whole of this output, don't bother.
//
if (Avail >= NumBytes) {
Avail += RdOff; // Space incl. wrap-around
if (Avail >= NumBytes) { // Case 2? => If not, we have case 3) (does not fit)
Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer
memcpy(pRing->pBuffer + WrOff, pData, Rem); // Copy 1st chunk
NumBytes -= Rem;
//
// OK, we have enough space in buffer. Copy in one or 2 chunks
// Special case: First check that assumed RdOff == 0 calculated that last element before wrap-around could not be used
// But 2nd check (considering space until wrap-around and until RdOff) revealed that RdOff is not 0, so we can use the last element
// In this case, we may use a copy straight until buffer end anyway without needing to copy 2 chunks
// Therefore, check if 2nd memcpy is necessary at all
//
Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer
if (Rem > NumBytes) {
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
pDst = pRing->pBuffer + WrOff;
WrOff += NumBytes;
while (NumBytes--) {
*pDst++ = *pData++;
};
pRing->WrOff = WrOff;
#else
SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
pRing->WrOff = WrOff + NumBytes;
#endif
} else {
//
// We reach the end of the buffer, so need to wrap around
//
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
pDst = pRing->pBuffer + WrOff;
NumBytes -= Rem;
WrOff = NumBytes;
do {
*pDst++ = *pData++;
} while (--Rem);
pDst = pRing->pBuffer;
while (NumBytes--) {
*pDst++ = *pData++;
};
pRing->WrOff = WrOff;
#else
SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, Rem);
SEGGER_RTT_MEMCPY(pRing->pBuffer, pData + Rem, NumBytes - Rem);
pRing->WrOff = NumBytes - Rem;
#endif
if (NumBytes) {
memcpy(pRing->pBuffer, pData + Rem, NumBytes);
}
pRing->WrOff = NumBytes;
return 1;
}
} else {
} else { // Potential case 4)
Avail = RdOff - WrOff - 1u;
if (Avail >= NumBytes) {
#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
pDst = pRing->pBuffer + WrOff;
WrOff += NumBytes;
while (NumBytes--) {
*pDst++ = *pData++;
};
pRing->WrOff = WrOff;
#else
SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
pRing->WrOff = WrOff + NumBytes;
#endif
return 1;
if (Avail >= NumBytes) { // Case 4)? => If not, we have case 5) (does not fit)
goto CopyStraight;
}
}
return 0; // No space in buffer
}
#endif
/*********************************************************************
*
* SEGGER_RTT_WriteDownBufferNoLock
*
* Function description
* Stores a specified number of characters in SEGGER RTT
* control block inside a <Down> buffer.
* SEGGER_RTT_WriteDownBufferNoLock does not lock the application.
* Used to do the same operation that J-Link does, to transfer
* RTT data from other channels, such as TCP/IP or UART.
*
* Parameters
* BufferIndex Index of "Down"-buffer to be used.
* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
*
* Return value
* Number of bytes which have been stored in the "Down"-buffer.
*
* Notes
* (1) Data is stored according to buffer flags.
* (2) For performance reasons this function does not call Init()
* and may only be called after RTT has been initialized.
* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
*
* Additional information
* This function must not be called when J-Link might also do RTT.
*/
unsigned SEGGER_RTT_WriteDownBufferNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
unsigned Status;
unsigned Avail;
const char* pData;
SEGGER_RTT_BUFFER_UP* pRing;
pData = (const char *)pBuffer;
//
// If we reach this point no data has been written
// Get "to-target" ring buffer.
// It is save to cast that to a "to-host" buffer. Up and Down buffer differ in volatility of offsets that might be modified by J-Link.
//
return 0;
pRing = (SEGGER_RTT_BUFFER_UP*)&_SEGGER_RTT.aDown[BufferIndex];
//
// How we output depends upon the mode...
//
switch (pRing->Flags) {
case SEGGER_RTT_MODE_NO_BLOCK_SKIP:
//
// If we are in skip mode and there is no space for the whole
// of this output, don't bother.
//
Avail = _GetAvailWriteSpace(pRing);
if (Avail < NumBytes) {
Status = 0u;
} else {
Status = NumBytes;
_WriteNoCheck(pRing, pData, NumBytes);
}
break;
case SEGGER_RTT_MODE_NO_BLOCK_TRIM:
//
// If we are in trim mode, trim to what we can output without blocking.
//
Avail = _GetAvailWriteSpace(pRing);
Status = Avail < NumBytes ? Avail : NumBytes;
_WriteNoCheck(pRing, pData, Status);
break;
case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:
//
// If we are in blocking mode, output everything.
//
Status = _WriteBlocking(pRing, pData, NumBytes);
break;
default:
Status = 0u;
break;
}
//
// Finish up.
//
return Status;
}
/*********************************************************************
@@ -944,6 +1098,48 @@ unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsig
return Status;
}
/*********************************************************************
*
* SEGGER_RTT_WriteDownBuffer
*
* Function description
* Stores a specified number of characters in SEGGER RTT control block in a <Down> buffer.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
*
* Return value
* Number of bytes which have been stored in the "Down"-buffer.
*
* Notes
* (1) Data is stored according to buffer flags.
*
* Additional information
* This function must not be called when J-Link might also do RTT.
* This function locks against all other RTT operations. I.e. during
* the write operation, writing from the application is also locked.
* If only one consumer writes to the down buffer,
* call SEGGER_RTT_WriteDownBufferNoLock() instead.
*/
unsigned SEGGER_RTT_WriteDownBuffer(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
unsigned Status;
//
INIT();
SEGGER_RTT_LOCK();
//
// Call the non-locking write function
//
Status = SEGGER_RTT_WriteDownBufferNoLock(BufferIndex, pBuffer, NumBytes);
//
// Finish up.
//
SEGGER_RTT_UNLOCK();
//
return Status;
}
/*********************************************************************
*
* SEGGER_RTT_Write
@@ -1636,7 +1832,7 @@ void SEGGER_RTT_Init (void) {
* >= 0 O.K.
* < 0 Error (e.g. if RTT is configured for non-blocking mode and there was no space in the buffer to set the new terminal Id)
*/
int SEGGER_RTT_SetTerminal (char TerminalId) {
int SEGGER_RTT_SetTerminal (unsigned char TerminalId) {
unsigned char ac[2];
SEGGER_RTT_BUFFER_UP* pRing;
unsigned Avail;
@@ -1646,8 +1842,8 @@ int SEGGER_RTT_SetTerminal (char TerminalId) {
//
r = 0;
ac[0] = 0xFFu;
if ((unsigned char)TerminalId < (unsigned char)sizeof(_aTerminalId)) { // We only support a certain number of channels
ac[1] = _aTerminalId[(unsigned char)TerminalId];
if (TerminalId < sizeof(_aTerminalId)) { // We only support a certain number of channels
ac[1] = _aTerminalId[TerminalId];
pRing = &_SEGGER_RTT.aUp[0]; // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed
SEGGER_RTT_LOCK(); // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing
if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
@@ -1686,7 +1882,7 @@ int SEGGER_RTT_SetTerminal (char TerminalId) {
* < 0 - Error.
*
*/
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s) {
int Status;
unsigned FragLen;
unsigned Avail;
@@ -1761,5 +1957,53 @@ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
return Status;
}
/*********************************************************************
*
* SEGGER_RTT_GetAvailWriteSpace
*
* Function description
* Returns the number of bytes available in the ring buffer.
*
* Parameters
* BufferIndex Index of the up buffer.
*
* Return value
* Number of bytes that are free in the selected up buffer.
*/
unsigned SEGGER_RTT_GetAvailWriteSpace (unsigned BufferIndex){
return _GetAvailWriteSpace(&_SEGGER_RTT.aUp[BufferIndex]);
}
/*********************************************************************
*
* SEGGER_RTT_GetBytesInBuffer()
*
* Function description
* Returns the number of bytes curretnly used in the up buffer.
*
* Parameters
* BufferIndex Index of the up buffer.
*
* Return value
* Number of bytes that are used in the buffer.
*/
unsigned SEGGER_RTT_GetBytesInBuffer(unsigned BufferIndex) {
unsigned RdOff;
unsigned WrOff;
unsigned r;
//
// Avoid warnings regarding volatile access order. It's not a problem
// in this case, but dampen compiler enthusiasm.
//
RdOff = _SEGGER_RTT.aUp[BufferIndex].RdOff;
WrOff = _SEGGER_RTT.aUp[BufferIndex].WrOff;
if (RdOff <= WrOff) {
r = WrOff - RdOff;
} else {
r = _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer - (WrOff - RdOff);
}
return r;
}
/*************************** End of file ****************************/
+96 -23
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,7 +42,7 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
@@ -60,7 +50,7 @@ File : SEGGER_RTT.h
Purpose : Implementation of SEGGER real-time transfer which allows
real-time communication on targets which support debugger
memory accesses while the CPU is running.
Revision: $Rev: 12706 $
Revision: $Rev: 17066 $
----------------------------------------------------------------------
*/
@@ -69,6 +59,65 @@ Revision: $Rev: 12706 $
#include "SEGGER_RTT_Conf.h"
/*********************************************************************
*
* Defines, defaults
*
**********************************************************************
*/
#ifndef RTT_USE_ASM
#if (defined __SES_ARM) // SEGGER Embedded Studio
#define _CC_HAS_RTT_ASM_SUPPORT 1
#elif (defined __CROSSWORKS_ARM) // Rowley Crossworks
#define _CC_HAS_RTT_ASM_SUPPORT 1
#elif (defined __GNUC__) // GCC
#define _CC_HAS_RTT_ASM_SUPPORT 1
#elif (defined __clang__) // Clang compiler
#define _CC_HAS_RTT_ASM_SUPPORT 1
#elif (defined __IASMARM__) // IAR assembler
#define _CC_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ICCARM__) // IAR compiler
#define _CC_HAS_RTT_ASM_SUPPORT 1
#else
#define _CC_HAS_RTT_ASM_SUPPORT 0
#endif
#if (defined __ARM_ARCH_7M__) // Cortex-M3/4
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ARM_ARCH_7EM__) // Cortex-M7
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ARM7M__) // IAR Cortex-M3/4
#if (__CORE__ == __ARM7M__)
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#else
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
#elif (defined __ARM7EM__) // IAR Cortex-M7
#if (__CORE__ == __ARM7EM__)
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#else
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
#else
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
//
// If IDE and core support the ASM version, enable ASM version by default
//
#if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT)
#define RTT_USE_ASM (1)
#else
#define RTT_USE_ASM (0)
#endif
#endif
#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file
#include <stdlib.h>
#include <stdarg.h>
/*********************************************************************
*
* Defines, fixed
@@ -158,24 +207,44 @@ int SEGGER_RTT_WaitKey (void);
unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_ASM_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c);
unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c);
unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c);
unsigned SEGGER_RTT_GetAvailWriteSpace (unsigned BufferIndex);
unsigned SEGGER_RTT_GetBytesInBuffer (unsigned BufferIndex);
//
// Function macro for performance optimization
//
#define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
#if RTT_USE_ASM
#define SEGGER_RTT_WriteSkipNoLock SEGGER_RTT_ASM_WriteSkipNoLock
#endif
/*********************************************************************
*
* RTT transfer functions to send RTT data via other channels.
*
**********************************************************************
*/
unsigned SEGGER_RTT_ReadUpBuffer (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
unsigned SEGGER_RTT_ReadUpBufferNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
unsigned SEGGER_RTT_WriteDownBuffer (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteDownBufferNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
#define SEGGER_RTT_HASDATA_UP(n) (_SEGGER_RTT.aUp[n].WrOff - _SEGGER_RTT.aUp[n].RdOff)
/*********************************************************************
*
* RTT "Terminal" API functions
*
**********************************************************************
*/
int SEGGER_RTT_SetTerminal (char TerminalId);
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
int SEGGER_RTT_SetTerminal (unsigned char TerminalId);
int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s);
/*********************************************************************
*
@@ -184,10 +253,14 @@ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
**********************************************************************
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
#ifdef __cplusplus
}
#endif
#endif // ifndef(SEGGER_RTT_ASM)
/*********************************************************************
*
* Defines
@@ -198,10 +271,10 @@ int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
//
// Operating modes. Define behavior if buffer is full (not enough space for entire message)
//
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default)
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits.
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer.
#define SEGGER_RTT_MODE_MASK (3U)
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default)
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits.
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer.
#define SEGGER_RTT_MODE_MASK (3)
//
// Control sequences, based on ANSI.
@@ -0,0 +1,235 @@
/*********************************************************************
* (c) SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_RTT_ASM_ARMv7M.S
Purpose : Assembler implementation of RTT functions for ARMv7M
Additional information:
This module is written to be assembler-independent and works with
GCC and clang (Embedded Studio) and IAR.
*/
#define SEGGER_RTT_ASM // Used to control processed input from header file
#include "SEGGER_RTT.h"
/*********************************************************************
*
* Defines, fixed
*
**********************************************************************
*/
#define _CCIAR 0
#define _CCCLANG 1
#if (defined __SES_ARM) || (defined __GNUC__) || (defined __clang__)
#define _CC_TYPE _CCCLANG
#define _PUB_SYM .global
#define _EXT_SYM .extern
#define _END .end
#define _WEAK .weak
#define _THUMB_FUNC .thumb_func
#define _THUMB_CODE .code 16
#define _WORD .word
#define _SECTION(Sect, Type, AlignExp) .section Sect ##, "ax"
#define _ALIGN(Exp) .align Exp
#define _PLACE_LITS .ltorg
#define _DATA_SECT_START
#define _C_STARTUP _start
#define _STACK_END __stack_end__
#define _RAMFUNC
//
// .text => Link to flash
// .fast => Link to RAM
// OtherSect => Usually link to RAM
// Alignment is 2^x
//
#elif defined (__IASMARM__)
#define _CC_TYPE _CCIAR
#define _PUB_SYM PUBLIC
#define _EXT_SYM EXTERN
#define _END END
#define _WEAK _WEAK
#define _THUMB_FUNC
#define _THUMB_CODE THUMB
#define _WORD DCD
#define _SECTION(Sect, Type, AlignExp) SECTION Sect ## : ## Type ## :REORDER:NOROOT ## (AlignExp)
#define _ALIGN(Exp) alignrom Exp
#define _PLACE_LITS
#define _DATA_SECT_START DATA
#define _C_STARTUP __iar_program_start
#define _STACK_END sfe(CSTACK)
#define _RAMFUNC SECTION_TYPE SHT_PROGBITS, SHF_WRITE | SHF_EXECINSTR
//
// .text => Link to flash
// .textrw => Link to RAM
// OtherSect => Usually link to RAM
// NOROOT => Allows linker to throw away the function, if not referenced
// Alignment is 2^x
//
#endif
#if (_CC_TYPE == _CCIAR)
NAME SEGGER_RTT_ASM_ARMv7M
#else
.syntax unified
#endif
#if defined (RTT_USE_ASM) && (RTT_USE_ASM == 1)
#define SHT_PROGBITS 0x1
/*********************************************************************
*
* Public / external symbols
*
**********************************************************************
*/
_EXT_SYM __aeabi_memcpy
_EXT_SYM __aeabi_memcpy4
_EXT_SYM _SEGGER_RTT
_PUB_SYM SEGGER_RTT_ASM_WriteSkipNoLock
/*********************************************************************
*
* SEGGER_RTT_WriteSkipNoLock
*
* Function description
* Stores a specified number of characters in SEGGER RTT
* control block which is then read by the host.
* SEGGER_RTT_WriteSkipNoLock does not lock the application and
* skips all data, if the data does not fit into the buffer.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
* MUST be > 0!!!
* This is done for performance reasons, so no initial check has do be done.
*
* Return value
* 1: Data has been copied
* 0: No space, data has not been copied
*
* Notes
* (1) If there is not enough space in the "Up"-buffer, all data is dropped.
* (2) For performance reasons this function does not call Init()
* and may only be called after RTT has been initialized.
* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
*/
_SECTION(.text, CODE, 2)
_ALIGN(2)
_THUMB_FUNC
SEGGER_RTT_ASM_WriteSkipNoLock: // unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pData, unsigned NumBytes) {
//
// Cases:
// 1) RdOff <= WrOff => Space until wrap-around is sufficient
// 2) RdOff <= WrOff => Space after wrap-around needed (copy in 2 chunks)
// 3) RdOff < WrOff => No space in buf
// 4) RdOff > WrOff => Space is sufficient
// 5) RdOff > WrOff => No space in buf
//
// 1) is the most common case for large buffers and assuming that J-Link reads the data fast enough
//
// Register usage:
// R0 Temporary needed as RdOff, <Tmp> register later on
// R1 pData
// R2 <NumBytes>
// R3 <Tmp> register. Hold free for subroutine calls
// R4 <Rem>
// R5 pRing->pBuffer
// R6 pRing (Points to active struct SEGGER_RTT_BUFFER_DOWN)
// R7 WrOff
//
PUSH {R4-R7}
ADD R3,R0,R0, LSL #+1
LDR.W R0,=_SEGGER_RTT // pRing = &_SEGGER_RTT.aUp[BufferIndex];
ADD R0,R0,R3, LSL #+3
ADD R6,R0,#+24
LDR R0,[R6, #+16] // RdOff = pRing->RdOff;
LDR R7,[R6, #+12] // WrOff = pRing->WrOff;
LDR R5,[R6, #+4] // pRing->pBuffer
CMP R7,R0
BCC.N _CheckCase4 // if (RdOff <= WrOff) { => Case 1), 2) or 3)
//
// Handling for case 1, later on identical to case 4
//
LDR R3,[R6, #+8] // Avail = pRing->SizeOfBuffer - WrOff - 1u; => Space until wrap-around (assume 1 byte not usable for case that RdOff == 0)
SUBS R4,R3,R7 // <Rem> (Used in case we jump into case 2 afterwards)
SUBS R3,R4,#+1 // <Avail>
CMP R3,R2
BCC.N _CheckCase2 // if (Avail >= NumBytes) { => Case 1)?
_Case4:
ADDS R5,R7,R5 // pBuffer += WrOff
ADDS R0,R2,R7 // v = WrOff + NumBytes
//
// 2x unrolling for the copy loop that is used most of the time
// This is a special optimization for small SystemView packets and makes them even faster
//
_ALIGN(2)
_LoopCopyStraight: // memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
LDRB R3,[R1], #+1
STRB R3,[R5], #+1 // *pDest++ = *pSrc++
SUBS R2,R2,#+1
BEQ _CSDone
LDRB R3,[R1], #+1
STRB R3,[R5], #+1 // *pDest++ = *pSrc++
SUBS R2,R2,#+1
BNE _LoopCopyStraight
_CSDone:
STR R0,[R6, #+12] // pRing->WrOff = WrOff + NumBytes;
MOVS R0,#+1
POP {R4-R7}
BX LR // Return 1
_CheckCase2:
ADDS R0,R0,R3 // Avail += RdOff; => Space incl. wrap-around
CMP R0,R2
BCC.N _Case3 // if (Avail >= NumBytes) { => Case 2? => If not, we have case 3) (does not fit)
//
// Handling for case 2
//
ADDS R0,R7,R5 // v = pRing->pBuffer + WrOff => Do not change pRing->pBuffer here because 2nd chunk needs org. value
SUBS R2,R2,R4 // NumBytes -= Rem; (Rem = pRing->SizeOfBuffer - WrOff; => Space until end of buffer)
_LoopCopyBeforeWrapAround: // memcpy(pRing->pBuffer + WrOff, pData, Rem); => Copy 1st chunk
LDRB R3,[R1], #+1
STRB R3,[R0], #+1 // *pDest++ = *pSrc++
SUBS R4,R4,#+1
BNE _LoopCopyBeforeWrapAround
//
// Special case: First check that assumed RdOff == 0 calculated that last element before wrap-around could not be used
// But 2nd check (considering space until wrap-around and until RdOff) revealed that RdOff is not 0, so we can use the last element
// In this case, we may use a copy straight until buffer end anyway without needing to copy 2 chunks
// Therefore, check if 2nd memcpy is necessary at all
//
ADDS R4,R2,#+0 // Save <NumBytes> (needed as counter in loop but must be written to <WrOff> after the loop). Also use this inst to update the flags to skip 2nd loop if possible
BEQ.N _No2ChunkNeeded // if (NumBytes) {
_LoopCopyAfterWrapAround: // memcpy(pRing->pBuffer, pData + Rem, NumBytes);
LDRB R3,[R1], #+1 // pData already points to the next src byte due to copy loop increment before this loop
STRB R3,[R5], #+1 // *pDest++ = *pSrc++
SUBS R2,R2,#+1
BNE _LoopCopyAfterWrapAround
_No2ChunkNeeded:
STR R4,[R6, #+12] // pRing->WrOff = NumBytes; => Must be written after copying data because J-Link may read control block asynchronously while writing into buffer
MOVS R0,#+1
POP {R4-R7}
BX LR // Return 1
_CheckCase4:
SUBS R0,R0,R7
SUBS R0,R0,#+1 // Avail = RdOff - WrOff - 1u;
CMP R0,R2
BCS.N _Case4 // if (Avail >= NumBytes) { => Case 4) == 1) ? => If not, we have case 5) == 3) (does not fit)
_Case3:
MOVS R0,#+0
POP {R4-R7}
BX LR // Return 0
_PLACE_LITS
#endif // defined (RTT_USE_ASM) && (RTT_USE_ASM == 1)
_END
/*************************** End of file ****************************/
@@ -0,0 +1,504 @@
/*********************************************************************
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER SystemView * Real-time application analysis *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 SEGGER Microcontroller 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. *
* *
**********************************************************************
* *
* SystemView version: 3.10 *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
File : SEGGER_RTT_printf.c
Purpose : Replacement for printf to write formatted data via RTT
Revision: $Rev: 16733 $
----------------------------------------------------------------------
*/
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64)
#endif
#include <stdlib.h>
#include <stdarg.h>
#define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0)
#define FORMAT_FLAG_PAD_ZERO (1u << 1)
#define FORMAT_FLAG_PRINT_SIGN (1u << 2)
#define FORMAT_FLAG_ALTERNATE (1u << 3)
/*********************************************************************
*
* Types
*
**********************************************************************
*/
typedef struct {
char* pBuffer;
unsigned BufferSize;
unsigned Cnt;
int ReturnValue;
unsigned RTTBufferIndex;
} SEGGER_RTT_PRINTF_DESC;
/*********************************************************************
*
* Function prototypes
*
**********************************************************************
*/
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _StoreChar
*/
static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) {
unsigned Cnt;
Cnt = p->Cnt;
if ((Cnt + 1u) <= p->BufferSize) {
*(p->pBuffer + Cnt) = c;
p->Cnt = Cnt + 1u;
p->ReturnValue++;
}
//
// Write part of string, when the buffer is full
//
if (p->Cnt == p->BufferSize) {
if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) {
p->ReturnValue = -1;
} else {
p->Cnt = 0u;
}
}
}
/*********************************************************************
*
* _PrintUnsigned
*/
static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
unsigned Div;
unsigned Digit;
unsigned Number;
unsigned Width;
char c;
Number = v;
Digit = 1u;
//
// Get actual field width
//
Width = 1u;
while (Number >= Base) {
Number = (Number / Base);
Width++;
}
if (NumDigits > Width) {
Width = NumDigits;
}
//
// Print leading chars if necessary
//
if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {
if (FieldWidth != 0u) {
if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {
c = '0';
} else {
c = ' ';
}
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, c);
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
if (pBufferDesc->ReturnValue >= 0) {
//
// Compute Digit.
// Loop until Digit has the value of the highest digit required.
// Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.
//
while (1) {
if (NumDigits > 1u) { // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned)
NumDigits--;
} else {
Div = v / Digit;
if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done
break;
}
}
Digit *= Base;
}
//
// Output digits
//
do {
Div = v / Digit;
v -= Div * Digit;
_StoreChar(pBufferDesc, _aV2C[Div]);
if (pBufferDesc->ReturnValue < 0) {
break;
}
Digit /= Base;
} while (Digit);
//
// Print trailing spaces if necessary
//
if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
if (FieldWidth != 0u) {
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, ' ');
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
}
}
/*********************************************************************
*
* _PrintInt
*/
static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
unsigned Width;
int Number;
Number = (v < 0) ? -v : v;
//
// Get actual field width
//
Width = 1u;
while (Number >= (int)Base) {
Number = (Number / (int)Base);
Width++;
}
if (NumDigits > Width) {
Width = NumDigits;
}
if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
FieldWidth--;
}
//
// Print leading spaces if necessary
//
if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {
if (FieldWidth != 0u) {
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, ' ');
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
//
// Print sign if necessary
//
if (pBufferDesc->ReturnValue >= 0) {
if (v < 0) {
v = -v;
_StoreChar(pBufferDesc, '-');
} else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
_StoreChar(pBufferDesc, '+');
} else {
}
if (pBufferDesc->ReturnValue >= 0) {
//
// Print leading zeros if necessary
//
if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {
if (FieldWidth != 0u) {
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, '0');
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
if (pBufferDesc->ReturnValue >= 0) {
//
// Print number without sign
//
_PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags);
}
}
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* SEGGER_RTT_vprintf
*
* Function description
* Stores a formatted string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* sFormat Pointer to format string
* pParamList Pointer to the list of arguments for the format string
*
* Return values
* >= 0: Number of bytes which have been stored in the "Up"-buffer.
* < 0: Error
*/
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) {
char c;
SEGGER_RTT_PRINTF_DESC BufferDesc;
int v;
unsigned NumDigits;
unsigned FormatFlags;
unsigned FieldWidth;
char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE];
BufferDesc.pBuffer = acBuffer;
BufferDesc.BufferSize = SEGGER_RTT_PRINTF_BUFFER_SIZE;
BufferDesc.Cnt = 0u;
BufferDesc.RTTBufferIndex = BufferIndex;
BufferDesc.ReturnValue = 0;
do {
c = *sFormat;
sFormat++;
if (c == 0u) {
break;
}
if (c == '%') {
//
// Filter out flags
//
FormatFlags = 0u;
v = 1;
do {
c = *sFormat;
switch (c) {
case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break;
case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break;
case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break;
default: v = 0; break;
}
} while (v);
//
// filter out field with
//
FieldWidth = 0u;
do {
c = *sFormat;
if ((c < '0') || (c > '9')) {
break;
}
sFormat++;
FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0');
} while (1);
//
// Filter out precision (number of digits to display)
//
NumDigits = 0u;
c = *sFormat;
if (c == '.') {
sFormat++;
do {
c = *sFormat;
if ((c < '0') || (c > '9')) {
break;
}
sFormat++;
NumDigits = NumDigits * 10u + ((unsigned)c - '0');
} while (1);
}
//
// Filter out length modifier
//
c = *sFormat;
do {
if ((c == 'l') || (c == 'h')) {
sFormat++;
c = *sFormat;
} else {
break;
}
} while (1);
//
// Handle specifiers
//
switch (c) {
case 'c': {
char c0;
v = va_arg(*pParamList, int);
c0 = (char)v;
_StoreChar(&BufferDesc, c0);
break;
}
case 'd':
v = va_arg(*pParamList, int);
_PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);
break;
case 'u':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags);
break;
case 'x':
case 'X':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags);
break;
case 's':
{
const char * s = va_arg(*pParamList, const char *);
do {
c = *s;
s++;
if (c == '\0') {
break;
}
_StoreChar(&BufferDesc, c);
} while (BufferDesc.ReturnValue >= 0);
}
break;
case 'p':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u);
break;
case '%':
_StoreChar(&BufferDesc, '%');
break;
default:
break;
}
sFormat++;
} else {
_StoreChar(&BufferDesc, c);
}
} while (BufferDesc.ReturnValue >= 0);
if (BufferDesc.ReturnValue > 0) {
//
// Write remaining data, if any
//
if (BufferDesc.Cnt != 0u) {
SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt);
}
BufferDesc.ReturnValue += (int)BufferDesc.Cnt;
}
return BufferDesc.ReturnValue;
}
/*********************************************************************
*
* SEGGER_RTT_printf
*
* Function description
* Stores a formatted string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* sFormat Pointer to format string, followed by the arguments for conversion
*
* Return values
* >= 0: Number of bytes which have been stored in the "Up"-buffer.
* < 0: Error
*
* Notes
* (1) Conversion specifications have following syntax:
* %[flags][FieldWidth][.Precision]ConversionSpecifier
* (2) Supported flags:
* -: Left justify within the field width
* +: Always print sign extension for signed conversions
* 0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision
* Supported conversion specifiers:
* c: Print the argument as one char
* d: Print the argument as a signed integer
* u: Print the argument as an unsigned integer
* x: Print the argument as an hexadecimal integer
* s: Print the string pointed to by the argument
* p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.)
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) {
int r;
va_list ParamList;
va_start(ParamList, sFormat);
r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList);
va_end(ParamList);
return r;
}
/*************************** End of file ****************************/
+131 -48
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,14 +42,14 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW.c
Purpose : System visualization API implementation.
Revision: $Rev: 12706 $
Revision: $Rev: 17331 $
Additional information:
Packet format:
@@ -70,12 +60,15 @@ Additional information:
Packets with IDs 24..31 are standard packets with extendible
structure and contain a length field.
<ID><Lenght><Data><TimeStampDelta>
Packet ID 31 is used for SystemView extended events.
<ID><Lenght><ID_EX><Data><TimeStampDelta>
Packets with IDs >= 32 always contain a length field.
<ID><Length><Data><TimeStampDelta>
Packet IDs:
0.. 31 : Standard packets, known by SystemViewer.
0.. 31 : Standard packets, known by SystemView.
32..1023 : OS-definable packets, described in a SystemView description file.
1024..2047 : User-definable packets, described in a SystemView description file.
2048..32767: Undefined.
@@ -540,6 +533,7 @@ static int _TrySendOverflowPacket(void) {
// Try to store packet in RTT buffer and update time stamp when this was successful
//
Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, aPacket, pPayload - aPacket);
SEGGER_SYSVIEW_ON_EVENT_RECORDED(pPayload - aPacket);
if (Status) {
_SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
_SYSVIEW_Globals.EnableState--; // EnableState has been 2, will be 1. Always.
@@ -573,6 +567,7 @@ static void _SendSyncInfo(void) {
// Send module information
//
SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, _abSync, 10);
SEGGER_SYSVIEW_ON_EVENT_RECORDED(10);
SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
{
U8* pPayload;
@@ -593,8 +588,9 @@ static void _SendSyncInfo(void) {
SEGGER_SYSVIEW_RecordSystime();
SEGGER_SYSVIEW_SendTaskList();
if (_NumModules > 0) {
int n;
SEGGER_SYSVIEW_SendNumModules();
for (int n = 0; n < _NumModules; n++) {
for (n = 0; n < _NumModules; n++) {
SEGGER_SYSVIEW_SendModule(n);
}
SEGGER_SYSVIEW_SendModuleDescription();
@@ -699,12 +695,14 @@ Send:
// Store packet in RTT buffer by overwriting old data and update time stamp
//
SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
SEGGER_SYSVIEW_ON_EVENT_RECORDED(pEndPacket - pStartPacket);
_SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
#else
//
// Try to store packet in RTT buffer and update time stamp when this was successful
//
Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
SEGGER_SYSVIEW_ON_EVENT_RECORDED(pEndPacket - pStartPacket);
if (Status) {
_SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
} else {
@@ -1206,13 +1204,14 @@ static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList)
*
* Function description
* Initializes the SYSVIEW module.
* Must be called before SystemViewer attaches to the system.
* Must be called before the Systemview Application connects to
* the system.
*
* Parameters
* SysFreq - Frequency of timestamp, i.e. CPU core clock frequency.
* SysFreq - Frequency of timestamp, usually CPU core clock frequency.
* CPUFreq - CPU core clock frequency.
* pOSAPI - Pointer to the API structure for OS-specific functions.
* pfSendSysDesc - Pointer to SendSysDesc callback function.
* pfSendSysDesc - Pointer to record system description callback function.
*
* Additional information
* This function initializes the RTT channel used to transport
@@ -1220,8 +1219,7 @@ static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList)
* The channel is assigned the label "SysView" for client software
* to identify the SystemView channel.
*
* Notes
* The channel is configured by the macro SEGGER_SYSVIEW_RTT_CHANNEL.
* The channel is configured with the macro SEGGER_SYSVIEW_RTT_CHANNEL.
*/
void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc) {
#ifdef SEGGER_RTT_SECTION
@@ -1250,9 +1248,6 @@ void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *
SEGGER_RTT_ConfigDownBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
#else
_SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
//
// TODO: Use SEGGER_RTT_AllocDownBuffer when SystemViewer is able to handle another Down Channel than Up Channel.
//
_SYSVIEW_Globals.DownChannel = _SYSVIEW_Globals.UpChannel;
SEGGER_RTT_ConfigDownBuffer (_SYSVIEW_Globals.DownChannel, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
#endif
@@ -1641,7 +1636,10 @@ void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) {
*
* Function description
* Start recording SystemView events.
* This function is triggered by the host application.
*
* This function is triggered by the SystemView Application on connect.
* For single-shot or post-mortem mode recording, it needs to be called
* by the application.
*
* Additional information
* This function enables transmission of SystemView packets recorded
@@ -1653,9 +1651,15 @@ void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) {
*
* Notes
* SEGGER_SYSVIEW_Start and SEGGER_SYSVIEW_Stop do not nest.
* When SEGGER_SYSVIEW_CAN_RESTART is 1, each received start command
* records the system information. This is required to enable restart
* of recordings when SystemView unexpectedly disconnects without sending
* a stop command before.
*/
void SEGGER_SYSVIEW_Start(void) {
#if (SEGGER_SYSVIEW_CAN_RESTART == 0)
if (_SYSVIEW_Globals.EnableState == 0) {
#endif
_SYSVIEW_Globals.EnableState = 1;
#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
_SendSyncInfo();
@@ -1663,6 +1667,7 @@ void SEGGER_SYSVIEW_Start(void) {
SEGGER_SYSVIEW_LOCK();
SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, _abSync, 10);
SEGGER_SYSVIEW_UNLOCK();
SEGGER_SYSVIEW_ON_EVENT_RECORDED(10);
SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
{
U8* pPayload;
@@ -1684,7 +1689,9 @@ void SEGGER_SYSVIEW_Start(void) {
SEGGER_SYSVIEW_SendTaskList();
SEGGER_SYSVIEW_SendNumModules();
#endif
#if (SEGGER_SYSVIEW_CAN_RESTART == 0)
}
#endif
}
/*********************************************************************
@@ -1694,6 +1701,10 @@ void SEGGER_SYSVIEW_Start(void) {
* Function description
* Stop recording SystemView events.
*
* This function is triggered by the SystemView Application on disconnect.
* For single-shot or post-mortem mode recording, it can be called
* by the application.
*
* Additional information
* This function disables transmission of SystemView packets recorded
* by subsequent trace calls. If transmission is enabled when
@@ -1711,6 +1722,17 @@ void SEGGER_SYSVIEW_Stop(void) {
RECORD_END();
}
/*********************************************************************
*
* SEGGER_SYSVIEW_GetChannelID()
*
* Function description
* Returns the RTT <Up> / <Down> channel ID used by SystemView.
*/
int SEGGER_SYSVIEW_GetChannelID(void) {
return CHANNEL_ID_UP;
}
/*********************************************************************
*
* SEGGER_SYSVIEW_GetSysDesc()
@@ -1786,14 +1808,19 @@ void SEGGER_SYSVIEW_SendTaskList(void) {
*
* Function description
* Send the system description string to the host.
* The system description is used by SystemViewer to identify the
* current application and handle events accordingly.
* The system description is used by the Systemview Application
* to identify the current application and handle events accordingly.
*
* The system description is usually called by the system description
* callback, to ensure it is only sent when the SystemView Application
* is connected.
*
* Parameters
* sSysDesc - Pointer to the 0-terminated system description string.
*
* Additional information
* One system description string may not exceed SEGGER_SYSVIEW_MAX_STRING_LEN characters.
* Multiple description strings can be recorded.
*
* The Following items can be described in a system description string.
* Each item is identified by its identifier, followed by '=' and the value.
@@ -2129,43 +2156,93 @@ void SEGGER_SYSVIEW_OnTaskStopReady(U32 TaskId, unsigned int Cause) {
/*********************************************************************
*
* SEGGER_SYSVIEW_OnUserStart()
* SEGGER_SYSVIEW_MarkStart()
*
* Function description
* Send a user event start, such as start of a subroutine for profiling.
* Record a Performance Marker Start event to start measuring runtime.
*
* Parameters
* UserId - User defined ID for the event.
* MarkerId - User defined ID for the marker.
*/
void SEGGER_SYSVIEW_OnUserStart(unsigned UserId) {
void SEGGER_SYSVIEW_MarkStart(unsigned MarkerId) {
U8* pPayload;
U8* pPayloadStart;
RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
//
pPayload = pPayloadStart;
ENCODE_U32(pPayload, UserId);
_SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_START);
ENCODE_U32(pPayload, MarkerId);
_SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_START);
RECORD_END();
}
/*********************************************************************
*
* SEGGER_SYSVIEW_OnUserStop()
* SEGGER_SYSVIEW_MarkStop()
*
* Function description
* Send a user event stop, such as return of a subroutine for profiling.
* Record a Performance Marker Stop event to stop measuring runtime.
*
* Parameters
* UserId - User defined ID for the event.
* MarkerId - User defined ID for the marker.
*/
void SEGGER_SYSVIEW_OnUserStop(unsigned UserId) {
void SEGGER_SYSVIEW_MarkStop(unsigned MarkerId) {
U8 * pPayload;
U8 * pPayloadStart;
RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
//
pPayload = pPayloadStart;
ENCODE_U32(pPayload, UserId);
_SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_STOP);
ENCODE_U32(pPayload, MarkerId);
_SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_STOP);
RECORD_END();
}
/*********************************************************************
*
* SEGGER_SYSVIEW_Mark()
*
* Function description
* Record a Performance Marker intermediate event.
*
* Parameters
* MarkerId - User defined ID for the marker.
*/
void SEGGER_SYSVIEW_Mark(unsigned int MarkerId) {
U8* pPayload;
U8* pPayloadStart;
RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
//
pPayload = pPayloadStart;
ENCODE_U32(pPayload, SYSVIEW_EVTID_EX_MARK);
ENCODE_U32(pPayload, MarkerId);
_SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_EX);
RECORD_END();
}
/*********************************************************************
*
* SEGGER_SYSVIEW_NameMarker()
*
* Function description
* Send the name of a Performance Marker to be displayed in SystemView.
*
* Marker names are usually set in the system description
* callback, to ensure it is only sent when the SystemView Application
* is connected.
*
* Parameters
* MarkerId - User defined ID for the marker.
* sName - Pointer to the marker name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes)
*/
void SEGGER_SYSVIEW_NameMarker(unsigned int MarkerId, const char* sName) {
U8* pPayload;
U8* pPayloadStart;
RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
//
pPayload = pPayloadStart;
ENCODE_U32(pPayload, SYSVIEW_EVTID_EX_NAME_MARKER);
ENCODE_U32(pPayload, MarkerId);
pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN);
_SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_EX);
RECORD_END();
}
@@ -2174,7 +2251,11 @@ void SEGGER_SYSVIEW_OnUserStop(unsigned UserId) {
* SEGGER_SYSVIEW_NameResource()
*
* Function description
* Send the name of a resource to be displayed in SystemViewer.
* Send the name of a resource to be displayed in SystemView.
*
* Marker names are usually set in the system description
* callback, to ensure it is only sent when the SystemView Application
* is connected.
*
* Parameters
* ResourceId - Id of the resource to be named. i.e. its address.
@@ -2364,7 +2445,7 @@ U32 SEGGER_SYSVIEW_ShrinkId(U32 Id) {
* sDescription - Pointer to a string containing the module name and optionally the module event description.
* NumEvents - Number of events the module wants to register.
* EventOffset - Offset to be added to the event Ids. Out parameter, set by this function. Do not modify after calling this function.
* pfSendModuleDesc - Callback function pointer to send more detailed module description to SystemViewer.
* pfSendModuleDesc - Callback function pointer to send more detailed module description to SystemView Application.
* pNext - Pointer to next registered module. Out parameter, set by this function. Do not modify after calling this function.
*/
void SEGGER_SYSVIEW_RegisterModule(SEGGER_SYSVIEW_MODULE* pModule) {
@@ -2526,7 +2607,7 @@ void SEGGER_SYSVIEW_SendNumModules(void) {
* SEGGER_SYSVIEW_PrintfHostEx()
*
* Function description
* Print a string which is formatted on the host by SystemViewer
* Print a string which is formatted on the host by the SystemView Application
* with Additional information.
*
* Parameters
@@ -2562,7 +2643,7 @@ void SEGGER_SYSVIEW_PrintfHostEx(const char* s, U32 Options, ...) {
* SEGGER_SYSVIEW_PrintfHost()
*
* Function description
* Print a string which is formatted on the host by SystemViewer.
* Print a string which is formatted on the host by the SystemView Application.
*
* Parameters
* s - String to be formatted.
@@ -2597,7 +2678,7 @@ void SEGGER_SYSVIEW_PrintfHost(const char* s, ...) {
*
* Function description
* Print a warnin string which is formatted on the host by
* SystemViewer.
* the SystemView Application.
*
* Parameters
* s - String to be formatted.
@@ -2632,7 +2713,7 @@ void SEGGER_SYSVIEW_WarnfHost(const char* s, ...) {
*
* Function description
* Print an error string which is formatted on the host by
* SystemViewer.
* the SystemView Application.
*
* Parameters
* s - String to be formatted.
@@ -2845,6 +2926,7 @@ void SEGGER_SYSVIEW_DisableEvents(U32 DisableMask) {
* > 0: Recording started.
*/
int SEGGER_SYSVIEW_IsStarted(void) {
#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
//
// Check if host is sending data which needs to be processed.
//
@@ -2855,6 +2937,7 @@ int SEGGER_SYSVIEW_IsStarted(void) {
_SYSVIEW_Globals.RecursionCnt = 0;
}
}
#endif
return _SYSVIEW_Globals.EnableState;
}
+33 -22
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,13 +42,13 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW.h
Purpose : System visualization API.
Revision: $Rev: 12706 $
Revision: $Rev: 17331 $
*/
#ifndef SEGGER_SYSVIEW_H
@@ -85,7 +75,10 @@ extern "C" {
**********************************************************************
*/
#define SEGGER_SYSVIEW_VERSION 21000
#define SEGGER_SYSVIEW_MAJOR 3
#define SEGGER_SYSVIEW_MINOR 10
#define SEGGER_SYSVIEW_REV 0
#define SEGGER_SYSVIEW_VERSION ((SEGGER_SYSVIEW_MAJOR * 10000) + (SEGGER_SYSVIEW_MINOR * 100) + SEGGER_SYSVIEW_REV)
#define SEGGER_SYSVIEW_INFO_SIZE 9 // Minimum size, which has to be reserved for a packet. 1-2 byte of message type, 0-2 byte of payload length, 1-5 bytes of timestamp.
#define SEGGER_SYSVIEW_QUANTA_U32 5 // Maximum number of bytes to encode a U32, should be reserved for each 32-bit value in a packet.
@@ -114,8 +107,8 @@ extern "C" {
#define SYSVIEW_EVTID_SYSTIME_CYCLES 12
#define SYSVIEW_EVTID_SYSTIME_US 13
#define SYSVIEW_EVTID_SYSDESC 14
#define SYSVIEW_EVTID_USER_START 15
#define SYSVIEW_EVTID_USER_STOP 16
#define SYSVIEW_EVTID_MARK_START 15
#define SYSVIEW_EVTID_MARK_STOP 16
#define SYSVIEW_EVTID_IDLE 17
#define SYSVIEW_EVTID_ISR_TO_SCHEDULER 18
#define SYSVIEW_EVTID_TIMER_ENTER 19
@@ -132,6 +125,11 @@ extern "C" {
#define SYSVIEW_EVTID_EX 31
//
// SystemView extended events. Sent with ID 31.
//
#define SYSVIEW_EVTID_EX_MARK 0
#define SYSVIEW_EVTID_EX_NAME_MARKER 1
//
// Event masks to disable/enable events
//
#define SYSVIEW_EVTMASK_NOP (1 << SYSVIEW_EVTID_NOP)
@@ -231,6 +229,7 @@ void SEGGER_SYSVIEW_SendTaskList (void);
void SEGGER_SYSVIEW_SendTaskInfo (const SEGGER_SYSVIEW_TASKINFO* pInfo);
void SEGGER_SYSVIEW_SendSysDesc (const char* sSysDesc);
int SEGGER_SYSVIEW_IsStarted (void);
int SEGGER_SYSVIEW_GetChannelID (void);
/*********************************************************************
*
@@ -264,8 +263,10 @@ void SEGGER_SYSVIEW_OnTaskStartExec (U32 TaskId);
void SEGGER_SYSVIEW_OnTaskStopExec (void);
void SEGGER_SYSVIEW_OnTaskStartReady (U32 TaskId);
void SEGGER_SYSVIEW_OnTaskStopReady (U32 TaskId, unsigned int Cause);
void SEGGER_SYSVIEW_OnUserStart (unsigned int UserId); // Start of user defined event (such as a subroutine to profile)
void SEGGER_SYSVIEW_OnUserStop (unsigned int UserId); // Start of user defined event
void SEGGER_SYSVIEW_MarkStart (unsigned int MarkerId);
void SEGGER_SYSVIEW_MarkStop (unsigned int MarkerId);
void SEGGER_SYSVIEW_Mark (unsigned int MarkerId);
void SEGGER_SYSVIEW_NameMarker (unsigned int MarkerId, const char* sName);
void SEGGER_SYSVIEW_NameResource (U32 ResourceId, const char* sName);
@@ -326,10 +327,20 @@ void SEGGER_SYSVIEW_Conf (void);
U32 SEGGER_SYSVIEW_X_GetTimestamp (void);
U32 SEGGER_SYSVIEW_X_GetInterruptId (void);
void SEGGER_SYSVIEW_X_StartComm (void);
void SEGGER_SYSVIEW_X_OnEventRecorded (unsigned NumBytes);
#ifdef __cplusplus
}
#endif
/*********************************************************************
*
* Compatibility API defines
*/
#define SEGGER_SYSVIEW_OnUserStart SEGGER_SYSVIEW_MarkStart
#define SEGGER_SYSVIEW_OnUserStop SEGGER_SYSVIEW_MarkStop
#endif
/*************************** End of file ****************************/
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,14 +42,14 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW_ConfDefaults.h
Purpose : Defines defaults for configurable defines used in
SEGGER SystemView.
Revision: $Rev: 12706 $
Revision: $Rev: 9599 $
*/
#ifndef SEGGER_SYSVIEW_CONFDEFAULTS_H
+7 -17
View File
@@ -1,9 +1,9 @@
/*********************************************************************
* SEGGER Microcontroller GmbH & Co. KG *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
**********************************************************************
* *
* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
@@ -17,24 +17,14 @@
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the RTT protocol and J-Link. *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* *
* o 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. *
* *
* o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
* nor the names of its contributors may be used to endorse or *
* promote products derived from this software without specific *
* prior written permission. *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
@@ -52,13 +42,13 @@
* *
**********************************************************************
* *
* SystemView version: V2.52d *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW_Int.h
Purpose : SEGGER SystemView internal header.
Revision: $Rev: 12706 $
Revision: $Rev: 9599 $
*/
#ifndef SEGGER_SYSVIEW_INT_H
+45 -4
View File
@@ -1,9 +1,50 @@
/*********************************************************************
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
* *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER SystemView * Real-time application analysis *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 SEGGER Microcontroller 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. *
* *
**********************************************************************
* *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW_FreeRTOS.c
@@ -211,6 +252,6 @@ const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
_cbSendTaskList,
};
#endif // CFG_DEBUG
#endif // CFG_DEBUG >= 3
/*************************** End of file ****************************/
+44 -3
View File
@@ -1,9 +1,50 @@
/*********************************************************************
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
* SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
* *
* (c) 1995 - 2019 SEGGER Microcontroller GmbH *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER SystemView * Real-time application analysis *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* SEGGER strongly recommends to not make any changes *
* to or modify the source code of this software in order to stay *
* compatible with the SystemView and RTT protocol, and J-Link. *
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* condition is met: *
* *
* o Redistributions of source code must retain the above copyright *
* notice, this condition and the following disclaimer. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 SEGGER Microcontroller 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. *
* *
**********************************************************************
* *
* SystemView version: 3.10 *
* *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : SEGGER_SYSVIEW_FreeRTOS.h
+47
View File
@@ -438,6 +438,53 @@ const char* dbg_err_str(int32_t err_id)
return str;
}
//--------------------------------------------------------------------+
// HCI STATUS
//--------------------------------------------------------------------+
static lookup_entry_t const _strhci_lookup[] =
{
{ .key = BLE_HCI_STATUS_CODE_SUCCESS , .data = "STATUS_CODE_SUCCESS" },
{ .key = BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND , .data = "STATUS_CODE_UNKNOWN_BTLE_COMMAND " },
{ .key = BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER , .data = "STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER" },
{ .key = BLE_HCI_AUTHENTICATION_FAILURE , .data = "AUTHENTICATION_FAILURE " },
{ .key = BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING , .data = "STATUS_CODE_PIN_OR_KEY_MISSING " },
{ .key = BLE_HCI_MEMORY_CAPACITY_EXCEEDED , .data = "MEMORY_CAPACITY_EXCEEDED " },
{ .key = BLE_HCI_CONNECTION_TIMEOUT , .data = "CONNECTION_TIMEOUT " },
{ .key = BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED , .data = "STATUS_CODE_COMMAND_DISALLOWED " },
{ .key = BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS , .data = "STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS" },
{ .key = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION , .data = "REMOTE_USER_TERMINATED_CONNECTION" },
{ .key = BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES , .data = "REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES" },
{ .key = BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF , .data = "REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF" },
{ .key = BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION , .data = "LOCAL_HOST_TERMINATED_CONNECTION " },
{ .key = BLE_HCI_UNSUPPORTED_REMOTE_FEATURE , .data = "UNSUPPORTED_REMOTE_FEATURE" },
{ .key = BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS , .data = "STATUS_CODE_INVALID_LMP_PARAMETERS " },
{ .key = BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR , .data = "STATUS_CODE_UNSPECIFIED_ERROR" },
{ .key = BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT , .data = "STATUS_CODE_LMP_RESPONSE_TIMEOUT " },
{ .key = BLE_HCI_STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION , .data = "STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION" },
{ .key = BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED , .data = "STATUS_CODE_LMP_PDU_NOT_ALLOWED" },
{ .key = BLE_HCI_INSTANT_PASSED , .data = "INSTANT_PASSED " },
{ .key = BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED , .data = "PAIRING_WITH_UNIT_KEY_UNSUPPORTED" },
{ .key = BLE_HCI_DIFFERENT_TRANSACTION_COLLISION , .data = "DIFFERENT_TRANSACTION_COLLISION" },
{ .key = BLE_HCI_PARAMETER_OUT_OF_MANDATORY_RANGE , .data = "PARAMETER_OUT_OF_MANDATORY_RANGE " },
{ .key = BLE_HCI_CONTROLLER_BUSY , .data = "CONTROLLER_BUSY" },
{ .key = BLE_HCI_CONN_INTERVAL_UNACCEPTABLE , .data = "CONN_INTERVAL_UNACCEPTABLE " },
{ .key = BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT , .data = "DIRECTED_ADVERTISER_TIMEOUT" },
{ .key = BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE , .data = "CONN_TERMINATED_DUE_TO_MIC_FAILURE " },
{ .key = BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED , .data = "CONN_FAILED_TO_BE_ESTABLISHED" }
};
lookup_table_t const _strhci_table =
{
.count = arrcount(_strhci_lookup),
.items = _strhci_lookup
};
const char* dbg_hci_str(uint8_t id)
{
return (const char *) lookup_find(&_strhci_table, id);
}
#endif
}
+1
View File
@@ -46,6 +46,7 @@
#if CFG_DEBUG
const char* dbg_ble_event_str(uint16_t evt_id);
const char* dbg_err_str(int32_t err_id);
const char* dbg_hci_str(uint8_t id);
#endif
int dbgHeapTotal(void);
@@ -8,3 +8,4 @@ category=Communication
url=https://github.com/adafruit/Adafruit_nRF52_Arduino
architectures=*
includes=BLEAdafruitService.h
depends=Adafruit NeoPixel, Adafruit Unified Sensor, Adafruit AHRS, Adafruit Sensor Calibration
@@ -28,13 +28,22 @@
#include "bluefruit_common.h"
#include "BLECharacteristic.h"
#include "BLEService.h"
#include "services/BLEAdafruitSensor.h"
#include "services/BLEAdafruitTemperature.h"
#include "services/BLEAdafruitAccel.h"
#include "services/BLEAdafruitLightSensor.h"
#include "services/BLEAdafruitButton.h"
#include "services/BLEAdafruitTone.h"
#include "services/BLEAdafruitAddressablePixel.h"
#include "services/BLEAdafruitBaro.h"
#include "services/BLEAdafruitButton.h"
#include "services/BLEAdafruitColor.h"
#include "services/BLEAdafruitGesture.h"
#include "services/BLEAdafruitGyro.h"
#include "services/BLEAdafruitHumid.h"
#include "services/BLEAdafruitLightSensor.h"
#include "services/BLEAdafruitMagnetic.h"
#include "services/BLEAdafruitProximity.h"
#include "services/BLEAdafruitQuaternion.h"
#include "services/BLEAdafruitSound.h"
#include "services/BLEAdafruitTemperature.h"
#include "services/BLEAdafruitTone.h"
#endif /* BLEADAFRUITSERVICE_H_ */
@@ -56,19 +56,9 @@ const uint8_t BLEAdafruitAccel::UUID128_CHR_DATA[16] =
// Constructor
BLEAdafruitAccel::BLEAdafruitAccel(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
}
err_t BLEAdafruitAccel::begin (void)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4*3);
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
return ERROR_NONE;
}
@@ -22,8 +22,8 @@
* THE SOFTWARE.
*/
#ifndef BLEADAFRUITACCEL_H_
#define BLEADAFRUITACCEL_H_
#ifndef BLEADAFRUIT_ACCEL_H_
#define BLEADAFRUIT_ACCEL_H_
class BLEAdafruitAccel : public BLEAdafruitSensor
{
@@ -31,10 +31,9 @@ class BLEAdafruitAccel : public BLEAdafruitSensor
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLECharacteristic Accel;
BLEAdafruitAccel(void);
virtual err_t begin(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUITACCEL_H_ */
#endif /* BLEADAFRUIT_ACCEL_H_ */
@@ -109,9 +109,9 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf
// Add Characteristic
_data.setProperties(CHR_PROPS_WRITE);
_data.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN);
// Change to use VLOC STACK to USER due to lack of memroy
// Data.setMaxLen(Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH));
_data.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
// start (2 byte) + flags (1 byte)
// TODO: for backward compatible with current CPB app, force to at least 10 pixels
_data.setMaxLen(3 + 30 /* bufsize */);
VERIFY_STATUS( _data.begin() );
// Add Characteristic
@@ -126,28 +126,34 @@ err_t BLEAdafruitAddressablePixel::begin(uint8_t pin, uint8_t type, uint16_t buf
return ERROR_NONE;
}
//--------------------------------------------------------------------+
// Static callbacks
//--------------------------------------------------------------------+
void BLEAdafruitAddressablePixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
void BLEAdafruitAddressablePixel::_pixel_write_handler(uint16_t conn_hdl, uint8_t* data, uint16_t len)
{
(void) conn_hdl;
if (len < 3) return;
BLEAdafruitAddressablePixel& svc = (BLEAdafruitAddressablePixel&) chr->parentService();
uint16_t index;
memcpy(&index, data, 2);
uint8_t flag = data[2];
uint8_t* buffer = svc._neo->getPixels() + index;
// pixel staring buffer
uint8_t* pixbuf = _neo->getPixels() + index;
memcpy(buffer, data+3, len-3);
// limit copied bytes up to strip's boundary
uint16_t copied_count = max16(_bufsize.read16(), index) - index;
copied_count = min16(len-3, copied_count);
if (copied_count) memcpy(pixbuf, data+3, copied_count);
// show flag
if ( flag & 0x01 )
{
svc._neo->show();
}
if ( flag & 0x01 ) _neo->show();
}
//--------------------------------------------------------------------+
// Static callbacks
//--------------------------------------------------------------------+
void BLEAdafruitAddressablePixel::pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
{
BLEAdafruitAddressablePixel& svc = (BLEAdafruitAddressablePixel&) chr->parentService();
svc._pixel_write_handler(conn_hdl, data, len);
}
@@ -22,10 +22,10 @@
* THE SOFTWARE.
*/
#ifndef BLEADAFRUITADDRESSABLEPIXEL_H_
#define BLEADAFRUITADDRESSABLEPIXEL_H_
#ifndef BLEADAFRUIT_ADDRESSABLEPIXEL_H_
#define BLEADAFRUIT_ADDRESSABLEPIXEL_H_
#include "Adafruit_NeoPixel.h"
#include <Adafruit_NeoPixel.h>
class BLEAdafruitAddressablePixel : public BLEService
{
@@ -49,9 +49,11 @@ class BLEAdafruitAddressablePixel : public BLEService
err_t begin(uint8_t pin, uint8_t type, uint16_t bufsize);
void _pixel_write_handler(uint16_t conn_hdl, uint8_t* data, uint16_t len);
static void pixel_data_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
};
#endif /* BLEADAFRUITADDRESSABLEPIXEL_H_ */
#endif /* BLEADAFRUIT_ADDRESSABLEPIXEL_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Barometric service 0800
* - Pressure 0801 | float[3] | Read + Notify | x, y, z
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitBaro::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x08, 0xAF, 0xAD
};
const uint8_t BLEAdafruitBaro::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x08, 0xAF, 0xAD
};
// Constructor
BLEAdafruitBaro::BLEAdafruitBaro(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4);
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_BARO_H_
#define BLEADAFRUIT_BARO_H_
class BLEAdafruitBaro : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitBaro(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_BARO_H_ */
@@ -56,18 +56,9 @@ const uint8_t BLEAdafruitButton::UUID128_CHR_DATA[16] =
// Constructor
BLEAdafruitButton::BLEAdafruitButton(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
}
err_t BLEAdafruitButton::begin(void)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4);
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
VERIFY_STATUS( BLEAdafruitSensor::begin(100) );
return ERROR_NONE;
}
@@ -22,8 +22,8 @@
* THE SOFTWARE.
*/
#ifndef BLE_ADAFRUIT_BUTTON_H_
#define BLE_ADAFRUIT_BUTTON_H_
#ifndef BLEADAFRUIT_BUTTON_H_
#define BLEADAFRUIT_BUTTON_H_
class BLEAdafruitButton : public BLEAdafruitSensor
{
@@ -32,7 +32,8 @@ class BLEAdafruitButton : public BLEAdafruitSensor
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitButton(void);
virtual err_t begin(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLE_ADAFRUIT_BUTTON_H_ */
#endif /* BLEADAFRUIT_BUTTON_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Color service 0A00
* - Color 0A01 | uint16_t[3] | Read + Notify | Red, Green, Blue each is 16-bit color
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitColor::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0A, 0xAF, 0xAD
};
const uint8_t BLEAdafruitColor::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0A, 0xAF, 0xAD
};
// Constructor
BLEAdafruitColor::BLEAdafruitColor(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(2*3);
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_COLOR_H_
#define BLEADAFRUIT_COLOR_H_
class BLEAdafruitColor : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitColor(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_COLOR_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Gesture service 06F00
* - Button 0F01 | unt8_t | Read + Notify | e.g 0: no gesture, 1: Up, 2: Down, 3: Left, 4: Right
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitGesture::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0F, 0xAF, 0xAD
};
const uint8_t BLEAdafruitGesture::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0F, 0xAF, 0xAD
};
// Constructor
BLEAdafruitGesture::BLEAdafruitGesture(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(1);
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_GESTURE_H_
#define BLEADAFRUIT_GESTURE_H_
class BLEAdafruitGesture : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitGesture(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_GESTURE_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Gyroscope service 0400
* - Gyro 0401 | float[3] | Read + Notify | x, y, z
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitGyro::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x04, 0xAF, 0xAD
};
const uint8_t BLEAdafruitGyro::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x04, 0xAF, 0xAD
};
// Constructor
BLEAdafruitGyro::BLEAdafruitGyro(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4*3); // float[3]
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_GYRO_H_
#define BLEADAFRUIT_GYRO_H_
class BLEAdafruitGyro : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitGyro(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_GYRO_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Humidity service 0700
* - Humid 0701 | float[3] | Read + Notify | x, y, z
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitHumid::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x07, 0xAF, 0xAD
};
const uint8_t BLEAdafruitHumid::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x07, 0xAF, 0xAD
};
// Constructor
BLEAdafruitHumid::BLEAdafruitHumid(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4);
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_HUMID_H_
#define BLEADAFRUIT_HUMID_H_
class BLEAdafruitHumid : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitHumid(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_HUMID_H_ */
@@ -56,19 +56,9 @@ const uint8_t BLEAdafruitLightSensor::UUID128_CHR_DATA[16] =
// Constructor
BLEAdafruitLightSensor::BLEAdafruitLightSensor(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
}
err_t BLEAdafruitLightSensor::begin (void)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4);
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
return ERROR_NONE;
}
@@ -22,8 +22,8 @@
* THE SOFTWARE.
*/
#ifndef BLE_ADAFRUIT_LIGHT_SENSOR_H_
#define BLE_ADAFRUIT_LIGHT_SENSOR_H_
#ifndef BLEADAFRUIT_LIGHT_SENSOR_H_
#define BLEADAFRUIT_LIGHT_SENSOR_H_
class BLEAdafruitLightSensor : public BLEAdafruitSensor
{
@@ -31,10 +31,9 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLECharacteristic Lux;
BLEAdafruitLightSensor(void);
virtual err_t begin(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLE_ADAFRUIT_LIGHT_SENSOR_H_ */
#endif /* BLEADAFRUIT_LIGHT_SENSOR_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Magnetic service 0500
* - Magnetic 0501 | float[3] | Read + Notify | x, y, z
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitMagnetic::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x05, 0xAF, 0xAD
};
const uint8_t BLEAdafruitMagnetic::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x05, 0xAF, 0xAD
};
// Constructor
BLEAdafruitMagnetic::BLEAdafruitMagnetic(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4*3); // float[3]
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_MAGNETIC_H_
#define BLEADAFRUIT_MAGNETIC_H_
class BLEAdafruitMagnetic : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitMagnetic(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_MAGNETIC_H_ */
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Accelerometer service 0E00
* - Data 0E01 | uint16_t | Read + Notify | unit-less
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitProximity::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0E, 0xAF, 0xAD
};
const uint8_t BLEAdafruitProximity::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0E, 0xAF, 0xAD
};
// Constructor
BLEAdafruitProximity::BLEAdafruitProximity(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(2);
}
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_PROXIMITY_H_
#define BLEADAFRUIT_PROXIMITY_H_
class BLEAdafruitProximity : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitProximity(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUIT_PROXIMITY_H_ */
@@ -0,0 +1,201 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
#include <Adafruit_AHRS.h>
#include <Adafruit_Sensor_Calibration.h>
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Quaternion service 0D00
* - Quater #include <Adafruit> 0D01 | float[4] | Read + Notify | qw, qx, qy, qz
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitQuaternion::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0D, 0xAF, 0xAD
};
const uint8_t BLEAdafruitQuaternion::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0D, 0xAF, 0xAD
};
// Constructor
BLEAdafruitQuaternion::BLEAdafruitQuaternion(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
_accel = _gyro = _mag = NULL;
_filter = NULL;
_calib = NULL;
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4*4);
}
err_t BLEAdafruitQuaternion::begin(Adafruit_AHRS_FusionInterface* filter, Adafruit_Sensor* accel, Adafruit_Sensor* gyro, Adafruit_Sensor* mag)
{
_filter = filter;
_accel = accel;
_gyro = gyro;
_mag = mag;
int32_t const period_ms = 100;
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
VERIFY_STATUS( BLEAdafruitSensor::_begin(period_ms) );
// filter timer run faster than measurement timer, but not too fast
int32_t const filter_ms = maxof(10, period_ms / FUSION_MEASURE_RATIO);
_filter_timer.begin(filter_ms, quaternion_filter_timer_cb, this, true);
_filter->begin(1000.0f/filter_ms);
return ERROR_NONE;
}
void BLEAdafruitQuaternion::setCalibration(Adafruit_Sensor_Calibration* calib)
{
_calib = calib;
}
void BLEAdafruitQuaternion::_notify_handler(uint16_t conn_hdl, uint16_t value)
{
// Start/Stop filter timer
if (value & BLE_GATT_HVX_NOTIFICATION)
{
_filter_timer.start();
}else
{
_filter_timer.stop();
}
// Call SuperClass function
BLEAdafruitSensor::_notify_handler(conn_hdl, value);
}
void BLEAdafruitQuaternion::_update_timer(int32_t ms)
{
int32_t const filter_ms = maxof(10, ms / FUSION_MEASURE_RATIO);
if ( filter_ms < 0 )
{
_filter_timer.stop();
}else if ( filter_ms > 0)
{
_filter_timer.setPeriod(filter_ms);
_filter->begin(1000.0f/filter_ms); // need to also change the sample frequency
}else
{
// Period = 0: keeping the current interval, but report on changes only
// Not applicable for this service
}
// Call SuperClass function
BLEAdafruitSensor::_update_timer(ms);
}
#if CFG_DEBUG
static void print_quaternion(float quater[4])
{
Serial.printf("Quaternion: %.04f, %.04f, %.04f, %.04f\n", quater[0], quater[1], quater[2], quater[3]);
}
#endif
// Invoked by period timer in Base class
// Note invoked in RTOS Timer thread
void BLEAdafruitQuaternion::_measure_handler(void)
{
float quater[4]; // w, x, y, z
_filter->getQuaternion(&quater[0], &quater[1], &quater[2], &quater[3]);
// TODO multiple connections
_measurement.notify(quater, sizeof(quater));
#if CFG_DEBUG
ada_callback(quater, sizeof(quater), print_quaternion, quater);
#endif
}
// Fusion Filter update
// This function take ~ 1-2 ms to get all sensor data
void BLEAdafruitQuaternion::_fitler_update(void)
{
// get sensor events
sensors_event_t accel_evt, gyro_evt, mag_evt;
// int start_ms = millis();
_accel->getEvent(&accel_evt);
_gyro->getEvent(&gyro_evt);
_mag->getEvent(&mag_evt);
// calibrate sensor if available
if (_calib)
{
_calib->calibrate(accel_evt);
_calib->calibrate(gyro_evt);
_calib->calibrate(mag_evt);
}
// Convert gyro from Rad/s to Degree/s
gyro_evt.gyro.x *= SENSORS_RADS_TO_DPS;
gyro_evt.gyro.y *= SENSORS_RADS_TO_DPS;
gyro_evt.gyro.z *= SENSORS_RADS_TO_DPS;
// apply filter
_filter->update(gyro_evt.gyro.x , gyro_evt.gyro.y, gyro_evt.gyro.z,
accel_evt.acceleration.x, accel_evt.acceleration.y, accel_evt.acceleration.z,
mag_evt.magnetic.x, mag_evt.magnetic.y, mag_evt.magnetic.z);
// start_ms = millis() - start_ms;
// PRINT_INT(start_ms);
}
//--------------------------------------------------------------------+
// Static Methods
//--------------------------------------------------------------------+
void BLEAdafruitQuaternion::quaternion_filter_timer_cb(TimerHandle_t xTimer)
{
BLEAdafruitQuaternion* svc = (BLEAdafruitQuaternion*) pvTimerGetTimerID(xTimer);
svc->_fitler_update();
}
@@ -0,0 +1,63 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_QUATERNION_H_
#define BLEADAFRUIT_QUATERNION_H_
// forward declaration
class Adafruit_AHRS_FusionInterface;
class Adafruit_Sensor_Calibration;
class BLEAdafruitQuaternion : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
static const uint8_t FUSION_MEASURE_RATIO = 10; // number of filter update for each measure report to client
BLEAdafruitQuaternion(void);
err_t begin(Adafruit_AHRS_FusionInterface* filter, Adafruit_Sensor* accel, Adafruit_Sensor* gyro, Adafruit_Sensor* mag);
void setCalibration(Adafruit_Sensor_Calibration* calib);
protected:
void _update_timer(int32_t ms);
void _measure_handler(void);
void _notify_handler(uint16_t conn_hdl, uint16_t value);
void _fitler_update(void);
private:
Adafruit_Sensor* _accel;
Adafruit_Sensor* _gyro;
Adafruit_Sensor* _mag;
Adafruit_AHRS_FusionInterface* _filter;
Adafruit_Sensor_Calibration* _calib;
SoftwareTimer _filter_timer;
// filter timer callback, 10x faster than period timer
static void quaternion_filter_timer_cb(TimerHandle_t xTimer);
};
#endif /* BLEADAFRUIT_QUATERNION_H_ */
@@ -31,22 +31,19 @@
BLEAdafruitSensor::BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid)
: BLEService(service_uuid), _measurement(data_uuid), _period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
{
_sensor = NULL;
_measure_cb = NULL;
_notify_cb = NULL;
}
void BLEAdafruitSensor::setMeasureCallback(measure_callback_t fp)
{
_measure_cb = fp;
}
err_t BLEAdafruitSensor::begin(int32_t ms)
err_t BLEAdafruitSensor::_begin(int32_t ms)
{
// Invoke base class begin()
VERIFY_STATUS( BLEService::begin() );
_measurement.setCccdWriteCallback(sensor_data_cccd_cb, true);
VERIFY_STATUS( _measurement.begin() );
_measurement.write32(0); // zero 4 bytes could help to init some services
_period.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
_period.setPermission(SECMODE_OPEN, SECMODE_OPEN);
@@ -62,27 +59,55 @@ err_t BLEAdafruitSensor::begin(int32_t ms)
return ERROR_NONE;
}
err_t BLEAdafruitSensor::begin(measure_callback_t fp, int32_t ms)
{
_measure_cb = fp;
return _begin(ms);
}
err_t BLEAdafruitSensor::begin(Adafruit_Sensor* sensor, int32_t ms)
{
_sensor = sensor;
return _begin(ms);
}
void BLEAdafruitSensor::setPeriod(int32_t period_ms)
{
_period.write32(period_ms);
_update_timer(period_ms);
}
void BLEAdafruitSensor::startMeasuring(void)
void BLEAdafruitSensor::setNotifyCallback(notify_callback_t fp)
{
_timer.start();
_notify_cb = fp;
}
void BLEAdafruitSensor::stopMeasuring(void)
//--------------------------------------------------------------------+
// Internal API
//--------------------------------------------------------------------+
void BLEAdafruitSensor::_notify_handler(uint16_t conn_hdl, uint16_t value)
{
_timer.stop();
}
// notify enabled
if (value & BLE_GATT_HVX_NOTIFICATION)
{
_timer.start();
}else
{
_timer.stop();
}
// invoke callback if any
if (_notify_cb) _notify_cb(conn_hdl, value);
// send initial notification if period = 0
// if ( 0 == svc._period.read32() )
// {
// svc._measurement.notify();
// }
}
void BLEAdafruitSensor::_update_timer(int32_t ms)
{
// TODO handle period = 0 which notify on changes ASAP
if ( ms < 0 )
{
_timer.stop();
@@ -95,26 +120,45 @@ void BLEAdafruitSensor::_update_timer(int32_t ms)
}
}
void BLEAdafruitSensor::_timer_callback(void)
void BLEAdafruitSensor::_measure_handler(void)
{
if (_measure_cb)
uint16_t len = _measurement.getMaxLen();
uint8_t buf[len];
// Use unified sensor API if available, only with fixed length sensor
if (_sensor && _measurement.isFixedLen())
{
uint8_t buf[_measurement.getMaxLen()];
uint16_t len = _measure_cb(buf, sizeof(buf));
len = min(len, sizeof(buf));
sensors_event_t event;
_sensor->getEvent(&event);
// Period = 0, compare with old data, only update on changes
if ( 0 == _period.read32() )
{
uint8_t prev_buf[_measurement.getMaxLen()];
_measurement.read(prev_buf, sizeof(prev_buf));
// skip notify if there is no changes
if ( 0 == memcmp(prev_buf, buf, len) ) return;
}
_measurement.notify(buf, len);
memcpy(buf, event.data, len);
}
// Else use callback
else if (_measure_cb)
{
len = _measure_cb(buf, sizeof(buf));
len = min(len, sizeof(buf));
}
else
{
return; // nothing to measure
}
// no data to notify
if (!len) return;
// Period = 0, compare with old data, only update on changes
if ( 0 == _period.read32() )
{
uint8_t prev_buf[_measurement.getMaxLen()];
_measurement.read(prev_buf, sizeof(prev_buf));
// skip notify if there is no changes
if ( 0 == memcmp(prev_buf, buf, len) ) return;
}
// TODO multiple connections
_measurement.notify(buf, len);
}
//--------------------------------------------------------------------+
@@ -124,37 +168,25 @@ void BLEAdafruitSensor::_timer_callback(void)
void BLEAdafruitSensor::sensor_timer_cb(TimerHandle_t xTimer)
{
BLEAdafruitSensor* svc = (BLEAdafruitSensor*) pvTimerGetTimerID(xTimer);
svc->_timer_callback();
svc->_measure_handler();
}
// Client update period, adjust timer accordingly
void BLEAdafruitSensor::sensor_period_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
{
BLEAdafruitSensor& svc = (BLEAdafruitSensor&) chr->parentService();
(void) conn_hdl;
BLEAdafruitSensor* svc = (BLEAdafruitSensor*) &chr->parentService();
int32_t ms = 0;
memcpy(&ms, data, len);
svc._update_timer(ms);
svc->_update_timer(ms);
}
void BLEAdafruitSensor::sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value)
{
BLEAdafruitSensor& svc = (BLEAdafruitSensor&) chr->parentService();
BLEAdafruitSensor* svc = (BLEAdafruitSensor*) &chr->parentService();
// notify enabled
if (value & BLE_GATT_HVX_NOTIFICATION)
{
svc._timer.start();
}else
{
svc._timer.stop();
}
// send initial notification if period = 0
// if ( 0 == svc._period.read32() )
// {
// svc._measurement.notify();
// }
svc->_notify_handler(conn_hdl, value);
}
@@ -22,36 +22,47 @@
* THE SOFTWARE.
*/
#ifndef BLE_ADAFRUIT_SENSOR_H_
#define BLE_ADAFRUIT_SENSOR_H_
#ifndef BLEADAFRUIT_SENSOR_H_
#define BLEADAFRUIT_SENSOR_H_
#include <Adafruit_Sensor.h>
class BLEAdafruitSensor : public BLEService
{
public:
static const int32_t DEFAULT_PERIOD = 1000;
typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled);
typedef uint16_t (*measure_callback_t )(uint8_t* buf, uint16_t bufsize);
BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid);
virtual err_t begin(int32_t ms);
void setMeasureCallback(measure_callback_t fp);
virtual err_t begin(measure_callback_t fp, int32_t ms = DEFAULT_PERIOD);
virtual err_t begin(Adafruit_Sensor* sensor, int32_t ms = DEFAULT_PERIOD);
void setPeriod(int32_t period_ms);
void startMeasuring(void);
void stopMeasuring(void);
void setNotifyCallback(notify_callback_t fp);
protected:
BLECharacteristic _period;
BLECharacteristic _measurement;
Adafruit_Sensor* _sensor;
measure_callback_t _measure_cb;
notify_callback_t _notify_cb;
SoftwareTimer _timer;
void _update_timer(int32_t ms);
void _timer_callback(void);
err_t _begin(int32_t ms);
virtual void _update_timer(int32_t ms);
virtual void _measure_handler(void);
virtual void _notify_handler(uint16_t conn_hdl, uint16_t value);
static void sensor_timer_cb(TimerHandle_t xTimer);
static void sensor_period_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
static void sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value);
};
#endif /* BLE_ADAFRUIT_SENSOR_H_ */
#endif /* BLEADAFRUIT_SENSOR_H_ */
@@ -0,0 +1,88 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "BLEAdafruitService.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
* ADAFxxx-C332-42A8-93BD-25E905756CB8
*
* Shared Characteristics
* - Measurement Period 0001 | int32_t | Read + Write |
* ms between measurements, -1: stop reading, 0: update when changes
*
* Sound service 0B00
* - Sound Samples 0B01 | int16_t[] | Read + Notify | samples, if dual channel then Left, Right, Left, Right ...
* - Number Channels 0B02 | uint8_t | Read | 1 for mono, 2 for dual
* - Measurement Period 0001
*/
const uint8_t BLEAdafruitSound::UUID128_SERVICE[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x0B, 0xAF, 0xAD
};
const uint8_t BLEAdafruitSound::UUID128_CHR_DATA[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x0B, 0xAF, 0xAD
};
const uint8_t BLEAdafruitSound::UUID128_CHR_CHANNEL_COUNT[16] =
{
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
0xA8, 0x42, 0x32, 0xC3, 0x02, 0x0B, 0xAF, 0xAD
};
// Constructor
BLEAdafruitSound::BLEAdafruitSound(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA), _channel_count(UUID128_CHR_CHANNEL_COUNT)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
// channel count Characteristic
_channel_count.setProperties(CHR_PROPS_READ);
_channel_count.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_channel_count.setFixedLen(1);
}
err_t BLEAdafruitSound::begin(uint8_t channel_count, measure_callback_t fp, int32_t ms)
{
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
VERIFY_STATUS( BLEAdafruitSensor::begin(fp, ms) );
// Add channel count Characteristic
VERIFY_STATUS( _channel_count.begin() );
_channel_count.write8(channel_count);
return ERROR_NONE;
}
@@ -0,0 +1,43 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef BLEADAFRUIT_SOUND_H_
#define BLEADAFRUIT_SOUND_H_
class BLEAdafruitSound : public BLEAdafruitSensor
{
public:
static const uint8_t UUID128_SERVICE[16];
static const uint8_t UUID128_CHR_DATA[16];
static const uint8_t UUID128_CHR_CHANNEL_COUNT[16];
BLEAdafruitSound(void);
err_t begin(uint8_t channel_count, measure_callback_t fp, int32_t ms = DEFAULT_PERIOD);
private:
BLECharacteristic _channel_count;
};
#endif /* BLEADAFRUIT_SOUND_H_ */
@@ -55,19 +55,10 @@ const uint8_t BLEAdafruitTemperature::UUID128_CHR_DATA[16] =
// Constructor
BLEAdafruitTemperature::BLEAdafruitTemperature(void)
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
{
}
err_t BLEAdafruitTemperature::begin (void)
{
// Setup Measurement Characteristic
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
_measurement.setFixedLen(4);
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
VERIFY_STATUS( BLEAdafruitSensor::begin(1000) );
return ERROR_NONE;
}
@@ -22,8 +22,8 @@
* THE SOFTWARE.
*/
#ifndef BLEADAFRUITTEMPERATURE_H_
#define BLEADAFRUITTEMPERATURE_H_
#ifndef BLEADAFRUIT_TEMPERATURE_H_
#define BLEADAFRUIT_TEMPERATURE_H_
class BLEAdafruitTemperature : public BLEAdafruitSensor
{
@@ -32,7 +32,8 @@ class BLEAdafruitTemperature : public BLEAdafruitSensor
static const uint8_t UUID128_CHR_DATA[16];
BLEAdafruitTemperature();
virtual err_t begin(void);
using BLEAdafruitSensor::begin;
};
#endif /* BLEADAFRUITTEMPERATURE_H_ */
#endif /* BLEADAFRUIT_TEMPERATURE_H_ */
@@ -60,6 +60,9 @@ err_t BLEAdafruitTone::begin(int pin)
_tone.setWriteCallback(tone_write_cb, true);
VERIFY_STATUS( _tone.begin() );
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
return ERROR_NONE;
}
@@ -79,11 +82,14 @@ void BLEAdafruitTone::tone_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, u
memcpy(&tone_data, data, len);
// frequency = 0 means no tone
int pin = svc._pin;
if (tone_data.freq == 0)
{
noTone(svc._pin);
noTone(pin);
digitalWrite(pin, LOW);
}else
{
tone(svc._pin, tone_data.freq, tone_data.duration);
tone(pin, tone_data.freq, tone_data.duration);
}
}
@@ -22,8 +22,8 @@
* THE SOFTWARE.
*/
#ifndef BLEADAFRUITTONE_H_
#define BLEADAFRUITTONE_H_
#ifndef BLEADAFRUIT_TONE_H_
#define BLEADAFRUIT_TONE_H_
class BLEAdafruitTone : public BLEService
{
@@ -41,4 +41,4 @@ class BLEAdafruitTone : public BLEService
static void tone_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
};
#endif /* BLEADAFRUITTONE_H_ */
#endif /* BLEADAFRUIT_TONE_H_ */
@@ -24,7 +24,7 @@ BLEBas blebas; // battery
void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
// while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("Bluefruit52 BLEUART Example");
Serial.println("---------------------------\n");
@@ -0,0 +1,495 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
/* This sketch demonstrate the BLE Adafruit Service that is used with
* "Adafruit Bluefruit Playground" app. Supported boards are
* - Circuit Playground Bluefruit : https://www.adafruit.com/product/4333
* - CLUE nRF52840 : https://www.adafruit.com/product/4500
* - Feather Sense : https://www.adafruit.com/product/4516
*/
#include <SPI.h>
#include <SdFat.h>
#include <PDM.h>
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>
#include <bluefruit.h>
#include <BLEAdafruitService.h>
//------------- Circuit Playground Bluefruit -------------//
#if defined(ARDUINO_NRF52840_CIRCUITPLAY)
#include <Adafruit_CircuitPlayground.h>
#define DEVICE_NAME "CPlay"
#define NEOPIXEL_COUNT 10
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
{
float temp = CircuitPlayground.temperature();
memcpy(buf, &temp, 4);
return 4;
}
uint16_t measure_light(uint8_t* buf, uint16_t bufsize)
{
float lux;
lux = CircuitPlayground.lightSensor();
memcpy(buf, &lux, 4);
return 4;
}
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
{
uint32_t button = 0;
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
memcpy(buf, &button, 4);
return 4;
}
//------------- CLUE & Feather Sense -------------//
#elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
#include <Adafruit_APDS9960.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_LIS3MDL.h>
#include <Adafruit_LSM6DS33.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_SPIFlash.h>
#include <Adafruit_AHRS.h>
#include <Adafruit_Sensor_Calibration.h>
#if defined(ARDUINO_NRF52840_CLUE)
#define DEVICE_NAME "CLUE"
#else
#define DEVICE_NAME "Sense"
#endif
#define NEOPIXEL_COUNT 1
BLEAdafruitBaro bleBaro;
BLEAdafruitColor bleColor;
BLEAdafruitGesture bleGesture;
BLEAdafruitHumid bleHumid;
BLEAdafruitProximity bleProximity;
BLEAdafruitQuaternion bleQuater;
Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel
Adafruit_LIS3MDL lis3mdl; // Magnetometer
Adafruit_APDS9960 apds9960; // Proximity, Light, Gesture, Color
Adafruit_BMP280 bmp280; // Temperature, Barometric
Adafruit_SHT31 sht30; // Humid
// pick your filter! slower == better quality output
//Adafruit_NXPSensorFusion filter; // slowest
//Adafruit_Madgwick filter; // faster than NXP
Adafruit_Mahony filter; // fastest/smalleset
// Sensor calibration
#define FILE_SENSOR_CALIB "sensor_calib.json"
Adafruit_Sensor_Calibration_SDFat cal;
Adafruit_FlashTransport_QSPI flashTransport;
Adafruit_SPIFlash flash(&flashTransport);
FatFileSystem fatfs;
void light_enable_callback(uint16_t conn_hdl, bool enabled)
{
(void) conn_hdl;
apds9960.enableColor(enabled);
}
uint16_t measure_light(uint8_t* buf, uint16_t bufsize)
{
float lux;
uint16_t r, g, b, c;
apds9960.getColorData(&r, &g, &b, &c);
lux = c;
memcpy(buf, &lux, 4);
return 4;
}
void color_enable_callback(uint16_t conn_hdl, bool enabled)
{
(void) conn_hdl;
apds9960.enableColor(enabled);
#ifdef ARDUINO_NRF52840_CLUE
digitalWrite(PIN_LED2, enabled);
#endif
}
uint16_t measure_color(uint8_t* buf, uint16_t bufsize)
{
uint16_t rgb[3];
uint16_t c;
(void) c;
apds9960.getColorData(rgb+0, rgb+1, rgb+2, &c);
memcpy(buf, rgb, sizeof(rgb));
return sizeof(rgb);
}
void gesture_enable_callback(uint16_t conn_hdl, bool enabled)
{
(void) conn_hdl;
apds9960.enableProximity(enabled);
apds9960.enableGesture(enabled);
}
uint16_t measure_gesture(uint8_t* buf, uint16_t bufsize)
{
uint8_t gesture = apds9960.readGesture();
if (gesture == 0) return 0; // skip no gesture value
// APDS9960 sensor position is rotated 90 degree left on CLUE
// We will need to correct that by rotating right for user convenience
uint8_t const clue_rotation[] = { 0, APDS9960_LEFT, APDS9960_RIGHT, APDS9960_DOWN, APDS9960_UP };
buf[0] = clue_rotation[gesture];
return 1;
}
void proximity_enable_callback(uint16_t conn_hdl, bool enabled)
{
(void) conn_hdl;
apds9960.enableProximity(enabled);
}
uint16_t measure_proximity(uint8_t* buf, uint16_t bufsize)
{
// APDS is only 8-bit, we better to map it to 16-bit value
uint8_t data8 = apds9960.readProximity();
uint16_t data16 = (uint16_t) map(data8, 0, UINT8_MAX, 0, UINT16_MAX);
memcpy(buf, &data16, 2);
return 2;
}
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
{
// Button is active LOW on most board except CPlay
// No slide switch
uint32_t button = 0;
button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 );
#if defined(PIN_BUTTON2)
button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 );
#endif
memcpy(buf, &button, 4);
return 4;
}
uint16_t measure_humid(uint8_t* buf, uint16_t bufsize)
{
float humid = sht30.readHumidity();
memcpy(buf, &humid, 4);
return 4;
}
#else
#error "Board is not supported"
#endif // end of board
//--------------------------------------------------------------------+
// Common for all Boards
//--------------------------------------------------------------------+
// BLE Service
BLEDfu bledfu; // OTA DFU service
BLEDis bledis; // device information
BLEUart bleuart; // uart over ble
BLEBas blebas; // battery
// Adafruit Service: ADAFxx-C332-42A8-93BD-25E905756CB8
BLEAdafruitTemperature bleTemp;
BLEAdafruitAccel bleAccel;
BLEAdafruitLightSensor bleLight;
BLEAdafruitButton bleButton;
BLEAdafruitTone bleTone;
BLEAdafruitAddressablePixel blePixel;
BLEAdafruitSound bleSound;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
int16_t pdmSample[256]; // sound samples
uint16_t pdmByteCount = 0;
//void pdm_plotter(uint16_t count)
//{
// for (int i = 0; i < count/2; i++) Serial.println(pdmSample[i]);
//}
uint16_t measure_sound(uint8_t* buf, uint16_t bufsize)
{
uint16_t const len = min(bufsize, pdmByteCount);
if ( len ) memcpy(buf, pdmSample, len);
pdmByteCount = 0; // clear count
// if (len) ada_callback(NULL, 0, pdm_plotter, len);
return len;
}
//--------------------------------------------------------------------+
// Codes
//--------------------------------------------------------------------+
void setup()
{
Adafruit_Sensor* accel_sensor;
Serial.begin(115200);
// while(!Serial) delay(10); // wait for native USB
#if defined ARDUINO_NRF52840_CIRCUITPLAY
CircuitPlayground.begin();
accel_sensor = &CircuitPlayground.lis;
#else
// Button
pinMode(PIN_BUTTON1, INPUT_PULLUP);
#if defined(PIN_BUTTON2)
pinMode(PIN_BUTTON2, INPUT_PULLUP);
#endif
#ifdef ARDUINO_NRF52840_CLUE
// White LEDs for color sensing
pinMode(PIN_LED2, OUTPUT);
digitalWrite(PIN_LED2, LOW);
#endif
apds9960.begin();
bmp280.begin();
sht30.begin(0x44);
lsm6ds33.begin_I2C();
lis3mdl.begin_I2C();
// set lowest range
lsm6ds33.setAccelRange(LSM6DS_ACCEL_RANGE_2_G);
lsm6ds33.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS);
lis3mdl.setRange(LIS3MDL_RANGE_4_GAUSS);
// set slightly above refresh rate
lsm6ds33.setAccelDataRate(LSM6DS_RATE_104_HZ);
lsm6ds33.setGyroDataRate(LSM6DS_RATE_104_HZ);
lis3mdl.setDataRate(LIS3MDL_DATARATE_1000_HZ);
lis3mdl.setPerformanceMode(LIS3MDL_MEDIUMMODE);
lis3mdl.setOperationMode(LIS3MDL_CONTINUOUSMODE);
// Increase I2C speed to 400 Khz
Wire.setClock(400000);
accel_sensor = lsm6ds33.getAccelerometerSensor();
// Init flash, filesystem and calibration & load calib json
flash.begin();
fatfs.begin(&flash);
cal.begin(FILE_SENSOR_CALIB, &fatfs);
cal.loadCalibration();
#endif
// 1 channel (mono mode) with 16 kHz sample rate
PDM.onReceive(onPDMdata);
PDM.begin(1, 16000);
Serial.println("Bluefruit Playground Example");
Serial.println("---------------------------\n");
// Setup the BLE LED to be enabled on CONNECT
// Note: This is actually the default behaviour, but provided
// here in case you want to control this LED manually via PIN 19
Bluefruit.autoConnLed(false);
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.begin();
Bluefruit.setTxPower(8); // Check bluefruit.h for supported values
Bluefruit.setName(DEVICE_NAME);
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
// To be consistent OTA DFU should be added first if it exists
bledfu.begin();
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
// Start BLE Battery Service
blebas.begin();
blebas.write(100);
//------------- Adafruit Service -------------//
bleAccel.begin(accel_sensor, 100); // TODO dropped in favor to Quaternion service for CLUE & Sense
bleButton.begin(measure_button, 100);
bleButton.setPeriod(0); // only notify if there is changes with buttons
strip.begin();
blePixel.begin(&strip);
bleSound.begin(1, measure_sound, 100);
// CPB doesn't support these on-board sensor
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
bleLight.begin(measure_light, 100);
bleTemp.begin(measure_temperature, 100);
#else
bleBaro.begin(bmp280.getPressureSensor(), 100);
bleColor.begin(measure_color, 100);
bleColor.setNotifyCallback(color_enable_callback);
bleGesture.begin(measure_gesture, 10); // sampling is 10 ms
bleGesture.setPeriod(0); // notify on changes only
bleGesture.setNotifyCallback(gesture_enable_callback);
bleHumid.begin(measure_humid, 100);
bleLight.begin(measure_light, 100);;
bleLight.setNotifyCallback(light_enable_callback);
bleProximity.begin(measure_proximity, 100);
bleProximity.setNotifyCallback(proximity_enable_callback);
// Quaternion with sensor calibration
bleQuater.begin(&filter, accel_sensor, lsm6ds33.getGyroSensor(), &lis3mdl);
bleQuater.setCalibration(&cal);
bleTemp.begin(bmp280.getTemperatureSensor(), 100);
#endif
#if defined(PIN_BUZZER)
bleTone.begin(PIN_BUZZER);
#endif
// Set up and start advertising
startAdv();
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
Serial.println("Once connected, enter character(s) that you wish to send");
}
void startAdv(void)
{
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
// Advertising with only board ID
struct ATTR_PACKED {
uint16_t mfr_id;
uint8_t field_len;
uint16_t field_key;
uint16_t field_value;
} mfr_adv;
mfr_adv.mfr_id = UUID16_COMPANY_ID_ADAFRUIT;
mfr_adv.field_len = 4;
mfr_adv.field_key = 1; // board id
mfr_adv.field_value = USB_PID;
Bluefruit.Advertising.addManufacturerData(&mfr_adv, sizeof(mfr_adv));
// Add name to advertising, since there is enough room
Bluefruit.Advertising.addName();
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
* https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
}
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
// Get the reference to current connection
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
/**
* Callback invoked when a connection is dropped
* @param conn_handle connection where this event happens
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
*/
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) conn_handle;
(void) reason;
#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
apds9960.enableGesture(false);
apds9960.enableProximity(false);
apds9960.enableColor(false);
#endif
#ifdef ARDUINO_NRF52840_CLUE
digitalWrite(PIN_LED2, LOW);
#endif
Serial.println();
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
void onPDMdata()
{
// query the number of bytes available
pdmByteCount = PDM.available();
// read into the sample buffer
PDM.read(pdmSample, pdmByteCount);
}
@@ -1,212 +0,0 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>
#include <bluefruit.h>
#include <BLEAdafruitService.h>
#include <Adafruit_CircuitPlayground.h>
// BLE Service
BLEDfu bledfu; // OTA DFU service
BLEDis bledis; // device information
BLEUart bleuart; // uart over ble
BLEBas blebas; // battery
// Adafruit Service: ADAFxx-C332-42A8-93BD-25E905756CB8
BLEAdafruitTemperature bleTemp;
BLEAdafruitAccel bleAccel;
BLEAdafruitLightSensor bleLight;
BLEAdafruitButton bleButton;
BLEAdafruitTone bleTone;
BLEAdafruitAddressablePixel blePixel;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, CPLAY_NEOPIXELPIN, NEO_GRB + NEO_KHZ800);
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
{
uint32_t button = 0;
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
memcpy(buf, &button, 4);
return 4;
}
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
{
float temp = CircuitPlayground.temperature();
memcpy(buf, &temp, 4);
return 4;
}
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
{
float lux = CircuitPlayground.lightSensor();
memcpy(buf, &lux, 4);
return 4;
}
uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
{
float accel[3];
accel[0] = CircuitPlayground.motionX();
accel[1] = CircuitPlayground.motionY();
accel[2] = CircuitPlayground.motionZ();
memcpy(buf, accel, sizeof(accel));
return sizeof(accel);
}
void setup()
{
Serial.begin(115200);
//while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("Bluefruit52 BLEUART Example");
Serial.println("---------------------------\n");
CircuitPlayground.begin();
// Setup the BLE LED to be enabled on CONNECT
// Note: This is actually the default behaviour, but provided
// here in case you want to control this LED manually via PIN 19
Bluefruit.autoConnLed(false);
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
Bluefruit.setName("Bluefruit52");
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
// To be consistent OTA DFU should be added first if it exists
bledfu.begin();
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
// Start BLE Battery Service
blebas.begin();
blebas.write(100);
// Adafruit Service
bleTemp.begin();
bleTemp.setMeasureCallback(measure_temperature);
bleAccel.begin();
bleAccel.setMeasureCallback(measure_accel);
bleLight.begin();
bleLight.setMeasureCallback(measure_light_sensor);
bleButton.begin();
bleButton.setMeasureCallback(measure_button);
bleButton.setPeriod(0); // only notify if there is changes with buttons
bleTone.begin(CPLAY_BUZZER);
strip.begin();
blePixel.begin(&strip);
// Set up and start advertising
startAdv();
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
Serial.println("Once connected, enter character(s) that you wish to send");
}
void startAdv(void)
{
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
// Advertising with only board ID
struct ATTR_PACKED {
uint16_t mfr_id;
uint8_t field_len;
uint16_t field_key;
uint16_t field_value;
} mfr_adv;
mfr_adv.mfr_id = UUID16_COMPANY_ID_ADAFRUIT;
mfr_adv.field_len = 4;
mfr_adv.field_key = 1; // board id
mfr_adv.field_value = USB_PID;
Bluefruit.Advertising.addManufacturerData(&mfr_adv, sizeof(mfr_adv));
// Secondary Scan Response packet (optional)
// Since there is no room for 'Name' in Advertising packet
Bluefruit.ScanResponse.addName();
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
* https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
}
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
// Get the reference to current connection
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
/**
* Callback invoked when a connection is dropped
* @param conn_handle connection where this event happens
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
*/
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) conn_handle;
(void) reason;
Serial.println();
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
@@ -61,9 +61,6 @@ uint32_t totalPixel = 0; // received pixel
// pixel line buffer, should be large enough to hold an image width
uint16_t pixel_buf[512];
// Use software timer to schedule bandwidth negotiation a few seconds after connection
SoftwareTimer negoTimer;
// Statistics for speed testing
uint32_t rxStartTime = 0;
uint32_t rxLastTime = 0;
@@ -112,9 +109,6 @@ void setup()
bleuart.setRxOverflowCallback(bleuart_overflow_callback);
// one-shot (non-repeating) 2 seconds timer
negoTimer.begin(2000, negotiate_bandwidth, NULL, false);
// Set up and start advertising
startAdv();
@@ -260,43 +254,8 @@ void bleuart_rx_callback(uint16_t conn_hdl)
}
}
void negotiate_bandwidth(TimerHandle_t xTimer)
{
(void) xTimer;
uint16_t conn_hdl = (uint16_t) ((uint32_t) negoTimer.getID());
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
// Switching from 1 Mb to 2 Mb PHY if needed
if ( conn->connected() )
{
// Requesting to Switching to 2MB PHY, larger data length and bigger MTU
// will increase the throughput on supported central. This should already
// be done with latest Bluefruit app.
//
// However, some Android devices require 2Mb PHY switching must be initiated
// from nRF side
if ( conn->getPHY() == BLE_GAP_PHY_1MBPS )
{
Serial.println("Requesting PHY change from 1 Mb to 2Mb");
conn->requestPHY();
// Data Length and MTU should already be done by Bluefruit app
// conn->requestDataLengthUpdate();
// conn->requestMtuExchange(247);
}
}
}
void connect_callback(uint16_t conn_handle)
{
// Set connection handle as timer ID
// Then schedule negotiation after a few seconds, we should not
// negotiate here since it increases chance to conflict with other
// on-going negotiation from central after connection
negoTimer.setID((void*) conn_handle);
negoTimer.start();
Serial.println("Connected");
Serial.println("Ready to receive new image");
}
@@ -18,53 +18,58 @@
/* This sketch demonstrates the "Image Upload" feature of Bluefruit Mobile App.
* Following TFT Display are supported
* - https://www.adafruit.com/product/3315
* - https://www.adafruit.com/product/3651
* - https://www.adafruit.com/product/4367
* - TFT 3.5" : FeatherWing https://www.adafruit.com/product/3651
* - TFT 2.4" : FeatherWing https://www.adafruit.com/product/3315
* - TFT Gizmo : https://www.adafruit.com/product/4367
* - Adafruit CLUE : https://www.adafruit.com/product/4500
*/
#define TFT_35_FEATHERWING 1
#define TFT_24_FEATHERWING 2
#define TFT_GIZMO 3
#if defined(ARDUINO_NRF52840_CIRCUITPLAY)
// Circuit Playground Bluefruit use with TFT GIZMO
#define DEVICE_NAME "CPLAY"
// [Configurable] Please select one of above supported Display to match your hardware setup
#define TFT_IN_USE TFT_35_FEATHERWING
#if defined(ARDUINO_NRF52832_FEATHER)
// Feather nRF52832
#define TFT_DC 11
#define TFT_CS 31
#elif defined(ARDUINO_NRF52840_CIRCUITPLAY)
// Circuit Playground Bluefruit for use with TFT 1.5" GIZMO
#define TFT_DC 1
#define TFT_CS 0
#define TFT_BACKLIGHT A3
#else
// Default for others
#define TFT_DC 10
#define TFT_CS 9
#endif
#if TFT_IN_USE == TFT_35_FEATHERWING
#include "Adafruit_HX8357.h"
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
#elif TFT_IN_USE == TFT_24_FEATHERWING
#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#elif TFT_IN_USE == TFT_GIZMO
#include "Adafruit_ST7789.h"
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1);
#else
#error "TFT display is not supported"
#endif
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI, 0, 1, -1); // CS = 0, DC = 1
#elif defined(ARDUINO_NRF52840_CLUE)
#define DEVICE_NAME "CLUE"
// CLUE use on-board TFT
#include "Adafruit_ST7789.h"
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST);
#else
#define DEVICE_NAME "Feather"
#define TFT_35_FEATHERWING 1
#define TFT_24_FEATHERWING 2
// [Configurable] For other boards please select which external display to match your hardware setup
#define TFT_IN_USE TFT_24_FEATHERWING
#if defined(ARDUINO_NRF52832_FEATHER)
// Feather nRF52832 pin map is different from others
#define TFT_DC 11
#define TFT_CS 31
#else
// Default for others
#define TFT_DC 10
#define TFT_CS 9
#endif // 832
#if TFT_IN_USE == TFT_35_FEATHERWING
#include "Adafruit_HX8357.h"
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
#elif TFT_IN_USE == TFT_24_FEATHERWING
#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#else
#error "TFT display is not supported"
#endif // TFT
#endif // board variants
// Universal color
#define COLOR_WHITE 0xFFFF
#define COLOR_BLACK 0x0000
#define COLOR_YELLOW 0xFFE0
@@ -96,9 +101,6 @@ uint32_t totalPixel = 0; // received pixel
// pixel line buffer, should be large enough to hold an image width
uint16_t pixel_buf[512];
// Use software timer to schedule bandwidth negotiation a few seconds after connection
SoftwareTimer negoTimer;
// Statistics for speed testing
uint32_t rxStartTime = 0;
uint32_t rxLastTime = 0;
@@ -110,11 +112,27 @@ void setup()
{
Serial.begin(115200);
#if TFT_IN_USE == TFT_GIZMO
#if defined(ARDUINO_NRF52840_CIRCUITPLAY)
tft.init(240, 240);
tft.setRotation(2);
pinMode(TFT_BACKLIGHT, OUTPUT);
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
// turn back light on
uint8_t backlight = A3;
pinMode(backlight, OUTPUT);
digitalWrite(backlight, HIGH);
#elif defined(ARDUINO_NRF52840_CLUE)
tft.init(240, 240);
tft.setRotation(1);
// Screen refresh rate control (datasheet 9.2.18, FRCTRL2)
uint8_t rtna = 0x01;
tft.sendCommand(0xC6, &rtna, 1);;
// turn back light on
uint8_t backlight = PIN_TFT_LITE;
pinMode(backlight, OUTPUT);
digitalWrite(backlight, HIGH);
#else
tft.begin();
@@ -156,9 +174,6 @@ void setup()
bleuart.setRxOverflowCallback(bleuart_overflow_callback);
// one-shot (non-repeating) 2 seconds timer
negoTimer.begin(2000, negotiate_bandwidth, NULL, false);
// Set up and start advertising
startAdv();
@@ -279,43 +294,8 @@ void bleuart_rx_callback(uint16_t conn_hdl)
}
}
void negotiate_bandwidth(TimerHandle_t xTimer)
{
(void) xTimer;
uint16_t conn_hdl = (uint16_t) ((uint32_t) negoTimer.getID());
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
// Switching from 1 Mb to 2 Mb PHY if needed
if ( conn->connected() )
{
// Requesting to Switching to 2MB PHY, larger data length and bigger MTU
// will increase the throughput on supported central. This should already
// be done with latest Bluefruit app.
//
// However, some Android devices require 2Mb PHY switching must be initiated
// from nRF side
if ( conn->getPHY() == BLE_GAP_PHY_1MBPS )
{
Serial.println("Requesting PHY change from 1 Mb to 2Mb");
conn->requestPHY();
// Data Length and MTU should already be done by Bluefruit app
// conn->requestDataLengthUpdate();
// conn->requestMtuExchange(247);
}
}
}
void connect_callback(uint16_t conn_handle)
{
// Set connection handle as timer ID
// Then schedule negotiation after a few seconds, we should not
// negotiate here since it increases chance to conflict with other
// on-going negotiation from central after connection
negoTimer.setID((void*) ((uint32_t)conn_handle));
negoTimer.start();
tft.println("Connected");
tft.setTextColor(COLOR_GREEN);
tft.println("Ready to receive new image");
@@ -29,7 +29,15 @@
#include <bluefruit.h>
#define NEOPIXEL_VERSION_STRING "Neopixel v2.0"
#define PIN 30 /* Pin used to drive the NeoPixels */
/* Pin used to drive the NeoPixels */
#if defined ARDUINO_NRF52840_CIRCUITPLAY
#define PIN PIN_NEOPIXEL
#elif defined ARDUINO_NRF52832_FEATHER
#define PIN 30
#else
#define PIN 6
#endif
#define MAXCOMPONENTS 4
uint8_t *pixelBuffer = NULL;
+1 -1
View File
@@ -1,5 +1,5 @@
name=Adafruit Bluefruit nRF52 Libraries
version=0.18.0
version=0.19.0
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules
@@ -128,6 +128,11 @@ uint16_t BLECharacteristic::getMaxLen(void)
return _max_len;
}
bool BLECharacteristic::isFixedLen(void)
{
return _attr_meta.vlen == 0;
}
void BLECharacteristic::setFixedLen(uint16_t fixed_len)
{
if ( fixed_len )
@@ -703,7 +708,12 @@ bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len
};
LOG_LV2("CHR", "Notify %d bytes", packet_len);
VERIFY_STATUS( sd_ble_gatts_hvx(conn_hdl, &hvx_params), false );
uint32_t status = sd_ble_gatts_hvx(conn_hdl, &hvx_params);
if(NRF_SUCCESS != status)
{
conn->releaseHvnPacket();
}
VERIFY_STATUS(status, false );
remaining -= packet_len;
u8data += packet_len;
@@ -84,6 +84,7 @@ class BLECharacteristic
void setBuffer(void* buf, uint16_t bufsize);
uint16_t getMaxLen(void);
bool isFixedLen(void);
/*------------- Descriptors -------------*/
void setUserDescriptor(const char* descriptor); // aka user descriptor
@@ -217,6 +217,11 @@ bool BLEConnection::getHvnPacket (void)
return xSemaphoreTake(_hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
bool BLEConnection::releaseHvnPacket(void)
{
return xSemaphoreGive(_hvn_sem);
}
bool BLEConnection::getWriteCmdPacket (void)
{
return xSemaphoreTake(_wrcmd_sem, ms2tick(BLE_GENERIC_TIMEOUT));
@@ -101,6 +101,7 @@ class BLEConnection
void stopRssi(void);
bool getHvnPacket(void);
bool releaseHvnPacket(void);
bool getWriteCmdPacket(void);
bool waitForIndicateConfirm(void);
+2 -7
View File
@@ -113,8 +113,6 @@ static void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
{
typedef struct
{
// convert from Big to Little Endian to use with BLE
// Public Key = 32-byte N1 + 32-byte N2
uint16_t line_num; /**< The line number where the error occurred. */
uint8_t const * p_file_name; /**< The file in which the error occurred. */
} assert_info_t;
@@ -124,10 +122,7 @@ static void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
LOG_LV1("SD Err", "assert at %s : %d", assert_info->p_file_name, assert_info->line_num);
}
while(1)
{
yield();
}
while(1) yield();
#endif
}
@@ -802,7 +797,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
{
ble_gap_evt_disconnected_t const* para = &evt->evt.gap_evt.params.disconnected;
LOG_LV2("GAP", "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
LOG_LV2("GAP", "Disconnect Reason: %s", dbg_hci_str(evt->evt.gap_evt.params.disconnected.reason));
// Turn off Conn LED If not connected at all
if ( !this->connected() ) _setConnLed(false);
+6 -1
View File
@@ -36,7 +36,12 @@
#define BLE_GATT_ATT_MTU_MAX 247
#define BLE_MAX_CONNECTION 20 // SD support up to 20 connections
#define CFG_SD_ATTR_TABLE_SIZE 0xC00
// Allocate more memory for GATT table for 840
#ifdef NRF52840_XXAA
#define CFG_SD_ATTR_TABLE_SIZE 0x1000
#else
#define CFG_SD_ATTR_TABLE_SIZE 0xC00
#endif
#include "BLEUuid.h"
#include "BLEAdvertising.h"
Loaded 100 of 111 files, more files were not shown because too many files have changed in this diff. Show more