Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define CONT PT_YIELD(&rf_pt);
- #define RESET PT_RESTART(&rf_pt);
- #define EXPECT(x) if (!(x)) { RESET; }
- PT_THREAD(rf_receive())
- {
- bool databit;
- PT_BEGIN(&rf_pt);
- // wait for first 10
- PT_WAIT_UNTIL(&rf_pt, (cur_bit == 0) && IS_VERY_LONG(cont_count));
- putc('B');
- LED_TOGGLE;
- PT_YIELD(&rf_pt);
- for (i = 0; i < 4; ++i) {
- // wait for 01
- EXPECT((cur_bit == 1) && IS_SHORT(cont_count));
- CONT;
- // wait for 10
- EXPECT((cur_bit == 0) && IS_SHORT(cont_count));
- CONT;
- }
- putc('P');
- // after preamble, 01
- EXPECT((cur_bit == 1) && IS_SHORT(cont_count));
- CONT;
- // first long now
- CONT;
- for (i = 0; i < BITS_TO_RECEIVE; ++i) {
- if (IS_SHORT(cont_count)) {
- DEBUG(putc('S'));
- CONT;
- if (IS_SHORT(cont_count) || (i == (BITS_TO_RECEIVE-1))) {
- databit = !cur_bit;
- if (databit)
- putc('1');
- else
- putc('0');
- CONT;
- } else {
- RESET;
- }
- } else if (IS_LONG(cont_count) || ((IS_VERY_LONG(cont_count)) && (i == (BITS_TO_RECEIVE-1)))) {
- DEBUG(putc('L'));
- databit = cur_bit;
- if (databit)
- putc('1');
- else
- putc('0');
- CONT;
- } else {
- RESET;
- }
- }
- putc('E');
- puts("\r\n");
- PT_END(&rf_pt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement