grbl/serial.h@0:8f0d870509fe, 2017-09-04 (annotated)
- Committer:
- Sergunb
- Date:
- Mon Sep 04 12:04:13 2017 +0000
- Revision:
- 0:8f0d870509fe
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8f0d870509fe | 1 | /* |
Sergunb | 0:8f0d870509fe | 2 | serial.c - Low level functions for sending and recieving bytes via the serial port |
Sergunb | 0:8f0d870509fe | 3 | Part of Grbl |
Sergunb | 0:8f0d870509fe | 4 | |
Sergunb | 0:8f0d870509fe | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC |
Sergunb | 0:8f0d870509fe | 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud |
Sergunb | 0:8f0d870509fe | 7 | |
Sergunb | 0:8f0d870509fe | 8 | Grbl is free software: you can redistribute it and/or modify |
Sergunb | 0:8f0d870509fe | 9 | it under the terms of the GNU General Public License as published by |
Sergunb | 0:8f0d870509fe | 10 | the Free Software Foundation, either version 3 of the License, or |
Sergunb | 0:8f0d870509fe | 11 | (at your option) any later version. |
Sergunb | 0:8f0d870509fe | 12 | |
Sergunb | 0:8f0d870509fe | 13 | Grbl is distributed in the hope that it will be useful, |
Sergunb | 0:8f0d870509fe | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8f0d870509fe | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8f0d870509fe | 16 | GNU General Public License for more details. |
Sergunb | 0:8f0d870509fe | 17 | |
Sergunb | 0:8f0d870509fe | 18 | You should have received a copy of the GNU General Public License |
Sergunb | 0:8f0d870509fe | 19 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
Sergunb | 0:8f0d870509fe | 20 | */ |
Sergunb | 0:8f0d870509fe | 21 | |
Sergunb | 0:8f0d870509fe | 22 | #ifndef serial_h |
Sergunb | 0:8f0d870509fe | 23 | #define serial_h |
Sergunb | 0:8f0d870509fe | 24 | |
Sergunb | 0:8f0d870509fe | 25 | #ifdef AVRTARGET |
Sergunb | 0:8f0d870509fe | 26 | #ifndef RX_BUFFER_SIZE |
Sergunb | 0:8f0d870509fe | 27 | #define RX_BUFFER_SIZE 128 |
Sergunb | 0:8f0d870509fe | 28 | #endif |
Sergunb | 0:8f0d870509fe | 29 | #ifndef TX_BUFFER_SIZE |
Sergunb | 0:8f0d870509fe | 30 | #ifdef USE_LINE_NUMBERS |
Sergunb | 0:8f0d870509fe | 31 | #define TX_BUFFER_SIZE 112 |
Sergunb | 0:8f0d870509fe | 32 | #else |
Sergunb | 0:8f0d870509fe | 33 | #define TX_BUFFER_SIZE 104 |
Sergunb | 0:8f0d870509fe | 34 | #endif |
Sergunb | 0:8f0d870509fe | 35 | #endif |
Sergunb | 0:8f0d870509fe | 36 | #else |
Sergunb | 0:8f0d870509fe | 37 | #define RX_BUFFER_SIZE 254 |
Sergunb | 0:8f0d870509fe | 38 | #ifndef WIN32 |
Sergunb | 0:8f0d870509fe | 39 | #define TX_BUFFER_SIZE 128 // Do not try 256 it will not work for STM32. |
Sergunb | 0:8f0d870509fe | 40 | #else |
Sergunb | 0:8f0d870509fe | 41 | #define TX_BUFFER_SIZE 254 |
Sergunb | 0:8f0d870509fe | 42 | #endif |
Sergunb | 0:8f0d870509fe | 43 | #endif |
Sergunb | 0:8f0d870509fe | 44 | |
Sergunb | 0:8f0d870509fe | 45 | #define SERIAL_NO_DATA 0xff |
Sergunb | 0:8f0d870509fe | 46 | |
Sergunb | 0:8f0d870509fe | 47 | #ifdef WIN32 |
Sergunb | 0:8f0d870509fe | 48 | void winserial_init(char *pPort); |
Sergunb | 0:8f0d870509fe | 49 | #endif |
Sergunb | 0:8f0d870509fe | 50 | |
Sergunb | 0:8f0d870509fe | 51 | void serial_init(); |
Sergunb | 0:8f0d870509fe | 52 | |
Sergunb | 0:8f0d870509fe | 53 | // Writes one byte to the TX serial buffer. Called by main program. |
Sergunb | 0:8f0d870509fe | 54 | void serial_write(uint8_t data); |
Sergunb | 0:8f0d870509fe | 55 | |
Sergunb | 0:8f0d870509fe | 56 | // Fetches the first byte in the serial read buffer. Called by main program. |
Sergunb | 0:8f0d870509fe | 57 | uint8_t serial_read(); |
Sergunb | 0:8f0d870509fe | 58 | |
Sergunb | 0:8f0d870509fe | 59 | // Reset and empty data in read buffer. Used by e-stop and reset. |
Sergunb | 0:8f0d870509fe | 60 | void serial_reset_read_buffer(); |
Sergunb | 0:8f0d870509fe | 61 | |
Sergunb | 0:8f0d870509fe | 62 | // Returns the number of bytes available in the RX serial buffer. |
Sergunb | 0:8f0d870509fe | 63 | uint8_t serial_get_rx_buffer_available(); |
Sergunb | 0:8f0d870509fe | 64 | |
Sergunb | 0:8f0d870509fe | 65 | // Returns the number of bytes used in the RX serial buffer. |
Sergunb | 0:8f0d870509fe | 66 | // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h. |
Sergunb | 0:8f0d870509fe | 67 | uint8_t serial_get_rx_buffer_count(); |
Sergunb | 0:8f0d870509fe | 68 | |
Sergunb | 0:8f0d870509fe | 69 | // Returns the number of bytes used in the TX serial buffer. |
Sergunb | 0:8f0d870509fe | 70 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks. |
Sergunb | 0:8f0d870509fe | 71 | uint8_t serial_get_tx_buffer_count(); |
Sergunb | 0:8f0d870509fe | 72 | |
Sergunb | 0:8f0d870509fe | 73 | #endif |