亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美日韩夫妻久久| 3d成人h动漫网站入口| 欧美午夜精品久久久久久超碰 | av男人天堂一区| 蜜臂av日日欢夜夜爽一区| 国产激情视频一区二区在线观看| 成人黄色大片在线观看| 欧美一区二区三区精品| 国产欧美综合在线观看第十页| 一区二区三区四区精品在线视频| 日韩国产精品久久| 成人免费视频免费观看| 欧美一级欧美三级在线观看| 国产香蕉久久精品综合网| 免费成人在线观看视频| 成人午夜激情影院| 色哟哟亚洲精品| 久久免费电影网| 亚洲国产欧美在线| 97成人超碰视| 日韩欧美第一区| 日韩高清一级片| 97久久精品人人爽人人爽蜜臀| 日韩免费高清电影| 亚洲一区二区三区视频在线| 国产精品一级片| 久久影院午夜论| 视频一区二区欧美| 在线看日韩精品电影| 久久午夜国产精品| 日本在线不卡视频| 欧美亚洲综合久久| 亚洲色图视频免费播放| 国产福利91精品一区二区三区| 欧美日本乱大交xxxxx| 亚洲三级久久久| 91免费国产在线观看| 久久夜色精品国产欧美乱极品| 精品一区二区三区在线观看国产| 在线看日韩精品电影| 亚洲一二三专区| 日本乱人伦aⅴ精品| 精品日韩av一区二区| 国产美女视频91| 精品美女被调教视频大全网站| 日本v片在线高清不卡在线观看| 色悠悠亚洲一区二区| 最新成人av在线| 99免费精品视频| 欧美精品久久天天躁| 天天色 色综合| 欧美三级日韩在线| 美脚の诱脚舐め脚责91 | 中文字幕亚洲不卡| 成人美女视频在线看| 一区二区三区四区国产精品| jlzzjlzz亚洲日本少妇| 亚洲综合在线视频| 在线观看日韩一区| 亚洲特级片在线| 欧美日韩一级片在线观看| 丝袜美腿亚洲色图| 国产亚洲精品7777| 成人激情图片网| 亚洲一区二区三区小说| 欧美疯狂做受xxxx富婆| 国产一区二区在线观看免费 | 国产精品久久久久9999吃药| 91在线观看高清| 洋洋成人永久网站入口| 精品剧情v国产在线观看在线| 蜜臀久久99精品久久久久宅男 | 国产精品自拍一区| 亚洲免费高清视频在线| 欧美日韩午夜影院| 国产精品一级黄| 亚洲免费资源在线播放| 欧美一区二区三区免费| 丰满岳乱妇一区二区三区| 亚洲成a人在线观看| 欧美mv和日韩mv的网站| 国产一区日韩二区欧美三区| 一区二区三区四区不卡在线| 欧美军同video69gay| 成人黄页在线观看| 亚洲成人777| 亚洲欧美国产毛片在线| 欧美日韩中文一区| 老司机精品视频线观看86| 国产精品全国免费观看高清| 在线欧美日韩精品| 黄色成人免费在线| 中文字幕不卡在线观看| 欧美一区二区三区婷婷月色| 国产高清久久久| 蜜臀国产一区二区三区在线播放| 欧美韩日一区二区三区四区| 欧美另类变人与禽xxxxx| 国产精品99久久久久| 美腿丝袜亚洲三区| 亚洲三级免费电影| 国产精品乱码一区二三区小蝌蚪| 欧美日韩一卡二卡| 国产一区二区导航在线播放| 亚洲大片精品永久免费| 国产精品私房写真福利视频| 91麻豆精品91久久久久久清纯| 国产成都精品91一区二区三| 国产最新精品精品你懂的| 亚洲一区二区3| 亚洲精品五月天| 国产日韩av一区| 久久精品人人做人人爽97| 欧美一级欧美三级在线观看| 91精品国产91热久久久做人人 | 伊人开心综合网| 国产欧美精品一区二区三区四区| 久久网站最新地址| 欧美一级国产精品| 日韩一区二区不卡| 欧美日韩国产a| 欧美日韩另类一区| 色综合激情久久| 91亚洲国产成人精品一区二三| 韩国一区二区在线观看| 亚洲成人午夜电影| 午夜国产精品一区| 一区二区三区四区高清精品免费观看| 亚洲卡通欧美制服中文| 中文字幕免费不卡| 亚洲免费资源在线播放| 亚洲天堂久久久久久久| 一区二区三区欧美视频| 亚洲欧美日本在线| 亚洲国产日韩在线一区模特| 亚洲自拍偷拍网站| 日韩高清中文字幕一区| 午夜精品福利一区二区三区av | 精品少妇一区二区三区日产乱码| 欧美电影精品一区二区| 精品国产一区二区精华| 中国色在线观看另类| 国产精品剧情在线亚洲| 亚洲欧洲综合另类在线| 亚洲午夜免费电影| 老司机精品视频线观看86| 韩国成人在线视频| 不卡的电影网站| 色婷婷综合久久| 亚洲成年人影院| 国产乱人伦精品一区二区在线观看| 亚洲精品老司机| 免费成人在线播放| 激情图片小说一区| 色综合中文字幕国产 | 欧美aaa在线| 亚洲电影第三页| 国产一区二区三区蝌蚪| 老司机精品视频线观看86| 97成人超碰视| 欧美精品色一区二区三区| 国产精品午夜电影| 亚洲宅男天堂在线观看无病毒| 精品无人区卡一卡二卡三乱码免费卡| 国产资源精品在线观看| 欧美在线制服丝袜| 欧美成人高清电影在线| 亚洲激情校园春色| 久久成人精品无人区| 日本道精品一区二区三区| 91麻豆精品国产91| 一区二区三区在线免费视频| 青青草视频一区| 91久久国产综合久久| 日韩欧美123| 亚洲高清在线精品| 国产成人自拍高清视频在线免费播放| 欧美日韩国产三级| 国产精品丝袜久久久久久app| 五月婷婷另类国产| 国产成人av福利| 欧美v日韩v国产v| 亚洲一区二区欧美| 色综合久久中文综合久久97| 精品美女一区二区| 精品欧美乱码久久久久久1区2区| 一区二区三区资源| 午夜精品久久久久久久久| av午夜一区麻豆| 欧美一区二区在线免费观看| 亚洲国产日韩在线一区模特| 国产一区二区影院| 久久久综合激的五月天| 亚洲资源在线观看| 在线精品视频免费播放| 日本一区二区视频在线观看| 国产一区二区女| 91麻豆精品国产91久久久久| 人人超碰91尤物精品国产| va亚洲va日韩不卡在线观看|