Commit 44aa2ba6 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

polishing

parent 98dfdb34
......@@ -34,7 +34,6 @@
<listOptionValue builtIn="false" value="__USE_LPCOPEN"/>
<listOptionValue builtIn="false" value="CR_INTEGER_PRINTF"/>
<listOptionValue builtIn="false" value="__LPC11XX__"/>
<listOptionValue builtIn="false" value="SDK_DEBUGCONSOLE=1"/>
<listOptionValue builtIn="false" value="__NEWLIB__"/>
</option>
<option id="gnu.c.compiler.option.misc.other.332718478" name="Other flags" superClass="gnu.c.compiler.option.misc.other" useByScannerDiscovery="false" value="-c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -fsingle-precision-constant" valueType="string"/>
......
......@@ -19,7 +19,7 @@
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
unsigned int TERMINAL_UID[5] = {0, 0, 0, 0, 0};
/*****************************************************************************
* Private functions
......@@ -28,46 +28,17 @@ unsigned int TERMINAL_UID[5] = {0, 0, 0, 0, 0};
static void alive_task(void *pvParameters)
{
(void *) pvParameters;
Board_LED_Set(0, true);
while (1)
{
vTaskDelay(1500 / portTICK_PERIOD_MS);
Board_LED_Toggle(0);
vTaskDelay(5000 / portTICK_PERIOD_MS);
DEBUGSTR("tick\n");
}
}
#endif //DEVEL_BOARD
static void setup_hardware(void)
static void check_system_stack_size(void)
{
// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate();
// Set up and initialize all required blocks and
// functions related to the board hardware
Board_Init();
#ifdef DEVEL_BOARD
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
unsigned int cmd_param[5] = {IAP_READ_UID, 0, 0, 0, 0};
iap_entry(cmd_param, TERMINAL_UID);
// Enable INTs for all GPIO ports
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
NVIC_EnableIRQ(EINT2_IRQn);
NVIC_EnableIRQ(EINT3_IRQn);
// can_driver_init();
terminal_init();
extern unsigned long _vStackTop[], _pvHeapStart[];
unsigned long ulInterruptStackSize;
/* The size of the stack used by main and interrupts is not defined in
......@@ -93,11 +64,23 @@ int main(void)
{
__disable_irq();
setup_hardware();
// Set up and initialize all required blocks and
// functions related to the board hardware
Board_Init();
#ifdef DEVEL_BOARD
xTaskCreate(alive_task, "alv_tsk",configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
#endif
//CAN_init();
terminal_init();
WDT_Init();
check_system_stack_size();
__enable_irq();
WDT_Init();
WDT_Feed();
/* Start the kernel. From here on, only tasks and interrupts will run. */
vTaskStartScheduler();
......@@ -105,6 +88,24 @@ int main(void)
return 1;
}
/* Used for run time statistics */
void vConfigureTimerForRunTimeStats(void)
{
/* Power up and feed the timer with a clock. */
Chip_TIMER_Init(LPC_TIMER32_0);
Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER32_0, TIMER_CAPSRC_RISING_PCLK, 1);
/* Reset Timer 0 */
Chip_TIMER_Reset(LPC_TIMER32_0);
/* Prescale to a frequency that is good enough to get a decent resolution,
but not too fast so as to overflow all the time. */
Chip_TIMER_PrescaleSet(LPC_TIMER32_0, ( configCPU_CLOCK_HZ / 10000UL ) - 1UL);
/* Start the counter. */
Chip_TIMER_Enable(LPC_TIMER32_0);
}
void vApplicationMallocFailedHook(void)
{
/* vApplicationMallocFailedHook() will only be called if
......
......@@ -42,8 +42,10 @@
*----------------------------------------------------------*/
#include <stdint.h>
extern uint32_t SystemCoreClock;
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
......@@ -52,20 +54,35 @@ extern uint32_t SystemCoreClock;
#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 )
#define configUSE_TRACE_FACILITY 1
#define configMAX_TASK_NAME_LEN ( 5 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 0
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 0
#define configGENERATE_RUN_TIME_STATS 0
#define configRECORD_STACK_HIGH_ADDRESS 1
#define configRECORD_STACK_HIGH_ADDRESS 1 // for max stack usage
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_CUSTOM_TICK 0
#ifdef RELEASE
#define configCHECK_FOR_STACK_OVERFLOW 0
#else
#define configCHECK_FOR_STACK_OVERFLOW 2
#endif
/* Run time and task stats gathering related definitions. */
extern void vConfigureTimerForRunTimeStats(void);
//#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
//#define portGET_RUN_TIME_COUNTER_VALUE() Chip_TIMER_ReadCount(LPC_TIMER32_0)
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* heap implementation */
#define configFRTOS_MEMORY_SCHEME 1 // scheme 1 - allocate only
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
......@@ -74,7 +91,7 @@ extern uint32_t SystemCoreClock;
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define configTIMER_QUEUE_LENGTH 3
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_TASK_STACK_DEPTH ( 80 )
/* Set the following definitions to 1 to include the API function, or zero
......
......@@ -40,6 +40,8 @@
* Public types/enumerations/variables
****************************************************************************/
unsigned int TERMINAL_UID[5] = {0, 0, 0, 0, 0};
/* System oscillator rate and clock rate on the CLKIN pin */
const uint32_t OscRateIn = 12000000;
const uint32_t ExtRateIn = 0;
......@@ -216,6 +218,9 @@ void Board_LED_Toggle(uint8_t LEDNumber)
board hardware */
void Board_Init(void)
{
// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate();
/* Sets up DEBUG UART */
DEBUGINIT();
......@@ -225,5 +230,18 @@ void Board_Init(void)
#ifdef DEVEL_BOARD
/* Initialize LEDs */
Board_LED_Init();
Board_LED_Set(0, false);
Board_LED_Set(1, false);
Board_LED_Set(2, false);
#endif // DEVEL_BOARD
// Enable INTs for all GPIO ports
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
NVIC_EnableIRQ(EINT2_IRQn);
NVIC_EnableIRQ(EINT3_IRQn);
//Read UID
unsigned int cmd_param[5] = {IAP_READ_UID, 0, 0, 0, 0};
iap_entry(cmd_param, TERMINAL_UID);
}
......@@ -17,7 +17,6 @@
#include "board.h"
#include "timers.h"
#include <limits.h>
#include <assert.h>
typedef struct
{
......@@ -68,6 +67,8 @@ void weigand_init(StreamBufferHandle_t buffer, uint8_t id, uint8_t dx_port, uint
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);
// LPC_GPIO is initialized in board.c
//Input mode
Chip_GPIO_SetPinDIRInput(LPC_GPIO, dx_port, d0_pin);
Chip_GPIO_SetPinDIRInput(LPC_GPIO, dx_port, d1_pin);
......@@ -127,7 +128,7 @@ 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
configASSERT(xTimerStart(device->timer, 0)); // Restarts timer if still running
}
}
......@@ -157,7 +158,7 @@ void weigand_int_handler(weigand26_t * device)
device->frame_buffer.value &= ~(1 << device->frame_buffer_ptr);
}
}
else // Clear other int on same port (FIXME)
else // Clear other pin int (no other GPIO pins expected to cause int)
{
Chip_GPIO_ClearInts(LPC_GPIO, device->port, 0xFFFFFFFF);
return;
......@@ -183,7 +184,7 @@ void weigand_int_handler(weigand26_t * device)
&pxHigherPriorityTaskWoken);
//Stream buffer should have had enough space (we checked)
assert(bytes_sent == WEIGAND26_BUFF_ITEM_SIZE);
configASSERT(bytes_sent == WEIGAND26_BUFF_ITEM_SIZE);
}
// Empty the frame buffer
device->frame_buffer_ptr = WEIGAND26_FRAME_SIZE;
......
......@@ -44,43 +44,43 @@ extern "C" {
*/
/* Type definitions. */
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE uint32_t
#define portBASE_TYPE long
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE uint32_t
#define portBASE_TYPE long
typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t;
typedef unsigned long UBaseType_t;
#if( configUSE_16_BIT_TICKS == 1 )
typedef uint16_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffff
typedef uint16_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffff
#else
typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
not need to be guarded with a critical section. */
#define portTICK_TYPE_IS_ATOMIC 1
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
not need to be guarded with a critical section. */
#define portTICK_TYPE_IS_ATOMIC 1
#endif
/*-----------------------------------------------------------*/
/* Architecture specifics. */
#define portSTACK_GROWTH ( -1 )
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
#define portBYTE_ALIGNMENT 8
#define portSTACK_GROWTH ( -1 )
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
#define portBYTE_ALIGNMENT 8
/*-----------------------------------------------------------*/
/* Scheduler utilities. */
extern void vPortYield( void );
#define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) )
#define portNVIC_PENDSVSET_BIT ( 1UL << 28UL )
#define portYIELD() vPortYield()
#define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) )
#define portNVIC_PENDSVSET_BIT ( 1UL << 28UL )
#define portYIELD() vPortYield()
#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
/*-----------------------------------------------------------*/
......@@ -92,12 +92,12 @@ extern void vPortExitCritical( void );
extern uint32_t ulSetInterruptMaskFromISR( void ) __attribute__((naked));
extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__((naked));
#define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vClearInterruptMaskFromISR( x )
#define portDISABLE_INTERRUPTS() __asm volatile ( " cpsid i " ::: "memory" )
#define portENABLE_INTERRUPTS() __asm volatile ( " cpsie i " ::: "memory" )
#define portENTER_CRITICAL() vPortEnterCritical()
#define portEXIT_CRITICAL() vPortExitCritical()
#define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vClearInterruptMaskFromISR( x )
#define portDISABLE_INTERRUPTS() __asm volatile ( " cpsid i " ::: "memory" )
#define portENABLE_INTERRUPTS() __asm volatile ( " cpsie i " ::: "memory" )
#define portENTER_CRITICAL() vPortEnterCritical()
#define portEXIT_CRITICAL() vPortExitCritical()
/*-----------------------------------------------------------*/
......
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