LEDComm  1.0
LEDComm Driver

Generic (but slow) Serial Driver using an LED instead of TX and RX wires. More...

Functions

void ldInit (void)
 LEDComm Driver initialization. More...
 
void ldObjectInit (LEDCommDriver_t *ldp, qnotify_t inotify, qnotify_t onotify)
 Initializes a generic full duplex driver object. More...
 
void ldStart (LEDCommDriver_t *ldp, const LEDCommConfig_t *config)
 Configures and starts the driver. More...
 
void ldStop (LEDCommDriver_t *ldp)
 Stops the driver. More...
 
void ldIncomingDataI (LEDCommDriver_t *ldp, uint8_t b)
 Handles incoming data. More...
 
msg_t ldRequestDataI (LEDCommDriver_t *ldp)
 Handles outgoing data. More...
 

LEDComm status flags

#define LD_PARITY_ERROR   32
 Parity error happened. More...
 
#define LD_FRAMING_ERROR   64
 Framing error happened. More...
 
#define LD_OVERRUN_ERROR   128
 Overflow happened. More...
 
#define LD_LINK_UP   256
 Link detected. More...
 
#define LD_LINK_DOWN   512
 No link detected. More...
 

Detailed Description

Generic (but slow) Serial Driver using an LED instead of TX and RX wires.

This module implements a generic half duplex serial driver that uses an LED instead of TX and RX wires. The driver implements a SerialDriver interface and uses I/O Queues for communication. Event flags are used to notify the application about incoming data, outgoing data and other I/O events.

Precondition
In order to use the LEDComm driver the source code must be extracted in the $(CHIBIOS)/ext directory. The project Makefile must be modified by adding $(CHIBIOS)/ext/ledcomm-X.Y.Z/ledcomm.c to the CSRC variable and $(CHIBIOS)/ext/ledcomm-X.Y.Z to the INCDIR variable.

Driver State Machine

The driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).

dot_inline_dotgraph_1.png

Macro Definition Documentation

#define LD_PARITY_ERROR   32

Parity error happened.

Definition at line 54 of file ledcomm.h.

#define LD_FRAMING_ERROR   64

Framing error happened.

Definition at line 55 of file ledcomm.h.

#define LD_OVERRUN_ERROR   128

Overflow happened.

Definition at line 56 of file ledcomm.h.

Referenced by ldIncomingDataI().

#define LD_LINK_UP   256

Link detected.

Definition at line 57 of file ledcomm.h.

#define LD_LINK_DOWN   512

No link detected.

Definition at line 58 of file ledcomm.h.

Function Documentation

void ldInit ( void  )

LEDComm Driver initialization.

Note
This function is NOT implicitly invoked by halInit(), you must explicitly initialize the driver.
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 296 of file ledcomm.c.

References ldObjectInit().

Here is the call graph for this function:

void ldObjectInit ( LEDCommDriver_t ldp,
qnotify_t  inotify,
qnotify_t  onotify 
)

Initializes a generic full duplex driver object.

The HW dependent part of the initialization has to be performed outside, usually in the hardware initialization code.

Parameters
[out]ldppointer to a LEDCommDriver structure
[in]inotifypointer to a callback function that is invoked when some data is read from the Queue. The value can be NULL.
[in]onotifypointer to a callback function that is invoked when some data is written in the Queue. The value can be NULL.
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 322 of file ledcomm.c.

References LD_STOP, LEDCOMM_BUFFERS_SIZE, and LEDCommDriver::vmt.

Referenced by ldInit().

void ldStart ( LEDCommDriver_t ldp,
const LEDCommConfig_t config 
)

Configures and starts the driver.

Parameters
[in]ldppointer to a LEDCommDriver object
[in]configthe architecture-dependent LEDComm driver configuration. If this parameter is set to NULL then a default configuration is used.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 341 of file ledcomm.c.

References LEDCommConfig_t::anode_pad, LEDCommConfig_t::anode_port, LEDCommConfig_t::cathode_extmode, LEDCommConfig_t::cathode_pad, LEDCommConfig_t::cathode_port, LEDCommConfig_t::data_bits, LD_READY, LD_STOP, LEDCOMM_DATA_BITS7, LEDCOMM_DEFAULT_SYNCS, and LEDCommConfig_t::threshold.

void ldStop ( LEDCommDriver_t ldp)

Stops the driver.

Any thread waiting on the driver's queues will be awakened with the message Q_RESET.

Parameters
[in]ldppointer to a LEDCommDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 413 of file ledcomm.c.

References LD_READY, and LD_STOP.

void ldIncomingDataI ( LEDCommDriver_t ldp,
uint8_t  b 
)

Handles incoming data.

This function must be called from the input interrupt service routine in order to enqueue incoming data and generate the related events.

Note
The incoming data event is only generated when the input queue becomes non-empty.
In order to gain some performance it is suggested to not use this function directly but copy this code directly into the interrupt service routine.
Parameters
[in]ldppointer to a LEDCommDriver structure
[in]bthe byte to be written in the driver's Input Queue
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 445 of file ledcomm.c.

References LD_OVERRUN_ERROR.

msg_t ldRequestDataI ( LEDCommDriver_t ldp)

Handles outgoing data.

Must be called from the output interrupt service routine in order to get the next byte to be transmitted.

Note
In order to gain some performance it is suggested to not use this function directly but copy this code directly into the interrupt service routine.
Parameters
[in]ldppointer to a LEDCommDriver structure
Returns
The byte value read from the driver's output queue.
Return values
Q_EMPTYif the queue is empty (the lower driver usually disables the interrupt source when this happens).
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 474 of file ledcomm.c.