one_net_status_t tal_look_for_packet(tick_t duration) { UInt8 blks_to_rx = ON_MAX_ENCODED_PKT_SIZE; tick_t end = get_tick_count() + duration; tal_turn_on_receiver(); rx_rf_count = 0; rx_rf_idx = 0; while(!SYNCDET) { if(get_tick_count() >= end) { return ONS_TIME_OUT; } // if done looking // } // while no sync detect // #ifdef HAS_LEDS set_rx_led(TRUE); #endif ENABLE_RX_BIT_INTERRUPTS(); do { // the id length should be the location in the byte stream where the // PID will be received. Look for the PID so we know how many bytes // to receive. if(rx_rf_count == ON_ENCODED_PID_IDX - ONE_NET_PREAMBLE_HEADER_LEN + ON_ENCODED_PID_SIZE) { // All packet size constants below are including the PREAMBLE & // SOF. Since these cause the sync detect, these won't be read // in, so the packet size that is being read in is shorter, so // subtract the ON_ENCODED_DST_DID_IDX since that is where the // read is being started. UInt16 raw_pid; if(!get_raw_pid(&encoded_pkt_bytes[ON_ENCODED_PID_IDX], &raw_pid)) { DISABLE_RX_BIT_INTERRUPTS(); #ifdef HAS_LEDS set_rx_led(FALSE); #endif return ONS_BAD_ENCODING; } blks_to_rx = get_encoded_packet_len(raw_pid, FALSE); if(blks_to_rx == 0) { // bad packet type DISABLE_RX_BIT_INTERRUPTS(); #ifdef HAS_LEDS set_rx_led(FALSE); #endif return ONS_BAD_PKT_TYPE; } } // if PID read // } while(rx_rf_count < blks_to_rx); DISABLE_RX_BIT_INTERRUPTS(); #ifdef HAS_LEDS set_rx_led(FALSE); #endif return ONS_SUCCESS; }
DMPAPI(void *) CreateUSBDevice(void) { USB_Device *usb = NULL; if ((usb = (USB_Device *)ker_Malloc(sizeof(USB_Device))) == NULL) return NULL; if (io_Init() == false) { err_print((char*)"%s: Init IO lib error!!\n", __FUNCTION__); ker_Mfree((void *)usb); return NULL; } usb->addr = vx86_GetUSBDevAddr(); usb->nIRQ = vx86_GetUSBDevIRQ(); if (usb->addr == 0x0000 || usb->nIRQ == 0) { io_Close(); ker_Mfree((void *)usb); return NULL; } usb->DevAddr = 0x00; usb->ReadySetAddr = false; usb->state = USB_DEV_NOT_ATTACHED; usb->stall = false; usb->InUse = 0; usb->IsSet = 0; usb->setup_in_handled = false; usb->setup_out_handled = false; usb->bulk_in_transmitting = false; usb->TimeOut = USB_NO_TIMEOUT; usb->InDataPtr = NULL; usb->OutDataPtr = NULL; usb->InDataSize = 0; usb->OutDataSize = 0; if ((usb->rcvd = CreateQueue(RX_QUEUE_SIZE)) == NULL) goto CREATE_RX_QUEUE_FAIL; if ((usb->xmit = CreateQueue(TX_QUEUE_SIZE)) == NULL) goto CREATE_TX_QUEUE_FAIL; usb->Setup.bmRequestType = 0; usb->Setup.bRequest = 0; usb->Setup.wValue.Value = 0; usb->Setup.wIndex.Value = 0; usb->Setup.wLength = 0; usb->ling_coding.dwDTERate = 0; usb->ling_coding.bCharFormat = 0; usb->ling_coding.bParityType = 0; usb->ling_coding.bDataBits = 0; usb->control_line_state = 0; usb->serial_state = 0; usb->DAR = usb->addr + 0x00; usb->CFR = usb->addr + 0x02; usb->FNR = usb->addr + 0x06; usb->IER = usb->addr + 0x08; usb->ISR = usb->addr + 0x0C; usb->TMR = usb->addr + 0x68; memset((Endpoint *)usb->EP, 0, sizeof(usb->EP)); usb->EP[0].CtrlTR = usb->addr + 0x10; usb->EP[1].OutTR = usb->addr + 0x12; usb->EP[1].InTR = usb->addr + 0x14; usb->EP[2].OutTR = usb->addr + 0x16; usb->EP[2].InTR = usb->addr + 0x18; usb->EP[3].OutTR = usb->addr + 0x1A; usb->EP[3].InTR = usb->addr + 0x1C; usb->EP[0].SetupDLR = usb->addr + 0x20; usb->EP[0].OutDLR = usb->addr + 0x24; usb->EP[0].InDLR = usb->addr + 0x28; usb->EP[1].OutDLR = usb->addr + 0x2C; usb->EP[1].InDLR = usb->addr + 0x30; usb->EP[2].OutDLR = usb->addr + 0x34; usb->EP[2].InDLR = usb->addr + 0x38; usb->EP[3].OutDLR = usb->addr + 0x3C; usb->EP[3].InDLR = usb->addr + 0x40; usb->EP[0].SetupDSR = usb->addr + 0x44; usb->EP[0].OutDSR = usb->addr + 0x48; usb->EP[0].InDSR = usb->addr + 0x4C; usb->EP[1].OutDSR = usb->addr + 0x50; usb->EP[1].InDSR = usb->addr + 0x54; usb->EP[2].OutDSR = usb->addr + 0x58; usb->EP[2].InDSR = usb->addr + 0x5C; usb->EP[3].OutDSR = usb->addr + 0x60; usb->EP[3].InDSR = usb->addr + 0x64; #ifdef DMP_86DUINO_MODE set_gpio_config_addr(GPIO_CONFIG_ADDR); // for 86duino set_tx_led(7, 2); set_rx_led(7, 3); TX_LED_OFF(); RX_LED_OFF(); #endif return (void *)usb; CREATE_TX_QUEUE_FAIL: DestoryQueue(usb->rcvd); CREATE_RX_QUEUE_FAIL: io_Close(); ker_Mfree((void *)usb); return NULL; }