Esempio n. 1
0
void  UART_RxStr (CPU_CHAR *str, CPU_INT16U num)
{
    CPU_CHAR    b;
    CPU_INT16U  i;
    
    
    i      =  0;
    str[i] = ' ';
    
    while(num) {                                                        /* Check error flags                                */
        b = UART_RxByte();
        num--;            
        if (b == 13) {                                                  /* Null character                                   */
            str[i] = '\0';    
            break;
        } else if (b == 8) {                                            /* Backspace                                        */
            if(i) {
                i--;
                str[i] = ' ';
            }                                         
        } else {                                                        /* For any other character, read and store          */
            str[i] = b;
            i++;
        }
        
        OSTimeDly(1);
    }
    
    if (str[i] != '\0') {
        str[i]  = '\0';                                                 /* Ensure all strings are null terminated           */
    }
}            
Esempio n. 2
0
void  BSP_UARTHandler (void)
{
    CPU_INT32U  status;
    CPU_INT32U  int_en;
    
    
    status           = BSP_UART_INTSTAT;                                /* Read the interrupt status register               */
    int_en           = BSP_UART_INTEN;                                  /* Read the interrupt enabled register              */
    
    status          &= BSP_UART_INTMASK;                                /* Mask all other interrupts                        */
    BSP_UART_INTCLR  = status;                                          /* Clear all triggered interrupts                   */
    status          &= int_en;                                          /* Mask non-enabled interrupts                      */
    
    if (status & BSP_UART_INTRX) {                                      /* If a Rx interrupt has occured and is enabled...  */
        UART_TxByte(UART_RxByte());                                     /* Notify Probe and provide the incoming character  */
    }
}
Esempio n. 3
0
/**
* Description: This function handles interrupts from the UART and insert the received byte into the buffer
* Arguments  : None
* Returns    : None
*/
void  BSP_UARTHandler (void)
{
    CPU_INT32U  status;
    CPU_INT32U  int_en;
    
    status           = BSP_UART_INTSTAT;                                /* Read the interrupt status register               */
    int_en           = BSP_UART_INTEN;                                  /* Read the interrupt enabled register              */
    
    status          &= BSP_UART_INTMASK;                                /* Mask all other interrupts                        */
    BSP_UART_INTCLR  = status;                                          /* Clear all triggered interrupts                   */
    status          &= int_en;                                          /* Mask non-enabled interrupts                      */
    
    if (status & BSP_UART_INTRX)
	{ 
	   //If a Rx interrupt has occured and is enabled...
	   //On stocke l'octet recu dans le buffer circulaire
	   Uart_Rx_Circular_Buffer[Circular_Buffer_Write_Index] = UART_RxByte();
		
		//On incrémente l'index d'écriture du buffer	
		if(Circular_Buffer_Write_Index >= (CIRCULAR_BUFFER_SIZE - 1))
		{
			Circular_Buffer_Write_Index = 0;	
		}
		else
		{
			Circular_Buffer_Write_Index++;
		}
		
		//Si l'index d'écriture est égal à l'index de lecture, c'est que le buffer est plein (on vient de faire un tour)
		if(Circular_Buffer_Write_Index == Circular_Buffer_Read_Index)
		{
			//TODO: gérer le buffer overflow
			Circular_Buffer_Overflow = OS_TRUE;
		}
	}
}