One more handsome victory over my own bug ;)
Now it looks reasonably stable: after several connects and pings at
BTstack counter 1276 :)
Please find a diff:
diff --git a/0my/bt-noos/usbh_bt_core.c b/0my/bt-noos/usbh_bt_core.c
index 909c5bd..04b2f5f 100644
--- a/0my/bt-noos/usbh_bt_core.c
+++ b/0my/bt-noos/usbh_bt_core.c
@@ -24,6 +24,7 @@
#include <string.h>
#define WIRELESS_CLASS 0xe0
+#define FRNUM_PERIOD 0x4000
// most of descriptors data is currently hardcoded:
@@ -57,7 +58,7 @@ typedef struct BT_State_s {
int evt_state;
uint8_t evt_hcn;
- int evt_tmo;
+ uint16_t evt_tmo;
int aclo_busy;
int aclo_state;
@@ -206,7 +207,10 @@ static int usb_bt_cmd_process()
static int usb_bt_evt_process()
{
int len, r;
+ uint16_t cur_fn, fn_diff;
+ cur_fn = HCD_GetCurrentFrame(BT_State.pdev);
+ fn_diff = (FRNUM_PERIOD + cur_fn - BT_State.evt_tmo) %
FRNUM_PERIOD;
switch(BT_State.evt_state){
case 0:
//while(!USB_OTG_IsEvenFrame(BT_State.pdev)); //
hopefully rare and harmless
@@ -217,11 +221,11 @@ static int usb_bt_evt_process()
EVT_ALIGNED_MAX_SIZE,
BT_State.evt_hcn
);
- BT_State.evt_tmo = 20 +
HCD_GetCurrentFrame(BT_State.pdev);
+ BT_State.evt_tmo = (2 + cur_fn) % FRNUM_PERIOD;
BT_State.evt_state = 1;
return 0;
case 1:
- if((int)HCD_GetCurrentFrame(BT_State.pdev) -
BT_State.evt_tmo >= 0){
+ if(fn_diff < FRNUM_PERIOD / 2){
BT_State.evt_state = 0;
break;
}
@@ -241,8 +245,9 @@ static int usb_bt_evt_process()
}
break;
case 2:
- if((int)HCD_GetCurrentFrame(BT_State.pdev) -
BT_State.evt_tmo >= 0)
+ if(fn_diff < FRNUM_PERIOD / 2){
BT_State.evt_state = 0;
+ }
break;
default: return -1;
}
On Dec 30, 10:24 pm, Bruno Montenegro <
brunomontene...@gmail.com>
wrote:
> it should be uploaded at btstack wiki page a link for your project, Vitaly.
> What do you think about this idea? the wikipage could also has an specific
> wiki page for microcontrollers implementation, based on the microcontroller
> architeture, e.g PIC implementation, Texas msp, atmel avr, arm 7 and so on.
> ---------------------------
> Bruno Montenegro
>
> *
> *