void Usb_t::IRxHandler() { OTG_FS->GINTMSK &= ~GINTMSK_RXFLVLM; // Disable RX irq until current one is processed uint32_t sts = OTG_FS->GRXSTSP; // Get the Status from the top of the FIFO uint32_t EpN = (sts & GRXSTSP_EPNUM_MASK); uint32_t cnt = (sts & GRXSTSP_BCNT_MASK) >> GRXSTSP_BCNT_OFF; uint32_t dpid = (sts & GRXSTSP_DPID_MASK) >> 15; Uart.Printf(" dpid %X\r\n", dpid); switch(sts & GRXSTSP_PKTSTS_MASK) { case GRXSTSP_SETUP_COMP: Uart.Printf(" setup comp\r\n"); // Ep[0].EnableOut(); // Reenable Out transactions, as core disables it when transfer completed // Ep[0].ClearOutNAK(); break; case GRXSTSP_SETUP_DATA: Uart.Printf(" setup %u %u\r\n", cnt, EpN); chSysLockFromIsr(); ReadFifo(SetupReq.Buf, OTG_FS->FIFO[0], cnt); chSysUnlockFromIsr(); // Uart.Printf("> %A\r\n", SetupReq.Buf, 8, ' '); Uart.Printf("%X %X %X %u %u\r\n", SetupReq.bmRequestType, SetupReq.bRequest, SetupReq.wValue, SetupReq.wIndex, SetupReq.wLength); break; case GRXSTSP_OUT_COMP: Uart.Printf(" out comp\r\n"); //Ep[EpN].EnableOut(); // Reenable Out transactions, as core disables it when transfer completed //Ep[EpN].ClearOutNAK(); //Ep[EpN].SetOutNAK(); break; case GRXSTSP_OUT_DATA: Uart.Printf(" out %u %u\r\n", cnt, EpN); chSysLockFromIsr(); ReadFifo(Ep[EpN].Rx.Ptr, OTG_FS->FIFO[0], cnt); chSysUnlockFromIsr(); Ep[EpN].Rx.Ptr += cnt; Ep[EpN].Rx.Cnt += cnt; break; default: Uart.Printf(" RX sts: %X\r\n", sts); break; } // switch OTG_FS->GINTMSK |= GINTMSK_RXFLVLM; // Reenable RX irq }
bool RunBuffer() { // fifo is read 32 bytes at a time // read fifo data to internal buffer if (cpreg.ctrl.GPReadEnable) ReadFifo(); SetStatus(); _dbg_assert_(COMMANDPROCESSOR, writePos >= readPos); g_pVideoData = &commandBuffer[readPos]; u32 availableBytes = writePos - readPos; while (OpcodeDecoder::CommandRunnable(availableBytes)) { cpreg.status.CommandIdle = 0; OpcodeDecoder::Run(availableBytes); // if data was read by the opcode decoder then the video data pointer changed readPos = (u32)(g_pVideoData - &commandBuffer[0]); _dbg_assert_(VIDEO, writePos >= readPos); availableBytes = writePos - readPos; } cpreg.status.CommandIdle = 1; bool ranDecoder = false; // move data remaining in the command buffer if (readPos > 0) { memmove(&commandBuffer[0], &commandBuffer[readPos], availableBytes); writePos -= readPos; readPos = 0; ranDecoder = true; } return ranDecoder; }
// Handle the communication of SSTP protocol bool ProcessSstpHttps(CEDAR *cedar, SOCK *s, SOCK_EVENT *se) { UINT tmp_size = 65536; UCHAR *tmp_buf; FIFO *recv_fifo; FIFO *send_fifo; SSTP_SERVER *sstp; bool ret = false; // Validate arguments if (cedar == NULL || s == NULL || se == NULL) { return false; } tmp_buf = Malloc(tmp_size); recv_fifo = NewFifo(); send_fifo = NewFifo(); sstp = NewSstpServer(cedar, &s->RemoteIP, s->RemotePort, &s->LocalIP, s->LocalPort, se, s->RemoteHostname, s->CipherName); while (true) { UINT r; bool is_disconnected = false; bool state_changed = false; // Receive data over SSL while (true) { r = Recv(s, tmp_buf, tmp_size, true); if (r == 0) { // SSL is disconnected is_disconnected = true; break; } else if (r == SOCK_LATER) { // Data is not received any more break; } else { // Queue the received data WriteFifo(recv_fifo, tmp_buf, r); state_changed = true; } } while (recv_fifo->size >= 4) { UCHAR *first4; UINT read_size = 0; bool ok = false; // Read 4 bytes from the beginning of the receive queue first4 = ((UCHAR *)recv_fifo->p) + recv_fifo->pos; if (first4[0] == SSTP_VERSION_1) { USHORT len = READ_USHORT(first4 + 2) & 0xFFF; if (len >= 4) { ok = true; if (recv_fifo->size >= len) { UCHAR *data; BLOCK *b; read_size = len; data = Malloc(read_size); ReadFifo(recv_fifo, data, read_size); b = NewBlock(data, read_size, 0); InsertQueue(sstp->RecvQueue, b); } } } if (read_size == 0) { break; } if (ok == false) { // Disconnect the connection since a bad packet received is_disconnected = true; break; } } // Process the timer interrupt SstpProcessInterrupt(sstp); if (sstp->Disconnected) { is_disconnected = true; } // Put the transmission data that SSTP module has generated into the transmission queue while (true) { BLOCK *b = GetNext(sstp->SendQueue); if (b == NULL) { break; } // When transmit a data packet, If there are packets of more than about // 2.5 MB in the transmission queue of the TCP, discard without transmission if (b->PriorityQoS || (send_fifo->size <= MAX_BUFFERING_PACKET_SIZE)) { WriteFifo(send_fifo, b->Buf, b->Size); } FreeBlock(b); } // Data is transmitted over SSL while (send_fifo->size != 0) { r = Send(s, ((UCHAR *)send_fifo->p) + send_fifo->pos, send_fifo->size, true); if (r == 0) { // SSL is disconnected is_disconnected = true; break; } else if (r == SOCK_LATER) { // Can not send any more break; } else { // Advance the transmission queue by the amount of the transmitted ReadFifo(send_fifo, NULL, r); state_changed = true; } } if (is_disconnected) { // Disconnected break; } // Wait for the next state change if (state_changed == false) { UINT select_time = SELECT_TIME; UINT r = GetNextIntervalForInterrupt(sstp->Interrupt); WaitSockEvent(se, MIN(r, select_time)); } } if (sstp != NULL && sstp->EstablishedCount >= 1) { ret = true; } FreeSstpServer(sstp); ReleaseFifo(recv_fifo); ReleaseFifo(send_fifo); Free(tmp_buf); YieldCpu(); Disconnect(s); return ret; }
void main() { uchar i=0, j=0; uint chksum=0; uchar buffer[17]; uchar temp=0; init(); LED1 = 1; // Blink LED twice - slave delay_ms(500); LED1 = 0; delay_ms(500); LED1 = 1; // Blink LED twice - slave delay_ms(500); LED1 = 0; WriteCMD(0xCA81); WriteCMD(0xCA83); // Enable FIFO while(1) { while(RFM12_IRQ==0) { temp= ReadFifo(); // read in next Rx byte buffer[i++] = temp; if(temp!=0){ for(t=0;t<4;t++){ LED1=1; // turn on led delay_ms(25); LED1=0; // turn on led delay_ms(25); } } if (i==17) // received data + checksum = 17 bytes { i=0; WriteCMD(0xCA81); // disable FIFO chksum=0; for(j=0 ; j<16 ; j++) // calc checksum chksum+=buffer[j]; chksum&=0x0FF; if(chksum==buffer[16]&&buffer[16]!=0) // if checksum ok { for(t=0;t<4;t++){ LED1=1; // turn on led delay_ms(25); LED1=0; // turn on led delay_ms(25); } } /// LED1=0; WriteCMD(0xCA81); // disable FIFO WriteCMD(0xCA83); // enable FIFO, re-Sync }//if }//while } //while }