This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| $|++; | |
| use Device::SerialPort; | |
| use Digest::CRC qw/crc16/; | |
| use Time::HiRes qw/usleep/; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "pca.h" | |
| #include "../model.h" | |
| #include "main.h" | |
| #include <avr/interrupt.h> | |
| #include <util/atomic.h> | |
| #define LED_DDRD DDRB | |
| #define LED_PORT PORTB | |
| #define LED_PIN PORTB0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| typedef enum _e_status { | |
| ACK = 0x00, | |
| NACK | |
| } e_status; | |
| struct timer_data { | |
| uint16_t crc16; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| // modify this to change the timer resolution | |
| typedef uint8_t st_type; | |
| /** | |
| * @brief software timer callback handler type declaration | |
| * | |
| * @return void | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @brief if there are no SEND/RECV routine definitions already existing | |
| * use the default definitions provided bellow | |
| */ | |
| #if !defined(SLIP_CHAR_SEND) || !defined(SLIP_CHAR_RECV) | |
| #include "config.h" | |
| #include "serial.h" | |
| /// redefine it, in your code to use different implementation of SEND routine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "pca.h" | |
| #include <util/delay.h> | |
| int main(void) | |
| { | |
| int cnt = 0; | |
| serial_init(E_BAUD_9600); | |
| serial_install_interrupts(E_FLAGS_SERIAL_RX_INTERRUPT); | |
| serial_flush(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void _serial_putc(char c, FILE *stream) { | |
| if ('\n' == c) { | |
| _serial_putc('\r', stream); | |
| } | |
| while (!serial_sendc(c)); | |
| } | |
| char _serial_getc(FILE *stream) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "pca.h" | |
| int main(int argc, char const *argv[]) | |
| { | |
| uint8_t c = 0x00; | |
| serial_init(E_BAUD_57600); | |
| serial_install_interrupts(E_FLAGS_SERIAL_RX_INTERRUPT); | |
| serial_flush(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ISR(USART_UDRE_vect, ISR_BLOCK) { | |
| // proceed if there still is data to be send | |
| if (g_tx_buff.head != g_tx_buff.tail) { | |
| UDR0 = g_tx_buff.ring[g_tx_buff.tail]; | |
| g_tx_buff.tail = (g_tx_buff.tail + 1) % SERIAL_TX_RING_SIZE; | |
| } | |
| else { | |
| // mask the interrupt everything has been send | |
| UCSR0B &= ~_BV(UDRIE0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // the RX ring buffer | |
| static volatile t_buffer g_rx_buff; | |
| ISR(USART_RX_vect, ISR_BLOCK) { | |
| // no frame error | |
| // UCSR0A must be read before UDR0 !!! | |
| if (bit_is_clear(UCSR0A, FE0)) { | |
| /// must read the data in order to clear the interrupt flag | |
| volatile unsigned char data = UDR0; |