Nico Bollen / LIN

Dependents:   MBED_LIN_RGB_Master_Example

LinMaster.h

Committer:
bollenn
Date:
2014-05-06
Revision:
1:58b5d1e8fae3
Parent:
0:c91a9ebab739
Child:
2:6d4c7f841a5d

File content as of revision 1:58b5d1e8fae3:

/*
 * A master device LIN communication library for mbed
 * 
 * Copyright (C) 2014 TASS Belgium NV
 * 
 * Released under GPL v2
 *
 * Other licensing models might apply at the sole discretion of the copyright holders.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
#include "mbed.h"

#ifndef MBED_LIN_MASTER_H
#define MBED_LIN_MASTER_H

#include "mbed.h"

/**  A master device LIN communication library for mbed
 *
 * @code
 * #include "mbed.h"
 * #include "LinMaster.h"
 * 
 * LinMaster lin(p30);
 * 
 * int main() {
 *     (void)lin.init();
 *     (void)lin.sendframe(M2S, 0x3C, (uint8_t*)u8Data, 8);
 * }
 * @endcode
 */
class LinMaster
{
public:
    /** LIN master constructor
     *
     * @param Pin The pinname to be used for LIN communication
     */
    LinMaster(PinName Pin);

    /** LIN master destructor */
    ~LinMaster();

    /** Initialise the LIN module
     * - configure IO
     * - configure Timer
     *
     * @return
     *   true on succes,
     *   false on fail
     */
    bool Init(void);

    /** Set the LIN baudrate
     *
     * @param uBaud baudrate value in kbps (1..20000)
     * @return
     *   true on succes,
     *   false on fail
     */
    bool Baudrate(uint16_t uBaud);

    /** Get the LIN baudrate
     *
     * @return
     *   The current configured LIN baudrate
     */
    uint16_t Baudrate(void);
    
    /** Send frame direction */
    enum FrameDir {
        M2S,     /**< Master to Slave */
        S2M      /**< Slave to Master */
    };
    
    /** Send a frame on the LIN bus
     *
     * @param Dir direction of the frame
     * @param u8ID LIN Frame ID
     * @param ptrData pointer to the data to be transmitted/received
     * @param u8Len lenght of the data to be transmitted/received
     * @return
     *   true on succes,
     *   false on fail
     */
    bool SendFrame(FrameDir Dir, uint8_t u8ID, uint8_t* ptrData, uint8_t u8Len);

private:
    uint16_t u16BitPeriod;
    uint8_t u8BreakLen;
    uint8_t u8DelimLen;
    PinName MyPin;
};

#endif /* MBED_LIN_MASTER_H */