* RX filter: 93.75 kHz
*/
-/*
- * For 434.550MHz, the frequency value is:
- *
- * 434.550e6 / (24e6 / 2**16) = 1186611.2
- */
-
-#define FREQ_CONTROL 1186611
-
/*
* For IF freq of 140.62kHz, the IF value is:
*
RF_PA_TABLE1_OFF, RF_POWER,
RF_PA_TABLE0_OFF, RF_POWER,
- RF_FREQ2_OFF, (FREQ_CONTROL >> 16) & 0xff,
- RF_FREQ1_OFF, (FREQ_CONTROL >> 8) & 0xff,
- RF_FREQ0_OFF, (FREQ_CONTROL >> 0) & 0xff,
-
RF_FSCTRL1_OFF, (IF_FREQ_CONTROL << RF_FSCTRL1_FREQ_IF_SHIFT),
RF_FSCTRL0_OFF, (0 << RF_FSCTRL0_FREQOFF_SHIFT),
RF_PKTCTRL0_LENGTH_CONFIG_FIXED),
};
+__xdata uint8_t ao_radio_dma;
+__xdata uint8_t ao_radio_dma_done;
+__xdata uint8_t ao_radio_done;
+__xdata uint8_t ao_radio_mutex;
+
+void
+ao_radio_general_isr(void) __interrupt 16
+{
+ S1CON &= ~0x03;
+ if (RFIF & RFIF_IM_TIMEOUT) {
+ ao_dma_abort(ao_radio_dma);
+ RFIF &= ~ RFIF_IM_TIMEOUT;
+ } else if (RFIF & RFIF_IM_DONE) {
+ ao_radio_done = 1;
+ ao_wakeup(&ao_radio_done);
+ RFIF &= ~RFIF_IM_DONE;
+ }
+}
void
ao_radio_set_telemetry(void)
RF[rdf_setup[i]] = rdf_setup[i+1];
}
-__xdata uint8_t ao_radio_dma;
-__xdata uint8_t ao_radio_dma_done;
-__xdata uint8_t ao_radio_mutex;
-
void
ao_radio_idle(void)
{
if (RF_MARCSTATE != RF_MARCSTATE_IDLE)
{
- RFST = RFST_SIDLE;
do {
+ RFST = RFST_SIDLE;
ao_yield();
} while (RF_MARCSTATE != RF_MARCSTATE_IDLE);
}
}
void
-ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant
+ao_radio_get(void)
{
ao_config_get();
ao_mutex_get(&ao_radio_mutex);
ao_radio_idle();
RF_CHANNR = ao_config.radio_channel;
+ RF_FREQ2 = (uint8_t) (ao_config.radio_cal >> 16);
+ RF_FREQ1 = (uint8_t) (ao_config.radio_cal >> 8);
+ RF_FREQ0 = (uint8_t) (ao_config.radio_cal);
+}
+
+
+void
+ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant
+{
+ ao_radio_get();
+ ao_radio_done = 0;
ao_dma_set_transfer(ao_radio_dma,
telemetry,
&RFDXADDR,
DMA_CFG1_PRIORITY_HIGH);
ao_dma_start(ao_radio_dma);
RFST = RFST_STX;
- __critical while (!ao_radio_dma_done)
- ao_sleep(&ao_radio_dma_done);
- ao_mutex_put(&ao_radio_mutex);
+ __critical while (!ao_radio_done)
+ ao_sleep(&ao_radio_done);
+ ao_radio_put();
}
uint8_t
ao_radio_recv(__xdata struct ao_radio_recv *radio) __reentrant
{
- ao_config_get();
- ao_mutex_get(&ao_radio_mutex);
- ao_radio_idle();
- RF_CHANNR = ao_config.radio_channel;
+ ao_radio_get();
ao_dma_set_transfer(ao_radio_dma,
&RFDXADDR,
radio,
RFST = RFST_SRX;
__critical while (!ao_radio_dma_done)
ao_sleep(&ao_radio_dma_done);
- ao_mutex_put(&ao_radio_mutex);
+ ao_radio_put();
return (ao_radio_dma_done & AO_DMA_DONE);
}
{
uint8_t i;
uint8_t pkt_len;
- ao_mutex_get(&ao_radio_mutex);
- ao_radio_idle();
+
+ ao_radio_get();
ao_radio_rdf_running = 1;
for (i = 0; i < sizeof (rdf_setup); i += 2)
RF[rdf_setup[i]] = rdf_setup[i+1];
ao_radio_idle();
for (i = 0; i < sizeof (telemetry_setup); i += 2)
RF[telemetry_setup[i]] = telemetry_setup[i+1];
- ao_mutex_put(&ao_radio_mutex);
+ ao_radio_put();
}
void
-ao_radio_abort(uint8_t reason)
+ao_radio_abort(void)
{
- ao_dma_abort(ao_radio_dma, reason);
+ ao_dma_abort(ao_radio_dma);
ao_radio_idle();
}
ao_radio_rdf_abort(void)
{
if (ao_radio_rdf_running)
- ao_radio_abort(AO_DMA_ABORTED);
+ ao_radio_abort();
+}
+
+
+/* Output carrier */
+void
+ao_radio_test(void)
+{
+ ao_set_monitor(0);
+ ao_packet_slave_stop();
+ ao_radio_get();
+ printf ("Hit a character to stop..."); flush();
+ RFST = RFST_STX;
+ getchar();
+ ao_radio_idle();
+ ao_radio_put();
+ putchar('\n');
}
+__code struct ao_cmds ao_radio_cmds[] = {
+ { 'C', ao_radio_test, "C Radio carrier test" },
+ { 0, ao_radio_test, NULL },
+};
+
void
ao_radio_init(void)
{
ao_radio_set_telemetry();
ao_radio_dma_done = 1;
ao_radio_dma = ao_dma_alloc(&ao_radio_dma_done);
+ RFIF = 0;
+ RFIM = RFIM_IM_TIMEOUT|RFIM_IM_DONE;
+ IEN2 |= IEN2_RFIE;
+ ao_cmd_register(&ao_radio_cmds[0]);
}