t

Dependencies:   DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos

Fork of DMSupport by Embedded Artists

Revision:
2:887c6b45e7fa
Child:
9:a33326afd686
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RtosLog.h	Tue Dec 02 15:21:18 2014 +0000
@@ -0,0 +1,64 @@
+/*
+ *  Copyright 2014 Embedded Artists AB
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#ifndef RTOSLOG_H
+#define RTOSLOG_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "dm_board_config.h"
+
+/**
+ * All threads can independantly call the printf function in the RtosLog class
+ * without risc of getting the output tangled up.
+ *
+ * The RtosLog class uses a Thread to process the messages one at a time.
+ */
+class RtosLog {
+public:
+    enum Constants {
+        MessageLen  = 80,
+        NumMessages =  16,
+    };
+  
+    RtosLog();
+    ~RtosLog();
+    
+    /** Starts the logger thread
+     */
+    void init();
+    
+    int printf(const char* format, ...);
+  
+private:
+    
+    typedef struct {
+        char*  ptr;                 /* Non-NULL if memory is allocated */
+        char   msg[MessageLen+1];   /* A counter value                 */
+    } message_t;
+ 
+    MemoryPool<message_t, NumMessages> _mpool;
+    Queue<message_t, NumMessages> _queue;
+    Semaphore _sem;
+    Serial _serial;
+    Thread* _thr;
+    
+    static void logTask(void const* args);
+};
+
+#endif
+
+