亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sos_timer.c

?? 嵌入式操作系統內核
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* -*- Mode: C; tab-width:4 -*- *//* ex: set ts=4 shiftwidth=4 softtabstop=4 cindent: *//**  * @brief delta timer implementation * @author Simon Han * @brief Pre-allocated timers with safe blocks * @author Ram Kumar */#include <sos_timer.h>#include <message_queue.h>#include <malloc.h>#include <hardware_types.h>#include <timer.h>#include <message.h>#include <measurement.h>#include <sos_sched.h>#include <sos_info.h>#include <sos_list.h>#include <sos_logging.h>#ifndef SOS_DEBUG_TIMER#undef DEBUG#define DEBUG(...)#undef DEBUG_SHORT#define DEBUG_SHORT(...)#define print_all_timers(...)#endif#define MAX_SLEEP_INTERVAL 250#define MAX_REALTIME_CLOCK 4//------------------------------------------------------------------------// INTERNAL DATA STRUCTURE//------------------------------------------------------------------------typedef struct {	uint16_t value;	uint16_t interval;	timer_callback_t f;} timer_realtime_t;//------------------------------------------------------------------------// GLOBAL VARIABLES//------------------------------------------------------------------------static list_t   deltaq;              //!< Timer delta queuestatic list_t   timer_pool;          //!< Pool of initialized timersstatic list_t   prealloc_timer_pool; //!< Pool of pre-allocated timersstatic list_t  periodic_pool;        //!< periodic pool used by soft_interruptstatic int32_t  outstanding_ticks = 0; static uint8_t num_realtime_clock = 0;static timer_realtime_t realtime[MAX_REALTIME_CLOCK];//static bool hw_interval_set = false;//------------------------------------------------------------------------// STATIC FUNCTION PROTOTYPES//------------------------------------------------------------------------static void timer_delta_q_insert(sos_timer_t *h, bool new_timer);static sos_timer_t* find_timer_block(sos_pid_t pid, uint8_t tid);static sos_timer_t *find_timer_in_periodic_pool(sos_pid_t pid, uint8_t tid);static sos_timer_t* alloc_from_timer_pool(sos_pid_t pid, uint8_t tid);static sos_timer_t* alloc_from_preallocated_timer_pool(sos_pid_t pid);static int8_t timer_remove_timer(sos_timer_t *tt);static void timer_update_delta(void);static void timer_pre_alloc_block_init(sos_timer_t *h, sos_pid_t pid);static uint16_t timer_update_realtime_clock(uint8_t cnt);//------------------------------------------------------------------------// KERNEL FUNCTIONS//------------------------------------------------------------------------/** * @brief Initialize the timer unit */void timer_init(void){	uint8_t i;  list_init(&deltaq);  list_init(&timer_pool);  list_init(&prealloc_timer_pool);  list_init(&periodic_pool);  for(i = 0; i < MAX_REALTIME_CLOCK; i++) {	realtime[i].f = NULL;    }}/** * @brief Pre-allocate timers for a module at load time */int8_t timer_preallocate(sos_pid_t pid, uint8_t num_timers){   // We have already checked if num_timer > 0 and pid is not NULL_PID  uint8_t i, j;  sos_timer_t* tt[MAX_PRE_ALLOCATED_TIMERS];     //! We cannot allow a single module to pre allocate a lot of timers  if (num_timers > MAX_PRE_ALLOCATED_TIMERS)	return -EINVAL;    //! First try to safely allocate memory blocks for all the pre-allocated timers  for (i = 0; i < num_timers; i++){	tt[i] = (sos_timer_t*)malloc_longterm(sizeof(sos_timer_t), TIMER_PID);	if (tt[i] == NULL){	  for (j = 0; j < i; j++){		ker_free(tt[j]);	  }	  return -ENOMEM;	}     }     //! If we get here then we have all the memory allocated   //! Now initialize all the data structures and just add them to the timer pool  for (i = 0; i < num_timers; i++){	timer_pre_alloc_block_init(tt[i], pid);  }    return SOS_OK;}/** * @brief remove timers for a particular pid */int8_t timer_remove_all(sos_pid_t pid){  list_link_t *link;    for(link = deltaq.l_next;	  link != (&deltaq); link = link->l_next) {	sos_timer_t *h = (sos_timer_t*)link;         	if(h->pid == pid) {	  link = link->l_prev;	  timer_remove_timer(h);	  ker_free(h);	  //	break; Ram - Why are we breaking from this loop ?	}  }	  for (link = timer_pool.l_next; link != (&timer_pool); link = link->l_next){	sos_timer_t *h = (sos_timer_t*)link;	if (h->pid == pid){	  link = link->l_prev;	  list_remove((list_link_t*)h);	  ker_free(h);	}  }  for (link = prealloc_timer_pool.l_next; link != (&prealloc_timer_pool); link = link->l_next){	sos_timer_t *h = (sos_timer_t*)link;	if (h->pid == pid){	  link = link->l_prev;	  list_remove((list_link_t*)h);	  ker_free(h);	}  }  for (link = periodic_pool.l_next; link != (&periodic_pool); link = link->l_next){	sos_timer_t *h = (sos_timer_t*)link;	if (h->pid == pid){	  link = link->l_prev;	  list_remove((list_link_t*)h);	  ker_free(h);	}  }  return SOS_OK;}#ifdef FAULT_TOLERANT_SOSint8_t timer_micro_reboot(sos_module_t *handle){  sos_pid_t pid;  list_link_t *link;  mod_header_ptr hdr;  uint8_t num_timers_left;    pid = handle->pid;  hdr = handle->header;  num_timers_left = sos_read_header_byte(hdr, offsetof(mod_header_t, num_timers));  DEBUG("Timer: Pre-alloc timers requested %d \n", num_timers_left);    if (num_timers_left > 0){	for (link = prealloc_timer_pool.l_next;		 link != (&prealloc_timer_pool);		 link = link->l_next){	  sos_timer_t *h = (sos_timer_t*)link;	  if (h->pid == pid)		num_timers_left--; // Assert - This value should NEVER become negative	}  }  DEBUG("Timer: Timers left to pre-allocate %d \n", num_timers_left);      //! Stop all timers of pid  //! Move timer blocks to the pre-allocated pool  //! or free them  for (link = deltaq.l_next;	   link != (&deltaq);	   link = link->l_next){	sos_timer_t *h = (sos_timer_t*)link;	if (h->pid == pid){	  link = link->l_prev;	  timer_remove_timer(h);	  if (num_timers_left > 0){		num_timers_left--;		timer_pre_alloc_block_init(h, pid);		DEBUG("Timer: Allocated active timer \n");	  }	  else		ker_free(h);	}  }    //! Remove all initialized timers  //! Move timer blocks to the pre-allocated pool  //! or free them  for (link = timer_pool.l_next;	   link != (&timer_pool);	   link = link->l_next){	sos_timer_t *h = (sos_timer_t*)link;	if (h->pid == pid){	  link = link->l_prev;	  list_remove((list_link_t*)h);	  if (num_timers_left > 0){		num_timers_left--;		timer_pre_alloc_block_init(h, pid);		DEBUG("Timer: Allocated an initialzed but non-running timer\n");	  }	  else		ker_free(h);	}  }    //! If necessary, allocate memory for the pre-allocated timers  if (num_timers_left > 0){ 	DEBUG("Timer: Alloc more memory for timers\n");     	if (timer_preallocate(pid, num_timers_left) != SOS_OK)	  return -ENOMEM;  }  return SOS_OK;}#endif//------------------------------------------------------------------------// STATIC FUNCTIONS//------------------------------------------------------------------------/** * @brief Initialize the pre-allocated timer blocks */ static void timer_pre_alloc_block_init(sos_timer_t *h, sos_pid_t pid){   h->pid = pid;                  //! Indicate ownership of a timer block   h->flag = TIMER_PRE_ALLOCATED; //! Pre-allocated timer block   list_insert_tail(&prealloc_timer_pool, (list_link_t*)h);}static void timer_set_hw_interval(int32_t cnt){	if( cnt < TIMER_MIN_INTERVAL ) {		DEBUG("set hw top to %d\n", TIMER_MIN_INTERVAL );		timer_setInterval(TIMER_MIN_INTERVAL);	} else if( cnt > MAX_SLEEP_INTERVAL ) {		DEBUG("set hw top to %d\n", MAX_SLEEP_INTERVAL);		timer_setInterval(MAX_SLEEP_INTERVAL);	} else {		DEBUG("set hw top to %d\n", cnt);		timer_setInterval((uint8_t)cnt);	}}static void timer_set_hw_top(int32_t cnt, bool update_outstanding){	uint8_t hw_cnt = timer_hardware_get_counter();	uint16_t rt_cnt;	HAS_CRITICAL_SECTION;	ENTER_CRITICAL_SECTION();	if( update_outstanding ) {		outstanding_ticks += hw_cnt;	} else {		outstanding_ticks = 0;	}	if( num_realtime_clock > 0 ) {		rt_cnt = timer_update_realtime_clock(hw_cnt);		if( rt_cnt < cnt ) {			cnt = rt_cnt;		}	}	timer_set_hw_interval(cnt);	LEAVE_CRITICAL_SECTION();}#ifdef SOS_DEBUG_TIMERstatic void print_all_timers(char *context){	list_link_t *link;	uint8_t i = 0;	DEBUG(" *** ALL TIMER: %s ***\n", context);	for(link = deltaq.l_next;			link != (&deltaq); link = link->l_next, i++) {		sos_timer_t *h = (sos_timer_t*)link;		DEBUG("(%d) pid = %d, tid = %d, ticks = %d, delta = %d, prev = %x, next = %x\n", i, h->pid, h->tid, h->ticks, h->delta, (int)h->list.l_prev, (int)h->list.l_next);	}}#endif/** * @brief insert handle into delta queue * This routine assumes that the data structure is set */static void timer_delta_q_insert(sos_timer_t *h, bool new_timer){	list_link_t *link;	int32_t hw_cnt;	HAS_CRITICAL_SECTION;		DEBUG("ticks = %d, delta = %d\n", h->ticks, h->delta);	if(list_empty(&deltaq) == true) {		//! empty queue		//! start the timer		DEBUG("empty q, set top to %d\n", h->delta);		if( new_timer ) {			// clear any outstnading ticks			// and start new timer			timer_set_hw_top(h->delta, false);		}		list_insert_head(&deltaq, (list_link_t*)h);		return;	}	ENTER_CRITICAL_SECTION();	hw_cnt = outstanding_ticks + timer_hardware_get_counter();	LEAVE_CRITICAL_SECTION();	if( new_timer ) {		// if it is a new timer, we need to add the ticks that are 		// already counted because these ticks will be subtracted 		// later.		// outstanding_ticks + timer_hardware_get_counter() is the 		// ticks that are already passed in time		h->delta += hw_cnt;		DEBUG("get hw_cnt = %d\n", hw_cnt);	}	link = deltaq.l_next;	// Check whether new timer will be new head	// because we need to modify hardware counter if it is the case	if( h->delta < (((sos_timer_t*)link)->delta)) {		DEBUG("new timer will be the head\n");		(((sos_timer_t*)link)->delta) -= (h->delta);		if( new_timer ) {			timer_set_hw_top(h->delta - hw_cnt, true);		}		list_insert_head(&deltaq, (list_link_t*)h);		return;	}	// Work this timer to the current position	for(/* initialized already */ ;		link != (&deltaq); 		link = link->l_next) {		sos_timer_t *curr = (sos_timer_t*)link;		if(h->delta < curr->delta) {			//! insert here			DEBUG("insert to middle\n");			curr->delta -= h->delta;			list_insert_before(link, (list_link_t*)h);			return;		}		h->delta -= curr->delta;	}	DEBUG("insert to tail\n");	list_insert_tail(&deltaq, (list_link_t*)h);	return;}/** * @brief Locate a timer block from the detlaq */static sos_timer_t* find_timer_block(sos_pid_t pid, uint8_t tid){   sos_timer_t* tt;      if (list_empty(&deltaq)){      return NULL;      }      tt = (sos_timer_t*) deltaq.l_next;   do{      if ((tt->pid == pid) &&          (tt->tid == tid))         return tt;      tt = (sos_timer_t*)tt->list.l_next;   } while ((list_t*)tt != &deltaq);   return NULL;}static sos_timer_t *find_timer_in_periodic_pool(sos_pid_t pid, uint8_t tid){   sos_timer_t* tt;   if (list_empty(&periodic_pool) == false) {	   tt = (sos_timer_t*) periodic_pool.l_next;	   do {		   if( (tt->pid == pid) && (tt->tid == tid) ) {				list_remove((list_t*)tt);				return tt;		   }		   tt = (sos_timer_t*)tt->list.l_next;	   } while((list_t*)tt != &periodic_pool);   }   return NULL;}/** * @brief Locate a free timer block from the preallocated timer pool */static sos_timer_t* alloc_from_preallocated_timer_pool(sos_pid_t pid){   sos_timer_t* tt;      if (list_empty(&prealloc_timer_pool))      return NULL;      //! Find an unused pre-allocated block or an intialized block   tt = (sos_timer_t*) prealloc_timer_pool.l_next;   do{	       if (tt->pid == pid)		{		  list_remove((list_t*)tt);		  return tt;		}	  tt = (sos_timer_t*)tt->list.l_next;   } while ((list_t*)tt != &prealloc_timer_pool);      return NULL;}static sos_timer_t* alloc_from_timer_pool(sos_pid_t pid, uint8_t tid){   sos_timer_t* tt;      if (list_empty(&timer_pool)) {      return NULL;   }      //! Find an unused pre-allocated block or an intialized block   tt = (sos_timer_t*) timer_pool.l_next;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品国产成人久久av盗摄| 欧美老女人第四色| 国产女人18毛片水真多成人如厕| 免费的国产精品| 欧美电视剧在线观看完整版| 国产一区在线观看视频| 国产偷国产偷亚洲高清人白洁 | 久久久不卡网国产精品二区| 国产白丝网站精品污在线入口| 国产精品毛片高清在线完整版| 色综合天天狠狠| 日韩二区三区在线观看| 久久综合给合久久狠狠狠97色69| 成人福利视频在线| 亚洲一区二区av在线| 欧美成人精品3d动漫h| 国产精品1024| 亚洲一区二区三区激情| 精品国产精品一区二区夜夜嗨| 国产91高潮流白浆在线麻豆 | 亚洲综合小说图片| 日韩女优毛片在线| 99久久伊人精品| 日本中文字幕不卡| 亚洲国产成人私人影院tom| 色偷偷久久人人79超碰人人澡| 亚洲成精国产精品女| 欧美激情在线看| 欧美精品在欧美一区二区少妇| 国产福利一区二区三区视频在线| 亚洲精品中文字幕乱码三区| 欧美videofree性高清杂交| 91网站在线播放| 精品一区二区三区香蕉蜜桃| 亚洲人成网站精品片在线观看| 91精品国产乱| 91麻豆蜜桃一区二区三区| 另类小说一区二区三区| 亚洲婷婷国产精品电影人久久| 日韩欧美中文一区| 在线精品视频小说1| 国产成人免费9x9x人网站视频| 午夜电影一区二区| 亚洲乱码日产精品bd | 久久久激情视频| 欧美视频在线观看一区| 成人亚洲一区二区一| 久久成人精品无人区| 亚洲国产婷婷综合在线精品| 国产精品网站导航| 久久综合丝袜日本网| 欧美日韩精品电影| 欧美日韩一级视频| 色哟哟一区二区三区| 国产成人精品一区二| 精品在线播放免费| 视频一区在线播放| 亚洲午夜电影在线观看| 亚洲视频小说图片| 国产精品欧美一区二区三区| 久久伊99综合婷婷久久伊| 91精品国产麻豆国产自产在线 | 91麻豆精品久久久久蜜臀| 91精彩视频在线观看| 91在线小视频| 97国产一区二区| 成人丝袜18视频在线观看| 国产呦精品一区二区三区网站| 美日韩黄色大片| 美国三级日本三级久久99| 亚洲www啪成人一区二区麻豆| 亚洲激情图片小说视频| 亚洲蜜桃精久久久久久久| 综合自拍亚洲综合图不卡区| 国产精品高潮呻吟| 国产精品毛片久久久久久久| 国产精品久久二区二区| 亚洲视频一区在线观看| 中文字幕一区二| 最新高清无码专区| 亚洲精品国产一区二区精华液| 亚洲欧美乱综合| 亚洲高清不卡在线| 日本伊人精品一区二区三区观看方式| 亚洲成人免费在线观看| 日韩精品一二三四| 激情综合网最新| 国产精品一区二区久久精品爱涩| 国产成人av电影在线| 成人爽a毛片一区二区免费| 国产99久久久国产精品潘金网站| 国产99一区视频免费| 精品99一区二区| 国产亚洲欧美在线| 国产精品国产三级国产三级人妇| 亚洲人成7777| 婷婷中文字幕综合| 久99久精品视频免费观看| 国产一区二区三区在线观看免费| 国产成人午夜精品5599| 91无套直看片红桃| 欧美二区在线观看| 久久天天做天天爱综合色| 中文字幕一区二区三区蜜月| 亚洲一区在线免费观看| 免费观看成人鲁鲁鲁鲁鲁视频| 国产大陆亚洲精品国产| 在线视频你懂得一区| 日韩欧美中文字幕制服| 中文字幕一区免费在线观看| 亚洲大片在线观看| 国产久卡久卡久卡久卡视频精品| 成人丝袜18视频在线观看| 欧美日韩视频在线第一区| 久久综合资源网| 亚洲国产日日夜夜| 国产电影一区在线| 欧美午夜精品一区二区三区| 日韩亚洲欧美一区二区三区| 国产精品免费视频网站| 日韩黄色片在线观看| 成人做爰69片免费看网站| 欧美三级日韩三级国产三级| 久久久精品免费免费| 偷拍亚洲欧洲综合| 国产69精品一区二区亚洲孕妇| 欧美日韩成人综合天天影院| 国产日产欧美一区| 免费观看久久久4p| 欧洲国产伦久久久久久久| 久久久久久久综合| 午夜久久久久久久久| 成人a级免费电影| 欧美成人免费网站| 亚洲成在人线在线播放| 不卡的看片网站| 日韩欧美一区在线| 亚洲午夜激情av| 91丨porny丨在线| 亚洲国产成人一区二区三区| 蜜臀va亚洲va欧美va天堂| 欧美综合视频在线观看| 欧美激情一区二区三区| 激情文学综合丁香| 日韩欧美国产一区二区三区| 亚洲国产精品视频| 国产精品免费久久| 国产一区亚洲一区| 日韩午夜激情av| 日韩在线a电影| 欧美视频日韩视频在线观看| 国产精品不卡一区| av亚洲精华国产精华| 国产欧美日本一区视频| 国产伦精品一区二区三区免费迷| 制服丝袜日韩国产| 亚洲成人动漫在线免费观看| 欧美性生交片4| 一区二区三区影院| 色国产综合视频| 亚洲午夜三级在线| 91精品1区2区| 亚洲国产欧美在线| 在线亚洲一区观看| 亚洲欧美另类综合偷拍| 日本精品视频一区二区三区| 亚洲欧美自拍偷拍| 一本到一区二区三区| 一区二区久久久久| 在线观看不卡视频| 天涯成人国产亚洲精品一区av| 欧美高清视频不卡网| 男男成人高潮片免费网站| 欧美大白屁股肥臀xxxxxx| 久久国产夜色精品鲁鲁99| 欧美电视剧免费全集观看| 久久国产三级精品| 国产欧美一区二区精品性色| 成人av在线播放网站| 亚洲美女偷拍久久| 欧美日韩国产精品成人| 奇米色777欧美一区二区| 久久综合久久综合久久| 风间由美一区二区三区在线观看| 国产精品无遮挡| 欧美无乱码久久久免费午夜一区| 视频在线观看国产精品| 日韩精品一区二| 成人开心网精品视频| 亚洲免费观看高清在线观看| 欧美日韩一区二区不卡| 色偷偷久久人人79超碰人人澡 | 蜜桃视频在线观看一区二区| 久久久久久电影| 色系网站成人免费| 奇米精品一区二区三区在线观看 | 1024国产精品| 在线成人av网站| 国产91精品精华液一区二区三区| 亚洲日本一区二区|