Beispiel #1
0
BT_ERROR BT_RaiseSoftIRQFromISR(BT_u32 ulSoftIRQ) {
	if(ulSoftIRQ < BT_CONFIG_SOFTIRQ_MAX) {
		g_ulPending |= (1 << ulSoftIRQ);
		BT_kMutexReleaseFromISR(g_pvMutex, NULL);
		return BT_ERR_NONE;
	}

	return BT_ERR_GENERIC;
}
Beispiel #2
0
static BT_ERROR i2c_irq_handler(BT_u32 ulIRQ, void *pParam) {

	BT_HANDLE hI2C = (BT_HANDLE) pParam;
	BT_u32 isr_status = hI2C->pRegs->INT_STATUS;

	BT_u32 avail_bytes;
	BT_u32 bytes_to_recv, bytes_to_send;

	BT_BOOL bRelease = BT_FALSE;

	if(isr_status & INT_MASK_NACK) {
		// NACK
		bRelease = BT_TRUE;
	}

	if(isr_status & INT_MASK_ARB_LOST) {
		// BUS Arbitration was lost.
		bRelease = BT_TRUE;
	}

	if(isr_status & INT_MASK_DATA) {
		if(hI2C->p_msg->len > I2C_FIFO_LEN) {
			bytes_to_recv = (I2C_FIFO_LEN + 1) - hI2C->pRegs->TRANSFER_SIZE;
			hI2C->p_msg->len -= bytes_to_recv;

			if(hI2C->p_msg->len > I2C_FIFO_LEN) {
				hI2C->pRegs->TRANSFER_SIZE = I2C_FIFO_LEN + 1;
			} else {
				hI2C->pRegs->TRANSFER_SIZE = hI2C->p_msg->len;
				if(!hI2C->bHold) {
					hI2C->pRegs->CONTROL &= CONTROL_HOLD;
				}
			}

			while(bytes_to_recv) {
				*hI2C->p_recv_buf++ = hI2C->pRegs->DATA;
				bytes_to_recv--;
			}

		}
	}

	if(isr_status & INT_MASK_COMP) {
		if(!hI2C->p_recv_buf) {
			if(hI2C->send_count > 0) {
				avail_bytes = I2C_FIFO_LEN - hI2C->pRegs->TRANSFER_SIZE;
				if(hI2C->send_count > avail_bytes) {
					bytes_to_send = avail_bytes;
				} else {
					bytes_to_send = hI2C->send_count;
				}

				while(bytes_to_send--) {
					hI2C->pRegs->DATA = *hI2C->p_send_buf++;
					hI2C->send_count--;
				}
			} else {
				bRelease = BT_TRUE;
			}

			if(!hI2C->send_count) {
				if(!hI2C->bHold) {
					hI2C->pRegs->CONTROL &= ~CONTROL_HOLD;
				}
			}
		} else {
			if(!hI2C->bHold) {
				hI2C->pRegs->CONTROL &= ~CONTROL_HOLD;
			}

			while(hI2C->pRegs->STATUS & STATUS_RXDV) {
				*hI2C->p_recv_buf++ = hI2C->pRegs->DATA;
				hI2C->recv_count--;
			}
			bRelease = BT_TRUE;
		}
	}

	if(bRelease) {
		BT_kMutexReleaseFromISR(hI2C->pMutex, NULL);
	}

	hI2C->err_status = isr_status & 0x000002EC;
	hI2C->pRegs->INT_STATUS = isr_status;			// Clear pending interrupts.

	return BT_ERR_NONE;
}
Beispiel #3
0
BT_ERROR BT_ReleaseMutexFromISR(BT_HANDLE hMutex, BT_BOOL *pbHigherPriorityThreadWoken) {
	return BT_kMutexReleaseFromISR(hMutex->pMutex, pbHigherPriorityThreadWoken);
}