diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 98ab8c6101ca4b9847ded458baa8e3745b62e841..ff3c0bc3be0bdd4f25b6fe445c0ac025da0d5f55 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -20,6 +20,9 @@ link_directories( add_executable(${PROJECT_NAME}_min test/min.c lib/hal_mcu/hal_mcu.c) target_link_libraries(${PROJECT_NAME}_min uart_drv) +add_executable(${PROJECT_NAME}_min2 test/min2.c lib/hal_mcu/hal_mcu.c) +target_link_libraries(${PROJECT_NAME}_min2) + add_executable(${PROJECT_NAME}_rxer test/LaunchPad_trx_main.c test/LaunchPad_trx_demo.c) target_link_libraries(${PROJECT_NAME}_rxer hal_mcu radio_drv) diff --git a/source/test/min2.c b/source/test/min2.c new file mode 100644 index 0000000000000000000000000000000000000000..ce9e3f50d93210659fbe502247bdc471d7ad1c7a --- /dev/null +++ b/source/test/min2.c @@ -0,0 +1,143 @@ +#include "msp430fr5994.h" +#include "stdio.h" +#include "lib/radio_drv/hal_types.h" + +/****************************************************************************** + * LOCAL FUNCTIONS + */ +unsigned long volatile time_counter; + + + +/****************************************************************************** + * @fn main + * + * @brief Main GUI application level control loop is implemented in the + * main loop. It is a state machine that cycles thru various states + * during the interactive use by the operator. The presents a text + * based GUI, the user is then promted to type in a command with + * a given set of parameters. The state machine then calls a simpler + * parser that tries to figure out what the user wants to do. + * + * input parameters + * + * @param void + * + * output parameters + * + * @return void + * + */ + + #define DCO_RANGE_SEL DCORSEL + #define DCO_FREQ_SEL DCOFSEL_4 + #define F_CPU_SCALE DIVM_0 + + #if DCO_RANGE_SEL==DCORSEL + #if DCO_FREQ_SEL>DCOFSEL_3 + #define F_CPU_RANGE 5333000UL + #else + #define F_CPU_RANGE 5333000UL*1.5 + #endif + #else + #define F_CPU_RANGE 2667000UL + #endif + + #if DCO_FREQ_SEL==DCOFSEL_1 + #define F_CPU F_CPU_RANGE*1.0 + #elif DCO_FREQ_SEL==DCOFSEL_2 + #define F_CPU F_CPU_RANGE*1.313 + #elif DCO_FREQ_SEL==DCOFSEL_3 + #define F_CPU F_CPU_RANGE*1.5 + #elif DCO_FREQ_SEL==DCOFSEL_4 + #define F_CPU F_CPU_RANGE*2.0 + #elif DCO_FREQ_SEL==DCOFSEL_5 + #define F_CPU F_CPU_RANGE*2.62 + #elif DCO_FREQ_SEL==DCOFSEL_6 + #define F_CPU F_CPU_RANGE*3.0 + #else //DCO_FREQ_SEL==DCOFSEL_0 + #define F_CPU 1000000UL + #endif + + #define F_CPU_SCALED_US F_CPU/(1<<F_CPU_SCALE)/1000000.0 + /* Number of CPU cycles per us */ + #define _delay_us(__us) \ + if((uint32_t) (F_CPU_SCALED_US * __us) != F_CPU_SCALED_US * __us)\ + __delay_cycles((uint32_t) ( F_CPU_SCALED_US * __us)+1);\ + else __delay_cycles((uint32_t) ( F_CPU_SCALED_US * __us)) +enum state_names {IDLE_RESET, WAIT, OPERATE}; +void main (void) +{ + + int idle_counter = 0; + + /* Stop WDT */ + WDTCTL = WDTPW + WDTHOLD; + + /* Setup MSP specific functions, IO's, timers and WDT */ + //Comes from lib/hal_mcu/hal_mcu.c + //msp_setup(); + + // Enable the interupts on port 2 to catch the user button (TRXEB) + + BUTTON_DIR &= ~BUTTON_PIN; // input direction + BUTTON_OUT |= BUTTON_PIN; // set high on port + BUTTON_PxIE |= BUTTON_PIN; // enable interupt + BUTTON_PxIES |= BUTTON_PIN; // Hi/lo edge + BUTTON_REN |= BUTTON_PIN; // Pull up resistor + BUTTON_PxIES &= ~BUTTON_PIN; // IFG cleared + + // Removed XTAL configuration and DCO Fault detection as not on exp430_fr5994 + + // Unlock CS registers. + CSCTL0 = CSKEY; + // Set DCO to 24MHz. + CSCTL1 = DCO_RANGE_SEL + DCO_FREQ_SEL; + // ACLK = VLO, SMCLK = MCLK = DCO + CSCTL2 = SELA_1 + SELS_3 + SELM_3; + // ACLK/1, SMCLK/8, MCLK/1 + CSCTL3 = DIVA_0 + DIVS_0 + F_CPU_SCALE; + // Power down unused clocks. + CSCTL4 = HFXTOFF + VLOOFF; + // Lock clock registers. + CSCTL0 = 0; + + // Setup Watch dog timer for 0.5 second tick using 16MHz DCO on MSP430FR5994 + // WDT 0.5s @ 16mHz, SMCLK, interval timer + WDTCTL= WDTPW + WDTSSEL_0 + WDTTMSEL + WDTIS_2; + SFRIE1 |= WDTIE; // Enable WDT interrupt + + // Unlock the system. + PM5CTL0 &= ~LOCKLPM5; + + P1DIR |= BIT0 | BIT1; + __enable_interrupt(); + /* Infinite loop with a 1 second timer */ + while(1) + { + P1OUT ^= BIT0; + _delay_us(4166); + _delay_us(8332); + } +} + +/****************************************************************************** + * @fn wdt_isr + * + * @brief Interrupt service routine for watch dog timer. + * + * input parameters + * + * @param void + * + * output parameters + * + * @return void + * + */ +HAL_ISR_FUNC_DECLARATION(wdt_isr,WDT) +{ + /* global "0.5 second" counter used for printing time stamped packet sniffer data */ + P1OUT ^= BIT1; + +}