Commit 578447ec authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

Use watchdog and other optimalizations

parent 15bc246c
This diff is collapsed.
//*****************************************************************************
// crp.c
//
// Code Read Protect
// Source file to create CRP word expected by LPCXpresso IDE linker
//*****************************************************************************
//
......
/*
===============================================================================
Name : main.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
===============================================================================
Main startup sequence
*/
#include <terminal.h>
#include "terminal.h"
#include "board.h"
//#include "canopen_driver.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
#include "watchdog.h"
/*****************************************************************************
* Private types/enumerations/variables
......@@ -24,11 +19,25 @@
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
unsigned int TERMINAL_UID[4] = {0, 0, 0, 0};
unsigned int TERMINAL_UID[5] = {0, 0, 0, 0, 0};
/*****************************************************************************
* Private functions
****************************************************************************/
#ifdef DEVEL_BOARD
static void alive_task(void *pvParameters)
{
(void *) pvParameters;
Board_LED_Set(0, true);
while (1)
{
vTaskDelay(1500 / portTICK_PERIOD_MS);
Board_LED_Toggle(0);
DEBUGSTR("tick\n");
}
}
#endif //DEVEL_BOARD
static void setup_hardware(void)
{
......@@ -39,9 +48,10 @@ static void setup_hardware(void)
Board_Init();
#ifdef DEVEL_BOARD
Board_LED_Set(0, false);
Board_LED_Set(1, false);
Board_LED_Set(2, false);
Board_LED_Set(0, false);
Board_LED_Set(1, false);
Board_LED_Set(2, false);
xTaskCreate(alive_task, "alv_tsk",configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
#endif
//Read UID
......@@ -54,9 +64,10 @@ static void setup_hardware(void)
NVIC_EnableIRQ(EINT2_IRQn);
NVIC_EnableIRQ(EINT3_IRQn);
// Initialize terminal ability
//can_driver_init();
// can_driver_init();
terminal_init();
WDT_Init();
extern unsigned long _vStackTop[], _pvHeapStart[];
unsigned long ulInterruptStackSize;
......@@ -75,16 +86,6 @@ static void setup_hardware(void)
}
static void alive_task(void *pvParameters)
{
Board_LED_Set(0, true);
while (1)
{
vTaskDelay(1500 / portTICK_PERIOD_MS);
Board_LED_Toggle(0);
}
}
/*****************************************************************************
* Public functions
****************************************************************************/
......@@ -95,8 +96,6 @@ int main(void)
setup_hardware();
xTaskCreate(alive_task, "alv_tsk",configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
__enable_irq();
/* Start the kernel. From here on, only tasks and interrupts will run. */
......@@ -132,6 +131,8 @@ void vApplicationIdleHook(void)
important that vApplicationIdleHook() is permitted to return to its calling
function, because it is the responsibility of the idle task to clean up
memory allocated by the kernel to any task that has since been deleted. */
WDT_Feed(); // Feed HW watchdog
}
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
......
......@@ -14,52 +14,6 @@
#include <string.h>
panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_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,
.acc_panel_beep_port = DOOR_1_ACC_PANEL_BEEP_PORT,
.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,
.relay_port = DOOR_1_RELAY_PORT,
.relay_pin = DOOR_1_RELAY_PIN,
.open_time_sec = DOOR_1_OPEN_TIME_MS,
.timer = NULL,
},
{
.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,
.acc_panel_beep_port = DOOR_2_ACC_PANEL_BEEP_PORT,
.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,
.relay_port = DOOR_2_RELAY_PORT,
.relay_pin = DOOR_2_RELAY_PIN,
.open_time_sec = DOOR_2_OPEN_TIME_MS,
.timer = NULL,
}
};
static void terminal_user_authorized(uint8_t panel_id)
{
// TODO
......
......@@ -35,9 +35,14 @@ void WDT_IRQHandler(void)
{
uint32_t wdtStatus = Chip_WWDT_GetStatus(LPC_WWDT);
if (wdtStatus & WWDT_WDMOD_WDTOF) {
//DO smth
while(Chip_WWDT_GetStatus(LPC_WWDT) & WWDT_WDMOD_WDTOF) {
if (wdtStatus & WWDT_WDMOD_WDTOF)
{
#ifdef DEBUG_ENABLE
DEBUGSTR("WDT\n");
#endif //DEBUG_ENABLE
// Restart WDT
while(Chip_WWDT_GetStatus(LPC_WWDT) & WWDT_WDMOD_WDTOF)
{
Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF);
}
Chip_WWDT_Start(LPC_WWDT); /* Needs restart */
......@@ -55,9 +60,9 @@ void WDT_Init(void)
Chip_WWDT_Init(LPC_WWDT);
/* Prior to initializing the watchdog driver, the clocking for the
watchdog must be enabled. This example uses the watchdog oscillator
set at a 50KHz (1Mhz / 20) clock rate. */
watchdog must be enabled. */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_WDTOSC_PD);
/* The watchdog oscillator will be set at a 50KHz (1Mhz / 20) clock rate. */
Chip_Clock_SetWDTOSC(WDTLFO_OSC_1_05, 20);
/* The WDT divides the input frequency into it by 4 */
......@@ -78,6 +83,11 @@ void WDT_Init(void)
NVIC_ClearPendingIRQ(WDT_IRQn);
NVIC_EnableIRQ(WDT_IRQn);
#ifdef RELEASE
/* Watchdog will cause reset on production version */
Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDRESET);
#endif
/* Start watchdog */
Chip_WWDT_Start(LPC_WWDT);
}
......
......@@ -45,11 +45,11 @@
extern uint32_t SystemCoreClock;
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 6 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2048 + 1024 ) )
#define configMAX_TASK_NAME_LEN ( 8 )
......@@ -73,13 +73,13 @@ extern uint32_t SystemCoreClock;
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define configTIMER_QUEUE_LENGTH 2
#define configTIMER_TASK_STACK_DEPTH ( 80 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskCleanUpResources 1
......
......@@ -43,6 +43,7 @@
/* 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] =
{
......@@ -162,6 +163,8 @@ void Board_Debug_Init(void)
#endif
}
#ifdef DEVEL_BOARD
/* Initializes board LED(s) */
static void Board_LED_Init(void)
{
......@@ -207,6 +210,8 @@ void Board_LED_Toggle(uint8_t LEDNumber)
Chip_GPIO_SetPinToggle(LPC_GPIO, 0, 9);
}
#endif // DEVEL_BOARD
/* Set up and initialize all required blocks and functions related to the
board hardware */
void Board_Init(void)
......@@ -217,6 +222,8 @@ void Board_Init(void)
/* Initialize GPIO */
Chip_GPIO_Init(LPC_GPIO);
#ifdef DEVEL_BOARD
/* Initialize LEDs */
Board_LED_Init();
#endif // DEVEL_BOARD
}
......@@ -51,17 +51,18 @@ extern "C" {
* This board has options that configure its operation at build-time.<br>
*/
#ifdef DEBUG
/** Define DEBUG_ENABLE to enable IO via the DEBUGSTR, DEBUGOUT, and
DEBUGIN macros. If not defined, DEBUG* functions will be optimized
out of the code at build time.
*/
//#define DEBUG_ENABLE
#define DEBUG_ENABLE
/** Define DEBUG_SEMIHOSTING along with DEBUG_ENABLE to enable IO support
via semihosting. You may need to use a C library that supports
semihosting with this option.
*/
#define DEBUG_SEMIHOSTING
#undef DEBUG_SEMIHOSTING
/** Board UART used for debug output and input using the DEBUG* macros. This
is also the port used for Board_UARTPutChar, Board_UARTGetChar, and
......@@ -69,21 +70,16 @@ extern "C" {
*/
#define DEBUG_UART LPC_USART
/**
* @}
*/
#endif // DEBUG
/* 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 "terminal_config.h"
#include "board_api.h"
......
......@@ -113,7 +113,7 @@ STATIC void SystemSetupClocking(void)
/* Sets up system pin muxing */
STATIC void SystemSetupMuxing(void)
{
int i;
size_t i;
/* Enable IOCON clock */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
......
......@@ -22,7 +22,7 @@
* use without further testing or modification.
**********************************************************************/
#include "CAN_Node_Def.h"
#include <can/CAN_Node_Def.h>
#include <stdint.h>
/* Application variables used in variable OD */
......
......@@ -25,8 +25,8 @@
#ifndef _CAN_NODE_DEF_H
#define _CAN_NODE_DEF_H
#include <can/canopen_driver.h>
#include <stdint.h>
#include "canopen_driver.h"
#define CAN_MASTER_NODE 0x7D /* 125 */
#define CAN_SLAVE1_NODE 0x01 /* 1 */
......
......@@ -22,8 +22,8 @@
* use without further testing or modification.
**********************************************************************/
#include "canopen_driver.h"
#include "CAN_Node_Def.h"
#include <can/canopen_driver.h>
#include <can/CAN_Node_Def.h>
#if defined ( __GNUC__ ) /* only for LPCXpresso, for keil/IAR this is done by linker */
#include "cr_section_macros.h"
......
......@@ -25,7 +25,7 @@
#ifndef CANOPEN_DRIVER_H_
#define CANOPEN_DRIVER_H_
#include "rom_drivers.h"
#include <can/rom_drivers.h>
/* Message buffers used by CANopen library:
CANopen driver RX 1
......
......@@ -26,7 +26,7 @@
#define PERIPHERAL CAN
#if (PERIPHERAL == CAN)
#include "rom_driver_CAN.h"
#include <can/rom_driver_CAN.h>
#endif /* (PERIPHERAL == CAN) */
#if (PERIPHERAL == USB)
......
......@@ -3,6 +3,52 @@
static StreamBufferHandle_t _reader_buffer;
panel_conf_t acc_panel[DOOR_ACC_PANEL_MAX_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,
.acc_panel_beep_port = DOOR_1_ACC_PANEL_BEEP_PORT,
.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,
.relay_port = DOOR_1_RELAY_PORT,
.relay_pin = DOOR_1_RELAY_PIN,
.open_time_sec = DOOR_1_OPEN_TIME_MS,
.timer = NULL,
},
{
.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,
.acc_panel_beep_port = DOOR_2_ACC_PANEL_BEEP_PORT,
.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,
.relay_port = DOOR_2_RELAY_PORT,
.relay_pin = DOOR_2_RELAY_PIN,
.open_time_sec = DOOR_2_OPEN_TIME_MS,
.timer = NULL,
}
};
static void panel_timer_callback(TimerHandle_t pxTimer)
{
configASSERT(pxTimer);
......
......@@ -224,7 +224,7 @@ _STD_END
int WRITEFUNC(int iFileHandle, char *pcBuffer, int iLength)
{
#if defined(DEBUG_ENABLE)
unsigned int i;
int i;
for (i = 0; i < iLength; i++) {
Board_UARTPutChar(pcBuffer[i]);
}
......
/*
* board_config.h
* terminal_config.h
*
* Created on: 24. 8. 2018
* Author: Petr
......@@ -8,14 +8,11 @@
#ifndef BSP_BOARD_CONFIG_H_
#define BSP_BOARD_CONFIG_H_
#include "chip.h"
#define DEVEL_BOARD
// Use global UID from chip as terminal unique ID
#define IAP_READ_UID 58
extern unsigned int TERMINAL_UID[4]; // 0 is least significant word
extern unsigned int TERMINAL_UID[5]; // 0 - status code, 1 - least significant word
//---------------------------------------------------------------------------------------------------------------------
// Values for door 0
......
......@@ -4,7 +4,9 @@
* Created on: 24. 8. 2018
* Author: Petr
*
* W26 frame | even parity (1b) | facility code (8b) | card number (16b) | odd parity (1b) | takes up-to ~52ms
* W26 frame
* | even parity (1b) | facility code (8b) | card number (16b) | odd parity (1b) |
* transmission takes up-to ~52ms
*
* data pulse 50us
* data interval 2ms
......@@ -103,7 +105,7 @@ void weigand_int_handler(weigand26_t * device)
Chip_GPIO_ClearInts(LPC_GPIO, device->port, (1 << device->pin_d1));
Chip_GPIO_ClearInts(LPC_GPIO, device->port, (1 << device->pin_d0));
//Resolve bit value
//Resolve pin
if (int_states & (1 << device->pin_d1)) // 0's
{
if (Chip_GPIO_ReadPortBit(LPC_GPIO, device->port, device->pin_d1) == 0)
......@@ -144,14 +146,14 @@ void weigand_int_handler(weigand26_t * device)
WEIGAND26_BUFF_ITEM_SIZE,
&pxHigherPriorityTaskWoken);
//Stream buffer should have had enough space
//Stream buffer should have had enough space (we checked)
assert(bytes_sent == WEIGAND26_BUFF_ITEM_SIZE);
}
// Discard data
// Empty the frame buffer
device->frame_buffer_ptr = WEIGAND26_FRAME_SIZE;
device->frame_buffer.value = 0;
// Wake potentially waiting task
// Wake potentially blocked higher priority task
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
}
}
......@@ -160,27 +162,39 @@ void weigand_int_handler(weigand26_t * device)
void PIOINT0_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT1_IRQn);
weigand_int_handler(&device[0]);
if (device[0].consumer_buffer != NULL)
{
weigand_int_handler(&device[0]);
}
}
//GPIO port 1 handler
void PIOINT1_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT1_IRQn);
weigand_int_handler(&device[1]);
if (device[1].consumer_buffer != NULL)
{
weigand_int_handler(&device[1]);
}
}
//GPIO port 2 handler
void PIOINT2_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT2_IRQn);
weigand_int_handler(&device[2]);
if (device[2].consumer_buffer != NULL)
{
weigand_int_handler(&device[2]);
}
}
//GPIO port 3 handler
void PIOINT3_IRQHandler(void)
{
NVIC_ClearPendingIRQ(EINT3_IRQn);
weigand_int_handler(&device[3]);
if (device[2].consumer_buffer != NULL)
{
weigand_int_handler(&device[2]);
}
}
......@@ -15,6 +15,7 @@
#include "stream_buffer.h"
#define WEIGAND26_FRAME_SIZE 26
#define WEIGAND26_FRAME_TIME_LIMIT 100 //ms
typedef union
{
......@@ -38,6 +39,7 @@ typedef struct
#define WEIGAND26_BUFF_ITEM_SIZE sizeof(weigand26_buff_item_t)
//One buffer for each receiving component is preferred
void weigand_init(StreamBufferHandle_t buffer, uint8_t id, uint8_t dx_port, uint8_t d0_pin, uint8_t d1_pin);
void weigand_disable(uint8_t dx_port, uint8_t d0_pin, uint8_t d1_pin);
......
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