Skip to content

Commit

Permalink
Add semaphore example
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwen-tw committed Jun 13, 2016
1 parent c6c89b7 commit 319787d
Show file tree
Hide file tree
Showing 12,600 changed files with 6,023,691 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
108 changes: 108 additions & 0 deletions firmware/freertos/semaphore/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/* Here is a good place to include header files that are required across
your application. */
//#include "something.h"

#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ 168000000
#define configTICK_RATE_HZ 1000
#define configMAX_PRIORITIES 10
#define configMINIMAL_STACK_SIZE 130
#define configTOTAL_HEAP_SIZE (75 * 1024)
#define configMAX_TASK_NAME_LEN 20
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0

/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0

/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1

/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE

/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
/* 15 priority levels */
#define configPRIO_BITS 4
#endif

/* Interrupt nesting behaviour configuration. */
#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
#define configMAX_API_CALL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5

/* Normal assert() semantics without relying on the provision of an assert.h header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

/* FreeRTOS MPU specific definitions. */
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0

/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0
#define INCLUDE_pcTaskGetTaskName 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 0

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

/* A header file that defines trace macro can be included here. */

#endif /* FREERTOS_CONFIG_H */
115 changes: 115 additions & 0 deletions firmware/freertos/semaphore/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#======================================================================#

#Output files

EXECUTABLE=firmware.elf
BIN_IMAGE=firmware.bin

#======================================================================#

#Toolchain

CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
GDB=arm-none-eabi-gdb

#======================================================================#

#Flags

CFLAGS=-g -mlittle-endian -mthumb \
-mcpu=cortex-m4 \
-mfpu=fpv4-sp-d16 -mfloat-abi=hard \
--specs=nano.specs \
--specs=nosys.specs
CFLAGS+=-D USE_STDPERIPH_DRIVER
CFLAGS+=-D STM32F4xx
CFLAGS+=-D __FPU_PRESENT=1 \
-D ARM_MATH_CM4 \
-D __FPU_USED=1
CFLAGS+=-I./


#stm32-flash
CFLAGS+=-Wl,-T,stm32_flash.ld

#======================================================================#

#Source code

CFLAGS+=-I./lib/CMSIS/Include
SRC=./lib/CMSIS/system_stm32f4xx.c

#StdPeriph
ST_LIB=./lib/STM32F4xx_StdPeriph_Driver

CFLAGS+=-I$(ST_LIB)/inc
CFLAGS+=-I./lib/CMSIS/ST/STM32F4xx/Include
SRC+=$(ST_LIB)/src/misc.c \
$(ST_LIB)/src/stm32f4xx_rcc.c \
$(ST_LIB)/src/stm32f4xx_dma.c \
$(ST_LIB)/src/stm32f4xx_flash.c \
$(ST_LIB)/src/stm32f4xx_gpio.c \
$(ST_LIB)/src/stm32f4xx_usart.c \
$(ST_LIB)/src/stm32f4xx_tim.c\
$(ST_LIB)/src/stm32f4xx_spi.c\
$(ST_LIB)/src/stm32f4xx_i2c.c

#FreeRTOS
ARCH=CM4F
FREERTOS=./lib/FreeRTOSV8.2.3/FreeRTOS

CFLAGS+=-I$(FREERTOS)/Source/include \
-I$(FREERTOS)/Source/portable/GCC/ARM_$(ARCH)
SRC+=$(FREERTOS)/Source/croutine.c \
$(FREERTOS)/Source/list.c \
$(FREERTOS)/Source/queue.c \
$(FREERTOS)/Source/tasks.c \
$(FREERTOS)/Source/timers.c \
$(FREERTOS)/Source/portable/MemMang/heap_4.c \
$(FREERTOS)/Source/portable/GCC/ARM_$(ARCH)/port.c

#STM32 startup file
STARTUP=./startup_stm32f4xx.s

#Major programs
SRC+=./main.c \
./usart.c

#======================================================================#

#Make rules

#Compile
all:$(BIN_IMAGE)

$(BIN_IMAGE):$(EXECUTABLE)
$(OBJCOPY) -O binary $^ $@

STARTUP_OBJ = startup_stm32f4xx.o

$(STARTUP_OBJ): $(STARTUP)
$(CC) $(CFLAGS) $^ -c $(STARTUP)

$(EXECUTABLE):$(SRC) $(STARTUP_OBJ)
$(CC) $(CFLAGS) $^ -o $@

#clean
clean:
rm -rf $(EXECUTABLE)
rm -rf $(BIN_IMAGE)

#Flash
flash:
st-flash write $(BIN_IMAGE) 0x8000000

#OpenOCD GDB server
openocd:
openocd -f ./openocd.cfg

#GNU Debugger
gdbauto:
cgdb -d $(GDB) -x ./openocd_gdb.gdb

#======================================================================
.PHONY:all clean flash
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* ----------------------------------------------------------------------
* Copyright (C) 2010 ARM Limited. All rights reserved.
*
* $Date: 29. November 2010
* $Revision: V1.0.3
*
* Project: CMSIS DSP Library
*
* Title: math_helper.h
*
*
* Description: Prototypes of all helper functions required.
*
* Target Processor: Cortex-M4/Cortex-M3
*
* Version 1.0.3 2010/11/29
* Re-organized the CMSIS folders and updated documentation.
*
* Version 1.0.2 2010/11/11
* Documentation updated.
*
* Version 1.0.1 2010/10/05
* Production release and review comments incorporated.
*
* Version 1.0.0 2010/09/20
* Production release and review comments incorporated.
*
* Version 0.0.7 2010/06/10
* Misra-C changes done
* -------------------------------------------------------------------- */


#include "arm_math.h"

#ifndef MATH_HELPER_H
#define MATH_HELPER_H

float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize);
void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples);
void arm_provide_guard_bits_q15(q15_t *input_buf, uint32_t blockSize, uint32_t guard_bits);
void arm_provide_guard_bits_q31(q31_t *input_buf, uint32_t blockSize, uint32_t guard_bits);
void arm_float_to_q14(float *pIn, q15_t *pOut, uint32_t numSamples);
void arm_float_to_q29(float *pIn, q31_t *pOut, uint32_t numSamples);
void arm_float_to_q28(float *pIn, q31_t *pOut, uint32_t numSamples);
void arm_float_to_q30(float *pIn, q31_t *pOut, uint32_t numSamples);
void arm_clip_f32(float *pIn, uint32_t numSamples);
uint32_t arm_calc_guard_bits(uint32_t num_adds);
void arm_apply_guard_bits (float32_t * pIn, uint32_t numSamples, uint32_t guard_bits);
uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples);
uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t *pOut, uint32_t numSamples);
uint32_t arm_calc_2pow(uint32_t guard_bits);
#endif

Loading

0 comments on commit 319787d

Please sign in to comment.