LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
UART Device Controller

Manages the sequence necessary when adding a UART devices to an input port.

The UART Device Controller gets information from the DCM driver Device Detection Manager Driver about the port state and when the DCM driver detects a UART device on the port the sequence below the following defines is started inside the UART Device Controller.

*/

#define   LOWEST_BITRATE                2400  //  Lowest possible bit rate (always used for sync and info)  [b/S]
#define   MIDLE_BITRATE                57600  //  Highest bit rate allowed when adjusting clock             [b/S]
#define   HIGHEST_BITRATE             460800  //  Highest possible bit rate                                 [b/S]

#define   MIDLE_BITRATE_DEVIATION         40  //  Largest deviation able to adjust clock to                 [%]
#define   MIDLE_BITRATE_INCREAMENT         1  //  Amount to adjust per loop                                 [%]
#define   MIDLE_BITRATE_FIX                5  //  Last adjustment to get in the middle of the bit           [%]

/*
  SEQUENCE WHEN UART DEVICE IS DETECTED
  =====================================

        HOST                                                                                DEVICE
    ------------------------------------------------------------        ----------------------------------------------------------------------
                                                                                        - Reset                 <----------------------------,
                                                                                          - Set TX active (low)                              |
                                                                                          - Set RX floating                                  |
                                                                                          - Wait half a second 1st.time (next time >=10mS)   |
                                                                                                                                             |
    - Enable UART communication                                                         - Enable UART communication                          |
      - Setup UART for LOWEST_BITRATE                                                     - Setup UART for LOWEST_BITRATE                    |
      - Setup hardware buffers                                                                                                               |
                                                                                                                                             |
                                                                                                                                             |
    - Sync clocks                                                                       - Sync clocks (only used on no XTAL devices)         |
      - Wait for receive of byte               <-.                   <-- SYNC             - Send sync pulse     <------------.               |
      - If CMD is received skip to send INFO     |                                                                           |               |
      - Check byte against SYNC                  |                                                                           |               |
      - If not SYNC increase UART clock        --'                                        - Timeout 5mS (UART byte time)   --'               |
      - Send sync feedback                                  SYNC -->                      - Receive sync pulse                               |
                                                                                                                                             |
                                                                                                                                             |
    - Exchange informations                                                             - Exchange informations                              |
      - Receive command data                                         <-- CMD              - Send command data (type,modes,speed, etc)        |
      - Send command data (type,modes,speed, etc)           CMD  -->                      - Receive command data                             |
      - Receive info data                                            <-- INFO             - Send info data (name,scaling,data format, etc)   |
      - Send info data (name,scaling,data format, etc)      INFO -->                      - Receive info data                                |
      - Receive acknowledge                                          <-- ACK              - When finished info send acknowledge              |
                                                                                          - Timeout (80mS)      -----------------------------'
      - When finished info send acknowledge                 ACK  -->                      - Receive acknowledge
      - Switch to valid communication speed                                               - Switch to valid communication speed


    - Communication running                                                              - Communication running
      - Receive data                                                 <-- DATA             - Send data
      - If out of sync, send not acknowledge                NACK -->                      - If not acknowledge, repeat send data
      - Receive data                                                 <-- DATA             - Send data
      - Receive data                                                 <-- DATA             - Send data
      - Receive data                                                 <-- DATA             - Send data
         --
      - Send data                                           DATA -->                      - Receive data
      - Receive data                                                 <-- DATA             - Send data
      - Receive data                                                 <-- DATA             - Send data
         --
      - Send command                                        CMD  -->                      - Receive command
      - Receive data                                                 <-- DATA             - Send data
      - Receive data                                                 <-- DATA             - Send data
         --
      - Send data                                           DATA -->                      - Receive data
      - If not acknowledge, repeat send data                         <-- NACK             - If out of sync, send not acknowledge
      - Send data                                           DATA -->                      - Receive data
         --


  DEVICES WITH XTAL
  =================

  Devices with a bit rate accuracy better that +-2% must start on LOWEST_BITRATE and skip the synchronisation sequence and just begin to send INFO.

  When placed wrong on an output port device TX should continue to transmit SYNC, INFO or DATA to ensure that the host detects
  that connection 6 is low

Ex.

  DEVICES WITHOUT XTAL
  ====================

  It is possible to use the power of the host to adjust to LOWEST_BITRATE if the device is not capable of meeting accuracy
  of the bit rate. The adjustment factor is then used when switching to higher speeds up to MIDLE_BITRATE.

  These devices must start with a bit rate at LOWEST_BITRATE + worst case deviation from LOWEST_BITRATE

  When placed wrong on an output port device TX should continue to transmit SYNC, INFO or DATA to ensure that the host detects
  that connection 6 is low



  DEVICES NOT ABLE TO RECEIVE
  ===========================

  Devices that is not able to receive should send SYNC several times (MIDLE_BITRATE_DEVIATION / MIDLE_BITRATE_INCREAMENT + 1)

  When placed wrong on an output port device TX should continue to transmit SYNC, INFO or DATA to ensure that the host detects
  that connection 6 is low



  HOST
  ====

  The host should check every data message format against the info once sent from the device and send NACK if not valid

  UART devices is connected when system powers up!: the power to input/output ports is powered up when DCM driver is ready to evaluate the devices on
  the ports (ensures that power up sync is executed when system is powered up)



  BIT RATE ADJUSTMENT
  ===================

    I.    Host starts with a bit rate at LOWEST_BITRATE

    II.   Device must start with a bit rate at LOWEST_BITRATE + worst case deviation from LOWEST_BITRATE

    III.  When the SYNC is received host will check it against the correct SYNC byte and if it is wrong the bit rate is raised MIDLE_BITRATE_INCREAMENT

    IV.   If SYNC is received correctly the bit rate is raised additionally MIDLE_BITRATE_FIX and SYNC is sent to the device

    V.    If info says that a higher bit rate is possible it is raised after transmitting ACK on the host and after receiving (or a time) ACK on the device
          (if host has adjusted the bit rate the same factor will be used when raising)
\n