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_SLAVE_H__
37 #define __CCIEF_BASIC_SLAVE_H__
39 #include <stdint.h>
41 /*[ Definition for sample code ]*/
42 #define CCIEF_BASIC_SLAVE_ERR_OK 0
43 #define CCIEF_BASIC_SLAVE_ERR_NG (-1)
44 #define CCIEF_BASIC_SLAVE_ERR_DEVICE_RANGE (-100)
46 /*[ Definition for CCIEF-BASIC environment ]*/
47 #define CCIEF_BASIC_PROTCOL_VERSION 1 /* Protocol Version */
48 #define CCIEF_BASIC_PORT_NUMBER 61450 /* Port number */
49 #define CCIEF_BASIC_MAX_FRAME_SIZE 6000 /* Size of MAX Packet [byte] */
50 #define CCIEF_BASIC_RX_RY_SIZE 8 /* Size of RX/RY [byte] */
51 #define CCIEF_BASIC_RWW_RWR_SIZE 64 /* Size of RWw/RWr [byte] */
52 #define CCIEF_BASIC_MAX_NUMBER_OF_OCCUPIED_STATIONS_GROUP 16 /* Number of MAX occupied stations for group */
53 #define CCIEF_BASIC_SLMP_COMMAND_CYCLIC_DATA 0x0E70 /* Cyclic Data(0E70h) of SLMP Command */
54 #define CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT 500 /* Default cyclic transmission timeout [ms] */
55 #define CCIEF_BASIC_CYCLIC_TRANSMISSION_TIMEOUT_COUNT 3 /* Default count of cyclic transmission timeout */
56 #define CCIEF_BASIC_UNIT_INFO_APPLICATION_STOP 0x0000 /* Stopping application for setting the unit info */
57 #define CCIEF_BASIC_UNIT_INFO_APPLICATION_RUNNING 0x0001 /* Running application for setting the unit info */
59 /*[ Definition for CCIEF-BASIC End Code ]*/
60 #define CCIEF_BASIC_END_OK 0x0000 /* Processing success. */
61 #define CCIEF_BASIC_END_DUPLICATE_MASTER 0xCFE0 /* Duplicate of the master. */
62 #define CCIEF_BASIC_END_NUMBER_OF_OCCUPIED_STATIONS 0xCFE1 /* Invalid number of occupied stations. */
63 #define CCIEF_BASIC_END_SLAVE 0xCFF0 /* Error of the slave. */
64 #define CCIEF_BASIC_END_DISCONNECTED_REQUEST 0xCFFF /* Disconnected request to Master. */
66 /*[ Definition for CCIEF-BASIC sample code ]*/
67 #define CCIEF_BASIC_BIT_ON 1 /* Bit ON */
68 #define CCIEF_BASIC_BIT_OFF 0 /* Bit OFF */
69 #define CCIEF_BASIC_CYCLIC_DATA_VALID 1 /* Valid of the cyclic data */
70 #define CCIEF_BASIC_CYCLIC_DATA_INVALID 0 /* Invalid of the cyclic data */
71 #define CCIEF_BASIC_SLAVE_ID_OCCUPIED_STATIONS 0xFFFFFFFF /* Slave Id of occupied stations. */
72 #define CCIEF_BASIC_DEVICE_TYPE_RX 1 /* Type of device for RX. */
73 #define CCIEF_BASIC_DEVICE_TYPE_RY 2 /* Type of device for RY. */
74 #define CCIEF_BASIC_DEVICE_TYPE_RWW 3 /* Type of device for RWw. */
75 #define CCIEF_BASIC_DEVICE_TYPE_RWR 4 /* Type of device for RWr. */
77 /*[ Structure for sample code ]*/
79 #ifdef _WIN32
80 typedef struct
81 {
82 uint16_t usVenderCode; /* Vender code */
83 uint32_t ulModelCode; /* Model code */
84 uint16_t usMachineVersion; /* Machine version */
85 uint32_t ulIpAddress; /* Slave ip address */
86 int iOccupiedStationNumber; /* Number of occupied stations */
87 } CCIEF_BASIC_SLAVE_INFO;
88 #elif __linux__
89 typedef struct
90 {
91 uint16_t usVenderCode; /* Vender code */
92 uint32_t ulModelCode; /* Model code */
93 uint16_t usMachineVersion; /* Machine version */
94 uint32_t ulIpAddress; /* Slave ip address */
95 uint32_t ulSubnetMask; /* Slave subnet mask */
96 int iOccupiedStationNumber; /* Number of occupied stations */
97 } CCIEF_BASIC_SLAVE_INFO;
98 #endif
100 typedef struct
101 {
102 uint16_t usUnitInfo; /* Information of the unit */
103 uint16_t usReserve; /* Reserve */
104 uint8_t aucTimeData[8]; /* Time of the master */
105 } CCIEF_BASIC_MASTER_NOTIFY_INFO;
107 typedef struct
108 {
109 uint32_t ulId; /* Id of the master */
110 uint8_t ucGroupNumber; /* Group number */
111 CCIEF_BASIC_MASTER_NOTIFY_INFO NotifyInfo; /* Notify information of the master */
112 } CCIEF_BASIC_SLAVE_MASTER_INFO;
114 /*[ Definition of callback function ]*/
115 typedef void(*CCIEF_BASIC_SLAVE_CALLBACK_RECV_CYCLIC_DATA)( int iCyclicState, int iOccupiedStationNumber );
116 typedef void(*CCIEF_BASIC_SLAVE_CALLBACK_CYCLIC_DISCONNECTION)( void );
118 /* Definition of function of sample code */
119 extern int ccief_basic_slave_initialize( CCIEF_BASIC_SLAVE_INFO *pInitialInfo,
120 CCIEF_BASIC_SLAVE_CALLBACK_RECV_CYCLIC_DATA pRecvCyclicDataFunc,
121 CCIEF_BASIC_SLAVE_CALLBACK_CYCLIC_DISCONNECTION pCyclicDisconnectionFunc );
122 extern void ccief_basic_slave_terminate( void );
123 extern int ccief_basic_slave_main( void );
124 extern int ccief_basic_slave_set_rx( int iNumber, int iValue );
125 extern int ccief_basic_slave_get_ry( int iNumber, int *piValue );
126 extern int ccief_basic_slave_get_rww( int iNumber, uint16_t *pusValue );
127 extern int ccief_basic_slave_set_rwr( int iNumber, uint16_t usValue );
128 extern uint16_t *ccief_basic_slave_get_pointer( int iDeviceType );
129 extern void ccief_basic_slave_set_unit_info( uint16_t usUnitInfo );
130 extern void ccief_basic_slave_set_err_code( uint16_t usErrCode );
131 extern void ccief_basic_slave_set_unit_data( uint32_t ulUnitData );
132 extern void ccief_basic_slave_get_master_info( CCIEF_BASIC_SLAVE_MASTER_INFO *pInfo );
134 #endif
135 /*EOF*/