BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions
bc2.h File Reference

Hardware presentation/abstraction for Basic Clock Module+ (BC2). More...

#include <bsp430/clock.h>
#include <bsp430/periph.h>

Go to the source code of this file.

Macros

#define BSP430_MODULE_BC2   defined(__MSP430_HAS_BC2__)
 
#define configBSP430_BC2_TRIM_TO_MCLK   0
 
#define BSP430_BC2_TRIM_TO_MCLK   include <bsp430/platform.h>
 
#define BSP430_BC2_LFXT1_IS_FAULTED_NI()   (BCSCTL3 & BSP430_BC2_LFXT1OF_)
 
#define BSP430_BC2_XT2_IS_FAULTED_NI()   (BC2CTL3 & BSP430_BC2_XT2OF_)
 
#define BSP430_CLOCK_LFXT1_IS_FAULTED_NI()   ((BCSCTL3 & (LFXT1S0 | LFXT1S1)) || BSP430_BC2_LFXT1_IS_FAULTED_NI())
 
#define BSP430_CLOCK_XT2_IS_FAULTED_NI()   ((BCSCTL1 & XT2OFF) || BSP430_BC2_XT2_IS_FAULTED_NI())
 
#define BSP430_CLOCK_CLEAR_FAULTS_NI()
 
#define BSP430_CLOCK_LFXT1_XCAP   XCAP_1
 
#define BSP430_CLOCK_NOMINAL_VLOCLK_HZ   12000U
 
#define BSP430_CLOCK_PUC_MCLK_HZ   1100000UL
 

Functions

int iBSP430bc2TrimToMCLK_ni (unsigned long mclk_Hz)
 

Detailed Description

Hardware presentation/abstraction for Basic Clock Module+ (BC2).

The BC2 ("Basic Clock Module+") peripheral is present in 2xx-family devices.

Module Configuration Options

Hardware Presentation Layer

As there can be only one instance of BC2 on any MCU, there is no structure supporting a BC2 HPL. Manipulate the peripheral through its registers directly.

Hardware Adaptation Layer

As there can be only one instance of BC2 on any MCU, there is no structure supporting a BC2 HAL.

The standard set of capabilities in the bsp430/clocks.h header are supported, with the following details:

factory-calibrated constants supporting that frequency. The selected frequency may be above or below the requested frequency, but will be the closest supported by available calibrated clocks.

Homepage
http://github.com/pabigot/bsp430

Macro Definition Documentation

#define BSP430_BC2_LFXT1_IS_FAULTED_NI ( )    (BCSCTL3 & BSP430_BC2_LFXT1OF_)

BC2-specific check for LFXT1 crystal fault condition.

This checks exactly for the fault condition.

Warning
On this platform the fault flags are read-only and may clear themselves. If a fault is detected after steps have been taken to enable the crystal, the peripheral should be reconfigured to explicitly avoid referencing the crystal lest it begin functioning and change system behavior.
Note
A crystal that has never been enabled will not register as faulted.
#define BSP430_BC2_TRIM_TO_MCLK   include <bsp430/platform.h>

Defined to a true value if configBSP430_BC2_TRIM_TO_MCLK was requested and BSP430_TIMER_CCACLK is available on the platform.

In the absence of this flag, iBSP430bc2TrimToMCLK_ni() will not be available and must not be referenced.

Dependency:
configBSP430_BC2_TRIM_TO_MCLK, BSP430_TIMER_CCACLK
Platform-Based Value:
Undefined here; include <bsp430/platform.h> to obtain the correct value of this macro.
#define BSP430_BC2_XT2_IS_FAULTED_NI ( )    (BC2CTL3 & BSP430_BC2_XT2OF_)

BC2-specific check for XT2 crystal fault condition.

If the platform does not support an XT2 crystal no fault is diagnosed.

Warning
On this platform the fault flags are read-only and may clear themselves. If a fault is detected after steps have been taken to enable the crystal, the peripheral should be reconfigured to explicitly avoid referencing the crystal lest it begin functioning and change system behavior.
Note
A crystal that has never been enabled will not register as faulted.
#define BSP430_CLOCK_CLEAR_FAULTS_NI ( )
Value:
do { \
} while (0)
#define BSP430_CLOCK_OSC_CLEAR_FAULT_NI()
Definition: clock.h:230

Clear all clock faults.

The BC2 oscillator fault flags are read-only, so this only clears the system oscillator flag.

Defaulted:
The value here is superseded by previously encountered definitions.
#define BSP430_CLOCK_LFXT1_IS_FAULTED_NI ( )    ((BCSCTL3 & (LFXT1S0 | LFXT1S1)) || BSP430_BC2_LFXT1_IS_FAULTED_NI())

Check whether the BC2-controlled LFXT1 crystal has a fault condition.

Note
Unlike most other MSP430 clock peripherals, MCUs with BC2 power-up with the crystal pins in their peripheral mode and with the external crystal selected as the LFXT1 source. However, the fault flag is still valid only if the external crystal is selected. This check will indicate a fault if one is present, or if the LFXT1 source is not the external crystal.
Warning
On this platform the fault flags are read-only and may clear themselves. If a fault is detected after steps have been taken to enable the crystal, the peripheral should be reconfigured to explicitly avoid referencing the crystal lest it begin functioning and change system behavior.
Defaulted:
The value here is superseded by previously encountered definitions.
See also
BSP430_BC2_LFXT1_IS_FAULTED_NI()
#define BSP430_CLOCK_LFXT1_XCAP   XCAP_1

Peripheral default setting for platform-specific constant

#define BSP430_CLOCK_NOMINAL_VLOCLK_HZ   12000U

Unconditional define for peripheral-specific constant

#define BSP430_CLOCK_PUC_MCLK_HZ   1100000UL

Unconditional define for peripheral-specific constant

#define BSP430_CLOCK_XT2_IS_FAULTED_NI ( )    ((BCSCTL1 & XT2OFF) || BSP430_BC2_XT2_IS_FAULTED_NI())

Check whether the BC2-controlled XT2 crystal has a fault condition.

Note
Oscillator fault flags are not set unless a fault has been detected. If the crystal has never been enabled, no fault will have been detected. On power-up, the XT2IN function is not enabled and BCSCTL1.XT2OFF is set, and BSP430 treats BCSCTL1.XT2OFF as an indication that the pins are not configured for crystal use, either because XT2 has not been configured or has been configured and found to be faulted. Although it is perfectly acceptable to have BCSCTL1.XT2OFF set and the crystal working fine, the complexity of detecting that case is not supported by this implementation.
Defaulted:
The value here is superseded by previously encountered definitions.
See also
BSP430_BC2_XT2_IS_FAULTED_NI()
#define BSP430_MODULE_BC2   defined(__MSP430_HAS_BC2__)

Defined on inclusion of <bsp430/periph/bc2.h>. The value evaluates to true if the target MCU supports the Basic Clock Module+, and false if it does not.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
#define configBSP430_BC2_TRIM_TO_MCLK   0

Define to a true value to request that ulBSP430bc2TrimToMCLK_ni() be made available.

Because implementation of this function depends on BSP430_TIMER_CCACLK, setting this option causes <bsp430/platform/bsp430_config.h> to default configBSP430_TIMER_CCACLK to true.

This value represents an application or system request for the feature; availability of the feature must be tested using BSP430_BC2_TRIM_TO_MCLK before attempting to invoke the function.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Affects:
BSP430_BC2_TRIM_TO_MCLK
Dependency:
BSP430_TIMER_CCACLK
Defaulted:
The value here is superseded by previously encountered definitions.

Function Documentation

int iBSP430bc2TrimToMCLK_ni ( unsigned long  mclk_Hz)

Adjust the DCO as necessary to reach the requested MCLK speed

nThe BC2 peripheral supports only a small number of calibrated DCO clock frequencies, and it is not uncommon for them to be off by a significant amount for the cheaper ValueLine MCUs. If an ACLK source at a trusted rate is available, the MCU can implement a loop to converge on a DCO configuration that supports a specific requested clock speed.

Returns
0 if the requested speed could be reached, -1 if an error occurred. Potential errors are inability to access BSP430_TIMER_CCACLK_PERIPH_HANDLE.
Warning
The accuracy of the resulting frequency is proportional to the accuracy of the returned value of ulBSP430clockACLK_Hz_ni(). If ACLK derives from VLOCLK, that estimate may be off by several percent, which will generally result in serial errors if SMCLK is used to generate a baud rate clock. You may wish to check BSP430_CLOCK_LFXT1_IS_FAULTED_NI() prior to invoking this, as is done by ulBSP430clockConfigureMCLK_ni() for this peripheral.
Dependency:
BSP430_BC2_TRIM_TO_MCLK, BSP430_TIMER_CCACLK