summaryrefslogtreecommitdiff
path: root/irmpextlog.c
diff options
context:
space:
mode:
authorukw2012-02-16 10:43:15 +0000
committerukw2012-02-16 10:43:15 +0000
commit6c3c57e6ed1d614a5ffec4747e271eb9e7aa8a68 (patch)
tree432a7d0236ba648cb43e5eda01da0890c80bccfd /irmpextlog.c
parent6ab7d63ce8432cc5a6fb9fe36d86fb1f01ffeccc (diff)
downloadirmp-6c3c57e6ed1d614a5ffec4747e271eb9e7aa8a68.zip
Version 2.1.0: port to PIC C18 compiler, added external logging
git-svn-id: svn://mikrocontroller.net/irmp@87 aeb2e35e-bfc4-4214-b83c-9e8de998ed28
Diffstat (limited to 'irmpextlog.c')
-rw-r--r--irmpextlog.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/irmpextlog.c b/irmpextlog.c
new file mode 100644
index 0000000..78537e9
--- /dev/null
+++ b/irmpextlog.c
@@ -0,0 +1,101 @@
+/*---------------------------------------------------------------------------------------------------------------------------------------------------
+ * irmpextlog.c - external logging
+ *
+ * $Id: irmpextlog.c,v 1.1 2012/02/16 10:40:08 fm Exp $
+ *
+ * If you cannot use the internal UART logging routine, adapt the
+ * source below for your application. The following implementation
+ * is an example for a PIC 18F2550 with USB interface.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *---------------------------------------------------------------------------------------------------------------------------------------------------
+ */
+#include "irmpconfig.h"
+
+#if IRMP_EXT_LOGGING == 1
+
+#include "irmpextlog.h"
+#include "system/usb/usb.h"
+
+#define bit_set(var,bitnr) ((var) |= 1 << (bitnr)) // set single bit in byte
+#define loglen 50 // byte length for saving the data from irmp.c
+ // check your USB settings for max length of USB interface used for this FW!
+static unsigned char logdata[loglen]; // array for saveing the data from irmp.c
+static unsigned char logindex = 3; // start index of logdata
+static char bitindex = 7; // bit position in current byte
+static unsigned int bitcount;
+
+/*---------------------------------------------------------------------------------------------------------------------------------------------------
+ * Initialize external logging
+ *---------------------------------------------------------------------------------------------------------------------------------------------------
+ */
+void
+initextlog (void) // reset all data to default, only during init
+{
+ unsigned char i;
+
+ for (i = 0; i < loglen; i++)
+ {
+ logdata[i] = 0;
+ }
+
+ bitcount = 0;
+ logindex = 3;
+ bitindex = 7;
+}
+
+/*---------------------------------------------------------------------------------------------------------------------------------------------------
+ * Send logging data via device (e.g. USB on PIC)
+ *---------------------------------------------------------------------------------------------------------------------------------------------------
+ */
+void
+sendextlog (unsigned char data)
+{
+ if (logindex == loglen || data == '\n') // buffer full or \n --> send to application
+ {
+ if (mUSBUSARTIsTxTrfReady()) // check USB, if ready send
+ {
+ logdata[0] = 0x01; // indicator for logging, depends on your application
+ logdata[1] = logindex; // save how much bytes are send from irmp.c
+ logdata[2] = 0; // set \n Index to 0; 0=buffer full; 0xA=\n received
+
+ if (data == '\n')
+ {
+ logdata[2] = data; // \n --> save \n=0xA in to check in app that \n was received
+ }
+
+ mUSBUSARTTxRam((unsigned char *) &logdata, loglen); // send all Data to main Seoftware
+
+ logindex = 3; // reset index
+ bitindex = 7; // reset bit position
+ logdata[logindex] = 0; // reset value of new logindex to 0
+ }
+ }
+ else
+ {
+ bitcount++;
+
+ if (data == '1')
+ {
+ bit_set(logdata[logindex], bitindex); // all logdata[logindex] on start = 0 --> only 1 must be set
+ }
+
+ bitindex--; // decrease bitposition, wirte from left to right
+
+ if (bitindex == -1) // byte complete Bit 7->0 --> next one
+ {
+ bitindex = 7;
+ logindex++;
+
+ if (logindex < loglen)
+ {
+ logdata[logindex] = 0; // set next byte to 0
+ }
+ }
+ }
+}
+
+#endif //IRMP_EXT_LOGGING