t
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos
Fork of DMSupport by
RtosLog.h
- Committer:
- embeddedartists
- Date:
- 2014-12-02
- Revision:
- 2:887c6b45e7fa
- Child:
- 9:a33326afd686
File content as of revision 2:887c6b45e7fa:
/* * 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