コード例 #1
0
unsigned long UARTgeth(uint8_t UART, uint8_t digits)
{
    if (digits > 8) digits = 8;

    char digs[8];
    uint8_t a, b, c;

    // Clear the leading non-number characters
    c = UARTpeekBlocking(UART);
    while (!((c > 47 && c < 58) || (c > 64 && c < 71)))
    {
        UARTgetc(UART); // Clear the peeked character
        c = UARTpeekBlocking(UART);
    }

    // Read in digits
    for (a = 0; a < digits; a++)
    {
        digs[a] = UARTgetc(UART);
        if (!((digs[a] > 47 && digs[a] < 58) || (digs[a] > 64 && digs[a] < 71)))
            break;
    }

    // Convert to integer
    unsigned long h = 0;
    for (b = 0; b < a; b++)
    {
        if (digs[b] < 58) h += (digs[b] - 48) * power(16, a - b - 1);
        else h += (digs[b] - 55) * power(16, a - b - 1);
    }

    return h;
}
コード例 #2
0
long UARTgeti(uint8_t UART)
{
    char digs[10];
    uint8_t a, b, c, neg = 0;

    // Clear the leading non-number characters
    c = UARTpeekBlocking(UART); // Peeked char is now in peekedChar
    while ((c < 48 || c > 57) && c != '-')
    {
        UARTgetc(UART); // Clear the peeked character
        c = UARTpeekBlocking(UART);
    }

    // Read in digits
    for (a = 0; a < 10; a++)
    {
        digs[a] = UARTgetc(UART);
        if (digs[a] == '-')
        {
            neg ^= 1;
            a--;    // No digit was read
            continue;
        }
        else if (digs[a] < 48 || digs[a] > 57) break;
    }

    // Convert to integer
    long i = 0;
    for (b = 0; b < a; b++)
        i += (digs[b] - 48) * power(10, a - b - 1);
    if (neg) i = -i;

    return i;
}
コード例 #3
0
unsigned long UARTgetu(uint8_t UART, uint8_t digits)
{
    char digs[10];
    uint8_t a, b, c;

    if (digits > 10) digits = 10;

    // Clear the leading non-number characters
    c = UARTpeekBlocking(UART); // Peeked char is now in peekedChar
    while (c < 48 || c > 57)
    {
        UARTgetc(UART); // Clear the peeked character
        c = UARTpeekBlocking(UART);
    }

    // Read in digits
    for (a = 0; a < digits; a++)
    {
        digs[a] = UARTgetc(UART);
        if (digs[a] < 48 || digs[a] > 57) break;
    }

    // Convert to integer
    unsigned long u = 0;
    for (b = 0; b < a; b++)
        u += (digs[b] - 48) * power(10, a - b - 1);

    return u;
}
コード例 #4
0
void NatcarUartUpdate(void)
{
	if(!Enabled) return;

	if (CurrentState == LISTEN) {
		// listen for the command chars
		if(UARTRxBytesAvail() >= 3) {
			CurrentCommand[0] = UARTgetc();
			CurrentCommand[1] = UARTgetc();
			CurrentCommand[2] = UARTgetc();

			// MAYBE? check the commands?
			CurrentState = ACTIVE;
		}
	} else if (CurrentState == ACTIVE) {
		// process commands
		// if..else handle each command
		if (strcmp(CurrentCommand, "HAI") == 0) {
			// write back "AOK"
			UARTwrite("AOK", 3);
			UARTFlushRx();
			CurrentState = LISTEN;
		} else if (strcmp(CurrentCommand, "PID") == 0) {
			// write in pid values ->
      for ( ; UARTRxBytesAvail() > 0; )
        NU_Buffer = NUB_Append(NU_Buffer, UARTgetc());
      
      // if we have sufficient data in NU_Buffer and we haven't
      // actually processed any data yet
      if (NUB_Len(NU_Buffer) >= 4 && NU_MessageLength == -1) {
        // read message length
        char msgLen[4];
        NU_Buffer = NUB_PopFront(NU_Buffer, &msgLen[0]);
        NU_Buffer = NUB_PopFront(NU_Buffer, &msgLen[1]);
        NU_Buffer = NUB_PopFront(NU_Buffer, &msgLen[2]);
        NU_Buffer = NUB_PopFront(NU_Buffer, &msgLen[3]);
        
        // do something with newfound data
        NU_MessageLength = atoi(msgLen);
      }

      // if buffer has enough data
      if (NUB_Len(NU_Buffer) >= NU_MessageLength) {
        // set variables accordingly
      }
		} else {
			// comamnd not recognized.. done with command and restart
			UARTFlushRx();
			CurrentState = LISTEN;
		}

		// if (done with command) then
		// clear buffers
		// CurrentState = LISTEN;
	} else {
		// shouldn't be here...
		// flush buffer and set to LISTEN
	}

}
コード例 #5
0
ファイル: main.c プロジェクト: MaciejKucia/BP_RFID
/// User code entry point ///
///
int main(void)
{
    char adr, value;
    //int i = 0;

    // Initialize
    //
    ROM_SysCtlClockSet (SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    // 1ms SysTick
    SysTickPeriodSet(SysCtlClockGet() / 1000);
    SysTickIntEnable();
    SysTickEnable();

    // Serial console
    Launchpad_UART_Init();

    // Booster pack
    BP_RFID_Init();
    IntMasterEnable();

    printf("[START]\n");

    for (;;)
    {
        printf("> ");
        switch(UARTgetc())
        {
        case 'c':
            adr = UARTgetc();
            printf("[direct command 0x%02x]\n", adr);
            BP_RFID_TRF_Write_Command(adr);
            break;

        case 'w':
            adr = UARTgetc();
            value = UARTgetc();
            BP_RFID_TRF_Write_Register(adr, value);
            printf("[write 0x%02x < 0x%02x]\n");
            break;

        case 'r':
            adr = UARTgetc();
            printf("[read 0x%02x > 0x%02x]\n", adr, BP_RFID_TRF_Read_Register(adr));
            break;

        case 'x':
            BP_ISO15693_Init();
            break;

        case '\n':
        case '\r':
            break;

        default:
            printf("[unknown command]\n");
        }
    }
}
コード例 #6
0
ファイル: Task_TempChange.c プロジェクト: lulupalooza/EECS690
extern void Task_TempChange( void *pvParameters ) {

	//
	//	No set-up necessary
	//

	//char UARTgetTest[12];

			//UARTprintf(UARTgets(UARTgetTest, 12));
	//
	//	Enter task loop
	//

	while ( 1 ) {

		printf( "SysTickTime: %08X\n", xPortSysTickCount );
		//char buf[256];

		//sprintf(buf, "%d", UARTgets(UARTgetTest, 12));

		char changeChar = UARTgetc();

		if(changeChar == '+')
			temperature++;
		else if(changeChar == '-')
			temperature--;

		printf("Custom Char: %c ", changeChar);
		printf("New Temperature: %c \n", temperature);

		vTaskDelay( 1 );
	}
}
コード例 #7
0
char *UARTgets(uint8_t UART, char *str, int num)
{
    int a = 0;
    while (a < num - 1)
    {
        str[a] = UARTpeekBlocking(UART);    // Waits for a character
        if (str[a] == '\n' || str[a] == '\r') break;
        UARTgetc(UART); // Permits peek() to move on to the next char
        a++;
    }

    // Clear the trailing newline char(s)
    while (UARTpeek(UART) == '\n' || UARTpeek(UART) == '\r')
        UARTgetc(UART);

    str[a] = '\0';
    return str;
}
コード例 #8
0
ファイル: main.c プロジェクト: kred/stellaris-logic-analyzer
void get_command()
{
    unsigned char c = 0;
    unsigned char i = 0;

    current_command[0] = 0;
    while((c = UARTgetc()) != '\r' && i < CMD_LEN)
    {
        UARTprintf("%c", c);
        current_command[i++] = c;
    }
    current_command[i] = 0;
    UARTprintf("\r\n");
}
コード例 #9
0
float UARTgetf(uint8_t UART)
{
    char digs[12];
    uint8_t a, c;

    // Clear the leading non-number characters
    c = UARTpeekBlocking(UART);
    while (c < 45 || c > 57 || c == 47)
    {
        UARTgetc(UART); // Clear the peeked character
        c = UARTpeekBlocking(UART);
    }

    // Read in digits
    for (a = 0; a < 12; a++)
    {
        digs[a] = UARTgetc(UART);
        if (digs[a] < 45 || digs[a] > 57 || digs[a] == 47) break;
    }
    digs[a] = 0;

    // Convert to float
    return atof(digs);
}
コード例 #10
0
ファイル: main.c プロジェクト: ahliao/HandKey_Tiva
// Main entry point
int main(void) {
	volatile uint32_t ui32Loop;

	// Set the clocking to run directly from the crystal.
	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_XTAL_16MHZ |
	               SYSCTL_OSC_MAIN);

	SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
	
	ui32Loop = SYSCTL_RCGC2_R;

	GPIO_PORTF_DIR_R = 0x08;
	GPIO_PORTF_DEN_R = 0x08;

	ConfigureUART();
	for (ui32Loop = 0; ui32Loop < 200000; ui32Loop++) {	}
	//UARTprintf("AT+NAMEGloveKey");
	UARTCharPut(UART1_BASE, 'f');
	for (ui32Loop = 0; ui32Loop < 2000000; ui32Loop++) { }



	while(1)
	{
		UARTprintf("Hi Clark\r\n");
		if (UARTCharsAvail(UART1_BASE)) {
			unsigned char temp = UARTgetc();
			UARTCharPutNonBlocking(UART0_BASE, temp);
 		}
		GPIO_PORTF_DATA_R |= 0x08;

		for (ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
		{
		}

		GPIO_PORTF_DATA_R &= ~(0x08);
		for (ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
		{
		}
	}

	return 0;
}
コード例 #11
0
ファイル: interfazHumana.c プロジェクト: devtodev/NXP
void interfazHumana(void * parametrosTarea)
{
	portTickType ticker = xTaskGetTickCount();
	int estado = MAINMENU;
	char input;

	while(1)
	{
		if (estado == ESTACIONADO)
			showAlertaSeguridad(&consolaBT);
		if (estado == ANDANDO) showAlertaSalud(&consolaBT);
		showMenu(&consolaBT, estado);

		// lee un caracter desde el BT
		if (!ColaVacia(&consolaBT.colaRx))
		{
			input = UARTgetc(&consolaBT);
			inputBTChar(&estado, input, &consolaBT);
		}
	}
}
コード例 #12
0
ファイル: UARTDemo.c プロジェクト: achapp/Rasware2009
char getc(void) {
	char ch = UARTgetc();
	return ch;
}
コード例 #13
0
ファイル: main-test.cpp プロジェクト: brNX/purpins_firmware
int main(){

	unsigned long ulClockMS=0;

	//
	// Enable lazy stacking for interrupt handlers.  This allows floating-point
	// instructions to be used within interrupt handlers, but at the expense of
	// extra stack usage.
	//
	MAP_FPUEnable();
	MAP_FPULazyStackingEnable();

	//
	// Set the clocking to run directly from the crystal.
	//
	MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
			SYSCTL_XTAL_16MHZ);

	MAP_IntMasterDisable();

	configureQEI();
	configurePWM();

	/*leftmotor_pid.setMaxOutput(255);
	leftmotor_pid.setMinOutput(-255);
	leftmotor_pid.setGains(12.0,5.0,0.0);
	leftmotor_pid.setSampleTime(1.0/QEILOOPFREQUENCY);*/

	leftmotor_pid.setInputLimits(-100,100);
	leftmotor_pid.setOutputLimits(-255,255);
    leftmotor_pid.setBias(0.0);
    leftmotor_pid.setMode(AUTO_MODE);


	configureUART();

	MAP_IntMasterEnable();


	// Get the current processor clock frequency.
	ulClockMS = MAP_SysCtlClockGet() / (3 * 1000);
	int char_counter=0;
	char inputbuffer[10];

	while(1){

		inputbuffer[char_counter]=UARTgetc();
		char_counter++;

		if (char_counter==3){
			inputbuffer[3]=0;
			goal_vel=atoi(inputbuffer);
			char_counter=0;
		}


		//uint32_t pos = MAP_QEIPositionGet(QEI1_BASE);
		/*uint32_t vel = MAP_QEIVelocityGet(QEI1_BASE);
		//UARTprintf("pos : %u \n",pos);QEIDirectionGet(QEI1_BASE)*/

		/*UARTprintf("vel : %d pwm %d\n",vel,pwm_value);
		MAP_SysCtlDelay(ulClockMS*50);*/

	}
	return 0;
}
コード例 #14
0
ファイル: GPS.c プロジェクト: simonfrfr/ERGO_GEN_5
int getdataz(void) {
return UARTgetc();
}
コード例 #15
0
ファイル: uart.c プロジェクト: BoomNPow/Rasware2013
unsigned char Getc(void)
{
  return UARTgetc();
}