Skip to content
Snippets Groups Projects
Select Git revision
  • d71fb23ad9c13e93479a837f94e66ce04bd3f48b
  • master default
  • slow-lib-int
  • ti-sample-project
  • working-spi-in-main
  • working-timera1-delay-fast-wdt
  • working-timer-a1
  • working-uart-isr-lib
  • working-uart-wdt-report
9 results

min2.c

Blame
  • min2.c 3.98 KiB
    #include "msp430fr5994.h"
    #include "stdio.h"
    #include "lib/radio_drv/hal_spi_rf.h"
    #include "lib/radio_drv/hal_types.h"
    #include "lib/hal_mcu/hal_mcu_fr5.h"
    #include "lib/uart_drv/uart_drv.h"
    #include "lib/hal_mcu/hal_timer.h"
    
    /******************************************************************************
     * LOCAL FUNCTIONS
     */
    extern void msp_setup(void);
    int ee_printf(const char *fmt, ...);
    
    /******************************************************************************
     * GLOBALS
     */
    char u_str[UART_BUFF_SIZE];
    unsigned char txBuffer[TX_BUFF_SIZE];
    unsigned long volatile main_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
     *
     */
    
    enum state_names {IDLE_RESET, WAIT, OPERATE};
    void main (void)
    {
    
    	int idle_counter = 0;
    	main_time_counter =0;
    	unsigned int waited = 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();
    
    	/* Initialize the UART port */
    	hal_uart_init();
    
    	// Setup the timer
      hal_timer_init(0x8000);
    
    	P1DIR |= BIT0 | BIT1;
    	P1OUT |= BIT0 | BIT1;
    	P3DIR |= BIT4;
    	P3SEL0 &= ~BIT4;
    	P3SEL1 &= ~BIT4;
    	//Setup SPI
    	/* Keep peripheral in reset state*/
    	UCB1CTLW1 |= UCSWRST;
    	UCB1CTL1 &=  ~(UCSSEL_3);
    	//Reset all config
    	UCB1CTLW0 = ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
    		 UCMST + UCMODE_3 + UCSYNC);
    
    	/* Configuration
    	 * -  8-bit
    	 * -  Master Mode
    	 * -  3-pin
    	 * -  synchronous mode
    	 * -  MSB first
    	 * -  Clock phase select = captured on first edge
    	 * -  Inactive state is low
    	 * -  SMCLK as clock source
    	 * -  Spi clk is adjusted corresponding to systemClock as the highest rate
    	 *    supported by the supported radios: this could be optimized and done
    	 *    after chip detect.
    	 */
    	UCB1CTLW0  |=  0x00+UCMST + UCSYNC + UCMODE_0 + UCMSB + UCCKPH;
    	UCB1CTLW0 |=  UCSSEL_2;
    	UCB1BRW   =  0x00;
    
    	UCB1BRW = 4;
    	// select bit RF_MISO_PIN, RF_MOSI_PIN, RF_SCLK as peripheral
    	RF_PORT_SEL0 |= RF_MISO_PIN + RF_MOSI_PIN + RF_SCLK_PIN;
    	// and set the correct direction on the port
    	RF_PORT_DIR |= RF_MOSI_PIN + RF_SCLK_PIN;
    
    	RF_PORT_OUT |= RF_MISO_PIN;
    	RF_PORT_REN |= RF_MISO_PIN;
    	RF_PORT_DIR &= ~(RF_MISO_PIN);
    
    	// select chip select bit RF_CS_N_PORT_SEL as a port
    	RF_CS_N_PORT_SEL0 &= ~RF_CS_N_PIN;
    	RF_CS_N_PORT_DIR |= RF_CS_N_PIN;
    	RF_CS_N_PORT_OUT |= RF_CS_N_PIN;
    
    	/* Release for operation */
    	UCB1CTL1 &= ~UCSWRST;
    
    	__enable_interrupt();
    	/* Infinite loop with a 1 second timer */
    	while(1)
    	{
    		hal_timer_wait(0x0190);
    		if(idle_counter!=main_time_counter){
    			idle_counter=main_time_counter;
    			ee_printf("Cnt:%3i\n\r", idle_counter);
    			ee_printf("TA0CCR:0x%4X\n\r", TA0R);
    		  TA0CCTL1 = CCIE;                       // interrupt enabled
    		  _BIS_SR(LPM0_bits + GIE);             // Enter LPM0
    			//Left LPM0
    		  TA0CCTL1 = 0;                       // interrupt disabled
    
    			P3OUT ^= BIT4;
    			waited = hal_timer_wait(0x09C4);
    			P3OUT ^= BIT4;
    			ee_printf("Waited:0x%4X\n\r", waited);
    
    		}
    		if(idle_counter>10){
    			//Use LPM0 For sleep
    		}
    	}
    }
    
    /******************************************************************************
     * @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)
    {
    	main_time_counter++;
    	/* global "0.5 second" counter used for printing time stamped packet sniffer data */
    	P1OUT ^= BIT0;
    }