]> cloudbase.mooo.com Git - irmp.git/blame - irmpextlog.c
Version 2.5.7: some corrections for PIC XC8 compiler
[irmp.git] / irmpextlog.c
CommitLineData
6c3c57e6 1/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
2 * irmpextlog.c - external logging\r
3 *\r
cb93f9e9 4 * $Id: irmpextlog.c,v 1.4 2014/02/19 12:57:36 fm Exp $\r
6c3c57e6 5 *\r
6 * If you cannot use the internal UART logging routine, adapt the\r
7 * source below for your application. The following implementation\r
8 * is an example for a PIC 18F2550 with USB interface.\r
9 *\r
10 * This program is free software; you can redistribute it and/or modify\r
11 * it under the terms of the GNU General Public License as published by\r
12 * the Free Software Foundation; either version 2 of the License, or\r
13 * (at your option) any later version.\r
14 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
15 */\r
acd29fb9 16#include "irmp.h"\r
6c3c57e6 17\r
18#if IRMP_EXT_LOGGING == 1\r
19\r
20#include "irmpextlog.h"\r
21#include "system/usb/usb.h"\r
22\r
23#define bit_set(var,bitnr) ((var) |= 1 << (bitnr)) // set single bit in byte\r
24#define loglen 50 // byte length for saving the data from irmp.c\r
25 // check your USB settings for max length of USB interface used for this FW!\r
26static unsigned char logdata[loglen]; // array for saveing the data from irmp.c\r
27static unsigned char logindex = 3; // start index of logdata\r
28static char bitindex = 7; // bit position in current byte\r
29static unsigned int bitcount;\r
30\r
31/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
32 * Initialize external logging\r
33 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
34 */\r
35void\r
36initextlog (void) // reset all data to default, only during init\r
37{\r
38 unsigned char i;\r
39 \r
40 for (i = 0; i < loglen; i++)\r
41 {\r
42 logdata[i] = 0;\r
43 }\r
44\r
45 bitcount = 0;\r
46 logindex = 3;\r
47 bitindex = 7;\r
48}\r
49\r
50/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
51 * Send logging data via device (e.g. USB on PIC)\r
52 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
53 */\r
54void\r
55sendextlog (unsigned char data)\r
56{\r
57 if (logindex == loglen || data == '\n') // buffer full or \n --> send to application\r
58 {\r
59 if (mUSBUSARTIsTxTrfReady()) // check USB, if ready send\r
60 {\r
61 logdata[0] = 0x01; // indicator for logging, depends on your application\r
62 logdata[1] = logindex; // save how much bytes are send from irmp.c\r
63 logdata[2] = 0; // set \n Index to 0; 0=buffer full; 0xA=\n received\r
64\r
65 if (data == '\n')\r
66 {\r
67 logdata[2] = data; // \n --> save \n=0xA in to check in app that \n was received\r
68 }\r
69\r
70 mUSBUSARTTxRam((unsigned char *) &logdata, loglen); // send all Data to main Seoftware\r
71 \r
72 logindex = 3; // reset index\r
73 bitindex = 7; // reset bit position\r
74 logdata[logindex] = 0; // reset value of new logindex to 0\r
75 }\r
76 }\r
77 else\r
78 {\r
79 bitcount++;\r
80\r
81 if (data == '1')\r
82 {\r
83 bit_set(logdata[logindex], bitindex); // all logdata[logindex] on start = 0 --> only 1 must be set\r
84 }\r
85\r
86 bitindex--; // decrease bitposition, wirte from left to right\r
87\r
88 if (bitindex == -1) // byte complete Bit 7->0 --> next one\r
89 {\r
90 bitindex = 7;\r
91 logindex++;\r
92\r
93 if (logindex < loglen)\r
94 {\r
95 logdata[logindex] = 0; // set next byte to 0\r
96 }\r
97 }\r
98 }\r
99}\r
100\r
101#endif //IRMP_EXT_LOGGING\r
1170a986 102\r
cb93f9e9 103#if defined(PIC_C18)\r
1170a986 104static void\r
105dummy (void)\r
106{\r
107 // Only to avoid C18 compiler error\r
108}\r
cb93f9e9 109#endif\r