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 EmbeddedArtists AB

RtosLog.h

Committer:
embeddedartists
Date:
2014-12-11
Revision:
9:a33326afd686
Parent:
2:887c6b45e7fa
Child:
34:fc366bab393f

File content as of revision 9:a33326afd686:

/*
 *  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 risk of getting the output tangled up.
 *
 * The RtosLog class uses a Thread to process the messages one at a time.
 *
 *
 * Example of using the RtosLog class:
 *
 * @code
 * #include "mbed.h"
 * #include "DMBoard.h"
 *
 * void myTask(void const*args) {
 *    RtosLog* log = DMBoard::instance().logger();
 *    ...
 *    log->printf("Hello world!\n");
 *    ...
 * }
 * @endcode
 *
 */
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