BLE demo for mbed Ported RunningElectronics's SBDBT firmware for BLE. It can communicate with iOS
Dependencies: FatFileSystem mbed
Fork of BTstack by
usb_itd.cpp
00001 #include "mbed.h" 00002 #include "usb_itd.h" 00003 #define __DEBUG 00004 #include "mydbg.h" 00005 00006 usb_itd::usb_itd(HCITD* itd) 00007 { 00008 DBG_ASSERT(itd); 00009 m_itd = itd; 00010 } 00011 00012 bool usb_itd::Done() 00013 { 00014 int cc = (m_itd->Control >> 28); 00015 if (cc == 0xe || cc == 0xf) { // not accessed? 00016 return false; 00017 } 00018 if (m_itd->Next) { 00019 return false; 00020 } 00021 return true; 00022 } 00023 00024 int usb_itd::ConditionCode() 00025 { 00026 int cc = (m_itd->Control >> 28); 00027 return cc; 00028 } 00029 00030 uint16_t usb_itd::get_psw(int n) 00031 { 00032 DBG_ASSERT(n >= 0 && n <= 7); 00033 DBG_ASSERT(m_itd); 00034 uint16_t psw = 0; 00035 switch(n) { 00036 case 0: psw = m_itd->OffsetPSW10; break; 00037 case 1: psw = m_itd->OffsetPSW10 >> 16; break; 00038 case 2: psw = m_itd->OffsetPSW32; break; 00039 case 3: psw = m_itd->OffsetPSW32 >> 16; break; 00040 case 4: psw = m_itd->OffsetPSW54; break; 00041 case 5: psw = m_itd->OffsetPSW54 >> 16; break; 00042 case 6: psw = m_itd->OffsetPSW76; break; 00043 case 7: psw = m_itd->OffsetPSW76 >> 16; break; 00044 } 00045 return psw; 00046 } 00047 00048 uint16_t usb_itd::StartingFrame() 00049 { 00050 return (m_itd->Control & ITD_SF); 00051 } 00052 00053 int usb_itd::FrameCount() 00054 { 00055 DBG_ASSERT(m_itd); 00056 int fc = ((m_itd->Control & ITD_FC) >> 24) + 1; 00057 DBG_ASSERT(fc >= 1 && fc <= 8); 00058 return fc; 00059 } 00060 00061 int usb_itd::PacketStatus(int n) 00062 { 00063 DBG_ASSERT(n >=0 && n <= 7); 00064 uint16_t psw = get_psw(n); 00065 int cc = (psw >> 12) & 0xf; 00066 return cc; 00067 } 00068 00069 int usb_itd::Length(int n) 00070 { 00071 DBG_ASSERT(n >=0 && n <= 7); 00072 uint16_t psw = get_psw(n); 00073 int size = psw & 0x7ff; 00074 int cc = (psw >> 12) & 0xf; 00075 if (cc == 0xe || cc == 0xf) { 00076 return -1; 00077 } 00078 if (cc == 0 || cc == 9) { 00079 return size; 00080 } 00081 debug(); 00082 return -1; 00083 } 00084 00085 uint8_t* usb_itd::BufferPage(int n, int size) 00086 { 00087 DBG_ASSERT(n >=0 && n <= 7); 00088 DBG_ASSERT(size >= 128 && size <= 956); 00089 uint8_t* buf = (uint8_t*)m_itd->BufferPage0 + n * size; 00090 DBG_ASSERT((uint32_t)(buf+size-1) <= m_itd->BufferEnd); 00091 return buf; 00092 } 00093 00094 void usb_itd::free() 00095 { 00096 DBG_ASSERT(m_itd); 00097 if (m_itd) { 00098 uint8_t* buf = (uint8_t*)m_itd->BufferPage0; 00099 DBG_ASSERT(buf); 00100 usb_free_bp(buf); 00101 usb_free_itd((byte*)m_itd); 00102 m_itd = NULL; 00103 } 00104 } 00105 00106 void usb_itd::debug() 00107 { 00108 DBG("itd =%08X\n", m_itd); 00109 DBG("itd->Control =%08X\n", m_itd->Control); 00110 DBG("itd->BufferPage0=%08X\n", m_itd->BufferPage0); 00111 DBG("itd->Next =%08X\n", m_itd->Next); 00112 DBG("itd->BufferEnd =%08X\n", m_itd->BufferEnd); 00113 DBG("itd->OffsetPSW10=%08X\n", m_itd->OffsetPSW10); 00114 DBG("itd->OffsetPSW32=%08X\n", m_itd->OffsetPSW32); 00115 DBG("itd->OffsetPSW54=%08X\n", m_itd->OffsetPSW54); 00116 DBG("itd->OffsetPSW76=%08X\n", m_itd->OffsetPSW76); 00117 }
Generated on Thu Jul 14 2022 15:03:49 by 1.7.2