Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be407af3b7 | ||
|
|
8e55f440f4 | ||
|
|
0a2718c34f | ||
|
|
ecdac7b3d3 | ||
|
|
c16d9662dd | ||
|
|
321722d9b1 | ||
|
|
8e4329c9d3 | ||
|
|
eceecf15d4 | ||
|
|
4b4a162f72 | ||
|
|
a19da2cbd3 | ||
|
|
a154d92903 | ||
|
|
c0bb094a39 | ||
|
|
c82c3b11cb | ||
|
|
d71e47036c |
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Display_Avr_3.iml" filepath="$PROJECT_DIR$/.idea/Display_Avr_3.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -13,3 +13,4 @@
|
|||||||
|
|
||||||
Деркачев Андрей
|
Деркачев Андрей
|
||||||
* Соединения и рефактор блоков UART, HDLC и вывода
|
* Соединения и рефактор блоков UART, HDLC и вывода
|
||||||
|
* Работа с I2C
|
||||||
@@ -0,0 +1,380 @@
|
|||||||
|
#include "frame.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern int window_length;
|
||||||
|
extern int raw_data_length;
|
||||||
|
extern int frame_number_range;
|
||||||
|
|
||||||
|
|
||||||
|
/* 33 crc*/
|
||||||
|
short crc[] = {1, 0, 0, 0, 0, 0,
|
||||||
|
1, 0, 0, 1, 1, 0,
|
||||||
|
0, 0, 0, 0, 1,
|
||||||
|
0, 0, 0, 1, 1, 1,
|
||||||
|
0, 1, 1, 0, 1, 1,
|
||||||
|
0, 1, 1, 1};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
short send_receive_num[][3] = {{0, 0, 0},
|
||||||
|
{0, 0, 1},
|
||||||
|
{0, 1, 0},
|
||||||
|
{0, 1, 1},
|
||||||
|
{1, 0, 0},
|
||||||
|
{1, 0, 1},
|
||||||
|
{1, 1, 0},
|
||||||
|
{1, 1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
|
static Frame *fill_flag_and_fcs(Frame *p_frame) {
|
||||||
|
|
||||||
|
short s[] = {0, 1, 1, 1, 1, 1, 1, 0};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
p_frame ->head_flag[i] = s[i];
|
||||||
|
p_frame ->rail_flag[i] = s[i];
|
||||||
|
}
|
||||||
|
for (i = 0; i < (sizeof(crc) / sizeof(short) - 1); ++i) {
|
||||||
|
p_frame ->fcs[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Frame *create_generic_unnumbered_frame(Frame *p_frame) {
|
||||||
|
|
||||||
|
fill_flag_and_fcs(p_frame);
|
||||||
|
p_frame ->control[0] = 1;
|
||||||
|
p_frame ->control[1] = 1;
|
||||||
|
p_frame ->s.size = 0;
|
||||||
|
return p_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Frame *create_generic_info_frame(Frame *p_frame) {
|
||||||
|
|
||||||
|
fill_flag_and_fcs(p_frame);
|
||||||
|
p_frame ->control[0] = 0;
|
||||||
|
p_frame ->s.size = 0;
|
||||||
|
return p_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Frame *create_generic_sup_frame(Frame *p_frame) {
|
||||||
|
|
||||||
|
fill_flag_and_fcs(p_frame);
|
||||||
|
p_frame ->control[0] = 1;
|
||||||
|
p_frame ->control[1] = 0;
|
||||||
|
p_frame ->s.size = 0;
|
||||||
|
return p_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void convert_frame_to_seq(Frame *p_frame, short seq[], int *size) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
(*size) = 0;
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
seq[*size] = p_frame ->address[i];
|
||||||
|
++(*size);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
seq[*size] = p_frame ->control[i];
|
||||||
|
++(*size);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < p_frame ->s.size; ++i) {
|
||||||
|
if (1 == (p_frame ->s.infor_type[i])) {
|
||||||
|
seq[*size] = p_frame ->s.information[i];
|
||||||
|
++(*size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < sizeof(crc) / sizeof(short) - 1; ++i) {
|
||||||
|
seq[*size] = p_frame ->fcs[i];
|
||||||
|
++(*size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* 0 has been filled before calling this method.*/
|
||||||
|
|
||||||
|
static int seq_fcs(short seq[], int size) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
int non_zero = 0;
|
||||||
|
int temp_non_zero;
|
||||||
|
bool new_non_zero = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < size; ++i) {
|
||||||
|
if (1 == seq[i]) {
|
||||||
|
non_zero = i;
|
||||||
|
new_non_zero = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;non_zero <= size - sizeof(crc)/sizeof(short);) {
|
||||||
|
new_non_zero = 0;
|
||||||
|
temp_non_zero = -1;
|
||||||
|
for (i = non_zero; i < non_zero + sizeof(crc)/sizeof(short); ++i) {
|
||||||
|
seq[i] ^= crc[i - non_zero];
|
||||||
|
if ((1 == seq[i]) && !new_non_zero) {
|
||||||
|
temp_non_zero = i;
|
||||||
|
new_non_zero = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-1 == temp_non_zero) {
|
||||||
|
for (i = non_zero + sizeof(crc) / sizeof(short); i < size; ++i) {
|
||||||
|
if (1 == seq[i]) {
|
||||||
|
non_zero = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == size) return -1;
|
||||||
|
} else {
|
||||||
|
non_zero = temp_non_zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return non_zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Here add fcs to one frame*/
|
||||||
|
static void add_fcs_to_frame(Frame *p_frame) {
|
||||||
|
|
||||||
|
short seq[1024];
|
||||||
|
int size = 0;
|
||||||
|
int i;
|
||||||
|
int non_zero = 0;
|
||||||
|
|
||||||
|
convert_frame_to_seq(p_frame, seq, &size);
|
||||||
|
|
||||||
|
seq_fcs(seq, size);
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(crc)/sizeof(short) - 1; ++i) {
|
||||||
|
p_frame ->fcs[i] = seq[size - (sizeof(crc)/sizeof(short) - 1) + i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void convert_decimal_2_binary(int decimal, short binary[]) {
|
||||||
|
|
||||||
|
binary[2] = decimal % 2;
|
||||||
|
binary[0] = decimal / 4;
|
||||||
|
binary[1] = (decimal - binary[0] * 4) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Here create SABME, UA and DISC.*/
|
||||||
|
Frame create_unnumbered_frame(short addr[], enum FRAME_TYPE ft, bool p_f) {
|
||||||
|
|
||||||
|
Frame f;
|
||||||
|
short s1[] = {1, 1, 0, 1, 1, 0};/* For SABME*/
|
||||||
|
short s2[] = {0, 0, 0, 1, 1, 0};/* For UA*/
|
||||||
|
short s3[] = {0, 0, 0, 0, 1, 0};/* For DISC*/
|
||||||
|
int i;
|
||||||
|
|
||||||
|
create_generic_unnumbered_frame(&f);
|
||||||
|
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
f.address[i] = addr[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(ft) {
|
||||||
|
case SABME :
|
||||||
|
for (i = 2; i < 8; ++i) {
|
||||||
|
f.control[i] = s1[i - 2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UA :
|
||||||
|
for (i = 2; i < 8; ++i) {
|
||||||
|
f.control[i] = s2[i - 2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISC :
|
||||||
|
for (i = 2; i < 8; ++i) {
|
||||||
|
f.control[i] = s3[i - 2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default : fprintf(stderr, "Call create unnumbered frame error!\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
f.control[4] = p_f;
|
||||||
|
|
||||||
|
add_fcs_to_frame(&f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
Frame create_sup_frame(short addr[], enum FRAME_TYPE ft, bool p_f, short want_receive) {
|
||||||
|
Frame f;
|
||||||
|
int i;
|
||||||
|
short next_receive[3];
|
||||||
|
create_generic_sup_frame(&f);
|
||||||
|
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
f.address[i] = addr[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
f.control[2] = 0;
|
||||||
|
switch(ft) {
|
||||||
|
case RR :
|
||||||
|
f.control[3] = 0;
|
||||||
|
break;
|
||||||
|
case REJ :
|
||||||
|
f.control[3] = 1;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
fprintf(stderr, "create sup frame error!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
f.control[4] = p_f;
|
||||||
|
|
||||||
|
|
||||||
|
convert_decimal_2_binary(want_receive, next_receive);
|
||||||
|
for (i = 5; i < 8; ++i) {
|
||||||
|
f.control[i] = next_receive[i - 5];
|
||||||
|
}
|
||||||
|
|
||||||
|
add_fcs_to_frame(&f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* prequestic : ($end - $start) % $raw_data_length = 0*/
|
||||||
|
Frame* create_infor_frames(short addr[], short send_n, bool p_f, short receive_n,
|
||||||
|
short data[], int start, int end, Frame *frames) { /*Normal data transferring.*/
|
||||||
|
|
||||||
|
Frame f;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
int ite = 0;
|
||||||
|
short receive_number[3];
|
||||||
|
short send_number[3];
|
||||||
|
|
||||||
|
if ((end -start + 1) > (850 * window_length)) {
|
||||||
|
fprintf(stderr, "One frame takes too long data!\n");
|
||||||
|
return &f;
|
||||||
|
}
|
||||||
|
|
||||||
|
convert_decimal_2_binary(receive_n, receive_number);
|
||||||
|
|
||||||
|
for (ite = 0; ite < ((end - start) / raw_data_length); ++ite) {
|
||||||
|
|
||||||
|
create_generic_info_frame(&f);
|
||||||
|
convert_decimal_2_binary(send_n, send_number);
|
||||||
|
for (i = 1; i < 4; ++i) {
|
||||||
|
|
||||||
|
f.control[i] = send_number[i - 1];
|
||||||
|
f.control[i + 4] = receive_number[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
send_n = (send_n + 1) % frame_number_range;
|
||||||
|
f.control[4] = p_f;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
k = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*bit stuffing!*/
|
||||||
|
for (i = start + ite * raw_data_length; i < start + (ite + 1) * raw_data_length; ++i) {
|
||||||
|
|
||||||
|
f.s.information[k] = data[i]; f.s.infor_type[k] = 1; ++k; ++f.s.size;
|
||||||
|
if (1 == data[i]) {
|
||||||
|
if (4 == (i - j)) {
|
||||||
|
f.s.information[k] = 0; f.s.infor_type[k] = 0; ++k; ++f.s.size;
|
||||||
|
j = i + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
j = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add_fcs_to_frame(&f);
|
||||||
|
frames[ite] = f;
|
||||||
|
}
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
|
|
||||||
|
short unnumbered[][8] = {
|
||||||
|
{1, 1, 1, 1, 0, 1, 1, 0}, /*SABME*/
|
||||||
|
{1, 1, 0, 0, 0, 1, 1, 0}, /*UA*/
|
||||||
|
{1, 1, 0, 0, 0, 0, 1, 0} /*DISC*/ };
|
||||||
|
|
||||||
|
enum FRAME_TYPE get_frame_type(Frame *p_frame) {
|
||||||
|
|
||||||
|
if (0 == p_frame ->control[0]) {
|
||||||
|
return INFOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == p_frame ->control[1]) {
|
||||||
|
if (0 == p_frame ->control[3]) return RR;
|
||||||
|
else return REJ;
|
||||||
|
} else {
|
||||||
|
if (1 == p_frame ->control[2]) return SABME;
|
||||||
|
else {
|
||||||
|
if (1 == p_frame ->control[5]) return UA;
|
||||||
|
else return DISC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "Inteprete Frame type error!\n");
|
||||||
|
return INFOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_address(Frame *p_frame, short *storage) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
storage[i] = p_frame ->address[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only for INFOR, */
|
||||||
|
short get_send_number(Frame *p_frame) {
|
||||||
|
|
||||||
|
int num;
|
||||||
|
num = p_frame ->control[1] * 4 + p_frame ->control[2] * 2 + p_frame ->control[3];
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
/* For INFOR, RR, REJ.*/
|
||||||
|
short get_expect_number(Frame *p_frame) {
|
||||||
|
|
||||||
|
int num;
|
||||||
|
num = p_frame ->control[5] * 4 + p_frame ->control[6] * 2 + p_frame ->control[7];
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only for INFOR.*/
|
||||||
|
void get_infor(Frame *p_frame, short *storage, int *size) {
|
||||||
|
int i;
|
||||||
|
*size = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < p_frame ->s.size; ++i) {
|
||||||
|
if (1 == p_frame ->s.infor_type[i]) {
|
||||||
|
storage[*size] = p_frame ->s.information[i];
|
||||||
|
++(*size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Here using fcs to judge whether the data is right.*/
|
||||||
|
bool is_fcs_right(Frame *p_frame) {
|
||||||
|
|
||||||
|
short seq[1024];
|
||||||
|
int size = 0;
|
||||||
|
int non_zero;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
convert_frame_to_seq(p_frame, seq, &size);
|
||||||
|
|
||||||
|
non_zero = seq_fcs(seq, size);
|
||||||
|
if (-1 == non_zero) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#ifndef _FRAME_H
|
||||||
|
#define _FRAME_H
|
||||||
|
|
||||||
|
typedef int bool;
|
||||||
|
|
||||||
|
/*This is the frame structure in HDLC.*/
|
||||||
|
typedef struct Frame {
|
||||||
|
|
||||||
|
short head_flag[8];
|
||||||
|
short address[8];
|
||||||
|
short control[8];
|
||||||
|
struct{
|
||||||
|
|
||||||
|
/*Actuall size should also be arry. It is also sequence of '01', here I simplify it.*/
|
||||||
|
short size; /*Record the real length of the data.*/
|
||||||
|
short information[1024];/*Capacity is 1024.*/
|
||||||
|
short infor_type[1024]; /*0 : bit stuffing; 1 : real data.*/
|
||||||
|
}s;
|
||||||
|
|
||||||
|
short fcs[32];
|
||||||
|
short rail_flag[8];
|
||||||
|
}Frame;
|
||||||
|
|
||||||
|
enum FRAME_TYPE {SABME, DISC, UA, REJ, RR, INFOR};
|
||||||
|
|
||||||
|
/* SABME, UA and DISC*/
|
||||||
|
Frame create_unnumbered_frame(short addr[], enum FRAME_TYPE ft, bool p_f);
|
||||||
|
|
||||||
|
/* REJ, RR*/
|
||||||
|
Frame create_sup_frame(short addr[], enum FRAME_TYPE ft, bool p_f, short next_receive);
|
||||||
|
|
||||||
|
/* Frame for normal data transferring.*/
|
||||||
|
Frame* create_infor_frames(short addr[], short send_number, bool p_f,
|
||||||
|
short receive_number, short data[], int start, int end, Frame *frames);/* Using $start,$end, better than $size*/
|
||||||
|
|
||||||
|
/*Extract frame type from the given frame. */
|
||||||
|
enum FRAME_TYPE get_frame_type(Frame *p_frame);
|
||||||
|
|
||||||
|
|
||||||
|
/* Extract address field from the given frame.*/
|
||||||
|
void get_address(Frame *p_frame, short *storage);
|
||||||
|
|
||||||
|
/* The # of the frame.*/
|
||||||
|
short get_send_number(Frame *p_frame);
|
||||||
|
|
||||||
|
/* The # of the frame sender wants.*/
|
||||||
|
short get_expect_number(Frame *p_frame);
|
||||||
|
|
||||||
|
/* Extract the real data from the given frame.*/
|
||||||
|
void get_infor(Frame *p_frame, short *storage, int *size);
|
||||||
|
|
||||||
|
|
||||||
|
/*Here using fcs to judge whether the data is right.*/
|
||||||
|
bool is_fcs_right(Frame *p_frame);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include "config.h"
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
#include "uart_hal.h"
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
//example
|
|
||||||
uint8_t data = 'A';
|
|
||||||
|
|
||||||
uart_init(9600,0);
|
|
||||||
uart_send_byte(data);
|
|
||||||
sei();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
if(uart_read_count() > 0){
|
|
||||||
data = uart_read();
|
|
||||||
uart_send_byte(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#include "uart_hal.h"
|
|
||||||
|
|
||||||
volatile static uint8_t rx_buffer[RX_BUFFER_SIZE] = {0};
|
|
||||||
volatile static uint16_t rx_count = 0;
|
|
||||||
volatile static uint8_t uart_tx_busy = 1;
|
|
||||||
// кольцевой буффер
|
|
||||||
ISR(USART_RX_vect){
|
|
||||||
|
|
||||||
volatile static uint16_t rx_write_pos = 0;
|
|
||||||
|
|
||||||
rx_buffer[rx_write_pos] = UDR0;
|
|
||||||
rx_count++;
|
|
||||||
rx_write_pos++;
|
|
||||||
if(rx_write_pos >= RX_BUFFER_SIZE){
|
|
||||||
rx_write_pos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ISR(USART_TX_vect){
|
|
||||||
uart_tx_busy = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void uart_init(uint32_t baud,uint8_t high_speed){
|
|
||||||
|
|
||||||
uint8_t speed = 16;
|
|
||||||
|
|
||||||
if(high_speed != 0){
|
|
||||||
speed = 8;
|
|
||||||
UCSR0A |= 1 << U2X0;
|
|
||||||
}
|
|
||||||
|
|
||||||
baud = (F_CPU/(speed*baud)) - 1;
|
|
||||||
|
|
||||||
UBRR0H = (baud & 0x0F00) >> 8;
|
|
||||||
UBRR0L = (baud & 0x00FF);
|
|
||||||
|
|
||||||
UCSR0B |= (1 << TXEN0) | (1 << RXEN0) | (1 << TXCIE0) | (1 << RXCIE0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void uart_send_byte(uint8_t c){
|
|
||||||
while(uart_tx_busy == 0);
|
|
||||||
uart_tx_busy = 0;
|
|
||||||
UDR0 = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void uart_send_array(uint8_t *c,uint16_t len){
|
|
||||||
for(uint16_t i = 0; i < len;i++){
|
|
||||||
uart_send_byte(c[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void uart_send_string(uint8_t *c){
|
|
||||||
uint16_t i = 0;
|
|
||||||
do{
|
|
||||||
uart_send_byte(c[i]);
|
|
||||||
i++;
|
|
||||||
|
|
||||||
}while(c[i] != '\0');
|
|
||||||
uart_send_byte(c[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t uart_read_count(void){
|
|
||||||
return rx_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t uart_read(void){
|
|
||||||
static uint16_t rx_read_pos = 0;
|
|
||||||
uint8_t data = 0;
|
|
||||||
|
|
||||||
data = rx_buffer[rx_read_pos];
|
|
||||||
rx_read_pos++;
|
|
||||||
rx_count--;
|
|
||||||
if(rx_read_pos >= RX_BUFFER_SIZE){
|
|
||||||
rx_read_pos = 0;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#ifndef UART_HAL_H_
|
|
||||||
#define UART_HAL_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "config.h"
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
|
|
||||||
#define RX_BUFFER_SIZE 128
|
|
||||||
|
|
||||||
void uart_init(uint32_t baud,uint8_t high_speed);
|
|
||||||
void uart_send_byte(uint8_t c);
|
|
||||||
void uart_send_array(uint8_t *c,uint16_t len);
|
|
||||||
void uart_send_string(uint8_t *c);
|
|
||||||
uint16_t uart_read_count(void);
|
|
||||||
uint8_t uart_read(void);
|
|
||||||
|
|
||||||
#endif /* UART_HAL_H_ */
|
|
||||||
Reference in New Issue
Block a user