Esempio n. 1
0
    /*******************************************************************************
    * Function Name: UART_UartGetByte
    ********************************************************************************
    *
    * Summary:
    *  Retrieves the next data element from the receive buffer, returns the
    *  received byte and error condition.
    *   - The RX software buffer is disabled: returns the data element retrieved
    *     from the RX FIFO. Undefined data will be returned if the RX FIFO is
    *     empty.
    *   - The RX software buffer is enabled: returns data element from the
    *     software receive buffer.
    *
    * Parameters:
    *  None
    *
    * Return:
    *  Bits 7-0 contain the next data element from the receive buffer and
    *  other bits contain the error condition.
    *
    * Side Effects:
    *  The errors bits may not correspond with reading characters due to RX FIFO
    *  and software buffer usage.
    *  RX software buffer is disabled: The internal software buffer overflow
    *  is not returned as status by this function.
    *  Check SCB_rxBufferOverflow to capture that error condition.
    *
    *******************************************************************************/
    uint32 UART_UartGetByte(void)
    {
        uint32 rxData;
        uint32 tmpStatus;

        #if (UART_CHECK_RX_SW_BUFFER)
        {
            UART_DisableInt();
        }
        #endif

        if (0u != UART_SpiUartGetRxBufferSize())
        {
            /* Enables interrupt to receive more bytes: at least one byte is in
            * buffer.
            */
            #if (UART_CHECK_RX_SW_BUFFER)
            {            
                UART_EnableInt();
            }
            #endif

            /* Get received byte */
            rxData = UART_SpiUartReadRxData();
        }
        else
        {
            /* Reads a byte directly from RX FIFO: underflow is raised in the case
            * of empty. Otherwise the first received byte will be read.
            */
            rxData = UART_RX_FIFO_RD_REG;

            /* Enables interrupt to receive more bytes.
            * The RX_NOT_EMPTY interrupt is cleared by the interrupt routine
            * in case the byte was received and read by code above.
            */
            #if (UART_CHECK_RX_SW_BUFFER)
            {
                UART_EnableInt();
            }
            #endif
        }

        /* Get and clear RX error mask */
        tmpStatus = (UART_GetRxInterruptSource() & UART_INTR_RX_ERR);
        UART_ClearRxInterruptSource(UART_INTR_RX_ERR);

        /* Puts together data and error status:
        * MP mode and accept address: 9th bit is set to notify mark.
        */
        rxData |= ((uint32) (tmpStatus << 8u));

        return (rxData);
    }
Esempio n. 2
0
void main(void)
{
	// Insert your main routine code here.
	unsigned char c = 0;
	M8C_EnableGInt;
	UART_EnableInt();
	UART_Start(UART_PARITY_NONE);
	PGA_1_Start(PGA_1_HIGHPOWER);
	ADCINC_Start(ADCINC_HIGHPOWER); // Apply power to the SC Block
	ADCINC_GetSamples(0);
	DAC6_Start(DAC6_HIGHPOWER);
	PWM8_DisableInt();
	PWM8_Start();
	for(;;)
	{
		PWM8_WritePulseWidth(m_to_s_mem[0]);
		DAC6_WriteBlind(m_to_s_mem[1]); 
		//if ( DELSIG8_bfStatus ) {
		//	DELSIG8_bfStatus = 0;
		//	s_to_m_mem[0] = DELSIG8_cResult;
		//}
		//ADCINC_GetSamples(1);
		//while(ADCINC_fIsDataAvailable() == 0);
		//s_to_m_mem[0] = ADCINC_bClearFlagGetData(); 
	}
	//mainloop:
	//	UART_SendData(temp++);
		//while( ++temp2 );
	//goto mainloop;
}
Esempio n. 3
0
    /*******************************************************************************
    * Function Name: UART_SpiUartClearRxBuffer
    ********************************************************************************
    *
    * Summary:
    *  Clears the receive buffer and RX FIFO.
    *
    * Parameters:
    *  None
    *
    * Return:
    *  None
    *
    *******************************************************************************/
    void UART_SpiUartClearRxBuffer(void)
    {
        #if (UART_CHECK_RX_SW_BUFFER)
        {
            /* Lock from component interruption */
            UART_DisableInt();

            /* Flush RX software buffer */
            UART_rxBufferHead = UART_rxBufferTail;
            UART_rxBufferOverflow = 0u;

            UART_CLEAR_RX_FIFO;
            UART_ClearRxInterruptSource(UART_INTR_RX_ALL);

            #if (UART_CHECK_UART_RTS_CONTROL_FLOW)
            {
                /* Enable RX Not Empty interrupt source to continue receiving
                * data into software buffer.
                */
                UART_INTR_RX_MASK_REG |= UART_INTR_RX_NOT_EMPTY;
            }
            #endif

            /* Release lock */
            UART_EnableInt();
        }
        #else
        {
            UART_CLEAR_RX_FIFO;
        }
        #endif
    }
Esempio n. 4
0
/*******************************************************************************
* Function Name: UART_ScbModeEnableIntr
****************************************************************************//**
*
*  Enables an interrupt for a specific mode.
*
*******************************************************************************/
static void UART_ScbEnableIntr(void)
{
#if (UART_SCB_IRQ_INTERNAL)
    /* Enable interrupt in NVIC */
    #if (UART_SCB_MODE_UNCONFIG_CONST_CFG)
        if (0u != UART_scbEnableIntr)
        {
            UART_EnableInt();
        }

    #else
        UART_EnableInt();

    #endif /* (UART_SCB_MODE_UNCONFIG_CONST_CFG) */
#endif /* (UART_SCB_IRQ_INTERNAL) */
}
Esempio n. 5
0
void UART1_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init UART                                                                                               */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Reset IP */
    SYS_ResetModule(UART1_RST);

    /* Configure UART1 and set UART1 Baudrate */
    UART_Open(UART1, 115200);

    /* Enable UART1 RX Time-Out Interrupt and RX Data Available Interrupt */
    UART_EnableInt(UART1, UART_INTEN_RXTOIEN_Msk | UART_INTEN_THREIEN_Msk | UART_INTEN_RDAIEN_Msk);
}
Esempio n. 6
0
char GPSBufferRead()
{
  char u8InChar;
  //int test;
  u8InChar = g_u8RecData[g_u32comRhead];
  g_u32comRhead = (g_u32comRhead == (RXBUFSIZE - 1)) ? 0 : (g_u32comRhead + 1);
  //test = g_u32comRbytes;
  UART_DisableInt(UART1, UART_INTEN_RDAIEN_Msk);
  g_u32comRbytes--;
  UART_EnableInt(UART1, UART_INTEN_RDAIEN_Msk);
  //printf("<%d\n",g_u32comRbytes);
 // if(g_u32comRbytes==0xFFFFFFFF)
  //  printf("Error:0x%x\n",test);
  return u8InChar;
}
Esempio n. 7
0
static rt_err_t CME_M7_control(struct rt_serial_device *serial, int cmd, void *arg)
{
    struct CME_M7_uart* uart;
    NVIC_InitTypeDef NVIC_InitStructure;

    RT_ASSERT(serial != RT_NULL);
    uart = (struct CME_M7_uart *)serial->parent.user_data;

    switch (cmd)
    {
    case RT_DEVICE_CTRL_CLR_INT:
        /* disable rx irq */
        NVIC_InitStructure.NVIC_IRQChannel = uart->irq;
		NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelCmd = FALSE;
		NVIC_Init(&NVIC_InitStructure);

		UART_EnableInt(uart->uart_device, UART_Int_RxNotEmpty, FALSE);
        break;

    case RT_DEVICE_CTRL_SET_INT:
        /* enable rx irq */
        NVIC_InitStructure.NVIC_IRQChannel = uart->irq;
		NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelCmd = TRUE;
		NVIC_Init(&NVIC_InitStructure);

		UART_ClearInt(uart->uart_device, UART_Int_RxNotEmpty);
		UART_EnableInt(uart->uart_device, UART_Int_RxNotEmpty, TRUE);
        break;
    }

    return RT_EOK;
}
Esempio n. 8
0
void setupGpsUART()
{
#ifdef GPS_UART
	/* Enable peripheral clock */
	CLK_EnableModuleClock(UART1_MODULE);
	/* Peripheral clock source */
	CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UARTSEL_HIRC, CLK_CLKDIV0_UART(1));
	/* Set PE multi-function pins for UART0 RXD, TXD */
	SYS->GPE_MFPH = SYS_GPE_MFPH_PE13MFP_UART1_RXD | SYS_GPE_MFPH_PE12MFP_UART1_TXD;
	/* Reset UART module */
	SYS_ResetModule(UART1_RST);
	/* Configure UART0 and set UART0 Baudrate */
	UART_Open(UART1, GPS_BAUD);
  UART_EnableInt(UART1, UART_INTEN_RDAIEN_Msk);
#endif
}
Esempio n. 9
0
    /*******************************************************************************
    * Function Name: UART_SpiUartClearTxBuffer
    ********************************************************************************
    *
    * Summary:
    *  Clears the transmit buffer and TX FIFO.
    *
    * Parameters:
    *  None
    *
    * Return:
    *  None
    *
    *******************************************************************************/
    void UART_SpiUartClearTxBuffer(void)
    {
        #if (UART_CHECK_TX_SW_BUFFER)
        {
            /* Lock from component interruption */
            UART_DisableInt();

            /* Flush TX software buffer */
            UART_txBufferHead = UART_txBufferTail;

            UART_INTR_TX_MASK_REG &= (uint32) ~UART_INTR_TX_NOT_FULL;
            UART_CLEAR_TX_FIFO;
            UART_ClearTxInterruptSource(UART_INTR_TX_ALL);

            /* Release lock */
            UART_EnableInt();
        }
        #else
        {
            UART_CLEAR_TX_FIFO;
        }
        #endif
    }
Esempio n. 10
0
/**   
  * @brief  VCOM_MainProcess, VCOM main process.
  * @param  None.
  * @retval None.
  */
void VCOM_MainProcess(void)
{
	int32_t i, i32Len;
	STR_USBD_T sParam;

	/* Enable UART Interrupt */
	UART_EnableInt(UART0, DRVUART_RDAINT);

	/* Initial USB */
	USBD_Init();

	sParam.UsbDeviceClass = USB_CLASS_CDC;
	sParam.u32CtrlMaxPacketSize = MAX_PACKET_SIZE_CTRL;
	sParam.u32EndpointCount = 3;
	sParam.EP[0].u32EpNum = BULK_IN_EP_NUM;
	sParam.EP[0].u32MaxPacketSize = MAX_PACKET_SIZE_BULK;
	sParam.EP[0].IsDirIN = TRUE;
	sParam.EP[0].IsIsoTransfer = FALSE;
	sParam.EP[1].u32EpNum = BULK_OUT_EP_NUM;
	sParam.EP[1].u32MaxPacketSize = MAX_PACKET_SIZE_BULK;
	sParam.EP[1].IsDirIN = FALSE;
	sParam.EP[1].IsIsoTransfer = FALSE;
	sParam.EP[2].u32EpNum = INT_IN_EP_NUM;
	sParam.EP[2].u32MaxPacketSize = MAX_PACKET_SIZE_INT;
	sParam.EP[2].IsDirIN = TRUE;
	sParam.EP[2].IsIsoTransfer = FALSE;
	USB_Open(&sParam);

	memset((void *)&gVcomInfo, 0, sizeof(STR_USBD_VCOM_T));

	while(1)
	{
		/* Check if any data to send to USB & USB is ready to send them out */
		if(comRbytes && (gVcomInfo.TxSize == 0))
		{
			i32Len = comRbytes;
			if(i32Len > MAX_PACKET_SIZE_BULK)
				i32Len = MAX_PACKET_SIZE_BULK;

			for(i=0;i<i32Len;i++)
			{
				gRxBuf[i] = comRbuf[comRhead++];
				if(comRhead >= RXBUFSIZE)
					comRhead = 0;
			}

			NVIC_DisableIRQ(UART0_IRQn);
			comRbytes -= i32Len;
			NVIC_EnableIRQ(UART0_IRQn);

			gVcomInfo.TxSize = i32Len;
			my_memcpy((uint8_t *)((uint32_t)USBD_SRAM_BASE + (uint32_t)USBD->BUFSEG2), (void *)gRxBuf, i32Len);
			USBD->MXPLD2 = i32Len;
		}


		/* Process the Bulk out data when bulk out data is ready. */
		if(gVcomInfo.BulkOutReady && (gVcomInfo.RxSize <= TXBUFSIZE - comTbytes))
		{
			for(i=0;i<gVcomInfo.RxSize;i++)
			{
				comTbuf[comTtail++] = *(gVcomInfo.RxBuf+i);
				if(comTtail >= TXBUFSIZE)
					comTtail = 0;
			}

			NVIC_DisableIRQ(UART0_IRQn);
			comTbytes += gVcomInfo.RxSize;
			NVIC_EnableIRQ(UART0_IRQn);

			gVcomInfo.RxSize = 0;
			gVcomInfo.BulkOutReady = 0; /* Clear bulk out ready flag */

			/* Ready to get next BULK out */
			USBD->MXPLD3 = MAX_PACKET_SIZE_BULK;
		}

		/* Process the software Tx FIFO */
		if(comTbytes)
		{
			/* Check if Tx is working */
			if (!(UART0->IER & UART_IER_THRE_IE))
			{
				/* Send one bytes out */
				UART0->THR = comTbuf[comThead++];
				if(comThead >= TXBUFSIZE)
					comThead = 0;

				NVIC_DisableIRQ(UART0_IRQn);
				comTbytes--;
				NVIC_EnableIRQ(UART0_IRQn);

				/* Enable Tx Empty Interrupt. (Trigger first one) */
				UART0->IER |= UART_IER_THRE_IE;
			}
		}
	}
}
Esempio n. 11
0
/*---------------------------------------------------------------------------------------------------------*/
void AutoFlow_FunctionRxTest()
{
    uint32_t u32i;

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  ______                                            _____  |\n");
    printf("| |      |                                          |     | |\n");
    printf("| |Master|--UART1_TXD(PB.5)  <==>  UART1_RXD(PB.4)--|Slave| |\n");
    printf("| |      |--UART1_nCTS(PB.7) <==> UART1_nRTS(PB.6)--|     | |\n");
    printf("| |______|                                          |_____| |\n");
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n");

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|       AutoFlow Function Test (Slave)                      |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code needs two boards. One is Master and    |\n");
    printf("|    the other is slave. Master will send 1k bytes data     |\n");
    printf("|    to slave.Slave will check if received data is correct  |\n");
    printf("|    after getting 1k bytes data.                           |\n");
    printf("|    Press any key to start...                              |\n");
    printf("+-----------------------------------------------------------+\n");
    GetChar();

    /* Enable RTS and CTS autoflow control */
    UART_EnableFlowCtrl(UART1);

    /* Set RTS Trigger Level as 8 bytes */
    UART1->FCR &= ~UART_FCR_RTS_TRI_LEV_Msk;
    UART1->FCR |= UART_FCR_RTS_TRI_LEV_8BYTES;

    /* Set RX Trigger Level as 8 bytes */
    UART1->FCR &= ~UART_FCR_RFITL_Msk;
    UART1->FCR |= UART_FCR_RFITL_8BYTES;

    /* Set Timeout time 0x3E bit-time and time-out counter enable */
    UART_SetTimeoutCnt(UART1, 0x3E);

    /* Enable RDA\RLS\RTO Interrupt  */
    UART_EnableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk));

    printf("\n Starting to receive data...\n");

    /* Wait for receive 1k bytes data */
    while(g_i32pointer < RXBUFSIZE);

    /* Compare Data */
    for(u32i = 0; u32i < RXBUFSIZE; u32i++) {
        if(g_u8RecData[u32i] != (u32i & 0xFF)) {
            printf("Compare Data Failed\n");
            while(1);
        }
    }
    printf("\n Receive OK & Check OK\n");

    /* Disable RDA\RLS\RTO Interrupt */
    UART_DisableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk));

}