Exemplo n.º 1
0
Arquivo: kerosin.c Projeto: C3MA/r0ket
int puts(const char * str)
{
	// There must be at least 1ms between USB frames (of up to 64 bytes)
	// This buffers all data and writes it out from the buffer one frame
	// and one millisecond at a time
#ifdef CFG_PRINTF_USBCDC
    if (USB_Configuration) 
    {
		while(*str)
			cdcBufferWrite(*str++);
		// Check if we can flush the buffer now or if we need to wait
		unsigned int currentTick = systickGetTicks();
		if (currentTick != lastTick)
		{
			uint8_t frame[64];
			uint32_t bytesRead = 0;
			while (cdcBufferDataPending())
			{
				// Read up to 64 bytes as long as possible
				bytesRead = cdcBufferReadLen(frame, 64);
				USB_WriteEP (CDC_DEP_IN, frame, bytesRead);
				systickDelay(1);
			}
			lastTick = currentTick;
		}
    }
#else
    // Handle output character by character in __putchar
    while(*str) __putchar(*str++);
#endif
	
	return 0;
}
Exemplo n.º 2
0
void USB_Configure_Event (void) {
	uint8_t HID_SendBuf[64];
  if (USB_Configuration) {                  /* Check if USB is configured */
    GetInReport();
		USB_WriteEP (HID_DATA_IN, HID_SendBuf, 64);
  }
}
Exemplo n.º 3
0
int main ()
{
	init ();

	gpioSetDir (3, 1, 1);
	gpioSetValue (3, 1, 1);

	int availBytes;
	char buf[32];
	uint8_t frame[64];
	for (int i = 0; i < 64; ++i) {
		frame[i] = i;
	} 
	while (1) {
		systickDelay (1);
		USB_WriteEP (CDC_DEP_IN, frame, 64);
		// CDC_WrOutBuf (text, &textLen);

		CDC_OutBufAvailChar (&availBytes);
		if (availBytes > 0) {
			int bytesToRead = availBytes > 32 ? 32 : availBytes;
			int bytesRead = CDC_RdOutBuf (buf, &bytesToRead);
			gpioSetValue (3, 1, 0);
		}
	}
}
Exemplo n.º 4
0
void UsbSerial_TxChar(char usbData)
{


  USB_WriteEP (CDC_DEP_IN, (unsigned char *)&usbData, 1);
	delay(50);
}
Exemplo n.º 5
0
void USB_Configure_Event (void) {

  if (USB_Configuration) {                  /* Check if USB is configured */
    GetInReport();
    USB_WriteEP(0x81, &InReport, sizeof(InReport));
  }
}
Exemplo n.º 6
0
void USB_EndPoint3 (uint32_t event) {
    switch (event) {
    case USB_EVT_IN:
        GetInReport();
        USB_WriteEP(0x83, &InReport, sizeof(InReport));
        break;
    }
}
void vOutputString( const char * const pcMessage )
{
	if( xSemaphoreTake( xCDCMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
	{
		USB_WriteEP( CDC_DEP_IN, ( uint8_t * ) pcMessage, strlen( pcMessage ) );
		xSemaphoreGive( xCDCMutex );
	}
}
Exemplo n.º 8
0
void USB_EndPoint1 (U32 event) {

  switch (event) {
    case USB_EVT_IN:
      GetInReport();
      USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));
      break;
  }
}
Exemplo n.º 9
0
INLINE uint32_t USB_ReqSetClrFeature (uint32_t sc) {
  uint32_t n, m;

  switch (SetupPacket.bmRequestType.BM.Recipient) {
    case REQUEST_TO_DEVICE:
      if (SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) {
        if (sc) {
          USB_WakeUpCfg(TRUE);
          USB_DeviceStatus |=  USB_GETSTATUS_REMOTE_WAKEUP;
        } else {
          USB_WakeUpCfg(FALSE);
          USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP;
        }
      } else if (SetupPacket.wValue.W == USB_FEATURE_TEST_MODE) {
          return USB_SetTestMode(SetupPacket.wIndex.WB.H);
      } else {
        return (FALSE);
      }
      break;
    case REQUEST_TO_INTERFACE:
      return (FALSE);
    case REQUEST_TO_ENDPOINT:
      n = SetupPacket.wIndex.WB.L & 0x8F;
      m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);
      if ((USB_Configuration != 0) && ((n & 0x0F) != 0) && (USB_EndPointMask & m)) {
        if (SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) {
          if (sc) {
            USB_SetStallEP(n);
            USB_EndPointHalt |=  m;
          } else {
            if ((USB_EndPointStall & m) != 0) {
              return (TRUE);
            }
            USB_ClrStallEP(n);
#if (USB_MSC)
            if ((n == MSC_EP_IN) && ((USB_EndPointHalt & m) != 0)) {
              /* Compliance Test: rewrite CSW after unstall */
              if (CSW.dSignature == MSC_CSW_Signature) {
                USB_WriteEP(MSC_EP_IN, (uint8_t *)&CSW, sizeof(CSW));
              }
            }
#endif
            USB_EndPointHalt &= ~m;
          }
        } else {
          return (FALSE);
        }
      } else {
        return (FALSE);
      }
      break;
    default:
      return (FALSE);
  }
  return (TRUE);
}
Exemplo n.º 10
0
/*
 *  USB Endpoint 2 Event Callback
 *   Called automatically on USB Endpoint 2 Event
 *    Parameter:       event
 */
void USB_EndPoint2(uint32_t event) {
	switch (event) {
	case USB_EVT_OUT:
		USB_ReadEP(USB_ENDPOINT_OUT(2), OUT2Packet);
		lasershark_process_uart_bridge_command();
		USB_WriteEP(USB_ENDPOINT_IN(2), IN2Packet, 64);
		break;
	case USB_EVT_IN:
		break;
	}
}
Exemplo n.º 11
0
/*
 *  USB Endpoint 1 Event Callback
 *   Called automatically on USB Endpoint 1 Event
 *    Parameter:       event
 */
void USB_EndPoint1(uint32_t event) {
	switch (event) {
	case USB_EVT_OUT:
		USB_ReadEP(USB_ENDPOINT_OUT(1), OUT1Packet);
		lasershark_process_command();
		USB_WriteEP(USB_ENDPOINT_IN(1), IN1Packet, 64);
		break;
	case USB_EVT_IN:
		break;
	}
}
Exemplo n.º 12
0
void USB_DataInStage (void) {
  uint32_t cnt;

  if (EP0Data.Count > USB_MAX_PACKET0) {
    cnt = USB_MAX_PACKET0;
  } else {
    cnt = EP0Data.Count;
  }
  cnt = USB_WriteEP(0x80, EP0Data.pData, cnt);
  EP0Data.pData += cnt;
  EP0Data.Count -= cnt;
}
Exemplo n.º 13
0
int SerialCDC::write(const char c) {
	unsigned int i;
	unsigned char cbuf;
	cbuf = c;
	while(!CDC_DepInEmpty)
		;
	USB_WriteEP (CDC_DEP_IN, (unsigned char *)&cbuf, 1);
	for (i=0; i<10000; i++) {
		if (!CDC_DepInEmpty)
			break;
	}
	return (1);
}
Exemplo n.º 14
0
void USB_Device_CDC()
{
        int  numBytesToRead, numBytesRead, numAvailByte;
        static char serBuf [USB_CDC_BUFSIZE];
        static unsigned char b[1];
        b[0] = 'h';
	#if PORT_NUM
        CDC_Init (1);
	#else
	  	CDC_Init (0);
	#endif

	  	Timer_Init();
	  	LED_Init();
        USB_Init();
        USB_Connect(TRUE);                        // USB Connect
        while (!USB_Configuration) ;              // wait until USB is configured

        uint8_t buffer[10];
        uint32_t idx, len;

        while(1)
        {
        	len = 0;
        	while(len == 0)
        	{
        		len = UARTReceive((LPC_UART_TypeDef *)LPC_UART0, buffer, sizeof(buffer));
        	}
        	idx = 0;
			while (idx < len)
			{
				UARTSend((LPC_UART_TypeDef *)LPC_UART0, &buffer[idx], 1);
				idx++;
			}
			USB_WriteEP (CDC_DEP_IN, buffer, len);

  /*              CDC_OutBufAvailChar (&numAvailByte);
                if (numAvailByte > 0)
                {
                	numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte;
                    numBytesRead = CDC_RdOutBuf (&serBuf[0], &numBytesToRead);
                    USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead);
                }*/
          /*      else
                {
                	Timer_Delay(100);
                	USB_WriteEP (CDC_DEP_IN, b, 1);
                }*/
        }
}
Exemplo n.º 15
0
void testWrite()
{
    static int flag = 0;
    unsigned int *memory = (unsigned int *)0x10000000;
    int i;

    if (!flag)
    {
        for (i=0; i<0x2000; i++)
            memory[i] = (unsigned int)&memory[i];
        flag = 1;
    }

    USB_WriteEP(USB_BULK_IN_EP, (uint8_t *)memory, 0x4000);
}
Exemplo n.º 16
0
/*----------------------------------------------------------------------------
  Reads character from serial port buffer and writes to USB buffer
 *---------------------------------------------------------------------------*/
void VCOM_Serial2Usb(void) {
  static char serBuf [USB_CDC_BUFSIZE];
         int  numBytesRead, numAvailByte;

  ser_AvailChar (&numAvailByte);
  if (numAvailByte > 0) {
    if (CDC_DepInEmpty) {
      numBytesRead = ser_Read (&serBuf[0], &numAvailByte);

      CDC_DepInEmpty = 0;
	  USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead);
    }
  }

}
Exemplo n.º 17
0
Arquivo: main.c Projeto: ADTL/ARMWork
void VCOM_Serial2Usb(void) {
  static char serBuf [USB_CDC_BUFSIZE];
  int  numBytesRead, numAvailByte;
	
  //ser_AvailChar (&numAvailByte);
  numAvailByte = USART_available(&usart);
  if (numAvailByte > 0) {
    if (CDC_DepInEmpty) {
      for ( numBytesRead = 0; numBytesRead < numAvailByte && numBytesRead < USB_CDC_BUFSIZE; numBytesRead++) 
        serBuf[numBytesRead] = USART_read(&usart);  //ser_Read (&serBuf[0], &numAvailByte);
      
      CDC_DepInEmpty = 0;
      USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead);
    }
  }

}
Exemplo n.º 18
0
Arquivo: main.c Projeto: DanBUK/r0ket
/*----------------------------------------------------------------------------
  Reads character from serial port buffer and writes to USB buffer
 *---------------------------------------------------------------------------*/
void
VCOM_Serial2Usb (void)
{
  int numBytesRead;

  if (UARTCount > 0)
    {
      if (CDC_DepInEmpty)
	{
	  numBytesRead = (UARTCount<USB_CDC_BUFSIZE)?UARTCount:USB_CDC_BUFSIZE;
	
	  CDC_DepInEmpty = 0;
	  USB_WriteEP (CDC_DEP_IN, (uint8_t*)&UARTBuffer, numBytesRead);
	  UARTCount=0;
	}
    }

}
Exemplo n.º 19
0
void sendChunk(void)
{
    uint32_t chunk;

    // reset timer
    g_sendTimerStart = LPC_TIMER1->TC;

    if (g_sendOffset>=g_sendLen)
    {
        g_sendComplete = 1;
        return;
    }

    if (g_sendLen-g_sendOffset>=USB_MAX_CHUNK)
        chunk = USB_MAX_CHUNK;
    else
        chunk = g_sendLen-g_sendOffset;

    USB_WriteEP(USB_BULK_IN_EP, (uint8_t *)g_sendData + g_sendOffset, chunk);

    g_sendOffset += chunk;
}
Exemplo n.º 20
0
void USB_StatusInStage (void) {
  USB_WriteEP(0x80, NULL, 0);
}
Exemplo n.º 21
0
void USB_StatusInStage(void) {
  USB_WriteEP(0x80, nullptr, 0);
}
Exemplo n.º 22
0
int main(void)
{
  // Configure cpu and mandatory peripherals
  systemInit();

  // Check if projectconfig.h is properly configured for this example
  #if !defined CFG_CHIBI
    #error "CFG_CHIBI must be enabled in projectconfig.h for this example"
  #endif
  #if CFG_CHIBI_PROMISCUOUS == 0
    #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example"
  #endif
  #if defined CFG_INTERFACE
    #error "CFG_INTERFACE must be disabled in projectconfig.h for this example"
  #endif

  #if defined CFG_CHIBI && CFG_CHIBI_PROMISCUOUS != 0
    // Get a reference to the Chibi peripheral control block
    chb_pcb_t *pcb = chb_get_pcb();
    
    // Wait for incoming frames and transmit the raw data over uart
    while(1)
    {
      // Check for incoming messages 
      while (pcb->data_rcv) 
      { 
        // get the length of the data
        rx_data.len = chb_read(&rx_data);
        // make sure the length is nonzero
        if (rx_data.len)
        {
          // Enable LED to indicate message reception 
          gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); 

          
          // Send raw data the to PC for processing using wsbridge
          uint8_t i;
          for (i=0; i<rx_data.len; i++)
          {
            #ifdef CFG_PRINTF_UART
              uartSendByte(rx_data.data[i]);
            #endif
            #ifdef CFG_PRINTF_USBCDC
               // ToDo: This really needs to be refactored!
              if (USB_Configuration) 
              {
                cdcBufferWrite(rx_data.data[i]);
                // Check if we can flush the buffer now or if we need to wait
                unsigned int currentTick = systickGetTicks();
                if (currentTick != lastTick)
                {
                  uint8_t frame[64];
                  uint32_t bytesRead = 0;
                  while (cdcBufferDataPending())
                  {
                    // Read 64 byte chunks until end of data
                    bytesRead = cdcBufferReadLen(frame, 64);
                    // debug_printf("%d,", bytesRead);
                    USB_WriteEP (CDC_DEP_IN, frame, bytesRead);
                    systickDelay(1);
                  }
                  lastTick = currentTick;
                }
              }  
            #endif
          }

          // Disable LED
          gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); 
        }
      }
    }
  #endif

  return 0;
}
Exemplo n.º 23
0
void USB_EndPoint1 (DWORD event) {
  GetInReport();
  USB_WriteEP(0x81, &InReport, sizeof(InReport));
}
static void prvCDCCommandConsoleTask( void *pvParameters )
{
char cRxedChar;
uint8_t ucInputIndex = 0;
char *pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
portBASE_TYPE xReturned;

	( void ) pvParameters;

	/* Obtain the address of the output buffer.  Note there is no mutual
	exclusion on this buffer as it is assumed only one command console
	interface will be used at any one time. */
	pcOutputString = FreeRTOS_CLIGetOutputBuffer();

	/* Initialise the virtual com port (CDC) interface. */
	prvSetupUSBDrivers();

	/* Send the welcome message.  This probably won't be seen as the console
	will not have been connected yet. */
	USB_WriteEP( CDC_DEP_IN, ( uint8_t * ) pcWelcomeMessage, strlen( pcWelcomeMessage ) );

	for( ;; )
	{
		/* No characters received yet for the current input string. */
		cRxedChar = 0;

		/* Only interested in reading one character at a time. */
		cRxedChar = cGetCDCChar();

		if( xSemaphoreTake( xCDCMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
		{
			/* Echo the character back. */
			USB_WriteEP( CDC_DEP_IN, ( uint8_t * ) &cRxedChar, sizeof( uint8_t ) );

			/* Was it the end of the line? */
			if( cRxedChar == '\n' || cRxedChar == '\r' )
			{
				/* Just to space the output from the input. */
				USB_WriteEP( CDC_DEP_IN, ( uint8_t * ) pcNewLine, strlen( pcNewLine ) );

				/* See if the command is empty, indicating that the last command is
				to be executed again. */
				if( ucInputIndex == 0 )
				{
					/* Copy the last command back into the input string. */
					strcpy( cInputString, cLastInputString );
				}

				/* Pass the received command to the command interpreter.  The
				command interpreter is called repeatedly until it returns pdFALSE
				(indicating there is no more output) as it might generate more than
				one string. */
				do
				{
					/* Get the next output string from the command interpreter. */
					xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );

					/* Write the generated string to the CDC. */
					USB_WriteEP( CDC_DEP_IN, ( uint8_t * ) pcOutputString, strlen( pcOutputString ) );
					vTaskDelay( 1 );

				} while( xReturned != pdFALSE );

				/* All the strings generated by the input command have been sent.
				Clear the input	string ready to receive the next command.  Remember
				the command that was just processed first in case it is to be
				processed again. */
				strcpy( cLastInputString, cInputString );
				ucInputIndex = 0;
				memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );

				USB_WriteEP( CDC_DEP_IN, ( uint8_t * ) pcEndOfOutputMessage, strlen( pcEndOfOutputMessage ) );
			}
			else
			{
				if( cRxedChar == '\r' )
				{
					/* Ignore the character. */
				}
				else if( cRxedChar == '\b' )
				{
					/* Backspace was pressed.  Erase the last character in the
					string - if any. */
					if( ucInputIndex > 0 )
					{
						ucInputIndex--;
						cInputString[ ucInputIndex ] = '\0';
					}
				}
				else
				{
					/* A character was entered.  Add it to the string
					entered so far.  When a \n is entered the complete
					string will be passed to the command interpreter. */
					if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
					{
						if( ucInputIndex < cmdMAX_INPUT_SIZE )
						{
							cInputString[ ucInputIndex ] = cRxedChar;
							ucInputIndex++;
						}
					}
				}
			}

			/* Must ensure to give the mutex back. */
			xSemaphoreGive( xCDCMutex );
		}
	}
}