-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_tx.h
More file actions
133 lines (114 loc) · 2.96 KB
/
example_tx.h
File metadata and controls
133 lines (114 loc) · 2.96 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* tx_example.h
*
* Created on: Jan 14, 2019
* Author: razvanm
*/
#ifndef EXAMPLE_TX_H_
#define EXAMPLE_TX_H_
#include <stdint.h>
#include <stdarg.h>
#include <driverlib/ioc.h>
#include <driverlib/systick.h>
#include <driverlib/gpio.h>
#include <driverlib/uart.h>
#include <driverlib/aon_batmon.h>
#include <radio/radio.h>
#include "board.h"
uint8_t g_printf_buffer[128] = {0};
void simple_itoa(int32_t nr, char* buff, uint8_t base){
static char values[] = "0123456789ABCDEF";
char *tmp_buff = buff;
if (base < 2 || base > 16)
return;
if (nr < 0){
*tmp_buff++ = '-';
nr *= -1;
}else if (nr == 0){
*tmp_buff++ = '0';
return;
}
int8_t digits = 0;
int32_t magnitude = 1;
while(magnitude < nr){
digits++;
magnitude *= base;
}
if (magnitude == nr){
digits++;
}
tmp_buff += digits;
*tmp_buff-- = 0;// End the number here
while(digits-- > 0){
*tmp_buff-- = values[(uint8_t)(nr % base)];
nr /= base;
}
}
int32_t simple_sprintf(char* buff, char* fmt, ...){
char* buffIdx = buff;
char ch;
va_list args;
va_start(args, fmt);
while ((ch = (*fmt++))){
if (ch != '%'){
*buffIdx++ = ch;
continue;
}
ch = *fmt++;
switch(ch){
case 'c':{
int32_t tmpChar = va_arg(args, int);
*buffIdx++ = (char)tmpChar;
break;
}
case 's':{
char* tmpStr = va_arg(args, char *);
while(*tmpStr){
*buffIdx++ = *tmpStr++;
}
break;
}
case 'd':{
int32_t tmpInt = va_arg(args, int);
simple_itoa(tmpInt, buffIdx, 10);
buffIdx += strlen(buffIdx);
break;
}
case 'x':
case 'X':{
int32_t tmpHexInt = va_arg(args, int);
simple_itoa(tmpHexInt, buffIdx, 16);
buffIdx += strlen(buffIdx);
break;
}
default:{
*buffIdx++ = ch;
break;
}
}
}
*buffIdx = '\0';
va_end(args);
return strlen(buff);
}
volatile uint32_t g_total_ticks = 0;
void SysTickIntHandler(){
g_total_ticks++;
}
void example_handler(){
AONBatMonEnable();
SysTickEnable();
SysTickPeriodSet(48000);
SysTickIntEnable();
IOCPinTypeGpioOutput(LED_GREEN);
uint32_t lastTick = g_total_ticks;
while(true){
if (g_total_ticks - lastTick > 999){
uint8_t totalChars = simple_sprintf((char*)&g_printf_buffer[0], "Total Ticks : %d. Temp : %d Deg C.", g_total_ticks, AONBatMonTemperatureGetDegC());
PHY_send(&g_printf_buffer[0], totalChars);
GPIO_toggleDio(LED_GREEN);
lastTick = g_total_ticks;
}
}
}
#endif /* EXAMPLE_TX_H_ */