安信可(云知声蜂鸟US516P6)SDK开发学习---freertos os接口函数封装管理

安信可(云知声蜂鸟US516P6)SDK开发学习—freertos os接口函数封装管理

线程,互斥锁,、延时函数,任务优先级定义,线程栈定义

#define uni_usleep(us)                    vTaskDelay(((us)/1001 + 1) / portTICK_PERIOD_MS)
#define uni_msleep(ms)                    vTaskDelay((ms) / portTICK_PERIOD_MS)
#define uni_sleep(s)                      vTaskDelay(((s) * 1000) / portTICK_PERIOD_MS)

#define uni_sem_t                         SemaphoreHandle_t
int uni_sem_init(uni_sem_t *sem, unsigned int value);
#define uni_sem_post(sem_ptr)             xSemaphoreGive(sem_ptr)
#define uni_sem_post_isr(sem_ptr, ptr)    xSemaphoreGiveFromISR(sem_ptr, ptr)
#define uni_sem_isr_yield(is)             portEND_SWITCHING_ISR(is)
#define uni_sem_wait(sem_ptr)             xSemaphoreTake(sem_ptr, portMAX_DELAY)
#define uni_sem_wait_ms(sem_ptr, ms)      xSemaphoreTake(sem_ptr, (ms)/portTICK_PERIOD_MS)
#define uni_sem_destroy(sem_ptr)          vSemaphoreDelete(sem_ptr)

/* THREAD STACK SIZE */
#define STACK_SIZE                        256               // 1KB (freeRTOS unit is word - 4 bytes)
#define STACK_SMALL_SIZE                  (STACK_SIZE * 1)  // 1KB
#define STACK_NORMAL_SIZE                 (STACK_SIZE * 2)  // 2kB
#define STACK_MIDDLE_SIZE                 (STACK_SIZE * 3)  // 3kB
#define STACK_LARGE_SIZE                  (STACK_SIZE * 4)  // 4kB

/* TASK PRIORITY */
#define OS_PRIORITY_IDLE                  tskIDLE_PRIORITY            //idle (lowest)
#define OS_PRIORITY_LOW                   (tskIDLE_PRIORITY + 1)      //low
#define OS_PRIORITY_NORMAL                (tskIDLE_PRIORITY + 2)      //normal
#define OS_PRIORITY_HIGH                  (tskIDLE_PRIORITY + 3)      //high
#define OS_PRIORITY_REALTIME              (configMAX_PRIORITIES - 1)  //realtime (highest)

typedef struct  {
    
    
    uni_u32 stack_size;
    uni_u32 priority;
    char task_name[16];
}thread_param;
typedef void (*start_routine)(void *);
#define uni_pthread_t                     TaskHandle_t
#define uni_pthread_id()                  xTaskGetCurrentTaskHandle()
int uni_pthread_create(uni_pthread_t *thread, thread_param *para,
                            start_routine task_func, void* arg);
#define uni_pthread_detach(th)            
#define uni_pthread_destroy(th)           vTaskDelete(th)


#define uni_mutex_t                       SemaphoreHandle_t
int uni_pthread_mutex_init(uni_mutex_t *mutex);
#define uni_pthread_mutex_destroy(mtx_ptr) \
                                          vSemaphoreDelete(mtx_ptr)
#define uni_pthread_mutex_lock(mtx_ptr)    \
                                          xSemaphoreTake(mtx_ptr, portMAX_DELAY)
#define uni_pthread_mutex_unlock(mtx_ptr)  \
                                          xSemaphoreGive(mtx_ptr)

static inline uni_u64 uni_get_clock_time_ms(void) {
    
    
  TickType_t xTicks = xTaskGetTickCount();
  return xTicks * portTICK_RATE_MS;
}

static inline uni_u32 uni_get_clock_time_sec(void) {
    
    
  TickType_t xTicks = xTaskGetTickCount();
  return xTicks / configTICK_RATE_HZ;
}
FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd.
使用版本如上

具体配置文件如下:

#define configUSE_PREEMPTION			1
#define configUSE_IDLE_HOOK			1
#define configUSE_TICK_HOOK			0
#define configCPU_CLOCK_HZ			( ( unsigned long ) 120000000)
#define configTICK_RATE_HZ			( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES			(  10 )
#define configMINIMAL_STACK_SIZE		( ( uint16_t ) 512 )
#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 37 * 1024 ) )
#define configMAX_TASK_NAME_LEN			( 16 )
#define configUSE_TRACE_FACILITY		1
#define configUSE_16_BIT_TICKS			0
#define configIDLE_SHOULD_YIELD			1
#define configUSE_MUTEXES			1
#define configQUEUE_REGISTRY_SIZE		8
#define configCHECK_FOR_STACK_OVERFLOW	        0
#define configUSE_RECURSIVE_MUTEXES		1
#define configUSE_MALLOC_FAILED_HOOK	        0
#define configUSE_APPLICATION_TASK_TAG	        0
#define configUSE_COUNTING_SEMAPHORES	        1
#define configGENERATE_RUN_TIME_STATS	        1
#define configSUPPORT_ZOL                       1

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 		        0
#define configMAX_CO_ROUTINE_PRIORITIES        ( 2 )

/* Software timer definitions. */
#define configUSE_TIMERS			0
#define configTIMER_TASK_PRIORITY		( 2 )
#define configTIMER_QUEUE_LENGTH		10
#define configTIMER_TASK_STACK_DEPTH	        ( configMINIMAL_STACK_SIZE * 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet		1
#define INCLUDE_uxTaskPriorityGet		1
#define INCLUDE_vTaskDelete			1
#define INCLUDE_vTaskCleanUpResources	        0
#define INCLUDE_vTaskSuspend			0
#define INCLUDE_vTaskDelayUntil			1
#define INCLUDE_vTaskDelay			1
#define INCLUDE_xTaskGetSchedulerState          1
#define INCLUDE_pcTaskGetTaskName 1

#define configPRIO_BITS       		2        /* 4 priority levels */


/* 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

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY 		( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
//#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

//0�������л�ʱ�ر������ж�   1�������л�ʱ�ر��ж����ȼ�Ϊ1��2��3���ж�  2�������л�ʱ�ر��ж����ȼ�Ϊ2��3���ж�  3�������л�ʱ�ر��ж����ȼ�Ϊ3���ж�
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	0

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

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

/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware,
              to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
/* #define xPortSysTickHandler SysTick_Handler */

#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
#define portGET_RUN_TIME_COUNTER_VALUE()	xTickCount

#define INCLUDE_xSemaphoreGetMutexHolder 1

#define traceTASK_DELETE DeleteTaskMallocMem

//#define use_MCPS_ANALYSIS
#ifdef use_MCPS_ANALYSIS
#define traceTASK_SWITCHED_IN()  trace_TASK_SWITCHED_IN()
#define traceTASK_SWITCHED_OUT() trace_TASK_SWITCHED_OUT()
#endif

#endif /* FREERTOS_CONFIG_H */

猜你喜欢

转载自blog.csdn.net/xushx_bigbear/article/details/130880053
今日推荐