void main(void) { volatile packet_t *p; volatile uint8_t t=20; uint8_t chan; char c; gpio_data(0); gpio_pad_dir_set( 1ULL << LED ); /* read from the data register instead of the pad */ /* this is needed because the led clamps the voltage low */ gpio_data_sel( 1ULL << LED); /* trim the reference osc. to 24MHz */ trim_xtal(); uart_init(UART1, 115200); vreg_init(); maca_init(); /* sets up tx_on, should be a board specific item */ *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2)); gpio_pad_dir_set( 1ULL << 44 ); set_power(0x0f); /* 0dbm */ chan = 0; set_channel(chan); /* channel 11 */ *MACA_MACPANID = 0xaaaa; *MACA_MAC16ADDR = 0x1111; *MACA_TXACKDELAY = 68; /* 68 puts the tx ack at about the correct spot */ set_prm_mode(AUTOACK); print_welcome("rftest-rx"); while(1) { /* call check_maca() periodically --- this works around */ /* a few lockup conditions */ check_maca(); if((p = rx_packet())) { /* print and free the packet */ printf("autoack-rx --- "); print_packet(p); maca_free_packet(p); } if(uart1_can_get()) { c = uart1_getc(); if(c == 'z') t++; if(c == 'x') t--; *MACA_TXACKDELAY = t; printf("tx ack delay: %d\n\r", t); } } }
void init_lowlevel(void) { /* button init */ /* set up kbi */ enable_irq_kbi(4); kbi_edge(4); enable_ext_wu(4); // kbi_pol_neg(7); // kbi_pol_pos(7); // gpio_sel0_pullup(29); // gpio_pu0_disable(29); trim_xtal(); /* uart init */ uart_init(BRINC, BRMOD, SAMP); default_vreg_init(); maca_init(); set_channel(RF_CHANNEL - 11); /* channel 11 */ set_power(0x12); /* 0x12 is the highest, not documented */ enable_irq(CRM); #if USE_32KHZ_XTAL enable_32khz_xtal(); #else cal_ring_osc(); #endif #if USE_32KHZ_XTAL *CRM_RTC_TIMEOUT = 32768 * 10; #else *CRM_RTC_TIMEOUT = cal_rtc_secs * 10; #endif #if (USE_WDT == 1) /* set the watchdog timer timeout to 1 sec */ cop_timeout_ms(WDT_TIMEOUT); /* enable the watchdog timer */ CRM->COP_CNTLbits.COP_EN = 1; #endif /* XXX debug */ /* trigger periodic rtc int */ // clear_rtc_wu_evt(); // enable_rtc_wu(); // enable_rtc_wu_irq(); }
int main(void) { int x = 32768; trim_xtal(); uart_init(UART1, 115200); rtc_init(); printf("pwm test\r\n"); pwm_init_stopped(TMR0, 12000000, x); pwm_init_stopped(TMR1, 12000000, x); TMR0->ENBL |= TMR_ENABLE_BIT(TMR0) | TMR_ENABLE_BIT(TMR1); for(;;) { printf("duty %d = %d%%\r\n", x, ((x * 100 + 32768) / 65536)); switch(uart1_getc()) { case '[': x -= 1; break; case ']': x += 1; break; case '-': x -= 32; break; case '=': x += 32; break; case '_': x -= 512; break; case '+': x += 512; break; case '`': x = 65535 * 0/10; break; case '1': x = 65535 * 1/10; break; case '2': x = 65535 * 2/10; break; case '3': x = 65535 * 3/10; break; case '4': x = 65535 * 4/10; break; case '5': x = 65535 * 5/10; break; case '6': x = 65535 * 6/10; break; case '7': x = 65535 * 7/10; break; case '8': x = 65535 * 8/10; break; case '9': x = 65535 * 9/10; break; case '0': x = 65535 * 10/10; break; } x &= 65535; pwm_duty(TMR0, x); } }
void main(void) { volatile packet_t *p; char c; uint16_t r=30; /* start reception 100us before ack should arrive */ uint16_t end=180; /* 750 us receive window*/ /* trim the reference osc. to 24MHz */ trim_xtal(); uart_init(UART1, 115200); vreg_init(); maca_init(); set_channel(0); /* channel 11 */ // set_power(0x0f); /* 0xf = -1dbm, see 3-22 */ // set_power(0x11); /* 0x11 = 3dbm, see 3-22 */ set_power(0x12); /* 0x12 is the highest, not documented */ /* sets up tx_on, should be a board specific item */ GPIO->FUNC_SEL_44 = 1; GPIO->PAD_DIR_SET_44 = 1; GPIO->FUNC_SEL_45 = 2; GPIO->PAD_DIR_SET_45 = 1; *MACA_RXACKDELAY = r; printf("rx warmup: %d\n\r", (int)(*MACA_WARMUP & 0xfff)); *MACA_RXEND = end; printf("rx end: %d\n\r", (int)(*MACA_RXEND & 0xfff)); set_prm_mode(AUTOACK); print_welcome("rftest-tx"); while(1) { /* call check_maca() periodically --- this works around */ /* a few lockup conditions */ check_maca(); while((p = rx_packet())) { if(p) { printf("RX: "); print_packet(p); free_packet(p); } } if(uart1_can_get()) { c = uart1_getc(); switch(c) { case 'z': r++; if(r > 4095) { r = 0; } *MACA_RXACKDELAY = r; printf("rx ack delay: %d\n\r", r); break; case 'x': if(r == 0) { r = 4095; } else { r--; } *MACA_RXACKDELAY = r; printf("rx ack delay: %d\n\r", r); break; case 'q': end++; if(r > 4095) { r = 0; } *MACA_RXEND = end; printf("rx end: %d\n\r", end); break; case 'w': end--; if(r == 0) { r = 4095; } else { r--; } *MACA_RXEND = end; printf("rx end: %d\n\r", end); break; default: p = get_free_packet(); if(p) { fill_packet(p); printf("autoack-tx --- "); print_packet(p); tx_packet(p); } break; } } } }
void main(void) { volatile packet_t *p; #ifdef CARRIER_SENSE volatile uint32_t i; #endif uint16_t r=30; /* start reception 100us before ack should arrive */ uint16_t end=180; /* 750 us receive window*/ /* trim the reference osc. to 24MHz */ trim_xtal(); uart_init(INC, MOD, SAMP); vreg_init(); maca_init(); ///* Setup the timer */ *TMR_ENBL = 0; /* tmrs reset to enabled */ *TMR0_SCTRL = 0; *TMR0_LOAD = 0; /* reload to zero */ *TMR0_COMP_UP = 18750; /* trigger a reload at the end */ *TMR0_CMPLD1 = 18750; /* compare 1 triggered reload level, 10HZ maybe? */ *TMR0_CNTR = 0; /* reset count register */ *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE); *TMR_ENBL = 0xf; /* enable all the timers --- why not? */ set_channel(CHANNEL); /* channel 11 */ set_power(0x12); /* 0x12 is the highest, not documented */ /* sets up tx_on, should be a board specific item */ GPIO->FUNC_SEL_44 = 1; GPIO->PAD_DIR_SET_44 = 1; GPIO->FUNC_SEL_45 = 2; GPIO->PAD_DIR_SET_45 = 1; *MACA_RXACKDELAY = r; *MACA_RXEND = end; set_prm_mode(AUTOACK); while(1) { if((*TMR0_SCTRL >> 15) != 0) tick(); /* call check_maca() periodically --- this works around */ /* a few lockup conditions */ check_maca(); while((p = rx_packet())) { if(p) free_packet(p); } p = get_free_packet(); if(p) { fill_packet(p); #ifdef CARRIER_SENSE for(i=0; i<POWER_DELAY; i++) {continue;} while(get_power()>74) {} #endif #ifdef BLOCKING_TX blocking_tx_packet(p); #else tx_packet(p); #endif current_pkts++; #if defined(RANDOM_WAIT_TIME) || defined(FIXED_WAIT) random_wait(); #endif } } }