//executed in ISR, called from scheduler.c void isr_openserial_rx() { if (openserial_vars.mode==MODE_INPUT) { if (openserial_vars.ready_receive_command==TRUE) { openserial_vars.ready_receive_command=FALSE; openserial_vars.received_command=uart_readByte(); openserial_vars.ready_receive_length=TRUE; } else if (openserial_vars.ready_receive_length==TRUE) { openserial_vars.ready_receive_length=FALSE; openserial_vars.input_buffer_bytes_still_to_come=uart_readByte(); } else { openserial_vars.input_buffer[openserial_vars.input_buffer_fill_level++]=uart_readByte(); if (openserial_vars.input_buffer_fill_level+1>SERIAL_INPUT_BUFFER_SIZE) { openserial_printError(COMPONENT_OPENSERIAL,ERR_INPUT_BUFFER_OVERFLOW, (errorparameter_t)0, (errorparameter_t)0); openserial_vars.input_buffer_fill_level=0; openserial_stop(); } openserial_vars.input_buffer_bytes_still_to_come--; if (openserial_vars.input_buffer_bytes_still_to_come==0) { openserial_stop(); } } } }
void cb_uartRxCb() { uint8_t byte; // toggle LED leds_error_toggle(); // read received byte byte = uart_readByte(); // echo that byte over serial uart_writeByte(byte); }
// executed in ISR, called from scheduler.c void isr_openserial_rx() { uint8_t rxbyte; uint8_t inputBufFill; // stop if I'm not in input mode if (openserial_vars.mode!=MODE_INPUT) { return; } // read byte just received rxbyte = uart_readByte(); //keep lenght inputBufFill=openserial_vars.inputBufFill; if ( openserial_vars.busyReceiving==FALSE && openserial_vars.lastRxByte==HDLC_FLAG && rxbyte!=HDLC_FLAG ) { // start of frame // I'm now receiving openserial_vars.busyReceiving = TRUE; // create the HDLC frame inputHdlcOpen(); // add the byte just received inputHdlcWrite(rxbyte); } else if ( openserial_vars.busyReceiving==TRUE && rxbyte!=HDLC_FLAG ) { // middle of frame // add the byte just received inputHdlcWrite(rxbyte); if (openserial_vars.inputBufFill+1>SERIAL_INPUT_BUFFER_SIZE){ // input buffer overflow openserial_printError(COMPONENT_OPENSERIAL,ERR_INPUT_BUFFER_OVERFLOW, (errorparameter_t)0, (errorparameter_t)0); openserial_vars.inputBufFill = 0; openserial_vars.busyReceiving = FALSE; openserial_stop(); } } else if ( openserial_vars.busyReceiving==TRUE && rxbyte==HDLC_FLAG ) { // end of frame // finalize the HDLC frame inputHdlcClose(); if (openserial_vars.inputBufFill==0){ // invalid HDLC frame openserial_printError(COMPONENT_OPENSERIAL,ERR_WRONG_CRC_INPUT, (errorparameter_t)inputBufFill, (errorparameter_t)0); } openserial_vars.busyReceiving = FALSE; openserial_stop(); } openserial_vars.lastRxByte = rxbyte; }
uint8_t isr_openserial_rx(void) { uint8_t rxbyte; uint8_t returnVal; returnVal = 0; // read byte just received rxbyte = uart_readByte(); if ( openserial_vars.hdlcBusyReceiving==FALSE && openserial_vars.hdlcLastRxByte==HDLC_FLAG && rxbyte!=HDLC_FLAG ) { // start of frame // I'm now receiving openserial_vars.hdlcBusyReceiving = TRUE; // create the HDLC frame inputHdlcOpen(); // add the byte just received inputHdlcWrite(rxbyte); } else if ( openserial_vars.hdlcBusyReceiving==TRUE && rxbyte!=HDLC_FLAG ) { // middle of frame // add the byte just received inputHdlcWrite(rxbyte); if (openserial_vars.inputBufFillLevel+1>SERIAL_INPUT_BUFFER_SIZE){ // push task scheduler_push_task(task_printInputBufferOverflow,TASKPRIO_OPENSERIAL); openserial_vars.inputBufFillLevel = 0; openserial_vars.hdlcBusyReceiving = FALSE; } } else if ( openserial_vars.hdlcBusyReceiving==TRUE && rxbyte==HDLC_FLAG ) { // end of frame // finalize the HDLC frame inputHdlcClose(); openserial_vars.hdlcBusyReceiving = FALSE; if (openserial_vars.inputBufFillLevel==0){ // push task scheduler_push_task(task_printWrongCRCInput,TASKPRIO_OPENSERIAL); } else { openserial_handleRxFrame(); openserial_vars.inputBufFillLevel = 0; returnVal = 1; } } openserial_vars.hdlcLastRxByte = rxbyte; return returnVal; }