• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sleep_us函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sleep_us函数的典型用法代码示例。如果您正苦于以下问题:C++ sleep_us函数的具体用法?C++ sleep_us怎么用?C++ sleep_us使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sleep_us函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: _temp_read

uint8_t _temp_read(const temp_def *def)
{
  uint8_t val = 0;

  _temp_pin_out(def);

  for (uint8_t i = 0; i < 8; i++)
  {
    _temp_pin_down(def);

    sleep_us(2); // Pull low for minimum 1 us

    val >>= 1;

    _temp_pin_up(def);
    _temp_pin_in(def);

    sleep_us(2); // Sample within 15 us

    if (_temp_check(def))
    {
      val |= 0x80;
    }

    sleep_us(60); // Cycle lasts at least 60 us

    _temp_pin_out(def);
  }

  return val;
}
开发者ID:logandk,项目名称:sous-vide,代码行数:31,代码来源:stm32f30x_temp.c


示例2: fork_sync_utimer

/**
 * \brief Forks a separate simple milisecond-sleep() -&- sync periodic timer
 *
 * Forks a very basic periodic timer process, that just ms-sleep()s for 
 * the specified interval and then calls the timer function.
 * The new "sync timer" process execution start immediately, the ms-sleep()
 * is called first (so the first call to the timer function will happen
 * \<interval\> seconds after the call to fork_basic_utimer)
 * @param child_id  @see fork_process()
 * @param desc      @see fork_process()
 * @param make_sock @see fork_process()
 * @param f         timer function/callback
 * @param param     parameter passed to the timer function
 * @param uinterval  interval in mili-seconds.
 * @return pid of the new process on success, -1 on error
 * (doesn't return anything in the child process)
 */
int fork_sync_utimer(int child_id, char* desc, int make_sock,
						utimer_function* f, void* param, int uinterval)
{
	int pid;
	ticks_t ts1 = 0;
	ticks_t ts2 = 0;

	pid=fork_process(child_id, desc, make_sock);
	if (pid<0) return -1;
	if (pid==0){
		/* child */
		ts2 = uinterval;
		if (cfg_child_init()) return -1;
		for(;;){
			if(ts2>0) sleep_us(uinterval);
			else sleep_us(1);
			ts1 = get_ticks_raw();
			cfg_update();
			f(TICKS_TO_MS(ts1), param); /* ticks in mili-seconds */
			ts2 = uinterval - get_ticks_raw() + ts1;
		}
	}
	/* parent */
	return pid;
}
开发者ID:SibghatullahSheikh,项目名称:kamailio,代码行数:42,代码来源:timer_proc.c


示例3: _temp_write

void _temp_write(const temp_def *def, uint8_t data)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    _temp_pin_down(def);

    sleep_us(2); // Pull low for minimum 1 us

    if (data & 0x01)
    {
      _temp_pin_up(def);
    }
    else
    {
      _temp_pin_down(def);
    }

    data >>= 1;

    sleep_us(60); // Cycle lasts at least 60 us

    _temp_pin_up(def);
  }

  _temp_pin_up(def);
}
开发者ID:logandk,项目名称:sous-vide,代码行数:26,代码来源:stm32f30x_temp.c


示例4: reload_permanent_list

static inline int reload_permanent_list(struct bl_rule *first,
					struct bl_rule *last,
					struct bl_head *head)
{
	struct bl_rule *p, *q;

	/* get list for write */
	lock_get( head->lock);
	while(head->count_write){
		lock_release( head->lock );
		sleep_us(5);
		lock_get( head->lock );
	}
	head->count_write = 1;
	while(head->count_read){
		lock_release( head->lock );
		sleep_us(5);
		lock_get( head->lock );
	}
	lock_release( head->lock );

	for(p = head->first ; p ; ){
		q = p;
		p = p->next;
		shm_free(q);
	}

	head->first = first;
	head->last = last;

	head->count_write = 0;

	return 0;
}
开发者ID:NoamRom89,项目名称:opensips,代码行数:34,代码来源:blacklists.c


示例5: fork_sync_timer

/**
 * \brief Forks a separate simple sleep() -&- sync periodic timer
 *
 * Forks a very basic periodic timer process, that just sleep()s for 
 * the specified interval and then calls the timer function.
 * The new "sync timer" process execution start immediately, the sleep()
 * is called first (so the first call to the timer function will happen
 * \<interval\> seconds after the call to fork_sync_timer)
 * @param child_id  @see fork_process()
 * @param desc      @see fork_process()
 * @param make_sock @see fork_process()
 * @param f         timer function/callback
 * @param param     parameter passed to the timer function
 * @param interval  interval in seconds.
 * @return pid of the new process on success, -1 on error
 * (doesn't return anything in the child process)
 */
