Commit c5b9c974 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

Preparation for cache

parent 578447ec
......@@ -76,7 +76,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;Default&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;0x100&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"/>
......
......@@ -67,7 +67,6 @@ static void setup_hardware(void)
// can_driver_init();
terminal_init();
WDT_Init();
extern unsigned long _vStackTop[], _pvHeapStart[];
unsigned long ulInterruptStackSize;
......@@ -98,6 +97,8 @@ int main(void)
__enable_irq();
WDT_Init();
/* Start the kernel. From here on, only tasks and interrupts will run. */
vTaskStartScheduler();
......
/* Similar to Set Associative Cache.
* Divide into sets. Each set is one line a sorted array.
*
*/
#include <static_cache.h>
static term_cache_item_t _cache_set_0[STATIC_CACHE_CAPACITY / STATIC_CACHE_SETS];
static term_cache_item_t _cache_set_1[STATIC_CACHE_CAPACITY / STATIC_CACHE_SETS];
static term_cache_item_t _cache_set_2[STATIC_CACHE_CAPACITY / STATIC_CACHE_SETS];
static term_cache_item_t _cache_set_3[STATIC_CACHE_CAPACITY / STATIC_CACHE_SETS];
static term_cache_item_t * _cache_sets[STATIC_CACHE_SETS] = {_cache_set_0, _cache_set_1, _cache_set_2, _cache_set_3};
// O(1)
static inline term_cache_item_t * _get_cache_set(uint32_t key)
{
return _cache_sets[(key & 0xC00000) >> 22];
}
// O(log (STATIC_CACHE_CAPACITY / STATIC_CACHE_SETS))
term_cache_item_t static_cache_get(uint32_t key)
{
}
// O(log (STATIC_CACHE_CAPACITY / 4) + (STATIC_CACHE_CAPACITY / 4))
void static_cache_insert(uint32_t key)
{
}
// O(log (STATIC_CACHE_CAPACITY / 4) + (STATIC_CACHE_CAPACITY / 4))
void static_cache_erase(uint32_t key)
{
}
#ifndef STATIC_CACHE_H_
#define STATIC_CACHE_H_
#include <stdint.h>
#define STATIC_CACHE_SETS 4
#define STATIC_CACHE_CAPACITY (128 * STATIC_CACHE_SETS)
typedef struct
{
uint32_t user_id : 24;
uint32_t is_valid : 1;
uint32_t location : 2;
uint32_t : 5; // reserved for future
} term_cache_item_t; // 4B
#endif /* STATIC_CACHE_H_ */
......@@ -7,13 +7,13 @@
#include "terminal.h"
#include "board.h"
#include "weigand.h"
#include "static_cache.h"
#include "FreeRTOS.h"
#include "task.h"
#include "stream_buffer.h"
#include <stdio.h>
#include <string.h>
static void terminal_user_authorized(uint8_t panel_id)
{
// TODO
......
......@@ -11,7 +11,6 @@
#include <stdint.h>
#include "panel.h"
void terminal_init(void);
void terminal_reconfigure(panel_conf_t * panel_cfg, uint8_t id);
......
......@@ -74,7 +74,7 @@ extern uint32_t SystemCoreClock;
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define configTIMER_QUEUE_LENGTH 2
#define configTIMER_QUEUE_LENGTH 3
#define configTIMER_TASK_STACK_DEPTH ( 80 )
/* Set the following definitions to 1 to include the API function, or zero
......
......@@ -74,7 +74,7 @@ void panel_init(uint8_t id)
//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);
//Create timer
//Create timer only once
if (acc_panel[id].timer == NULL)
{
acc_panel[id].timer = xTimerCreate("PNL", (acc_panel[id].open_time_sec / portTICK_PERIOD_MS), pdFALSE, (void *)(uint32_t) id, panel_timer_callback);
......@@ -137,6 +137,6 @@ void panel_unlock(uint8_t id, bool with_beep, bool with_ok_led)
}
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);
configASSERT(xTimerStart(acc_panel[id].timer, 0));
}
......@@ -16,10 +16,10 @@
#define ACC_PANEL_1 1
#define ACC_PANEL_2 2
#pragma pack(push, 1)
typedef struct
{
uint8_t acc_panel_on : 1;
TimerHandle_t timer;
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;
......@@ -29,10 +29,8 @@ typedef struct
uint8_t acc_panel_gled_pin : 4;
uint8_t relay_port : 4;
uint8_t relay_pin : 4;
uint16_t open_time_sec;
TimerHandle_t timer;
uint8_t acc_panel_on : 1;
} panel_conf_t; //TOTAL SIZE 6B
#pragma pack(pop)
extern panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_COUNT];
......@@ -40,6 +38,7 @@ void panel_init(uint8_t id);
void panel_deinit(uint8_t id);
// user_id is 24-bit number
int8_t panel_get_request_from_buffer(uint32_t * user_id);
void panel_unlock(uint8_t id, bool with_beep, bool with_ok_led);
......
......@@ -8,34 +8,55 @@
* | even parity (1b) | facility code (8b) | card number (16b) | odd parity (1b) |
* transmission takes up-to ~52ms
*
*
* data pulse 50us
* data interval 2ms
*/
#include "weigand.h"
#include "board.h"
#include "timers.h"
#include <limits.h>
#include <assert.h>
typedef struct
{
weigand26_frame_t frame_buffer;
StreamBufferHandle_t consumer_buffer;
TimerHandle_t timer;
uint8_t frame_buffer_ptr;
uint8_t port;
uint8_t pin_d0;
uint8_t pin_d1;
uint8_t id;
StreamBufferHandle_t consumer_buffer;
} weigand26_t;
static weigand26_t device[WEIGAND_DEVICE_LIMIT];
static weigand26_t device[WEIGAND_DEVICE_LIMIT] = {0};
static void weigand_frame_timeout(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
// Which timer expired
uint32_t id = (int32_t) pvTimerGetTimerID(pxTimer);
portENTER_CRITICAL(); // Prevent weigand_int_handler from being invoked
if (device[id].frame_buffer_ptr != WEIGAND26_FRAME_SIZE)
{
// Empty the frame buffer
device[id].frame_buffer.value = 0;
device[id].frame_buffer_ptr = WEIGAND26_FRAME_SIZE;
}
portEXIT_CRITICAL();
}
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);
//Save device information
device[dx_port].consumer_buffer = buffer;
device[dx_port].port = dx_port;
device[dx_port].pin_d0 = d0_pin;
device[dx_port].pin_d1 = d1_pin;
......@@ -59,8 +80,12 @@ void weigand_init(StreamBufferHandle_t buffer, uint8_t id, uint8_t dx_port, uint
Chip_GPIO_ClearInts(LPC_GPIO, dx_port, (1 << d0_pin));
Chip_GPIO_ClearInts(LPC_GPIO, dx_port, (1 << d1_pin));
//Create stream
device[dx_port].consumer_buffer = buffer;
//Create timer
if (device[dx_port].timer == NULL)
{
device[dx_port].timer = xTimerCreate("WG", (WEIGAND26_FRAME_TIME_LIMIT / portTICK_PERIOD_MS), pdFALSE, (void *)(uint32_t) dx_port, weigand_frame_timeout);
}
configASSERT(device[dx_port].timer);
//Enable INT for both pins
Chip_GPIO_EnableInt(LPC_GPIO, dx_port, (1 << d0_pin) | (1 << d1_pin));
......@@ -98,6 +123,14 @@ bool weigand_is_parity_ok(weigand26_frame_t frame)
return even_parity == ((frame.value >> 25) & 0x1) && odd_parity == (frame.value & 0x1);
}
static inline void _wake_timer_on_frame_start(weigand26_t * device)
{
if (device->frame_buffer_ptr == WEIGAND26_FRAME_SIZE)
{
assert(xTimerStart(device->timer, 0)); // Restarts timer if still running
}
}
void weigand_int_handler(weigand26_t * device)
{
uint32_t int_states = Chip_GPIO_GetMaskedInts(LPC_GPIO, device->port);
......@@ -110,6 +143,7 @@ void weigand_int_handler(weigand26_t * device)
{
if (Chip_GPIO_ReadPortBit(LPC_GPIO, device->port, device->pin_d1) == 0)
{
_wake_timer_on_frame_start(device);
device->frame_buffer_ptr--;
device->frame_buffer.value |= (1 << device->frame_buffer_ptr);
}
......@@ -118,6 +152,7 @@ void weigand_int_handler(weigand26_t * device)
{
if (Chip_GPIO_ReadPortBit(LPC_GPIO, device->port, device->pin_d0) == 0)
{
_wake_timer_on_frame_start(device);
device->frame_buffer_ptr--;
device->frame_buffer.value &= ~(1 << device->frame_buffer_ptr);
}
......@@ -125,9 +160,10 @@ void weigand_int_handler(weigand26_t * device)
else // Clear other int on same port (FIXME)
{
Chip_GPIO_ClearInts(LPC_GPIO, device->port, 0xFFFFFFFF);
return;
}
//Whole frame received
if (device->frame_buffer_ptr == 0 && device->consumer_buffer != NULL)
if (device->frame_buffer_ptr == 0)
{
BaseType_t pxHigherPriorityTaskWoken = pdFALSE;
......@@ -192,9 +228,9 @@ void PIOINT2_IRQHandler(void)
void PIOINT3_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT3_IRQn);
if (device[2].consumer_buffer != NULL)
if (device[3].consumer_buffer != NULL)
{
weigand_int_handler(&device[2]);
weigand_int_handler(&device[3]);
}
}
......@@ -15,7 +15,7 @@
#include "stream_buffer.h"
#define WEIGAND26_FRAME_SIZE 26
#define WEIGAND26_FRAME_TIME_LIMIT 100 //ms
#define WEIGAND26_FRAME_TIME_LIMIT 80 // frame takes up to 52ms
typedef union
{
......@@ -28,7 +28,7 @@ typedef union
uint32_t : 6; //padding
};
uint32_t value;
} weigand26_frame_t;
} weigand26_frame_t; // 4B
// Buffer item type required from consumer of this driver to be used
typedef struct
......
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