📄 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
}
/*------------------------------------------------------------------------------
0ooo
ooo0 ( )
( ) ) /
\ ( (_/
\_) Modify By:cuiqingwei [gary]
------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -