void onAlarm(void *x) { redLedToggle(); // schedule the next alarm *exactly* 1000 milliseconds after this one nextPeriod += PERIOD; alarmSchedule(&alarm, nextPeriod - getJiffies()); }
void appMain(void) { uint16_t i; // ------------------------- serial number DPRINTF("Mote %#04x starting...\n", localAddress); // ------------------------- external flash #if WRITE_TO_FLASH prepareExtFlash(); #endif // ------------------------- light sensors if (localAddress != 0x0796) { PRINT("init isl\n"); islInit(); islOn(); } else { PRINT("init ads\n"); adsInit(); adsSelectInput(0); } // ------------------------- main loop mdelay(3000); DPRINTF("starting main loop...\n"); for (i = 0; i < 6; ++i) { redLedToggle(); mdelay(100); } ledOff(); uint32_t nextDataReadTime = 0; uint32_t nextBlinkTime = 0; for (;;) { uint32_t now = getRealTime(); if (timeAfter32(now, nextDataReadTime)) { if (getJiffies() < 300 * 1000ul ) { nextDataReadTime = now + DATA_INTERVAL_SMALL; } else { nextDataReadTime = now + DATA_INTERVAL; } DataPacket_t packet; readSensors(&packet); #if PRINT_PACKET printPacket(&packet); #endif } if (timeAfter32(now, nextBlinkTime)) { nextBlinkTime = now + BLINK_INTERVAL; ledOn(); msleep(100); ledOff(); } msleep(1000); } }
//------------------------------------------- // Entry point for the application //------------------------------------------- void appMain(void) { PRINTF("\n\nAccelerometer data gathering app\n"); extFlashWake(); // start with clean and new... cleanFlash(); accelOn(); userButtonEnable(onUserButton); mdelay(START_DELAY); uint16_t lastSecond; uint16_t samplesPerSecond; for (;;) { while (!isActiveMode); redLedOn(); lastSecond = getTimeSec(); samplesPerSecond = 0; uint16_t i; for (i = 0; isActiveMode; i++) { if (i % 10 == 0) redLedToggle(); uint32_t now = getTimeMs(); uint32_t endTime = now + MAIN_LOOP_LENGTH; Packet_t p; p.timestamp = now; p.acc_x = accelReadX(); p.acc_y = accelReadY(); p.acc_z = accelReadZ(); printPacket(&p); samplesPerSecond++; uint16_t currentSecond = getTimeSec(); if (currentSecond != lastSecond) { PRINTF("samples per second = %u\n", samplesPerSecond); lastSecond = currentSecond; samplesPerSecond = 0; } while (timeAfter32(endTime, getTimeMs())); } redLedOff(); } }
int main(void) { led_initialise(); // Real programs never die! for(;;) { greenLedToggle(); greenLed2Toggle(); redLedToggle(); yellowLedToggle(); delay(); } }
void radioRecvCb() { static uint8_t buffer[128]; int16_t len; redLedToggle(); len = radioRecv(buffer, sizeof(buffer) - 1); if (len <= 0) { PRINTF("radio recv failed, len=%d\n", len); return; } if (len > 0) { buffer[len] = 0; PRINTF("recv: %s\n", (char *) buffer); } }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(blink_red_process, ev, data) { PROCESS_BEGIN(); static struct etimer timer; while (1) { etimer_set(&timer, TIMER_INTERRUPT_HZ / 2); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); redLedToggle(); yellowLedToggle(); // for Atmega } PROCESS_END(); }
void appMain(void) { alarmInit(&alarm, alarmCallback, (void *) 0); alarmSchedule(&alarm, 10); for (;;) { // PRINT("in app main...\n"); redLedToggle(); #if 1 // will get different error messages depending on whether in mdelay or in msleep msleep(1000); #else mdelay(1000); #endif } }
void appMain(void) { redLedToggle(); // initialize and schedule the alarm alarmInit(&alarm, onAlarm, NULL); nextPeriod = PERIOD; // jiffie counter starts from 0 (zero) after reset alarmSchedule(&alarm, PERIOD - getJiffies()); // enter infinite low-power loop for (;;) { sleep(10); } }
// Timer #1 callback function void onTimer1(void *x) { static uint8_t counter; PRINTF("onTimer1\n"); redLedToggle(); // start (schedule) timer #1 alarmSchedule(&timer1, 700); if (++counter == 3) { // In case the counter is 3, start (schedule) timer #2 too PRINTF("reschedule alarm\n"); alarmSchedule(&timer2, 200); } }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(send_process, ev, data) { PROCESS_BEGIN(); static struct etimer timer; static uint16_t counter = 0; while (1) { PRINTF("Sending %i\n", counter); radioSend(&counter, sizeof(counter)); ++counter; redLedToggle(); waitTimer(timer, TIMER_INTERRUPT_HZ); } PROCESS_END(); }
void appMain(void) { Socket_t socket; socketOpen(&socket, recvData); socketBind(&socket, COUNTER_PORT); socketSetDstAddress(&socket, MOS_ADDR_ROOT); #if BASE_STATION (void) sendData; for (;;) { // PRINT("in app main\n"); redLedToggle(); mdelay(SLEEP_TIME_MS); } #else sendData(&socket); #endif }
static void rxByte1(void) { uint8_t rxByte, bitnum; bool rxOk; uint16_t i; #if USE_SW_SERIAL_INTERRUPTS udelay(75); #endif restart: rxByte = 0; TBCCR2 = TBR; for (bitnum = 0; bitnum < 8; ++bitnum) { // wait for next data bit TBCCTL2 = OUT; TBCCR2 += UART_BITTIME; while (0 == (TBCCTL2 & CCIFG)); rxByte |= pinRead(UART1_RX_PORT, UART1_RX_PIN) << bitnum; } // wait for the stop bit TBCCTL2 = OUT; TBCCR2 += UART_BITTIME; while (0 == (TBCCTL2 & CCIFG)); // ok if stop bit is 1 rxOk = pinRead(UART1_RX_PORT, UART1_RX_PIN); if (rxOk) serialRecvCb[1](rxByte); else redLedToggle(); // receive next byte immediately, do not wait for the next int for (i = 0; i < 1000; ++i) { if (!pinRead(UART0_RX_PORT, UART0_RX_PIN)) { udelay(50); goto restart; } } }
static void macRecv(MacInfo_t *mi, uint8_t *data, uint16_t len) { PRINTF("got %d bytes from 0x%04x (0x%02x) \n", len, mi->originalSrc.shortAddr, *data); redLedToggle(); }
static void recvData(Socket_t *socket, uint8_t *data, uint16_t len) { PRINTF("got %d bytes from 0x%04x (0x%02x) \n", len, socket->recvMacInfo->originalSrc.shortAddr, *data); redLedToggle(); }
//------------------------------------------- // Entry point for the application //------------------------------------------- void appMain(void) { while (1) { static uint_t i; // test 1: counter 0-7 for (i = 0; i < 8; ++i) { ledsSet(i); msleep(PAUSE); } // test 2: all off, then red on/off, then green on/off, finally blue on/off ledsSet(0); msleep(PAUSE); redLedOn(); msleep(PAUSE); redLedOff(); msleep(PAUSE); greenLedOn(); msleep(PAUSE); greenLedOff(); msleep(PAUSE); blueLedOn(); msleep(PAUSE); blueLedOff(); msleep(PAUSE); // test 3: all on, then blue off, green off, red off ledsSet(7); msleep(PAUSE); blueLedOff(); msleep(PAUSE); greenLedOff(); msleep(PAUSE); redLedOff(); msleep(PAUSE); // test 4: repeat last two tests with toggle redLedToggle(); msleep(PAUSE); redLedToggle(); msleep(PAUSE); greenLedToggle(); msleep(PAUSE); greenLedToggle(); msleep(PAUSE); blueLedToggle(); msleep(PAUSE); blueLedToggle(); msleep(PAUSE); ledsSet(7); msleep(PAUSE); blueLedToggle(); msleep(PAUSE); greenLedToggle(); msleep(PAUSE); redLedToggle(); msleep(PAUSE); // test 5: check that isOn functions work ledsSet(0); ASSERT(!redLedGet()); ASSERT(!greenLedGet()); ASSERT(!blueLedGet()); ledsSet(7); ASSERT(redLedGet()); ASSERT(greenLedGet()); ASSERT(blueLedGet()); } // EOF while (1) }
//------------------------------------------- // Entry point for the application //------------------------------------------- void appMain(void) { char *ss; uint16_t len, i; AccelVector3D_t accel; int16_t ax0, ay0, az0; int16_t ax, ay, az; int16_t dx0, dy0, dz0; int16_t vx0, vy0, vz0; int16_t vx, vy, vz; int16_t sx, sy, sz; int16_t t=1; int32_t ssx, ssy, ssz; //code curX = curY = curZ = 0; ax0 = ay0 = az0 = 0; ax = ay = az = 0; vx0 = vy0 = vz0 = 0; vx = vy = vz = 0; dx0 = dy0 = dz0 = accel_prec; vx=0; vy=0; vz=0; ssx = ssy = ssz = 0; //Turn the Accelerometer on (P4.0=1)! PIN_AS_DATA(4,0); PIN_AS_OUTPUT(4,0); PIN_SET(4,0); adcSetChannel(1); ADC12MCTL2 = SREF_AVCC_AVSS; for( i=0; i<cnt_warmup; i++){ accel.x = adcRead(ACC_X_PORT); accel.y = adcRead(ACC_Y_PORT); accel.z = adcRead(ACC_Z_PORT); ssx += accel.x; ssy += accel.y; ssz += accel.z; msleep(10); } ax0 = ssx / cnt_warmup; ay0 = ssy / cnt_warmup; az0 = ssz / cnt_warmup; ax0 >>= dx0; ay0 >>= dy0; az0 >>= dz0; while(1) { accel.x = adcRead(ACC_X_PORT); accel.y = adcRead(ACC_Y_PORT); accel.z = adcRead(ACC_Z_PORT); ax = accel.x >> dx0; ax = (ax - ax0); ay = accel.y >> dy0; ay = (ay - ay0); az = accel.z >> dz0; az = (az - az0); vx0 = vx; vx = vx0 + ax * t; sx = ((vx + vx0) / 2) * t; curX += (sx / mm); vy0 = vy; vy = vy0 + ay * t; sy = ((vy + vy0) / 2) * t; curY += (sy / mm); vz0 = vz; vz = vz0 + az * t; sz = ((vz + vz0) / 2) * t; curZ += (sz / mm); PRINTF("%4u %4u %4u", accel.x, accel.y, accel.z); PRINTF(" %5d %5d %5d", ax0, ay0, az0); PRINTF(" %5d %5d %5d", ax, ay, az); PRINTF(" %7d %7d %7d", vx, vy, vz); PRINTF(" %7d %7d %7d", sx, sy, sz); PRINTF(" %7d %7d %7d", curX, curY, curZ); PRINTF("\n"); redLedToggle(); msleep(10); } }