Commit 43b14b12 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

Add panel module

parent 88346f9d
......@@ -70,7 +70,7 @@
<tool command="arm-none-eabi-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="com.crt.advproject.link.exe.debug.843938519" name="MCU Linker" superClass="com.crt.advproject.link.exe.debug">
<option id="com.crt.advproject.link.thumb.686732510" name="Thumb mode" superClass="com.crt.advproject.link.thumb" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.crt.advproject.link.memory.load.image.1714228801" name="Plain load image" superClass="com.crt.advproject.link.memory.load.image" useByScannerDiscovery="false" value="false;" valueType="string"/>
<option id="com.crt.advproject.link.memory.heapAndStack.657739555" name="Heap and Stack options" superClass="com.crt.advproject.link.memory.heapAndStack" useByScannerDiscovery="false" value="&amp;Heap:Default;Post Data;0x400&amp;Stack:Default;End;Default" valueType="string"/>
<option id="com.crt.advproject.link.memory.heapAndStack.657739555" name="Heap and Stack options" superClass="com.crt.advproject.link.memory.heapAndStack" useByScannerDiscovery="false" value="&amp;Heap:Default;Post Data;Default&amp;Stack:Default;End;Default" valueType="string"/>
<option id="com.crt.advproject.link.memory.data.1084767913" name="Global data placement" superClass="com.crt.advproject.link.memory.data" useByScannerDiscovery="false" value="Default" valueType="string"/>
<option id="com.crt.advproject.link.memory.sections.169757493" name="Extra linker script input sections" superClass="com.crt.advproject.link.memory.sections" useByScannerDiscovery="false" valueType="stringList"/>
<option id="com.crt.advproject.link.gcc.multicore.master.userobjs.540811877" name="Slave Objects (not visible)" superClass="com.crt.advproject.link.gcc.multicore.master.userobjs" useByScannerDiscovery="false" valueType="userObjs"/>
......
......@@ -9,7 +9,6 @@
*/
#include <terminal.h>
#include "board_config.h"
#include "board.h"
//#include "canopen_driver.h"
#include "FreeRTOS.h"
......
......@@ -72,7 +72,7 @@ extern uint32_t SystemCoreClock;
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 0
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 2
#define configTIMER_TASK_STACK_DEPTH ( 80 )
......
......@@ -76,10 +76,15 @@ extern "C" {
/* Board name */
#define BOARD_NXP_XPRESSO_11C24
/* Translator for IOCON */
extern const CHIP_IOCON_PIO_T CHIP_IOCON_PIO[][12];
/**
* @}
*/
#include "board_config.h"
#include "board_api.h"
#ifdef __cplusplus
......
......@@ -43,6 +43,69 @@
/* System oscillator rate and clock rate on the CLKIN pin */
const uint32_t OscRateIn = 12000000;
const uint32_t ExtRateIn = 0;
/* Translator for IOCON */
const CHIP_IOCON_PIO_T CHIP_IOCON_PIO[][12] =
{
{
IOCON_PIO0_0,
IOCON_PIO0_1,
IOCON_PIO0_2,
IOCON_PIO0_3,
IOCON_PIO0_4,
IOCON_PIO0_5,
IOCON_PIO0_6,
IOCON_PIO0_7,
IOCON_PIO0_8,
IOCON_PIO0_9,
IOCON_PIO0_10,
IOCON_PIO0_11,
},
{
IOCON_PIO1_0,
IOCON_PIO1_1,
IOCON_PIO1_2,
IOCON_PIO1_3,
IOCON_PIO1_4,
IOCON_PIO1_5,
IOCON_PIO1_6,
IOCON_PIO1_7,
IOCON_PIO1_8,
IOCON_PIO1_9,
IOCON_PIO1_10,
IOCON_PIO1_11,
},
{
IOCON_PIO2_0,
IOCON_PIO2_1,
IOCON_PIO2_2,
IOCON_PIO2_3,
IOCON_PIO2_4,
IOCON_PIO2_5,
IOCON_PIO2_6,
IOCON_PIO2_7,
IOCON_PIO2_8,
IOCON_PIO2_9,
IOCON_PIO2_10,
#if !defined(CHIP_LPC1125)
IOCON_PIO2_11,
#else
0,
#endif
},
{
IOCON_PIO3_0,
#if !defined(CHIP_LPC1125)
IOCON_PIO3_1,
#else
0,
#endif
IOCON_PIO3_2,
IOCON_PIO3_3,
IOCON_PIO3_4,
IOCON_PIO3_5,
0,
}
};
/*****************************************************************************
* Private functions
......
......@@ -32,7 +32,7 @@ extern unsigned int TERMINAL_UID[4];
#define DOOR_0_RELAY_PORT 0
#define DOOR_0_RELAY_PIN 0
#define DOOR_0_OPEN_TIME_SEC 10
#define DOOR_0_OPEN_TIME_MS 5000
//---------------------------------------------------------------------------------------------------------------------
//Default values for door 1
......@@ -49,7 +49,7 @@ extern unsigned int TERMINAL_UID[4];
#define DOOR_1_RELAY_PORT 0
#define DOOR_1_RELAY_PIN 0
#define DOOR_1_OPEN_TIME_SEC 10
#define DOOR_1_OPEN_TIME_MS 5000
//---------------------------------------------------------------------------------------------------------------------
//Default values for door 2
......@@ -59,18 +59,21 @@ extern unsigned int TERMINAL_UID[4];
#define DOOR_2_ACC_PANEL_PORT 3
#define DOOR_2_ACC_PANEL_D0_PIN 1
#define DOOR_2_ACC_PANEL_D1_PIN 2
#define DOOR_2_ACC_PANEL_BEEP_PORT 0
#define DOOR_2_ACC_PANEL_BEEP_PORT 2
#define DOOR_2_ACC_PANEL_BEEP_PIN 0
#define DOOR_2_ACC_PANEL_GLED_PORT 0
#define DOOR_2_ACC_PANEL_GLED_PIN 0
#define DOOR_2_ACC_PANEL_GLED_PORT 2
#define DOOR_2_ACC_PANEL_GLED_PIN 1
#define DOOR_2_RELAY_PORT 0
#define DOOR_2_RELAY_PIN 0
#define DOOR_2_OPEN_TIME_SEC 10
#define DOOR_2_RELAY_PORT 2
#define DOOR_2_RELAY_PIN 2
#define DOOR_2_OPEN_TIME_MS 5000
#define WEIGAND_DEVICE_LIMIT 3
#define SERIAL_DEVICE_LIMIT 0
#define DOOR_ACC_PANEL_MAX_COUNT (WEIGAND_DEVICE_LIMIT + SERIAL_DEVICE_LIMIT)
#define LOG_HIGH 1
#define LOG_LOW 0
#endif /* BSP_BOARD_CONFIG_H_ */
#include "panel.h"
static void panel_timer_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (int32_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);
}
void panel_init(uint8_t id)
{
//Create stream buffer
acc_panel[id].card_stream = xStreamBufferCreate(CONSUMER_BUFF_SIZE, CONSUMER_BUFF_SIZE);
configASSERT(acc_panel[id].card_stream);
//Init interface to reader
weigand_init(acc_panel[id].card_stream, acc_panel[id].acc_panel_port, acc_panel[id].acc_panel_d0_pin, acc_panel[id].acc_panel_d1_pin);
//Create timer
if (acc_panel[id].timer == NULL)
{
acc_panel[id].timer = xTimerCreate("PNL_TMR", (acc_panel[id].open_time_sec / portTICK_PERIOD_MS), pdFALSE, (void *)(uint32_t) id, panel_timer_callback);
}
configASSERT(acc_panel[id].timer);
//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_PULLUP, IOCON_FUNC0);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].acc_panel_gled_port, acc_panel[id].acc_panel_gled_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_PULLUP, 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, 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);
}
void panel_deinit(uint8_t id)
{
if (acc_panel[id].card_stream != NULL)
{
vStreamBufferDelete(acc_panel[id].card_stream);
acc_panel[id].card_stream = NULL;
}
if (xTimerDelete(acc_panel[id].timer, 0) != pdFAIL)
{
acc_panel[id].timer = NULL;
}
weigand_disable(acc_panel[id].acc_panel_port, acc_panel[id].acc_panel_d0_pin, acc_panel[id].acc_panel_d1_pin);
}
void panel_unlock(uint8_t id)
{
// Unlock state
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, acc_panel[id].acc_panel_gled_port, acc_panel[id].acc_panel_gled_pin, LOG_LOW);
Chip_GPIO_SetPinState(LPC_GPIO, acc_panel[id].relay_port, acc_panel[id].relay_pin, LOG_LOW);
//Start timer
xTimerStart(acc_panel[id].timer, 0);
}
#ifndef BSP_PANEL_H_
#define BSP_PANEL_H_
#include <stdint.h>
#include "board.h"
#include "FreeRTOS.h"
#include "stream_buffer.h"
#include "timers.h"
#include "weigand.h"
#define ACC_PANEL_0 0
#define ACC_PANEL_1 1
#define ACC_PANEL_2 2
#pragma pack(push, 1)
typedef struct
{
uint8_t acc_panel_on : 1;
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 open_time_sec;
StreamBufferHandle_t card_stream;
TimerHandle_t timer;
} panel_conf_t; //TOTAL SIZE 6B
#pragma pack(pop)
extern panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT];
void panel_init(uint8_t id);
void panel_deinit(uint8_t id);
void panel_unlock(uint8_t id);
#endif /* BSP_PANEL_H_ */
......@@ -5,19 +5,16 @@
*/
#include "terminal.h"
#include "board.h"
#include "weigand.h"
#include "board_config.h"
#include "FreeRTOS.h"
#include "task.h"
#include "stream_buffer.h"
#include <stdio.h>
#include <string.h>
#define ACC_PANEL_0 0
#define ACC_PANEL_1 1
#define ACC_PANEL_2 2
static StreamBufferHandle_t _cr_stream[DOOR_ACC_PANEL_MAX_COUNT] = {0};
static panel_conf_t _acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
{
{
.acc_panel_on = DOOR_0_ACC_PANEL_ON,
......@@ -30,7 +27,9 @@ static panel_conf_t _acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
.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_SEC,
.open_time_sec = DOOR_0_OPEN_TIME_MS,
.card_stream = NULL,
.timer = NULL,
},
{
.acc_panel_on = DOOR_1_ACC_PANEL_ON,
......@@ -43,7 +42,9 @@ static panel_conf_t _acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
.acc_panel_gled_pin = DOOR_1_ACC_PANEL_GLED_PIN,
.relay_port = DOOR_1_RELAY_PORT,
.relay_pin = DOOR_1_RELAY_PIN,
.open_time_sec = DOOR_1_OPEN_TIME_SEC,
.open_time_sec = DOOR_1_OPEN_TIME_MS,
.card_stream = NULL,
.timer = NULL,
},
{
.acc_panel_on = DOOR_2_ACC_PANEL_ON,
......@@ -56,24 +57,36 @@ static panel_conf_t _acc_panel[DOOR_ACC_PANEL_MAX_COUNT] =
.acc_panel_gled_pin = DOOR_2_ACC_PANEL_GLED_PIN,
.relay_port = DOOR_2_RELAY_PORT,
.relay_pin = DOOR_2_RELAY_PIN,
.open_time_sec = DOOR_2_OPEN_TIME_SEC,
.open_time_sec = DOOR_2_OPEN_TIME_MS,
.card_stream = NULL,
.timer = NULL,
}
};
static void terminal_process_card(uint8_t facility_code, uint16_t card_number, uint8_t reader_id)
static void terminal_user_authorized(uint8_t panel_id)
{
panel_unlock(panel_id);
}
static void terminal_user_not_authorized(uint8_t panel_id)
{
(void)panel_id;
}
static void terminal_process_card(uint8_t facility_code, uint16_t user_number, uint8_t panel_id)
{
#ifdef DEVEL_BOARD
printf("Facility: %u Card: %u Parity: %u\n", facility_code, card_number);
//printf("Facility: %u Card: %u Parity: %u\n", facility_code, user_number);
Board_LED_Set(1, true);
vTaskDelay(1000 / portTICK_PERIOD_MS);
Board_LED_Set(1, false);
if (facility_code == 12 && user_number == 27762) terminal_user_authorized(panel_id);
#endif
}
static void terminal_reader_task(void *pvParameters)
static void terminal_task(void *pvParameters)
{
//printf("test");
(void)pvParameters;
while (true)
......@@ -81,25 +94,25 @@ static void terminal_reader_task(void *pvParameters)
weigand26_frame_t card_data;
size_t bytes_got;
if (_acc_panel[ACC_PANEL_0].acc_panel_on)
if (acc_panel[ACC_PANEL_0].acc_panel_on)
{
bytes_got = xStreamBufferReceive(_cr_stream[0], &card_data, sizeof card_data, pdMS_TO_TICKS(0));
bytes_got = xStreamBufferReceive(acc_panel[ACC_PANEL_0].card_stream, &card_data, sizeof card_data, pdMS_TO_TICKS(0));
if (bytes_got == sizeof card_data && weigand_is_parity_ok(card_data))
{
terminal_process_card(card_data.facility_code, card_data.card_number, ACC_PANEL_0);
}
}
if (_acc_panel[ACC_PANEL_1].acc_panel_on)
if (acc_panel[ACC_PANEL_1].acc_panel_on)
{
bytes_got = xStreamBufferReceive(_cr_stream[1], &card_data, sizeof card_data, pdMS_TO_TICKS(0));
bytes_got = xStreamBufferReceive(acc_panel[ACC_PANEL_1].card_stream, &card_data, sizeof card_data, pdMS_TO_TICKS(0));
if (bytes_got == sizeof card_data && weigand_is_parity_ok(card_data))
{
terminal_process_card(card_data.facility_code, card_data.card_number, ACC_PANEL_1);
}
}
if (_acc_panel[ACC_PANEL_2].acc_panel_on)
if (acc_panel[ACC_PANEL_2].acc_panel_on)
{
bytes_got = xStreamBufferReceive(_cr_stream[2], &card_data, sizeof card_data, pdMS_TO_TICKS(0));
bytes_got = xStreamBufferReceive(acc_panel[ACC_PANEL_2].card_stream, &card_data, sizeof card_data, pdMS_TO_TICKS(0));
if (bytes_got == sizeof card_data && weigand_is_parity_ok(card_data))
{
terminal_process_card(card_data.facility_code, card_data.card_number, ACC_PANEL_2);
......@@ -110,36 +123,33 @@ static void terminal_reader_task(void *pvParameters)
void terminal_init(void)
{
for (int i = 0; i < DOOR_ACC_PANEL_MAX_COUNT; ++i)
for (size_t id = 0; id < DOOR_ACC_PANEL_MAX_COUNT; ++id)
{
if (_acc_panel[i].acc_panel_on) terminal_reconfigure(NULL, i);
if (acc_panel[id].acc_panel_on) terminal_reconfigure(NULL, id);
}
xTaskCreate(terminal_reader_task, "term_tsk", configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
xTaskCreate(terminal_task, "term_tsk", configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
}
void terminal_reconfigure(panel_conf_t * acc_panel, uint8_t id)
void terminal_reconfigure(panel_conf_t * panel_cfg, uint8_t panel_id)
{
if (id >= DOOR_ACC_PANEL_MAX_COUNT) return;
if (panel_id >= DOOR_ACC_PANEL_MAX_COUNT) return;
portENTER_CRITICAL();
if (acc_panel != NULL)
if (panel_cfg != NULL)
{
memcpy(&_acc_panel[id], acc_panel, sizeof(_acc_panel[id]));
memcpy(&acc_panel[panel_id], panel_cfg, sizeof(acc_panel[panel_id]));
//disable interface
panel_deinit(panel_id);
}
portEXIT_CRITICAL();
//reconfigure interface to card reader
if (acc_panel[id].acc_panel_on)
{
_cr_stream[id] = xStreamBufferCreate(CONSUMER_BUFF_SIZE, CONSUMER_BUFF_SIZE);
configASSERT(_cr_stream[id]);
weigand_init(_cr_stream[id], _acc_panel[id].acc_panel_port, _acc_panel[id].acc_panel_d0_pin, _acc_panel[id].acc_panel_d1_pin);
}
//disable interface
else
if (acc_panel[panel_id].acc_panel_on)
{
vStreamBufferDelete(_cr_stream[id]);
_cr_stream[id] = NULL;
weigand_disable(_acc_panel[id].acc_panel_port, _acc_panel[id].acc_panel_d0_pin, _acc_panel[id].acc_panel_d1_pin);
panel_init(panel_id);
}
portEXIT_CRITICAL();
}
......@@ -9,26 +9,11 @@
#define BSP_TERMINAL_H_
#include <stdint.h>
#include "panel.h"
#pragma pack(push, 1)
typedef struct
{
uint8_t acc_panel_on : 1;
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;
uint8_t open_time_sec : 8;
} panel_conf_t; //TOTAL SIZE 6B
#pragma pack(pop)
void terminal_init(void);
void terminal_reconfigure(panel_conf_t * acc_panel, uint8_t id);
void terminal_reconfigure(panel_conf_t * panel_cfg, uint8_t id);
#endif /* BSP_TERMINAL_H_ */
......@@ -11,8 +11,7 @@
*/
#include "weigand.h"
#include "chip.h"
#include "board_config.h"
#include "board.h"
#include <limits.h>
#include <assert.h>
......@@ -32,8 +31,8 @@ void weigand_init(StreamBufferHandle_t buffer, uint8_t dx_port, uint8_t d0_pin,
device[dx_port].frame_buffer_ptr = WEIGAND26_FRAME_SIZE;
//Enable pull-ups
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO3_1, IOCON_MODE_PULLUP);
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO3_2, IOCON_MODE_PULLUP);
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);
//Input mode
Chip_GPIO_SetPinDIRInput(LPC_GPIO, dx_port, d0_pin);
......
......@@ -204,7 +204,7 @@ typedef void (*PendedFunction_t)( void *, uint32_t );
* // Start the timer. No block time is specified, and even if one was
* // it would be ignored because the scheduler has not yet been
* // started.
* if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
* if( != pdPASS )
* {
* // The timer could not be set into the Active state.
* }
......
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