Commit 99336c53 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa
Browse files

add timer for gled + other

parent 8bcfd08f
......@@ -91,7 +91,7 @@ extern void vConfigureTimerForRunTimeStats(void);
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_QUEUE_LENGTH 8
#define configTIMER_TASK_STACK_DEPTH ( 80 )
/* Set the following definitions to 1 to include the API function, or zero
......
......@@ -20,17 +20,16 @@ typedef union
struct
{
uint32_t user_id : 24;
uint32_t panel0 : 1;
uint32_t panel1 : 1;
uint32_t panel2 : 1;
uint32_t : 5; // reserved for future
uint32_t panelA : 1;
uint32_t panelB : 1;
uint32_t : 6; // reserved for future
};
#pragma pack(pop)
cache_item_t as_cache_item;
uint32_t as_bitvalue;
}term_cache_item_t; // 4B
static bool _learn_mode_panel[3] = {false,false,false};
static uint32_t _learn_enable_user_id = 7632370;
static void terminal_user_authorized(uint8_t panel_id)
......@@ -51,21 +50,21 @@ static void terminal_user_identified(uint32_t user_id, uint8_t panel_id)
{
if (user_id == _learn_enable_user_id)
{
_learn_mode_panel[panel_id] = !_learn_mode_panel[panel_id];
panel_conf[panel_id].learn_mode = !panel_conf[panel_id].learn_mode;
return;
}
term_cache_item_t user;
user.user_id = user_id;
if (_learn_mode_panel[panel_id])
if (panel_conf[panel_id].learn_mode)
{
user.as_bitvalue |= _BIT(panel_id) << 24;
static_cache_insert(user.as_cache_item);
}
else if (static_cache_get(&user.as_cache_item))
{
if ((user.panel2 << 2 | user.panel1 << 1 | user.panel0) & _BIT(panel_id))
if ((user.panelB << 1 | user.panelA) & _BIT(panel_id))
{
terminal_user_authorized(panel_id);
return;
......@@ -85,7 +84,7 @@ static void terminal_task(void *pvParameters)
{
uint32_t user_id;
uint8_t panel_id = panel_get_request_from_buffer(&user_id);
if (panel_id > 0)
if (panel_id < DOOR_ACC_PANEL_COUNT)
{
terminal_user_identified(user_id, panel_id);
}
......@@ -94,9 +93,9 @@ static void terminal_task(void *pvParameters)
void terminal_init(void)
{
for (size_t id = 0; id < DOOR_ACC_PANEL_MAX_COUNT; ++id)
for (size_t id = 0; id < DOOR_ACC_PANEL_COUNT; ++id)
{
if (acc_panel[id].acc_panel_on) terminal_reconfigure(NULL, id);
if (panel_conf[id].acc_panel_on) terminal_reconfigure(NULL, id);
}
xTaskCreate(terminal_task, "term_tsk", configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
......@@ -115,16 +114,16 @@ void terminal_init(void)
void terminal_reconfigure(panel_conf_t * panel_cfg, uint8_t panel_id)
{
if (panel_id >= DOOR_ACC_PANEL_MAX_COUNT) return;
if (panel_id >= DOOR_ACC_PANEL_COUNT) return;
portENTER_CRITICAL();
if (panel_cfg != NULL)
{
memcpy(&acc_panel[panel_id], panel_cfg, sizeof(panel_conf_t));
memcpy(&panel_conf[panel_id], panel_cfg, sizeof(panel_conf_t));
//reconfigure interface to card reader
if (acc_panel[panel_id].acc_panel_on)
if (panel_conf[panel_id].acc_panel_on)
{
panel_init(panel_id);
}
......
......@@ -14,64 +14,63 @@
#define IAP_READ_UID 58
extern unsigned int TERMINAL_UID[5]; // 0 - status code, 1 - least significant word
//---------------------------------------------------------------------------------------------------------------------
// Values for door 0
//---------------------------------------------------------------------------------------------------------------------
#define DOOR_0_ACC_PANEL_ON false
#define DOOR_0_ACC_PANEL_PORT 1 // Port must be unique for each access panel (reader)
#define DOOR_0_ACC_PANEL_D0_PIN 1
#define DOOR_0_ACC_PANEL_D1_PIN 2
#define DOOR_0_ACC_PANEL_BEEP_PORT 0
#define DOOR_0_ACC_PANEL_BEEP_PIN 0
#define DOOR_0_ACC_PANEL_GLED_PORT 0
#define DOOR_0_ACC_PANEL_GLED_PIN 0
#define DOOR_0_RELAY_PORT 0
#define DOOR_0_RELAY_PIN 0
#define DOOR_0_OPEN_TIME_MS 3000
#define ACC_PANEL_A 0
#define ACC_PANEL_B 1
//---------------------------------------------------------------------------------------------------------------------
// Values for door 1
// Settings for panel A
//---------------------------------------------------------------------------------------------------------------------
#define DOOR_1_ACC_PANEL_ON true
#define DOOR_1_ACC_PANEL_PORT 2 // Port must be unique for each access panel (reader)
#define DOOR_1_ACC_PANEL_D0_PIN 7
#define DOOR_1_ACC_PANEL_D1_PIN 8
// Can be only 2 or 3.
#define DOOR_1_ACC_PANEL_D0_PIN 0
#define DOOR_1_ACC_PANEL_D1_PIN 6
#define DOOR_1_ACC_PANEL_BEEP_PORT 2
#define DOOR_1_ACC_PANEL_BEEP_PIN 3
#define DOOR_1_ACC_PANEL_BEEP_PIN 7
#define DOOR_1_ACC_PANEL_GLED_PORT 2
#define DOOR_1_ACC_PANEL_GLED_PIN 6
#define DOOR_1_RELAY_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 8
#define DOOR_1_RELAY_PORT 1
#define DOOR_1_RELAY_PIN 10
#define DOOR_1_OPEN_TIME_MS 2000
#define DOOR_1_SENSOR_PORT 0
#define DOOR_1_SENSOR_PIN 6
#define DOOR_1_OPEN_TIME_MS 8000
#define DOOR_1_OK_GLED_TIME_MS 2000
//---------------------------------------------------------------------------------------------------------------------
// Values for door 2
// Settings for panel B
//---------------------------------------------------------------------------------------------------------------------
#define DOOR_2_ACC_PANEL_ON true
#define DOOR_2_ACC_PANEL_PORT 3 // Port must be unique for each access panel (reader)
// Can be only 2 or 3.
#define DOOR_2_ACC_PANEL_D0_PIN 1
#define DOOR_2_ACC_PANEL_D1_PIN 2
#define DOOR_2_ACC_PANEL_BEEP_PORT 2
#define DOOR_2_ACC_PANEL_BEEP_PIN 0
#define DOOR_2_ACC_PANEL_BEEP_PIN 10
#define DOOR_2_ACC_PANEL_GLED_PORT 2
#define DOOR_2_ACC_PANEL_GLED_PIN 1
#define DOOR_2_RELAY_PORT 2
#define DOOR_2_RELAY_PIN 2
#define DOOR_2_OPEN_TIME_MS 2000
#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 0
#define DOOR_2_SENSOR_PIN 7
#define DOOR_2_OPEN_TIME_MS 8000
#define DOOR_2_OK_GLED_TIME_MS 2000
//---------------------------------------------------------------------------------------------------------------------
#define BEEP_ON_SUCCESS true
#define BEEP_ON_SUCCESS false
#define OK_LED_ON_SUCCESS true
#define WEIGAND_DEVICE_LIMIT 4
#define SERIAL_DEVICE_LIMIT 0
#define DOOR_ACC_PANEL_MAX_COUNT 3
#define DOOR_ACC_PANEL_COUNT 2
// IO
#define LOG_HIGH 1
......
......@@ -211,7 +211,7 @@ void CAN_rx(uint8_t msg_obj_num)
LPC_CCAN_API->can_receive(&msg_obj);
if (msg_obj_num == 1)
{
CAN_frame_callback(msg_obj.mode_id & CAN_EXT_ID_BIT_MASK, msg_obj.data, msg_obj.dlc);
//CAN_frame_callback(msg_obj.mode_id & CAN_EXT_ID_BIT_MASK, msg_obj.data, msg_obj.dlc);
}
}
......
......@@ -3,24 +3,9 @@
static StreamBufferHandle_t _reader_buffer;
panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
static const panel_wiring_t _panel_wiring[DOOR_ACC_PANEL_COUNT] =
{
{
.acc_panel_on = DOOR_0_ACC_PANEL_ON,
.acc_panel_port = DOOR_0_ACC_PANEL_PORT,
.acc_panel_d0_pin = DOOR_0_ACC_PANEL_D0_PIN,
.acc_panel_d1_pin = DOOR_0_ACC_PANEL_D1_PIN,
.acc_panel_beep_port = DOOR_0_ACC_PANEL_BEEP_PORT,
.acc_panel_beep_pin = DOOR_0_ACC_PANEL_BEEP_PIN,
.acc_panel_gled_port = DOOR_0_ACC_PANEL_GLED_PORT,
.acc_panel_gled_pin = DOOR_0_ACC_PANEL_GLED_PIN,
.relay_port = DOOR_0_RELAY_PORT,
.relay_pin = DOOR_0_RELAY_PIN,
.open_time_sec = DOOR_0_OPEN_TIME_MS,
.timer = NULL,
},
{
.acc_panel_on = DOOR_1_ACC_PANEL_ON,
.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,
......@@ -28,13 +13,14 @@ panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
.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,
.open_time_sec = DOOR_1_OPEN_TIME_MS,
.timer = NULL,
.sensor_port = DOOR_1_SENSOR_PORT,
.sensor_pin = DOOR_1_SENSOR_PIN,
},
{
.acc_panel_on = DOOR_2_ACC_PANEL_ON,
.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,
......@@ -42,69 +28,138 @@ panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
.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_COUNT] =
{
{
.timer_ok = NULL,
.timer_open = NULL,
.acc_panel_on = DOOR_1_ACC_PANEL_ON,
.open_time_sec = DOOR_1_OPEN_TIME_MS,
.gled_time_sec = DOOR_1_OK_GLED_TIME_MS,
.learn_mode = false,
},
{
.timer_ok = NULL,
.timer_open = NULL,
.acc_panel_on = DOOR_2_ACC_PANEL_ON,
.open_time_sec = DOOR_2_OPEN_TIME_MS,
.timer = NULL,
.gled_time_sec = DOOR_2_OK_GLED_TIME_MS,
.learn_mode = false,
}
};
static void panel_timer_callback(TimerHandle_t pxTimer)
static void panel_timer_open_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (int32_t) pvTimerGetTimerID(pxTimer);
uint32_t id = (uint32_t) pvTimerGetTimerID(pxTimer);
// Lock state
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].acc_panel_beep_port, acc_panel[id].acc_panel_beep_pin, LOG_HIGH);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].acc_panel_gled_port, acc_panel[id].acc_panel_gled_pin, LOG_HIGH);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].relay_port, acc_panel[id].relay_pin, LOG_HIGH);
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(WEIGAND_DEVICE_LIMIT * WEIGAND26_BUFF_ITEM_SIZE, WEIGAND26_BUFF_ITEM_SIZE);
_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, acc_panel[id].acc_panel_port, acc_panel[id].acc_panel_d0_pin, acc_panel[id].acc_panel_d1_pin);
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 (acc_panel[id].timer == NULL)
if (panel_conf[id].timer_open == NULL)
{
acc_panel[id].timer = xTimerCreate("PNL", (acc_panel[id].open_time_sec / portTICK_PERIOD_MS), pdFALSE, (void *)(uint32_t) id, panel_timer_callback);
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(acc_panel[id].timer);
configASSERT(panel_conf[id].timer_open);
//Setup LED
Chip_GPIO_SetPinDIROutput(LPC_GPIO, acc_panel[id].acc_panel_gled_port, acc_panel[id].acc_panel_gled_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[acc_panel[id].acc_panel_gled_port][acc_panel[id].acc_panel_gled_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].acc_panel_gled_port, acc_panel[id].acc_panel_gled_pin, LOG_HIGH);
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, acc_panel[id].acc_panel_beep_port, acc_panel[id].acc_panel_beep_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[acc_panel[id].acc_panel_beep_port][acc_panel[id].acc_panel_beep_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].acc_panel_beep_port, acc_panel[id].acc_panel_beep_pin, LOG_HIGH);
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, acc_panel[id].relay_port, acc_panel[id].relay_pin);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[acc_panel[id].relay_port][acc_panel[id].relay_pin], IOCON_MODE_PULLUP, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].relay_port, acc_panel[id].relay_pin, LOG_HIGH);
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(acc_panel[id].timer, 0) != pdFAIL)
if (xTimerDelete(panel_conf[id].timer_open, 0) != pdFAIL)
{
acc_panel[id].timer = NULL;
panel_conf[id].timer_open = NULL;
}
if (xTimerDelete(panel_conf[id].timer_ok, 0) != pdFAIL)
{
panel_conf[id].timer_ok = NULL;
}
weigand_disable(acc_panel[id].acc_panel_port, acc_panel[id].acc_panel_d0_pin, acc_panel[id].acc_panel_d1_pin);
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)
......@@ -120,8 +175,10 @@ int8_t panel_get_request_from_buffer(uint32_t * user_id)
*user_id = (item.frame.facility_code << 16) | item.frame.card_number;
return item.source;
}
return -1;
else
{
return -1;
}
}
void panel_unlock(uint8_t id, bool with_beep, bool with_ok_led)
......@@ -129,14 +186,44 @@ void panel_unlock(uint8_t id, bool with_beep, bool with_ok_led)
// Unlock state
if (with_beep)
{
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].acc_panel_beep_port, acc_panel[id].acc_panel_beep_pin, LOG_LOW);
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, acc_panel[id].acc_panel_gled_port, acc_panel[id].acc_panel_gled_pin, LOG_LOW);
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, acc_panel[id].relay_port, acc_panel[id].relay_pin, LOG_LOW);
//Start timer
configASSERT(xTimerStart(acc_panel[id].timer, 0));
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);
}
......@@ -12,27 +12,35 @@
#include "timers.h"
#include "weigand.h"
#define ACC_PANEL_0 0
#define ACC_PANEL_1 1
#define ACC_PANEL_2 2
typedef struct
{
TimerHandle_t timer;
TimerHandle_t timer_open;
TimerHandle_t timer_ok;
uint16_t open_time_sec;
uint8_t acc_panel_port : 4;
uint8_t acc_panel_d0_pin : 4;
uint8_t acc_panel_d1_pin : 4;
uint8_t acc_panel_beep_port : 4;
uint8_t acc_panel_beep_pin : 4;
uint8_t acc_panel_gled_port : 4;
uint8_t acc_panel_gled_pin : 4;
uint8_t relay_port : 4;
uint8_t relay_pin : 4;
uint16_t gled_time_sec;
uint8_t acc_panel_on : 1;
} panel_conf_t; //TOTAL SIZE 6B
uint8_t learn_mode : 1;
} panel_conf_t; //TOTAL SIZE 12B
extern panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT];
typedef struct
{
uint8_t acc_panel_port;
uint8_t acc_panel_d0_pin;
uint8_t acc_panel_d1_pin;
uint8_t acc_panel_beep_port;
uint8_t acc_panel_beep_pin;
uint8_t acc_panel_gled_port;
uint8_t acc_panel_gled_pin;
uint8_t acc_panel_rled_port;
uint8_t acc_panel_rled_pin;
uint8_t relay_port;
uint8_t relay_pin;
uint8_t sensor_port;
uint8_t sensor_pin;
} panel_wiring_t;
extern panel_conf_t panel_conf[DOOR_ACC_PANEL_COUNT];
void panel_init(uint8_t id);
......
......@@ -52,7 +52,7 @@ static void weigand_frame_timeout(TimerHandle_t pxTimer)
void weigand_init(StreamBufferHandle_t buffer, uint8_t id, uint8_t dx_port, uint8_t d0_pin, uint8_t d1_pin)
{
configASSERT(dx_port < WEIGAND_DEVICE_LIMIT);
configASSERT(dx_port == 2 || dx_port == 3);
//Save device information
device[dx_port].consumer_buffer = buffer;
......@@ -63,9 +63,9 @@ void weigand_init(StreamBufferHandle_t buffer, uint8_t id, uint8_t dx_port, uint
device[dx_port].frame_buffer_ptr = WEIGAND26_FRAME_SIZE;
device[dx_port].id = id;
//Enable pull-ups
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[dx_port][d0_pin], IOCON_MODE_PULLUP, IOCON_FUNC0);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[dx_port][d1_pin], IOCON_MODE_PULLUP, IOCON_FUNC0);
//Normal function
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[dx_port][d0_pin], IOCON_MODE_INACT, IOCON_FUNC0);
Chip_IOCON_PinMux(LPC_IOCON, CHIP_IOCON_PIO[dx_port][d1_pin], IOCON_MODE_INACT, IOCON_FUNC0);
// LPC_GPIO is initialized in board.c
......@@ -94,6 +94,8 @@ void weigand_init(StreamBufferHandle_t buffer, uint8_t id, uint8_t dx_port, uint
void weigand_disable(uint8_t dx_port, uint8_t d0_pin, uint8_t d1_pin)
{
configASSERT(dx_port == 2 || dx_port == 3);
Chip_GPIO_DisableInt(LPC_GPIO, dx_port, (1 << d0_pin) | (1 << d1_pin));
}
......@@ -135,9 +137,8 @@ static inline void _wake_timer_on_frame_start(weigand26_t * device)
void weigand_int_handler(weigand26_t * device)
{
uint32_t int_states = Chip_GPIO_GetMaskedInts(LPC_GPIO, device->port);
//Clear int flag on each pin
Chip_GPIO_ClearInts(LPC_GPIO, device->port, (1 << device->pin_d1));
Chip_GPIO_ClearInts(LPC_GPIO, device->port, (1 << device->pin_d0));
//Clear int flag on all pins
Chip_GPIO_ClearInts(LPC_GPIO, device->port, 0xFFFFFFFF);
//Resolve pin
if (int_states & (1 << device->pin_d1)) // 0's
......@@ -158,9 +159,8 @@ void weigand_int_handler(weigand26_t * device)
device->frame_buffer.value &= ~(1 << device->frame_buffer_ptr);
}
}
else // Clear other pin int (no other GPIO pins expected to cause int)
else
{
Chip_GPIO_ClearInts(LPC_GPIO, device->port, 0xFFFFFFFF);
return;
}
//Whole frame received
......@@ -195,25 +195,7 @@ void weigand_int_handler(weigand26_t * device)
}
}
//GPIO port 0 handler
void PIOINT0_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT1_IRQn);
if (device[0].consumer_buffer != NULL)
{
weigand_int_handler(&device[0]);
}
}
//GPIO port 1 handler
void PIOINT1_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT1_IRQn);
if (device[1].consumer_buffer != NULL)
{
weigand_int_handler(&device[1]);
}
}
//GPIO port 2 handler
void PIOINT2_IRQHandler(void)
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.crt.dsfdebug.crtmcu.launchType">
<stringAttribute key=".gdbinit" value=""/>
<stringAttribute key="com.crt.ctrlcenter.OFSemuDetails" value="LinkServer"/>
<booleanAttribute key="com.crt.ctrlcenter.crtInit" value="true"/>
<stringAttribute key="com.crt.ctrlcenter.currentWireType" value="SWD"/>
<booleanAttribute key="com.crt.ctrlcenter.mainBreakIsHardware" value="true"/>
<booleanAttribute key="com.crt.ctrlcenter.saveState" value="true"/>
<stringAttribute key="com.crt.ctrlcenter.serialNumber" value="LinkServerNXPNXP CMSIS-DAPUNKNOWN_SERIAL"/>
<stringAttribute key="com.crt.ctrlcenter.targetbase" value="NXP LPC11xx (*)"/>
<stringAttribute key="com.crt.ctrlcenter.targetconfig" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;config chipvendor=&quot;NXP&quot; genname=&quot;NXP LPC11xx&quot; id=&quot;config.gdb.stub&quot;&gt;&lt;parameters&gt;&lt;params&gt;&lt;param default=&quot;true&quot; description=&quot;Vector catch&quot; name=&quot;Vector catch&quot; value=&quot;False&quot; var=&quot;vector.catch&quot;&gt;&lt;enum value=&quot;True&quot;/&gt;&#13;&#10;&lt;enum value=&quot;False&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;/params&gt;&#13;&#10;&lt;initValue value=&quot;false&quot; var=&quot;vector.catch&quot;/&gt;&#13;&#10;&lt;params&gt;&lt;param default=&quot;On&quot; description=&quot;Enablement of semihosting support&quot; name=&quot;Semihosting support&quot; value=&quot;On&quot; var=&quot;internal.semihost&quot;&gt;&lt;enum value=&quot;On&quot;/&gt;&#13;&#10;&lt;enum value=&quot;Off&quot;/&gt;&#13;&#10;&lt;enum value=&quot;Auto&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;/params&gt;&#13;&#10;&lt;params&gt;&lt;param default=&quot;&quot; description=&quot;Maximum wire speed in KHz (leave blank to Auto-detect). Not all values are supported by all targets&quot; name=&quot;Maximum wire speed&quot; probe=&quot;^(?!Redlink Server|LinkServer$).*$&quot; type=&quot;nullString&quot; value=&quot;&quot; var=&quot;emu.speed&quot;&gt;&lt;enum value=&quot;&quot;/&gt;&#13;&#10;&lt;enum value=&quot;30000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;15000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;10000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;7500&quot;/&gt;&#13;&#10;&lt;enum value=&quot;6000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;5000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;3750&quot;/&gt;&#13;&#10;&lt;enum value=&quot;3000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;2500&quot;/&gt;&#13;&#10;&lt;enum value=&quot;2000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;1500&quot;/&gt;&#13;&#10;&lt;enum value=&quot;1250&quot;/&gt;&#13;&#10;&lt;enum value=&quot;1200&quot;/&gt;&#13;&#10;&lt;enum value=&quot;1000&quot;/&gt;&#13;&#10;&lt;enum value=&quot;750&quot;/&gt;&#13;&#10;&lt;enum value=&quot;600&quot;/&gt;&#13;&#10;&lt;enum value=&quot;500&quot;/&gt;&#13;&#10;&lt;enum value=&quot;400&quot;/&gt;&#13;&#10;&lt;enum value=&quot;300&quot;/&gt;&#13;&#10;&lt;enum value=&quot;250&quot;/&gt;&#13;&#10;&lt;enum value=&quot;200&quot;/&gt;&#13;&#10;&lt;enum value=&quot;150&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;/params&gt;&#13;&#10;&lt;params&gt;&lt;param content=&quot;serverScript&quot; description=&quot;Connect script&quot; name=&quot;Connect Script&quot; probe=&quot;(?i)(Redlink\s+Server|CMSIS-DAP|LinkServer)&quot; required=&quot;false&quot; type=&quot;nullString&quot; value=&quot;&quot; var=&quot;internal.connect.script&quot;/&gt;&#13;&#10;&lt;param content=&quot;serverScript&quot; description=&quot;Reset script&quot; name=&quot;Reset Script&quot; probe=&quot;(?i)(Redlink\s+Server|CMSIS-DAP|LinkServer)&quot; required=&quot;false&quot; type=&quot;nullString&quot; value=&quot;&quot; var=&quot;internal.reset.script&quot;/&gt;&#13;&#10;&lt;param default=&quot;&quot; description=&quot;Select the reset handling type for this debug connection&quot; name=&quot;Reset Handling&quot; probe=&quot;(?i)(Redlink\s+Server|CMSIS-DAP|LinkServer)&quot; value=&quot;&quot; var=&quot;internal.resethandling&quot;&gt;&lt;enum value=&quot;Default&quot;/&gt;&#13;&#10;&lt;enum value=&quot;SYSRESETREQ&quot;/&gt;&#13;&#10;&lt;enum value=&quot;VECTRESET&quot;/&gt;&#13;&#10;&lt;enum value=&quot;SOFT&quot;/&gt;&#13;&#10;&lt;enum value=&quot;&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;&quot; description=&quot;Select the reset handling type for this debug connection before running a flash driver&quot; name=&quot;Flash Driver Reset Handling&quot; probe=&quot;(?i)(Redlink\s+Server|CMSIS-DAP|LinkServer)&quot; value=&quot;&quot; var=&quot;flash.driver.reset&quot;&gt;&lt;enum value=&quot;Default&quot;/&gt;&#13;&#10;&lt;enum value=&quot;VECTRESET&quot;/&gt;&#13;&#10;&lt;enum value=&quot;SYSRESETREQ&quot;/&gt;&#13;&#10;&lt;enum value=&quot;SOFT&quot;/&gt;&#13;&#10;&lt;enum value=&quot;&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;&quot; description=&quot;Additional options&quot; name=&quot;Additional options&quot; value=&quot;&quot; var=&quot;misc.options&quot;/&gt;&#13;&#10;&lt;param default=&quot;2&quot; description=&quot;Set stub debug level (1-4)&quot; name=&quot;Debug Level &quot; value=&quot;2&quot; var=&quot;debug.level&quot;/&gt;&#13;&#10;&lt;param default=&quot;False&quot; description=&quot;when True, attach to running target only (without loading image)&quot; name=&quot;Attach only&quot; required=&quot;true&quot; value=&quot;True&quot; var=&quot;attach&quot;&gt;&lt;enum value=&quot;True&quot;/&gt;&#13;&#10;&lt;enum value=&quot;False&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;True&quot; description=&quot;Deprecated. Functionality superseded by &amp;apos;Attach only&amp;apos;&quot; name=&quot;Load image&quot; type=&quot;boolean&quot; value=&quot;False&quot; var=&quot;load&quot;&gt;&lt;enum value=&quot;True&quot;/&gt;&#13;&#10;&lt;enum value=&quot;False&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;cont&quot; description=&quot;Run, continue or (do nothing)&quot; name=&quot;Run/Continue image&quot; value=&quot;cont&quot; var=&quot;run&quot;&gt;&lt;enum value=&quot;run&quot;/&gt;&#13;&#10;&lt;enum value=&quot;cont&quot;/&gt;&#13;&#10;&lt;enum value=&quot;&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;off&quot; description=&quot;If on is specified, make the debugger treat unknown memory as non-existent and refuse \naccesses to such memory. If off is specified, treat the memory as RAM&quot; name=&quot;Memory Access Checking&quot; value=&quot;off&quot; var=&quot;mem.access&quot;&gt;&lt;enum value=&quot;on&quot;/&gt;&#13;&#10;&lt;enum value=&quot;off&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;cont&quot; description=&quot;choose the disconnect behavior for the target&quot; name=&quot;Disconnect behavior&quot; value=&quot;cont&quot; var=&quot;ondisconnect&quot;&gt;&lt;enum value=&quot;nochange&quot;/&gt;&#13;&#10;&lt;enum value=&quot;stop&quot;/&gt;&#13;&#10;&lt;enum value=&quot;cont&quot;/&gt;&#13;&#10;&lt;enum value=&quot;run_cont&quot;/&gt;&#13;&#10;&lt;/param&gt;&#13;&#10;&lt;param default=&quot;&quot; description=&quot;Command to run before starting the debugger&quot; name=&quot;Pre launch command&quot; value=&quot;&quot; var=&quot;internal.prelaunch.command&am