Esempio n. 1
0
/**
 *	Implementing the CHAR dev write API.
 *
 *	Note, this doesn't implement ulFlags specific options yet!
 **/
static BT_s32 uartWrite(BT_HANDLE hUart, BT_u32 ulFlags, BT_u32 ulSize, const BT_u8 *pucSource) {
	volatile LM3Sxx_UART_REGS *pRegs = hUart->pRegs;

	BT_ERROR Error = BT_ERR_NONE;
	BT_u8 ucData;
	BT_u8 *pSrc = (BT_u8*)pucSource;
	BT_u32 slWritten = 0;

	switch(hUart->eMode) {
	case BT_UART_MODE_POLLED:
	{
		while(ulSize) {
			while((pRegs->FR & LM3Sxx_UART_FR_TXFF)) {
				BT_ThreadYield();
			}
			pRegs->DR = *pucSource++;
			ulSize--;
			slWritten++;
		}
		break;
	}

	case BT_UART_MODE_BUFFERED:
	{
		slWritten = BT_FifoWrite(hUart->hTxFifo, ulSize, pSrc, 0);

		pRegs->IM &= ~LM3Sxx_UART_INT_TX;	// Disable the interrupt

		while (!BT_FifoIsEmpty(hUart->hTxFifo, &Error) && (!(pRegs->FR & LM3Sxx_UART_FR_TXFF))) {
			BT_FifoRead(hUart->hTxFifo, 1, &ucData, 0);
			pRegs->DR = ucData;
		}
		pRegs->IM |= LM3Sxx_UART_INT_TX;	// Enable the interrupt
		break;
	}

	default:
		break;
	}
	return slWritten;
}
Esempio n. 2
0
void isr_CAN(BT_HANDLE hCan) {
	volatile LPC17xx_CAN_REGS *pRegs = hCan->pRegs;
	BT_ERROR Error;
	BT_CAN_MESSAGE oMessage;

	BT_u32 ulICR = pRegs->CANICR;

	if (ulICR & LPC17xx_CAN_ICR_RI) {
		CanReceive(g_CAN_HANDLES[0], &oMessage);
		BT_FifoWrite(hCan->hRxFifo, 1, &oMessage, &Error);
	}
	if (ulICR & LPC17xx_CAN_ICR_TI) {
		while (!BT_FifoIsEmpty(hCan->hTxFifo, &Error) && (canFindFreeBuffer(hCan) != LPC17xx_CAN_NO_FREE_BUFFER)) {
			BT_FifoRead(hCan->hTxFifo, 1, &oMessage, &Error);
			CanTransmit(hCan, &oMessage);
		}
	}
	if (BT_FifoIsEmpty(hCan->hTxFifo, &Error)) {
		pRegs->CANIER &= ~LPC17xx_CAN_IER_TIE;	// Disable the interrupt
	}
}
Esempio n. 3
0
/**
 *	Note, this doesn't implement ulFlags specific options yet!
 **/
static BT_ERROR canWrite(BT_HANDLE hCan, BT_CAN_MESSAGE *pCanMessage) {
	volatile LPC17xx_CAN_REGS *pRegs = hCan->pRegs;
	BT_CAN_MESSAGE oMessage;

	BT_ERROR Error = BT_ERR_NONE;

	switch(hCan->eMode) {
	case BT_CAN_MODE_POLLED:
	{
		BT_u32 ulIndex;
		while ((ulIndex = canFindFreeBuffer(hCan)) == LPC17xx_CAN_NO_FREE_BUFFER) {
			BT_ThreadYield();
		}
		CanTransmit(hCan, pCanMessage);
		break;
	}

	case BT_CAN_MODE_BUFFERED:
	{
		BT_FifoWrite(hCan->hTxFifo, 1, pCanMessage, &Error);

		while (!BT_FifoIsEmpty(hCan->hTxFifo, &Error) && (canFindFreeBuffer(hCan) != LPC17xx_CAN_NO_FREE_BUFFER)) {
			BT_FifoRead(hCan->hTxFifo, 1, &oMessage, &Error);
			CanTransmit(hCan, &oMessage);
		}

		pRegs->CANIER |= LPC17xx_CAN_IER_TIE;	// Enable the interrupt

		break;
	}

	default:
		break;
	}
	return Error;
}