hpw422移植新的sdk
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/*!
|
||||
* \file hal_assert.h
|
||||
*
|
||||
* \brief The header of hal_assert.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
#ifndef HAL_ASSERT_H
|
||||
#define HAL_ASSERT_H
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Macros
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* HAL_ASSERT( expression ) - The given expression must evaluate as "true" or else the assert
|
||||
* handler is called. From here, the call stack feature of the debugger can pinpoint where
|
||||
* the problem occurred.
|
||||
*
|
||||
* HAL_ASSERT_FORCED( ) - If asserts are in use, immediately calls the assert handler.
|
||||
*
|
||||
* HAL_ASSERT_STATEMENT( statement ) - Inserts the given C statement but only when asserts
|
||||
* are in use. This macros allows debug code that is not part of an expression.
|
||||
*
|
||||
* HAL_ASSERT_DECLARATION( declaration ) - Inserts the given C declaration but only when asserts
|
||||
* are in use. This macros allows debug code that is not part of an expression.
|
||||
*
|
||||
* Asserts can be disabled for optimum performance and minimum code size (ideal for
|
||||
* finalized, debugged production code). To disable, define the preprocessor
|
||||
* symbol HALNODEBUG at the project level.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HALNODEBUG
|
||||
#define HAL_ASSERT(expr)
|
||||
#define HAL_ASSERT_FORCED()
|
||||
#define HAL_ASSERT_STATEMENT(statement)
|
||||
#define HAL_ASSERT_DECLARATION(declaration)
|
||||
#else
|
||||
#define HAL_ASSERT(expr) st( if (!( expr )) halAssertHandler(); )
|
||||
#define HAL_ASSERT_FORCED() halAssertHandler()
|
||||
#define HAL_ASSERT_STATEMENT(statement) st( statement )
|
||||
#define HAL_ASSERT_DECLARATION(declaration) declaration
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This macro compares the size of the first parameter to the integer value
|
||||
* of the second parameter. If they do not match, a compile time error for
|
||||
* negative array size occurs (even gnu chokes on negative array size).
|
||||
*
|
||||
* This compare is done by creating a typedef for an array. No variables are
|
||||
* created and no memory is consumed with this check. The created type is
|
||||
* used for checking only and is not for use by any other code. The value
|
||||
* of 10 in this macro is arbitrary, it just needs to be a value larger
|
||||
* than one to result in a positive number for the array size.
|
||||
*/
|
||||
#define HAL_ASSERT_SIZE(x,y) typedef char x ## _assert_size_t[-1+10*(sizeof(x) == (y))]
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Prototypes
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
void halAssertHandler(void);
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
*/
|
||||
|
||||
/**************************************************************************************************
|
||||
* FUNCTIONS - API
|
||||
**************************************************************************************************/
|
||||
|
||||
|
||||
extern void halAssertHazardLights(void);
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include "hal_board_cfg.h"
|
||||
@@ -0,0 +1,131 @@
|
||||
/*!
|
||||
* \file hal_defs.h
|
||||
*
|
||||
* \brief The header of hal_defs.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
#ifndef HAL_DEFS_H
|
||||
#define HAL_DEFS_H
|
||||
#include "xc6xxx.h"
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Macros
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef BV
|
||||
#define BV(n) (1 << (n))
|
||||
#endif
|
||||
|
||||
#ifndef BF
|
||||
#define BF(x,b,s) (((x) & (b)) >> (s))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(n,m) (((n) < (m)) ? (n) : (m))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(n,m) (((n) < (m)) ? (m) : (n))
|
||||
#endif
|
||||
|
||||
#ifndef ABS
|
||||
#define ABS(n) (((n) < 0) ? -(n) : (n))
|
||||
#endif
|
||||
|
||||
|
||||
/* takes a byte out of a uint32 : var - uint32, ByteNum - byte to take out (0 - 3) */
|
||||
#define BREAK_UINT32( var, ByteNum ) \
|
||||
(uint8)((uint32)(((var) >>((ByteNum) * 8)) & 0x00FF))
|
||||
|
||||
#define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) \
|
||||
((uint32)((uint32)((Byte0) & 0x00FF) \
|
||||
+ ((uint32)((Byte1) & 0x00FF) << 8) \
|
||||
+ ((uint32)((Byte2) & 0x00FF) << 16) \
|
||||
+ ((uint32)((Byte3) & 0x00FF) << 24)))
|
||||
|
||||
#define BUILD_UINT16(loByte, hiByte) \
|
||||
((uint16)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
|
||||
|
||||
#define HI_UINT16(a) (((a) >> 8) & 0xFF)
|
||||
#define LO_UINT16(a) ((a) & 0xFF)
|
||||
|
||||
#define BUILD_UINT8(hiByte, loByte) \
|
||||
((uint8)(((loByte) & 0x0F) + (((hiByte) & 0x0F) << 4)))
|
||||
|
||||
#define HI_UINT8(a) (((a) >> 4) & 0x0F)
|
||||
#define LO_UINT8(a) ((a) & 0x0F)
|
||||
|
||||
// Write the 32bit value of 'val' in little endian format to the buffer pointed
|
||||
// to by pBuf, and increment pBuf by 4
|
||||
#define UINT32_TO_BUF_LITTLE_ENDIAN(pBuf,val) \
|
||||
do { \
|
||||
*(pBuf)++ = ((((uint32)(val)) >> 0) & 0xFF); \
|
||||
*(pBuf)++ = ((((uint32)(val)) >> 8) & 0xFF); \
|
||||
*(pBuf)++ = ((((uint32)(val)) >> 16) & 0xFF); \
|
||||
*(pBuf)++ = ((((uint32)(val)) >> 24) & 0xFF); \
|
||||
} while (0)
|
||||
|
||||
// Return the 32bit little-endian formatted value pointed to by pBuf, and increment pBuf by 4
|
||||
#define BUF_TO_UINT32_LITTLE_ENDIAN(pBuf) (((pBuf) += 4), BUILD_UINT32((pBuf)[-4], (pBuf)[-3], (pBuf)[-2], (pBuf)[-1]))
|
||||
|
||||
#ifndef CHECK_BIT
|
||||
#define CHECK_BIT(DISCS, IDX) ((DISCS) & (1<<(IDX)))
|
||||
#endif
|
||||
#ifndef GET_BIT
|
||||
#define GET_BIT(DISCS, IDX) (((DISCS)[((IDX) / 8)] & BV((IDX) % 8)) ? TRUE : FALSE)
|
||||
#endif
|
||||
#ifndef SET_BIT
|
||||
#define SET_BIT(DISCS, IDX) (((DISCS)[((IDX) / 8)] |= BV((IDX) % 8)))
|
||||
#endif
|
||||
#ifndef CLR_BIT
|
||||
#define CLR_BIT(DISCS, IDX) (((DISCS)[((IDX) / 8)] &= (BV((IDX) % 8) ^ 0xFF)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This macro is for use by other macros to form a fully valid C statement.
|
||||
* Without this, the if/else conditionals could show unexpected behavior.
|
||||
*
|
||||
* For example, use...
|
||||
* #define SET_REGS() st( ioreg1 = 0; ioreg2 = 0; )
|
||||
* instead of ...
|
||||
* #define SET_REGS() { ioreg1 = 0; ioreg2 = 0; }
|
||||
* or
|
||||
* #define SET_REGS() ioreg1 = 0; ioreg2 = 0;
|
||||
* The last macro would not behave as expected in the if/else construct.
|
||||
* The second to last macro will cause a compiler error in certain uses
|
||||
* of if/else construct
|
||||
*
|
||||
* It is not necessary, or recommended, to use this macro where there is
|
||||
* already a valid C statement. For example, the following is redundant...
|
||||
* #define CALL_FUNC() st( func(); )
|
||||
* This should simply be...
|
||||
* #define CALL_FUNC() func()
|
||||
*
|
||||
* (The while condition below evaluates false without generating a
|
||||
* constant-controlling-loop type of warning on most compilers.)
|
||||
*/
|
||||
#define st(x) do { x } while (__LINE__ == -1)
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
*/
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
/*!
|
||||
* \file hal_drivers.h
|
||||
*
|
||||
* \brief The header of hal_drivers.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
#ifndef HAL_DRIVER_H
|
||||
#define HAL_DRIVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
* INCLUDES
|
||||
**************************************************************************************************/
|
||||
|
||||
#include "hal_types.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
* CONSTANTS
|
||||
**************************************************************************************************/
|
||||
|
||||
#define HAL_BUZZER_EVENT 0x0080
|
||||
#define PERIOD_RSSI_RESET_EVT 0x0040
|
||||
#define HAL_LED_BLINK_EVENT 0x0020
|
||||
#define HAL_KEY_EVENT 0x0010
|
||||
|
||||
#if defined POWER_SAVING
|
||||
#define HAL_SLEEP_TIMER_EVENT 0x0004
|
||||
#define HAL_PWRMGR_HOLD_EVENT 0x0002
|
||||
#define HAL_PWRMGR_CONSERVE_EVENT 0x0001
|
||||
#endif
|
||||
|
||||
#define HAL_PWRMGR_CONSERVE_DELAY 10
|
||||
#define PERIOD_RSSI_RESET_TIMEOUT 10
|
||||
|
||||
/**************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**************************************************************************************************/
|
||||
|
||||
extern uint8 Hal_TaskID;
|
||||
|
||||
/**************************************************************************************************
|
||||
* FUNCTIONS - API
|
||||
**************************************************************************************************/
|
||||
|
||||
extern void Hal_Init ( uint8 task_id );
|
||||
|
||||
/*
|
||||
* Process Serial Buffer
|
||||
*/
|
||||
extern uint16 Hal_ProcessEvent ( uint8 task_id, uint16 events );
|
||||
|
||||
/*
|
||||
* Process Polls
|
||||
*/
|
||||
extern void Hal_ProcessPoll (void);
|
||||
|
||||
/*
|
||||
* Initialize HW
|
||||
*/
|
||||
extern void HalDriverInit (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
**************************************************************************************************/
|
||||
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* \file hal_sleep.h
|
||||
*
|
||||
* \brief The header of hal_sleep.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
#ifndef HAL_SLEEP_H
|
||||
#define HAL_SLEEP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "hal_types.h"
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
extern void system_sleep_init(void);
|
||||
/*
|
||||
* Execute power management procedure
|
||||
*/
|
||||
extern void halSleep( uint32 osal_timer );
|
||||
|
||||
/*
|
||||
* Used in mac_mcu
|
||||
*/
|
||||
extern void halSleepWait(uint16 duration);
|
||||
|
||||
/*
|
||||
* Used in hal_drivers, AN044 - DELAY EXTERNAL INTERRUPTS
|
||||
*/
|
||||
extern void halRestoreSleepLevel( void );
|
||||
|
||||
/*
|
||||
* Used by the interrupt routines to exit from sleep.
|
||||
*/
|
||||
extern void halSleepExit(void);
|
||||
|
||||
/*
|
||||
* Set the max sleep loop time lesser than the T2 rollover period.
|
||||
*/
|
||||
extern void halSetMaxSleepLoopTime(uint32 rolloverTime);
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*!
|
||||
* \file hal_timer.h
|
||||
*
|
||||
* \brief The header of hal_timer.c
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include "hal_types.h"
|
||||
|
||||
#define OSAL_TIMER (TIMER1_IDX)
|
||||
|
||||
void osal_timer_init(void);
|
||||
void osal_timer_start(void);
|
||||
void osal_timer_tick_set(uint32 tick);
|
||||
uint32 getMcuPrecisionCount(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user