示例#1
0
static void
rx_dma_callback(DMA_HANDLE handle, uint8_t status, void *arg)
{
	/*
	 * We are here because DMA completed, or UART reception stopped and
	 * we think we have a packet in the buffer.
	 */
	perf_begin(pc_txns);

	/* disable UART DMA */
	rCR3 &= ~(USART_CR3_DMAT | USART_CR3_DMAR);

	/* handle the received packet */
	rx_handle_packet();

	/* re-set DMA for reception first, so we are ready to receive before we start sending */
	dma_reset();

	/* send the reply to the just-processed request */
	dma_packet.crc = 0;
	dma_packet.crc = crc_packet(&dma_packet);
	stm32_dmasetup(
		tx_dma,
		(uint32_t)&rDR,
		(uint32_t)&dma_packet,
		PKT_SIZE(dma_packet),
		DMA_CCR_DIR		|
		DMA_CCR_MINC		|
		DMA_CCR_PSIZE_8BITS	|
		DMA_CCR_MSIZE_8BITS);
	stm32_dmastart(tx_dma, NULL, NULL, false);
	rCR3 |= USART_CR3_DMAT;

	perf_end(pc_txns);
}
示例#2
0
文件: spi.c 项目: ans10528/Firmware
static void
rx_dma_callback(DMA_HANDLE handle, uint8_t status, void *arg)
{
    uint16_t sr = rSR;
    
    stm32_dmastop(rx_dma);
    stm32_dmastop(tx_dma);
    
    /* handle the received packet */
    rx_handle_packet();
    
    /* re-set DMA for reception first, so we are ready to receive before we start sending */
    if (!(sr & SPI_SR_BSY)) {
        dma_reset();
    }
    
    /* send the reply to the just-processed request */
    dma_packet.crc = 0;
    dma_packet.crc = crc_packet(&dma_packet);
    stm32_dmasetup(
                   tx_dma,
                   (uint32_t)&rDR,
                   (uint32_t)&dma_packet,
                   PKT_SIZE(dma_packet),
                   DMA_CCR_DIR		|
                   DMA_CCR_MINC		|
                   DMA_CCR_PSIZE_8BITS	|
                   DMA_CCR_MSIZE_8BITS	|
                   DMA_CCR_PRIMED);
    stm32_dmastart(tx_dma, NULL, NULL, false);
    
    perf_end(pc_txns);
}