Commit 2753a5ab authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

panel: refactor and rename "panel" to "reader"

parent 0ced4a8f
// ACS protocol definitions
// ACS CAN protocol
//
// Contains defines and data types for the protocol
//
#ifndef CAN_TERM_PROTOCOL_H_
#define CAN_TERM_PROTOCOL_H_
#ifndef ACS_CAN_PROTOCOL_H_
#define ACS_CAN_PROTOCOL_H_
// Used Message object numbers
#define ACS_MSGOBJ_SEND_DOOR_A 0
......@@ -35,43 +38,46 @@
#define ACS_FC_MASK (((1 << ACS_FC_BITS) - 1) << ACS_FC_OFFSET)
#define ACS_PRIO_MASK (((1 << ACS_PRIO_BITS) - 1) << ACS_PRIO_OFFSET)
#define ACC_MAX_PRIO 0
#define ACS_MAX_PRIO 0
#define ACS_LOW_PRIO ((1 << ACS_PRIO_BITS) - 1)
// ACS protocol function codes
#define FC_RESERVED 0x0
#define FC_USER_AUTH_REQ 0x1
#define FC_USER_NOT_AUTH_RESP 0x2
#define FC_USER_AUTH_RESP 0x3
#define FC_PANEL_CTRL 0x4
#define FC_NEW_USER 0x5
#define FC_DOOR_STATUS 0x6
#define FC_ALIVE 0x7
#define FC_USER_AUTH_REQ 0x1 // S -> M
#define FC_USER_NOT_AUTH_RESP 0x2 // M -> S
#define FC_USER_AUTH_RESP 0x3 // M -> S
#define FC_DOOR_CTRL 0x4 // M -> S
#define FC_NEW_USER 0x5 // S -> M
#define FC_DOOR_STATUS 0x6 // S -> M
#define FC_ALIVE 0x7 // M -> S
// priorities for each function code (0-7)
#define PRIO_RESERVED 0x0
#define PRIO_USER_AUTH_REQ 0x2
#define PRIO_USER_AUTH_RESP_FAIL 0x2
#define PRIO_USER_AUTH_RESP_OK 0x2
#define PRIO_PANEL_CTRL 0x3
#define PRIO_DOOR_CTRL 0x3
#define PRIO_NEW_USER 0x3
#define PRIO_DOOR_STATUS 0x4
#define PRIO_ALIVE 0x1
// Data for FC_DOOR_CTRL
#define DATA_DOOR_CTRL_MODE_DEF 0x00
#define DATA_DOOR_CTRL_UNLCK 0x01
#define DATA_DOOR_CTRL_LOCK 0x02
#define DATA_DOOR_CTRL_LEARN 0x03
#define DATA_DOOR_CTRL_CLR_CACHE 0x04
#define PANEL_CTRL_DATA_DEF 0x00
#define PANEL_CTRL_DATA_UNLCK 0x01
#define PANEL_CTRL_DATA_LOCK 0x02
#define PANEL_CTRL_DATA_LEARN 0x03
#define PANEL_CTRL_DATA_CLR_CACHE 0x04
// Data for FC_DOOR_STATUS
#define DATA_DOOR_STATUS_CLOSED 0x0
#define DATA_DOOR_STATUS_OPEN 0x1
#define DOOR_STATUS_DATA_CLOSED 0x0
#define DOOR_STATUS_DATA_OPEN 0x1
// Setting for master communication status
#define ACS_MASTER_ALIVE_PERIOD_MS 5000
#define ACS_MASTER_ALIVE_TIMEOUT_MS 10000
#define MASTER_ALIVE_PERIOD 5000 // ms
#define MASTER_ALIVE_TIMEOUT 10000 // ms
// data types
// Data type definitions
#pragma pack(push,1)
......@@ -86,28 +92,28 @@ typedef union
uint32_t flags : 3;
};
uint32_t scalar;
} msg_head_t;
} acs_msg_head_t;
typedef struct
{
uint32_t user_id;
} msg_data_auth_req_t;
} acs_msg_data_auth_req_t;
typedef struct
{
uint32_t user_id;
} msg_data_auth_resp_t;
} acs_msg_data_auth_resp_t;
typedef struct
{
uint32_t user_id;
} msg_data_new_user_t;
} acs_msg_data_new_user_t;
typedef struct
{
uint8_t ctrl_command;
} msg_data_panel_ctrl_t;
} acs_msg_data_door_ctrl_t;
#pragma pack(pop)
#endif /* CAN_TERM_PROTOCOL_H_ */
#endif /* ACS_CAN_PROTOCOL_H_ */
......@@ -62,7 +62,7 @@ int main(void)
Board_Print_Reset_Reason();
WDT_Init(PANEL_WATCHDOG_TIMEOUT);
WDT_Init(HW_WATCHDOG_TIMEOUT);
storage_init();
......
This diff is collapsed.
......@@ -8,11 +8,11 @@
#ifndef BSP_TERMINAL_H_
#define BSP_TERMINAL_H_
#include <reader.h>
#include <stdint.h>
#include "panel.h"
void terminal_init(void);
void terminal_reconfigure(panel_conf_t * panel_cfg, uint8_t id);
void terminal_reconfigure(reader_conf_t * reader_cfg, uint8_t id);
#endif /* BSP_TERMINAL_H_ */
......@@ -6,22 +6,22 @@
#include "terminal_config.h"
#include "storage.h"
#include "can/can_term_protocol.h"
#include "acs_can_protocol.h"
#define ACS_ADDR_BIT_MASK ((1 << ACS_ADDR_BITS) - 1)
// door addresses in ACS
uint16_t _ACS_PANEL_A_ADDR = 0x4; // even
uint16_t _ACS_PANEL_B_ADDR = 0x5; // odd
uint16_t _READER_A_ADDR = 0x4; // even
uint16_t _READER_B_ADDR = 0x5; // odd
inline uint16_t get_acs_panel_a_addr(void)
inline uint16_t get_reader_a_addr(void)
{
return _ACS_PANEL_A_ADDR;
return _READER_A_ADDR;
}
inline uint16_t get_acs_panel_b_addr(void)
inline uint16_t get_reader_b_addr(void)
{
return _ACS_PANEL_B_ADDR;
return _READER_B_ADDR;
}
static bool _load_acs_addrs_from_ext_stor(void)
......@@ -30,11 +30,11 @@ static bool _load_acs_addrs_from_ext_stor(void)
uint16_t first_addr = 0;
ret_val &= storage_read_word_le(PTR_ACS_PANEL_FIRST_ADDR, &first_addr);
ret_val &= storage_read_word_le(PTR_READER_FIRST_ADDR, &first_addr);
if (ret_val)
{
set_acs_panel_addr(first_addr);
set_reader_addr(first_addr);
}
return ret_val;
......@@ -44,24 +44,24 @@ static bool _save_acs_addrs_from_ext_stor(void)
{
bool ret_val = true;
ret_val &= storage_write_word_le(PTR_ACS_PANEL_FIRST_ADDR, _ACS_PANEL_A_ADDR);
ret_val &= storage_write_word_le(PTR_READER_FIRST_ADDR, _READER_A_ADDR);
return ret_val;
}
void set_acs_panel_addr(uint16_t first_acs_addr)
void set_reader_addr(uint16_t first_acs_addr)
{
first_acs_addr &= ACS_ADDR_BIT_MASK;
if (first_acs_addr & 0x1) // even address
{
_ACS_PANEL_B_ADDR = first_acs_addr;
_ACS_PANEL_A_ADDR = first_acs_addr - 1;
_READER_B_ADDR = first_acs_addr;
_READER_A_ADDR = first_acs_addr - 1;
}
else // odd address
{
_ACS_PANEL_A_ADDR = first_acs_addr;
_ACS_PANEL_B_ADDR = first_acs_addr + 1;
_READER_A_ADDR = first_acs_addr;
_READER_B_ADDR = first_acs_addr + 1;
}
}
......
......@@ -30,17 +30,17 @@
extern unsigned int TERMINAL_UID[5]; // 0 - status code, 1 - least significant word
//-------------------------------------------------------------
// Door addresses in ACS system
// Door addresses in a network for ACS system
//
// Read from external storage on startup
// Designed to be even (address A) and odd (address B)
// Always true: ADDR_B = ADDR_A + 1
// Address getters
extern uint16_t get_acs_panel_a_addr(void);
extern uint16_t get_acs_panel_b_addr(void);
extern uint16_t get_reader_a_addr(void);
extern uint16_t get_reader_b_addr(void);
// Address setter
void set_acs_panel_addr(const uint16_t first_acs_addr);
void set_reader_addr(const uint16_t first_acs_addr);
// Expected organization in external address space:
// | 0x00 | A_ADDR [7:0]
......@@ -49,7 +49,7 @@ void set_acs_panel_addr(const uint16_t first_acs_addr);
// The address actually uses less then 16 bits. See address bit width in ACS protocol.
#define PTR_ACS_PANEL_FIRST_ADDR 0x0 // pointer to external memory
#define PTR_READER_FIRST_ADDR 0x0 // pointer to external memory
// Setting for I2C external storage for door adresses
......@@ -60,64 +60,64 @@ void set_acs_panel_addr(const uint16_t first_acs_addr);
//-------------------------------------------------------------
// internal number of card readers
#define ACC_PANEL_A 0
#define ACC_PANEL_B 1
#define ACS_READER_A_IDX 0
#define ACS_READER_B_IDX 1
// card reader count 1/2
#define DOOR_ACC_PANEL_COUNT 2
#define ACS_READER_COUNT 2
#define BEEP_ON_SUCCESS false
#define OK_LED_ON_SUCCESS true
// communication status led
#define ACS_PANEL_STATUS_LED_PORT 0
#define ACS_PANEL_STATUS_LED_PIN 6
#define ACS_COMM_STATUS_LED_PORT 0
#define ACS_COMM_STATUS_LED_PIN 6
//---------------------------------------------------------------------------------------------------------------------
// Settings for panel A
// Settings for RFID reader A
//---------------------------------------------------------------------------------------------------------------------
#define DOOR_1_ACC_PANEL_ON true
#define DOOR_1_ACC_PANEL_PORT 3 // Port must be unique for each access panel (reader)
// Can be only 2 or 3.
#define DOOR_1_ACC_PANEL_D0_PIN 2
#define DOOR_1_ACC_PANEL_D1_PIN 1
#define DOOR_1_ACC_PANEL_BEEP_PORT 2
#define DOOR_1_ACC_PANEL_BEEP_PIN 7
#define DOOR_1_ACC_PANEL_GLED_PORT 2
#define DOOR_1_ACC_PANEL_GLED_PIN 1
#define DOOR_1_ACC_PANEL_RLED_PORT 2
#define DOOR_1_ACC_PANEL_RLED_PIN 0
#define DOOR_1_RELAY_PORT 1
#define DOOR_1_RELAY_PIN 10
#define DOOR_1_SENSOR_PORT 1
#define DOOR_1_SENSOR_PIN 8
#define DOOR_1_OPEN_TIME_MS 8000
#define DOOR_1_OK_GLED_TIME_MS 4000
#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
#define ACS_READER_A_SENSOR_PORT 1
#define ACS_READER_A_SENSOR_PIN 8
#define ACS_READER_A_OPEN_TIME_MS 8000
#define ACS_READER_A_OK_GLED_TIME_MS 4000
//---------------------------------------------------------------------------------------------------------------------
// Settings for panel B
// Settings for RFID reader B
//---------------------------------------------------------------------------------------------------------------------
#define DOOR_2_ACC_PANEL_ON true
#define DOOR_2_ACC_PANEL_PORT 2 // Port must be unique for each access panel (reader)
// Can be only 2 or 3.
#define DOOR_2_ACC_PANEL_D0_PIN 8
#define DOOR_2_ACC_PANEL_D1_PIN 6
#define DOOR_2_ACC_PANEL_BEEP_PORT 2
#define DOOR_2_ACC_PANEL_BEEP_PIN 10
#define DOOR_2_ACC_PANEL_GLED_PORT 2
#define DOOR_2_ACC_PANEL_GLED_PIN 3
#define DOOR_2_ACC_PANEL_RLED_PORT 2
#define DOOR_2_ACC_PANEL_RLED_PIN 2
#define DOOR_2_RELAY_PORT 1
#define DOOR_2_RELAY_PIN 11
#define DOOR_2_SENSOR_PORT 1
#define DOOR_2_SENSOR_PIN 5
#define DOOR_2_OPEN_TIME_MS 8000
#define DOOR_2_OK_GLED_TIME_MS 4000
#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
#define ACS_READER_B_SENSOR_PORT 1
#define ACS_READER_B_SENSOR_PIN 5
#define ACS_READER_B_OPEN_TIME_MS 8000
#define ACS_READER_B_OK_GLED_TIME_MS 4000
//---------------------------------------------------------------------------------------------------------------------
// Internal setting
......@@ -125,16 +125,16 @@ void set_acs_panel_addr(const uint16_t first_acs_addr);
// if following is changed it will need code modification
#define WEIGAND_DEVICE_LIMIT 4
#define SERIAL_DEVICE_LIMIT 0
#define DOOR_ACC_PANEL_MAXCOUNT 2
#define ACS_READER_MAXCOUNT 2
#define TERMINAL_TIMER_ID 15
#if DOOR_ACC_PANEL_COUNT > DOOR_ACC_PANEL_MAXCOUNT
#if ACS_READER_COUNT > ACS_READER_MAXCOUNT
#error "reader max count limit"
#endif
//---------------------------------------------------------------------------------------------------------------------
#define PANEL_WATCHDOG_TIMEOUT 1 // in seconds
#define HW_WATCHDOG_TIMEOUT 1 // in seconds
//---------------------------------------------------------------------------------------------------------------------
......
......@@ -194,9 +194,9 @@ static void Board_LED_Init(void)
Board_LED_Set(BOARD_LED_DBG_B, false);
#endif
Chip_IOCON_PinMux(LPC_IOCON,
CHIP_IOCON_PIO[ACS_PANEL_STATUS_LED_PORT][ACS_PANEL_STATUS_LED_PIN],
CHIP_IOCON_PIO[ACS_COMM_STATUS_LED_PORT][ACS_COMM_STATUS_LED_PIN],
IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinDIROutput(LPC_GPIO, ACS_PANEL_STATUS_LED_PORT, ACS_PANEL_STATUS_LED_PIN);
Chip_GPIO_SetPinDIROutput(LPC_GPIO, ACS_COMM_STATUS_LED_PORT, ACS_COMM_STATUS_LED_PIN);
Board_LED_Set(BOARD_LED_STATUS, false);
}
......@@ -217,7 +217,7 @@ void Board_LED_Set(board_led_t led_number, bool on)
return;
#endif
case BOARD_LED_STATUS:
Chip_GPIO_SetPinState(LPC_GPIO, ACS_PANEL_STATUS_LED_PORT, ACS_PANEL_STATUS_LED_PIN, !on);
Chip_GPIO_SetPinState(LPC_GPIO, ACS_COMM_STATUS_LED_PORT, ACS_COMM_STATUS_LED_PIN, !on);
return;
default:
return;
......@@ -238,7 +238,7 @@ bool Board_LED_Test(board_led_t led_number)
return !Chip_GPIO_GetPinState(LPC_GPIO, 0, 9);
#endif
case BOARD_LED_STATUS:
return !Chip_GPIO_GetPinState(LPC_GPIO, ACS_PANEL_STATUS_LED_PORT, ACS_PANEL_STATUS_LED_PIN);
return !Chip_GPIO_GetPinState(LPC_GPIO, ACS_COMM_STATUS_LED_PORT, ACS_COMM_STATUS_LED_PIN);
default:
return 0;
}
......@@ -260,7 +260,7 @@ void Board_LED_Toggle(board_led_t led_number)
return;
#endif
case BOARD_LED_STATUS:
Chip_GPIO_SetPinToggle(LPC_GPIO, ACS_PANEL_STATUS_LED_PORT, ACS_PANEL_STATUS_LED_PIN);
Chip_GPIO_SetPinToggle(LPC_GPIO, ACS_COMM_STATUS_LED_PORT, ACS_COMM_STATUS_LED_PIN);
return;
default:
return;
......
......@@ -3,7 +3,6 @@
**********************************************************************/
#include "can/can_term_driver.h"
#include "can/can_term_protocol.h"
#include <string.h>
#if defined ( __GNUC__ )
......
#include "panel.h"
static StreamBufferHandle_t _reader_buffer;
static const panel_wiring_t _panel_wiring[DOOR_ACC_PANEL_MAXCOUNT] =
{
{
.acc_panel_port = DOOR_1_ACC_PANEL_PORT,
.acc_panel_d0_pin = DOOR_1_ACC_PANEL_D0_PIN,
.acc_panel_d1_pin = DOOR_1_ACC_PANEL_D1_PIN,
.acc_panel_beep_port = DOOR_1_ACC_PANEL_BEEP_PORT,
.acc_panel_beep_pin = DOOR_1_ACC_PANEL_BEEP_PIN,
.acc_panel_gled_port = DOOR_1_ACC_PANEL_GLED_PORT,
.acc_panel_gled_pin = DOOR_1_ACC_PANEL_GLED_PIN,
.acc_panel_rled_port = DOOR_1_ACC_PANEL_RLED_PORT,
.acc_panel_rled_pin = DOOR_1_ACC_PANEL_RLED_PIN,
.relay_port = DOOR_1_RELAY_PORT,
.relay_pin = DOOR_1_RELAY_PIN,
.sensor_port = DOOR_1_SENSOR_PORT,
.sensor_pin = DOOR_1_SENSOR_PIN,
},
{
.acc_panel_port = DOOR_2_ACC_PANEL_PORT,
.acc_panel_d0_pin = DOOR_2_ACC_PANEL_D0_PIN,
.acc_panel_d1_pin = DOOR_2_ACC_PANEL_D1_PIN,
.acc_panel_beep_port = DOOR_2_ACC_PANEL_BEEP_PORT,
.acc_panel_beep_pin = DOOR_2_ACC_PANEL_BEEP_PIN,
.acc_panel_gled_port = DOOR_2_ACC_PANEL_GLED_PORT,
.acc_panel_gled_pin = DOOR_2_ACC_PANEL_GLED_PIN,
.acc_panel_rled_port = DOOR_2_ACC_PANEL_RLED_PORT,
.acc_panel_rled_pin = DOOR_2_ACC_PANEL_RLED_PIN,
.relay_port = DOOR_2_RELAY_PORT,
.relay_pin = DOOR_2_RELAY_PIN,
.sensor_port = DOOR_2_SENSOR_PORT,
.sensor_pin = DOOR_2_SENSOR_PIN,
}
};
panel_conf_t panel_conf[DOOR_ACC_PANEL_MAXCOUNT] =
{
{
.timer_ok = NULL,
.timer_open = NULL,
.open_time_sec = DOOR_1_OPEN_TIME_MS,
.gled_time_sec = DOOR_1_OK_GLED_TIME_MS,
.mode = PANEL_MODE_DEF,
.enabled = DOOR_1_ACC_PANEL_ON,
},
{
.timer_ok = NULL,
.timer_open = NULL,
.open_time_sec = DOOR_2_OPEN_TIME_MS,
.gled_time_sec = DOOR_2_OK_GLED_TIME_MS,
.mode = PANEL_MODE_DEF,
.enabled = DOOR_2_ACC_PANEL_ON,
}
};
static void panel_timer_open_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (uint32_t) pvTimerGetTimerID(pxTimer);
if (id < DOOR_ACC_PANEL_COUNT)
{
// Lock state
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].relay_port, _panel_wiring[id].relay_pin, LOG_HIGH);
}
}
static void panel_timer_ok_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (uint32_t) pvTimerGetTimerID(pxTimer);
if (id < DOOR_ACC_PANEL_COUNT)
{
// Lock state
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_beep_port, _panel_wiring[id].acc_panel_beep_pin, LOG_LOW);
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_gled_port, _panel_wiring[id].acc_panel_gled_pin, LOG_LOW);
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_rled_port, _panel_wiring[id].acc_panel_rled_pin, LOG_HIGH);
}
}
void panel_init(uint8_t id)
{
//Create stream buffer to receive id from all card readers
if (_reader_buffer == NULL)
{
_reader_buffer = xStreamBufferCreate(2 * DOOR_ACC_PANEL_COUNT * WEIGAND26_BUFF_ITEM_SIZE, WEIGAND26_BUFF_ITEM_SIZE);
}
configASSERT(_reader_buffer);
//Init interface to reader
weigand_init(_reader_buffer, id, _panel_wiring[id].acc_panel_port, _panel_wiring[id].acc_panel_d0_pin, _panel_wiring[id].acc_panel_d1_pin);
//Create timer only once
if (panel_conf[id].timer_open == NULL)
{
panel_conf[id].timer_open = xTimerCreate("PT0", (panel_conf[id].open_time_sec / portTICK_PERIOD_MS), pdFALSE, (void *)(uint32_t) id, panel_timer_open_callback);
}
configASSERT(panel_conf[id].timer_open);
if (panel_conf[id].timer_ok == NULL)
{
panel_conf[id].timer_ok = xTimerCreate("PT1", (panel_conf[id].gled_time_sec / portTICK_PERIOD_MS), pdFALSE, (void *)(uint32_t) id, panel_timer_ok_callback);
}
configASSERT(panel_conf[id].timer_ok);
//Setup GLED
Chip_GPIO_SetPinDIROutput(LPC_GPIO, _panel_wiring[id].acc_panel_gled_port, _panel_wiring[id].acc_panel_gled_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[_panel_wiring[id].acc_panel_gled_port][_panel_wiring[id].acc_panel_gled_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_gled_port, _panel_wiring[id].acc_panel_gled_pin, LOG_LOW);
//Setup RLED
Chip_GPIO_SetPinDIROutput(LPC_GPIO, _panel_wiring[id].acc_panel_rled_port, _panel_wiring[id].acc_panel_rled_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[_panel_wiring[id].acc_panel_rled_port][_panel_wiring[id].acc_panel_rled_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_rled_port, _panel_wiring[id].acc_panel_rled_pin, LOG_HIGH);
//Setup BEEPER
Chip_GPIO_SetPinDIROutput(LPC_GPIO, _panel_wiring[id].acc_panel_beep_port, _panel_wiring[id].acc_panel_beep_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[_panel_wiring[id].acc_panel_beep_port][_panel_wiring[id].acc_panel_beep_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_beep_port, _panel_wiring[id].acc_panel_beep_pin, LOG_LOW);
//RELAY
Chip_GPIO_SetPinDIROutput(LPC_GPIO, _panel_wiring[id].relay_port, _panel_wiring[id].relay_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[_panel_wiring[id].relay_port][_panel_wiring[id].relay_pin], IOCON_MODE_PULLUP, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].relay_port, _panel_wiring[id].relay_pin, LOG_HIGH);
//SENSOR
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[_panel_wiring[id].sensor_port][_panel_wiring[id].sensor_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinDIRInput(LPC_GPIO, _panel_wiring[id].sensor_port, _panel_wiring[id].sensor_pin);
#ifdef SENSOR_TYPE
#if SENSOR_TYPE == SENSOR_IS_NO
Chip_GPIO_SetupPinInt(LPC_GPIO, _panel_wiring[id].sensor_port, _panel_wiring[id].sensor_pin, GPIO_INT_ACTIVE_LOW_LEVEL);
#else
Chip_GPIO_SetupPinInt(LPC_GPIO, _panel_wiring[id].sensor_port, _panel_wiring[id].sensor_pin, GPIO_INT_ACTIVE_HIGH_LEVEL);
Chip_GPIO_ClearInts(LPC_GPIO, _panel_wiring[id].sensor_port, (1 << _panel_wiring[id].sensor_pin));
Chip_GPIO_EnableInt(LPC_GPIO, _panel_wiring[id].sensor_port, (1 << _panel_wiring[id].sensor_pin));
#endif
#endif
}
void panel_deinit(uint8_t id)
{
if (xTimerDelete(panel_conf[id].timer_open, 0) != pdFAIL)
{
panel_conf[id].timer_open = NULL;
}
if (xTimerDelete(panel_conf[id].timer_ok, 0) != pdFAIL)
{
panel_conf[id].timer_ok = NULL;
}
weigand_disable(_panel_wiring[id].acc_panel_port, _panel_wiring[id].acc_panel_d0_pin, _panel_wiring[id].acc_panel_d1_pin);
}
int8_t panel_get_request_from_buffer(uint32_t * user_id)
{
weigand26_buff_item_t item;
size_t bytes_got;
// Suspend if empty
bytes_got = xStreamBufferReceive(_reader_buffer, &item, WEIGAND26_BUFF_ITEM_SIZE, pdMS_TO_TICKS(portMAX_DELAY));
if (bytes_got == WEIGAND26_BUFF_ITEM_SIZE && weigand_is_parity_ok(item.frame))
{
*user_id = (item.frame.facility_code << 16) | item.frame.card_number;
return item.source;
}
else
{
return -1;
}
}
void panel_unlock(uint8_t id, bool with_beep, bool with_ok_led)
{
// Unlock state
if (with_beep)
{
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_beep_port, _panel_wiring[id].acc_panel_beep_pin, LOG_HIGH);
}
if (with_ok_led)
{
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_gled_port, _panel_wiring[id].acc_panel_gled_pin, LOG_HIGH);
}
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].acc_panel_rled_port, _panel_wiring[id].acc_panel_rled_pin, LOG_LOW);
configASSERT(xTimerStart(panel_conf[id].timer_open, 0));
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[id].relay_port, _panel_wiring[id].relay_pin, LOG_LOW);
configASSERT(xTimerStart(panel_conf[id].timer_ok, 0));
}
//GPIO port 0 handler
void PIOINT0_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT0_IRQn);
uint32_t int_states = Chip_GPIO_GetMaskedInts(LPC_GPIO, 0);
//Clear int flag on each pin
Chip_GPIO_ClearInts(LPC_GPIO, 0, 0xFFFFFFFF);
if (int_states & (1 << _panel_wiring[ACC_PANEL_A].sensor_pin))
{
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[ACC_PANEL_A].relay_port, _panel_wiring[ACC_PANEL_A].relay_pin, LOG_HIGH);
}
else if (int_states & (1 << _panel_wiring[ACC_PANEL_B].sensor_pin))
{
Chip_GPIO_SetPinState(LPC_GPIO, _panel_wiring[ACC_PANEL_B].relay_port, _panel_wiring[ACC_PANEL_B].relay_pin, LOG_HIGH);
}
else
{
return;
}
}
//GPIO port 1 handler
void PIOINT1_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT1_IRQn);
}
#include <reader.h>
static StreamBufferHandle_t _reader_buffer;
static const reader_wiring_t _reader_wiring[ACS_READER_MAXCOUNT] =
{
{
.data_port = ACS_READER_A_DATA_PORT,
.d0_pin = ACS_READER_A_D0_PIN,
.d1_pin = ACS_READER_A_D1_PIN,
.beep_port = ACS_READER_A_BEEP_PORT,
.beep_pin = ACS_READER_A_BEEP_PIN,
.gled_port = ACS_READER_A_GLED_PORT,
.gled_pin = ACS_READER_A_GLED_PIN,
.rled_port = ACS_READER_A_RLED_PORT,
.rled_pin = ACS_READER_A_RLED_PIN,
.relay_port = ACS_READER_A_RELAY_PORT,
.relay_pin = ACS_READER_A_RELAY_PIN,
.sensor_port = ACS_READER_A_SENSOR_PORT,
.sensor_pin = ACS_READER_A_SENSOR_PIN,
},
{
.data_port = ACS_READER_B_DATA_PORT,
.d0_pin = ACS_READER_B_D0_PIN,
.d1_pin = ACS_READER_B_D1_PIN,
.beep_port = ACS_READER_B_BEEP_PORT,
.beep_pin = ACS_READER_B_BEEP_PIN,
.gled_port = ACS_READER_B_GLED_PORT,
.gled_pin = ACS_READER_B_GLED_PIN,
.rled_port = ACS_READER_B_RLED_PORT,
.rled_pin = ACS_READER_B_RLED_PIN,
.relay_port = ACS_READER_B_RELAY_PORT,
.relay_pin = ACS_READER_B_RELAY_PIN,
.sensor_port = ACS_READER_B_SENSOR_PORT,
.sensor_pin = ACS_READER_B_SENSOR_PIN,
}
};
reader_conf_t reader_conf[ACS_READER_MAXCOUNT] =
{
{
.timer_ok = NULL,
.timer_open = NULL,
.open_time_sec = ACS_READER_A_OPEN_TIME_MS,
.gled_time_sec = ACS_READER_A_OK_GLED_TIME_MS,
.mode = READER_MODE_DEF,
.enabled = ACS_READER_A_ENABLED,
},
{
.timer_ok = NULL,
.timer_open = NULL,
.open_time_sec = ACS_READER_B_OPEN_TIME_MS,
.gled_time_sec = ACS_READER_B_OK_GLED_TIME_MS,
.mode = READER_MODE_DEF,
.enabled = ACS_READER_B_ENABLED,
}
};
static void reader_timer_open_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (uint32_t) pvTimerGetTimerID(pxTimer);
if (id < ACS_READER_COUNT)
{
// Lock state
Chip_GPIO_SetPinState(LPC_GPIO, _reader_wiring[id].relay_port, _reader_wiring[id].relay_pin, LOG_HIGH);
}
}
static void reader_timer_ok_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (uint32_t) pvTimerGetTimerID(pxTimer);
if (id < ACS_READER_COUNT)
{
// Lock state
Chip_GPIO_SetPinState(LPC_GPIO, _reader_wiring[id].beep_port, _reader_wiring[id].beep_pin, LOG_LOW);
Chip_GPIO_SetPinState(LPC_GPIO, _reader_wiring[id].gled_port, _reader_wiring[id].gled_pin, LOG_LOW);
Chip_GPIO_SetPinState(LPC_GPIO, _reader_wiring[id].rled_port, _reader_wiring[id].rled_pin, LOG_HIGH);
}
}
void reader_init(uint8_t id)
{
//Create stream buffer to receive id from all card readers
if (_reader_buffer == NULL)
{