Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MBED_LIN_RGB_Master_Example
Diff: LinMaster.h
- Revision:
- 3:3656b0de0e43
- Parent:
- 2:6d4c7f841a5d
- Child:
- 4:41b153e9a39c
--- a/LinMaster.h Sun May 11 13:14:16 2014 +0000
+++ b/LinMaster.h Tue May 26 08:33:46 2015 +0000
@@ -28,8 +28,6 @@
#ifndef MBED_LIN_MASTER_H
#define MBED_LIN_MASTER_H
-#include "mbed.h"
-
/** A master device LIN communication library for mbed
*
* @code
@@ -51,7 +49,7 @@
*
* @param Pin The pinname to be used for LIN communication
*/
- LinMaster(PinName Pin);
+ LinMaster(PinName InPin, PinName OutPin);
/** LIN master destructor */
~LinMaster();
@@ -64,7 +62,7 @@
* true on succes,
* false on fail
*/
- bool Init(void);
+ bool init(void);
/** Set the LIN baudrate
*
@@ -73,22 +71,24 @@
* true on succes,
* false on fail
*/
- bool Baudrate(uint16_t uBaud);
+ bool baudrate(uint16_t uBaud);
/** Get the LIN baudrate
*
* @return
* The current configured LIN baudrate
*/
- uint16_t Baudrate(void);
+ uint16_t baudrate(void);
/** Bus status */
- enum DriverStatus {
- INIT, /**< initializing */
- IDLE, /**< idle */
- WAKEUP, /**< busy sending a wake up pulse */
- TRANSMIT, /**< busy sending a frame */
- RECEIVE /**< busy receiving data */
+ enum DriverStatus_t {
+ INIT, /**< initializing */
+ IDLE, /**< idle */
+ RXWAKEUP, /**< wake up pulses detected since the last request */
+ DOMINANT, /**< dominant level detected, longer than a wake up pulse */
+ TRANSMIT, /**< busy receiving data */
+ RECEIVE, /**< busy receiving data */
+ TXWAKEUP /**< busy sending a wake up pulse */
};
/** Get the current LIN driver status
@@ -96,61 +96,132 @@
* @return
* The current LIN driver status
*/
- DriverStatus GetDriverStatus(void) {return ( DriverStat );};
-
- /** Frame status */
- enum FrameStatus {
- READY, /**< the frame is ready */
- BREAK, /**< break is being sent */
- DELIMITER, /**< delimiter is being sent */
- SYNC, /**< sync field is being sent */
- ID, /**< Frame ID byte is being sent */
- DATA /**< Data bytes are being sent */
+ DriverStatus_t status(void) {return ( DriverState );};
+
+ /** Frame Direction Type */
+ enum FrameType_t {
+ S2M,
+ M2S
+ };
+
+ /** CRC Type */
+ enum CrcType_t {
+ Classic,
+ Enhanced
};
- /** Get the current frame status
- *
- * @return
- * The current frame status
- */
- FrameStatus GetFrameStatus(void) {return ( FrameStat );};
+ /** Brake Type */
+ enum BrakeType_t {
+ Normal,
+ AutoConfig
+ };
- /** Send frame direction */
- enum FrameDir {
- M2S, /**< Master to Slave */
- S2M /**< Slave to Master */
+ /** Frame */
+ struct Frame_t {
+ FrameType_t FrameType;
+ CrcType_t CrcType;
+ BrakeType_t Brake;
+ uint8_t DataLen;
+ uint8_t FrameID;
+ uint8_t Data[8];
};
/** 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
+ * @param ptrFrame pointer to the frame to transmit
+ * @return
+ * true on succes,
+ * false on fail
+ */
+ bool tx_frame(Frame_t * ptrFrame);
+
+ /** Receive a frame on the LIN bus
+ *
+ * @param ptrFrame pointer to the frame to receive
* @return
* true on succes,
* false on fail
*/
- bool SendFrame(FrameDir Dir, uint8_t u8ID, uint8_t* ptrData, uint8_t u8Len);
+ bool rx_frame(Frame_t * ptrFrame);
void TickEventHndl(void);
+ void PinEventHndl(void);
+
private:
- DriverStatus DriverStat;
- FrameStatus FrameStat;
- uint16_t u16BitPeriod;
- uint8_t u8BreakLen;
- uint8_t u8DelimLen;
- uint8_t u8TickCnt;
- uint8_t u8NextBusLvl;
- uint8_t u8FrameID;
- FrameDir Direction;
- uint8_t u8FrameData[8];
- uint8_t u8FrameLen;
- uint8_t u8Byte;
- uint8_t u8ByteOnLin;
- PinName MyPin;
- Ticker MyTicker;
+ enum FrameError_t {
+ NoError, /* No error */
+ NoSlaveResp, /* No slave response, LIN message has timed out */
+ FramingErr, /* Framing error */
+ CollisionErr, /* Collision error */
+ BusVoltage /* Bus voltage to low */
+ };
+
+ enum FrameStatus_t {
+ FStart,
+ Break_OK,
+ Sync_OK,
+ ID_OK,
+ Data0,
+ Data1,
+ Data2,
+ Data3,
+ Data4,
+ Data5,
+ Data6,
+ Data7,
+ CRC
+ };
+
+ enum ByteStatus_t {
+ BStart,
+ StartbitEdge, /* Begin of startbit received */
+ StartbitSample, /* Startbit sample */
+ Databit0Edge, /* Databit edge */
+ Databit0Sample, /* Databit sample */
+ Databit1Edge, /* Databit edge */
+ Databit1Sample, /* Databit sample */
+ Databit2Edge, /* Databit edge */
+ Databit2Sample, /* Databit sample */
+ Databit3Edge, /* Databit edge */
+ Databit3Sample, /* Databit sample */
+ Databit4Edge, /* Databit edge */
+ Databit4Sample, /* Databit sample */
+ Databit5Edge, /* Databit edge */
+ Databit5Sample, /* Databit sample */
+ Databit6Edge, /* Databit edge */
+ Databit6Sample, /* Databit sample */
+ Databit7Edge, /* Databit edge */
+ Databit7Sample, /* Databit sample */
+ StopbitEdge, /* Stopbit edge */
+ StopbitSample, /* Stopbit sample */
+ BDone
+ };
+
+ volatile DriverStatus_t DriverState;
+ volatile FrameError_t LastError;
+ volatile FrameStatus_t FrameStatus;
+ volatile ByteStatus_t ByteStatus;
+ volatile FrameType_t linMessageType;
+
+ uint8_t breakLength;
+ uint8_t FrameLength;
+
+ uint8_t TXbuf[11];
+ uint8_t TXbufIndex;
+ uint8_t RXbuf[11];
+ uint8_t RXbufIndex;
+ uint8_t RXtimeout;
+ uint16_t RXtimeoutSubCTR;
+ uint16_t u16HalfBitPeriod;
+
+ PinName MyInPin;
+ PinName MyOutPin;
+ Ticker MyTicker;
+ Timer MyTimer;
+
+ uint8_t parity(uint8_t u8BYTE);
+
};
#endif /* MBED_LIN_MASTER_H */