int main(void) { pt1.lc = 0; pt2.lc = 0; while (1) { protothread1(&pt1); protothread2(&pt2); } }
int main(void) { // === config the uart, DMA, vref, timer5 ISR ============= PT_setup(); // === setup system wide interrupts ==================== INTEnableSystemMultiVectoredInt(); // === set up i/o port pin =============== mPORTASetBits(BIT_0 | BIT_1 ); //Clear bits to ensure light is off. mPORTASetPinsDigitalOut(BIT_0 | BIT_1 ); //Set port as output mPORTBSetBits(BIT_0 ); //Clear bits to ensure light is off. mPORTBSetPinsDigitalOut(BIT_0 ); //Set port as output // === now the threads ==================== // init the thread control semaphores PT_SEM_INIT(&control_t1, 0); // start blocked PT_SEM_INIT(&control_t2, 1); // start unblocked PT_SEM_INIT(&send_sem, 1); // start with ready to send // init the threads PT_INIT(&pt1); PT_INIT(&pt2); PT_INIT(&pt3); PT_INIT(&pt4); PT_INIT(&pt5); // init the optional rate scheduler PT_RATE_INIT(); // schedule the threads while(1) { PT_RATE_LOOP(); // not necessary if you use PT_SCHEDULE PT_RATE_SCHEDULE(protothread1(&pt1), t1_rate); if (run_t4) PT_RATE_SCHEDULE(protothread4(&pt4), t4_rate); //run always PT_RATE_SCHEDULE(protothread2(&pt2), t1_rate); if (cmd[0] != 'k') PT_RATE_SCHEDULE(protothread3(&pt3),t3_rate); PT_SCHEDULE(protothread5(&pt5)); /* // alternate scheme PT_SCHEDULE(protothread1(&pt1)); if (run_t4) PT_SCHEDULE(protothread4(&pt4)); PT_SCHEDULE(protothread2(&pt2)); if (run_t4) PT_SCHEDULE(protothread4(&pt4)); if (cmd[0] != 'k') PT_SCHEDULE(protothread3(&pt3)); */ } } // main
int main(void) { /* Initialize the protothread state variables with PT_INIT(). */ PT_INIT(&pt1); PT_INIT(&pt2); /* * Then we schedule the two protothreads by repeatedly calling their * protothread functions and passing a pointer to the protothread * state variables as arguments. */ while(1) { protothread1(&pt1); protothread2(&pt2); } }
int main(void) { // pin 11 = PB3 DDRB |= _BV(PB3); // pin 10 = PB2 DDRB |= _BV(PB2); /* Initialize clock */ clock_init(); /* Initialize the protothread state variables with PT_INIT(). */ PT_INIT(&pt1); PT_INIT(&pt2); /* * Then we schedule the two protothreads by repeatedly calling their * protothread functions and passing a pointer to the protothread * state variables as arguments. */ while(1) { protothread1(&pt1); protothread2(&pt2); } }