t
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos
Fork of DMSupport by
RtosLog.h@2:887c6b45e7fa, 2014-12-02 (annotated)
- Committer:
- embeddedartists
- Date:
- Tue Dec 02 15:21:18 2014 +0000
- Revision:
- 2:887c6b45e7fa
- Child:
- 9:a33326afd686
Added RTOS-safe logger (RtosLog). Switched USBHost library so that it works in an RTOS setting. Modified the FAT file system to work in an RTOS setting.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 2:887c6b45e7fa | 1 | /* |
embeddedartists | 2:887c6b45e7fa | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 2:887c6b45e7fa | 3 | * |
embeddedartists | 2:887c6b45e7fa | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 2:887c6b45e7fa | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 2:887c6b45e7fa | 6 | * You may obtain a copy of the License at |
embeddedartists | 2:887c6b45e7fa | 7 | * |
embeddedartists | 2:887c6b45e7fa | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 2:887c6b45e7fa | 9 | * |
embeddedartists | 2:887c6b45e7fa | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 2:887c6b45e7fa | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 2:887c6b45e7fa | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 2:887c6b45e7fa | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 2:887c6b45e7fa | 14 | * limitations under the License. |
embeddedartists | 2:887c6b45e7fa | 15 | */ |
embeddedartists | 2:887c6b45e7fa | 16 | |
embeddedartists | 2:887c6b45e7fa | 17 | #ifndef RTOSLOG_H |
embeddedartists | 2:887c6b45e7fa | 18 | #define RTOSLOG_H |
embeddedartists | 2:887c6b45e7fa | 19 | |
embeddedartists | 2:887c6b45e7fa | 20 | #include "mbed.h" |
embeddedartists | 2:887c6b45e7fa | 21 | #include "rtos.h" |
embeddedartists | 2:887c6b45e7fa | 22 | #include "dm_board_config.h" |
embeddedartists | 2:887c6b45e7fa | 23 | |
embeddedartists | 2:887c6b45e7fa | 24 | /** |
embeddedartists | 2:887c6b45e7fa | 25 | * All threads can independantly call the printf function in the RtosLog class |
embeddedartists | 2:887c6b45e7fa | 26 | * without risc of getting the output tangled up. |
embeddedartists | 2:887c6b45e7fa | 27 | * |
embeddedartists | 2:887c6b45e7fa | 28 | * The RtosLog class uses a Thread to process the messages one at a time. |
embeddedartists | 2:887c6b45e7fa | 29 | */ |
embeddedartists | 2:887c6b45e7fa | 30 | class RtosLog { |
embeddedartists | 2:887c6b45e7fa | 31 | public: |
embeddedartists | 2:887c6b45e7fa | 32 | enum Constants { |
embeddedartists | 2:887c6b45e7fa | 33 | MessageLen = 80, |
embeddedartists | 2:887c6b45e7fa | 34 | NumMessages = 16, |
embeddedartists | 2:887c6b45e7fa | 35 | }; |
embeddedartists | 2:887c6b45e7fa | 36 | |
embeddedartists | 2:887c6b45e7fa | 37 | RtosLog(); |
embeddedartists | 2:887c6b45e7fa | 38 | ~RtosLog(); |
embeddedartists | 2:887c6b45e7fa | 39 | |
embeddedartists | 2:887c6b45e7fa | 40 | /** Starts the logger thread |
embeddedartists | 2:887c6b45e7fa | 41 | */ |
embeddedartists | 2:887c6b45e7fa | 42 | void init(); |
embeddedartists | 2:887c6b45e7fa | 43 | |
embeddedartists | 2:887c6b45e7fa | 44 | int printf(const char* format, ...); |
embeddedartists | 2:887c6b45e7fa | 45 | |
embeddedartists | 2:887c6b45e7fa | 46 | private: |
embeddedartists | 2:887c6b45e7fa | 47 | |
embeddedartists | 2:887c6b45e7fa | 48 | typedef struct { |
embeddedartists | 2:887c6b45e7fa | 49 | char* ptr; /* Non-NULL if memory is allocated */ |
embeddedartists | 2:887c6b45e7fa | 50 | char msg[MessageLen+1]; /* A counter value */ |
embeddedartists | 2:887c6b45e7fa | 51 | } message_t; |
embeddedartists | 2:887c6b45e7fa | 52 | |
embeddedartists | 2:887c6b45e7fa | 53 | MemoryPool<message_t, NumMessages> _mpool; |
embeddedartists | 2:887c6b45e7fa | 54 | Queue<message_t, NumMessages> _queue; |
embeddedartists | 2:887c6b45e7fa | 55 | Semaphore _sem; |
embeddedartists | 2:887c6b45e7fa | 56 | Serial _serial; |
embeddedartists | 2:887c6b45e7fa | 57 | Thread* _thr; |
embeddedartists | 2:887c6b45e7fa | 58 | |
embeddedartists | 2:887c6b45e7fa | 59 | static void logTask(void const* args); |
embeddedartists | 2:887c6b45e7fa | 60 | }; |
embeddedartists | 2:887c6b45e7fa | 61 | |
embeddedartists | 2:887c6b45e7fa | 62 | #endif |
embeddedartists | 2:887c6b45e7fa | 63 | |
embeddedartists | 2:887c6b45e7fa | 64 |