static void UART2_RxTxHandler(void)
{
	uint32_t IntStatus, byteCnt, timeout = 1000000;
	uint8_t c;
	IntStatus = UARTIntStatus(UART2_BASE, true);
	UARTIntClear(UART2_BASE, IntStatus);
	if(IntStatus & UART_INT_TX)
	{
		byteCnt = RINGBUF_GetFill(&long_Uart2_TxRingBuf);
		if (byteCnt)
		{
			RINGBUF_Get(&long_Uart2_TxRingBuf, &c);
			UARTCharPutNonBlocking(UART2_BASE, c);
			if (byteCnt == 1)
			{
				UARTIntDisable(UART2_BASE, UART_INT_TX);
			}
		}
		else
		{
			UARTIntDisable(UART2_BASE, UART_INT_TX);
		}
	}
	else if (IntStatus & (UART_INT_RX | UART_INT_RT))
	{
		while(!UARTCharsAvail(UART2_BASE) && (timeout--));
		c = UARTCharGet(UART2_BASE);
		RINGBUF_Put(&long_Uart0_RxRingBuf,c);
	}
	else
	{
		c = UARTCharGet(UART2_BASE);
	}
}
Ejemplo n.º 2
0
int main(void)
{
    // Set the clock to run from the crystal at 8Mhz
    SysCtlClockSet (SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                    SYSCTL_XTAL_8MHZ);

    // Initialise the OLED display.
    RIT128x96x4Init (1000000);

    // Initialise UART
    uart_initialise ();

    long i = 0;

    char string[50] = {0};

    long length = ((char) UARTCharGet (UART0_BASE)) - 48;

    while (i < length)
    {
        string[i] = ((char)UARTCharGet (UART0_BASE));
        i++;
    }
    string[i] = '\0';

    vulncpy (string);

}
Ejemplo n.º 3
0
unsigned short get_short(void) {
    unsigned short result = 0x0000;
    unsigned char c;
    
    c = UARTCharGet(UART0_BASE);
    result |= ((unsigned short)c) << 8;
    c = UARTCharGet(UART0_BASE);
    result |= (unsigned short)c;
    
    return result;
}
Ejemplo n.º 4
0
int main(void)
{
	/*Set the clocking to directly run from the crystal at 8MHz*/
	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);


    /* Make the UART pins be peripheral controlled. */
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	
	/* Sets the configuration of a UART. */
	UARTConfigSetExpClk(UART0_BASE, 8000000, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    while(1)
    {

    if(UARTCharsAvail(UART0_BASE))
    {
    	/* Unsigned Char */
    	UARTCharPut(UART0_BASE,(unsigned char)(UARTCharGet(UART0_BASE)+1));
    }

    }

}
Ejemplo n.º 5
0
static void charIntHandler(char_device *dev)
{
    portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
    unsigned long ulStatus;
    unsigned char ucData;

    //
    // Get the interrrupt status.
    //
    ulStatus = UARTIntStatus(dev->PortBase, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(dev->PortBase, ulStatus);

    if(ulStatus & UART_INT_RX){
        ucData =UARTCharGet(dev->PortBase);
        xQueueSendFromISR(dev->RxQueue, &ucData, &xHigherPriorityTaskWoken);
    }

    if(ulStatus & UART_INT_TX){
        if(xQueueReceiveFromISR(dev->TxQueue, &ucData, &xHigherPriorityTaskWoken))
            UARTCharPut(dev->PortBase, ucData);
    }
	portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}
Ejemplo n.º 6
0
//*****************************************************************************
//
//! xuart0301 test execute main body.
//
//! \return None.
//
//*****************************************************************************
static void xuart0301Execute(void)
{
    unsigned char UartData = 0;
    unsigned char i = 0;
    xtBoolean bTmpBoolean = xfalse;

    UART_Print("\r\nPlease wait 1 s then type the follow string\r\n");
    UART_Print("123456789ABCDE\r\n");

    bTmpBoolean = UARTCharsAvail(UART_BASE);
    TestAssert((xfalse == bTmpBoolean),
            "UART 0301: Function UARTCharsAvail failed!\r\n");
    
    while((UartData = UARTCharGet(UART_BASE)) != '\n')
    {
        UARTCharPut(UART_BASE, UartData);
        if(++i >= 15)
        {
            break;
        }
    }
    UARTCharPut(UART_BASE, '\r');
    UARTCharPut(UART_BASE, '\n');

}
Ejemplo n.º 7
0
/**
 * Turn off interrupt sources that may interrupt us (SysTick and Ethernet) and then switch control
 * to the Boot Loader. This will never return!
 */
void halSwitchToBootloader()
{
    while(UARTCharsAvail(UART0_BASE))
    {
        UARTCharGet(UART0_BASE);
    }

    EthernetIntDisable(ETH_BASE, 0xFFFF);
    SysTickIntDisable();
    IntDisable(INT_UART0);
    UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    UARTIntClear(UART0_BASE, UART_INT_RX | UART_INT_RT);


    delayMs(100);
    // Call the boot loader so that it will listen for an update on the UART.
    (*((void (*)(void))(*(unsigned long *)0x2c)))();

    //
    // The boot loader should take control, so this should never be reached.
    // Just in case, loop forever.
    //
    while(1)
    {
    }

}
Ejemplo n.º 8
0
int platform_uart_recv( unsigned id, unsigned timer_id, int timeout )
{
    u32 base = uart_base[ id ];
    timer_data_type tmr_start, tmr_crt;
    int res;

    if( timeout == 0 )
    {
        return UARTCharGetNonBlocking( base );
    }
    else if( timeout == PLATFORM_UART_INFINITE_TIMEOUT )
    {
        // Receive char blocking
        return UARTCharGet( base );
    }
    else
    {
        // Receive char with the specified timeout
        tmr_start = platform_timer_op( timer_id, PLATFORM_TIMER_OP_START, 0 );
        while( 1 )
        {
            if( ( res = UARTCharGetNonBlocking( base ) ) >= 0 )
                break;
            tmr_crt = platform_timer_op( timer_id, PLATFORM_TIMER_OP_READ, 0 );
            if( platform_timer_get_diff_us( timer_id, tmr_crt, tmr_start ) >= timeout )
                break;
        }
        return res;
    }
}
Ejemplo n.º 9
0
int platform_s_uart_recv( unsigned id, s32 timeout )
{
  u32 base = uart_base[ id ];

  if( timeout == 0 )
    return UARTCharGetNonBlocking( base );
  return UARTCharGet( base );
}
Ejemplo n.º 10
0
void loop(){

	char le = (char) UARTCharGet(b5);
	putChar(le);
	UARTCharPut(b5, (char)((int) le - 32));
	SysCtlDelay(3000);

}
Ejemplo n.º 11
0
static size_t uartGet(uint8_t* data, size_t nData, void* usr)
{
    uint32_t uart_base = (uint32_t) usr;
    size_t ret = 0;
    while (ret < nData && UARTCharsAvail(uart_base))
        data[ret++] = UARTCharGet(uart_base);
    return ret;
}
Ejemplo n.º 12
0
void rien(void) {
    unsigned long ulStatus;
    ulStatus = UARTIntStatus(UART5_BASE, true);
    UARTIntClear(UART5_BASE, ulStatus);

    while(UARTCharsAvail(UART5_BASE)) {
        char c = UARTCharGet(UART5_BASE);
        switch(UART5_buffer_state) {
        case 1:
            //On reçoit alpha, beta et gamma
            *UART5_buffer_pointer = c;
            UART5_buffer_pointer++;
            if (UART5_buffer_pointer - UART5_buffer >= 3) {
                UART5_buffer_state = 0;
                UART5_buffer_pointer = UART5_buffer;
                unsigned char should_move = UART5_buffer[2];
                if (should_move) {
                    go_angle = UART5_buffer[0] | (UART5_buffer[1] << 8);
                    if (go_angle > 360)
                    	go_angle = 0;
                	new_order = 1;
                }
                else {
                	new_order = 0;
                }
            }
            break;
        default:
            //On reçoit un int de start ou une commande aimant
            if ((c == 0xFE) && (UART5_buffer_pointer - UART5_buffer == 3)) {
                //Aimant activé
                UART5_buffer_pointer = UART5_buffer;
                actuators_servo_raise(0);
                actuators_servo_raise(1);
            }
            else if ((c == 0xFD) && (UART5_buffer_pointer - UART5_buffer == 3)) {
                //Aimant désactivé
            	actuators_servo_lower(0);
            	actuators_servo_lower(1);
                UART5_buffer_pointer = UART5_buffer;
            }
            else if (c != 0xFF) {
                //Truc pas normal, on reset la stack
                UART5_buffer_pointer = UART5_buffer;
            }
            else {
                //Octet de start
                *UART5_buffer_pointer = c;
                UART5_buffer_pointer++;
                if (UART5_buffer_pointer - UART5_buffer >= 4) {
                    //Passage en réception des angles
                    UART5_buffer_state = 1;
                    UART5_buffer_pointer = UART5_buffer;
                }
            }
        }
    }
}
Ejemplo n.º 13
0
void main_loop(){

	unsigned char message[5];
	int count = 0;
	//pwmCounter = 0;
	//parse and execute loop
	while (1)
    {

    	if (UARTCharsAvail(UART0_BASE)){
    		if(count==0){
    			message[0] =  UARTCharGet(UART0_BASE);	//grab first byte
    			//toggle();
    		}
    		if(count==1){
    			message[1] = UARTCharGet(UART0_BASE);
    			//toggle();
    		}
    		if(count==2){
    			message[2] = UARTCharGet(UART0_BASE);
    			//toggle();
    		}
    		if(count==3){
    			message[3] = UARTCharGet(UART0_BASE); //grab last byte
    			//toggle();
    		}
    		if(count==4){
    			message[4] = UARTCharGet(UART0_BASE); //grab CRC
				if (crc8(0,message,4)==message[4]){
					UARTCharPut(UART0_BASE, 0xFF);	//CRC good (tell python end that)
					parseAndExecute(message);
				}else{
					UARTCharPut(UART0_BASE, 0x00);	//CRC bad
					redOn();
				}
    		}

    		count = count + 1;
    		if(count == 5)
    				count = 0;

    	}
    }
}
Ejemplo n.º 14
0
void Timer0IntHandler(void)
{
	int i;
	// Limpia el flag de interrupcion
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

/*	//Escribo el comando en el YEI
	for(i=0; i<sizeof(todos_normalizados); i++){
				UARTCharPut(UART4_BASE, todos_normalizados[i]);}*/

/*	//Escribo el comando en el YEI
	for(i=0; i<sizeof(giroscopo); i++){
				UARTCharPut(UART4_BASE, giroscopo[i]);}*/

	//Escribo el comando en el YEI
	for(i=0; i<sizeof(aceleracion); i++){
				UARTCharPut(UART4_BASE, aceleracion[i]);}

/*	//Escribo el comando en el YEI
	for(i=0; i<sizeof(magnetometro); i++){
				UARTCharPut(UART4_BASE, magnetometro[i]);}*/

	//Escribo el comando en el YEI
		for(i=0; i<sizeof(orientacion); i++){
					UARTCharPut(UART4_BASE, orientacion[i]);}

	cThisChar='0';
	int contador2=0;
	int contador_end_lines=0;

					do{

			    	cThisChar=UARTCharGet(UART4_BASE);
			    	BuffYEI[contador2]=cThisChar;
			    	contador2=contador2+1;
			    		if((cThisChar == '\n'))
			    			contador_end_lines=contador_end_lines+1;

						} while(contador_end_lines != 2);

		rc = f_open(&Fil, "BuffGPS.TXT", FA_WRITE | FA_OPEN_ALWAYS);	//abre o crea un archivo
		rc = f_lseek(&Fil, Fil.fsize);
		rc = f_write(&Fil, &BuffYEI, contador2, &bw);
		rc = f_sync(&Fil);
		rc = f_close(&Fil);

		if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
		{
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
		}
		else
		{
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
		}
}
Ejemplo n.º 15
0
void readPackage(){

	//debug_red = false;
	
	while(UARTCharsAvail(UART_PC_COMM)){
		
		package[packageCounter] = (char)UARTCharGet(UART_PC_COMM);
		
		getCommand();
	}
	
	while(UARTCharsAvail(UART4_BASE)) {
		
		if (read_mpu) {
			
			sensorData[sensorDataCounter++] = (char)UARTCharGet(UART4_BASE);
		
			if (sensorDataCounter == 6) {
				read_mpu = false;
				sensorDataCounter = 0;
				
				atualizaLeiturasMPU6050();
			}
		} else if (read_sonar) {
			sonarData[sonarDataCounter++] = (char)UARTCharGet(UART4_BASE);
			
			if (sonarDataCounter == 3) {
				read_sonar = false;
				sonarDataCounter = 0;
				atualizaLeituraSonar(sonarData[0]);
			}
		} else {
			
			char aux = (char)UARTCharGet(UART4_BASE);
			
			if (aux == MESSAGE_TYPE_DADOS_MPU6050) {
				read_mpu = true;
			}
			else if (aux == MESSAGE_TYPE_DADOS_SONAR) read_sonar = true;
		}
	}
}
Ejemplo n.º 16
0
Archivo: Base.c Proyecto: ilabmp/micro
void UARTIntHandler0() {
	unsigned long ulStatus;
	static char tempPacket = 0;

	ulStatus = UARTIntStatus(UART0_BASE, true);

	UARTIntClear(UART0_BASE, ulStatus);

	while (UARTCharsAvail(UART0_BASE)) {
		tempPacket = UARTCharGet(UART0_BASE);
	}
}
Ejemplo n.º 17
0
void UART3_int_handler(void)
{
	ISR_flag = 1;
	volatile uint8_t bit = UARTCharGet(UART3_BASE);
	ring_uart_read_buffer[ring_uart_write_pos] = bit; 
	if(++ring_uart_write_pos >= UART_RX_RING_LEN)
	{
		ring_uart_write_pos =0;
	}

	HWREG(UART3_BASE + UART_O_ICR) = UART_INT_RX;

}
Ejemplo n.º 18
0
void UARTPollRead(uint32_t BASE, char* read_buffer, uint32_t size)
{
    while (UARTCharsAvail(BASE))
    {
        for (int i =0; i < size; i++)
        {
           
            read_buffer[i] = UARTCharGet(BASE);
         
            
        }
    }   
}
Ejemplo n.º 19
0
//UART1 interrupt handler
void
UARTIntHandler1 () {
		unsigned long ulStatus;
		unsigned long c;
		int display_offset = 0;
		int i;
		int errorFlag = 0;

    // Get the interrrupt status.
    ulStatus = UARTIntStatus(UART1_BASE, true);


    // Clear the asserted interrupts.
    UARTIntClear(UART1_BASE, ulStatus);

    // Loop while there are characters in the receive FIFO.
    while(UARTCharsAvail(UART1_BASE))
    {
				c = UARTCharGet(UART1_BASE);
			
			
				display2[display_offset++] = (char)c;
				
    }
		
		display2[display_offset-1] = '\0';
		
		for(i = 0; i < (display_offset - 1); i++)
		{
			if(display2[i] == 'p')
			{
					errorFlag = 1;
			}
		}
		
		if(errorFlag == 1)
		{
			RIT128x96x4Clear();
			RIT128x96x4StringDraw("----------------------", 0, 50, 15);
			RIT128x96x4StringDraw("Error", 50, 75, 15);
			RIT128x96x4StringDraw(display, 0, 0, 15);
		}
		else
		{
			RIT128x96x4Clear();
			RIT128x96x4StringDraw("----------------------", 0, 50, 15);
			RIT128x96x4StringDraw(display, 0, 0, 15);
			RIT128x96x4StringDraw(display2, 0, 60, 15);
		}

}
Ejemplo n.º 20
0
void Test2(void){
	print( " : ");
	//if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
	if (UARTCharsAvail(UART0_BASE)){
		if(UARTCharGet(UART0_BASE) =='s'){
			print( "Enter the temperature  : ");
			sd1 = UARTCharGet(UART0_BASE);
			UARTCharPut(UART0_BASE,sd1);
			sd2 = UARTCharGet(UART0_BASE);
			UARTCharPut(UART0_BASE,sd2);
			print("Set Temperature updated to ");
			print_tc(sd1,sd2);
		}
	}
	else{
		get_temp();
		cd1 = ui32TempValueC/10 +48;
		cd2 = ui32TempValueC%10 + 48;
		if(cd1 >sd1){
			GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,2);
		}
		else if(cd1 == sd1){
			if(cd2 >sd2){
				GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,2);
			}
			else{
				GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,8);
			}
		}
		else{
			GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,8);
		}
		print("Current Temp = ");
		print_tc(cd1,cd2);
		print(", Set Temp = ");
		print_tc(sd1,sd2);
	}
}
int uart_Read(Fd_t fd, unsigned char *pBuff, int len)
{
	int i = 0;
	ROM_UARTIntDisable(UART1_BASE, UART_INT_RX);

	for(i=0; i< len; i++)
	{
		pBuff[i] = (unsigned char)UARTCharGet(UART1_BASE);
	}

	ROM_UARTIntEnable(UART1_BASE, UART_INT_RX);

	return len;
}
static void Bluetooth_RxTxHandler(void) {
	uint32_t IntStatus;
	IntStatus = UARTIntStatus(UART0_BASE, true);
	UARTIntClear(UART0_BASE, IntStatus);

	if (IntStatus & UART_INT_TX) {
		if (txTail < MAX_TX_BUF) {
			if (txHead != txTail) {
				UARTCharPutNonBlocking(UART0_BASE, txBuffer[txTail++]);
			} else {
				HC05_PutEvtIntoQueue(HC05_TX_DONE_EVENT);
			}
		} else {
			if (0 != txHead) {
				UARTCharPutNonBlocking(UART0_BASE, txBuffer[0]);
				txTail = 1;
			} else {
				HC05_PutEvtIntoQueue(HC05_TX_DONE_EVENT);
			}
		}
	}
	while (UARTCharsAvail(UART0_BASE)) {
		b_is_has_new_data = true;
		if (rxHead + 1 < MAX_RX_BUF) {
			if ((rxHead + 1) != rxTail) {
				rxBuffer[rxHead++] = UARTCharGet(UART0_BASE);
				ui16_rxSize++;
			}
		} else {
			if (0 != rxTail) {
				rxBuffer[rxHead] = UARTCharGet(UART0_BASE);
				ui16_rxSize++;
				rxHead = 0;
			}
		}
	}
}
Ejemplo n.º 23
0
/*
    a - reset pitch
    A - reset roll
*/
int ContropMessageLoop(unsigned long a,unsigned char b)
{
  inc = UARTCharGet(UART0_BASE);
  switch (inc)
  {
    case 'a':
    EncodeResetPitch();
    break;
    case 'A':
    EncodeResetRoll();
    break;
  }
  inc = 0;
  return 0;
}
Ejemplo n.º 24
0
/**
 * @brief the interrupt handler for the uart interrupt vector
 */
void UART0_intHandler(void)
{
    while (UARTCharsAvail(UART0_BASE))
    {
        uint32_t c = UARTCharGet(UART0_BASE);
        /* XXX process error flags for this character ?? */
        sReceiveBuffer[sReceiveTailIdx] = (uint8_t)c;
        sReceiveTailIdx++;

        if (sReceiveTailIdx >= CC2650_RECV_CIRC_BUFF_SIZE)
        {
            sReceiveTailIdx = 0;
        }
    }
}
Ejemplo n.º 25
0
uint32_t Uart::readByte(uint8_t * buffer, uint32_t length)
{
    uint32_t data;
    for (uint32_t i = 0; i < length; i++)
    {
        data = UARTCharGet(uart_.base);
        *buffer++ = (uint8_t)data;
    }

    // Wait until it is complete
    while(UARTBusy(uart_.base))
        ;

    return 0;
}
Ejemplo n.º 26
0
uint32_t inpTemp(){
	clrscr();
	char str[25] = "Enter the temperature : ";
	uint32_t temp=0,i;

	for(i=0;i<25;i++)
		UARTCharPut(UART0_BASE,str[i]);

	int flag=1;
	while (flag)
	{
		if (UARTCharsAvail(UART0_BASE)){
			char c = UARTCharGet(UART0_BASE);
			UARTCharPut(UART0_BASE,c);
			if(c>=48 && c<58){
				if(temp==0&&c=='0'){
					UARTCharPut(UART0_BASE,'\b');
					UARTCharPut(UART0_BASE,' ');
					UARTCharPut(UART0_BASE,'\b');
				}
				else
				temp = temp*10 + (c-48);
			}else if(c=='\b'){
				if(temp>0){
					temp = temp/10;
					UARTCharPut(UART0_BASE,' ');
					UARTCharPut(UART0_BASE,c);
				}else
					UARTCharPut(UART0_BASE,' ');
			}
			else
				flag=0;
		}
	}

	clrscr();
	char prompt[MAX_STRING_LENGTH]="Set Temperature updated to XX oC";
	prompt[28]=temp%10+48;
	prompt[27]=(temp/10)%10+48;
	if(DEGREE)
	prompt[30]=176;
	for(i=0;i<32;i++)
		UARTCharPut(UART0_BASE,prompt[i]);

	SysCtlDelay(SysCtlClockGet()); // Wait around 3 sec
	clrscr();
	return temp;
}
Ejemplo n.º 27
0
void UARTIntHandler(void)
{

	uint32_t ui32Status;
	char c;
	ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status

	UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts

	while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
	{
		c = UARTCharGet(UART0_BASE);
		if(c=='s'||c=='S')
			ui32TempSet = inpTemp();
	}
}
Ejemplo n.º 28
0
//UART interrupt handler
void UARTIntHandler0 ()
{
		unsigned long ulStatus;
		unsigned long c;
		int display_offset = 0;
		int buffer_offset = 0;
		int size;

    //
    // Get the interrrupt status.
    //
    ulStatus = UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ulStatus);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE))
    {
				c = UARTCharGet(UART0_BASE);
			
				//
        // Read the next character from the UART and write it back to the UART.
        //
				if(buffer_offset == 2)
				{
					size = c - 5;
				}
				
				if(buffer_offset >= 8)
				{
						display2[display_offset++] = (char)c;
				}
				buffer_offset++;
				
    }
		display2[size] = '\0';
		
		morseDisplay(display2,size);
		
		GPIOPinIntClear(GPIO_PORTB_BASE, GPIO_PIN_1);
}
Ejemplo n.º 29
0
uint32_t Uart::readByte(uint8_t * buffer, uint32_t length)
{
    uint32_t data;

    // Read all bytes from UART (blocking)
    for (uint32_t i = 0; i < length; i++)
    {
        data = UARTCharGet(config_.base);
        *buffer++ = (uint8_t)data;
    }

    // Wait until it is complete
    while(UARTBusy(config_.base))
        ;

    return 0;
}
Ejemplo n.º 30
0
int
main(void)
{
	char cThisChar;
	FRESULT rc;				/* Result code */

	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
			SYSCTL_XTAL_16MHZ);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB0_U1RX);
	GPIOPinConfigure(GPIO_PB1_U1TX);

	GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
						UART_CONFIG_PAR_NONE));

	UARTFIFOLevelSet(UART1_BASE,UART_FIFO_TX7_8,UART_FIFO_RX7_8);
	UARTTxIntModeSet(UART1_BASE, UART_TXINT_MODE_FIFO) ;

	// Habilito la interrupcion
	UARTIntRegister(UART1_BASE,UART1IntHandler);
	UARTIntClear(UART1_BASE, UART_INT_TX | UART_INT_RX);
	UARTEnable(UART1_BASE);
	IntEnable(INT_UART1);
	UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_TX);


	rc = f_mount(0, &Fatfs);					//registra un area de trabajo
	rc = f_open(&Fil, "Buff.TXT", FA_WRITE | FA_CREATE_ALWAYS);	//abre o crea un archivo


	cThisChar = UARTCharGet(UART1_BASE);

	rc = f_write(&Fil, Buff, contador, &bw);

	rc = f_close(&Fil);

	return(0);
}