Skip to content
Snippets Groups Projects
Commit 1bdcd9fd authored by Edward Longman's avatar Edward Longman
Browse files

move into msp_setup function

parent a5290be8
No related branches found
No related tags found
No related merge requests found
...@@ -168,55 +168,7 @@ void msp_setup(void) { ...@@ -168,55 +168,7 @@ void msp_setup(void) {
#endif #endif
#if defined (__MSP430FR5994__) #if defined (__MSP430FR5994__)
//Define the Main Clock setup options. Done here for the delay function setup #include "hal_mcu_fr5.h"
#define DCO_RANGE_SEL DCORSEL
#define DCO_FREQ_SEL DCOFSEL_4
#define F_CPU_SCALE DIVM_0
/**
* @defgroup Delay_function
* @brief Directives to create the _delay_us macro.
* @{
*/
/**
* @def _delay_us(__us)
* @brief Delay for a specified time using the __delay_cycles primitive.
*
* @param[in] __us - time to delay for
* @return none
* @note Assumes using the internal DCO. Will need modification to work with
* XTAL. VLO is two innacurate (6%) for this to be a good delay anyway.
* Max possible delay is (2**32-1)*F_CPU
* That would be 178s for 24MHz.
* helped by https://docs.microsoft.com/en-us/cpp/preprocessor/hash-if-hash-elif-hash-else-and-hash-endif-directives-c-cpp?view=vs-2019
* and https://github.com/ab2tech/msp430/blob/master/include/msp/delay.h
*
*/
#if DCO_RANGE_SEL==DCORSEL
#define F_CPU_RANGE 16000000UL
#else
#define F_CPU_RANGE 5330000UL
#endif
#if DCO_FREQ_SEL==DCOFSEL_0
#define F_CPU F_CPU_RANGE*1.0
#elif DCO_FREQ_SEL==DCOFSEL_1
#define F_CPU F_CPU_RANGE*1.25
#elif DCO_FREQ_SEL==DCOFSEL_2
#define F_CPU F_CPU_RANGE*1.0
#else //DCO_FREQ_SEL==DCOFSEL_3
#define F_CPU F_CPU_RANGE*1.5
#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))
/** @} */
/******************************************************************************* /*******************************************************************************
* @brief Setup all the peripherals of the MSP430, set the CPU speed to 16MHz, * @brief Setup all the peripherals of the MSP430, set the CPU speed to 16MHz,
* enable the 250kHz and configure WDT for a 1 sec tick speed. * enable the 250kHz and configure WDT for a 1 sec tick speed.
...@@ -228,7 +180,6 @@ void msp_setup(void) { ...@@ -228,7 +180,6 @@ void msp_setup(void) {
* @return none * @return none
*******************************************************************************/ *******************************************************************************/
void msp_setup(void) { void msp_setup(void) {
// Enable the interupts on port 2 to catch the user button (TRXEB) // Enable the interupts on port 2 to catch the user button (TRXEB)
BUTTON_DIR &= ~BUTTON_PIN; // input direction BUTTON_DIR &= ~BUTTON_PIN; // input direction
...@@ -241,7 +192,7 @@ void msp_setup(void) { ...@@ -241,7 +192,7 @@ void msp_setup(void) {
// Removed XTAL configuration and DCO Fault detection as not on exp430_fr5994 // Removed XTAL configuration and DCO Fault detection as not on exp430_fr5994
// Unlock CS registers. // Unlock CS registers.
CSCTL0_H = 0xA5; CSCTL0 = CSKEY;
// Set DCO to 24MHz. // Set DCO to 24MHz.
CSCTL1 = DCO_RANGE_SEL + DCO_FREQ_SEL; CSCTL1 = DCO_RANGE_SEL + DCO_FREQ_SEL;
// ACLK = VLO, SMCLK = MCLK = DCO // ACLK = VLO, SMCLK = MCLK = DCO
...@@ -251,7 +202,7 @@ void msp_setup(void) { ...@@ -251,7 +202,7 @@ void msp_setup(void) {
// Power down unused clocks. // Power down unused clocks.
CSCTL4 = HFXTOFF + VLOOFF; CSCTL4 = HFXTOFF + VLOOFF;
// Lock clock registers. // Lock clock registers.
CSCTL0_H = 0; CSCTL0 = 0;
// Setup Watch dog timer for 0.5 second tick using 16MHz DCO on MSP430FR5994 // Setup Watch dog timer for 0.5 second tick using 16MHz DCO on MSP430FR5994
// WDT 0.5s @ 16mHz, SMCLK, interval timer // WDT 0.5s @ 16mHz, SMCLK, interval timer
......
//Define the Main Clock setup options. Done here for the delay function setup
#define DCO_RANGE_SEL DCORSEL
#define DCO_FREQ_SEL DCOFSEL_4
#define F_CPU_SCALE DIVM_0
/**
* @defgroup Delay_function
* @brief Directives to create the _delay_us macro.
* @{
*/
/**
* @def _delay_us(__us)
* @brief Delay for a specified time using the __delay_cycles primitive.
*
* @param[in] __us - time to delay for
* @return none
* @note Assumes using the internal DCO. Will need modification to work with
* XTAL. VLO is two innacurate (6%) for this to be a good delay anyway.
* Max possible delay is (2**32-1)*F_CPU
* That would be 178s for 24MHz.
* helped by https://docs.microsoft.com/en-us/cpp/preprocessor/hash-if-hash-elif-hash-else-and-hash-endif-directives-c-cpp?view=vs-2019
* and https://github.com/ab2tech/msp430/blob/master/include/msp/delay.h
*
*/
#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))
/** @} */
#include "msp430fr5994.h" #include "msp430fr5994.h"
#include "stdio.h" #include "stdio.h"
#include "lib/radio_drv/hal_types.h" #include "lib/radio_drv/hal_types.h"
#include "lib/hal_mcu/hal_mcu_fr5.h"
/****************************************************************************** /******************************************************************************
* LOCAL FUNCTIONS * LOCAL FUNCTIONS
*/ */
extern void msp_setup(void);
unsigned long volatile time_counter; unsigned long volatile time_counter;
...@@ -29,42 +31,6 @@ unsigned long volatile time_counter; ...@@ -29,42 +31,6 @@ unsigned long volatile time_counter;
* *
*/ */
#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}; enum state_names {IDLE_RESET, WAIT, OPERATE};
void main (void) void main (void)
{ {
...@@ -76,39 +42,11 @@ void main (void) ...@@ -76,39 +42,11 @@ void main (void)
/* Setup MSP specific functions, IO's, timers and WDT */ /* Setup MSP specific functions, IO's, timers and WDT */
//Comes from lib/hal_mcu/hal_mcu.c //Comes from lib/hal_mcu/hal_mcu.c
//msp_setup(); msp_setup();
// Enable the interupts on port 2 to catch the user button (TRXEB) // 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; P1DIR |= BIT0 | BIT1;
__enable_interrupt(); __enable_interrupt();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment