forked from isavitsky/433T30D-LoRa-KISS-TNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
71 lines (60 loc) · 1.13 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "config.h"
#include "util.h"
uint8_t random()
{
seed ^= seed << 13;
seed ^= seed >> 17;
seed ^= seed << 5;
return (uint8_t)(seed >> 8);
}
void eeprom_write_byte(uint8_t idx, uint8_t val)
{
if ( idx < CFG_SZ )
{
FLASH_DUKR = 0xAE;
FLASH_DUKR = 0x56;
cfg[idx] = val;
while(!FLASH_IAPSR_EOP);
FLASH_IAPSR_DUL = 0;
}
}
uint8_t assemble(uint8_t len, uint8_t id)
{
uint8_t i, idx = 0;
if ( flag.header_implicit )
idx++;
if ( flag.rf_multiframe )
idx++;
if ( flag.header_implicit )
rf_txbuf[0] = len;
if ( flag.rf_multiframe )
{
rf_txbuf[idx-1] = id;
}
for(i = idx; i < len+idx; i++)
{
rf_txbuf[i] = cbuf_pop();
}
return len+idx;
}
char cbuf_pop2(void)
{
if ( CBUF_Len(utmpbuf) < TTBL_SZ )
RTS_SET_LOW;
return CBUF_Pop(utmpbuf);
}
char cbuf_pop(void)
{
if ( CBUF_Len(urxcbuf) < TBL_SZ )
RTS_SET_LOW;
return CBUF_Pop(urxcbuf);
}
void cbuf_push(char c)
{
/* Hardware flow control */
if ( CBUF_Len(urxcbuf) >= TBH_SZ )
{
RTS_SET_HIGH;
}
CBUF_Push(urxcbuf, c);
}