c892115c5df1725e7a42519bd54b0e1a97aae51a
[processor-sdk/cclink.git] / CCIEF-BASIC_Master / sample / include / CCIEF_BASIC_MASTER.h
1 /*
2  * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
3  * Copyright (C) 2016 CC-Link Partner Association -http://am.cc-link.org/
4  * 
5  * 
6  *  Redistribution and use in source and binary forms, with or without 
7  *  modification, are permitted provided that the following conditions 
8  *  are met:
9  *
10  *    Redistributions of source code must retain the above copyright 
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  *    Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the 
15  *    documentation and/or other materials provided with the   
16  *    distribution.
17  *
18  *    Neither the name of Texas Instruments Incorporated nor the names of
19  *    its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34 */
36 #ifndef         __CCIEF_BASIC_MASTER_H__
37 #define         __CCIEF_BASIC_MASTER_H__
39 #include <stdint.h>
41 /*[ Definition for sample code ]*/
42 #define CCIEF_BASIC_MASTER_ERR_OK                                                       0
43 #define CCIEF_BASIC_MASTER_ERR_NG                                                       (-1)
44 #define CCIEF_BASIC_MASTER_ERR_DEVICE_RANGE                                     (-100)
45 #define CCIEF_BASIC_MASTER_ERR_MASTER_DUPLICATION                       (-200)
46 #define CCIEF_BASIC_MASTER_ERR_SLAVE_DUPLICATION                        (-300)
48 /*[ Definition for CCIEF-BASIC environment ]*/
49 #define CCIEF_BASIC_PROTCOL_VERSION                                                     1                       /* Protocol Version */
50 #define CCIEF_BASIC_PORT_NUMBER_CYCLIC                                          61450           /* Port number of Cyclic */
51 #define CCIEF_BASIC_MAX_FRAME_SIZE                                                      6000            /* Size of MAX Packet [byte] */
52 #define CCIEF_BASIC_RX_RY_SIZE                                                          8                       /* Size of RX/RY [byte] */
53 #define CCIEF_BASIC_RWW_RWR_SIZE                                                        64                      /* Size of RWw/RWr [byte] */
54 #define CCIEF_BASIC_MAX_SLAVE_NUMBER                                            64                      /* Number of MAX slaves */
55 #define CCIEF_BASIC_MAX_GROUP_NUMBER                                            64                      /* Number of MAX groups */
56 #define CCIEF_BASIC_MAX_NUMBER_OF_OCCUPIED_STATIONS_GROUP       16                      /* Number of MAX occupied stations for group */
57 #define CCIEF_BASIC_SLMP_COMMAND_CYCLIC_DATA                            0x0E70          /* Cyclic Data(0E70h) of SLMP Command */
58 #define CCIEF_BASIC_MASTER_PERSUASION_TIME                                      2500            /* Master persuasion time(2500ms) [ms] */
59 #define CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT                         500                     /* Default cyclic transmission timeout [ms] */
60 #define CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT_COUNT           3                       /* Default count of cyclic transmission timeout */
61 #define CCIEF_BASIC_MAX_CONSTANT_LINK_SCAN_TIME                         2000            /* Constant link scan time MAX [ms] */
62 #define CCIEF_BASIC_UNIT_INFO_APPLICATION_STOP                          0x0000          /* Stopping application for setting the unit info */
63 #define CCIEF_BASIC_UNIT_INFO_APPLICATION_RUNNING                       0x0001          /* Running application for setting the unit info */
65 /*[ Definition for CCIEF-BASIC End Code ]*/
66 #define CCIEF_BASIC_END_OK                                                                      0x0000          /* Processing success. */
67 #define CCIEF_BASIC_END_DUPLICATE_MASTER                                        0xCFE0          /* Duplicate of the master. */
68 #define CCIEF_BASIC_END_NUMBER_OF_OCCUPIED_STATIONS                     0xCFE1          /* Invalid number of occupied stations. */
69 #define CCIEF_BASIC_END_SLAVE                                                           0xCFF0          /* Error of the slave. */
70 #define CCIEF_BASIC_END_DISCONNECTED_REQUEST                            0xCFFF          /* Disconnected request from Slave. */
72 /*[ Definition for CCIEF-BASIC sample code ]*/
73 #define CCIEF_BASIC_BIT_ON                                                                      1                       /* Bit ON */
74 #define CCIEF_BASIC_BIT_OFF                                                                     0                       /* Bit OFF */
75 #define CCIEF_BASIC_CYCLIC_STATE_OFF                                            0                       /* Cyclic state OFF. */
76 #define CCIEF_BASIC_CYCLIC_STATE_ON                                                     1                       /* Cyclic state ON. */
77 #define CCIEF_BASIC_CYCLIC_START                                                        1                       /* Start the cyclic of the slave. */
78 #define CCIEF_BASIC_CYCLIC_STOP                                                         0                       /* Stop the cyclic of the slave. */
79 #define CCIEF_BASIC_SLAVE_ID_OCCUPIED_STATIONS                          0xFFFFFFFF      /* Slave Id of occupied stations. */
80 #define CCIEF_BASIC_CONSTANT_LINK_SCAN_NOT_USE                          0                       /* Not using the constant link scan. */
81 #define CCIEF_BASIC_CONSTANT_LINK_SCAN_USE                                      1                       /* Using the constant link scan. */
82 #define CCIEF_BASIC_DEVICE_TYPE_RX                                                      1                       /* Type of device for RX. */
83 #define CCIEF_BASIC_DEVICE_TYPE_RY                                                      2                       /* Type of device for RY. */
84 #define CCIEF_BASIC_DEVICE_TYPE_RWW                                                     3                       /* Type of device for RWw. */
85 #define CCIEF_BASIC_DEVICE_TYPE_RWR                                                     4                       /* Type of device for RWr. */
86 #define CCIEF_BASIC_SLAVE_DUPLICATION_NOT_DETECT                        0                       /* Slave dupsication not detect. */
87 #define CCIEF_BASIC_SLAVE_DUPLICATION_DETECT                            1                       /* Slave dupsication detect. */
88 #define CCIEF_BASIC_SLAVE_RESPONSE_NOT_RECEIVED                         0                       /* Response not receive. */
89 #define CCIEF_BASIC_SLAVE_RESPONSE_RECEIVED                                     1                       /* Response receive. */
90 #define CCIEF_BASIC_PACKET_COUNT_MAX                                                    64                      /* Number of packets to processed per main loop */
92 /*[ Definition for CCIEF-BASIC state ]*/
93 /* Master */
94 #define CCIEF_BASIC_STATE_MASTER_INITAL                                         0                       /* Initialization of the master. */
95 #define CCIEF_BASIC_STATE_MASTER_WAITING                                        1                       /* Waiting for the cyclic operation. */
96 #define CCIEF_BASIC_STATE_MASTER_PERSUASION                                     2                       /* Persuasion of the master. */
97 #define CCIEF_BASIC_STATE_MASTER_LINK_SCAN_END                          3                       /* End of the link scan. */
98 #define CCIEF_BASIC_STATE_MASTER_LINK_SCAN                                      4                       /* Running the link scan. */
99 /* Slave */
100 #define CCIEF_BASIC_STATE_SLAVE_INITAL                                          0                       /* Initialization of the slave. */
101 #define CCIEF_BASIC_STATE_SLAVE_DISCONNECT                                      1                       /* Disconnection of the cyclic network. */
102 #define CCIEF_BASIC_STATE_SLAVE_CONNECTING                                      2                       /* Connecting for the cyclic network. */
103 #define CCIEF_BASIC_STATE_SLAVE_CYCLIC_STOP                                     3                       /* Stop the cyclic operation. */
104 #define CCIEF_BASIC_STATE_SLAVE_CYCLIC_END                                      4                       /* End of the cyclic operation. */
105 #define CCIEF_BASIC_STATE_SLAVE_CYCLIC                                          5                       /* Running the cyclic operation. */
107 /*[ Definition for CCIEF-BASIC event ]*/
108 /* Master */
109 #define CCIEF_BASIC_EVENT_MASTER_INITAL                                         0                       /* Initialization of the master. */
110 #define CCIEF_BASIC_EVENT_MASTER_PARAMETER_GET                          1                       /* Getting the parameter. */
111 #define CCIEF_BASIC_EVENT_MASTER_PARAMETER_CHANGE                       2                       /* Changing the parameter. */
112 #define CCIEF_BASIC_EVENT_MASTER_PERSUASION_TIMEOUT                     3                       /* Timeout of monitoring the persuasion frame. */
113 #define CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_START                        4                       /* Starting the link scan. */
114 #define CCIEF_BASIC_EVENT_MASTER_LINK_SCAN_END                          5                       /* End of the link scan. */
115 #define CCIEF_BASIC_EVENT_MASTER_CYCLIC_DATA_RECV                       6                       /* Receiving the cyclic data from the master. */
116 #define CCIEF_BASIC_EVENT_MASTER_DUPLICATION_ERR_RECV           7                       /* Receiving the error of the duplication master from the slave. */
117 /* Slave */
118 #define CCIEF_BASIC_EVENT_SLAVE_INITAL                                          0                       /* Initialization of the slave. */
119 #define CCIEF_BASIC_EVENT_SLAVE_PARAMETER_CHANGE                        1                       /* Changing the parameter. */
120 #define CCIEF_BASIC_EVENT_SLAVE_LINK_SCAN_START                         2                       /* Starting the link scan. */
121 #define CCIEF_BASIC_EVENT_SLAVE_CYCLIC_DATA_RECV                        3                       /* Receiving the cyclic data from the slave. */
122 #define CCIEF_BASIC_EVENT_SLAVE_CYCLIC_DATA_TIMEOUT                     4                       /* Timeout the response of the cyclic data. */
123 #define CCIEF_BASIC_EVENT_SLAVE_CYCLIC_END                                      5                       /* The end of the cyclic data of all slaves. */
124 #define CCIEF_BASIC_EVENT_SLAVE_DUPLICATION_MASTER_ERR          6                       /* Receiving the error of the duplication master from the slave. */
126 /*[ Structure for sample code ]*/
127 typedef struct 
129         uint8_t         ucGroupNumber;                                          /* Group number */
130         uint16_t        usCyclicTransmissionTimeout;            /* Cyclic transmission timeout */
131         uint16_t        usCyclicTransmissionTimeoutCount;       /* Count of cyclic transmission timeout */
132         uint16_t        usConstantLinkScanTime;                         /* Constant link scan time */
133 } CCIEF_BASIC_GROUP_PARAMETER;
135 typedef struct 
137         uint32_t        ulIpAddress;                            /* Slave ip address */
138         uint16_t        usOccupiedStationNumber;        /* Number of occupied stations */
139         uint8_t         ucGroupNumber;                          /* Group number */
140 } CCIEF_BASIC_SLAVE_PARAMETER;
142 typedef struct 
144         int                                                     iTotalGroupNumber;                                              /* Total number of the groups */
145         CCIEF_BASIC_GROUP_PARAMETER     Group[CCIEF_BASIC_MAX_GROUP_NUMBER];    /* Parameter of the groups */
146         int                                                     iTotalSlaveNumber;                                              /* Total number of the slaves */
147         CCIEF_BASIC_SLAVE_PARAMETER     Slave[CCIEF_BASIC_MAX_SLAVE_NUMBER];    /* Parameter of the slaves */
148 } CCIEF_BASIC_MASTER_PARAMETER;
150 typedef struct 
152         uint16_t        usVenderCode;           /* Vender code */
153         uint16_t        usReserve1;                     /* Reserve */
154         uint32_t        ulModelCode;            /* Model code */
155         uint16_t        usMachineVersion;       /* Machine version */
156         uint16_t        usReserve2;                     /* Reserve */
157         uint16_t        usUnitInfo;                     /* Information of the unit */
158         uint16_t        usErrCode;                      /* Error code */
159         uint32_t        ulUnitData;                     /* Data of the unit */
160 } CCIEF_BASIC_SLAVE_NOTIFY_INFO;
162 typedef struct 
164         uint16_t                                                usProtocolVersion;                      /* Protocol version */
165         uint16_t                                                usEndCode;                                      /* Error code of the slave */
166         uint32_t                                                ulId;                                           /* Id of the slave */
167         uint8_t                                                 ucGroupNumber;                          /* Group number of the slave */
168         uint16_t                                                usFrameSequenceNumber;          /* Frame sequence number */
169         int                                                             usOccupiedStationNumber;        /* Number of occupied stations */
170         int                                                             iState;                                         /* State of the slave */
171         CCIEF_BASIC_SLAVE_NOTIFY_INFO   NotifyInfo;                                     /* Notify information from the slave */
172         int                                                             iCyclicState;                           /* Cyclic state */
173         int                                                             iStationNumber;                         /* Number of stations */
174 } CCIEF_BASIC_SLAVE_INFO;
176 typedef struct 
178         uint16_t        usProtocolVersion;                              /* Protocol version */
179         uint32_t        ulId;                                                   /* Id of the master */
180         uint8_t         ucGroupNumber;                                  /* Group number of the slave */
181         int                     iTotalSlaveNumber;                              /* Total number of the slaves */
182         int                     usTotalOccupiedStationNumber;   /* Total number of occupied stations */
183         int                     iState;                                                 /* State of Master */
184         uint16_t        usUnitInfo;                                             /* Information of the unit */
185         uint16_t        usFrameSequenceNumber;                  /* Frame sequence number */
186         uint16_t        usParameterId;                                  /* Parameter id */
187         int64_t         llTimeData;                                             /* Data of time */
188         int64_t         llLinkScanTimeCurrent;                  /* Current link scan time[us] */
189         int64_t         llLinkScanTimeMinimum;                  /* Minimum link scan time[us] */
190         int64_t         llLinkScanTimeMaximum;                  /* Maximum link scan time[us] */
191 } CCIEF_BASIC_GROUP_INFO;
193 /*[ Definition of callback function ]*/
194 typedef void(*CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END)( uint8_t ucGroupNumber );
196 /* Definition of function of sample program */
197 extern int ccief_basic_master_initialize( uint32_t ulIpAddress, uint32_t ulSubnetMask, CCIEF_BASIC_MASTER_PARAMETER *pParameter,
198                                                                                 CCIEF_BASIC_MASTER_CALLBACK_CYCLIC_LINK_SCAN_END pCyclicLinkScanEndFunc );
199 extern void ccief_basic_master_terminate( void );
200 extern int ccief_basic_master_main( void );
201 extern int ccief_basic_master_start_cyclic( int iSlaveNumber );
202 extern int ccief_basic_master_stop_cyclic( int iSlaveNumber );
203 extern int ccief_basic_master_get_rx( int iNumber, int *piValue );
204 extern int ccief_basic_master_set_ry( int iNumber, int iValue );
205 extern int ccief_basic_master_set_rww( int iNumber, uint16_t usValue );
206 extern int ccief_basic_master_get_rwr( int iNumber, uint16_t *pusValue );
207 extern uint16_t *ccief_basic_master_get_pointer( int iDeviceType );
208 extern void ccief_basic_master_set_unit_info( uint16_t usUnitInfo );
209 extern int ccief_basic_master_get_slave_info( int iSlaveNumber, CCIEF_BASIC_SLAVE_INFO *pSlaveInfo );
210 extern int ccief_basic_master_get_group_info( int iGroupNumber, CCIEF_BASIC_GROUP_INFO *pGroupInfo );
212 #endif
213 /*EOF*/