//--------------------------------------------------------------------+ // Setup/Teardown + helper declare //--------------------------------------------------------------------+ void setUp(void) { memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); hcd_init(); dev_addr = 1; hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); period_head_arr = get_period_head( hostid, 1 ); p_int_qhd = NULL; memclr_(&pipe_hdl, sizeof(pipe_handle_t)); }
void setUp(void) { length = 0; dev_addr = 1; memclr_(cdch_data, sizeof(cdch_data_t)*TUSB_CFG_HOST_DEVICE_MAX); }
error_t custom_add_in_characteristic(uint16_t service_handle, ble_uuid_t* p_uuid, uint8_t properties, uint8_t *p_data, uint16_t min_length, uint16_t max_length, ble_gatts_char_handles_t* p_char_handle) { /* Characteristic metadata */ ble_gatts_attr_md_t cccd_md; ble_gatt_char_props_t char_props; memcpy(&char_props, &properties, 1); if ( char_props.notify || char_props.indicate ) { /* Notification requires cccd */ memclr_( &cccd_md, sizeof(ble_gatts_attr_md_t) ); cccd_md.vloc = BLE_GATTS_VLOC_STACK; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm); } ble_gatts_char_md_t char_md = { 0 }; char_md.char_props = char_props; char_md.p_cccd_md = (char_props.notify || char_props.indicate ) ? &cccd_md : NULL; /* Attribute declaration */ ble_gatts_attr_md_t attr_md = { 0 }; attr_md.vloc = BLE_GATTS_VLOC_STACK; attr_md.vlen = (min_length == max_length) ? 0 : 1; if ( char_props.read || char_props.notify || char_props.indicate ) { BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm); } if ( char_props.write ) { BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); } ble_gatts_attr_t attr_char_value = { 0 }; attr_char_value.p_uuid = p_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.init_len = min_length; attr_char_value.max_len = max_length; attr_char_value.p_value = p_data; ASSERT_STATUS ( sd_ble_gatts_characteristic_add(service_handle, &char_md, &attr_char_value, p_char_handle) ); return ERROR_NONE; }
//--------------------------------------------------------------------+ // Setup/Teardown + helper declare //--------------------------------------------------------------------+ void setUp(void) { ehci_controller_init(); memclr_(xfer_data, sizeof(xfer_data)); memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); TEST_ASSERT_STATUS( hcd_init() ); dev_addr = 1; hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); async_head = get_async_head( hostid ); //------------- pipe open -------------// pipe_hdl_bulk = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_bulk.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl_bulk.xfer_type); p_qhd_bulk = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_bulk.index ]; }
tusb_error_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc) { uint8_t phy_ep = endpoint_address_to_physical_index( p_endpoint_desc->bEndpointAddress ); //------------- Realize Endpoint with Max Packet Size -------------// endpoint_set_max_packet_size(phy_ep, p_endpoint_desc->wMaxPacketSize.size); //------------- DMA set up -------------// memclr_(dcd_dd + phy_ep, sizeof(dcd_dma_descriptor_t)); dcd_dd[phy_ep].is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) ? 1 : 0; dcd_dd[phy_ep].max_packet_size = p_endpoint_desc->wMaxPacketSize.size; dcd_dd[phy_ep].is_retired = 1; // dd is not active at first LPC_USB->USBEpDMAEn = BIT_(phy_ep); sie_command_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+phy_ep, 1, 0); // clear all endpoint status return TUSB_ERROR_NONE; }
void cush_close(uint8_t dev_addr) { tusb_error_t err1, err2; custom_interface_info_t * p_interface = &custom_interface[dev_addr-1]; // TODO re-consider to check pipe valid before calling pipe_close if( pipehandle_is_valid( p_interface->pipe_in ) ) { err1 = hcd_pipe_close( p_interface->pipe_in ); } if ( pipehandle_is_valid( p_interface->pipe_out ) ) { err2 = hcd_pipe_close( p_interface->pipe_out ); } memclr_(p_interface, sizeof(custom_interface_info_t)); ASSERT(err1 == TUSB_ERROR_NONE && err2 == TUSB_ERROR_NONE, (void) 0 ); }
error_t custom_add_in_characteristic(uint16_t service_handle, ble_uuid_t *p_uuid, uint8_t properties, SecurityManager::SecurityMode_t requiredSecurity, uint8_t *p_data, uint16_t length, uint16_t max_length, const uint8_t *userDescriptionDescriptorValuePtr, uint16_t userDescriptionDescriptorValueLen, bool readAuthorization, bool writeAuthorization, ble_gatts_char_handles_t *p_char_handle) { /* Characteristic metadata */ ble_gatts_attr_md_t cccd_md; ble_gatt_char_props_t char_props; memcpy(&char_props, &properties, 1); if (char_props.notify || char_props.indicate) { /* Notification requires cccd */ memclr_( &cccd_md, sizeof(ble_gatts_attr_md_t)); cccd_md.vloc = BLE_GATTS_VLOC_STACK; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm); } ble_gatts_char_md_t char_md = {0}; char_md.char_props = char_props; char_md.p_cccd_md = (char_props.notify || char_props.indicate) ? &cccd_md : NULL; if ((userDescriptionDescriptorValueLen > 0) && (userDescriptionDescriptorValuePtr != NULL)) { char_md.p_char_user_desc = const_cast<uint8_t *>(userDescriptionDescriptorValuePtr); char_md.char_user_desc_max_size = userDescriptionDescriptorValueLen; char_md.char_user_desc_size = userDescriptionDescriptorValueLen; } /* Attribute declaration */ ble_gatts_attr_md_t attr_md = {0}; attr_md.rd_auth = readAuthorization; attr_md.wr_auth = writeAuthorization; attr_md.vloc = BLE_GATTS_VLOC_STACK; /* Always set variable size */ attr_md.vlen = 1; if (char_props.read || char_props.notify || char_props.indicate) { switch (requiredSecurity) { case SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK : BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm); break; case SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM : BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.read_perm); break; case SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM : BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&attr_md.read_perm); break; case SecurityManager::SECURITY_MODE_SIGNED_NO_MITM : BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(&attr_md.read_perm); break; case SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM : BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(&attr_md.read_perm); break; default: break; }; } if (char_props.write || char_props.write_wo_resp) { switch (requiredSecurity) { case SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK : BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); break; case SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM : BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.write_perm); break; case SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM : BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&attr_md.write_perm); break; case SecurityManager::SECURITY_MODE_SIGNED_NO_MITM : BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(&attr_md.write_perm); break; case SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM : BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(&attr_md.write_perm); break; default: break; }; } ble_gatts_attr_t attr_char_value = {0}; attr_char_value.p_uuid = p_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.init_len = length; attr_char_value.max_len = max_length; attr_char_value.p_value = p_data; ASSERT_STATUS ( sd_ble_gatts_characteristic_add(service_handle, &char_md, &attr_char_value, p_char_handle)); return ERROR_NONE; }
//--------------------------------------------------------------------+ // USBH-CLASS API //--------------------------------------------------------------------+ void cush_init(void) { memclr_(&custom_interface, sizeof(custom_interface_info_t) * TUSB_CFG_HOST_DEVICE_MAX); }
//--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ void ehci_controller_init(void) { memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); }