
A board support package for the LPC4088 Display Module.
Dependencies: DM_HttpServer DM_USBHost
Dependents: lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more
Fork of DMSupport by
RtosLog.h@39:e1cb4dd9bfeb, 2015-04-28 (annotated)
- Committer:
- alindvall
- Date:
- Tue Apr 28 11:47:20 2015 +0000
- Revision:
- 39:e1cb4dd9bfeb
- Parent:
- 34:fc366bab393f
Added display frame rate setting. Updated used libraries.
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 | 34:fc366bab393f | 24 | #if defined(DM_BOARD_USE_USBSERIAL_IN_RTOSLOG) |
embeddedartists | 34:fc366bab393f | 25 | #include "USBSerial.h" |
embeddedartists | 34:fc366bab393f | 26 | #endif |
embeddedartists | 34:fc366bab393f | 27 | |
embeddedartists | 2:887c6b45e7fa | 28 | /** |
embeddedartists | 2:887c6b45e7fa | 29 | * All threads can independantly call the printf function in the RtosLog class |
embeddedartists | 9:a33326afd686 | 30 | * without risk of getting the output tangled up. |
embeddedartists | 2:887c6b45e7fa | 31 | * |
embeddedartists | 2:887c6b45e7fa | 32 | * The RtosLog class uses a Thread to process the messages one at a time. |
embeddedartists | 9:a33326afd686 | 33 | * |
embeddedartists | 9:a33326afd686 | 34 | * |
embeddedartists | 9:a33326afd686 | 35 | * Example of using the RtosLog class: |
embeddedartists | 9:a33326afd686 | 36 | * |
embeddedartists | 9:a33326afd686 | 37 | * @code |
embeddedartists | 9:a33326afd686 | 38 | * #include "mbed.h" |
embeddedartists | 9:a33326afd686 | 39 | * #include "DMBoard.h" |
embeddedartists | 9:a33326afd686 | 40 | * |
embeddedartists | 9:a33326afd686 | 41 | * void myTask(void const*args) { |
embeddedartists | 9:a33326afd686 | 42 | * RtosLog* log = DMBoard::instance().logger(); |
embeddedartists | 9:a33326afd686 | 43 | * ... |
embeddedartists | 9:a33326afd686 | 44 | * log->printf("Hello world!\n"); |
embeddedartists | 9:a33326afd686 | 45 | * ... |
embeddedartists | 9:a33326afd686 | 46 | * } |
embeddedartists | 9:a33326afd686 | 47 | * @endcode |
embeddedartists | 9:a33326afd686 | 48 | * |
embeddedartists | 2:887c6b45e7fa | 49 | */ |
embeddedartists | 2:887c6b45e7fa | 50 | class RtosLog { |
embeddedartists | 2:887c6b45e7fa | 51 | public: |
embeddedartists | 2:887c6b45e7fa | 52 | enum Constants { |
embeddedartists | 2:887c6b45e7fa | 53 | MessageLen = 80, |
embeddedartists | 2:887c6b45e7fa | 54 | NumMessages = 16, |
embeddedartists | 2:887c6b45e7fa | 55 | }; |
embeddedartists | 2:887c6b45e7fa | 56 | |
embeddedartists | 2:887c6b45e7fa | 57 | RtosLog(); |
embeddedartists | 2:887c6b45e7fa | 58 | ~RtosLog(); |
embeddedartists | 2:887c6b45e7fa | 59 | |
embeddedartists | 34:fc366bab393f | 60 | /** Starts the logger thread, called from DMBoard::instance().init() |
embeddedartists | 2:887c6b45e7fa | 61 | */ |
embeddedartists | 2:887c6b45e7fa | 62 | void init(); |
embeddedartists | 2:887c6b45e7fa | 63 | |
embeddedartists | 34:fc366bab393f | 64 | /** Printf that works in an RTOS |
embeddedartists | 34:fc366bab393f | 65 | * |
embeddedartists | 34:fc366bab393f | 66 | * This function will create a string from the specified format and |
embeddedartists | 34:fc366bab393f | 67 | * optional extra arguments and put it into a message that the RtosLog |
embeddedartists | 34:fc366bab393f | 68 | * thread will write to the log. |
embeddedartists | 34:fc366bab393f | 69 | * |
embeddedartists | 34:fc366bab393f | 70 | * Note that if the underlying queue is full then this function |
embeddedartists | 34:fc366bab393f | 71 | * will block until an entry becomes available. This is required to |
embeddedartists | 34:fc366bab393f | 72 | * make sure that all printf calls actually get printed. If this happens |
embeddedartists | 34:fc366bab393f | 73 | * too often then increase the priority of the RtosLog thread or reduce |
embeddedartists | 34:fc366bab393f | 74 | * the number of printed messages. |
embeddedartists | 34:fc366bab393f | 75 | * |
embeddedartists | 34:fc366bab393f | 76 | * @param format format string |
embeddedartists | 34:fc366bab393f | 77 | * @param ... optional extra arguments |
embeddedartists | 34:fc366bab393f | 78 | */ |
embeddedartists | 2:887c6b45e7fa | 79 | int printf(const char* format, ...); |
embeddedartists | 34:fc366bab393f | 80 | |
embeddedartists | 34:fc366bab393f | 81 | /** Printf that works in an RTOS |
embeddedartists | 34:fc366bab393f | 82 | * |
embeddedartists | 34:fc366bab393f | 83 | * This function will create a string from the specified format and |
embeddedartists | 34:fc366bab393f | 84 | * optional extra arguments and put it into a message that the RtosLog |
embeddedartists | 34:fc366bab393f | 85 | * thread will write to the log. |
embeddedartists | 34:fc366bab393f | 86 | * |
embeddedartists | 34:fc366bab393f | 87 | * Note that if the underlying queue is full then this function |
embeddedartists | 34:fc366bab393f | 88 | * discards the message and returns immediately. |
embeddedartists | 34:fc366bab393f | 89 | * |
embeddedartists | 34:fc366bab393f | 90 | * @param format format string |
embeddedartists | 34:fc366bab393f | 91 | * @param ... optional extra arguments |
embeddedartists | 34:fc366bab393f | 92 | */ |
embeddedartists | 34:fc366bab393f | 93 | int isr_printf(const char* format, ...); |
embeddedartists | 2:887c6b45e7fa | 94 | |
embeddedartists | 2:887c6b45e7fa | 95 | private: |
embeddedartists | 2:887c6b45e7fa | 96 | |
embeddedartists | 2:887c6b45e7fa | 97 | typedef struct { |
embeddedartists | 2:887c6b45e7fa | 98 | char* ptr; /* Non-NULL if memory is allocated */ |
embeddedartists | 2:887c6b45e7fa | 99 | char msg[MessageLen+1]; /* A counter value */ |
embeddedartists | 2:887c6b45e7fa | 100 | } message_t; |
embeddedartists | 2:887c6b45e7fa | 101 | |
embeddedartists | 2:887c6b45e7fa | 102 | MemoryPool<message_t, NumMessages> _mpool; |
embeddedartists | 2:887c6b45e7fa | 103 | Queue<message_t, NumMessages> _queue; |
embeddedartists | 2:887c6b45e7fa | 104 | Semaphore _sem; |
embeddedartists | 34:fc366bab393f | 105 | #if defined(DM_BOARD_USE_USBSERIAL_IN_RTOSLOG) |
embeddedartists | 34:fc366bab393f | 106 | USBSerial _serial; |
embeddedartists | 34:fc366bab393f | 107 | #else |
embeddedartists | 2:887c6b45e7fa | 108 | Serial _serial; |
embeddedartists | 34:fc366bab393f | 109 | #endif |
embeddedartists | 2:887c6b45e7fa | 110 | Thread* _thr; |
embeddedartists | 2:887c6b45e7fa | 111 | |
embeddedartists | 2:887c6b45e7fa | 112 | static void logTask(void const* args); |
embeddedartists | 2:887c6b45e7fa | 113 | }; |
embeddedartists | 2:887c6b45e7fa | 114 | |
embeddedartists | 2:887c6b45e7fa | 115 | #endif |