void interrupt ISRRx ( void ) #endif { if ( INTCONbits.TMR0IF && INTCONbits.TMR0IE ) { if ( !Servo.Phase ) { if ( Servo_Idx == 0 && Servo.FL ) FL_SERVO = 1; if ( Servo_Idx == 1 && Servo.FR ) FR_SERVO = 1; if ( Servo_Idx == 2 && Servo.BL ) BL_SERVO = 1; if ( Servo_Idx == 3 && Servo.BR ) BR_SERVO = 1; Ticks4NextInterrupt = 65535 - Servo_PWM[Servo_Idx]; write_timer_0(Ticks4NextInterrupt); } else { if ( Servo_Idx == 0 && Servo.FL ) FL_SERVO = 0; if ( Servo_Idx == 1 && Servo.FR ) FR_SERVO = 0; if ( Servo_Idx == 2 && Servo.BL ) BL_SERVO = 0; if ( Servo_Idx == 3 && Servo.BR ) BR_SERVO = 0; Ticks4NextInterrupt = 65535 - Ticks4Window + Servo_PWM[Servo_Idx]; write_timer_0(Ticks4NextInterrupt); if ( ++Servo_Idx > 3 ) Servo_Idx = 0; } Servo.Phase = !Servo.Phase; INTCONbits.TMR0IF = 0; } if ( PIE1bits.RCIE && PIR1bits.RCIF ) { char_recv = usart_getc(); //usart_putc(char_recv); PIR1bits.RCIF = 0; } }
int UARTClass::read( void ) { // Block until a byte becomes available, to save user confusion. while (!this->available()) ; return usart_getc(this->_dev); }
int HardwareSerial::read(void) { if(usart_data_available(usart_device) > 0) { return usart_getc(usart_device); } else { return -1; } }
int FastSerial::peek(void) { if (available() <= 0) return (-1); // pull character from tail return usart_getc(this->usart_device); }
int main(void) { int i = 0; char ch = 0; os_status stat = OS_OK; stat = os_init(); stat = stat; stm32utils_system_init(); /* led flashes -> sign of system reset ok */ for(i = 0; i < 6; i++) { gpio_toggle_bit(GPIOA, 0); delay(50); } /* Boot Animation */ os_putchar(0x0C); /* clear screen */ os_printf("Booting...\r\n\r\n"); os_printf(" _\r\n"); os_printf(" _ / /\r\n"); os_printf(" | | ___ __ _ _| |_ __ _ _ __ __ _ _ _\r\n"); os_printf(" | | / _ \\/ _` |_ _/ _` | \\/ _)/ _` | / / / /\r\n"); os_printf(" | |_ _ __( (_| | | | (_| | | | ( (_| | \\ \\ \\ \\\r\n"); os_printf(" |_ _ _\\___|\\__,_| | | \\__, / | | \\__,_| /_/ /_/\r\n"); os_printf(" /_/ \\_ _/\r\n" ); os_printf("\r\n"); os_printf("Ousia "); os_printf(VERSION); os_printf(" "); os_printf(VER_NAME); os_printf("\r\n\tby Librae - [email protected]"); os_printf("\r\n\r\n"); os_printf("Hello, Ousia ~\r\n"); for (;;) { if (USART1->flag_trigger) { for (i = 0; i < USART1->cnt_trigger; i++) { ch = usart_getc(USART1); if (ch) { switch( ch ) { case '\r': os_printf( "\r\n" ); break; case '\b': os_printf( "\b \b" ); break; default: os_printf( "%c", ch ); break; } } } USART1->cnt_trigger = 0; } delay(10); } return 0; }
int usart_tgetc(int timeout) { int c; int i; if (!timeout) /* timeout specified? */ return usart_getc(); /* no, just return it */ for (i=0; i < timeout; i++) { if ((c = usart_getc()) != -1) /* any character found? */ return c; /* yes, return it */ SLEEP_MS(10); } return -1; }
/** * @brief Nonblocking USART receive. * @param dev Serial port to receive bytes from * @param buf Buffer to store received bytes into * @param len Maximum number of bytes to store * @return Number of bytes received */ uint32 usart_rx(usart_dev *dev, uint8 *buf, uint32 len) { uint32 rxed = 0; while (usart_data_available(dev) && rxed < len) { *buf++ = usart_getc(dev); rxed++; } return rxed; }
void IRQ_USART2(void) { char t = usart_getc(&usartcfg); if (t == '\r') usart_putc(&usartcfg, '\n'); usart_putc(&usartcfg, t); }
// read a character from the rx buffer uint8_t serial_read(void) { if (usart_tstc()) { uint8_t c = usart_getc(); if (!serial_rx_hook(c)) { return c; } } return SERIAL_NO_DATA; }
static void dbg_uart_recv(void) { uint8_t chr = usart_getc(&console_uart); /* Put sequence on queue */ queue_push(&(dbg_uart.rx), chr); #ifndef LOADER #ifdef CONFIG_KDB softirq_schedule(KDB_SOFTIRQ); #endif #endif }
// UART void getDate(int *yy,int *mm, int*dd) { char temp[5]; int i; do { usart_prints("\nPlease Enter Year (yyyy):"); for (i = 0; i <= 4; i++) { temp[i] = usart_getc(); // Get character usart_putc(temp[i]); // Echo it back } temp[i] = '\0'; sscanf(temp,"%d",yy); } while(*yy < 2016 || *yy > 2020); do { usart_prints("\nPlease Enter Month (mm):"); for (i = 0; i <= 2; i++) { temp[i] = usart_getc(); // Get character usart_putc(temp[i]); // Echo it back } temp[i] = '\0'; sscanf(temp,"%d",mm); } while(*mm < 1 || *mm > 12); do { usart_prints("\nPlease Enter Day (dd):"); for (i = 0; i <= 2; i++) { temp[i] = usart_getc(); // Get character usart_putc(temp[i]); // Echo it back } temp[i] = '\0'; sscanf(temp,"%d",dd); } while(*dd < 1 || *dd > 31); usart_prints("\n"); }
void usart_gets(RAM_SCLS char *buffer, unsigned char len) { unsigned char i; unsigned char dat; for(i=0;i<len;i++) { while(!usart_drdy()); dat = usart_getc(); *buffer = dat; buffer++; /* read until a \0 is received */ if(!dat)return; } }
int usart_read(char *buf, size_t buflen) { char *p = buf; int i; int ch; int cnt = 0; for (i=0; i < buflen; i++, p++) { if ((ch = usart_getc()) == -1) break; *p = (char)ch; ++cnt; } return cnt; }
int uart_GetString (char *str) { int pos=0; char *str_old = str; while ( *(str-1)!=0x0d ) { if (usart_drdy()) { *str= usart_getc(); usart_putc (*str); if (*str==0x08) str--; else str++; } } *str=0; return (str-str_old); }
USART_INTEGER usart_geti() { long i = 0; #ifdef USART_SUPPORT_SIGNED int8_t sign = 1; #endif while (1) { char ch = usart_getc(); if ('0' <= ch && ch <= '9') { // Accept only digits i = i * 10 + (ch - '0'); usart_putc(ch); } else if (ch == '\r') { // Exit with return code usart_putc('\r'); usart_putc('\n'); #ifdef USART_SUPPORT_SIGNED return i * sign; #else return i; #endif #ifdef USART_SUPPORT_SIGNED } else if (ch == '-') { // negative number usart_putc(ch); sign = -1; } else if (ch == '+') { // positive number usart_putc(ch); sign = +1; #endif } else if (ch == 0x1b) { // cancel usart_putc('\r'); usart_putc('\n'); usart_putc('>'); i = 0; #ifdef USART_SUPPORT_SIGNED sign = 1; #endif } } return 0; }
size_t usart_getstr_s(char* str, size_t len) { uint16_t i; for (i = 0; i < len - 1; i++) { char ch = usart_getc(); switch (ch) { case '\r': goto finish; case 0x1b: str -= i; i = 0; goto finish; default: usart_putc(ch); *str++ = ch; break; } } finish: *str = 0; usart_putc('\r'); usart_putc('\n'); return i; }
/*-----------------------------------------------------------------vSerialTask() * * Handle (usb/serial) from console and monitored device. * The idea here is to handle the incoming characters as quickly as possible. * All data coming from the console or the datalogger * is delimited by <CR><LF>. Finding an end of line "gives" a semaphore. * * eventually this should be moved down to the */ static void vSerialTask(void* pvParameters) { portTickType xLastWakeTime = xTaskGetTickCount(); const portTickType xWakePeriod = 50; usart_init(USART1); usart_set_baud_rate(USART1, USART_USE_PCLK, 9600); usart_enable(USART1); deviceComm.len=0; deviceComm.gotline=false; vSemaphoreCreateBinary( deviceComm.xGotLineSemaphore ); //if( deviceComm.xGotLineSemaphore == NULL ) //{ // FREAK OUT!!! //} consoleComm.len=0; consoleComm.gotline=false; vSemaphoreCreateBinary( consoleComm.xGotLineSemaphore ); //if( consoleComm.xGotLineSemaphore == NULL ) //{ // FREAK THE HELL OUT!!! //} // usart_init(USART2); // usart_set_baud_rate(USART2, USART_USE_PCLK, 9600); // usart_enable(USART2); while (true) { togglePin(YEL_LED); uint32_t rc=0; unsigned char ch; #if 0 if (!deviceComm.gotline) { //rc=usart_data_available(USART1); while (usart_data_available(USART1) && deviceComm.len<(MAX_COMMAND_LINE_LENGTH-1)) { ch=usart_getc(USART1); if (ch=='\r') { deviceComm.gotline=true; deviceComm.line[deviceComm.len]='\0'; //xSemaphoreGive(deviceComm.xGotLineSemaphore); break; } else if (ch!='\n') { deviceComm.line[deviceComm.len++]=ch; } } } #endif if (!consoleComm.gotline) { while(SerialUSB.isConnected() && SerialUSB.available() && consoleComm.len<(MAX_COMMAND_LINE_LENGTH-1)) { ch=SerialUSB.read(); SerialUSB.write(ch); if (ch=='\r') { consoleComm.gotline=true; consoleComm.line[consoleComm.len]='\0'; //xSemaphoreGive(consoleComm.xGotLineSemaphore); break; } else if ((ch==ASCII_DELETE) || (ch==ASCII_BACKSPACE)) { if (consoleComm.len) consoleComm.len--; } else if (ch!='\n') { consoleComm.line[consoleComm.len++]=ch; } } } vTaskDelayUntil(&xLastWakeTime, xWakePeriod); } }
uint8 HardwareSerial::read(void) { return usart_getc(usart_num); }
uint8 HardwareSerial::read(void) { // Block until a byte becomes available, to save user confusion. while (!this->available()) ; return usart_getc(this->usart_device); }
int FastSerial::read(void) { if (available() <= 0) return (-1); return usart_getc(this->usart_device); }
int STM32HardwareUsart::getc() { return usart_getc(m_regs); }
// Regardless of what the USB is up to, we check the USART to see // if there's something we should be doing. static void checkEcho() { static char bDebug=0, antDebug; static int giro=0; char buffer[80]; if (usart_drdy()) { // Have a character to huh unsigned char rxByte; rxByte = usart_getc(); usart_putc(rxByte); switch (rxByte) { case ' ': bDebug=!bDebug; printf ("\n\rDebug=%d ",bDebug); setMotorsDebug (bDebug); break; case 'a': velocidad++; motorSpeed (velocidad, MOTOR_1); motorSpeed (velocidad, MOTOR_2); break; case 'z': velocidad--; motorSpeed (velocidad, MOTOR_1); motorSpeed (velocidad, MOTOR_2); break; case 'e': antDebug=bDebug; setMotorsDebug (0); printf ("\n\rEntre velocidad: "); uart_GetString(buffer); velocidad = atoi (buffer); printf ("\n\rVelocidad = %d",velocidad); motorSpeed (velocidad, MOTOR_1); motorSpeed (velocidad, MOTOR_2); setMotorsDebug (antDebug); break; case 'X': if(deviceState == DETACHED) printf("Detached\r\n"); else if(deviceState == ATTACHED) printf("Attached\r\n"); else if(deviceState == POWERED) printf("Powered\r\n"); else if(deviceState == DEFAULT) printf("Default\r\n"); else if(deviceState == ADDRESS) printf("Address\r\n"); else if(deviceState == CONFIGURED) printf("Configured\r\n"); else printf("Unknown state\r\n"); printf("UCON: %x, UCFG: %x\r\n", UCON, UCFG); break; } } }
uint8 HardwareSerial::read(void) { return usart_getc(this->usart_device); }
int main(void) { uint16_t CalcCRC16(uint8_t data_array[], int data_lenght); int i; /////////////////////OSCYLATOR 32MHZ/////////////////////////////////////////// init_osc32(); ////KONFIGURACJA ADC//////////////////////////////////////////////////////////////// konfiguracja_adc(); /////////UART//////////////////////////////////////////////////////////////////////// PORTC_OUTSET = PIN7_bm; //Let's make PC7 as TX PORTC_DIRSET = PIN7_bm; //TX pin as output PORTC_OUTCLR = PIN6_bm; PORTC_DIRCLR = PIN6_bm; //PC6 as RX setUpSerial(); /////////////////////////////////////////////////////////////////////////////// PORTF_DIR=PIN0_bm; //PORTF_OUTSET=PIN0_bm; //zapalenie diody PORTC.DIRSET = PIN0_bm; // pin C0 jako wyjœcie PORTC.DIRSET = PIN1_bm; // pin C0 jako wyjœcie ////////////////////////Flip//////////////////////////////////////////////// PORTE.DIRCLR = PIN5_bm; // pin E5 jako wejœcie PORTE.PIN5CTRL = PORT_OPC_PULLUP_gc; // podci¹gniêcie do zasilania ////////////////////////////Klawisze gora do³ prawo lewo////////////////////////////////////////// PORTF.DIRCLR = PIN1_bm|PIN2_bm|PIN5_bm|PIN6_bm; PORTF.PIN1CTRL = PORT_OPC_PULLUP_gc|PORT_ISC_FALLING_gc; PORTF.PIN2CTRL = PORT_OPC_PULLUP_gc; PORTF.PIN5CTRL = PORT_OPC_PULLUP_gc; PORTF.PIN6CTRL = PORT_OPC_PULLUP_gc; ///////////////////////////////////Przerwanie INT0///////////////////////////////////////////////////// init_int0(); //////////////////////////TIMER0////////////////////////////////////////////////////// timer(); //////////////////////W£¥CZENIE PRZERWAÑ////////////////////////////////////////// sei(); // globalne w³¹czenie przerwañ //////////////////////////////////////////////////////////////////////////////////////// LcdInit(); // inicjalizacja sterownika LCD LcdGoto(0,0); Lcd("*Inzynierka_DiagBoX*"); // wyœwietlenie napisu LcdGoto(20,0); Lcd("Przedstawia:"); LcdGoto(25,1); Lcd("Marek Wudarczyk"); _delay_ms(1000); LcdClear(); while (1){ LcdClear(); LcdGoto(0,0); LcdDec(ADC); LcdGoto(5,0); Lcd("CNT = "); LcdDec(TCC0.CNT); LcdGoto(0,1); LcdDec(TCC0.PER); LcdGoto(20,1); Lcd("czas:"); LcdDec(c); i=usart_getc(); if(i==2){ while(1){ uint8_t i,j=0; i=usart_getc(); uint16_t ADC = ADC_GetResults(); uint8_t buff[] = {mlody_bajt(ADC),stary_bajt(ADC)}; buff[2] = mlody_bajt(CalcCRC16(buff,2)); buff[3] = stary_bajt(CalcCRC16(buff,2)); while(j<4){ sendChar(buff[j]); j++; } LcdClear(); Lcd("CRC:"); LcdDec(buff[2]); _delay_ms(10); if(i == 2){ break; } } i=0; } if(i==1){ PORTF_OUTTGL=PIN0_bm; i=0; } if(!(PORTE.IN & PIN5_bm)) /* je¿eli przycisk FLIP jest wciœniêty*/ { while(1){ uint32_t licz; licz++; if((licz>15100)&&(PORTE.IN & PIN5_bm)){ licz=0; c+=10; break; } } } _delay_ms(100); } }
// Reset and empty data in read buffer. Used by e-stop and reset. void serial_reset_read_buffer(void) { while (usart_tstc()) { usart_getc(); } }
char readchar( void ){ return usart_getc( 0 ); }
uint8 gps_read(void){ while(!gps_available()); return usart_getc(GPS_USART); }