void appMain(void) { static uint8_t buffer[100]; radioSetTxPower(TX_POWER); radioSetReceiveHandle(rcvRadio); radioOn(); uint32_t lastTime = getTimeMs(); for (;;) { int8_t rssi = radioGetLastRSSI(); if ((int32_t) getTimeMs() - (int32_t) lastTime > 1000) { radioSend(buffer, sizeof(buffer)); PRINTF("rssi=%d\n", rssi); lastTime = getTimeMs(); if (rxOk) --rxOk; if (!rxOk) redLedOn(); else redLedOff(); } greenLedToggle(); busyWait(getWaitInterval(rssi)); } }
int main(void) { led_initialise(); // Real programs never die! for(;;) { greenLedToggle(); greenLed2Toggle(); redLedToggle(); yellowLedToggle(); delay(); } }
// ------------------------------------- // Main function // ------------------------------------- void appMain(void) { uint16_t i; // timers (used to get an extra interrupt context) alarmInit(&timer, onTimer, NULL); alarmSchedule(&timer, 1000); // radio radioSetReceiveHandle(radioRecvCb); radioOn(); for (i = 0; i < BUFFER_SIZE; i++) { buffer[i] = i; } randomInit(); // SELECT_FLASH; // extFlashBulkErase(); // UNSELECT_FLASH; for (i = 0; ; i++) { uint32_t address = i * 64ul; SELECT_FLASH; if (IS_ALIGNED(address, EXT_FLASH_SECTOR_SIZE)) { PRINTF("erase address %lu\n", address); flashErase(address); } PRINTF("write address %lu\n", address); flashWrite(address); if (address > 0) { PRINTF("verify...\n"); flashRead(address - 64); } UNSELECT_FLASH; msleep(randomInRange(400, 1000)); PRINTF("send smth to radio...\n"); radioSend("hello world", sizeof("hello world")); greenLedToggle(); } }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(blink_green_process, ev, data) { PROCESS_BEGIN(); static struct etimer timer; while (1) { etimer_set(&timer, TIMER_INTERRUPT_HZ); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); greenLedToggle(); } PROCESS_END(); }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(receive_process, ev, data) { PROCESS_BEGIN(); radioOn(); while (1) { waitRadioPacket(ev); if (radioPacketBuffer->receivedLength >= 2) { uint16_t counter = ((uint16_t *) radioPacketBuffer->buffer)[0]; PRINTF("Received counter %i\n", counter); greenLedToggle(); } } PROCESS_END(); }
int main(void) { volatile int count = 0; led_initialise(); // printf("SystemBusClock = %ld\n", SystemBusClock); // printf("SystemCoreClock = %ld\n", SystemCoreClock); // Real programs never die! for(;;) { count++; greenLedToggle(); // printf("Count = %d\n", count); waitMS(100); } return 0; }
//------------------------------------------- // 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) }