Bladeren bron

feat:添加设置结构体4字节对齐宏
module:iso15765
ticket_ID:iso15765

yangyongkai 3 jaren geleden
bovenliggende
commit
5748a19194
1 gewijzigde bestanden met toevoegingen van 113 en 8 verwijderingen
  1. 113 8
      BleCanBoxCode/STM32F103RCT6/Middle/iso15765-canbus-master/src/lib_iso15765.h

+ 113 - 8
BleCanBoxCode/STM32F103RCT6/Middle/iso15765-canbus-master/src/lib_iso15765.h

@@ -34,7 +34,7 @@ SOFTWARE.
 
 #define I15765_MSG_SIZE     516 /* Max. size of the TP up to 4095 bytes */
 #define I15765_QUEUE_ELMS   64  /* No. of max incoming frames that the* reception buffer can hold */
-
+#define ARM_M4              1
 /* Alignment is required for Microcontrollers */
 #if defined(__clang__)
     #define ALIGNMENT __attribute__ ((aligned (4)))
@@ -206,8 +206,12 @@ typedef enum
 } stream_sts;
 
 /* --- Network Layer Timing PARAMs (ref: iso15765-2 p.) -------------------- */
-
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     uint32_t n_bs;  /* FlowControl N_PDU not received (lost, overwritten) on the
              * sender side or preceding FirstFrame N_PDU or ConsecutiveFrame
@@ -220,10 +224,18 @@ typedef struct ALIGNMENT
              * N_USData.indication with <N_Result> = N_TIMEOUT_Cr */
     uint32_t n_cs;
 } n_timeouts;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /* --- Address information (ref: iso15765-2 p.) ---------------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     uint8_t n_pr;       /* Network Address Priority */
     uint8_t n_sa;       /* Network Source Address */
@@ -231,10 +243,17 @@ typedef struct ALIGNMENT
     uint8_t n_ae;       /* Network Address Extension */
     ta_type n_tt;       /* Network Target Address type */
 } n_ai_t;
-
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 /* --- Protocol control information (ref: iso15765-2 p.) ------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     uint8_t  fs;     /* FlowStatus: whether the sending network entity can proceed with the message transmission 'flow_sts' */
     uint8_t  bs;     /* BlockSize */
@@ -243,10 +262,17 @@ typedef struct ALIGNMENT
     pci_type pt;     /* Type of the received pdu 'pci_type' */
     uint16_t dl;     /* PCI data length (if 0 frame must be ignored) */
 } n_pci_t;
-
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 /* --- Protocol dt unit (ref: iso15765-2 p.) ------------------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     mtype    n_mt;     /* Message Type */
     uint16_t sz;       /* Actual data size */
@@ -254,29 +280,50 @@ typedef struct ALIGNMENT
     n_pci_t  n_pci;    /* Protocol control information */
     uint8_t  dt[128];  /* Data Field */
 } n_pdu_t;
-
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 /* --- N_USdt.cfm (ref: iso15765-2 p.6) ------------------------------------ */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     n_ai_t  n_ai;    /* Address information */
     n_pci_t n_pci;   /* Protocol control information */
     n_rslt  rslt;    /* Result of the request */
 } n_cfm_t;
-
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 /* --- N_FF.indn (ref: iso15765-2 p.6) ------------------------------------ */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     cbus_fr_format fr_fmt;  /* CANBus Frame format */
     n_ai_t         n_ai;    /* Address information */
     n_pci_t        n_pci;   /* Protocol control information */
     uint16_t       msg_sz;  /* Size of the message that will be received */
 } n_ff_indn_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /* --- N_USData.request (ref: iso15765-2 p6.) ------------------------------ */
-
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     cbus_fr_format fr_fmt;                 /* CANBus Frame format */
     n_ai_t         n_ai;                   /* Address information */
@@ -284,10 +331,18 @@ typedef struct ALIGNMENT
     uint16_t       msg_sz;                 /* Message actual size */
     uint8_t        msg[I15765_MSG_SIZE];   /* Message to be transmitted */
 } n_req_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /* --- N_USdt.indn (ref: iso15765-2 p.7) ---------------------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     cbus_fr_format fr_fmt;                  /* CANBus Frame format */
     n_ai_t         n_ai;                    /* Address information */
@@ -296,16 +351,32 @@ typedef struct ALIGNMENT
     uint16_t       msg_sz;                  /* Received message actual size */
     uint8_t        msg[I15765_MSG_SIZE];    /* Received message data */
 } n_indn_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     n_ai_t n_ai;        /* Address information. Not supported:the lib handles only 1 stream */
     n_pci_t n_pci;      /* Protocol control information. Not supported:the lib handles only 1 stream) */
     fl_param param;     /* Parameter to change */
     uint8_t pval;       /* Value to set */
 } n_chg_param_req_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     n_ai_t n_ai;        /* Address information. Not supported:the lib handles only 1 stream */
     n_pci_t n_pci;      /* Protocol control information. Not supported: because the lib handles only 1 stream */
@@ -313,7 +384,9 @@ typedef struct ALIGNMENT
     uint8_t pval;       /* Requested Value to set */
     n_rslt rslt;        /* Result of the request */
 } n_chg_param_cfm_t;
-
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 typedef enum
 {
@@ -325,7 +398,12 @@ typedef enum
 
 /* --- Callbacks  ---------------------------------------------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     void (*indn)(n_indn_t *);                         /* Indication Callback: Will be fired when a reception is available or an error occured during the reception. */
     void (*ff_indn)(n_ff_indn_t *);                   /* First Frame Indication Callback: Will be fired when a FF is received, giving back some useful information */
@@ -344,10 +422,18 @@ typedef struct ALIGNMENT
         uint8_t *                                     /* - Frame Data Array */
     );
 } n_callbacks_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /* --- PDU Stream  --------------------------------------------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     cbus_fr_format fr_fmt;              /* CANBus Frame format */
     n_pdu_t        pdu;                 /* Keep information about the in/out frame in a PDU format */
@@ -362,10 +448,18 @@ typedef struct ALIGNMENT
     n_timeouts  last_upd;               /* Time keeper for timouts */
     uint8_t     msg[I15765_MSG_SIZE];   /* Received/Transmit message buffer */
 } n_iostream_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /* --- iso15765 timing configuration (ref: iso15765-2 p.25)----------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     uint8_t  stmin;  /* Default min. frame transmission separation */
     uint8_t  bs;     /* Max. Block size during transmission */
@@ -373,10 +467,18 @@ typedef struct ALIGNMENT
     uint16_t n_bs;   /* Time until reception of the next FlowControl N_PDU */
     uint16_t n_cr;   /* Time until reception of the next ConsecutiveFrame N_PDU */
 } n_config_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /* --- iso15765 Handler  --------------------------------------------------- */
 
+#if ARM_M4
+#pragma pack(4)
+typedef struct
+#else
 typedef struct ALIGNMENT
+#endif //ARM_M4
 {
     addr_md addr_md;                                              /* Selected address mode of the TP */
     cbus_id_type fr_id_type;                                      /* CANBus frame Id Type */
@@ -389,6 +491,9 @@ typedef struct ALIGNMENT
     iqueue_t inqueue;                                             /* Queue handler for the incoming canbus frames */
     uint8_t inq_buf[I15765_QUEUE_ELMS * sizeof(canbus_frame_t)];  /* Queue buffer */
 } iso15765_t;
+#if ARM_M4
+#pragma pack()
+#endif //ARM_M4
 
 /******************************************************************************
 * Declaration | Public Functions