Пример #1
0
void UART_IRQHandler(UCOM_DATA_T *pUcom )
{
	uint32_t count = 0;
	/* Handle transmit interrupt if enabled */
	if (pUcom->selected->IER & UART_IER_THREINT) {
		if (pUcom->txBuf_count > 0) {
			count = Chip_UART_Send(pUcom->selected, &pUcom->txBuf[pUcom->txBuf_uartIndex], pUcom->txBuf_count);
			pUcom->txBuf_count -= count;
			pUcom->txBuf_uartIndex += count;
		}
		/* If  usbRxBuf empty check if any packet pending USB EP RAM */
		if (pUcom->txBuf_count < 1) {
			if ((pUcom->usbRxPending > 0) && USB_IsConfigured(pUcom->hUsb)) {
				pUcom->usbRxPending--;
				pUcom->txBuf_count = USBD_API->hw->ReadEP(pUcom->hUsb, pUcom->outEndpoint, pUcom->txBuf);
				pUcom->txBuf_uartIndex = 0;

			}
			else {
				/* all data transmitted on UART disable UART_IER_THREINT */
				Chip_UART_IntDisable(pUcom->selected, UART_IER_THREINT);
			}
		}
	}

	/* Handle receive interrupt */
	count = Chip_UART_Read(pUcom->selected, &pUcom->rxBuf[pUcom->rxBuf_uartIndex], UCOM_BUF_SZ - pUcom->rxBuf_uartIndex);

	if (count) {
		/* Note, following logic works if UCOM_BUF_SZ is 2^n size only. */
		pUcom->rxBuf_uartIndex = (pUcom->rxBuf_uartIndex + count) & (UCOM_BUF_SZ - 1);
		/* If USB Tx is not busy kick start USB Tx */
		if ((pUcom->usbTxBusy == 0) && USB_IsConfigured(pUcom->hUsb)) {
			pUcom->usbTxBusy = 1;
			count = USBD_API->hw->WriteEP(pUcom->hUsb, pUcom->inEndpoint, &pUcom->rxBuf[pUcom->rxBuf_usbIndex], count);
			pUcom->rxBuf_usbIndex = (pUcom->rxBuf_usbIndex + count) & (UCOM_BUF_SZ - 1);
		}
	}

}
Пример #2
0
/**
 * @brief	UART interrupt handler sub-routine
 * @return	Nothing
 */
void LPC_UARTHNDLR(void)
{
	uint32_t count = 0;
	/* Handle transmit interrupt if enabled */
	if ((Chip_UART_GetStatus(LPC_USART) & UART_STAT_TXRDY) != 0) {
		if (g_uCOM.txBuf_count > 0) {
			count = Chip_UART_Send(LPC_USART, &g_uCOM.txBuf[g_uCOM.txBuf_uartIndex], g_uCOM.txBuf_count);
			g_uCOM.txBuf_count -= count;
			g_uCOM.txBuf_uartIndex += count;
		}
		/* If  usbRxBuf empty check if any packet pending USB EP RAM */
		if (g_uCOM.txBuf_count < 1) {
			if ((g_uCOM.usbRxPending > 0) && USB_IsConfigured(g_uCOM.hUsb)) {
				g_uCOM.usbRxPending--;
				g_uCOM.txBuf_count = USBD_API->hw->ReadEP(g_uCOM.hUsb, USB_CDC_OUT_EP, g_uCOM.txBuf);
				g_uCOM.txBuf_uartIndex = 0;

			}
			else {
				/* all data transmitted on UART disable UART_INTEN_TXRDY */
				Chip_UART_IntDisable(LPC_USART, UART_INTEN_TXRDY);
			}
		}
	}

	/* Handle receive interrupt */
	count = Chip_UART_Read(LPC_USART, &g_uCOM.rxBuf[g_uCOM.rxBuf_uartIndex], UCOM_BUF_SZ - g_uCOM.rxBuf_uartIndex);

	if (count) {
		/* Note, following logic works if UCOM_BUF_SZ is 2^n size only. */
		g_uCOM.rxBuf_uartIndex = (g_uCOM.rxBuf_uartIndex + count) & (UCOM_BUF_SZ - 1);
		/* If USB Tx is not busy kick start USB Tx */
		if ((g_uCOM.usbTxBusy == 0) && USB_IsConfigured(g_uCOM.hUsb)) {
			g_uCOM.usbTxBusy = 1;
			count = USBD_API->hw->WriteEP(g_uCOM.hUsb, USB_CDC_IN_EP, &g_uCOM.rxBuf[g_uCOM.rxBuf_usbIndex], count);
			g_uCOM.rxBuf_usbIndex = (g_uCOM.rxBuf_usbIndex + count) & (UCOM_BUF_SZ - 1);
		}
	}

}
Пример #3
0
/* Keyboard tasks */
void Keyboard_Tasks(void)
{
	/* check if moue report timer expired */
	if (ms_timerExpired(&g_keyBoard.tmo)) {
		/* reset timer */
		ms_timerStart(&g_keyBoard.tmo);
		/* check device is configured before sending report. */
		if ( USB_IsConfigured(g_keyBoard.hUsb)) {
			/* update report based on board state */
			Keyboard_UpdateReport();
			/* send report data */
			if (g_keyBoard.tx_busy == 0) {
				g_keyBoard.tx_busy = 1;
				USBD_API->hw->WriteEP(g_keyBoard.hUsb, HID_EP_IN, &g_keyBoard.report[0], KEYBOARD_REPORT_SIZE);
			}
		}
	}
}
Пример #4
0
/* Keyboard tasks */
void Keyboard_Tasks(void)
{
	/* check device is configured before sending report. */
	if ( USB_IsConfigured(g_keyBoard.hUsb)) {
		/* send report data */
		if (g_keyBoard.tx_busy == 0) {
			g_keyBoard.tx_busy = 1;
			/* update report based on board state */
			Keyboard_UpdateReport();
			USBD_API->hw->WriteEP(g_keyBoard.hUsb, HID_EP_IN, &g_keyBoard.report[0], KEYBOARD_REPORT_SIZE);
		}
	}
	else {
		/* reset busy flag if we get disconnected. */
		g_keyBoard.tx_busy = 0;
	}

}
Пример #5
0
/* Mouse tasks */
void Mouse_Tasks(int leftCount, int rightCount)
{
	/* check device is configured before sending report. */
	if ( USB_IsConfigured(g_mouse.hUsb)) {
		if (g_mouse.tx_busy == 0) {
			/* update report based on board state */
			Mouse_UpdateReport(leftCount, rightCount);
			/* send report data */
			g_mouse.tx_busy = 1;
			USBD_API->hw->WriteEP(g_mouse.hUsb, HID_EP_IN, &g_mouse.report[0], MOUSE_REPORT_SIZE);
		}
	}
	else {
		/* reset busy flag if we get disconnected. */
		g_mouse.tx_busy = 0;
	}

}
Пример #6
0
/*********************************************************************
*
*       _CmdGetConfiguration
*
* Function description
*   Returns the current configuration value to the HOST. If the device
*   is unconfigured then this request should return 0x00. Associated
*   with the SET_CONFIGURATION request.
*
*/
static void _CmdGetConfiguration(void) {
  U8 IsConfigured;
  IsConfigured = USB_IsConfigured();
  _WriteEP0(&IsConfigured, 1, 0);
}