Jarda Pajskr / freemaster_lib

Dependents:   FreeMASTER_HelloWorld FreeMASTER_HelloWorld2 FreeMASTER_HelloWorld3

Fork of freemaster_lib by Jarda Pajskr

Revision:
0:fb135bf60f82
Child:
8:17470feaa6be
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/class/freemaster_class.cpp	Mon May 05 20:13:09 2014 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+
+#include "freemaster_class.h"
+
+#if DEVICE_SERIAL
+#define FMSTR_USE_TSA_DYNAMIC 1
+#define FMSTR_REC_OWNBUFF 1
+namespace mbed {
+Freemaster::Freemaster(PinName tx, PinName rx, uint32_t tsaMembers, uint32_t recBufferSize, uint32_t flags) {
+    serial_init(&_serial, tx, rx);
+    _baud = 9600;
+    serial_irq_handler(&_serial, Freemaster::_irq_handler, (uint32_t)this);
+    FMSTR_InitSerialBase((FMSTR_BPTR)&_serial.uart->BDH);
+    FMSTR_Init();
+#if !(FMSTR_POLL_DRIVEN)
+    serial_irq_set(&_serial, RxIrq, 1);
+    serial_irq_set(&_serial, TxIrq, 1);
+#endif
+#if (FMSTR_USE_TSA_DYNAMIC)
+    tsaTable=malloc(tsaMembers*sizeof(FMSTR_TSA_ENTRY)); 
+    FMSTR_SetUpTsaBuff((FMSTR_ADDR)tsaTable, (tsaMembers)*sizeof(FMSTR_TSA_ENTRY));
+#endif
+
+#if (FMSTR_REC_OWNBUFF)
+    recBuf=malloc(recBufferSize); 
+    FMSTR_SetUpRecBuff((FMSTR_ADDR)recBuf, recBufferSize);
+#endif
+}
+
+FMSTR_BOOL Freemaster::TsaAddVar(FMSTR_TSATBL_STRPTR name, FMSTR_TSATBL_STRPTR type, FMSTR_TSATBL_VOIDPTR addr, FMSTR_TSATBL_VOIDPTR info) {
+#if FMSTR_USE_TSA_DYNAMIC
+    return FMSTR_TsaAddVar(name, type, addr, info);
+#else
+    return FMSTR_FALSE;
+#endif
+}
+
+void Freemaster::baud(int baudrate) {
+    serial_baud(&_serial, baudrate);
+    _baud = baudrate;
+}
+
+void Freemaster::Recorder() {
+    FMSTR_Recorder();
+}
+
+void Freemaster::Poll() {
+    FMSTR_Poll();
+}
+
+void Freemaster::_irq_handler(uint32_t id, SerialIrq irq_type) {
+    FMSTR_Isr();
+}
+
+} // namespace mbed
+
+#endif