int fork_sync_timer(int child_id, char* desc, int make_sock,
						timer_function* f, void* param, int interval)
{
	int pid;
	ticks_t ts1 = 0;
	ticks_t ts2 = 0;

	pid=fork_process(child_id, desc, make_sock);
	if (pid<0) return -1;
	if (pid==0){
		/* child */
		interval *= 1000;  /* miliseconds */
		ts2 = interval;
		if (cfg_child_init()) return -1;
		for(;;){
			if (ts2>interval)
				sleep_us(1000);    /* 1 milisecond sleep to catch up */
			else
				sleep_us(ts2*1000); /* microseconds sleep */
			ts1 = get_ticks_raw();
			cfg_update();
			f(TICKS_TO_S(ts1), param); /* ticks in sec for compatibility with old
									  timers */
			/* adjust the next sleep duration */
			ts2 = interval - TICKS_TO_MS(get_ticks_raw()) + TICKS_TO_MS(ts1);
		}
	}
	/* parent */
	return pid;
}
开发者ID:AlessioCasco,项目名称:kamailio,代码行数:47,代码来源:timer_proc.c


示例6: delete_expired

static inline void delete_expired(struct bl_head *elem, unsigned int ticks)
{
	struct bl_rule *p, *q;

	p = q = 0;

	/* get list for write */
	lock_get(elem->lock);
	while(elem->count_write){
		lock_release(elem->lock);
		sleep_us(5);
		lock_get(elem->lock);
	}
	elem->count_write = 1;
	while(elem->count_read){
		lock_release(elem->lock);
		sleep_us(5);
		lock_get(elem->lock);
	}
	lock_release(elem->lock);

	if(elem->first==NULL)
		goto done;

	for( q=0,p = elem->first ; p ; q=p,p=p->next) {
		if(p->expire_end > ticks)
			break;
	}

	if (q==NULL)
		/* nothing to remove */
		goto done;

	if (p==NULL) {
		/* remove everything */
		q = elem->first;
		elem->first = elem->last = NULL;
	} else {
		/* remove up to p */
		q->next = 0;
		q = elem->first;
		elem->first = p;
	}

done:
	elem->count_write = 0;

	for( ; q ; ){
		p = q;
		q = q->next;
		shm_free(p);
	}

	return;
}
开发者ID:NoamRom89,项目名称:opensips,代码行数:55,代码来源:blacklists.c


示例7: memcpy

void c_client::client_run_state()
{
	uchar message[UDP1_BUFFER_LONG];
	ushort *num_cmd = (ushort *)&message[2];
	int num_cmd_sent = 0, num_cmd_in = 0, num_cmd_err = 0;

	for (ushort i = 0; i < CMD_SENT; i++)
	{
		if (i % 8 == 0)
		{
			if ((i / 8) % 2 == 1)
				memcpy(message, message1_long, UDP1_BUFFER_LONG);
			else
				memcpy(message, message2_long, UDP1_BUFFER_LONG);
			*num_cmd = i;
			send_block((char *)message, UDP1_BUFFER_LONG);
			num_cmd_sent++;
			sleep_us(10000);
		}
		else
		{
			if (i % 2 == 1)
				memcpy(message, message1_short, 100);
			else
				memcpy(message, message2_short, 100);
			*num_cmd = i;
			send_block((char *)message, 100);
			num_cmd_sent++;
			sleep_us(2000);
		}
		cout_mtx.lock();
		cout << "client out cmd:" << (int) message[0] << " cmd_num=" << *num_cmd << endl;
		cout_mtx.unlock();

		int i1 = receive_block((char *)message);
		if (i1 > 0)
		{
			num_cmd_in++;
			cout_mtx.lock();
			cout << "client in cmd:" << (int)message[0] << " cmd_num=" << *num_cmd << endl;
			if ((i1 != 100) && (i1 != UDP1_BUFFER_LONG))
			{
				cout << "====== ERROR c_client received command length=" << i1 << endl;
				num_cmd_err++;
			}
			cout_mtx.unlock();
		}
	}
	cout_mtx.lock();
	cout << "===== END c_client::server_run_state() =====" << endl;
	cout << "Client sent commands=" << num_cmd_sent << " received=" << num_cmd_in << " wrong commands=" << num_cmd_err << endl;
	cout_mtx.unlock();
}
开发者ID:jlopez2022,项目名称:cpp_utils,代码行数:53,代码来源:Protocol_UDP_V003.cpp


示例8: async_task_run

int async_task_run(int idx)
{
	async_task_t *ptask;
	int received;

	LM_DBG("async task worker %d ready\n", idx);

	for( ; ; ) {
		if(unlikely(_async_task_usleep)) sleep_us(_async_task_usleep);
		if ((received = recvfrom(_async_task_sockets[0],
							&ptask, sizeof(async_task_t*),
							0, NULL, 0)) < 0) {
			LM_ERR("failed to received task (%d: %s)\n", errno, strerror(errno));
			continue;
		}
		if(received != sizeof(async_task_t*)) {
			LM_ERR("invalid task size %d\n", received);
			continue;
		}
		if(ptask->exec!=NULL) {
			LM_DBG("task executed [%p] (%p/%p)\n", ptask,
					ptask->exec, ptask->param);
			ptask->exec(ptask->param);
		}
		shm_free(ptask);
	}

	return 0;
}
开发者ID:4N7HR4X,项目名称:kamailio,代码行数:29,代码来源:async_task.c


示例9: wait_async_reply

static inline struct mi_root* wait_async_reply(struct mi_handler *hdl)
{
	struct mi_root *mi_rpl;
	int i;
	int x;

	for( i=0 ; i<MAX_XMLRPC_WAIT ; i++ ) {
		if (hdl->param)
			break;
		sleep_us(1000*500);
	}

	if (i==MAX_XMLRPC_WAIT) {
		/* no more waiting ....*/
		lock_get(xr_lock);
		if (hdl->param==NULL) {
			hdl->param = XMLRPC_ASYNC_EXPIRED;
			x = 0;
		} else {
			x = 1;
		}
		lock_release(xr_lock);
		if (x==0) {
			LM_INFO("exiting before receiving reply\n");
			return NULL;
		}
	}

	mi_rpl = (struct mi_root *)hdl->param;
	if (mi_rpl==XMLRPC_ASYNC_FAILED)
		mi_rpl = NULL;

	free_async_handler(hdl);
	return mi_rpl;
}
开发者ID:Drooids,项目名称:openser-xmlrpc,代码行数:35,代码来源:xr_server.c


示例10: init_modules

/*
 * Initialize all loaded modules, the initialization
 * is done *AFTER* the configuration file is parsed
 */
int init_modules(void)
{
	struct sr_module* t;

	if(async_task_init()<0)
		return -1;

	for(t = modules; t; t = t->next) {
		if (t->exports.init_f) {
			if (t->exports.init_f() != 0) {
				LM_ERR("Error while initializing module %s\n", t->exports.name);
				return -1;
			}
			/* delay next module init, if configured */
			if(unlikely(modinit_delay>0))
				sleep_us(modinit_delay);
		}
		if (t->exports.response_f)
			mod_response_cbk_no++;
	}
	mod_response_cbks=pkg_malloc(mod_response_cbk_no *
									sizeof(response_function));
	if (mod_response_cbks==0){
		LM_ERR("memory allocation failure for %d response_f callbacks\n",
					mod_response_cbk_no);
		return -1;
	}
	for (t=modules, i=0; t && (i<mod_response_cbk_no); t=t->next) {
		if (t->exports.response_f) {
			mod_response_cbks[i]=t->exports.response_f;
			i++;
		}
	}
	return 0;
}
开发者ID:lbalaceanu,项目名称:kamailio,代码行数:39,代码来源:sr_module.c


示例11: write_to_fifo

int write_to_fifo(const string& fifo, const char * buf, unsigned int len)
{
    int fd_fifo;
    int retry = SER_WRITE_TIMEOUT / SER_WRITE_INTERVAL;

    for(; retry>0; retry--) {

        if((fd_fifo = open(fifo.c_str(),
                           O_WRONLY | O_NONBLOCK)) == -1) {
            ERROR("while opening %s: %s\n",
                  fifo.c_str(),strerror(errno));

            if(retry)
                sleep_us(50000);
        }
        else {
            break;
        }
    }

    if(!retry)
        return -1;

    DBG("write_to_fifo: <%s>\n",buf);
    int l = write(fd_fifo,buf,len);
    close(fd_fifo);

    if(l==-1)
        ERROR("while writing: %s\n",strerror(errno));
    else
        DBG("Write to fifo: completed\n");

    return l;
}
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:34,代码来源:AmUtils.cpp


示例12: calib

static void calib(int max_cnt, s16 *avg_data) {
	int cnt = 0;
	int ax = 0, ay = 0, az = 0, gx = 0, gy = 0, gz = 0;
	while(1){
		sleep_us(10*1000);

		static s16 acc_x, acc_y, acc_z, gy_x, gy_y, gy_z;
		
		if(mouse_sensor_getdata_no_fifo(&acc_x, &acc_y, &acc_z, &gy_x, &gy_y, &gy_z)){
			ax += acc_x;
			ay += acc_y;
			az += acc_z;

			gx += gy_x;
			gy += gy_y;
			gz += gy_z;

			++cnt;
			if(cnt >= max_cnt){
				break;
			}
		}
	}
	avg_data[0] = gx / max_cnt;
	avg_data[1] = gy / max_cnt;
	avg_data[2] = gz / max_cnt;
	avg_data[3] = ax / max_cnt;
	avg_data[4] = ay / max_cnt;
	avg_data[5] = az / max_cnt;

}
开发者ID:zxty123,项目名称:foamProject,代码行数:31,代码来源:airmouse_cali.c


示例13: evrexec_process

void evrexec_process(evrexec_task_t *it, int idx)
{
	sip_msg_t *fmsg;
	sr_kemi_eng_t *keng = NULL;
	str sidx = STR_NULL;

	if(it!=NULL) {
		fmsg = faked_msg_next();
		set_route_type(LOCAL_ROUTE);
		if(it->wait>0) sleep_us(it->wait);
		keng = sr_kemi_eng_get();
		if(keng==NULL) {
			if(it->rtid>=0 && event_rt.rlist[it->rtid]!=NULL) {
				run_top_route(event_rt.rlist[it->rtid], fmsg, 0);
			} else {
				LM_WARN("empty event route block [%.*s]\n",
						it->ename.len, it->ename.s);
			}
		} else {
			sidx.s = int2str(idx, &sidx.len);
			if(sr_kemi_route(keng, fmsg, EVENT_ROUTE,
						&it->ename, &sidx)<0) {
				LM_ERR("error running event route kemi callback\n");
			}
		}
	}
	/* avoid exiting the process */
	while(1) { sleep(3600); }
}
开发者ID:adubovikov,项目名称:kamailio,代码行数:29,代码来源:evrexec_mod.c


示例14: sink_udp

void
sink_udp(int sockfd)	/* TODO: use recvfrom ?? */
{
	int		n, flags;

	if (pauseinit)
		sleep_us(pauseinit*1000);

	for ( ; ; ) {	/* read until peer closes connection; -n opt ignored */
			/* msgpeek = 0 or MSG_PEEK */
		flags = msgpeek;
	oncemore:
		if ( (n = recv(sockfd, rbuf, readlen, flags)) < 0) {
			err_sys("recv error");

		} else if (n == 0) {
			if (verbose)
				fprintf(stderr, "connection closed by peer\n");
			break;

#ifdef	notdef		/* following not possible with TCP */
		} else if (n != readlen)
			err_quit("read returned %d, expected %d", n, readlen);
#else
		}
#endif

		if (verbose) {
			fprintf(stderr, "received %d bytes%s\n", n,
					(flags == MSG_PEEK) ? " (MSG_PEEK)" : "");
			if (verbose > 1) {
	fprintf(stderr, "printing %d bytes\n", n);
				rbuf[n] = 0;	/* make certain it's null terminated */
				fprintf(stderr, "SDAP header: %lx\n", *((long *) rbuf));
				fprintf(stderr, "next long: %lx\n", *((long *) rbuf+4));
				fputs(&rbuf[8], stderr);
			}
		}

		if (pauserw)
			sleep_us(pauserw*1000);

		if (flags != 0) {
			flags = 0;		/* avoid infinite loop */
			goto oncemore;	/* read the message again */
		}
	}
开发者ID:rkks,项目名称:refer,代码行数:47,代码来源:sinkudp.c


示例15: m_usleep

static int m_usleep(struct sip_msg *msg, int *useconds)
{
	LM_DBG("sleep %d\n", *(unsigned int*)useconds);

	sleep_us(*(unsigned int*)useconds);

	return 1;
}
开发者ID:rrb3942,项目名称:opensips,代码行数:8,代码来源:cfgutils.c


示例16: lpc_eep_init

void lpc_eep_init(CORE* core)
{
    LPC_EEPROM->PWRDWN |= LPC_EEPROM_PWRDWN_Msk;
    //EEPROM operates on M3 clock
    LPC_EEPROM->CLKDIV = lpc_power_get_core_clock_inside() / EEP_CLK - 1;
    sleep_us(100);
    LPC_EEPROM->PWRDWN &= ~LPC_EEPROM_PWRDWN_Msk;
}
开发者ID:roma-jam,项目名称:stm32_template,代码行数:8,代码来源:lpc_eep.c


示例17: _temp_init

void _temp_init(const temp_def *def)
{
  // Send initialization sequence
  _temp_pin_out(def);
  _temp_pin_down(def);
  sleep_us(500); // Pull low for minimum 480 us
  _temp_pin_in(def);
  sleep_us(20); // Wait 15 to 60 us
  uint32_t presense_start = timer_now();
  while (_temp_check(def))
  {
    // Presense pulse 60 to 240 us
    if (timer_now() - presense_start > 3) break;
  }
  _temp_pin_out(def);
  _temp_pin_up(def);
  sleep_us(480); // Receive sequence is minimum 480 us
}
开发者ID:logandk,项目名称:sous-vide,代码行数:18,代码来源:stm32f30x_temp.c


示例18: rpc_mtree_match

void rpc_mtree_match(rpc_t* rpc, void* ctx)
{
	str tname = STR_NULL;
	str tomatch = STR_NULL;
	int mode = -1;

	m_tree_t *tr;

	if(!mt_defined_trees())
	{
		rpc->fault(ctx, 500, "Empty tree list.");
		return;
	}

	if (rpc->scan(ctx, ".SSd", &tname, &tomatch, &mode) < 3) {
		rpc->fault(ctx, 500, "Invalid Parameters");
		return;
	}

	if (mode !=0 && mode != 2) {
		rpc->fault(ctx, 500, "Invalid parameter 'mode'");
		return;
	}

again:
	lock_get( mt_lock );
	if (mt_reload_flag) {
		lock_release( mt_lock );
		sleep_us(5);
		goto again;
	}
	mt_tree_refcnt++;
	lock_release( mt_lock );

	tr = mt_get_tree(&tname);
	if(tr==NULL)
	{
		/* no tree with such name*/
		rpc->fault(ctx, 404, "Not found tree");
		goto error;
	}

	if(mt_rpc_match_prefix(rpc, ctx, tr, &tomatch, mode)<0)
	{
		LM_DBG("no prefix found in [%.*s] for [%.*s]\n",
				tname.len, tname.s,
				tomatch.len, tomatch.s);
		rpc->fault(ctx, 404, "Not found");
	}

error:
	lock_get( mt_lock );
	mt_tree_refcnt--;
	lock_release( mt_lock );

}
开发者ID:TheGrandWazoo,项目名称:kamailio,代码行数:56,代码来源:mtree_mod.c


示例19: m_usleep

static int m_usleep(struct sip_msg *msg, char *time, char *str2)
{
	int s;
	if(fixup_get_ivalue(msg, (gparam_t*)time, &s)!=0)
	{
		LM_ERR("cannot get time interval value\n");
		return -1;
	}
	sleep_us((unsigned int)s);
	return 1;
}
开发者ID:lazedo,项目名称:kamailio,代码行数:11,代码来源:cfgutils.c


示例20: digitalWrite

	uint16_t TTP229::ReadForEvent()
	{
		uint16_t buttonState = 0;
		
		for(uint8_t i = 0; i < keys; ++i) // sleep for some kind of slow data reading
		{
			digitalWrite(SCLport, SCLpin, LOW);
			
			sleep_us(1);
			
			digitalWrite(SCLport, SCLpin, HIGH);
			
			sleep_us(1);
			
			if(!digitalRead(SDOportPin, SDOpin))
				buttonState |= _BV(i);
		}
		
		return buttonState;
	}
开发者ID:glararan,项目名称:VAVRL,代码行数:20,代码来源:TTP229.cpp



注:本文中的sleep_us函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sleepmgr_enter_sleep函数代码示例发布时间:2022-05-30
下一篇:
C++ sleep_seconds函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap