terminal_config.h 6.36 KB
Newer Older
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
1 2 3 4 5 6
/**
 *  @file
 *  @brief Terminal client configuration (hardware and software).
 * *
 *  @author Petr Elexa
 *  @see LICENSE
Petr's avatar
Petr committed
7 8 9
 *
 */

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
10 11
#ifndef TERM_CONFIG_H_
#define TERM_CONFIG_H_
Petr's avatar
Petr committed
12

13
#include <stdint.h>
14
#include <stdbool.h>
15

16
//#define DEVEL_BOARD // LPCXpresso11C24 development board
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
17 18 19

//-------------------------------------------------------------
// General settings.
20
//-------------------------------------------------------------
Petr's avatar
Petr committed
21

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
22
// Enable write of ACS address to external storage on startup.
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
23
#define ENABLE_LOCAL_ACS_ADDR_WRITE 0
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
24

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
25 26
// Enable caching for operation when communication is lost. (Experimental feature)
// Cache expiration is to be handled by master (Not implemented)
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
27
#define CACHING_ENABLED 0
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
28

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
29 30
// CAN bus speed b/s - affects maximum data cable length.
// Suggested option for common use are 100kbit/s and 125kbit/s.
31 32
#define CAN_BAUD_RATE 125000

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
33 34 35 36 37
// Setting for I2C external storage for door adresses
// (EEPROM, IO EXPANDER or device with same access).
#define STORE_I2C_BUS_FREQ   400000 // 100kHz or 400kHz
#define STORE_I2C_SLAVE_ADDR 0x50   // 7bit address

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
38
// Internal index of card readers (can be only swapped).
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
39 40 41
#define ACS_READER_A_IDX 0
#define ACS_READER_B_IDX 1

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
42
#define BEEP_ON_SUCCESS true
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
43 44 45
#define OK_LED_ON_SUCCESS true

// Door sensor types (reed switch).
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
46 47
#define SENSOR_IS_NO 0  // Normally open (Form A) when door open.
#define SENSOR_IS_NC 1  // Normally closed (Form B) when door open.
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
48 49 50 51 52 53 54 55 56 57

// If DOOR_SENSOR_TYPE is defined enables door sensor.
#define DOOR_SENSOR_TYPE SENSOR_IS_NO

// Communication status led.
#define ACS_COMM_STATUS_LED_PORT  0
#define ACS_COMM_STATUS_LED_PIN   6

//-------------------------------------------------------------
// Global UID from vendor (from chip).
58
//-------------------------------------------------------------
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
59
#define IAP_READ_UID 58
60
extern unsigned int TERMINAL_UID[5]; // 0 - status code, 1 - least significant word
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
61

62
//-------------------------------------------------------------
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
63 64
// Door addresses in a network for ACS system.
//-------------------------------------------------------------
65
//
66 67 68 69
// Read from external storage on startup
// Designed to be even (address A) and odd (address B)
// Always true: ADDR_B = ADDR_A + 1

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
70 71 72 73
/**
* @brief Get network address of door A.
*
*/
74
extern uint16_t get_reader_a_addr(void);
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
75 76 77 78
/**
* @brief Get network address of door B.
*
*/
79
extern uint16_t get_reader_b_addr(void);
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
80 81 82 83 84 85
/**
 * @brief Address setter.
 *
 * @param acs_addr ... ACS network address (odd or even).
 */
void set_reader_addr(const uint16_t acs_addr);
86 87 88 89 90 91 92 93

// Expected organization in external address space:
// | 0x00 | A_ADDR [7:0]
// | 0x01 | A_ADDR [9:8]
//          PADDING [15:10]

// The address actually uses less then 16 bits. See address bit width in ACS protocol.

94
#define PTR_READER_FIRST_ADDR 0x0 // pointer to external memory
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
95
#define STORE_DEV_BUSY_FOR 50 // Number of read commands to try before EEPROM timeout
96

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
97
//---------------------------------------------------------------------------------------------------------------------
98
// Settings for RFID reader A
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
99
//---------------------------------------------------------------------------------------------------------------------
100 101 102 103 104 105 106 107 108 109 110 111 112 113
#define ACS_READER_A_ENABLED         true

#define ACS_READER_A_DATA_PORT       3 // Port must be unique for each reader
                                       // Can be only 2 or 3.
#define ACS_READER_A_D0_PIN     2
#define ACS_READER_A_D1_PIN     1
#define ACS_READER_A_BEEP_PORT  2
#define ACS_READER_A_BEEP_PIN   7
#define ACS_READER_A_GLED_PORT  2
#define ACS_READER_A_GLED_PIN   1
#define ACS_READER_A_RLED_PORT  2
#define ACS_READER_A_RLED_PIN   0
#define ACS_READER_A_RELAY_PORT           1
#define ACS_READER_A_RELAY_PIN            10
114
#define ACS_READER_A_SENSOR_PORT          1 // Can be only 0 or 1.
115 116
#define ACS_READER_A_SENSOR_PIN           8

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
117 118
#define ACS_READER_A_OPEN_TIME_MS         5000
#define ACS_READER_A_OK_GLED_TIME_MS      500
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
119 120

//---------------------------------------------------------------------------------------------------------------------
121
// Settings for RFID reader B
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
122
//---------------------------------------------------------------------------------------------------------------------
123 124 125 126 127 128 129 130 131 132 133 134 135 136
#define ACS_READER_B_ENABLED         true

#define ACS_READER_B_DATA_PORT       2 // Port must be unique for each reader
                                       // Can be only 2 or 3.
#define ACS_READER_B_D0_PIN     8
#define ACS_READER_B_D1_PIN     6
#define ACS_READER_B_BEEP_PORT  2
#define ACS_READER_B_BEEP_PIN   10
#define ACS_READER_B_GLED_PORT  2
#define ACS_READER_B_GLED_PIN   3
#define ACS_READER_B_RLED_PORT  2
#define ACS_READER_B_RLED_PIN   2
#define ACS_READER_B_RELAY_PORT           1
#define ACS_READER_B_RELAY_PIN            11
137
#define ACS_READER_B_SENSOR_PORT          1 // Can be only 0 or 1.
138 139
#define ACS_READER_B_SENSOR_PIN           5

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
140 141
#define ACS_READER_B_OPEN_TIME_MS         5000
#define ACS_READER_B_OK_GLED_TIME_MS      500
142

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
143

144
//---------------------------------------------------------------------------------------------------------------------
145
// Internal setting
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
146
//---------------------------------------------------------------------------------------------------------------------
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
147

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
148
// Not user modifiable.
149
#define WEIGAND_DEVICE_LIMIT 4
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
150
#define SERIAL_DEVICE_LIMIT 0
151
#define ACS_READER_MAXCOUNT 2
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
152 153
#define TERMINAL_TIMER_ID 15

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
154
//---------------------------------------------------------------------------------------------------------------------
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
155
//---------------------------------------------------------------------------------------------------------------------
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
156

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
157
#define HW_WATCHDOG_TIMEOUT 2 // in seconds
158

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
159
//---------------------------------------------------------------------------------------------------------------------
160
// IO
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
161 162
//---------------------------------------------------------------------------------------------------------------------

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
163 164 165
#define LOG_HIGH 1
#define LOG_LOW 0

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
166
//---------------------------------------------------------------------------------------------------------------------
167 168
//---------------------------------------------------------------------------------------------------------------------

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
169 170 171 172 173
/**
*
* @brief Initialize configuration for terminal.
*
*        Reads address from storage.
174
* @note Fails if I2C bus is in invalid state
Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
175 176
* @return true if succeeded
*/
177 178 179 180
bool terminal_config_init(void);

//---------------------------------------------------------------------------------------------------------------------

Bc. Petr Elexa's avatar
Bc. Petr Elexa committed
181
#endif /* TERM_CONFIG_H_ */