background image

 

    Telink TLSR8232 BLE SDK Developer Handbook 

AN-19112700-E1 

93 

Ver.1.0.0 

1)  T

he “attNum” can be used to indicate the number of valid Attributes in current 

Attribute Table, i.e. the maximum Attribute Handle value. This number is only used in 

the invalid Attribute item 0 of Attribute Table array. 

{49,0,0,0,0,0},//ATT_END_H 

– 1 = 49 in “5316_ble_remote” 

“attNum = 49” indicates there are 49 valid Attributes in current Attribute Table. 
In BLE, Attribute Handle value starts from 0x0001 with increment step of 1, while the 

array index starts from 0. When this virtual Attribute is added to the Attribute Table, 

each Attribute index equals its Attribute Handle value. After the Attribute Table is 

defined, Attribute Handle value of an Attribute can be obtained by counting its index 

in current Attribute Table array. 

The final index is the number of valid Attributes (i.e. attNum) in current Attribute 

Table. In current SDK, the attNum is set as 49; if user adds or deletes any Attribute, 

the attNum needs to be modified correspondingly. 

2)  T

he “attNum” can also be used to specify Attributes constituting current Service.   

The UUID of the first Attribute for each Service must be 
“GATT_UUID_PRIMARY_SERVICE (0x2800)”; the first Attribute of a Service sets 
“attNum” and it indicates following “attNum” Attributes constitute current Service.   
As shown in 

Figure 3-30

, for the gap service, the Attribute with UUID of 

“GATT_UUID_PRIMARY_SERVICE” sets the “attNum” as 7, it indicates the seven 
Attributes from Attribute Handle 1 to Attribute Handle 7 constitute the gap service. 

Similarly, for the HID service

, the “attNum” of the first Attribute is set as 27, and it 

indicates the following 27 Attributes constitute the HID service. 

Except for Attribute item 0 and the first Attribute of each Service, attNum values of all 

Attributes must be set as 0. 

 

3.4.2.2 perm 

The “perm” is short for “permission” and it serves to specify access permission of current 
Attribute by Client. 

The “perm” of each Attribute is configurable as one or combination of following values. 

 

#define

 ATT_PERMISSIONS_READ                  0x01  

 

#define

 ATT_PERMISSIONS_WRITE                 0x02  

 

#define

 ATT_PERMISSIONS_AUTHEN_READ          0x04  

 

#define

 ATT_PERMISSIONS_AUTHEN_WRITE         0x08 

 

#define

 ATT_PERMISSIONS_AUTHOR_READ          0x10  

 

#define

 ATT_PERMISSIONS_AUTHOR_WRITE         0x20 

 

#define

 ATT_PERMISSIONS_ENCRYPT_READ         0x40 

 

#define

 ATT_PERMISSIONS_ENCRYPT_WRITE        0x80  

 

Содержание TLSR8232

Страница 1: ...Application Note Telink TLSR8232 BLE SDK Developer Handbook AN 19112700 E1 TELINK SEMICONDUCTOR Brief This document is the developer guide for TLSR8232 BLE SDK 1 3 0 Version 1 0 0 2019 11 27 ...

Страница 2: ...is document or any products herein This document may contain technical inaccuracies or typographical errors Telink Semiconductor disclaims any and all liability for any errors inaccuracies or incompleteness contained herein Copyright 2019 Telink Semiconductor Shanghai Ltd Co Information For further information on the technology product and business term please contact Telink Semiconductor Company ...

Страница 3: ...Telink TLSR8232 BLE SDK Developer Handbook AN 19112700 E1 2 Ver 1 0 0 Revision History Version 1 0 0 2019 11 27 This is the Initial release ...

Страница 4: ...es 21 2 1 MCU Address Space 21 2 1 1 MCU Address Space Allocation 21 2 1 2 SRAM Space Allocation 21 2 1 2 1 SRAM and Firmware Space 21 2 1 2 2 list File Analysis Demo 25 2 1 3 MCU Address Space Access 29 2 1 3 1 Peripheral Space Access 29 2 1 3 2 Flash Space Operation 30 2 1 4 SDK Flash Space Allocation 32 2 1 4 1 Space Allocation of 512kB Flash 33 2 1 4 2 Space Allocation of 128kB Flash 35 2 2 Cl...

Страница 5: ...ing ConnSlaveRole 50 3 2 4 Link Layer Timing Sequence 51 3 2 4 1 Timing Sequence in Idle State 52 3 2 4 2 Timing Sequence in Advertising State 52 3 2 4 3 Timing Sequence in Conn state Slave Role 53 3 2 4 4 Conn State Slave Role Timing Protection 54 3 2 5 Link Layer TX FIFO RX FIFO 55 3 2 6 Controller HCI Event 58 3 2 6 1 HCI Event 59 3 2 6 2 HCI LE Event 60 3 2 7 Telink Defined Event 62 3 2 7 1 BL...

Страница 6: ...AdvEnable 78 3 2 8 9 bls_ll_setAdvDuration 78 3 2 8 10 blc_ll_setAdvCustomedChannel 79 3 2 8 11 rf_set_power_level_index 79 3 2 8 12 bls_ll_terminateConnection 80 3 2 8 13 Get Connection Parameters 81 3 2 8 14 blc_ll_getCurrentState 81 3 2 8 15 blc_ll_getLatestAvgRSSI 81 3 2 8 16 Whitelist Resolvinglist 82 3 2 9 2M PHY Supported 83 3 2 10 Data Length Extension 84 3 3 L2CAP 85 3 3 1 Register L2CAP ...

Страница 7: ...sponse 102 3 4 3 5 Read Request Read Response 103 3 4 3 6 Read Blob Request Read Blob Response 103 3 4 3 7 Exchange MTU Request Exchange MTU Response 104 3 4 3 8 Write Request Write Response 105 3 4 3 9 Write Command 106 3 4 3 10 Handle Value Notification 106 3 4 3 11 Handle Value Indication 107 3 4 3 12 Handle Value Confirmation 108 3 5 SMP 109 3 5 1 SMP Parameter Configuration 109 3 5 1 1 Device...

Страница 8: ...Fail to Enter Suspend Deepsleep When Wakeup Level is Valid 127 4 7 BLE System PM Reference 128 4 8 Timer Wakeup of APP Layer 129 5 Low Battery Detect 131 5 1 Significance of Low Battery Detect 131 5 2 Implementation of Low Battery Detect 131 5 2 1 Cautions of Low Battery Detect 131 5 2 1 1 MUST Use GPIO Input Channel 132 5 2 1 2 MUST Use ADC Differential Mode 133 5 2 1 3 MUST Use DFIFO for ADC Sam...

Страница 9: ... 156 7 4 2 Keyscan Flow Timing Optimization 157 7 5 Deepsleep Wakeup Fast Keyscan 159 7 6 Repeat Key Processing 161 7 7 Stuck Key Processing 162 7 8 Power Optimization for Long Key Press 164 8 LED Management 165 8 1 LED Task Related Functions 165 8 2 LED Task Configuration and Management 165 8 2 1 LED Event Definition 165 8 2 2 LED Event Priority 166 9 blt Software Timer 168 9 1 Timer Initializati...

Страница 10: ...Timing Design 182 10 2 4 IR Initialization 185 10 2 4 1 rc_ir_init 185 10 2 4 2 IR Hardware Configuration 185 10 2 4 3 IR Variable Initialization 186 10 2 5 FIFO Task Configuration 186 10 2 5 1 FIFO Task_data 186 10 2 5 2 FifoTask_idle 187 10 2 5 3 FifoTask_repeat 188 10 2 5 4 FifoTask_repeat n FifoTask_idle_repeat n 189 10 2 6 Check IR Busy Status in APP Layer 189 11 Drivers in BLE SDK 190 11 1 E...

Страница 11: ... 10 Ver 1 0 0 12 BLE SPP Module 199 12 1 Command and Data Packet Format 199 12 2 Function Description 205 12 2 1 Module Sends Commands and Data 206 12 2 2 Module Receives Data 207 12 3 Power Management of Module 209 Appendix 210 Appendix 1 crc16 Algorithm 210 ...

Страница 12: ... 46 Figure 3 5 State Diagram of Link Layer State Machine in BLE Spec 48 Figure 3 6 Telink Link Layer State Machine 48 Figure 3 7 Idle Advertising 50 Figure 3 8 BLE Slave LL State 50 Figure 3 9 Timing Sequence in Advertising State 52 Figure 3 10 Timing Sequence in Conn state Slave Role 53 Figure 3 11 RX Overflow Case 1 56 Figure 3 12 RX Overflow Case 2 57 Figure 3 13 HCI Event 58 Figure 3 14 Discon...

Страница 13: ...d by Type Request Read by Type Response 102 Figure 3 38 Find Information Request Find Information Response 102 Figure 3 39 Read Request Read Response 103 Figure 3 40 Read Blob Request Read Blob Response 103 Figure 3 41 Exchange MTU Request Exchange MTU Response 104 Figure 3 42 Write Request Write Response 106 Figure 3 43 Handle Value Notification in BLE Spec 106 Figure 3 44 Handle Value Indication...

Страница 14: ...84 Figure 11 1 EMI Test Tool 193 Figure 11 2 Select Data Bus 193 Figure 11 3 Swire synchronization operation 194 Figure 11 4 Set Channel 194 Figure 11 5 Select RF Mode 195 Figure 11 6 Interface After RF Mode Setting 195 Figure 11 7 Select Test Mode 196 Figure 11 8 Set TX Packet Number 196 Figure 11 9 TX Mode Interface 197 Figure 11 10 Read RX Packet Number and RSSI 197 Figure 12 1 Module Hardware ...

Страница 15: ...es APP layer and BLE protocol stack Figure 1 1 shows the file structure after the SDK project is imported to Telink IDE which mainly contains six top layer folders boot common drivers proj_lib stack and vendor Figure 1 1 SDK File Structure boot This folder contains software bootloader common This folder contains generic APIs such as printf and shift operation drivers This folder contains all the p...

Страница 16: ...l select internal 32k rc as 32k counter clock source cpu_wakeup_init basic MCU hardware initialization negligible to users clock_init SYS_CLK_16M_Crystal clock initialization users only needs to fill related parameters accordingly gpio_init GPIO initialization users only need to configure related parameters in app_config h rf_drv_init RF_MODE_BLE_1M RF initialization negligible to users only suppo...

Страница 17: ...LE Slave project configuration files for services and profiles Based on Telink Attribute structure as well as Attributes such as GATT standard HID and proprietary OTA users can add their own services and profiles as needed 1 1 4 BLE Stack Entry There are two entry functions in BLE stack code of Telink BLE SDK 1 BLE related interrupt processing entry in irq_handler function of main c file irq_blt_s...

Страница 18: ...K 1 2 0 provides two libraries liblt_5316_512K a and liblt_5316_128K a Providing two libraries is to save some Flash space for 128k Flash IC which is at the expense of removing BLE4 2 DLE features etc It is verified that removing some features of BLE saves little space while loses some functions of BLE and brings inconvenience to users Therefore SDK 1 3 0 reduced its library to liblt_5316 a only I...

Страница 19: ... 18 Ver 1 0 0 Figure 1 2 Select library 1 4 Demo 5316 BLE SDK provides multiple BLE demos for users Each demo code has its specific hardware Through running the demo a user can observe effects directly and modify demo code for his own application development ...

Страница 20: ...complete BLE Slave system 5316 remote 5316 module 5316 sample are all complete BLE Slave stacks 5316 module only acts as BLE SPP module to communicate with Host MCU via UART interface Usually applications are written in the peer MCU with BLE host 5316 remote is a demo of BLE remote controller which supports basic functions of remote It can connect with standard iOS Android device or Telink 826x ma...

Страница 21: ...eature test provides demo code for some common features related to BLE Users can implement their own functions based on these demos All features will be introduced in BLE section 5316 driver test provides sample code for basic drivers based on which users can implement their own driver functions ...

Страница 22: ...he 8M byte peripheral space 0x800000 to 0x808000 are for register space 0x808000 to 0xFFFFFF for SRAM space Please see the datasheet for SRAM sizes Program space Peripheral Space 0x800000 0x808000 Register SRAM 0xffffff 0x000000 0x7fffff FLASH Customizable Figure 2 1 MCU Address Space Allocation 2 1 2 SRAM Space Allocation 2 1 2 1 SRAM and Firmware Space This section provides a further description...

Страница 23: ... bss stack and unused area vector ramcode in SRAM is a copy of vector ramcode in Flash 1 vectors ram_code vectors is a code section of Flash Firmware the executable bin file generated by program compiling in SDK and it corresponds to the assembling file cstartup_5316 s i e the startup code bootloader ramcode is memory resident code in Flash Firmware and it corresponds to all functions with keyword...

Страница 24: ... Its calculation is implemented in boot link As shown below the compiling result _ramcode_size_ equals the code size of vector and ramcode 0x0 vectors vectors vectors ram_code ram_code ram_code PROVIDE _ramcode_size_ Calculate actual ramcode size vector ramcode PROVIDE _ramcode_size_div_16_ 15 16 PROVIDE _ramcode_size_div_256_ 255 256 PROVIDE _ramcode_size_div_16_align_256_ 255 256 16 2 cache cach...

Страница 25: ...8780 0x8087ff in SRAM is wasted as non ramcode is resident in SRAM If _ramcode_size_ is 0x701 255 bytes will be wasted if _ramcode_size_ is 0x800 no byte will be wasted The maximum size of wasted SRAM area is 255 bytes therefore in program design users need to check list files to view ramcode occupation and try to avoid serious waste Since cache size is fixed as 2 25K 0x900 the ending address of c...

Страница 26: ... of Flash firmware Functions with _attribute_ram_code_ in firmware will be compiled as ram_code while other functions without this keyword will be compiled as text text occupies the maximum space of Firmware which largely exceeds SRAM size generally Therefore the code needs to be executed after it is loaded into cache by cache buffer function 6 rodata data init value In Firmware except vector ram_...

Страница 27: ...ile Below lists the sections in the list file Detailed introductions are followed 1 vectors start from Flash 0 size is 0x100 2 ram_code start from Flash 0x100 size is 0x168c 3 text start from Flash 0x1790 size is 0x6f30 4 rodata start from Flash 0x86c0 size is 0xa64 5 data start from SRAM 0x80a100 size is 0x194 6 bss start from SRAM 0x80a2a0 size is 0xc98 By calculation bss ending address is 0x80a...

Страница 28: ...or vector is the bootloader corresponding to the assembly file startup_5316 s As shown in the list file the size of this section is 256 bytes with starting address in Flash being 0 ending address 0xff After power on it is loaded to SRAM and the corresponding address in SRAM is 0x808000 0x8080ff 2 ram_code ram_code section contains 0x168c bytes with starting address being 0x100 ending address 0x178...

Страница 29: ...ial values of initialized global variables in Firmware data init value is not a specific section in the list file Users can search the keyword _dstored_ and find the value 0x9124 which is the starting address of data init value 00009124 g ABS 00000000 _dstored_ The _dstored_ definition in the boot link is shown below It tells the compiler that initial values of initialized global variables in the ...

Страница 30: ...5678 write SRAM 0x8000 0x8003 In the program functions including write_reg8 write_reg16 write_reg32 read_reg8 read_reg16 and read_reg32 which implement pointer operation are used to write or read the peripheral space correspondingly Please see drivers 5316 bsp h for details Please note that for operations such as write_reg8 0x8000 read_reg16 0x8000 whose definitions are shown as below the base add...

Страница 31: ...u32 len u8 buf u8 data 6 0x11 0x22 0x33 0x44 0x55 0x66 flash_write_page 0x12000 6 data write 6 byte data 0x665544332211 into Flash starting from 0x12000 flash_write_page accesses pages in Flash The maximum len for operations of flash_write_page is 256 bytes the size of one page This function is not allowed to write Flash space across two or more pages If the addr is the starting address of one pag...

Страница 32: ...p It takes tens of milliseconds to hundreds of milliseconds to execute the flash_erase_sector function Therefore during mainloop of main program once MCU enters BLE connection state try not to invoke the flash_erase_sector to avoid disconnection If it s inevitable to erase Flash during BLE connection BLE timing sequence protection as introduced in section 3 2 4 4 Conn State Slave Role Timing Prote...

Страница 33: ...ult of the second reading should be the new value 0x5A but the actual result is still the old data buffered in the cache i e 0xff Therefore in the case of multiple reading of the same address if its value will be modified use the API flash_read_page rather than pointer to ensure the result of reading is the new value written into this address rather than the old value in the cache u8 result flash_...

Страница 34: ...ult address space allocation and corresponding interfaces 1 The sector from 0x76000 to 0x76FFF serves to store MAC address Actually the 6 byte MAC address is stored in Flash area from 0x76000 for lower byte of MAC address to 0x76005 for higher byte of MAC address For example if 0x11 0x22 0x33 0x44 0x55 0x66 are stored in FLASH 0x76000 to 0x76005 the MAC address is 0x665544332211 Corresponding to S...

Страница 35: ...which has 2 bytes TP0 TP1 and is stored in 0x77040 and 0x77041 correspondingly 3 The third 64 byte unit serves to store capacitance calibration value of external 32kHz crystal Corresponding to SDK actual calibration values will be burned into the addresses above by Telink jig system If users want to modify the address please ensure the burning address of Telink jig system is also modified correspo...

Страница 36: ...ase see OTA section for allocation methods The space allocation shown above is the default allocation method of 128K chip Actually all the space allocations provide users corresponding interfaces for modification by which users can modify Flash space allocation as needed The following introduces the default space allocation and corresponding interfaces 1 The sector 0x1F000 0x1FFFF serves to store ...

Страница 37: ... and is stored in 0x1E000 2 The second 64 byte unit serves to store calibration value of TP value Actually this calibration value has only 2 bytes TP0 TP1 and stored in 0x1E040 and 0x1E041 correspondingly Corresponding to SDK actual calibration values will be burned into the addresses above by Telink jig system If users want to modify the address please ensure the burning address of Telink jig sys...

Страница 38: ...provide time reference for BLE timing Therefore users cannot use timer0 for other functions For last generation IC of Telink 826x the clock for system timer is the system clock while for TLSR8232 as the figure shown below though system timer has multiple sources SDK divides the external 24MHz crystal oscillator by 2 3 and obtains 16M clock which will not change with the change of system clock Figu...

Страница 39: ... the hardware modules of system clock When setting the clock for a module only CLOCK_SYS_CLOCK_HZ CLOCK_SYS_CLOCK_1S can be used In other words if a user see that the above definitions are used for clock setting it means the clock source of this module is system clock If the setting of PWM cycle and duty ratio in PWM driver is as follows it means the clock source of PWM is system clock pwm_set_cyc...

Страница 40: ... usage of the software timer is shown as below 1 Start timing Set an u32 variable read and record current System Timer tick u32 start_tick clock_time clock_time returns System Timer tick value 2 Continuously query if the difference between current System Timer tick and start_tick exceeds the timing value at somewhere of the firmware If yes the timer is triggered to execute corresponding operation ...

Страница 41: ...ould refer to the actual IC package when using GPIOs Please follow the format above to use GPIO see drivers 5316 gpio c for details There is a special GPIO with SWS Single Wire Slave function Its SWS function for debugging and firmware burning is enabled when power on Generally it is not used in firmware The SWS pin of 5316 is PC7 2 3 2 GPIO State Control In this section only the basic GPIO states...

Страница 42: ...internal analog pull up pull down resistor x1 pull up x10 pull down x100 pull up The resistance range for x1 is 8Kohm 60Kohm x10 80Kohm 600Kohm x100 500Kohm 2Mohm void gpio_setup_up_down_resistor GPIO_PinTypeDef gpio GPIO_PullTypeDef up_down There are four configurations for up_down PM_PIN_PULLUP_1M PM_PIN_PULLUP_10K PM_PIN_PULLDOWN_100K PM_PIN_UP_DOWN_FLOAT Note PM_PIN_PULLUP_1M represents x100 p...

Страница 43: ... initialize states of all GPIOs Each IO will be initialized to its default state by gpio_init function unless related GPIO parameters are pre configured in the app_config h The default states of 23 GPIOs are as below 1 func Except SWS other GPIOs are generic GPIO function 2 ie For SWS default ie is 1 for other GPIOs default ie is 0 3 oe For all GPIOs default oe is 0 4 dataO For all GPIOs default d...

Страница 44: ...state of one GPIO is configured to different values in app_config h and user_init the configuration in user_init will take effect finally according to firmware timing sequence 2 3 4 Configure SWS Pull up to Avoid MCU Errors Telink MCU uses the SWS Single Wire Slave pin for debugging and firmware burning In final application code the state of SWS is shown as below 1 Set as SWS function rather than ...

Страница 45: ...above BLE protocol stack includes two parts Host and Controller As BLE bottom layer protocol the Controller contains Physical Layer PHY and Link Layer LL Host Controller Inter HCI is the sole communication interface for all data transfer between Controller and Host As BLE upper layer protocol the Host contains protocols including Logic Link Control and Adaption Protocol L2CAP Attribute Protocol AT...

Страница 46: ...en Controller receives RF data in Physical Layer it will first check whether the data belong to Link Layer or Host and then process correspondingly If the data belong to LL the data will be processed directly if the data belong to Host the data will be sent to Host via HCI 3 1 2 Telink BLE SDK Architecture 3 1 2 1 Telink BLE Controller Telink BLE SDK supports standard BLE Controller including HCI ...

Страница 47: ...ck architecture will be simplified based on the standard architecture so as to minimize system resource consumption of the whole SDK including SRAM running time power consumption and etc Following shows Telink BLE Slave architecture In SDK 5316 ble remote and 5316 module are both based on this architecture 826x BLE Stack HIDS Security Manager OTA Logical Link Control and Adaption Protocol HCI Attr...

Страница 48: ...PP layer based on GATT Basic Profiles including HIDS BAS and OTA are provided in 5316 BLE SDK demo code Based on this architecture the following provides a basic introduction of 5316 BLE protocol stack and user APIs of each layer Physical Layer is totally controlled by Link Layer and it does not involve any other layers Though HCI still implements part of data transfer between Host and Controller ...

Страница 49: ...Master role connection Figure 3 6 Telink Link Layer State Machine Telink BLE SDK Link Layer state machine is consistent with BLE Spec and it contains five basic states Idle Standby Scanning Advertising Initiating and Connection Connection state contains Slave Role only no Master Role Slave Role is single connection by default In this document Slave Role will be called as Conn state Slave role or C...

Страница 50: ...ate void 3 2 3 Link Layer State Machine Combined Application 3 2 3 1 Link Layer State Machine Initialization Telink BLE SDK Link Layer fully supports all states however it s flexible in design Each state can be assembled as a module be default there s only the basic Idle module and user needs to add modules and establish state machine combination for his application For example for BLE Slave appli...

Страница 51: ...mation in single direction e g beacon The module initialization code of Link Layer state machine is u8 tbl_mac 6 blc_ll_initBasicMCU tbl_mac blc_ll_initAdvertising_module tbl_mac State switch of Idle and Advertising is implemented via bls_ll_setAdvEnable 3 2 3 3 Idle Advertising ConnSlaveRole Advertising Idle bls_ll_setAdvEnable 0 bls_ll_setAdvEnable 1 Connection Slave role a c c e p t m a s t e r...

Страница 52: ...dv channels Master will send connection request if it receives adv packet After Link Layer receives this connection request it will respond establish connection and enter ConnSlaveRole 4 When Link Layer is in ConnSlaveRole it will return to Idle State or Advertising state in any of the following cases a Master sends terminate command to Slave and requests disconnection Slave will exit ConnSlaveRol...

Страница 53: ...nterval chn 37 chn 38 chn 39 TX RX TX TX RX RX UI task suspend UI task suspend Figure 3 9 Timing Sequence in Advertising State As shown in Figure 3 9 an Adv event is triggered by Link Layer during each adv interval A typical Adv event with three active adv channels will send an advertising packet in channel 37 38 and 39 respectively After an adv packet is sent Slave enters Rx state and waits for r...

Страница 54: ...nter brx start phase During this interrupt MCU sets BLE state machine of PHY to enter brx state hardware in bottom layer prepares for packet transfer and then MCU exits from the interrupt irq 2 brx working phase After brx start phase ends and MCU exits from irq hardware in bottom layer enters Rx state first and waits for packet from Master An ack packet will be sent to respond to each received dat...

Страница 55: ...ow this mechanism so that BLE timing sequence won t be disturbed when Brx Event is stopped Corresponding APIs are shown as below int bls_ll_requestConnBrxEventDisable void void bls_ll_disableConnBrxEvent void void bls_ll_restoreConnBrxEvent void API bls_ll_requestConnBrxEventDisable serves to send a request to disable Brx Event 1 If the return value is 0 it indicates the request to disable Brx Eve...

Страница 56: ...red in a BLE RX FIFO and then transmitted to BLE Host or APP layer for processing Both BLE TX FIFO and BLE RX FIFO in Slave role are defined in APP layer MYFIFO_INIT blt_rxfifo 64 8 MYFIFO_INIT blt_txfifo 40 16 By default RX FIFO size is 64 and TX FIFO size is 40 It s not allowed to modify the two size values unless it s needed to use data length extension in core 4 2 Both TX FIFO number and RX FI...

Страница 57: ...for RX TX Timer0 etc UI task sleep UI task Brx event n brx post brx start brx working RX1 TX1 RX2 TX2 Brx event n 1 RX3 TX3 RX6 TX6 UI task brx post brx start brx working UI task sleep wptr 2 0 1 2 3 4 5 6 7 rptr 0 RX4 TX4 RX5 TX5 wptr 2 6 8 1 0 0 6 1 2 3 1 4 2 5 3 6 4 7 5 rptr 0 If the RX fifo rptr is 0 before the pkt is received assuming that there are multiple pkts in one brx event and main_loo...

Страница 58: ...whether the difference of current RX FIFO wptr and rptr exceeds Rx FIFO number If the check result shows current Rx FIFO is fully occupied the RF won t send ACK to the peer and BLE protocol ensures data will be re transmitted Similarly if there are more than 8 valid packets in an interval the default number 8 is not enough Default TX FIFO number is 16 which is enough to process common audio remote...

Страница 59: ... Host HCI BLE Controller HCI cmd Host data Controller data HCI event Figure 3 13 HCI Event For the definition of Controller HCI event please refer to Core_v5 0 Vol 2 Part E 7 7 Events LE Meta Event in 7 7 65 refers to HCI LE low energy Event while others are common HCI events As defined in the Spec 5316 BLE SDK also divides Controller HCI event into two types HCI Event and HCI LE event Since 5316 ...

Страница 60: ...MPLETE Please refer to Core_v5 0 Vol 2 Part E 7 7 5 Disconnection Complete Event Total data length of this event is 7 and 1 byte param len is 4 as shown below Please refer to BLE Spec for data definition hci event 0x04 event code 0x05 param len status connection handle reason 4 0x00 Figure 3 14 Disconnection Complete Event 2 HCI_EVT_ENCRYPTION_CHANGE and CI_EVT_ENCRYPTION_KEY_REFRESH Please refer ...

Страница 61: ...isconnect event by default 3 2 6 2 HCI LE Event When the event code in HCI event is HCI_EVT_LE_META it indicates it s a HCI LE event common subevent code are shown as below define HCI_SUB_EVT_LE_CONNECTION_COMPLETE 0x01 define HCI_SUB_EVT_LE_ADVERTISING_REPORT 0x02 define HCI_SUB_EVT_LE_CONNECTION_UPDATE_COMPLETE 0x03 1 HCI_SUB_EVT_LE_CONNECTION_COMPLETE Please refer to Core_v5 0 Vol 2 Part E 7 7 ...

Страница 62: ...tion Update Complete Event When connection update in Controller takes effect HCI_SUB_EVT_LE_CONNECTION_UPDATE_COMPLETE will be reported to Host Total data length of this event is 13 and 1 byte param len is 10 as shown below Please refer to BLE Spec for data definition hci event event code param len subevent code connection handle conn interval conn latency 0x04 0x3e 10 0x03 status supervision time...

Страница 63: ...stack ble ll ll h Current new SDK supports the following callback events BLT_EV_FLAG_CONNECT BLT_EV_FLAG_TERMINATE has the same function as HCI_SUB_EVT_LE_CONNECTION_COMPLETE and HCI_EVT_DISCONNECTION_COMPLETE in HCI event but data definition of these events are different define BLT_EV_FLAG_ADV 0 define BLT_EV_FLAG_ADV_DURATION_TIMEOUT 1 define BLT_EV_FLAG_SCAN_RSP 2 define BLT_EV_FLAG_CONNECT 3 d...

Страница 64: ...ons is void bls_app_registerEventCallback u8 e blt_event_callback_t p 2 The second Callback functions of all the events share one entry Whether the event responds depends on if the corresponding event mask is enabled This we call shared event entry Registering event callback via shared event entry use the same API of HCI event typedef int hci_event_handler_t u32 h u8 para int n void blc_hci_regist...

Страница 65: ...entation of the two methods are shown below by taking connect event callback and terminate event callback for example 1 Method 1 independent registration void task_connect u8 e u8 p int n add connect callback code here void task_terminate u8 e u8 p int n add terminate callback code here bls_app_registerEventCallback BLT_EV_FLAG_CONNECT task_connect bls_app_registerEventCallback BLT_EV_FLAG_TERMINA...

Страница 66: ...g duration a timer will be started in BLE stack bottom layer When the timer reaches the specified duration advertising is stopped and this event is triggered In the callback function of this event users can implement operations such as modifying adv event type re enabling advertising re configuring advertising duration and etc Pointer p null pointer Data length n 0 Note This event won t be trigger...

Страница 67: ...rresponding to InitA in Figure 3 20 to hop typedef struct u32 dma_len u8 type u8 rf_len u8 scanA 6 u8 advA 6 u8 accessCode 4 u8 crcinit 3 u8 winSize u16 winOffset u16 interval u16 latency u16 timeout u8 chm 5 u8 hop rf_packet_connect_t 3 2 7 5 BLT_EV_FLAG_TERMINATE Event trigger condition This event will be triggered when Link Layer state machine exits Conn state Slave role in any of the three spe...

Страница 68: ...e reason is the actual parameter reason of this API 3 2 7 6 BLT_EV_FLAG_ENCRYPTION_CONN_DONE Event trigger condition This event will be triggered when encryption of Link Layer is finished i e Link Layer receives start encryption response from Master Pointer p p points to an u8 type variable smp_flag which indicates current encryption of Link Layer is triggered during first pairing or auto re conne...

Страница 69: ...m for real time demanding applications Take keyboard scanning as an example if user presses keys fast to avoid key press loss and process debouncing it s recommended to set the scan interval as 10 20ms longer suspend time e g 400ms or 1s which may be reached when latency is enabled will lead to key press loss So it s needed to judge current suspend time before MCU enters suspend if it s too long t...

Страница 70: ...conn_chn_map 0 bit0 bit7 represent channel0 channel7 respectively conn_chn_map 1 bit0 bit7 represent channel8 channel15 respectively conn_chn_map 2 bit0 bit7 represent channel16 channel23 respectively conn_chn_map 3 bit0 bit7 represent channel24 channel31 respectively conn_chn_map 4 bit0 bit4 represent channel32 channel36 respectively 3 2 7 10 BLT_EV_FLAG_CHN_MAP_UPDATE Event trigger condition Whe...

Страница 71: ...iggered before Slave enters suspend Pointer p Null pointer Data length n 0 3 2 7 14 BLT_EV_FLAG_SUSPEND_EXIT Event trigger condition When Slave executes function blt_sdk_main_loop this event will be triggered after Slave is woken up from suspend Pointer p Null pointer Data length n 0 Note This callback is executed after SDK bottom layer executes cpu_sleep_wakeup and Slave is woke up and this event...

Страница 72: ...to operate Controller have corresponding HCI command complete event or HCI command status event as response to Host layer However in Telink BLE SDK there are different situations 1 For applications such as 5316_hci Telink IC only serves as BLE controller and needs to work together with BLE Host MCU Each HCI command will generate corresponding HCI command complete event or HCI command status event ...

Страница 73: ... mac_public As introduced above the 6 byte BLE MAC address will be downloaded into specific Flash area of the actual products by Telink jig system Users need to obtain the MAC address from Bluetooth SIG 3 2 8 4 Link Layer State Machine Initialization The APIs below are used to configure initialization of each module when BLE state machine is established Please see the previous section for introduc...

Страница 74: ...evice name is set as Ghid in the adv data shown above 3 2 8 6 bls_ll_setScanRspData Please refer to Core_v5 0 Vol 2 Part E 7 8 8 LE Set Scan response Data Command Similar to the setting of Adv packet Payload an API is used to set Scan response Payload ble_sts_t bls_ll_setScanRspData u8 data u8 len The data pointer points to the starting address of scanRspData in Payload while the len indicates dat...

Страница 75: ...f device will be shown according to the configuration in Attribute Table Please refer to Attribute Table section for details 3 2 8 7 bls_ll_setAdvParam Please refer to Core_v5 0 Vol 2 Part E 7 8 5 LE Set Advertising Parameters Command Figure 3 23 Advertising Event in BLE Stack The figure above shows Advertising Event Adv Event in brief in BLE stack It indicates during each T_advEvent Slave impleme...

Страница 76: ... Connect Request from other device For example Connectable Undirected Event can respond to both Scan request and Connect Request while Non connectable Undirected Event will respond to neither Scan request nor Connect Request For Connectable Directed Event YES marked with an asterisk indicates the matched Connect Request received won t be filtered by whitelist and this event will surely respond to ...

Страница 77: ...WN_ADDRESS_RESOLVE_PRIVATE_PUBLIC 2 OWN_ADDRESS_RESOLVE_PRIVATE_RANDOM 3 own_addr_type_t Only two parameters are introduced herein OWN_ADDRESS_PUBLIC means using public MAC address for advertising The actual address is the set by API API blc_ll_initAdvertising_module u8 public_adr in MAC address initialization OWN_ADDRESS_RANDOM means using random static MAC address for advertising The address is ...

Страница 78: ...define ADV_FP_ALLOW_SCAN_WL_ALLOW_CONN_WL 0x03 define ADV_FP_NONE ADV_FP_ALLOW_SCAN_ANY_ALLOW_CONN_ANY The table below lists possible values and reasons for the return value ble_sts_t ble_sts_t Value ERR Reason BLE_SUCCESS 0 HCI_ERR_INVALID_HCI_CMD_PARA MS 0x12 The value of intervalMin or intervalMax does not meet the requirement of BLE Spec According to Host command design in HCI part of BLE Spec...

Страница 79: ...ble_sts_t bls_ll_setAdvDuration u32 duration_us u8 duration_en After bls_ll_setAdvParam sets all adv parameters successfully and the bls_ll_setAdvEnable 1 is called to start advertising the API bls_ll_setAdvDuration can be called to set duration of adv event so that advertising will be automatically disabled after this duration duration_en 1 enable timing function 0 disable timing function duratio...

Страница 80: ...e won t check adv event timeout in connection state the callback of BLT_EV_FLAG_ADV_DURATION_TIMEOUT won t be triggered When Slave stays in connection state for certain duration e g 10s then terminates connection and returns to adv state before it sends out the first adv packet the Stack will regard current time exceeds the preset 2s timeout and trigger the callback of BLT_EV_FLAG_ADV_DURATION_TIM...

Страница 81: ...tively terminate connection When data packets from peer device are decrypted if an authentication data MIC error is detected the bls_ll_terminateConnection HCI_ERR_CONN_TERM_MIC_FAILURE will be called to inform the peer device of the decryption error and connection is terminated After Slave invokes this API to actively initiate disconnection the event BLT_EV_FLAG_TERMINATE will be triggered The te...

Страница 82: ...8 API bls_ll_getConnectionLatency returns the actual Latency value API bls_ll_getConnectionTimeout returns the current conn timeout unit being 10ms Suppose current conn timeout is 1000ms the return value would be 1000ms 10ms 100 3 2 8 14 blc_ll_getCurrentState The API below is used to obtain current Link Layer state u8 blc_ll_getCurrentState void The return values of this function are as below 531...

Страница 83: ...e return values are shown below ble_sts_t Value ERR Reason BLE_SUCCESS 0 Add success HCI_ERR_MEM_CAP_EXCEE DED 0x07 Whitelist is full add failure ble_sts_t ll_whiteList_delete u8 type u8 addr Delete a device from whitelist and the return value is BLE_SUCCESS RPA Resolvable Private Address device needs to use Resolvinglist To save RAM space Resolvinglist can store up to two devices only in current ...

Страница 84: ...lly exchange the PHYs they each support and prefer then master will send LL_PHY_UPDATE_IND and after instance reaches master and slave will use their new PHYs to transmit and receive data If it is started by slave slave will send LL_PHY_REQ PDU master will directly send LL_PHY_UPDATE_IND to respond slave and after instance reaches master and slave will use their new PHYs to transmit and receive da...

Страница 85: ...s only can be transmitted in fragmented packets thus the transmission efficiency is low and it cannot meet actual demands With DLE data of 251B can be transmitted at once which greatly improves the transmission efficiency and is very favorable for applications of big data transmission such as Audio and OTA DLE is a feature of link layer please refer to Core_v5 0 Vol 6 Part B Link Layer Specificati...

Страница 86: ...yload size of transmission 12 4 byte aligned Rx FIFO size actual maximum payload size of receiving 28 16 byte aligned 3 3 L2CAP Logical Link Control and Adaptation Protocol L2CAP for short connects the upper APP layer and the lower Controller layer By acting as an adaptor between the Host and the Controller the L2CAP makes data processing details of the Controller become negligible to the upper la...

Страница 87: ...rocessing function void blc_l2cap_register_handler void p In BLE Slave applications such as 5316 remote 5316 module the function to process data of Controller in L2CAP layer of SDK is shown as below int blc_l2cap_packet_receive u16 connHandle u8 p This function is already implemented in stack which it will analyze the received data and transfer the data to ATT or SMP Initialization blc_l2cap_regis...

Страница 88: ...ARAMETER UPDATE REQUEST to Master and actively apply for a new set of connection parameters void bls_l2cap_requestConnParamUpdate u16 min_interval u16 max_interval u16 latency u16 timeout The four parameters of this API correspond to the parameters in the data field of the CONNECTION PARAMETER UPDATE REQUEST The min_interval and max_interval are in a unit of 1 25ms e g for 9ms connection interval ...

Страница 89: ...gure below shows the command format if result is 0x0000 it indicates the request command is accepted if result is 0x0001 it indicates the request command is rejected Whether actual Android iOS device will accept or reject the connection parameter update request is determined by corresponding BLE Master User can refer to Master compatibility test As shown in Figure 3 26 Master accepts the request F...

Страница 90: ...ify as needed based on this simple demo design No matter whether parameter request of Slave is accepted the API below can be called to respond to this request void blc_l2cap_SendConnParamUpdateResponse u16 connHandle int result connHandle indicates current connection ID result has two options accept and reject typedef enum CONN_PARAM_UPDATE_ACCEPT 0x0000 CONN_PARAM_UPDATE_REJECT 0x0001 conn_para_u...

Страница 91: ...0 When Slave receives the conn_req it switches state from advertising to connection and clears the instant of Slave to 0 Each connection packet of Master and Slave is a connection event For the first connection event after the conn_req the instant value is 1 for the second connection event the instant value is 2 and so on When Master sends a LL_CONNECTION_UPDATE_REQ the final parameter instant ind...

Страница 92: ...service hids h and stack ble uuid h Telink proprietary profiles OTA etc are not supported in standard Bluetooth The 16 byte proprietary device UUIDs are defined in stack ble uuid h 2 Attribute Handle Slave supports multiple Attributes which compose an Attribute Table In Attribute Table each Attribute is identified by an Attribute Handle value After connection is established Master will analyze and...

Страница 93: ...bytes aligned u8 uuid u8 pAttrValue att_readwrite_callback_t w att_readwrite_callback_t r attribute_t Attribute Table code is available in app_att c as shown below Figure 3 30 5316 BLE SDK Attribute Table Please note that the key word const is added to Attribute Table definition const attribute_t my_Attributes By adding the const the compiler will store the array data to Flash rather than RAM whil...

Страница 94: ...es constituting current Service The UUID of the first Attribute for each Service must be GATT_UUID_PRIMARY_SERVICE 0x2800 the first Attribute of a Service sets attNum and it indicates following attNum Attributes constitute current Service As shown in Figure 3 30 for the gap service the Attribute with UUID of GATT_UUID_PRIMARY_SERVICE sets the attNum as 7 it indicates the seven Attributes from Attr...

Страница 95: ...ink proprietary 16 byte UUID For example for Attribute of OTA related code is shown as below define TELINK_SPP_DATA_OTA 0x12 0x2B 0x0d 0x0c 0x0b 0x0a 0x09 0x08 0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00 const u8 my_OtaUUID 16 TELINK_SPP_DATA_OTA 0 ATT_PERMISSIONS_RDWR 16 sizeof my_OtaData u8 my_OtaUUID my_OtaData otaWrite otaRead The uuid points to the address of my_OtaUUID in Flash and the uuidLen i...

Страница 96: ...ads hidInformation For Attribute battery value with Attribute Handle being 40 related code is as shown below u8 my_batVal 1 99 0 1 2 1 u8 my_batCharUUID u8 my_batVal 0 In practical application the my_batVal indicates current battery level and it will be updated according to ADC sampling result then Slave will actively notify or Master will actively read to transfer the my_batVal to Master The star...

Страница 97: ... operations is allowed to take effect By setting the callback function w user can process Write Request and Write Command in ATT layer of Master If the callback function w is not set user needs to evaluate whether the area pointed by pAttrValue can process the command e g If the pAttrValue points to Flash write operation is not allowed or if the attrLen is not long enough for Master write operatio...

Страница 98: ...i e for an Attribute user can select whether to set the callback read function as needed null pointer 0 indicates not setting callback read function The trigger condition for callback function r is When Slave receives any Attribute PDU with Attribute Opcode as shown below Slave will check whether the callback function r is set 1 opcode 0x0A Read Request see Core_v5 0 2 opcode 0x0C Read Blob Reques...

Страница 99: ...ack function r modify contents in RAM pointed by the pAttrValue in this callback function and the return value must be 0 3 4 2 7 Attribute Table Layout Figure 3 34 shows Service Attribute layout based on Attribute Table The attnum of the first Attribute indicates the number of valid Attributes in current ATT Table the remaining Attributes are assigned to different Services the first Attribute of e...

Страница 100: ...itialization only needs to transfer the pointer of Attribute Table in APP layer to protocol stack and the API is void bls_att_setAttributeTable u8 p p is the pointer of Attribute Table 3 4 3 Attribute PDU GATT API As required by BLE Spec 5316 BLE SDK currently supports the following Attribute PDU types 1 Requests Data request sent from Client to Server ...

Страница 101: ...F 3 4 4 9 and 3 4 4 10 for details of Read by Group Type Request and Read by Group Type Response The Read by Group Type Request command sent by Master specifies starting and ending attHandle as well as attGroupType After the request is received Slave will check through current Attribute Table according to the specified starting and ending attHandle and find the Attribute Group that matches the spe...

Страница 102: ...uest and Read by Group Type Response commands 3 4 3 2 Find by Type Value Request Find by Type Value Response Please see Core_v5 0 Vol 3 Part F 3 4 3 3 and 3 4 3 4 for details of Find by Type Value Request and Find by Type Value Response The Find by Type Value Request command sent by Master specifies starting and ending attHandle as well as AttributeType and Attribute Value After the request is rec...

Страница 103: ...rrent attHandle 0003 followed by 6 byte Attribute Value 3 4 3 4 Find Information Request Find Information Response Please refer to Core_v5 0 Vol 3 Part F 3 4 3 1 and 3 4 3 2 for details about Find information request and Find information response The Find information request command sent by Master specifies starting and ending attHandle After the request is received Slave will respond to Master wi...

Страница 104: ...If some Slave Attribute corresponds to Attribute Value with length exceeding MTU_SIZE It s set as 23 in current SDK Master needs to read the Attribute Value via the Read Blob Request command so that the Attribute Value can be sent in packets This command specifies the attHandle and ValueOffset After the request is received Slave will find corresponding Attribute and respond to Master with the Attr...

Страница 105: ... 1 Callback function of MTU size exchange Function prototype typedef void attRxMtuSizeExchangeCommpleteCb u16 connHandle u16 remoteMtuSize u16 effectMtuSize The first u16 is current connection handle and it should be BLS_CONN_HANDLE in Slave applications The second u16 is ClientRxMTU of Master The third is the Rx MTU size finally used The API is for registerring this callback function void blc_att...

Страница 106: ... u16 connHandle u16 mtu_size connHandle is ID of Slave conection i e BLS_CONN_HANDLE while mtu_size is ServerRxMTU blc_att_requestMtuSizeExchange BLS_CONN_HANDLE 158 After the ATT_Exchange_MTU_req is received Master will respond with ATT_Exchange_MTU_rsp Then the callback function registered via blc_att_registerMtuSizeExchangeCb will be triggered and the second parameter of the callback function i...

Страница 107: ...ion Figure 3 43 Handle Value Notification in BLE Spec The figure above shows the format of Handle Value Notification in BLE Spec 5316 BLE SDK supplies an API for Handle Value Notification of an Attribute By invoking this API user can push the notify data into bottom layer BLE software FIFO Stack will push the data of software FIFO into hardware FIFO during the latest packet transfer interval and f...

Страница 108: ...ndle Value Indication Please refer to Core_v5 0 Vol 3 Part F 3 4 7 2 for details about Handle Value Indication Figure 3 44 Handle Value Indication in BLE Spec The figure above shows the format of Handle Value Indication in BLE Spec 5316 BLE SDK supplies an API for Handle Value Indication of an Attribute By invoking this API user can push the indicate data into bottom layer BLE software FIFO Stack ...

Страница 109: ... ble_sts_t Value ERR reason BLE_SUCCESS 0 HCI_ERR_CONN_NOT_ESTABLISH 0x3E Link Layer is in None Conn state SMP_EER_PAIRING_IS_GOING_ON 0x8F Data cannot be sent during pairing phase HCI_ERR_CONTROLLER_TX_FIFO_NOT_ENOUG H 0x3A Tasks with mass data are being executed software Tx FIFO is not enough ATT_ERR_PREVIOUS_INDICATE_DATA_HAS_NO T_CONFIRMED 0x6B The previous indicate data has not been confirmed...

Страница 110: ...ecification for details of SMP 3 5 1 SMP Parameter Configuration Parameter configuration related to SMP initialization includes device bonding OOB Out Of Band data verification and Secure Connection SC 3 5 1 1 Device Bonding When it s needed to bond peer device information after pairing the function below should be called to enable current device bonding request int blc_smp_enableBonding int en en...

Страница 111: ...N_TRRIGER SMP_PARING_PEER_TRRIGER smp_paringTrriger_t 1 encrypt_en SMP_PARING_DISABLE_TRRIGER It indicates pairing encryption is disabled for current device connection Even if peer device requests for pairing encryption the device will reject this request It applies to the case when current device does not support encrypted pairing As shown below Master sends pairing request and then Slave respond...

Страница 112: ...g Peer Trigger Note This function can only be called before connection It s recommended to call this function in initialization 3 5 3 SMP Event As introduced in Controller part except for Telink defined events there are some SMP events e g BLT_EV_FLAG_PAIRING_BEGIN BLT_EV_FLAG_PAIRING_END 3 5 3 1 BLT_EV_FLAG_PAIRING_BEGIN Event trigger condition When Slave just establishes connection with Master a...

Страница 113: ...ces can be re connected successfully The API below serves to set the maximum device number for current storage which should not exceed 4 SMP_BONDING_DEVICE_MAX_NUM The default value is 4 define SMP_BONDING_DEVICE_MAX_NUM 4 ble_sts_t blc_smp_param_setBondingDeviceMaxNumber int device_num Suppose it s set as blc_smp_param_setBondingDeviceMaxNumber 4 When pairing information of four paired devices ar...

Страница 114: ...ice As introduced above if Slave is successively paired with MasterA B C and D since MasterD is the latest device at this moment MasterD is index 3 Then Slave is re connected with MaserB since the latest device at this moment MasterB is index 3 Please pay attention to the case when more than four Master devices are paired When Slave is successively paired with MasterA B C and D if it s paired with...

Страница 115: ... devices currently to obtain info of the latest connected device index should be set to 2 blc_smp_param_loadByIndex 2 The API below obtains information of bonding device from Flash via Master address connection addr in Link Layer u32 blc_smp_param_loadByAddr u8 addr_type u8 addr smp_param_save_t smp_param_load If the return value is 0 it indicates info obtaining failure if the return value is non ...

Страница 116: ... in this mode other digital and analog registers and memory are volatile i e all data won t be held The retention analog registers DEEP_ANA_REG in pm h can be used to store some necessary information After wakeup from deepsleep MCU is rebooted and it s equivalent to power cycle power cycle will reset all registers firmware restarts running and enters initialization User can store some information ...

Страница 117: ... to set this wakeup source in cpu_sleep_wakeup The two wakeup sources including PM_WAKEUP_CORE and PM_WAKEUP_PAD are derived from GPIO High Low level of all GPIOs can be configured to wakeup MCU from suspend deepsleep via the CORE PAD module The CORE module can only wakeup MCU from suspend while the PAD module can wakeup MCU from both suspend and deepsleep However 5316 BLE SDK GPIO CORE works as w...

Страница 118: ...r low power mode and set wakeup source s int cpu_sleep_wakeup SleepMode_TypeDef SleepWakeupSrc_TypeDef unsigned int wakeup_tick 1 Parameter deepsleep 0 enter suspend 1 enter deepsleep 2 Parameter wakeup_src It s used to configure wakeup source s for current suspend deepsleep and PM_WAKEUP_PAD PM_WAKEUP_CORE and PM_WAKEUP_TIMER can be selected Note that PM_WAKEUP_TIMER and PM_WAKEUP_CORE can be use...

Страница 119: ...PIO wakeup error occurs currently E g When a GPIO CORE high level wakeup is configured when this GPIO is high level it tries to invoke cpu_sleep_wakeup to enter suspend and wakeup source is set as PM_WAKEUP_CORE In this case MCU cannot enter suspend but will exit cpu_sleep_wakeup immediately and return the value STATUS_GPIO_ERR_NO_ENTER_PM 4 STATUS_ENTER_SUSPEND represents the status enters suspen...

Страница 120: ...ep mode when this function is executed and it can be woken up by GPIO PAD and Timer Timer wakeup time is 10s relative to function execution moment If GPIO PAD wakeup is triggered before 10s expires MCU will be woke up by GPIO otherwise MCU will be woken up by Timer 4 2 BLE Low Power Management In 5316 BLE SDK low power management is implemented via power management of Link Layer In current Telink ...

Страница 121: ... process UI task or enter suspend Actually BLE PM includes the management of the UI task suspend duration User can manage this duration and determine whether to run UI task or enter suspend to save power BLE PM does not include the management of deepsleep User can directly invoke cpu_sleep_wakeup in UI layer to enter deepsleep BLE PM does not need user to directly invoke the API cpu_sleep_wakeup i...

Страница 122: ...spendMask If the variable is not configured the value equals the default SUSPEND_DISABLE Values for SuspendMask include Power Management define SUSPEND_DISABLE 0 define SUSPEND_ADV BIT 0 define SUSPEND_CONN BIT 1 define MCU_STALL BIT 6 MCU_STALL is a special mode and it will be introduced later Please refer to Link Layer timing sequence section 3 2 4 and working mechanism of low power management s...

Страница 123: ... layer and become invalid The wakeup source for suspend or deepsleep needs to be re configured 4 3 4 Working Mechanism of Low Power Managment To better understand the configurations of SuspendMask and WakeupSource this section introduces the principle of low power management mechanism In SDK mainloop is a structure of while 1 while 1 blt_sdk_main_loop UI task blt_sdk_main_loop is being executed in...

Страница 124: ...ter low power mode and loop of while 1 is being executed nonstop 2 If Adv Event of Advertising State or Brx Event of Conn state Slave role is being executed blt_brx_sleep will not be executed as RF task is in operation SDK only enter sleep mode after Adv Event or Brx Event is completed blt_brx_sleep will be executed only if it is not under the two conditions above void blt_brx_sleep void if Link L...

Страница 125: ...atency_use bls_calculateLatency wakeup_tick T_brx latency_use 1 conn_interval else conn_latency 0 wakeup_tick T_brx conn_interval Execute callback function of event BLT_EV_FLAG_SUSPEND_ENTER cpu_sleep_wakeup 0 PM_WAKEUP_TIMER WakeupSource wakeup_tick Execute callback function of event BLT_EV_FLAG_SUSPEND_EXIT if current suspend is woken up by GPIO CORE in advance Execute callback function of event...

Страница 126: ... e g there are data to be sent or there are data received from Master to be processed MCU must be woke up during next interval to continue the task so system latency should be 0 b If current system has no task to process system latency should equal connection latency except in the case below If update map request or update connection parameter request is received from Master and the actual update ...

Страница 127: ... in the callback function of BLT_EV_FLAG_SUSPEND_ENTER event Following is a key scan application example to illustrate the usage of BLT_EV_FLAG_SUSPEND_ENTER callback function and bls_pm_getSystemWakeupTick bls_app_registerEventCallback BLT_EV_FLAG_SUSPEND_ENTER ble_remote_set_sleep_wakeup void ble_remote_set_sleep_wakeup u8 e u8 p int n if bls_ll_getCurrentState BLS_LINK_STATE_CONN u32 bls_pm_get...

Страница 128: ...s configured to wake up from suspend by high level of certain GPIO CORE the GPIO input must be low level when MCU invokes cpu_wakeup_sleep to enter suspend If the GPIO is already high level input currently the configuration won t take effect and Slave doesn t enter suspend This also applies to GPIO PAD wakeup The situation above may lead to unexpected problems For example MCU is expected to enter ...

Страница 129: ...asks the blt_pm_proc should be close to the blt_sdk_main_loop since its setting depends on processing result of other tasks in UI entry Conclusions of low power management are 1 If suspend needs to be disabled for task such as IR the SuspendMask should be set as SUSPEND_DISABLE 2 In Advertising state if Slave continuous adv time reaches 60s it should be configured to enter deepsleep in current mai...

Страница 130: ...rther optimize power consumption When the LONG_PRESS_KEY_POWER_OPTIMIZE is 1 after key press is stabilized key_matrix_same_as_last_cnt 5 user can set latency value manually If it s configured as bls_pm_setManualLatency 4 suspend will last for 5 conn_intervals When conn_interval is 10 ms MCU will wake up for every 50 ms 10 4 1 50ms to process LED task and detect key press Actually user needs to con...

Страница 131: ...me If yes suspend will be triggered to wake up in advance at app wakeup_tick as shown in Figure 4 3 If not this wakeup_tick is negligible to bottom layer and wakeup time depends on BLE timing sequence Conn interval UI task brx event sleep app_wakeup_tick T_brx T_wakeup Figure 4 3 Trigger APP Wakup Tick in Advance ...

Страница 132: ...ow this voltage level MCU should shutdown to stop working or enter deepsleep as implemented in the SDK Before MCU shutdown certain UI behavior e g quick LED blinking in the 5316_ble_remote can be used as low battery alarm so as to remind user that it s time to recharge or replace the low battery Secure voltage or alarm voltage is set at 2 0V in current SDK For certain extreme condition of power in...

Страница 133: ...0P B1P B2P B3P B4P B5P B6P B7P PGA0P PGA1P TEMSENSORP RSSI_P VBAT ADC_InputPchTypeDef There are two ways to implement ADC sampling of supply voltage via GPIO input channel 1 Directly connect power supply to GPIO input channel of ADC At ADC initialization by setting specific GPIO to high impedance voltage at the GPIO equals supply voltage so ADC can directly sample supply voltage 2 Use GPIO high le...

Страница 134: ... Mode is forbidden Differential mode supports positive and negative input channel thus voltage to be measured equals the voltage difference of positive end and negative end If only one GPIO input channel is available for ADC this GPIO should be set as positive input channel while GND should be set as negative input channel By this setting voltage difference equals voltage of positive end The code ...

Страница 135: ...le adc_hw_initialized is used to call one initialization When the variable is set to 0 one initialization is called and then the variable should be set to 1 to disable further initialization By using the adc_hw_initialized ADC tasks can switch between Low Battery Detect and other ADC tasks ADC other task Due to dynamic ADC task switch the adc_vbat_init may be executed multiple times so it must be ...

Страница 136: ...ADC time to 41us Sampling 8 times is recommended to get more accurate result If users modify the marco definition the calculation of ADC should be modified accordingly The source code is u32 adcValueAvg adc_sample 2 adc_sample 3 adc_sample 4 adc_sample 5 2 5 2 2 3 Low Battery Voltage Alarm The parameter minVol_mV of the battery_power_check specifies secure or alarm voltage in unit of mV As explain...

Страница 137: ...battery_power_check BATTERY_VOL_MIN 200 2 2V else battery_power_check BATTERY_VOL_MIN 2 0 V Please note that the initialization of GPIO wakeup must be placed before the code above or it may lead to GPIO wakeup failure Value of the analog register DEEP_ANA_REG2 can tell whether it s wakeup from low battery shutdown Battery detect after this wakeup will raise 2000mV alarm voltage to 2200mV recover v...

Страница 138: ...rmware_2 bin RF transform New_firmware storage area 0x00000 0x20000 Firmware_2 bin 0x40000 slave ota_master 0x00000 0x20000 Ota_master bin 0x40000 Firmware_3 bin R F t r a n s f o r m New_firmware storage area OTA of the 2n 1 th time OTA of the 2n 2 th time 0x80000 Figure 6 1 5316F512K Flash Storage Structure 1 OTA Master burns new firmware2 into the Master Flash area starting from 0x20000 2 OTA f...

Страница 139: ... to RAM and the following instruction fetch address equals 0x20000 plus PC pointer value By modifying flag bit value of Flash 0x8 and 0x20008 the part of Flash code to be executed will be determined In TLSR8232 SDK with OTA function support the OTA upgrade process of the 2n 1 th or 2n 2 th time is shown as below 1 After MCU is powered on read Flash address 0x8 and 0x20008 and compare the value wit...

Страница 140: ... 8 based on the new firmware starting address i e ota_program_offset 8 is written with 0x4b and offset address 8 based on the old firmware starting address is written with 0x00 This indicates Slave will execute the firmware from the new area after the next booting 13 Slave reboots and the new firmware will take effect 14 During the whole OTA upgrade process Slave will continuously check whether th...

Страница 141: ... does not need such a large area e g FW size does not exceed 60kB only part of the two 128kB space 0x00000 0x20000 0x20000 0x40000 are used To use the redundant space as data storage area the setting below can be followed bls_ota_setFirmwareSizeAndOffset 60 0x20000 By the configuration above the two 60kB Flash areas 0x00000 0x0F000 and 0x20000 0x2F000 can be used as firmware storage space while th...

Страница 142: ...ck ble ble h includes the reference of ble_ll_ota h Second add OTA related contents in the Attribute Table The att_readwrite_callback_t r and att_readwrite_callback_t w of the OTA data Attribute should be set as otaRead and otaWrite respectively the attribute should be set as Read and Write_without_Rsp Master sends data via Write Command and does not need Slave to respond with ack to enable faster...

Страница 143: ...e this command corresponding callback function is available on Slave side for user to transfer firmware version number 2 0xff01 OTA_Start command To start OTA upgrade process Master needs to send this command to Slave 3 0xff02 OTA_end command When Master confirms all OTA data are correctly received by Slave it will send this command which can be followed by four valid bytes to double check Slave h...

Страница 144: ...0x0b 0x0a 0x09 0x08 0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00 TELINK_SPP data for ota In Read By Type Request from Master the Type is set as the 16 byte UUID The Attribute Handle for the OTA UUID is available from Read By Type Rsp responded by Slave In the figure below the Attribute Handle value is shown as 0x0031 Figure 6 4 Master Obtains OTA Attribute Handle via Read By Type Request 3 optional Obt...

Страница 145: ...gure 6 7 Master Sends OTA start 7 Read 16 byte firmware each time starting from Master Flash 0x20000 assemble them into OTA data packet set corresponding adr_index calculate CRC value and push the packet into TX FIFO until all data of the firmware are sent to Slave OTA data format is used in data transfer 20 byte valid data contains 2 byte adr_index 16 byte firmware data and 2 byte CRC value to th...

Страница 146: ...tes eight 0xff are added to complement 16 bytes CRC calculation result for the former 18 bytes 0xa9 0xff is 0xUVWX Figure 6 8 Master OTA Data 8 After firmware data are sent Master checks if BLE link layer data are all sent out Only when link layer data is acked by Slave it s considered the data is sent successfully If all data are sent Master will send an ota_end command to inform Slave OTA end pa...

Страница 147: ...espondingly The interface in ble_ll_ota h to register this callback function is typedef void ota_versionCb_t void void bls_ota_registerVersionReqCb ota_versionCb_t cb 2 OTA start command is received first two bytes are 0xff01 Slave enters OTA mode If the bls_ota_registerStartCmdCb function is used to register the callback function of OTA start then the callback function is executed to modify some ...

Страница 148: ...rom Master equals the adr_max in this packet If equal OTA succeeds if not equal OTA fails due to packet loss After successful OTA Slave will set the booting flag of the old firmware address in Flash as 0 set the booting flag of the new firmware address in Flash as 0x4b then MCU reboots 5 Slave provides OTA state callback function After Slave starts OTA MCU will finally reboot regardless of OTA res...

Страница 149: ...ess as shown below void LED_show_ota_result int result irq_disable WATCHDOG_DISABLE gpio_set_output_en GPIO_LED 1 if result OTA_SUCCESS OTA success gpio_write GPIO_LED 1 sleep_us 2000000 led on for 2s gpio_write GPIO_LED 0 else OTA fail gpio_set_output_en GPIO_LED 0 bls_ota_registerResultIndicateCb LED_show_ota_result The otaWrite function in Slave is assembled in lib other related interfaces are ...

Страница 150: ...igure 7 1 Row Column Key Matrix Keyscan related configurations in app_config h are shown as below On Telink demo board Row0 Row4 pins are PA5 PA4 PA3 PA2 and PA1 while CoL0 CoL5 pins are PC6 PC5 PC4 PC3 PC2 and PC1 Define drive pin array and scan pin array define KB_DRIVE_PINS GPIO_PA5 GPIO_PA4 GPIO_PA3 GPIO_PA2 GPIO_PA1 define KB_SCAN_PINS GPIO_PC6 GPIO_PC5 GPIO_PC4 GPIO_PC3 GPIO_PC2 GPIO_PC1 Key...

Страница 151: ...ATRIX_ROW_PULL define PULL_WAKEUP_SRC_PC6 MATRIX_COL_PULL define PULL_WAKEUP_SRC_PC5 MATRIX_COL_PULL define PULL_WAKEUP_SRC_PC4 MATRIX_COL_PULL define PULL_WAKEUP_SRC_PC3 MATRIX_COL_PULL define PULL_WAKEUP_SRC_PC2 MATRIX_COL_PULL define PULL_WAKEUP_SRC_PC1 MATRIX_COL_PULL Since ie of general GPIOs is set as 0 by default in gpio_init to read level on scan pins corresponding ie should be enabled def...

Страница 152: ...es in matrix are different during two adjacent key scans it s considered as an update In actual code a debounce filtering processing is enabled It will be considered as a valid update only when button states stay the same during two adjacent key scans but different with the latest stored matrix keyboard state 1 will be returned by the function to indicate valid update matrix keyboard state will be...

Страница 153: ...cordingly for example the keycode of the button between Row0 and CoL1 is VK_UP In the kb_scan_key function the kb_event cnt will be cleared before each scan while the array kb_event keycode won t be cleared automatically Whenever 1 is returned to indicate valid update the kb_event cnt will be used to check current valid count number of pressed buttons 1 If current kb_event cnt 0 previous valid mat...

Страница 154: ...efore each key scan so that it can be used to check whether valid update occurs as shown in the example below In the sample code when kb_event keycode 0 is not zero it s considered a button is pressed but the code won t check further whether two buttons are pressed at the same time or one of the two pressed buttons is released kb_event keycode 0 0 manually clear keycode 0 int det_key kb_scan_key 0...

Страница 155: ...r keycode definition The kb_remap_key_row function in keyboard c serves to process keycode void kb_remap_key_row int drv_ind u32 m int key_max kb_data_t kb_data Figure 7 2 Keycode Processing Function CTRL KEY will be obtained by kb_event ctrl_key and its keycode ranges from 0xe0 to 0xe7 which cannot be used by users In proj drivers usbkeycode h define VK_CTRL 0xe0 define VK_SHIFT 0xe1 define VK_AL...

Страница 156: ...S_START VK_EXT_START 0xa0 VK_SLEEP VK_SYS_START 0xa0 sleep VK_POWER 0xa1 power VK_WAKEUP 0xa2 wake up VK_SYS_END 0xa3 VK_SYS_CNT VK_SYS_END VK_SYS_START 0xa3 0xa0 0x03 VK_MEDIA_START VK_SYS_END 0xa3 VK_W_SRCH VK_MEDIA_START 0xa3 VK_WEB 0xa4 VK_W_BACK VK_W_FORWRD VK_W_STOP VK_W_REFRESH VK_W_FAV 0xa9 VK_MEDIA VK_MAIL VK_CAL VK_MY_COMP VK_NEXT_TRK VK_PREV_TRK VK_STOP b0 VK_PLAY_PAUSE VK_W_MUTE VK_VOL...

Страница 157: ...if no button press is detected on any column scan_pin_need kb_key_pressed gpio In the function kb_key_pressed all rows output low level and stabilized level of scan pins will be read after 20us delay A release_cnt is set as 6 if a detection shows all pressed buttons in the matrix are released it won t consider no button is pressed and stop row by row scan immediately but buffers for six frames If ...

Страница 158: ...ering and fast obtain key values In other cases the filt_en is set as 1 to enable filtering Only when pressed_matrix stays the same during two adjacent key scans but different from the latest valid pressed_matrix the key_changed is set as 1 to indicate valid update in matrix keyboard 4 Buffer processing for pressed_matrix Push pressed_matrix into buffer When the read_key in kb_scan_key int numlock...

Страница 159: ...gh level on GPIO will set GPIO IRQ service flag bit core_648 BIT 18 this flag bit can be used to check whether any button is pressed when a button is pressed 10 11 VCC high level will be read on corresponding drive pin define reg_irq_mask REG_ADDR32 0x640 define reg_irq_src REG_ADDR32 0x648 FLD_IRQ_GPIO_EN BIT 18 As long as GPIO interrupt mask bit core_640 BIT 18 is not enabled the configuration w...

Страница 160: ...tections all show button release state the keyscan flow will be stopped 7 5 Deepsleep Wakeup Fast Keyscan After Slave enters deepsleep during connection state it can be woke up by button press action After wakeup firmware is rebooted in mainloop following user_init Slave will first send adv packets establishes connection and then sends the key value to BLE Master Though 5316 BLE SDK adopts some pr...

Страница 161: ...event_cache kb_event sizeof kb_event endif In initialization key scan is processed before user_init After it s detected by reading retention analog register that MCU enters deep wakeup from connection state the kb_scan_key is invoked to directly obtain the whole matrix button state without enabling the debounce filtering If key scan process shows a button is pressed button state update is returned...

Страница 162: ...d The deepback_pre_proc specifies whether manual release is needed The deepback_post_proc will determine whether to push a button release event into BLE TX FIFO accordingly 7 6 Repeat Key Processing When a button is pressed and held it s needed to enable repeat key function to repeatedly send the key value with a specific interval The repeat key function is masked by default By configuring related...

Страница 163: ... or ashtray If keyscan detects some button is pressed and held without the stuck key processing MCU won t enter deepsleep or other low power state since it always considers the button is not released Two related macros in app_config h are stuck key define STUCK_KEY_PROCESS_ENABLE 0 define STUCK_KEY_ENTERDEEP_TIME 60 in s By default the stuck key processing function is masked User can set the STUCK...

Страница 164: ...sTime STUCK_KEY_ENTERDEEP_TIME 1000000 u32 pin KB_DRIVE_PINS for int i 0 i sizeof pin sizeof pin i extern u8 stuckKeyPress if stuckKeyPress i cpu_set_gpio_wakeup pin i 0 1 reverse stuck key pad wakeup level cpu_sleep_wakeup 1 PM_WAKEUP_PAD 0 deepsleep endif Check whether the latest pressed button is held for more than 60s if yes it s considered as stuck key all row numbers with stuck key will be o...

Страница 165: ...er Handbook AN 19112700 E1 164 Ver 1 0 0 7 8 Power Optimization for Long Key Press Power optimization can be enabled for long pressed keys by enabling the macro LONG_PRESS_KEY_POWER_OPTIMIZE Please refer to the PM section for details ...

Страница 166: ...ther LED task is not finished DEVICE_LED_BUSY If yes MCU will carry out corresponding LED task operation 8 2 LED Task Configuration and Management 8 2 1 LED Event Definition The following structure is used to define a LED event typedef struct unsigned short onTime_ms unsigned short offTime_ms unsigned char repeatCount 0xff special for long on offTime_ms 0 long off onTime_ms 0 unsigned char priorit...

Страница 167: ... LED management When LED is idle LED will accept any LED event delivered by invoking the device_led_setup When LED is busy with a LED event old LED event if another event new LED event comes MCU will compare priority level of the two LED events if the new LED event has higher priority level the old LED event will be discarded and MCU starts to execute the new LED event if the new LED event has the...

Страница 168: ...Telink TLSR8232 BLE SDK Developer Handbook AN 19112700 E1 167 Ver 1 0 0 Users can refer to the code in current 5316 ble remote project for LED related processing ...

Страница 169: ...d and execute timer task This design is implemented based on Timer wakeup of APP layer section 4 8 Current design can run up to four timers and maximum timer number is modifiable via the macro below define MAX_TIMER_NUM 4 timer max number 9 1 Timer Initialization Call the API below to initialize blt software timer void blt_soft_timer_init void Timer initialization only registers blt_soft_timer_pro...

Страница 170: ...rinciple is shown as below 1 First check whether there is still user defined timer in current timer table If not directly exit the function and disable timing wakeup of APP layer if there s timer task continue the flow if blt_timer currentNum bls_pm_setAppWakeupLowPower 0 0 disable return 2 Check whether the nearest timer task reaches if the task reaches exit the function otherwise continue the fl...

Страница 171: ...he new timing cycle unit us 4 In step 3 if tasks in timer task table change the previous time sequence may be disturbed and re ordering is needed if change_flg blt_soft_timer_sort 5 If the nearest timer task will be responded within 3s it can be modified as a value larger than 3s as needed from now the response time will be set as wakeup time of APP layer in advance otherwise APP layer wakeup in a...

Страница 172: ...e is more than 0 this return value will be used as the new timing cycle unit us As shown in the implementation code if timer number exceeds the maximum value the adding operation will fail Whenever a new timer task is added re ordering must be implemented to ensure timer tasks are time ordered while the index corresponding to the nearest timer task should be 0 9 4 Delete Timer Task As introduced a...

Страница 173: ...CHN1_TOGGLE gpio 1 toggle to see the effect static u8 flg 0 flg flg if flg return 7000 else return 17000 int gpio_test2 void DBG_CHN2_TOGGLE gpio 2 toggle to see the effect timer last for 5 second if clock_time_exceed 0 5000000 return 1 blt_soft_timer_delete gpio_test2 return 0 int gpio_test3 void gpio 3 toggle to see the effect DBG_CHN3_TOGGLE return 0 ...

Страница 174: ...dd gpio_test1 7000 blt_soft_timer_add gpio_test2 13000 blt_soft_timer_add gpio_test3 27000 Four tasks are defined with differenet features 1 Toggle gpio_test0 once every 23ms 2 gpio_test1 uses 7ms 17ms toggle timer 3 Delete gpio_test2 after 5s which can be implemented by invoking blt_soft_timer_delete gpio_test2 or return 1 4 Toggle gpio_test3 once every 27ms ...

Страница 175: ...d PWM0_N PWM5_N Six channel PWM is defined in driver typedef enum PWM0_ID 0 PWM1_ID PWM2_ID PWM3_ID PWM4_ID PWM5_ID pwm_id Only six channel PWM0 PWM5 are configured in software while the other six channel PWM0_N PWM5_N is inverted output of PWM0 PWM5 waveform For example PWM0_N is inverted output of PWM0 waveform When PWM0 is high level PWM0_N is low level When PWM0 is low level PWM0_N is high lev...

Страница 176: ...system_clock_hz int pwm_clk is used to set PWM clock system_clock_hz current system clock CLOCK_SYS_CLOCK_HZ The marco is defined in app_config h pwm_clk PWM clock to be configured system_clock_hz must be an integral multiple of pwm_clk so as to get the right PWM clock via frequency division To increase accuracy of PWM waveform PWM clock must be as large as possible but smaller than system clock I...

Страница 177: ...a PWM signal frame is calculated as below PWM duty PWM cmp PWM cycle The figure below shows the result of pwm_set_cycle_and_duty PWM0_ID 5 2 The cycle of a Signal Frame is five PWM clocks 2 PWM clocks in high level PWM duty is 40 PWM clock PWM waveform 1 2 3 4 5 cycle cmp Signal Frame Signal Frame Figure 10 1 PWM Cycle Duty For PWM0 PWM5 by default hardware will set PWM output high level followed ...

Страница 178: ...R_MODE 0x03 PWM_IR_FIFO_MODE 0x07 PWM_IR_DMA_FIFO_MODE 0x0F pwm_mode The API to set PWM mode is void pwm_set_mode pwm_id id pwm_mode mode PWM0 supports all five modes Normal mode Counting mode IR mode IR FIFO mode and IR DMA FIFO mod while PWM1 PWM5 only support normal mode In other words PWM0 supports other four special modes besides normal mode Please section 8 5 in TLSR8232 datasheet for detail...

Страница 179: ...firmware pointer PC will jump to interrupt handling part irq_handler To enable interrupt response please make sure all mask bits corresponding to current IRQ are enabled One IRQ may correspond to multiple mask bits which are the relation of logic And IRQ request won t trigger interrupt response unless all of its related mask bits are enabled PWM driver in the register h only involves the following...

Страница 180: ...ed by the API pwm_set_pulse_num As shown in the figure above PWM0 will generate a Pnum IRQ signal at the end of a pulse group containing three Signal Frames 3 IRQ_PWM0_IR_DMA_FIFO_DONE In IR DMA FIFO mode PWM0 will generate an IR waveform send done IRQ signal IRQ_PWM0_IR_DMA_FIFO_DONE after all PWM waveforms configured in DMA are sent As described above IRQ request won t trigger interrupt response...

Страница 181: ... For TLSR8232 n can be up to 256 After DMA data buffer takes effect PWM HW module will send out waveform 1 waveform n successively After all waveforms are sent PWM is stopped automatically and IRQ_PWM0_IR_DMA_FIFO_DONE is triggered 10 1 10 1 Configuration of DMA FIFO Each DMA FIFO uses 2 bytes 16 bits to configure one PWM waveform When the API below is called 2 byte DMA FIFO data will be returned ...

Страница 182: ...igned short cycle_tick unsigned short cmp_tick 10 1 10 2 Set DMA FIFO Buffer After DMA FIFO buffer is configured call the API below to set the starting address of the buffer to DMA module Void pwm_set_dma_address void pdat 10 1 10 3 Start and Stop of IR DMA FIFO Mode After DMA FIFO buffer is prepared call the API below to start sending PWM waveforms void pwm_start_dma_ir_sending void After all PWM...

Страница 183: ...e 5316 introduces an extra IR DMA FIFO mode which is not supported by 826x In IR DMA FIFO mode since FIFO can be defined in SRAM more FIFOs are available which can effectively solve the shortcoming of PWM IR mode above IR DMA FIFO mode supports pre storage of multiple PWM waveforms into SRAM Once DMA is started no software involvement is needed This can save frequent SW processing time and avoid P...

Страница 184: ...nt the first FifoTask_repeat is 110ms later after IR is started After FifoTask_idle is finished trigger IRQ_PWM0_IR_DMA_FIFO_DONE 3 In interrupt function of IRQ_PWM0_IR_DMA_FIFO_DONE start the first FifoTask_repeat Each FifoTask_repeat lasts for 110ms By adding FifoTask_repeat in corresponding interrupt function IR repeat signals can be sent continuously 4 The time point to stop IR is not certain ...

Страница 185: ...ollowing flow In the interrupt when FifoTask_data is finished enable FifoTask_idle In the interrupt when FifoTask_idle is finished enable FifoTask_repeat Before manually stopping IR DMA FIFO mode FifoTask_repeat is executed continually void ir_nec_send u8 addr1 u8 addr2 u8 cmd Add FifoTask_data to Dma ir_send_ctrl is_sending IR_SENDING_DATA ir_send_ctrl sending_start_time clock_time pwm_start_dma_...

Страница 186: ...t_phase PWM0_ID 0 no phase at pwm beginning pwm_set_cycle_and_duty PWM0_ID PWM_CARRIER_CYCLE_TICK PWM_CARRIER_HIGH_TICK pwm_set_dma_address T_dmaData_buf reg_irq_mask FLD_IRQ_SW_PWM_EN reg_pwm_irq_sta FLD_IRQ_PWM0_IR_DMA_FIFO_DONE Since only PWM0 supports ID DMA FIFO mode PA0 is selected to correspond to PWM0 herein In the demo IR carrier frequency is 38K cycle is 26 3us and duty cycle is 1 3 The ...

Страница 187: ...ation 10 2 5 1 FIFO Task_data As per demo IR protocol to send a cmd e g 7 first send start signal i e 9ms carrier signal 4 5ms low level signal no carrier then send address address cmd cmd In the demo code address is 0x88 When sending the final bit of cmd logical 0 or logical 1 always contains some non carrier signals at the end If cmd is not followed by any data there may be a problem on Rx side ...

Страница 188: ..._buf data T_dmaData_buf data_num waveform_logic_1_2nd else waveform for logic_0 T_dmaData_buf data T_dmaData_buf data_num waveform_logic_0_1st T_dmaData_buf data T_dmaData_buf data_num waveform_logic_0_2nd waveform for stop bit T_dmaData_buf data T_dmaData_buf data_num waveform_stop_bit_1st T_dmaData_buf data T_dmaData_buf data_num waveform_stop_bit_2nd T_dmaData_buf dma_len T_dmaData_buf data_num...

Страница 189: ...peat pwm_config_dma_fifo_waveform 0 PWM0_PULSE_NORMAL tick_2_repeat_sysTimer PWM_CARRIER_CYCLE_TICK 10 2 5 3 FifoTask_repeat As per Demo IR protocol repeat signal is 9ms carrier signal 2 25ms non carrier signal Similar to the processing of FifoTask_data the end of repeat signal should be followed by 560us carrier signal as stop signal As introduced in IR timing design repeat signal lasts for 110ms...

Страница 190: ...ifoTask_repeat n FifoTask_idle_repeat n By simple superposition in DMA Fifo buffer FifoTask_repeat n and FifoTask_idle_repeat n can be implemented on the basis of FifoTask_idle and FifoTask_repeat 10 2 6 Check IR Busy Status in APP Layer In the Application layer user can use the variable ir_send_ctrl is_sending to check whether IR is busy sending data or repeat signal ir_send_ctrl is_sending As sh...

Страница 191: ... crystal i e 32kHz RC The error of this crystal is large so its accuracy will be influenced for applications with long suspend time Currently 32kHz RC supports up to 3s suspend by default Once the suspend time exceeds 3s inaccurate packet Rx time will be caused by BLE timing error this case usually needs packet Rx Tx retry thus to increase power consumption and result in disconnection To ensure ti...

Страница 192: ...r The function is void emicarrieronly RF_ModeTypeDef rf_mode RF_TxPowerTypeDef pwr signed char rf_chn Parameters rf_mode Set RF mode RF_MODE_BLE_1M and RF_MODE_BLE_2M are optional pwr Set tx power see the definition of RF_TxPowerTypeDef for its values rf_chn Set RF channel the channel actually used is 2400 rf_chn 11 3 1 2 CD Mode CD mode is used to test the sending of carrirer with data The functi...

Страница 193: ... RF_TxPowerTypeDef pwr signed char rf_chn void emitx0f RF_ModeTypeDef rf_mode RF_TxPowerTypeDef pwr signed char rf_chn void emitx55 RF_ModeTypeDef rf_mode RF_TxPowerTypeDef pwr signed char rf_chn Parameters rf_mode Set RF mode RF_MODE_BLE_1M and RF_MODE_BLE_2M are optional pwr Set tx power see the definition of RF_TxPowerTypeDef for its values rf_chn Set RF channel the channel actually used is 240...

Страница 194: ...their own testing and customize their own testing methods by calling related functions 11 3 2 EMI Test Tool Telink provides EMI Test Tool in order to facilitate testing EMI Test Tool can be used with EMI test in project 5316_driver_test to implement EMI test easily The tool interface is shown as below Figure 11 1 EMI Test Tool Step 1 User can select hardware connection method as needed When Swire ...

Страница 195: ...E1 194 Ver 1 0 0 Figure 11 3 Swire synchronization operation Step 2 Set chn i e input frequency e g 2402 in the corresponding box and click Set_Channel The log window will show Swire OK to indicate normal communication as shown below Figure 11 4 Set Channel ...

Страница 196: ...0 0 Step 3 Select power level and BLE mode via the corresponding drop down box and click Set_Power Set_RF_Mode Figure 11 5 Select RF Mode Figure 11 6 Interface After RF Mode Setting Step 4 Click Carrier CarrierData RXTest PRBS9 0x55 0x0f to enter corresponding test mode ...

Страница 197: ...nk TLSR8232 BLE SDK Developer Handbook AN 19112700 E1 196 Ver 1 0 0 Figure 11 7 Select Test Mode Step 5 In TX mode user can select to send 1000 packets or unlimited packets Figure 11 8 Set TX Packet Number ...

Страница 198: ...112700 E1 197 Ver 1 0 0 Figure 11 9 TX Mode Interface Step 6 In RX mode number of received packets can be read by clicking Read_Rx_Cnt while current RSSI can be obtained by clicking ReadRssi as shown below Figure 11 10 Read RX Packet Number and RSSI ...

Страница 199: ...Telink TLSR8232 BLE SDK Developer Handbook AN 19112700 E1 198 Ver 1 0 0 11 4 PHY Test To be added ...

Страница 200: ...tion cmdID 2 Command ID ParaLen 2 Length of parameters Parameters n Parameter payload Table 12 2 BLE SPP Events From Telink BLE Module to Host Field Bytes Description Token 1 Always be 0xFF ParaLen 1 Length of parameters eventId 2 Event ID Parameters n Parameter payload BLE SPP command indicates a command sent from the Host to Telink BLE module while BLE SPP event indicates a synchronous event or ...

Страница 201: ...06 e g 02 FF 06 00 01 02 03 04 05 06 Command Complete event Enable Disable Advertising 0xFF0A 0x0001 Enable 0x01 Disable 0x00 e g 0A FF 01 00 01 Command Complete event Get Module Available Data Buffer 0xFF0C 0x0000 NA 0C FF 00 00 Command Complete event Set Advertising Type 0xFF0D 0x0001 0x00 connectable undirected adv 0x01 connectable directed adv 0x02 scannable undirected adv 0x03 non connectable...

Страница 202: ...ss Parameter 2 address e g 01 02 03 04 05 06 e g 10 FF 07 00 00 01 02 03 04 05 06 Command Complete event Reset White List Entry 0xFF11 0x0000 NA 11 FF 00 00 Command Complete event Set Filter Policy 0xFF12 0x0001 00 All device 01 connReq from all device scanReq from WL 02 scanReq from all device connReq from WL 03 scanReq and connReq from WL e g 12 FF 01 00 00 Command Complete event Set device name...

Страница 203: ... current device expects new latency 0x00 u16 connTimeout e g 0x012C means current device expects new timeout 0x12C 10ms 3000ms 15 FF 08 00 A0 00 A2 00 00 00 2C 01 Command Complete event Get module s current work state 0xFF16 0x0000 NA 16 FF 00 00 Command Complete Event Terminate connection 0xFF17 0x0000 NA 17 FF 00 00 Command Complete Event Restart Module 0xFF18 0x0000 NA 18 FF 00 00 No Command Co...

Страница 204: ...tem from MAC binding table 0xFF1B 0x0006 MacAddr MAC address to be deleted from MAC binding table e g B4 CE BF 01 E7 60 e g 1B FF 06 00 B4 CE BF 01 E7 60 Command Complete Event Send Data 0xFF1C 0x0016 e g 0x0007 Handle 2 bytes of the Attribute Service to client E g 0x0011 Data payload Max Len 20bytes E g 01 02 03 04 05 e g 1C FF 07 00 11 00 01 02 03 04 05 Command Complete Event Table 12 4 General ...

Страница 205: ... A0 07 01 02 03 04 05 06 Get Available Buffer Num Event Asynchronous 0xFF 0x04 0x070C State 0x00 OK other Fail Buffer Size 1Byte Eg state 0x00 Buffer Size 0x04 e g FF 03 0C 07 00 04 Connection Event Asynchronous 0xFF 0x02 0x0783 NA FF 02 83 07 Terminate Event Asynchronous 0xFF 0x02 0x0784 NA FF 02 84 07 Channel map change Event Asynchronous 0xFF 0x02 0x078a NA FF 02 8a 07 Connection parameter upda...

Страница 206: ...tool connects PC via USB the serial port assistant in PC establishes soft connection with serial port tool thus the working environment of the module is established Before using the module function the Firmware should be burned to the module 5316 BLE SDK provides module project users only need to compile the module project to obtain the bin file Note the bin file in this documents sets BLE_MODULE_...

Страница 207: ...project as needed The PC can transfer commands and data to the module while the module can only report corresponding events to the PC If it is commands that are transferred by the PC the module will process the commands and report an event to the PC according to the processing result if it is data that are transferred by the PC the module will transfer the data to a remote device via BLE and repor...

Страница 208: ... 0 Figure 12 4 Module Sending Data Figure 12 5 Phone Receiving Data 12 2 2 Module Receives Data The phone can send data to the module the module will report to the PC after it receives the data as Figure 12 6 and Figure 12 7 show The part highlighted by the red rectangle ...

Страница 209: ...ndbook AN 19112700 E1 208 Ver 1 0 0 in Figure 12 6 is the data sent by the phone the part highlighted by the red rectangle in Figure 12 7 is the data received by the module Figure 12 6 Phone Sending Data Figure 12 7 Module Receiving Data ...

Страница 210: ... users requirements and hardware design One GPIO is used to wake up the module so that the module can receive the commands and data sent by the Host another GPIO is used to wake up the Host if the Host enables low power so that the Host can receive the events reported by the module If the module enables low power mode the connection of hardware should be the same as below Figure 12 8 Connection of...

Страница 211: ...1 0 0 Appendix Appendix 1 crc16 Algorithm unsigned shortcrc16 unsigned char pD int len static unsigned short poly 2 0 0xa001 unsigned short crc 0xffff unsigned char ds int i j for j len j 0 j unsigned char ds pD for i 0 i 8 i crc crc 1 poly crc ds 1 ds ds 1 return crc ...

Отзывы: