Commit 647fedca authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

panels: add can message HW filters

parent 787e42bd
......@@ -128,34 +128,31 @@ void term_can_recv(uint8_t msg_obj_num)
uint8_t panel_id;
// get target door if message is for us
if (msg_obj.msgobj == ACS_MSGOBJ_RECV_DOOR_A) //TODO pouzit dva MSG OBJ pro A a B
if (msg_obj.msgobj == ACS_MSGOBJ_RECV_DOOR_A)
{
if (head.dst == ACC_PANEL_A_ADDR)
{
panel_id = ACC_PANEL_A;
DEBUGSTR("for door A\n");
}
else if (head.dst == ACC_PANEL_B_ADDR)
{
panel_id = ACC_PANEL_B;
DEBUGSTR("for door B\n");
}
else if (head.dst == ACS_BROADCAST_ADDR)
panel_id = ACC_PANEL_A;
DEBUGSTR("for door A\n");
}
else if (msg_obj.msgobj == ACS_MSGOBJ_RECV_DOOR_B)
{
panel_id = ACC_PANEL_B;
DEBUGSTR("for door B\n");
}
else if (msg_obj.msgobj == ACS_MSGOBJ_RECV_BCAST)
{
//broadcast message
if (head.fc == FC_ALIVE &&
head.src >= ACS_MSTR_FIRST_ADDR &&
head.src <= ACS_MSTR_LAST_ADDR)
{
if (head.fc == FC_ALIVE &&
head.src >= ACS_MSTR_FIRST_ADDR &&
head.src <= ACS_MSTR_LAST_ADDR)
{
// update master address if timeout occurred
portENTER_CRITICAL();
if (_master_timeout == true) _act_master = head.src;
_master_timeout = false;
portEXIT_CRITICAL();
DEBUGSTR("master alive\n");
}
return;
// update master address if timeout occurred
portENTER_CRITICAL();
if (_master_timeout == true) _act_master = head.src;
_master_timeout = false;
portEXIT_CRITICAL();
DEBUGSTR("master alive\n");
}
else return;
return;
}
else return;
......@@ -333,8 +330,9 @@ static void terminal_task(void *pvParameters)
void terminal_init(void)
{
//init CAN comm
/* CAN Callback Functions of on-chip drivers */
// init CAN driver
/* assign CAN callback functions of on-chip drivers */
CCAN_CALLBACKS_T term_can_callbacks =
{
term_can_recv, /* callback for any message received CAN frame which ID matches with any of the message objects' masks */
......@@ -348,19 +346,32 @@ void terminal_init(void)
};
CAN_init(&term_can_callbacks, CAN_BAUD_RATE);
CAN_recv_filter_set_eff(ACS_MSGOBJ_RECV_DOOR_A);
//CAN_recv_filter_set(ACS_MSGOBJ_RECV_DOOR_A, ACC_PANEL_A_ADDR << ACS_DST_ADDR_OFFSET, ACS_DST_ADDR_MASK);
//CAN_recv_filter_set(ACS_MSGOBJ_RECV_DOOR_B, ACC_PANEL_B_ADDR << ACS_DST_ADDR_OFFSET, ACS_DST_ADDR_MASK);
// CAN msg filter for door A
CAN_recv_filter(ACS_MSGOBJ_RECV_DOOR_A,
ACC_PANEL_A_ADDR << ACS_DST_ADDR_OFFSET,
ACS_DST_ADDR_MASK, true);
// CAN msg filter for door B
CAN_recv_filter(ACS_MSGOBJ_RECV_DOOR_B,
ACC_PANEL_B_ADDR << ACS_DST_ADDR_OFFSET,
ACS_DST_ADDR_MASK, true);
// CAN msg filter for broadcast
CAN_recv_filter(ACS_MSGOBJ_RECV_BCAST,
ACS_BROADCAST_ADDR << ACS_DST_ADDR_OFFSET,
ACS_DST_ADDR_MASK, true);
// initialize panels
for (size_t id = 0; id < DOOR_ACC_PANEL_COUNT; ++id)
{
if (panel_conf[id].enabled) terminal_reconfigure(NULL, id);
}
// create timer for master alive status timeout
_act_timer = xTimerCreate("MAT", (MASTER_ALIVE_TIMEOUT / portTICK_PERIOD_MS),
pdTRUE, (void *)_act_timer_id, _timer_callback);
configASSERT(_act_timer);
// create task for terminal loop
xTaskCreate(terminal_task, "term_tsk", configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
}
......
......@@ -11,9 +11,13 @@
__BSS(RESERVED) char CAN_driver_memory[184]; /* reserve 184 bytes for CAN driver */
#endif
//
#define CCAN_BCR_QUANTA(x) ((x) & 0x3F)
// Synch. Jump Width
#define CCAN_BCR_SJW(x) (((x) & 0x3) << 6)
// Time segment 1
#define CCAN_BCR_TSEG1(x) (((x) & 0x0F) << 8)
// Time segment 2
#define CCAN_BCR_TSEG2(x) (((x) & 0x07) << 12)
......@@ -64,22 +68,22 @@ static void _timing_calculate(uint32_t baud_rate, uint32_t * can_api_timing_cfg)
inline static void _100_kbaud_75sp(uint32_t * can_api_timing_cfg)
{
/* 100kb 75% sampling point, CAN_CLK tolerance X% */
/* 100kb 75% sampling point, CAN_CLK tolerance 5% */
/* Propagation time for UTP copper cable (0.64c) with maximum distance of 100 meter is 0.55us */
/* CANCLKDIV: CAN_CLK=48MHz */
/* CANBT register: TSEG1=14, TSEG2=5, SJW=4, BRP=X (actual value written is -1) */
//can_api_timing_cfg[0] = X;
//can_api_timing_cfg[1] = X;
//can_api_timing_cfg[0] = 0;
//can_api_timing_cfg[1] = CCAN_BCR_QUANTA(X) | CCAN_BCR_SJW(3) | CCAN_BCR_TSEG1(13) | CCAN_BCR_TSEG2(4);
}
inline static void _125_kbaud_75sp(uint32_t * can_api_timing_cfg)
{
/* 125kb 75%, CAN_CLK tolerance X% */
/* 125kb 75%, CAN_CLK tolerance 5% */
/* Propagation time for UTP copper cable (0.64c) with maximum distance of 100 meter is 0.55us */
/* CANCLKDIV: CAN_CLK=48MHz */
/* CANBT register: TSEG1=11, TSEG2=4, SJW=4, BRP=X (actual value written is -1) */
//can_api_timing_cfg[0] = X;
//can_api_timing_cfg[1] = X;
/* CANBT register: TSEG1=11, TSEG2=4, SJW=4, BRP=4 (actual value written is -1) */
//can_api_timing_cfg[0] = 0;
//can_api_timing_cfg[1] = CCAN_BCR_QUANTA(X) | CCAN_BCR_SJW(3) | CCAN_BCR_TSEG1(10) | CCAN_BCR_TSEG2(3);
}
/*****************************************************************************
......@@ -120,25 +124,32 @@ void CAN_init(CCAN_CALLBACKS_T * ptr_callbacks, uint32_t baud_rate)
NVIC_EnableIRQ(CAN_IRQn);
}
void CAN_recv_filter_set(uint8_t msgobj_num, uint32_t id, uint32_t mask)
// Configure Message object filter
// matches when <recieved_id> & mask == id & mask
void CAN_recv_filter(uint8_t msgobj_num, uint32_t id, uint32_t mask, bool extended)
{
CCAN_MSG_OBJ_T msg_obj = {0, };
/* Configure Message object filter */
if (extended == true)
{
id |= CAN_MSGOBJ_EXT;
mask |= CAN_MSGOBJ_EXT;
}
msg_obj.msgobj = msgobj_num;
msg_obj.mode_id = id;
msg_obj.mask = mask;
LPC_CCAN_API->config_rxmsgobj(&msg_obj);
}
void CAN_recv_filter_set_eff(uint8_t msgobj_num)
/* Configure Message object to receive all extended frames 0-0x1FFFFFFF */
void CAN_recv_filter_all_ext(uint8_t msgobj_num)
{
CCAN_MSG_OBJ_T msg_obj = {0, };
/* Configure Message object to receive all extended frames 0-0x1FFFFFFF */
msg_obj.msgobj = msgobj_num;
msg_obj.mode_id = CAN_MSGOBJ_EXT;
msg_obj.mask = 0x0;
msg_obj.mask = CAN_MSGOBJ_EXT;
LPC_CCAN_API->config_rxmsgobj(&msg_obj);
}
......
......@@ -16,8 +16,8 @@
#define CAN_DLC_MAX 8
void CAN_init(CCAN_CALLBACKS_T * ptr_callbacks, uint32_t baud_rate);
void CAN_recv_filter_set(uint8_t msgobj_num, uint32_t id, uint32_t mask);
void CAN_recv_filter_set_eff(uint8_t msgobj_num);
void CAN_recv_filter(uint8_t msgobj_num, uint32_t id, uint32_t mask, bool extended);
void CAN_recv_filter_all_ext(uint8_t msgobj_num);
void CAN_send_once(uint8_t msgobj_num, uint32_t id, uint8_t * data, uint8_t size);
void CAN_send_test(void);
......
......@@ -6,6 +6,7 @@
#define ACS_MSGOBJ_SEND_DOOR_B 1
#define ACS_MSGOBJ_RECV_DOOR_A 2
#define ACS_MSGOBJ_RECV_DOOR_B 3
#define ACS_MSGOBJ_RECV_BCAST 4
// HEAD partitions sizes
#define ACS_PRIO_BITS 3
......@@ -53,7 +54,7 @@
#define PRIO_PANEL_CTRL 0x3
#define PRIO_NEW_USER 0x3
#define PRIO_DOOR_STATUS 0x4
#define PRIO_ALIVE 0x4
#define PRIO_ALIVE 0x1
#define PANEL_CTRL_DATA_DEF 0x00
......
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