本文整理汇总了C++中RTIMER_NOW函数的典型用法代码示例。如果您正苦于以下问题:C++ RTIMER_NOW函数的具体用法?C++ RTIMER_NOW怎么用?C++ RTIMER_NOW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTIMER_NOW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
/*---------------------------------------------------------------------------*/
static void
init(void)
{
radio_is_on = 0;
waiting_for_packet = 0;
PT_INIT(&pt);
rtimer_set(&rt, RTIMER_NOW() + xmac_config.off_time, 1,
(void (*)(struct rtimer *, void *))powercycle, NULL);
xmac_is_on = 1;
#if WITH_ENCOUNTER_OPTIMIZATION
list_init(encounter_list);
memb_init(&encounter_memb);
#endif /* WITH_ENCOUNTER_OPTIMIZATION */
#if XMAC_CONF_ANNOUNCEMENTS
announcement_register_listen_callback(listen_callback);
ctimer_set(&announcement_cycle_ctimer, ANNOUNCEMENT_TIME,
cycle_announcement, NULL);
#endif /* XMAC_CONF_ANNOUNCEMENTS */
}
示例2: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_time_process, ev, data)
{
struct {
uint16_t len;
uint16_t clock;
uint16_t rtimer;
uint16_t timesynch;
uint16_t timesynch_authority;
uint16_t time[2];
} msg;
unsigned long newtime;
const char *nextptr;
PROCESS_BEGIN();
if(data != NULL) {
newtime = shell_strtolong(data, &nextptr);
if(data != nextptr) {
shell_set_time(newtime);
}
}
msg.clock = (uint16_t)clock_time();
msg.rtimer = (uint16_t)RTIMER_NOW();
#if TIMESYNCH_CONF_ENABLED
msg.timesynch = timesynch_time();
msg.timesynch_authority = timesynch_authority_level();
#else
msg.timesynch = 0;
msg.timesynch_authority = -1;
#endif
msg.time[0] = (uint16_t)(shell_time() >> 16);
msg.time[1] = (uint16_t)(shell_time());
msg.len = 6;
shell_output(&time_command, &msg, sizeof(msg), "", 0);
PROCESS_END();
}
示例3: rtimer_arch_schedule
/**
* \brief Schedules an rtimer task to be triggered at time t
* \param t The time when the task will need executed. This is an absolute
* time, in other words the task will be executed AT time \e t,
* not IN \e t ticks
*/
void
rtimer_arch_schedule(rtimer_clock_t t)
{
rtimer_clock_t now;
uint32_t primask = __get_PRIMASK();
__set_PRIMASK(1);
now = RTIMER_NOW();
/*
* New value must be a few ticks in the future.
*/
if((int32_t)(t - now) < 20) {
t = now + 20;
}
LPC_RITIMER->COMPVAL = t;
__set_PRIMASK(primask);
NVIC_EnableIRQ(RIT_IRQn);
}
示例4: xmac_init
/*---------------------------------------------------------------------------*/
const struct mac_driver *
xmac_init(const struct radio_driver *d)
{
#if WITH_TIMETABLE
timetable_clear(&xmac_timetable);
#endif
radio_is_on = 0;
waiting_for_packet = 0;
PT_INIT(&pt);
rtimer_set(&rt, RTIMER_NOW() + xmac_config.off_time, 1,
TC(powercycle), NULL);
xmac_is_on = 1;
radio = d;
radio->set_receive_function(input_packet);
BB_SET("xmac.state_addr", (int) &waiting_for_packet);
BB_SET(XMAC_RECEIVER, 0);
BB_SET(XMAC_STROBES, 0);
BB_SET(XMAC_SEND_WITH_ACK, 0);
BB_SET(XMAC_SEND_WITH_NOACK, 0);
return &xmac_driver;
}
示例5: advanceSlot
/*---------------------------------------------------------------------------*/
static void advanceSlot(struct rtimer *t, void *ptr, int status) {
off(TURN_OFF);
last = RTIMER_TIME(t);
if(!(rtimer_set(t, last + REGULAR_SLOT, 1, (void (*)(struct rtimer *, void *))advanceSlot, NULL) == RTIMER_OK)) {
printf("%s\n", "WPI-MAC: Could not schedule task!!!!!");
}
if(current_slot == TOTAL_SLOTS + 1) {
current_slot = BROADCAST_SLOT;
} else {
current_slot++;
}
if(current_slot > (TOTAL_SLOTS - 1)) {
current_slot = BROADCAST_SLOT;
}
//printf("Slot is now %u\n", current_slot);
unsigned char somethingToSend = check_buffers(current_slot);
if(somethingToSend) {
// grab the necessary info from our queue
QueuedPacket *curr = QPQueue[current_slot];
real_send(curr->sent, curr->ptr, curr->packet);
} else if(current_slot == BROADCAST_SLOT || current_slot == node_id) { // just need to be awake to listen
// if(!(rtimer_set(t, last + CONTENTION_PREPARE + (CONTENTION_TICKS * (CONTENTION_SLOTS)), 1, (void (*)(struct rtimer *, void *))async_on, NULL) == RTIMER_OK)){
// printf("%s\n", "Could not schedule task!!!!!");
// }
rtimer_clock_t stall = last + CONTENTION_PREPARE + (CONTENTION_TICKS * (CONTENTION_SLOTS));
// printf("STALLLLL: %u %u %u %u\n", RTIMER_NOW(), stall, REGULAR_SLOT, last);
while(RTIMER_CLOCK_LT(RTIMER_NOW(), stall));
if(!radio_is_on) on();
} else {
// we can snooze
if(radio_is_on) off(TURN_OFF);
}
}
示例6: lpm_exit
/*---------------------------------------------------------------------------*/
void
lpm_exit()
{
if((REG(SYS_CTRL_PMCTL) & SYS_CTRL_PMCTL_PM3) == SYS_CTRL_PMCTL_PM0) {
/* We either just exited PM0 or we were not sleeping in the first place.
* We don't need to do anything clever */
return;
}
/*
* When returning from PM1/2, the sleep timer value (used by RTIMER_NOW()) is
* not up-to-date until a positive edge on the 32-kHz clock has been detected
* after the system clock restarted. To ensure an updated value is read, wait
* for a positive transition on the 32-kHz clock by polling the
* SYS_CTRL_CLOCK_STA.SYNC_32K bit, before reading the sleep timer value.
*/
while(REG(SYS_CTRL_CLOCK_STA) & SYS_CTRL_CLOCK_STA_SYNC_32K);
while(!(REG(SYS_CTRL_CLOCK_STA) & SYS_CTRL_CLOCK_STA_SYNC_32K));
LPM_STATS_ADD(REG(SYS_CTRL_PMCTL) & SYS_CTRL_PMCTL_PM3,
RTIMER_NOW() - sleep_enter_time);
/* Adjust the system clock, since it was not counting while we were sleeping
* We need to convert sleep duration from rtimer ticks to clock ticks */
clock_adjust();
/* Restore system clock to the 32 MHz XOSC */
select_32_mhz_xosc();
/* Restore PMCTL to PM0 for next pass */
REG(SYS_CTRL_PMCTL) = SYS_CTRL_PMCTL_PM0;
/* Remember IRQ energest for next pass */
ENERGEST_IRQ_SAVE(irq_energest);
ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
}
示例7: PROCESS_THREAD
PROCESS_THREAD(cc26xx_demo_process, ev, data)
{
PROCESS_EXITHANDLER(broadcast_close(&bc))
PROCESS_BEGIN();
gpio_relay_init();
relay_all_clear();
counter = 0;
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
etimer_set(&et, CLOCK_SECOND);
while(1) {
PROCESS_YIELD();
if(ev == PROCESS_EVENT_TIMER) {
leds_on(LEDS_PERIODIC);
etimer_set(&et, CLOCK_SECOND*5);
rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
rt_callback, NULL);
counter = Get_ADC_reading();
packetbuf_copyfrom(&counter, sizeof(counter));
broadcast_send(&bc);
// printf("adc data value : %d \r\n",counter);
}
watchdog_periodic();
}
PROCESS_END();
}
示例8: powercycle
/*---------------------------------------------------------------------------*/
static char
powercycle(struct rtimer *t, void *ptr)
{
#if SYNC_CYCLE_STARTS
static volatile rtimer_clock_t sync_cycle_start;
static volatile uint8_t sync_cycle_phase;
#endif
PT_BEGIN(&pt);
#if SYNC_CYCLE_STARTS
sync_cycle_start = RTIMER_NOW();
#else
cycle_start = RTIMER_NOW();
#endif
while(1) {
static uint8_t packet_seen;
static rtimer_clock_t t0;
static uint8_t count;
#if SYNC_CYCLE_STARTS
/* Compute cycle start when RTIMER_ARCH_SECOND is not a multiple
of CHANNEL_CHECK_RATE */
if(sync_cycle_phase++ == NETSTACK_RDC_CHANNEL_CHECK_RATE) {
sync_cycle_phase = 0;
sync_cycle_start += RTIMER_ARCH_SECOND;
cycle_start = sync_cycle_start;
} else {
#if (RTIMER_ARCH_SECOND * NETSTACK_RDC_CHANNEL_CHECK_RATE) > 65535
cycle_start = sync_cycle_start + ((unsigned long)(sync_cycle_phase*RTIMER_ARCH_SECOND))/NETSTACK_RDC_CHANNEL_CHECK_RATE;
#else
cycle_start = sync_cycle_start + (sync_cycle_phase*RTIMER_ARCH_SECOND)/NETSTACK_RDC_CHANNEL_CHECK_RATE;
#endif
}
#else
cycle_start += CYCLE_TIME;
#endif
packet_seen = 0;
for(count = 0; count < CCA_COUNT_MAX; ++count) {
t0 = RTIMER_NOW();
if(we_are_sending == 0 && we_are_receiving_burst == 0) {
powercycle_turn_radio_on();
/* Check if a packet is seen in the air. If so, we keep the
radio on for a while (LISTEN_TIME_AFTER_PACKET_DETECTED) to
be able to receive the packet. We also continuously check
the radio medium to make sure that we wasn't woken up by a
false positive: a spurious radio interference that was not
caused by an incoming packet. */
if(NETSTACK_RADIO.channel_clear() == 0) {
packet_seen = 1;
break;
}
powercycle_turn_radio_off();
}
schedule_powercycle_fixed(t, RTIMER_NOW() + CCA_SLEEP_TIME);
PT_YIELD(&pt);
}
if(packet_seen) {
static rtimer_clock_t start;
static uint8_t silence_periods, periods;
start = RTIMER_NOW();
periods = silence_periods = 0;
while(we_are_sending == 0 && radio_is_on &&
RTIMER_CLOCK_LT(RTIMER_NOW(),
(start + LISTEN_TIME_AFTER_PACKET_DETECTED))) {
/* Check for a number of consecutive periods of
non-activity. If we see two such periods, we turn the
radio off. Also, if a packet has been successfully
received (as indicated by the
NETSTACK_RADIO.pending_packet() function), we stop
snooping. */
#if !RDC_CONF_HARDWARE_CSMA
/* A cca cycle will disrupt rx on some radios, e.g. mc1322x, rf230 */
/*TODO: Modify those drivers to just return the internal RSSI when already in rx mode */
if(NETSTACK_RADIO.channel_clear()) {
++silence_periods;
} else {
silence_periods = 0;
}
#endif
++periods;
if(NETSTACK_RADIO.receiving_packet()) {
silence_periods = 0;
}
if(silence_periods > MAX_SILENCE_PERIODS) {
powercycle_turn_radio_off();
break;
}
if(WITH_FAST_SLEEP &&
periods > MAX_NONACTIVITY_PERIODS &&
!(NETSTACK_RADIO.receiving_packet() ||
//.........这里部分代码省略.........
示例9: PROCESS_THREAD
PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
//microSD Test
uint8_t obuffer[514];
uint8_t ibuffer[514];
uint16_t j, i;
uint32_t start, end;
//printf("\nChecksum is: %x", microSD_data_crc( buffer ));
//wdt_disable();
init:
printf("\nmicroSD_init() = %u\n", i = microSD_init());
if( i != 0 )
goto init;
printf("Size of uint64_t = %u\n", sizeof(uint64_t));
printf("Size of uint32_t = %u\n", sizeof(uint32_t));
printf("Size of uint16_t = %u\n", sizeof(uint16_t));
printf("Size of int = %u\n", sizeof(int));
/* for (j = 0; j < 512; j+=4) {
obuffer[j] = 'H';
obuffer[j + 1] = 'e';
obuffer[j + 2] = 'r';
obuffer[j + 3] = '\n';
}*/
//clock_init();
//printf("\nmicroSD_set_CRC() = %u", microSD_set_CRC(1));
//start = clock_time();
/*for( j = 500; j < 8192; j++ ) {
printf("\n%u", j);
retry_write:
if( microSD_write_block(0L + j, obuffer) != 0 ) {
printf("\n Error writing block %lu", 0L + j);
//goto retry_write;
}
watchdog_periodic();
retry_read:
if( microSD_read_block(0L+j, ibuffer) != 0) {
goto retry_read;
}
watchdog_periodic();
for (i = 0; i < 512; i+=4) {
watchdog_periodic();
if( ibuffer[i] != 'H' || ibuffer[i + 1] != 'e' || ibuffer[i + 2] != 'r' || ibuffer[i + 3] != '\n' ) {
printf("\n Error in block %u", j);
for(i = 0; i< 512; i++) {
if( i%2 == 0 ) {
printf(" ");
}
if( i%32 == 0){
printf("\n");
}
printf("%02x", ibuffer[i]);
}
break;
}
}
printf("\nChecksum is : %x", ( (uint16_t)ibuffer[512] << 8 ) + ibuffer[513]);
printf("\nChecksum should be: %x", microSD_data_crc( ibuffer ));
}*/
rtimer_arch_init();
start = RTIMER_NOW();
for( j = 0; j < 30; j++ ) {
microSD_write_block( j, obuffer );
}
end = RTIMER_NOW();
printf("\nWrite time = %lu (%lu)", end - start, (end - start) / 30);
rtimer_arch_init();
start = RTIMER_NOW();
for( j = 0; j < 30; j++ ) {
if( microSD_read_block( j, obuffer ) != 0 ) {
printf("\n Block %u read error", j);
microSD_init();
j--;
continue;
}
}
end = RTIMER_NOW();
printf("\nRead time = %lu (%lu)", end - start, (end - start) / 30);
printf("\nSecond = %lu", RTIMER_SECOND);
printf("\n");
//if( microSD_write_block(38000L + j, buffer) != 0 ) {
// printf("\n Error writing block %lu", 38000L + j);
//}
//end = clock_time();
//printf("\nTime = %lu", (end - start) );
//printf("\nSecond = %lu", CLOCK_SECOND );
/*
for (i = 0; i < 8192; i++) {
if( (j = microSD_read_block(0L+i, buffer)) != 0 ) {
printf("\nmicroSD_read_block() failed with %u", j);
}
for (j = 0; j < 512; j+=4) {
if( buffer[j] != 'f' || buffer[j + 1] != 'e' || buffer[j + 2] != 'r' || buffer[j + 3] != '\n' ) {
printf("\n Error in block %u", i);
break;
}
}
}
//.........这里部分代码省略.........
示例10: PROCESS_THREAD
//.........这里部分代码省略.........
0x1e, 0xdd, 0xe9, 0x9d, 0xe6, 0x0d, 0x06, 0x82,
0xc6, 0x00, 0xb0, 0x34, 0xe0, 0x63, 0xb7, 0xd3,
0x23, 0x77, 0x23, 0xda, 0x70, 0xab, 0x75, 0x52 }, /* adata */
32, /* adata_len */
{ 0x9c, 0x8d, 0x5d, 0xd2, 0x27, 0xfd, 0x9f, 0x81,
0x23, 0x76, 0x01, 0x83, 0x0a, 0xfe, 0xe4, 0xf0,
0x11, 0x56, 0x36, 0xc8, 0xe5, 0xd5, 0xfd, 0x74,
0x3c, 0xb9, 0xaf, 0xed }, /* mdata */
28, /* mdata_len */
4, /* mic_len */
{ 0x23, 0x90, 0x29, 0xf1, 0x50, 0xbc, 0xcb, 0xd6,
0x7e, 0xdb, 0xb6, 0x7f, 0x8a, 0xe4, 0x56, 0xb4,
0xea, 0x06, 0x6a, 0x4b, 0xee, 0xe0, 0x65, 0xf9 } /* expected */
}
};
static uint8_t adata[ADATA_MAX_LEN];
static uint8_t mdata[MDATA_MAX_LEN];
static uint8_t mic[MIC_MAX_LEN];
static int i;
static uint8_t key_size_index = -1, ret;
static rtimer_clock_t time, time2, total_time;
PROCESS_BEGIN();
puts("-----------------------------------------\n"
"Initializing cryptoprocessor...");
crypto_init();
for(i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
if(key_size_index != vectors[i].key_size_index) {
key_size_index = vectors[i].key_size_index;
printf("-----------------------------------------\n"
"Filling %d-bit key store...\n", 128 + (key_size_index << 6));
time = RTIMER_NOW();
ret = aes_load_keys(keys[key_size_index].keys,
keys[key_size_index].key_size, keys[key_size_index].count, 0);
time = RTIMER_NOW() - time;
printf("aes_load_keys(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
break;
}
}
printf("-----------------------------------------\n"
"Test vector #%d: %s\n"
"len_len=%d key_area=%d\n"
"adata_len=%d mdata_len=%d mic_len=%d\n",
i, vectors[i].encrypt ? "encrypt" : "decrypt",
vectors[i].len_len, vectors[i].key_area,
vectors[i].adata_len, vectors[i].mdata_len, vectors[i].mic_len);
/* adata and mdata have to be in SRAM. */
rom_util_memcpy(adata, vectors[i].adata, vectors[i].adata_len);
rom_util_memcpy(mdata, vectors[i].mdata, vectors[i].mdata_len);
time = RTIMER_NOW();
if(vectors[i].encrypt) {
ret = ccm_auth_encrypt_start(vectors[i].len_len, vectors[i].key_area,
vectors[i].nonce, adata,
vectors[i].adata_len, mdata,
vectors[i].mdata_len, mdata,
vectors[i].mic_len, &ccm_test_process);
time2 = RTIMER_NOW();
time = time2 - time;
示例11: main
/*---------------------------------Main Routine----------------------------*/
int
main(void)
{
/* GCC depends on register r1 set to 0 (?) */
asm volatile ("clr r1");
/* Initialize in a subroutine to maximize stack space */
initialize();
#if DEBUG
{struct process *p;
for(p = PROCESS_LIST();p != NULL; p = ((struct process *)p->next)) {
PRINTA("Process=%p Thread=%p Name=\"%s\" \n",p,p->thread,PROCESS_NAME_STRING(p));
}
}
#endif
while(1) {
process_run();
watchdog_periodic();
/* Print rssi of all received packets, useful for range testing */
#ifdef RF230_MIN_RX_POWER
uint8_t lastprint;
if (rf230_last_rssi != lastprint) { //can be set in halbb.c interrupt routine
PRINTA("%u ",rf230_last_rssi);
lastprint=rf230_last_rssi;
}
#endif
#if 0
/* Clock.c can trigger a periodic PLL calibration in the RF230BB driver.
* This can show when that happens.
*/
extern uint8_t rf230_calibrated;
if (rf230_calibrated) {
PRINTA("\nRF230 calibrated!\n");
rf230_calibrated=0;
}
#endif
#if TESTRTIMER
/* Timeout can be increased up to 8 seconds maximum.
* A one second cycle is convenient for triggering the various debug printouts.
* The triggers are staggered to avoid printing everything at once.
* My Jackdaw is 4% slow.
*/
if (rtimerflag) {
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
rtimerflag=0;
#if STAMPS
if ((rtime%STAMPS)==0) {
PRINTA("%us ",rtime);
if (rtime%STAMPS*10) PRINTA("\n");
}
#endif
rtime+=1;
#if PINGS && UIP_CONF_IPV6_RPL
extern void raven_ping6(void);
if ((rtime%PINGS)==1) {
PRINTA("**Ping\n");
raven_ping6();
}
#endif
#if ROUTES && UIP_CONF_IPV6_RPL
if ((rtime%ROUTES)==2) {
extern uip_ds6_netif_t uip_ds6_if;
uint8_t i,j;
uip_ds6_nbr_t *nbr;
PRINTA("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
if (uip_ds6_if.addr_list[i].isused) {
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
PRINTA("\n");
}
}
PRINTA("\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);
for(nbr = nbr_table_head(ds6_neighbors);
nbr != NULL;
nbr = nbr_table_next(ds6_neighbors, nbr)) {
uip_debug_ipaddr_print(&nbr->ipaddr);
PRINTA("\n");
j=0;
}
if (j) PRINTA(" <none>");
PRINTA("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
uip_ds6_route_t *r;
for(r = uip_ds6_route_head();
r != NULL;
r = uip_ds6_route_next(r)) {
if(r->isused) {
//.........这里部分代码省略.........
示例12: transmit
/*---------------------------------------------------------------------------*/
static int
transmit(unsigned short transmit_len)
{
uint8_t counter;
int ret = RADIO_TX_ERR;
rtimer_clock_t t0;
transmit_len; /* hush the warning */
if(!(rf_flags & RX_ACTIVE)) {
t0 = RTIMER_NOW();
on();
rf_flags |= WAS_OFF;
while (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME));
}
if(channel_clear() == CC2530_RF_CCA_BUSY) {
RIMESTATS_ADD(contentiondrop);
return RADIO_TX_COLLISION;
}
/*
* prepare() double checked that TX_ACTIVE is low. If SFD is high we are
* receiving. Abort transmission and bail out with RADIO_TX_COLLISION
*/
if(FSMSTAT1 & FSMSTAT1_SFD) {
RIMESTATS_ADD(contentiondrop);
return RADIO_TX_COLLISION;
}
/* Start the transmission */
RF_TX_LED_ON();
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
CC2530_CSP_ISTXON();
counter = 0;
while(!(FSMSTAT1 & FSMSTAT1_TX_ACTIVE) && (counter++ < 3)) {
clock_delay_usec(6);
}
if(!(FSMSTAT1 & FSMSTAT1_TX_ACTIVE)) {
PUTSTRING("RF: TX never active.\n");
CC2530_CSP_ISFLUSHTX();
ret = RADIO_TX_ERR;
} else {
/* Wait for the transmission to finish */
while(FSMSTAT1 & FSMSTAT1_TX_ACTIVE);
ret = RADIO_TX_OK;
}
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
if(rf_flags & WAS_OFF){
off();
}
RIMESTATS_ADD(lltx);
RF_TX_LED_OFF();
/* OK, sent. We are now ready to send more */
return ret;
}
示例13: transmit
/*---------------------------------------------------------------------------*/
static int
transmit(unsigned short transmit_len)
{
uint8_t counter;
int ret = RADIO_TX_ERR;
rtimer_clock_t t0;
uint8_t was_off = 0;
PRINTF("RF: Transmit\n");
if(!(rf_flags & RX_ACTIVE)) {
t0 = RTIMER_NOW();
on();
was_off = 1;
while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME));
}
if(channel_clear() == CC2538_RF_CCA_BUSY) {
RIMESTATS_ADD(contentiondrop);
return RADIO_TX_COLLISION;
}
/*
* prepare() double checked that TX_ACTIVE is low. If SFD is high we are
* receiving. Abort transmission and bail out with RADIO_TX_COLLISION
*/
if(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_SFD) {
RIMESTATS_ADD(contentiondrop);
return RADIO_TX_COLLISION;
}
/* Start the transmission */
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
CC2538_RF_CSP_ISTXON();
counter = 0;
while(!((REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE))
&& (counter++ < 3)) {
clock_delay_usec(6);
}
if(!(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE)) {
PRINTF("RF: TX never active.\n");
CC2538_RF_CSP_ISFLUSHTX();
ret = RADIO_TX_ERR;
} else {
/* Wait for the transmission to finish */
while(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE);
ret = RADIO_TX_OK;
}
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
if(was_off) {
off();
}
RIMESTATS_ADD(lltx);
return ret;
}
示例14: value
/**
* \brief Returns a reading from the sensor
* \param type MPU_9250_SENSOR_TYPE_ACC_[XYZ] or MPU_9250_SENSOR_TYPE_GYRO_[XYZ]
* \return centi-G (ACC) or centi-Deg/Sec (Gyro)
*/
static int
value(int type)
{
int rv;
float converted_val = 0;
if(state == SENSOR_STATE_DISABLED) {
PRINTF("MPU: Sensor Disabled\n");
return CC26XX_SENSOR_READING_ERROR;
}
memset(sensor_value, 0, sizeof(sensor_value));
if((type & MPU_9250_SENSOR_TYPE_ACC) != 0) {
t0 = RTIMER_NOW();
while(!int_status() &&
(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + READING_WAIT_TIMEOUT)));
rv = acc_read(sensor_value);
if(rv == 0) {
return CC26XX_SENSOR_READING_ERROR;
}
PRINTF("MPU: ACC = 0x%04x 0x%04x 0x%04x = ",
sensor_value[0], sensor_value[1], sensor_value[2]);
/* Convert */
if(type == MPU_9250_SENSOR_TYPE_ACC_X) {
converted_val = acc_convert(sensor_value[0]);
} else if(type == MPU_9250_SENSOR_TYPE_ACC_Y) {
converted_val = acc_convert(sensor_value[1]);
} else if(type == MPU_9250_SENSOR_TYPE_ACC_Z) {
converted_val = acc_convert(sensor_value[2]);
}
rv = (int)(converted_val * 100);
} else if((type & MPU_9250_SENSOR_TYPE_GYRO) != 0) {
t0 = RTIMER_NOW();
while(!int_status() &&
(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + READING_WAIT_TIMEOUT)));
rv = gyro_read(sensor_value);
if(rv == 0) {
return CC26XX_SENSOR_READING_ERROR;
}
PRINTF("MPU: Gyro = 0x%04x 0x%04x 0x%04x = ",
sensor_value[0], sensor_value[1], sensor_value[2]);
if(type == MPU_9250_SENSOR_TYPE_GYRO_X) {
converted_val = gyro_convert(sensor_value[0]);
} else if(type == MPU_9250_SENSOR_TYPE_GYRO_Y) {
converted_val = gyro_convert(sensor_value[1]);
} else if(type == MPU_9250_SENSOR_TYPE_GYRO_Z) {
converted_val = gyro_convert(sensor_value[2]);
}
rv = (int)(converted_val * 100);
} else {
PRINTF("MPU: Invalid type\n");
rv = CC26XX_SENSOR_READING_ERROR;
}
PRINTF("%ld\n", (long int)(converted_val * 100));
return rv;
}
示例15: lpm_drop
/*---------------------------------------------------------------------------*/
void
lpm_drop()
{
lpm_registered_module_t *module;
uint8_t max_pm = LPM_MODE_MAX_SUPPORTED;
uint8_t module_pm;
clock_time_t next_event;
uint32_t domains = LOCKABLE_DOMAINS;
if(RTIMER_CLOCK_LT(soc_rtc_get_next_trigger(),
RTIMER_NOW() + STANDBY_MIN_DURATION)) {
lpm_sleep();
return;
}
/* Collect max allowed PM permission from interested modules */
for(module = list_head(modules_list); module != NULL;
module = module->next) {
if(module->request_max_pm) {
module_pm = module->request_max_pm();
if(module_pm < max_pm) {
max_pm = module_pm;
}
}
}
/* Check if any events fired during this process. Last chance to abort */
if(process_nevents()) {
return;
}
/* Drop */
if(max_pm == LPM_MODE_SLEEP) {
lpm_sleep();
} else {
/* Critical. Don't get interrupted! */
ti_lib_int_master_disable();
/*
* Reschedule AON RTC CH1 to fire an event N ticks before the next etimer
* event
*/
next_event = etimer_next_expiration_time();
if(next_event) {
next_event = next_event - clock_time();
soc_rtc_schedule_one_shot(AON_RTC_CH1, RTIMER_NOW() +
(next_event * (RTIMER_SECOND / CLOCK_SECOND)));
}
/*
* Notify all registered modules that we are dropping to mode X. We do not
* need to do this for simple sleep.
*
* This is a chance for modules to delay us a little bit until an ongoing
* operation has finished (e.g. uart TX) or to configure themselves for
* deep sleep.
*
* At this stage, we also collect power domain locks, if any.
* The argument to PRCMPowerDomainOff() is a bitwise OR, so every time
* we encounter a lock we just clear the respective bits in the 'domains'
* variable as required by the lock. In the end the domains variable will
* just hold whatever has not been cleared
*/
for(module = list_head(modules_list); module != NULL;
module = module->next) {
if(module->shutdown) {
module->shutdown(max_pm);
}
/* Clear the bits specified in the lock */
domains &= ~module->domain_lock;
}
/* Pat the dog: We don't want it to shout right after we wake up */
watchdog_periodic();
/* Clear unacceptable bits, just in case a lock provided a bad value */
domains &= LOCKABLE_DOMAINS;
/*
* Freeze the IOs on the boundary between MCU and AON. We only do this if
* PERIPH is not needed
*/
if(domains & PRCM_DOMAIN_PERIPH) {
ti_lib_aon_ioc_freeze_enable();
}
/*
* Among LOCKABLE_DOMAINS, turn off those that are not locked
*
* If domains is != 0, pass it as-is
*/
if(domains) {
ti_lib_prcm_power_domain_off(domains);
}
/*
//.........这里部分代码省略.........