Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Forwarded from mlat 🏳️🌈]
- ISR(USART_RXC_vect) {
- char r = UDR;
- switch (uart.state) {
- case UART_IDLE: //payload start
- while (UCSRA & (1 << UDRE)) {}
- if (r < BUFSIZE && r > 0) {
- uart.len = r; //set payload length
- uart.state = UART_PAYLOAD;
- UDR = 0x00;
- } else if (r == 0) {
- UDR = 0xf0;
- } else if (r >= BUFSIZE) {
- UDR = 0xf9;
- }
- while (UCSRA & (1 << UDRE)) {}
- break;
- case UART_PAYLOAD:
- uart.buffer[uart.idx] = r;
- uart.crc = _crc8_ccitt_update(uart.crc, r);
- uart.idx++;
- if (uart.len == uart.idx) {
- uart.state = UART_CRC;
- }
- break;
- case UART_CRC:
- while (UCSRA & (1 << UDRE)) {}
- if (_crc8_ccitt_update(uart.crc, r)) {
- UDR = 0;
- } else {
- UDR = 0xff;
- }
- while (UCSRA & (1 << UDRE)) {}
- uart.state = UART_IDLE;
- break;
- case UART_CONFIRM:
- uart.conf_ret = r;
- uart.state = UART_IDLE;
- case UART_LOCK:
- while (UCSRA & (1 << UDRE)) {}
- UDR = 0xff;
- while (UCSRA & (1 << UDRE)) {}
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement