📄 syslib.h
字号:
#ifndef SYSLIB_H
#define SYSLIB_H
#include "port.h"
#include "bsp.h"
/*64-th bits value*/
struct U64
{
unsigned long w[2];
};
EXPORT void U64addU32(const struct U64 * pFirst, const unsigned long second, struct U64 * pResult);
EXPORT unsigned long U64mulU32(const struct U64 * pFirst, const unsigned long second, struct U64* pRezult);
EXPORT void incU64(struct U64 * pU64);
EXPORT unsigned int U32divU16s(const unsigned long dividend, const unsigned int divisor, unsigned long * pResult);
EXPORT unsigned int U32divU16(const unsigned long dividend, const unsigned int divisor, unsigned int * pReminder);
EXPORT unsigned int U64divU16(const struct U64 * puDividend, const unsigned int uDivider, struct U64 * puQuotient);
/*******************************************************
* Own assert routine
*******************************************************/
/* debug mode assert routine - just move control to debugger */
#define ASSERT() asm(debug)
/*******************************************************
* Byte/Word convertion routines
*******************************************************/
#define archHiByte(x) (((UWord16)(x) >> 8) & 0x00FF)
#define archLoByte(x) ((UWord16)(x) & 0x00FF)
#define archBytes2Word(hi, lo) ((UWord16)((hi << 8) | lo))
inline unsigned short archGetLimitBit(void)
{
register unsigned short ret;
asm( move.w SR, ret );
asm( bfclr 0xffbf, ret );
return ret;
}
/* void archResetLimitBit (void); */
#define archResetLimitBit() asm(bfclr #0x40,SR)
/* void archSetNoSat (void); */
#define archSetNoSat() asm(bfclr #0x10,OMR)
/* void archSetSat32 (void); */
#define archSetSat32() asm(bfset #0x10,OMR)
/* Get, then set saturation mode */
//EXPORT bool archGetSetSaturationMode (bool bSatMode);
/* set saturation mode and return it previous value */
inline Word16 archGetSetSaturationMode (register bool bSatMode)
{
register Word16 ret;
asm {
move.w OMR,ret
bfclr 0xffef,ret
}
if(bSatMode) /* using "if" enables compile-time optimization */
asm (bfset 0x10,OMR);
else
asm (bfclr 0x10,OMR);
return ret;
}
/* void archSet2CompRound (void); */
#define archSet2CompRound() asm(bfset #0x20,OMR)
/* void archSetConvRound (void); */
#define archSetConvRound() asm(bfclr #0x20,OMR)
/* void archStop (void); */
#define archStop() asm(stop)
/* void archTrap (void); */
#define archTrap() asm(swi)
/* void archWait (void); */
#define archWait() asm(wait)
/* void archEnableInt (void); */
#define archEnableInt() asm(bfclr #0x0300,SR)
/* void archDisableInt (void); */
#define archDisableInt() asm(bfset #0x0300,SR)
#define archMemRead(Local, Remote, Bytes) *(Local) = *(Remote)
#define archMemWrite(Remote, Local, Bytes) *(Remote) = *(Local)
#define archCoreRegisterBitSet(Mask, Reg) asm(bfset Mask,Reg)
#define archCoreRegisterBitClear(Mask, Reg) asm(bfclr Mask,Reg)
#define archCoreRegisterBitChange(Mask, Reg) asm(bfchg Mask,Reg)
#define archCoreRegisterBitTestHigh(Mask, Reg) asm(bftsth Mask,Reg)
#define archCoreRegisterBitTestLow(Mask, Reg) asm(bftstl Mask,Reg)
#define archMemBitSet(Mask, Addr) asm(bfset Mask,Addr)
#define archMemBitClear(Mask, Addr) asm(bfclr Mask,Addr)
#define archMemBitChange(Mask, Addr) asm(bfchg Mask,Addr)
#define archMemBitTestHigh(Mask, Addr) asm(bftsth Mask,Addr)
#define archMemBitTestLow(Mask, Addr) asm(bftstl Mask,Addr)
/********************************************************
* Intrinsics and operation primitives
********************************************************/
/* substitute for shl intrinsic - shift only in 1 direction !!!
original shl() remain usable, for shifts by immediate number
the original shl may be better
*/
inline Word16 shl2(register Word16 num, register Word16 shift)
{
asm( asll.w shift, num );
return num;
}
/* substitute for shr intrinsic - shift only in 1 direction !!!
same situation as in shl2()
*/
inline Word16 shr2(register Word16 num, register Word16 shift)
{
asm ( asrr.w shift, num );
return num;
}
/* Primitives (impyuu, impysu) */
inline UWord32 impyuu(register UWord16 unsigA, register UWord16 unsigB)
{
register UWord32 l;
asm {
.iasm_reg2regsetcopyflag off
move.w unsigA,A0
move.w unsigB,B0
impyuu A0,B0,l /* thanks to impyuu F0,F0,FFF, we can use 'l' as destination */
.iasm_reg2regsetcopyflag on
}
return l;
}
inline Word32 impysu(register Word16 sigA, register UWord16 unsigB)
{
register Word32 l;
asm {
.iasm_reg2regsetcopyflag off
move.w sigA,A1
move.w unsigB,B0
impysu A1,B0,Y /* unlike with impyuu, there is no impysu F0,F0,FFF (must use Y) */
move.w Y0,l.1 /* so we must transfer 32bit-wide Y to return register 'l' */
lsrr.l 16,l /* I'd rather use l.0 - but it is not implemented */
move.w Y1,l.1
.iasm_reg2regsetcopyflag on
}
return l;
}
/*******************************************************
* Routines for P <-> X Memory Access
*
* - All routines can be used in pragma interrupt ISRs
*
*******************************************************/
#define memset memMemset
#define memSetP memMemsetP
#define memcpy memMemcpy
UWord16 memReadP16 (UWord16 *pSrc);
UWord32 memReadP32 (UWord32 *pSrc);
void memWriteP16 (UWord16 Data, Word16 *pDest);
void memWriteP32 (UWord32 Data, Word32 *pDest);
void * memCopyXtoP (void *pDest, const void *pSrc, ssize_t Count);
void * memCopyPtoX (void *pDest, const void *pSrc, ssize_t Count);
void * memCopyPtoP (void *pDest, const void *pSrc, ssize_t Count);
void * memMemset (void *dest, int c, ssize_t count);
void * memMemcpy (void *dest, const void *src, ssize_t count);
void * memMemsetP (void *dest, int c, ssize_t count);
asm void memCopyWordXtoP ( UWord32 *dest, const UWord16 *src, UWord16 count );
asm void memCopyWordPtoX ( UWord32 *addr, const UWord16 *dest, UWord16 count );
asm void memCopyWordXtoX( UWord32 *dest, const UWord16 *src, UWord16 count );
/***************************************************************************
P Interbal RAM circular buffer support
***************************************************************************/
/* Put word value to P Internal RAM Buffer */
inline void bspPutWord2PMemBuf(register unsigned short value , register unsigned short bufferOffset)
{
asm( adda #BASE_CIRCULAR_BUFFER_ADDRESS , bufferOffset , R0 );
asm( move.w value , P:(R0)+ );
};
/* Get word value from P Internal RAM Buffer */
inline unsigned short bspGetWordFromPMemBuf(register unsigned int bufferOffset)
{
register unsigned int Value;
asm( adda #BASE_CIRCULAR_BUFFER_ADDRESS , bufferOffset , R0 );
asm( move.w P:(R0)+ , Value );
return Value;
};
EXPORT void stackcheckInitialize (void); /* called from config.c */
/*******************************************************
* Interface to check for stack overflow
*
* To enable the stack check, define #INCLUDE_STACK_CHECK in appconfig.h
*
* stackcheckSizeAllocated() returns the stack size that was allocated in linker.cmd
*
* stackcheckSizeUsed() returns the stack size actually used so far in the application
*
* Note that stack overflow has occurred if
* stackcheckSizeUsed () > stackcheckSizeAllocated ()
*
*******************************************************/
EXPORT long stackcheckSizeUsed (void);
EXPORT long stackcheckSizeAllocated (void);
#endif /* SYSLIB_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -