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

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);
}
}
......
This diff is collapsed.
......@@ -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)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment