/***************************************************************************** Module Name: RFSlvTst.c Purpose: Serial interface between RF radio module, using RF5050 protocol, via the UART, and Mailbox RAM resident on this uC. 2 byte header version. This file is the test program for the mbRFSlv module and the Mailbox RAM MB module. Operation: Allows remote program to read to / write from the Mailbox RAM. Also loads two timers and the ISR latency values for monitoring remotely. Created by: Don Carveth don@botgoodies.com www.botgoodies.com Copyright(c) 2002 Don Carveth See mbRFslv.h for description ******************************************************************************/ #include #include #include #include "StdDefs.h" #include "MB.h" #include "mbRFslv.h" void Initialize(void); void calc_latency(void); void SlowCounter(int x); void AssignMailbox(int x); void LEDsOff(int x); INT16S LC, SC; CHARU MaxRLatency, MaxWLatency; // ****************************** MAIN ************ int main(void) { Initialize(); for (;;) { run_led(15000, 30000); LC++; if(LC > 9999) LC = 0; calc_latency(); // For testing ISR max latency SlowCounter(10000); AssignMailbox(500); //LEDsOff(100); } return 1; } //--------------------------------- Initialize void Initialize(void) { cli(); PORTB = 0xFF; DDRB = 0x03; PORTD = 0x7F; // Turn the LED on, unused as inputs with pull-ups DDRD = 0xA0; // Pin 5 as run LED, Pin 7 as Xmtr power TCCR0 = 0x05; // TCNT0 enabled, divide by 1024 // Ree Running, Overflows every 16 ms // Used for ISR Latency tests only TIMSK = 0x04; // Timer overflow 1 interrupt enabled InitializeMailbox(); InitializeRF(); sei(); } void calc_latency(void) { if (r_latency > MaxRLatency) MaxRLatency = r_latency; if (w_latency > MaxWLatency) MaxWLatency = w_latency; } // Assign some changing variables to Maiblox for testing void AssignMailbox(int x) { static int c; if (c >= x) { mbLC = LC; // Assign LC to Mailbox RAM mbSC = SC; // Assign SC to Mailbox RAM mbMaxRLatency = MaxRLatency; mbMaxWLatency = MaxWLatency; c = 0; } else c++; } void SlowCounter(int x) { static int c; if (c >= x) { SC++; if (SC > 9999) SC = 0; c = 0; } else c++; } // comm LEDs off every x calls to LEDsOff void LEDsOff(int x) { static int c; if (c > x) { RF_LED_OFF(); c = 0; } else c++; }