?? hal_mcu.c
字號:
/***********************************************************************************
Filename: hal_mcu.c
Description: hal mcu library
***********************************************************************************/
#include "hal_types.h"
#include "hal_mcu.h"
#include "clock.h"
/***********************************************************************************
* @fn halMcuInit
*
* @brief Set system clock
*
* @param none
*
* @return none
*/
void halMcuInit(void)
{
clockSetMainSrc(CLOCK_SRC_XOSC);
}
/***********************************************************************************
* @fn halMcuWaitUs
*
* @brief Busy wait function. Waits the specified number of microseconds. Use
* assumptions about number of clock cycles needed for the various
* instructions. The duration of one cycle depends on MCLK. In this HAL
* , it is set to 8 MHz, thus 8 cycles per usec.
*
* NB! This function is highly dependent on architecture and compiler!
*
* @param uint16 usec - number of microseconds delay
*
* @return none
*/
void halMcuWaitUs(uint16 usec)
{
while(usec--)
{
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
}
/***********************************************************************************
* @fn halMcuWaitMs
*
* @brief Busy wait function. Waits the specified number of milliseconds. Use
* assumptions about number of clock cycles needed for the various
* instructions.
*
* NB! This function is highly dependent on architecture and compiler!
*
* @param uint16 millisec - number of milliseconds delay
*
* @return none
*/
void halMcuWaitMs(uint16 msec)
{
while(msec--)
halMcuWaitUs(1000);
}
/***********************************************************************************
* @fn halMcuSetLowPowerMode
*
* @brief Sets the MCU in a low power mode. Will turn global interrupts on at
* the same time as entering the LPM mode. The MCU must be waken from
* an interrupt (status register on stack must be modified).
*
* NB! This function is highly dependent on architecture and compiler!
*
* @param uint8 mode - power mode
*
* @return none
*/
void halMcuSetLowPowerMode(uint8 mode)
{
// comment: not yet implemented
//HAL_ASSERT(FALSE);
}
/******************************************************************************
* @fn halMcuReset
*
* @brief
* Resets the MCU. This utilize the watchdog timer as there is no other way
* for a software reset. The reset will not occur until ~2 ms.
* NB: The function will not return! (hangs until reset)
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
void halMcuReset(void)
{
const uint8 WDT_INTERVAL_MSEC_2= 0x03; // after ~2 ms
WDCTL = ((WDCTL & 0xFC) | (WDT_INTERVAL_MSEC_2 & 0x03));
// Start watchdog
WDCTL &= ~0x04; // Select watchdog mode
WDCTL |= 0x08; // Enable timer
while(1); // Halt here until reset
}
/***********************************************************************************
Copyright 2007 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -