⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lin_dev.c

📁 针对日本瑞莎单片机r8c/23系列开发的LIN网络开发编程
💻 C
📖 第 1 页 / 共 2 页
字号:
  {UNCONDITION_FRAME, (unsigned char)LIN_F1_REQ_NODE_A_AD,                   10}, //30
  {UNCONDITION_FRAME, (unsigned char)LIN_F2_REQ_NODE_A_SWITCH_AND_COUNTER,   10}, //30
  {UNCONDITION_FRAME, (unsigned char)LIN_F3_CMD_SWITCH,                      10}, //30
  {UNCONDITION_FRAME, (unsigned char)LIN_F4_REQ_NODE_B_AD,                   10}, //30
  {UNCONDITION_FRAME, (unsigned char)LIN_F5_REQ_NODE_B_SWITCH_AND_COUNTER,   10}  //30
};

/* The "LIN_id_table[]" for a Master node defines all of the frames that are used within the
 * LIN cluster.  "LIN_id_table[]" for a Slave node defines only those frames that the Slave
 * node will receive or transmit.  The frames are listed in "LIN_id_table[]" in the order in
 * which they are enumerated in "lin_dev.h".  This enumeration is node dependent.  The
 * same frame most likely will have a different number ("LIN_frame_name") on each node where
 * it is processed.
 *
 * frame_id - This field holds the 6-bit LIN Frame ID assigned to the frame.  The 8-bit LIN
 *            Protected ID is this same ID with the 2 parity bits added as the MSBits.  The
 *            frame ID's may be assigned freely (within the ranges allowed by the LIN
 *            specification) according to the requirements of the LIN cluster.
 *            Slave node special - if the frame ID's will be configurable, "LIN_id_table[]"
 *            can be located in RAM and the frame ID's can be initialized to 0xFF.  However,
 *            even in this case, the frame ID's for Diagnostic frames (0x3C, 0x3D and 0x3E)
 *            must be initialized to their standard values.
 *
 * node_name - This is the name of the LIN node that will "publish" the data for the frame.
 *             Master node special for Event Triggered or Diagnostic Response frames - "node_name"
 *             should be set to LIN_ANY_SLV, since no one Slave node will publish the data.
 *             Slave nodes special for Event Triggered frames - if a Slave node is configured
 *             to publish data for an Event Triggered frame, "node_name" must be set to the name
 *             of the Slave node.
 *
 * message_id - This ID identifies each type of message used in the LIN cluster and allows the
 *              Slave nodes to be configured dynamically to associate each message type with the
 *              frame ID used for that message type in a particular LIN cluster configuration.
 *              The Message ID is broken into 2 bytes.  The LSByte holds the Message ID known to
 *              the Slave node.  Each type of message used in the LIN cluster (encoder position
 *              request, encoder status request, temp display command, Event Triggered request for
 *              encoder position, etc) must be assigned an 8-bit Message ID.  This Message ID will
 *              be used as the LSByte of the Message ID for all frames (for both Master and Slave
 *              nodes) that transport this type of message.   For Slave nodes, the MSByte is always
 *              set to 0x00.  For Master nodes, the MSByte holds the NAD of the Slave node that
 *              will transmit or receive the frame, except for Event Triggered frames.  The MSByte
 *              of the Message ID for Event Triggered frames is left at 0x00, since these frames
 *              are not associated with any particular Slave node (NAD).  For both Master and Slave
 *              nodes, the Message ID of Diagnostic frames is left set to 0x0000, since the Message
 *              ID of these frames is never used (the frame ID's of Diagnostic frames are never
 *              changed).
 *
 * frame_type - The only frame types allowed to be used in "LIN_id_table[]" are UNCONDITION_FRAME
 *              and EVENT_TRIG_FRAME.  Even if a frame is sent in a Sporadic slot, the type of the
 *              frame itself is UNCONDITION_FRAME.
 *
 * data_length - The length of the frame data field in bytes.  The number of bytes for the data
 *               field of an Event Triggered frame is always one byte longer than the data field of
 *               the associated Unconditional frame, since the first byte in the data field of an
 *               Event Triggered frame is always the PID of the Unconditional frame for which the
 *               response is made.  The length of the data field must be the same for all Slave
 *               nodes that may publish data for an Event Triggered frame.
 *
 * check_sum_type - The type of checksum used for LIN 2.0 compliant Slave nodes must be set to
 *                  "LIN_ENHANCED".  If LIN 1.3 compliant Slave nodes are included in the LIN cluster,
 *                  the checksum type must be set to "LIN_CLASSIC" for all frames associated with
 *                  these nodes.  It is not allowed to mix LIN 1.3 compliant Slave nodes with LIN 2.0
 *                  compliant Slave nodes in an Event Triggered frame.  The checksum type for all
 *                  Diagnostic frames must be set to "LIN_CLASSIC".
 *
 * num_sigs - It is possible to pack several signals into one frame.  The number of signals carried
 *            in a frame is given in the "num_sigs" field, except for Event Triggered frames.
 *            Master node special for Event Triggered frames - the "num_sigs" field is always set to 0.
 *            Slave nodes special for Event Triggered frames - the "num_sigs" field is set to the
 *            "frame_name" (index number "enumerated" in "lin_dev.h") of the Unconditional frame
 *            associated with the Event Triggered frame.
 *
 * data_address - This field holds a pointer to the signal table that defines all of the signals
 *                carried in the frame.  This field is never used for Event Triggered frames (neither
 *                by Master nodes nor by Slave nodes) and may be set to 0x0000.
 *
   typedef struct {
      unsigned char  frame_id;         LIN message frame ID (without parity bits) for this frame.
      unsigned char  node_name;        Name of the node that publishes the data.
      unsigned int   message_id;       Message ID for node configuration.
      unsigned char  frame_type;       Type of LIN message frame.
      unsigned char  data_length;      Number of bytes in the data field.
      unsigned char  check_sum_type;   Type of checksum to be used (enhanced or classic).
      unsigned char  num_sigs;         Number of signals associated with this frame.
      unsigned char  *data_address;    Address of the structure that lists the signals.
   } FRAME_ID_TBL;
 *
 *    */
const FRAME_ID_TBL  LIN_id_table[5 + 1] = {
   {0x01, LIN_SLV_A, 0x0001, UNCONDITION_FRAME, 2, LIN_ENHANCED, 1, (unsigned char*)LIN_F1_Sigtable_Req_Node_A_AD},
   {0x02, LIN_SLV_A, 0x0002, UNCONDITION_FRAME, 2, LIN_ENHANCED, 2, (unsigned char*)LIN_F2_Sigtable_Req_Node_A_Switch_and_Counter},
   {0x03, LIN_MST,   0x0003, UNCONDITION_FRAME, 1, LIN_ENHANCED, 1, (unsigned char*)LIN_F3_Sigtable_Cmd_Switch},
   {0x04, LIN_SLV_B, 0x0004, UNCONDITION_FRAME, 2, LIN_ENHANCED, 1, (unsigned char*)LIN_F4_Sigtable_Req_Node_B_AD},
   {0x05, LIN_SLV_B, 0x0005, UNCONDITION_FRAME, 2, LIN_ENHANCED, 2, (unsigned char*)LIN_F5_Sigtable_Req_Node_B_Switch_and_Counter},
   {0xFE, 0, 0, 0, 0, 0, 0, 0}   //Required "empty" entry as a table delimiter.
};
/*const FRAME_ID_TBL  LIN_id_table[1 + 1] = {
   {0x02, LIN_SLV_A, 0x0002, UNCONDITION_FRAME, 2, LIN_ENHANCED, 2, (unsigned char*)LIN_F2_Sigtable_Req_Node_A_Switch_and_Counter},
   {0xFE, 0, 0, 0, 0, 0, 0, 0}
};*/

/* The following structures define each of the signals that are transported
 * in a given frame.  One such structure must exist for each frame defined in
 * "LIN_id_table[]".  The signal enums are defined in "lin_dev.h" and allocated
 * below.  The signal names are purely optional and may be chosen to fit the
 * application.
 *
   typedef struct {
      unsigned char  signal_name;      Signal name.  Actually, an enumerated value, not a string.
      unsigned char  signal_offset;    Bit offset of the signal data in the frame data field.
   } FRAME_SIGNAL_TBL;
 *    */
const FRAME_SIGNAL_TBL  LIN_F1_Sigtable_Req_Node_A_AD[1] = {
      {(unsigned char)LIN_SIG_NODE_A_AD, 0}
};

const FRAME_SIGNAL_TBL  LIN_F2_Sigtable_Req_Node_A_Switch_and_Counter[2] = {
      {(unsigned char)LIN_SIG_NODE_A_SWITCH, 0},
  	  {(unsigned char)LIN_SIG_NODE_A_COUNTER, 8}
};

const FRAME_SIGNAL_TBL  LIN_F3_Sigtable_Cmd_Switch[1] = {
      {(unsigned char)LIN_SIG_CMD_SWITCH, 0}
};

const FRAME_SIGNAL_TBL  LIN_F4_Sigtable_Req_Node_B_AD[1] = {
      {(unsigned char)LIN_SIG_NODE_B_AD, 0}
};

const FRAME_SIGNAL_TBL  LIN_F5_Sigtable_Req_Node_B_Switch_and_Counter[2] = {
      {(unsigned char)LIN_SIG_NODE_B_SWITCH, 0},
  	  {(unsigned char)LIN_SIG_NODE_B_COUNTER, 8}
};

/* The "LIN_signal_table" is a structure that declares the elements associated
 * with each signal used by the LIN system.
 *
   typedef struct {
      unsigned char  signal_byte;      Signal data size in bytes.
      unsigned char  signal_bit;       Signal data size in bits.
      unsigned char  *signal_address;  Address of the signal data [byte 0 is status byte].
   } SIGNAL_TBL;
 *
 *    */
const SIGNAL_TBL  LIN_signal_table[7] = {
   {2, 16,  &LIN_SIG_Node_A_AD_data[0]},
   {1, 8,   &LIN_SIG_Node_A_Switch_data[0]},
   {1, 8,   &LIN_SIG_Node_A_Counter_data[0]},
   {1, 8,   &LIN_SIG_Cmd_Switch_data[0]},
   {2, 16,  &LIN_SIG_Node_B_AD_data[0]},
   {1, 8,   &LIN_SIG_Node_B_Switch_data[0]},
   {1, 8,   &LIN_SIG_Node_B_Counter_data[0]}
};


/**********************************************************************
 *
 * Modification Record
 *
 **********************************************************************
 *
 *    Version 1.1 16 Mar 2006   Bob Chamberlain
 *    Version 1.2 14 Sep 2006   Demo for AE, Carl Stenquist
 *    Version 1.2 14 Sep 2006   Two slave version. CS
 *********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -