mirror of
				https://github.com/flyingcys/realtek_ameba.git
				synced 2025-07-31 20:31:06 +00:00 
			
		
		
		
	
						commit
						3e75e46d81
					
				
					 4 changed files with 579 additions and 423 deletions
				
			
		|  | @ -1,35 +1,47 @@ | ||||||
| /* rtthread includes */ | /* rtthread includes */ | ||||||
| #include <rtthread.h> | 
 | ||||||
| #include <osdep_service.h> | #include <osdep_service.h> | ||||||
|  | #include <rtthread_service.h> | ||||||
|  | #ifdef SECTION | ||||||
|  | #undef SECTION | ||||||
|  | #endif | ||||||
|  | #include <rthw.h> | ||||||
|  | #include <rtthread.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <freertos_pmu.h> | 
 | ||||||
| //#include <tcm_heap.h>
 | // #define RTTHREAD_SERVICE_DEBUG
 | ||||||
|  | #define RTTHREAD_SERVICE_DEBUG_LEVEL 2 | ||||||
| /********************* os depended utilities ********************/ | /********************* os depended utilities ********************/ | ||||||
|  | #ifdef RTTHREAD_SERVICE_DEBUG | ||||||
|  | #define DEBUG_LOG(_level, fmt, args...)  if ((_level) >= RTTHREAD_SERVICE_DEBUG_LEVEL) rt_kprintf(fmt, args) | ||||||
|  | #else | ||||||
|  | #define DEBUG_LOG(level, fmt, args...) | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef USE_MUTEX_FOR_SPINLOCK | #ifndef USE_MUTEX_FOR_SPINLOCK | ||||||
| #define USE_MUTEX_FOR_SPINLOCK 1 | #define USE_MUTEX_FOR_SPINLOCK 1 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| rt_uint16_t ameba_sem = 0; | extern uint32_t pmu_yield_os_check(void); | ||||||
| rt_uint16_t ameba_mutex = 0; | extern _LONG_CALL_ void DelayUs(u32 us); | ||||||
| rt_uint16_t ameba_spin = 0; | extern _LONG_CALL_ void DelayMs(u32 ms); | ||||||
| 
 | extern uint32_t pmu_set_sysactive_time(uint32_t timeout_ms); | ||||||
| //----- ------------------------------------------------------------------
 |  | ||||||
| // Misc Function
 |  | ||||||
| //----- ------------------------------------------------------------------
 |  | ||||||
| 
 | 
 | ||||||
| void save_and_cli(void) | void save_and_cli(void) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s runing...\n", __LINE__, __FUNCTION__); | ||||||
|     rt_enter_critical(); |     rt_enter_critical(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void restore_flags(void) | void restore_flags(void) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s runing...\n", __LINE__, __FUNCTION__); | ||||||
|     rt_exit_critical(); |     rt_exit_critical(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void cli(void) | void cli(void) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s runing...\n", __LINE__, __FUNCTION__); | ||||||
|     rt_hw_interrupt_disable(); |     rt_hw_interrupt_disable(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -71,16 +83,19 @@ static unsigned int __div64_32(u64 *n, unsigned int base) | ||||||
| 
 | 
 | ||||||
| u8* _rtthread_malloc(u32 sz) | u8* _rtthread_malloc(u32 sz) | ||||||
| { | { | ||||||
|     u8 *pbuf = (u8 *)rt_malloc(sz); |     void *pbuf; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s sz:%d\n", __LINE__, __FUNCTION__, sz); | ||||||
|  |     pbuf = rt_malloc(sz); | ||||||
|     return pbuf; |     return pbuf; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u8* _rtthread_zmalloc(u32 sz) | u8* _rtthread_zmalloc(u32 sz) | ||||||
| { | { | ||||||
| 	u8 *pbuf = rt_malloc(sz); |     void *pbuf = rt_malloc(sz); | ||||||
|      |      | ||||||
| 	if (pbuf != NULL) |     DEBUG_LOG(2, "L:%d fun:%s sz:%d\n", __LINE__, __FUNCTION__, sz); | ||||||
|  |     if (pbuf != RT_NULL) | ||||||
|         memset(pbuf, 0, sz); |         memset(pbuf, 0, sz); | ||||||
| 
 | 
 | ||||||
|     return pbuf;     |     return pbuf;     | ||||||
|  | @ -88,17 +103,20 @@ u8* _rtthread_zmalloc(u32 sz) | ||||||
| 
 | 
 | ||||||
| void _rtthread_mfree(u8 *pbuf, u32 sz) | void _rtthread_mfree(u8 *pbuf, u32 sz) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s\n", __LINE__, __FUNCTION__); | ||||||
|     rt_free(pbuf); |     rt_free(pbuf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_memcpy(void* dst, void* src, u32 sz) | static void _rtthread_memcpy(void* dst, void* src, u32 sz) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s dst:0x%08x src:0x%08x sz:%d\n", __LINE__, __FUNCTION__, dst, src, sz); | ||||||
|     memcpy(dst, src, sz); |     memcpy(dst, src, sz); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_memcmp(void *dst, void *src, u32 sz) | static int _rtthread_memcmp(void *dst, void *src, u32 sz) | ||||||
| { | { | ||||||
| //under Linux/GNU/GLibc, the return value of memcmp for two same mem. chunk is 0
 | //under Linux/GNU/GLibc, the return value of memcmp for two same mem. chunk is 0
 | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s dst:0x%08x src:0x%08x sz:%d\n", __LINE__, __FUNCTION__, dst, src, sz); | ||||||
|     if (!(memcmp(dst, src, sz))) |     if (!(memcmp(dst, src, sz))) | ||||||
|         return 1; |         return 1; | ||||||
| 
 | 
 | ||||||
|  | @ -107,34 +125,52 @@ static int _rtthread_memcmp(void *dst, void *src, u32 sz) | ||||||
| 
 | 
 | ||||||
| static void _rtthread_memset(void *pbuf, int c, u32 sz) | static void _rtthread_memset(void *pbuf, int c, u32 sz) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s buf:0x%08x c:%c sz:%d\n", __LINE__, __FUNCTION__, pbuf, c, sz); | ||||||
|     memset(pbuf, c, sz); |     memset(pbuf, c, sz); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_init_sema(_sema *sema, int init_val) | static void _rtthread_init_sema(_sema *sema, int init_val) | ||||||
| { | { | ||||||
|     char name[RT_NAME_MAX]; |     char name[RT_NAME_MAX]; | ||||||
|  |     static int ameba_sem = 0; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s begin val:%d\n", __LINE__, __FUNCTION__, init_val); | ||||||
|     memset(name, 0, RT_NAME_MAX); |     memset(name, 0, RT_NAME_MAX); | ||||||
|     snprintf(name, RT_NAME_MAX, "sem-%04d", ameba_sem ++); |     snprintf(name, RT_NAME_MAX, "sem-%03d", ameba_sem); | ||||||
|      |  | ||||||
|     *sema = rt_sem_create(name, init_val, RT_IPC_FLAG_FIFO); |     *sema = rt_sem_create(name, init_val, RT_IPC_FLAG_FIFO); | ||||||
|  |     if (*sema != RT_NULL) | ||||||
|  |         ameba_sem ++; | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s end sema:0x%08x num:%d\n", __LINE__, __FUNCTION__, *sema, ameba_sem); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_free_sema(_sema *sema) | static void _rtthread_free_sema(_sema *sema) | ||||||
| { | { | ||||||
| 	if(*sema != NULL) |     RT_ASSERT(*sema != RT_NULL); | ||||||
|         rt_sem_delete(*sema); |  | ||||||
| 
 | 
 | ||||||
| 	*sema = NULL; |     DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x\n", __LINE__, __FUNCTION__, *sema); | ||||||
|  |     rt_sem_delete(*sema); | ||||||
|  |     *sema = RT_NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_up_sema(_sema *sema) | static void _rtthread_up_sema(_sema *sema) | ||||||
| { | { | ||||||
|  |     if (*sema == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("err!! up sema is NULL\n"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x\n", __LINE__, __FUNCTION__, *sema); | ||||||
|     rt_sem_release(*sema); |     rt_sem_release(*sema); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_up_sema_from_isr(_sema *sema) | static void _rtthread_up_sema_from_isr(_sema *sema) | ||||||
| { | { | ||||||
|  |     if (*sema == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("err!! up sema from isr is NULL\n"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x\n", __LINE__, __FUNCTION__, *sema); | ||||||
|     rt_sem_release(*sema); |     rt_sem_release(*sema); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -142,14 +178,14 @@ static u32 _rtthread_down_sema(_sema *sema, u32 timeout) | ||||||
| { | { | ||||||
|     rt_int32_t tick; |     rt_int32_t tick; | ||||||
| 
 | 
 | ||||||
|  |     RT_ASSERT(*sema != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x timeout:%d\n", __LINE__, __FUNCTION__, *sema, timeout); | ||||||
|  | 
 | ||||||
|     if(timeout >= RT_TICK_MAX / 2)  |     if(timeout >= RT_TICK_MAX / 2)  | ||||||
|     { |  | ||||||
|         tick = RT_WAITING_FOREVER; |         tick = RT_WAITING_FOREVER; | ||||||
| 	}  |  | ||||||
|     else  |     else  | ||||||
|     { |  | ||||||
|         tick = rtw_ms_to_systime(timeout); |         tick = rtw_ms_to_systime(timeout); | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
|     if(rt_sem_take(*sema, tick) != RT_EOK) |     if(rt_sem_take(*sema, tick) != RT_EOK) | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  | @ -160,24 +196,31 @@ static u32 _rtthread_down_sema(_sema *sema, u32 timeout) | ||||||
| static void _rtthread_mutex_init(_mutex *pmutex) | static void _rtthread_mutex_init(_mutex *pmutex) | ||||||
| { | { | ||||||
|     char name[RT_NAME_MAX]; |     char name[RT_NAME_MAX]; | ||||||
|  |     static int ameba_mutex = 0; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s begin\n", __LINE__, __FUNCTION__); | ||||||
|     memset(name, 0, RT_NAME_MAX); |     memset(name, 0, RT_NAME_MAX); | ||||||
| 
 |     snprintf(name, RT_NAME_MAX, "mux-%03d", ameba_mutex); | ||||||
|     snprintf(name, RT_NAME_MAX, "rmux-%03d", ameba_mutex ++); |  | ||||||
| 
 |  | ||||||
|     *pmutex = rt_mutex_create(name, RT_IPC_FLAG_FIFO); |     *pmutex = rt_mutex_create(name, RT_IPC_FLAG_FIFO); | ||||||
|  |     if (*pmutex != RT_NULL) | ||||||
|  |         ameba_mutex ++; | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s end pmutex:0x%08x\n", __LINE__, __FUNCTION__, *pmutex); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_mutex_free(_mutex *pmutex) | static void _rtthread_mutex_free(_mutex *pmutex) | ||||||
| { | { | ||||||
| 	if(*pmutex != NULL) |     RT_ASSERT(*pmutex != RT_NULL); | ||||||
|         rt_mutex_delete(*pmutex);    |  | ||||||
| 
 | 
 | ||||||
| 	*pmutex = NULL; |     DEBUG_LOG(2, "L:%d fun:%s pmutex:0x%08x\n", __LINE__, __FUNCTION__, *pmutex); | ||||||
|  |     rt_mutex_delete(*pmutex); | ||||||
|  |     *pmutex = RT_NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_mutex_get(_lock *plock) | static void _rtthread_mutex_get(_lock *plock) | ||||||
| { | { | ||||||
|  |     RT_ASSERT(*plock != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s pmutex:0x%08x\n", __LINE__, __FUNCTION__, *plock); | ||||||
|     rt_mutex_take(*plock, RT_WAITING_FOREVER); |     rt_mutex_take(*plock, RT_WAITING_FOREVER); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -185,49 +228,59 @@ static int _rtthread_mutex_get_timeout(_lock *plock, u32 timeout_ms) | ||||||
| { | { | ||||||
|     rt_int32_t tick; |     rt_int32_t tick; | ||||||
| 
 | 
 | ||||||
|  |     RT_ASSERT(*plock != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x timeout_ms:%d\n", __LINE__, __FUNCTION__, *plock, timeout_ms); | ||||||
|     if(timeout_ms >= RT_TICK_MAX / 2)  |     if(timeout_ms >= RT_TICK_MAX / 2)  | ||||||
|     { |  | ||||||
|         tick = RT_WAITING_FOREVER; |         tick = RT_WAITING_FOREVER; | ||||||
| 	}  |  | ||||||
|     else |     else | ||||||
|     { |  | ||||||
|         tick = rtw_ms_to_systime(timeout_ms); |         tick = rtw_ms_to_systime(timeout_ms); | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
|     return rt_mutex_take(*plock, tick); |     return rt_mutex_take(*plock, tick); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_mutex_put(_lock *plock) | static void _rtthread_mutex_put(_lock *plock) | ||||||
| { | { | ||||||
|  |     if (*plock == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("err!! mutex put is null\n"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s pmutex:0x%08x\n", __LINE__, __FUNCTION__, *plock); | ||||||
|     rt_mutex_release(*plock); |     rt_mutex_release(*plock); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_enter_critical(_lock *plock, _irqL *pirqL) | static void _rtthread_enter_critical(_lock *plock, _irqL *pirqL) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL); | ||||||
|     rt_enter_critical(); |     rt_enter_critical(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_exit_critical(_lock *plock, _irqL *pirqL) | static void _rtthread_exit_critical(_lock *plock, _irqL *pirqL) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL); | ||||||
|     rt_exit_critical(); |     rt_exit_critical(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static u32 uxSavedInterruptStatus = 0; | // static rt_base_t level;
 | ||||||
| static void _rtthread_enter_critical_from_isr(_lock *plock, _irqL *pirqL) | static void _rtthread_enter_critical_from_isr(_lock *plock, _irqL *pirqL) | ||||||
| { | { | ||||||
|     rt_enter_critical(); |     DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL); | ||||||
|  |     *pirqL = rt_hw_interrupt_disable(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_exit_critical_from_isr(_lock *plock, _irqL *pirqL) | static void _rtthread_exit_critical_from_isr(_lock *plock, _irqL *pirqL) | ||||||
| { | { | ||||||
|     rt_exit_critical(); |     DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL); | ||||||
|  |     rt_hw_interrupt_enable(*pirqL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL) | static int _rtthread_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL) | ||||||
| { | { | ||||||
| 	int result = rt_mutex_take(*pmutex, RT_WAITING_FOREVER); |     RT_ASSERT(*pmutex != RT_NULL); | ||||||
| 
 | 
 | ||||||
|     if(result != RT_EOK) |     DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL); | ||||||
|  |     if(rt_mutex_take(*pmutex, RT_WAITING_FOREVER) != RT_EOK) | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
|  | @ -235,6 +288,12 @@ static int _rtthread_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL) | ||||||
| 
 | 
 | ||||||
| static void _rtthread_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL) | static void _rtthread_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL) | ||||||
| { | { | ||||||
|  |     if (*pmutex == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("err!! critical mutex is null\n"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL); | ||||||
|     rt_mutex_release(*pmutex); |     rt_mutex_release(*pmutex); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -242,21 +301,27 @@ static void _rtthread_spinlock_init(_lock *plock) | ||||||
| { | { | ||||||
| #if USE_MUTEX_FOR_SPINLOCK | #if USE_MUTEX_FOR_SPINLOCK | ||||||
|     char name[RT_NAME_MAX]; |     char name[RT_NAME_MAX]; | ||||||
|  |     static int ameba_spin = 0; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s begin\n", __LINE__, __FUNCTION__); | ||||||
|     memset(name, 0, RT_NAME_MAX); |     memset(name, 0, RT_NAME_MAX); | ||||||
| 
 |     snprintf(name, RT_NAME_MAX, "spn-03d", ameba_spin); | ||||||
|     snprintf(name, RT_NAME_MAX, "spin-03d", ameba_spin ++); |     *plock = rt_mutex_create(name, RT_IPC_FLAG_FIFO); | ||||||
|      |     if (*plock != RT_NULL) | ||||||
|     *plock = rt_sem_create(name, 1, RT_IPC_FLAG_FIFO); |         ameba_spin ++; | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s end plock:0x%08x ameba_spin:%d\n", __LINE__, __FUNCTION__, *plock, ameba_spin); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_spinlock_free(_lock *plock) | static void _rtthread_spinlock_free(_lock *plock) | ||||||
| { | { | ||||||
| #if USE_MUTEX_FOR_SPINLOCK | #if USE_MUTEX_FOR_SPINLOCK | ||||||
| 	if(*plock != NULL) |     // RT_ASSERT(*plock != RT_NULL);
 | ||||||
|         rt_sem_delete(*plock); |     if (*plock == RT_NULL) | ||||||
|  |         return; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x\n", __LINE__, __FUNCTION__, *plock); | ||||||
|  |     rt_mutex_delete(*plock); | ||||||
|     *plock = NULL; |     *plock = NULL; | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -264,21 +329,35 @@ static void _rtthread_spinlock_free(_lock *plock) | ||||||
| static void _rtthread_spinlock(_lock *plock) | static void _rtthread_spinlock(_lock *plock) | ||||||
| { | { | ||||||
| #if USE_MUTEX_FOR_SPINLOCK | #if USE_MUTEX_FOR_SPINLOCK | ||||||
|     rt_sem_take(*plock, RT_WAITING_FOREVER); |     RT_ASSERT(*plock != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x\n", __LINE__, __FUNCTION__, *plock); | ||||||
|  |     rt_mutex_take(*plock, RT_WAITING_FOREVER); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_spinunlock(_lock *plock) | static void _rtthread_spinunlock(_lock *plock) | ||||||
| { | { | ||||||
| #if USE_MUTEX_FOR_SPINLOCK | #if USE_MUTEX_FOR_SPINLOCK | ||||||
|     rt_sem_release(*plock); |     if (*plock == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("err!! spinunlock is null\n"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x\n", __LINE__, __FUNCTION__, *plock); | ||||||
|  |     rt_mutex_release(*plock); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_spinlock_irqsave(_lock *plock, _irqL *irqL) | static void _rtthread_spinlock_irqsave(_lock *plock, _irqL *irqL) | ||||||
| { | { | ||||||
| #if USE_MUTEX_FOR_SPINLOCK | #if USE_MUTEX_FOR_SPINLOCK | ||||||
|     while(rt_sem_take(*plock, 0) != RT_EOK) |     if (*plock == RT_NULL) | ||||||
|  |         rt_kprintf("err!! spinlock irqsave null\n"); | ||||||
|  |      | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x irqL:0x%08x\n", __LINE__, __FUNCTION__, *plock, *irqL); | ||||||
|  |     *irqL = 0xdeadbeff; | ||||||
|  |     while (rt_mutex_take(*plock, 0) != RT_EOK) | ||||||
|     { |     { | ||||||
|         rt_kprintf("spinlock_irqsave failed!\n"); |         rt_kprintf("spinlock_irqsave failed!\n"); | ||||||
|     } |     } | ||||||
|  | @ -288,33 +367,71 @@ static void _rtthread_spinlock_irqsave(_lock *plock, _irqL *irqL) | ||||||
| static void _rtthread_spinunlock_irqsave(_lock *plock, _irqL *irqL) | static void _rtthread_spinunlock_irqsave(_lock *plock, _irqL *irqL) | ||||||
| { | { | ||||||
| #if USE_MUTEX_FOR_SPINLOCK | #if USE_MUTEX_FOR_SPINLOCK | ||||||
|     rt_sem_release(*plock); |     if (*plock == RT_NULL) | ||||||
|  |         rt_kprintf("err!! spinunlock irqsave null\n"); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x irqL:0x%08x\n", __LINE__, __FUNCTION__, *plock, *irqL); | ||||||
|  |     rt_mutex_release(*plock); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_init_xqueue( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages ) | static int _rtthread_init_xqueue( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages ) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s begin name:%s size:%d msgs:%d\n", __LINE__, __FUNCTION__, name, message_size, number_of_messages); | ||||||
|  | 
 | ||||||
|  |     *queue = rt_mq_create(name, message_size, number_of_messages, RT_IPC_FLAG_FIFO); | ||||||
|  |     if (*queue == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("err!! create xqueue fail\n"); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s end queue:0x%08x\n", __LINE__, __FUNCTION__, *queue); | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_push_to_xqueue( _xqueue* queue, void* message, u32 timeout_ms ) | static int _rtthread_push_to_xqueue( _xqueue* queue, void* message, u32 timeout_ms ) | ||||||
|  | { | ||||||
|  |     RT_ASSERT(*queue != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s queue:0x%08x timeout_ms:%d\n", __LINE__, __FUNCTION__, *queue, timeout_ms); | ||||||
|  |     if (rt_mq_send(*queue, message, ((rt_mq_t)*queue)->msg_size) != RT_EOK) | ||||||
|     { |     { | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_pop_from_xqueue( _xqueue* queue, void* message, u32 timeout_ms ) | static int _rtthread_pop_from_xqueue( _xqueue* queue, void* message, u32 timeout_ms ) | ||||||
|  | { | ||||||
|  |     rt_uint32_t tick; | ||||||
|  | 
 | ||||||
|  |     RT_ASSERT(*queue != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s queue:0x%08x msg:0x%08x timeout_ms:%d\n", __LINE__, __FUNCTION__, *queue, message, timeout_ms); | ||||||
|  |     if(timeout_ms >= RT_TICK_MAX / 2)  | ||||||
|  |         tick = RT_WAITING_FOREVER; | ||||||
|  |     else  | ||||||
|  |         tick = rtw_ms_to_systime(timeout_ms); | ||||||
|  | 
 | ||||||
|  |     if (rt_mq_recv(*queue, message, ((rt_mq_t)*queue)->msg_size, tick) != RT_EOK) | ||||||
|     { |     { | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_deinit_xqueue( _xqueue* queue ) | static int _rtthread_deinit_xqueue( _xqueue* queue ) | ||||||
| { | { | ||||||
|     return -1; |     RT_ASSERT(*queue != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s queue:0x%08x\n", __LINE__, __FUNCTION__, *queue); | ||||||
|  |     rt_mq_delete(*queue); | ||||||
|  |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static u32 _rtthread_get_current_time(void) | static u32 _rtthread_get_current_time(void) | ||||||
| { | { | ||||||
|     return rt_tick_get(); |     return (u32)rt_tick_get(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static u32 _rtthread_systime_to_ms(u32 systime) | static u32 _rtthread_systime_to_ms(u32 systime) | ||||||
|  | @ -339,14 +456,14 @@ static u32 _rtthread_sec_to_systime(u32 sec) | ||||||
| 
 | 
 | ||||||
| static void _rtthread_msleep_os(int ms) | static void _rtthread_msleep_os(int ms) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s ms:%d\n", __LINE__, __FUNCTION__, ms); | ||||||
| #if defined(CONFIG_PLATFORM_8195A) | #if defined(CONFIG_PLATFORM_8195A) | ||||||
|     rt_thread_delay(rt_tick_from_millisecond(ms)); |     rt_thread_delay(rt_tick_from_millisecond(ms)); | ||||||
| #elif defined(CONFIG_PLATFORM_8711B) | #elif defined(CONFIG_PLATFORM_8711B) | ||||||
| 	if (pmu_yield_os_check()) { |     if (pmu_yield_os_check())  | ||||||
|         rt_thread_delay(rt_tick_from_millisecond(ms)); |         rt_thread_delay(rt_tick_from_millisecond(ms)); | ||||||
| 	} else { |     else  | ||||||
|         DelayMs(ms); |         DelayMs(ms); | ||||||
| 	} |  | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -359,8 +476,6 @@ static void _rtthread_usleep_os(int us) | ||||||
|     //DBG_ERR("%s: Please Implement micro-second delay\n", __FUNCTION__);
 |     //DBG_ERR("%s: Please Implement micro-second delay\n", __FUNCTION__);
 | ||||||
| #elif defined(CONFIG_PLATFORM_8711B) | #elif defined(CONFIG_PLATFORM_8711B) | ||||||
|     DelayUs(us); |     DelayUs(us); | ||||||
| #else |  | ||||||
| 	#error "Please implement hardware dependent micro second level sleep here" |  | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -388,11 +503,10 @@ static void _rtthread_yield_os(void) | ||||||
| #if defined(CONFIG_PLATFORM_8195A) | #if defined(CONFIG_PLATFORM_8195A) | ||||||
|     rt_thread_yield(); |     rt_thread_yield(); | ||||||
| #elif defined(CONFIG_PLATFORM_8711B) | #elif defined(CONFIG_PLATFORM_8711B) | ||||||
| 	if (pmu_yield_os_check()) { |     if (pmu_yield_os_check())  | ||||||
|         rt_thread_yield(); |         rt_thread_yield(); | ||||||
| 	} else { |     else  | ||||||
|         DelayMs(1); |         DelayMs(1); | ||||||
| 	} |  | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -500,7 +614,7 @@ static int _rtthread_arc4random(void) | ||||||
|     return (int)seed; |     return (int)seed; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int _rtthread_get_random_bytes(void *buf, size_t len) | static int _rtthread_get_random_bytes(void *buf, u32 len) | ||||||
| { | { | ||||||
| #if 1 //becuase of 4-byte align, we use the follow code style.
 | #if 1 //becuase of 4-byte align, we use the follow code style.
 | ||||||
|     unsigned int ranbuf; |     unsigned int ranbuf; | ||||||
|  | @ -539,106 +653,96 @@ static u32 _rtthread_GetFreeHeapSize(void) | ||||||
| #ifndef RT_USING_LWIP | #ifndef RT_USING_LWIP | ||||||
| #define     RT_LWIP_TCPTHREAD_PRIORITY       10 | #define     RT_LWIP_TCPTHREAD_PRIORITY       10 | ||||||
| #endif | #endif | ||||||
| void *tcm_heap_malloc(int size); |  | ||||||
| static int _rtthread_create_task(struct task_struct *ptask, const char *name, | static int _rtthread_create_task(struct task_struct *ptask, const char *name, | ||||||
|     u32  stack_size, u32 priority, thread_func_t func, void *thctx) |     u32  stack_size, u32 priority, thread_func_t func, void *thctx) | ||||||
| { | { | ||||||
|       rt_err_t result; |  | ||||||
|     rt_thread_t tid; |     rt_thread_t tid; | ||||||
|     char * stack; |  | ||||||
| 
 | 
 | ||||||
|     DBG_INFO("create_task %s: ptask 0x%08X, stack %d priority %d \n", name, ptask, stack_size, priority); |     DEBUG_LOG(3, "L:%d fun:%s begin name:%s stack_size:%d priority:%d func:0x%08x thctx:0x%08x\n", \ | ||||||
|  |         __LINE__, __FUNCTION__, name, stack_size, priority, func, thctx); | ||||||
| 
 | 
 | ||||||
|  |     rt_memset(ptask, 0, sizeof(struct task_struct)); | ||||||
|     ptask->task_name = name; |     ptask->task_name = name; | ||||||
|     ptask->blocked = 0; |     ptask->blocked = 0; | ||||||
|     ptask->callback_running = 0; |     ptask->callback_running = 0; | ||||||
| 
 | 
 | ||||||
|     //OSDEP_DBG("&ptask->wakeup_sema: 0x%08X \n", &ptask->wakeup_sema);
 |  | ||||||
|     _rtthread_init_sema(&ptask->wakeup_sema, 0); |     _rtthread_init_sema(&ptask->wakeup_sema, 0); | ||||||
| 
 |     if (ptask->wakeup_sema == RT_NULL) | ||||||
|     //OSDEP_DBG("&ptask->terminate_sema: 0x%08X \n", &ptask->terminate_sema);
 |     { | ||||||
|  |         rt_kprintf("L:%d create wakeup sem fail\n"); | ||||||
|  |         goto _thread_err; | ||||||
|  |     } | ||||||
|     _rtthread_init_sema(&ptask->terminate_sema, 0); |     _rtthread_init_sema(&ptask->terminate_sema, 0); | ||||||
| 
 |     if (ptask->terminate_sema == RT_NULL) | ||||||
|     if(strcmp(name, "rtw_recv_tasklet") == 0) |  | ||||||
|     { |     { | ||||||
|         stack_size = 3000; |         rt_kprintf("L:%d terminate sem fail\n"); | ||||||
|     } |         goto _thread_err; | ||||||
|     else if(strcmp(name, "cmd_thread") == 0) |  | ||||||
|     { |  | ||||||
|         stack_size = 1800; |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         stack_size = stack_size + 512; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     tid = rt_malloc(RT_ALIGN(sizeof(struct rt_thread), 8) + stack_size); |     stack_size = (stack_size * 3); | ||||||
|     if(!tid) |  | ||||||
|     { |  | ||||||
|         rt_kprintf("no memory NULL for thread:%s\n", name); |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     stack = (char *)tid + RT_ALIGN(sizeof(struct rt_thread), 8); |  | ||||||
| 
 | 
 | ||||||
|     priority = RT_LWIP_TCPTHREAD_PRIORITY + priority; |     priority = RT_LWIP_TCPTHREAD_PRIORITY + priority; | ||||||
|     if(priority >= RT_THREAD_PRIORITY_MAX) |     if(priority >= RT_THREAD_PRIORITY_MAX) | ||||||
|     { |  | ||||||
|         priority = RT_THREAD_PRIORITY_MAX - 1; |         priority = RT_THREAD_PRIORITY_MAX - 1; | ||||||
|  | 
 | ||||||
|  |     tid = rt_thread_create(name, func, thctx, stack_size, priority, 10); | ||||||
|  |     if (tid == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("L:%d thread create fail\n"); | ||||||
|  |         goto _thread_err; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     result = rt_thread_init(tid, |  | ||||||
|                            name, |  | ||||||
|                            func, thctx,         // fun, parameter
 |  | ||||||
|                            stack, stack_size,   // stack, size
 |  | ||||||
|                            priority,            //priority
 |  | ||||||
|                            10 |  | ||||||
|                           ); |  | ||||||
| 
 |  | ||||||
|     if(result == RT_EOK) |  | ||||||
|     { |  | ||||||
|     ptask->task = tid; |     ptask->task = tid; | ||||||
|     rt_thread_startup(tid); |     rt_thread_startup(tid); | ||||||
|     } | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s end stack_size:%d priority:%d wakeup:0x%08x terminate:0x%08x\n", \ | ||||||
|  |         __LINE__, __FUNCTION__, stack_size, priority, ptask->wakeup_sema, ptask->terminate_sema); | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
|  | 
 | ||||||
|  | _thread_err: | ||||||
|  |     if (ptask->wakeup_sema) | ||||||
|  |         _rtthread_free_sema(&ptask->wakeup_sema); | ||||||
|  |     if (ptask->terminate_sema) | ||||||
|  |         _rtthread_free_sema(&ptask->terminate_sema); | ||||||
|  |     rt_memset(ptask, 0, sizeof(struct task_struct)); | ||||||
|  |     return RT_FALSE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_delete_task(struct task_struct *ptask) | static void _rtthread_delete_task(struct task_struct *ptask) | ||||||
| { | { | ||||||
| 	if (!ptask->task){ |     if (!ptask->task) | ||||||
| 		DBG_ERR("_rtthread_delete_task(): ptask is NULL!\n"); |     { | ||||||
|  |         rt_kprintf("_rtthread_delete_task(): ptask is NULL!\n"); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     rt_kprintf("[func]:%s [line]:%d\n", __FUNCTION__, __LINE__); |     DEBUG_LOG(2, "L:%d fun:%s name:%s\n", __LINE__, __FUNCTION__, ptask->task_name); | ||||||
|     ptask->blocked = 1; |     ptask->blocked = 1; | ||||||
| 
 | 
 | ||||||
|     _rtthread_up_sema(&ptask->wakeup_sema); |     _rtthread_up_sema(&ptask->wakeup_sema); | ||||||
|     _rtthread_down_sema(&ptask->terminate_sema, TIMER_MAX_DELAY); |     _rtthread_down_sema(&ptask->terminate_sema, TIMER_MAX_DELAY); | ||||||
| 
 | 
 | ||||||
| 	//rtw_deinit_queue(&wq->work_queue);
 |  | ||||||
|     _rtthread_free_sema(&ptask->wakeup_sema); |     _rtthread_free_sema(&ptask->wakeup_sema); | ||||||
|     _rtthread_free_sema(&ptask->terminate_sema); |     _rtthread_free_sema(&ptask->terminate_sema); | ||||||
| 
 | 
 | ||||||
|     ptask->task = 0; |     ptask->task = 0; | ||||||
| 	 |  | ||||||
| 	DBG_TRACE("Delete Task \"%s\"\n", ptask->task_name); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void _rtthread_wakeup_task(struct task_struct *ptask) | void _rtthread_wakeup_task(struct task_struct *ptask) | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(2, "L:%d fun:%s name:%s\n", __LINE__, __FUNCTION__, ptask->task_name); | ||||||
|     _rtthread_up_sema(&ptask->wakeup_sema); |     _rtthread_up_sema(&ptask->wakeup_sema); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_thread_enter(char *name) | static void _rtthread_thread_enter(char *name) | ||||||
| { | { | ||||||
| //	rt_kprintf("RTKTHREAD %s\n", name);
 |     DEBUG_LOG(3, "L:%d fun:%s name:%s\n", __LINE__, __FUNCTION__, name); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _rtthread_thread_exit(void) | static void _rtthread_thread_exit(void) | ||||||
| { | { | ||||||
| //	rt_kprintf("RTKTHREAD exit %s\n", __FUNCTION__); 
 |     DEBUG_LOG(3, "L:%d fun:%s\n", __LINE__, __FUNCTION__); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| _timerHandle _rtthread_timerCreate( const signed char *pcTimerName,  | _timerHandle _rtthread_timerCreate( const signed char *pcTimerName,  | ||||||
|  | @ -651,46 +755,38 @@ _timerHandle _rtthread_timerCreate( const signed char *pcTimerName, | ||||||
|     rt_tick_t time; |     rt_tick_t time; | ||||||
|     rt_uint8_t flag; |     rt_uint8_t flag; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s begin name:%s reload:%d tick:%d fun:0x%08x ID:0x%08x\n",  | ||||||
|  |         __LINE__, __FUNCTION__, pcTimerName, uxAutoReload, xTimerPeriodInTicks, pxCallbackFunction, pvTimerID); | ||||||
|  | 
 | ||||||
|     if(uxAutoReload == 1) |     if(uxAutoReload == 1) | ||||||
|     { |         flag = (RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_PERIODIC); | ||||||
|         flag |= RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_PERIODIC; |  | ||||||
|     } |  | ||||||
|     else |     else | ||||||
|     { |         flag = (RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT); | ||||||
|         flag |= RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     if( xTimerPeriodInTicks >= (RT_TICK_MAX / 2) ) |     if( xTimerPeriodInTicks >= (RT_TICK_MAX / 2) ) | ||||||
|     { |  | ||||||
|         time = (RT_TICK_MAX / 2) - 1; |         time = (RT_TICK_MAX / 2) - 1; | ||||||
|     } |  | ||||||
|     else |     else | ||||||
|     { |  | ||||||
|         time = xTimerPeriodInTicks; |         time = xTimerPeriodInTicks; | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     timer = rt_timer_create(pcTimerName, |     timer = rt_timer_create(pcTimerName, pxCallbackFunction, RT_NULL, time, flag); | ||||||
|                             pxCallbackFunction, |     if(timer == RT_NULL) | ||||||
|                             RT_NULL, |  | ||||||
|                             time, |  | ||||||
|                             flag); |  | ||||||
| 
 |  | ||||||
|     //OSDEP_DBG("%s: %s 0x%08X tick:%d uxAutoReload:%d, Callback:0x%08X, pvTimerID:0x%08X, \n", __FUNCTION__, pcTimerName, timer, xTimerPeriodInTicks, uxAutoReload, pxCallbackFunction, pvTimerID);
 |  | ||||||
| 
 |  | ||||||
|     if(timer) |  | ||||||
|     { |     { | ||||||
|         timer->parameter = timer; |         rt_kprintf("timer create fail\n"); | ||||||
|  |         return RT_NULL; | ||||||
|     } |     } | ||||||
|  |     timer->parameter = timer; | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s end timer:0x%08x\n", __LINE__, __FUNCTION__, timer); | ||||||
| 
 | 
 | ||||||
|     return (_timerHandle)timer; |     return (_timerHandle)timer; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32 _rtthread_timerDelete( _timerHandle xTimer,  | u32 _rtthread_timerDelete(_timerHandle xTimer, osdepTickType xBlockTime) | ||||||
| 							   osdepTickType xBlockTime ) |  | ||||||
| { | { | ||||||
|     if(rt_timer_delete(xTimer) != RT_EOK) |     DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|         return RT_FALSE; |  | ||||||
| 
 | 
 | ||||||
|  |     RT_ASSERT(xTimer != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     rt_timer_delete(xTimer); | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -698,31 +794,36 @@ u32 _rtthread_timerIsTimerActive( _timerHandle xTimer ) | ||||||
| { | { | ||||||
|     rt_timer_t pxTimer = (rt_timer_t)xTimer; |     rt_timer_t pxTimer = (rt_timer_t)xTimer; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|     if(!xTimer) |     if(!xTimer) | ||||||
|     { |     { | ||||||
|  |         rt_kprintf("err!! timer is active null\n"); | ||||||
|         return 0; |         return 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return (pxTimer->parent.flag & RT_TIMER_FLAG_ACTIVATED) ? 1 : 0; |     return (pxTimer->parent.flag & RT_TIMER_FLAG_ACTIVATED) ? 1 : 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32  _rtthread_timerStop( _timerHandle xTimer,  | u32  _rtthread_timerStop(_timerHandle xTimer, osdepTickType xBlockTime) | ||||||
| 							   osdepTickType xBlockTime ) |  | ||||||
| { | { | ||||||
|     rt_err_t result = rt_timer_stop(xTimer); |     RT_ASSERT(xTimer != RT_NULL); | ||||||
|     if(result != RT_EOK) |  | ||||||
|         return RT_FALSE; |  | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|  |     if (rt_timer_stop(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         // rt_kprintf("timer stop fail\n");
 | ||||||
|  |         return RT_FALSE; | ||||||
|  |     } | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32  _rtthread_timerChangePeriod( _timerHandle xTimer,  | u32  _rtthread_timerChangePeriod( _timerHandle xTimer, osdepTickType xNewPeriod, osdepTickType xBlockTime ) | ||||||
| 							   osdepTickType xNewPeriod,  |  | ||||||
| 							   osdepTickType xBlockTime ) |  | ||||||
| { | { | ||||||
|     rt_err_t result; |  | ||||||
|     int time; |     int time; | ||||||
| 
 | 
 | ||||||
|  |     RT_ASSERT(xTimer != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x new_tick:%d\n", __LINE__, __FUNCTION__, xTimer, xNewPeriod); | ||||||
|     if(xNewPeriod == 0) |     if(xNewPeriod == 0) | ||||||
|         time = 1; |         time = 1; | ||||||
|     else if(xNewPeriod >= (RT_TICK_MAX / 2)) |     else if(xNewPeriod >= (RT_TICK_MAX / 2)) | ||||||
|  | @ -730,11 +831,14 @@ u32  _rtthread_timerChangePeriod( _timerHandle xTimer, | ||||||
|     else |     else | ||||||
|         time = xNewPeriod; |         time = xNewPeriod; | ||||||
| 
 | 
 | ||||||
|     result = rt_timer_stop(xTimer); |     rt_timer_stop(xTimer); | ||||||
|     result = rt_timer_control(xTimer, RT_TIMER_CTRL_SET_TIME, (void *)&time); |     rt_timer_control(xTimer, RT_TIMER_CTRL_SET_TIME, (void *)&time); | ||||||
| 
 | 
 | ||||||
|     if(rt_timer_start(xTimer) != RT_EOK) |     if(rt_timer_start(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("change time and timer start fail\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
|  | @ -743,41 +847,79 @@ void *_rtthread_timerGetID( _timerHandle xTimer ) | ||||||
|     return xTimer; |     return xTimer; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32  _rtthread_timerStart( _timerHandle xTimer,  | u32  _rtthread_timerStart( _timerHandle xTimer, osdepTickType xBlockTime ) | ||||||
| 							   osdepTickType xBlockTime ) |  | ||||||
| { | { | ||||||
|  |     RT_ASSERT(xTimer != RT_NULL); | ||||||
|  | 
 | ||||||
|  |     DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|     if(rt_timer_start(xTimer) != RT_EOK) |     if(rt_timer_start(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("change time and timer start fail\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32  _rtthread_timerStartFromISR( _timerHandle xTimer,  | u32  _rtthread_timerStartFromISR( _timerHandle xTimer, osdepBASE_TYPE *pxHigherPriorityTaskWoken ) | ||||||
| 							   osdepBASE_TYPE *pxHigherPriorityTaskWoken ) |  | ||||||
| { | { | ||||||
|     if(rt_timer_start(xTimer) != RT_EOK) |     DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|  | 
 | ||||||
|  |     if (xTimer == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer start from isr null\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if(rt_timer_start(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer start from isr fail\n"); | ||||||
|  |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE;   |     return RT_TRUE;   | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32  _rtthread_timerStopFromISR( _timerHandle xTimer,  | u32  _rtthread_timerStopFromISR( _timerHandle xTimer, osdepBASE_TYPE *pxHigherPriorityTaskWoken ) | ||||||
| 							   osdepBASE_TYPE *pxHigherPriorityTaskWoken ) |  | ||||||
| { | { | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|  | 
 | ||||||
|  |     if (xTimer == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer start from isr null\n"); | ||||||
|  |         return RT_FALSE; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     if(rt_timer_stop(xTimer) != RT_EOK) |     if(rt_timer_stop(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer stop from isr fail\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| u32  _rtthread_timerResetFromISR( _timerHandle xTimer,  | u32  _rtthread_timerResetFromISR( _timerHandle xTimer, osdepBASE_TYPE *pxHigherPriorityTaskWoken ) | ||||||
| 							   osdepBASE_TYPE *pxHigherPriorityTaskWoken ) |  | ||||||
| { | { | ||||||
|     if(rt_timer_stop(xTimer) != RT_EOK) |     DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|  | 
 | ||||||
|  |     if (xTimer == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer Reset from isr null\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if(rt_timer_stop(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer Reset from isr stop fail\n"); | ||||||
|  |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if(rt_timer_start(xTimer) != RT_EOK) |     if(rt_timer_start(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer Reset from isr start fail\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
|  | @ -786,9 +928,16 @@ u32  _rtthread_timerChangePeriodFromISR( _timerHandle xTimer, | ||||||
|                                osdepTickType xNewPeriod,  |                                osdepTickType xNewPeriod,  | ||||||
|                                osdepBASE_TYPE *pxHigherPriorityTaskWoken ) |                                osdepBASE_TYPE *pxHigherPriorityTaskWoken ) | ||||||
| { | { | ||||||
|     rt_err_t result; |  | ||||||
|     int time; |     int time; | ||||||
| 
 | 
 | ||||||
|  |     DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|  | 
 | ||||||
|  |     if (xTimer == RT_NULL) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer Change Period from isr null\n"); | ||||||
|  |         return RT_FALSE; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     if(xNewPeriod == 0) |     if(xNewPeriod == 0) | ||||||
|         time = 1; |         time = 1; | ||||||
|     else if(xNewPeriod >= (RT_TICK_MAX / 2)) |     else if(xNewPeriod >= (RT_TICK_MAX / 2)) | ||||||
|  | @ -796,11 +945,14 @@ u32  _rtthread_timerChangePeriodFromISR( _timerHandle xTimer, | ||||||
|     else |     else | ||||||
|         time = xNewPeriod; |         time = xNewPeriod; | ||||||
| 
 | 
 | ||||||
|     result = rt_timer_stop(xTimer); |     rt_timer_stop(xTimer); | ||||||
|     result = rt_timer_control(xTimer, RT_TIMER_CTRL_SET_TIME, (void *)&time); |     rt_timer_control(xTimer, RT_TIMER_CTRL_SET_TIME, (void *)&time); | ||||||
| 
 | 
 | ||||||
|     if(rt_timer_start(xTimer) != RT_EOK) |     if(rt_timer_start(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer Change Period from isr start fail\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
|  | @ -808,14 +960,16 @@ u32  _rtthread_timerChangePeriodFromISR( _timerHandle xTimer, | ||||||
| u32  _rtthread_timerReset( _timerHandle xTimer,  | u32  _rtthread_timerReset( _timerHandle xTimer,  | ||||||
|                                osdepTickType xBlockTime ) |                                osdepTickType xBlockTime ) | ||||||
| { | { | ||||||
|     rt_err_t result = rt_timer_stop(xTimer); |     RT_ASSERT(xTimer != RT_NULL); | ||||||
| 
 | 
 | ||||||
|     if(result != RT_EOK) |     DEBUG_LOG(2, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer); | ||||||
|         return RT_FALSE; |  | ||||||
| 
 | 
 | ||||||
|     result = rt_timer_start(xTimer); |     rt_timer_stop(xTimer); | ||||||
|     if(result != RT_EOK) |     if(rt_timer_start(xTimer) != RT_EOK) | ||||||
|  |     { | ||||||
|  |         rt_kprintf("timer reset fail\n"); | ||||||
|         return RT_FALSE; |         return RT_FALSE; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return RT_TRUE; |     return RT_TRUE; | ||||||
| } | } | ||||||
|  | @ -862,7 +1016,7 @@ void _rtthread_wakelock_timeout(uint32_t timeout) | ||||||
|      |      | ||||||
| #elif defined(CONFIG_PLATFORM_8711B) | #elif defined(CONFIG_PLATFORM_8711B) | ||||||
|     if (pmu_yield_os_check())  |     if (pmu_yield_os_check())  | ||||||
| 		pmu_set_sysactive_time(PMU_WLAN_DEVICE, timeout); |         pmu_set_sysactive_time(/*PMU_WLAN_DEVICE, */timeout); | ||||||
|     else |     else | ||||||
|         printf("can't aquire wake during suspend flow!!\n"); |         printf("can't aquire wake during suspend flow!!\n"); | ||||||
| #endif | #endif | ||||||
|  | @ -881,7 +1035,6 @@ u8 _rtthread_get_scheduler_state(void) | ||||||
|     return state; |     return state; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| const struct osdep_service_ops osdep_service = { | const struct osdep_service_ops osdep_service = { | ||||||
|     _rtthread_malloc,           //rtw_vmalloc
 |     _rtthread_malloc,           //rtw_vmalloc
 | ||||||
|     _rtthread_zmalloc,          //rtw_zvmalloc
 |     _rtthread_zmalloc,          //rtw_zvmalloc
 | ||||||
|  | @ -992,4 +1145,3 @@ uint32_t xTaskGetTickCount( void ) | ||||||
|     return rt_tick_get(); |     return rt_tick_get(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -11,6 +11,8 @@ | ||||||
| #include "build_info.h" | #include "build_info.h" | ||||||
| #include "rtconfig.h" | #include "rtconfig.h" | ||||||
| 
 | 
 | ||||||
|  | extern int rtthread_startup(void); | ||||||
|  | 
 | ||||||
| void APP_Start(void) | void APP_Start(void) | ||||||
| { | { | ||||||
| #if CONFIG_SOC_PS_MODULE | #if CONFIG_SOC_PS_MODULE | ||||||
|  |  | ||||||
|  | @ -53,7 +53,7 @@ | ||||||
| /*
 | /*
 | ||||||
|  * < CONFIG OS  |  * < CONFIG OS  | ||||||
|  */ |  */ | ||||||
| #define CONFIG_KERNEL 1 | // #define CONFIG_KERNEL 0
 | ||||||
| #define PLATFORM_FREERTOS 1 | #define PLATFORM_FREERTOS 1 | ||||||
| #undef  PLATFORM_UCOSII | #undef  PLATFORM_UCOSII | ||||||
| #undef  PLATFORM_ECOS | #undef  PLATFORM_ECOS | ||||||
|  |  | ||||||
|  | @ -297,6 +297,7 @@ UartLogCmdExecuteRam( | ||||||
| 	return FALSE; | 	return FALSE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #ifdef CONFIG_KERNEL | ||||||
| 
 | 
 | ||||||
| VOID | VOID | ||||||
| RtlConsolTaskRam( | RtlConsolTaskRam( | ||||||
|  | @ -361,6 +362,7 @@ RtlConsolTaskRam( | ||||||
| 		} | 		} | ||||||
| 	}while(1); | 	}while(1); | ||||||
| } | } | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|   * @brief    Set UartLog Baud Rate use baudrate val. |   * @brief    Set UartLog Baud Rate use baudrate val. | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue