2020-04-21 18:20:01 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ( c) S E G G E R M i c r o c o n t r o l l e r G m b H *
* The E m b e d d e d E x p e r t s *
* www. s e g g e r . c o m *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- - - - - - - - - - - - - - - - - - - - - - - - - - END- O F - H E A D E R - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
File : S E G G E R _ R T T _ A S M _ A R M v7 M . S
Purpose : A s s e m b l e r i m p l e m e n t a t i o n o f R T T f u n c t i o n s f o r A R M v7 M
Additional i n f o r m a t i o n :
This m o d u l e i s w r i t t e n t o b e a s s e m b l e r - i n d e p e n d e n t a n d w o r k s w i t h
GCC a n d c l a n g ( E m b e d d e d S t u d i o ) a n d I A R .
* /
# define S E G G E R _ R T T _ A S M / / U s e d t o c o n t r o l p r o c e s s e d i n p u t f r o m h e a d e r f i l e
# include " S E G G E R _ R T T . h "
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Defines, f i x e d
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* /
2023-06-06 19:07:58 +02:00
2020-04-21 18:20:01 +02:00
# define _ C C I A R 0
# define _ C C C L A N G 1
# if ( d e f i n e d _ _ S E S _ A R M ) | | ( d e f i n e d _ _ G N U C _ _ ) | | ( d e f i n e d _ _ c l a n g _ _ )
# define _ C C _ T Y P E _ C C C L A N G
# define _ P U B _ S Y M . g l o b a l
# define _ E X T _ S Y M . e x t e r n
# define _ E N D . e n d
# define _ W E A K . w e a k
# define _ T H U M B _ F U N C . t h u m b _ f u n c
# define _ T H U M B _ C O D E . c o d e 1 6
# define _ W O R D . w o r d
# define _ S E C T I O N ( S e c t , T y p e , A l i g n E x p ) . s e c t i o n S e c t ## , " ax "
2023-03-17 10:12:49 +01:00
# define _ A L I G N ( E x p ) . a l i g n E x p
2020-04-21 18:20:01 +02:00
# define _ P L A C E _ L I T S . l t o r g
2023-03-17 10:12:49 +01:00
# define _ D A T A _ S E C T _ S T A R T
2020-04-21 18:20:01 +02:00
# define _ C _ S T A R T U P _ s t a r t
# define _ S T A C K _ E N D _ _ s t a c k _ e n d _ _
# define _ R A M F U N C
/ /
/ / .text = > Link t o f l a s h
/ / .fast = > Link t o R A M
/ / OtherSect = > U s u a l l y l i n k t o R A M
/ / Alignment i s 2 ^ x
/ /
# elif d e f i n e d ( _ _ I A S M A R M _ _ )
# define _ C C _ T Y P E _ C C I A R
# define _ P U B _ S Y M P U B L I C
# define _ E X T _ S Y M E X T E R N
# define _ E N D E N D
# define _ W E A K _ W E A K
# define _ T H U M B _ F U N C
# define _ T H U M B _ C O D E T H U M B
# define _ W O R D D C D
# define _ S E C T I O N ( S e c t , T y p e , A l i g n E x p ) S E C T I O N S e c t ## : # # T y p e # # : R E O R D E R : N O R O O T # # ( A l i g n E x p )
2023-03-17 10:12:49 +01:00
# define _ A L I G N ( E x p ) a l i g n r o m E x p
2020-04-21 18:20:01 +02:00
# define _ P L A C E _ L I T S
# define _ D A T A _ S E C T _ S T A R T D A T A
# define _ C _ S T A R T U P _ _ i a r _ p r o g r a m _ s t a r t
# define _ S T A C K _ E N D s f e ( C S T A C K )
# define _ R A M F U N C S E C T I O N _ T Y P E S H T _ P R O G B I T S , S H F _ W R I T E | S H F _ E X E C I N S T R
/ /
/ / .text = > Link t o f l a s h
/ / .textrw = > Link t o R A M
/ / OtherSect = > U s u a l l y l i n k t o R A M
/ / NOROOT = > A l l o w s l i n k e r t o t h r o w a w a y t h e f u n c t i o n , i f n o t r e f e r e n c e d
/ / Alignment i s 2 ^ x
/ /
# endif
# if ( _ C C _ T Y P E = = _ C C I A R )
NAME S E G G E R _ R T T _ A S M _ A R M v7 M
# else
.syntax unified
# endif
# if d e f i n e d ( R T T _ U S E _ A S M ) & & ( R T T _ U S E _ A S M = = 1 )
# define S H T _ P R O G B I T S 0 x1
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Public / e x t e r n a l s y m b o l s
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* /
_ EXT_ S Y M _ _ a e a b i _ m e m c p y
_ EXT_ S Y M _ _ a e a b i _ m e m c p y 4
_ EXT_ S Y M _ S E G G E R _ R T T
_ PUB_ S Y M S E G G E R _ R T T _ A S M _ W r i t e S k i p N o L o c k
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* SEGGER_ R T T _ W r i t e S k i p N o L o c k
*
* Function d e s c r i p t i o n
* Stores a s p e c i f i e d n u m b e r o f c h a r a c t e r s i n S E G G E R R T T
* control b l o c k w h i c h i s t h e n r e a d b y t h e h o s t .
* SEGGER_ R T T _ W r i t e S k i p N o L o c k d o e s n o t l o c k t h e a p p l i c a t i o n a n d
* skips a l l d a t a , i f t h e d a t a d o e s n o t f i t i n t o t h e b u f f e r .
*
* Parameters
* BufferIndex I n d e x o f " U p " - b u f f e r t o b e u s e d ( e . g . 0 f o r " T e r m i n a l " ) .
* pBuffer P o i n t e r t o c h a r a c t e r a r r a y . D o e s n o t n e e d t o p o i n t t o a \ 0 t e r m i n a t e d s t r i n g .
* NumBytes N u m b e r o f b y t e s t o b e s t o r e d i n t h e S E G G E R R T T c o n t r o l b l o c k .
* MUST b e > 0 ! ! !
* This i s d o n e f o r p e r f o r m a n c e r e a s o n s , s o n o i n i t i a l c h e c k h a s d o b e d o n e .
*
* Return v a l u e
* 1 : Data h a s b e e n c o p i e d
* 0 : No s p a c e , d a t a h a s n o t b e e n c o p i e d
*
* Notes
* ( 1 ) If t h e r e i s n o t e n o u g h s p a c e i n t h e " U p " - b u f f e r , a l l d a t a i s d r o p p e d .
* ( 2 ) For p e r f o r m a n c e r e a s o n s t h i s f u n c t i o n d o e s n o t c a l l I n i t ( )
* and m a y o n l y b e c a l l e d a f t e r R T T h a s b e e n i n i t i a l i z e d .
* Either b y c a l l i n g S E G G E R _ R T T _ I n i t ( ) o r c a l l i n g a n o t h e r R T T A P I f u n c t i o n f i r s t .
* /
_ SECTION( . t e x t , C O D E , 2 )
_ ALIGN( 2 )
_ THUMB_ F U N C
SEGGER_RTT_ASM_WriteSkipNoLock : / / unsigned S E G G E R _ R T T _ W r i t e S k i p N o L o c k ( u n s i g n e d B u f f e r I n d e x , c o n s t v o i d * p D a t a , u n s i g n e d N u m B y t e s ) {
/ /
/ / Cases :
/ / 1 ) RdOff < = W r O f f = > S p a c e u n t i l w r a p - a r o u n d i s s u f f i c i e n t
/ / 2 ) RdOff < = W r O f f = > S p a c e a f t e r w r a p - a r o u n d n e e d e d ( c o p y i n 2 c h u n k s )
/ / 3 ) RdOff < W r O f f = > N o s p a c e i n b u f
/ / 4 ) RdOff > W r O f f = > S p a c e i s s u f f i c i e n t
/ / 5 ) RdOff > W r O f f = > N o s p a c e i n b u f
/ /
/ / 1 ) is t h e m o s t c o m m o n c a s e f o r l a r g e b u f f e r s a n d a s s u m i n g t h a t J - L i n k r e a d s t h e d a t a f a s t e n o u g h
/ /
/ / Register u s a g e :
/ / R0 T e m p o r a r y n e e d e d a s R d O f f , < T m p > r e g i s t e r l a t e r o n
/ / R1 p D a t a
/ / R2 < N u m B y t e s >
/ / R3 < T m p > r e g i s t e r . H o l d f r e e f o r s u b r o u t i n e c a l l s
/ / R4 < R e m >
/ / R5 p R i n g - > p B u f f e r
/ / R6 p R i n g ( P o i n t s t o a c t i v e s t r u c t S E G G E R _ R T T _ B U F F E R _ D O W N )
/ / R7 W r O f f
/ /
PUSH { R 4 - R 7 }
ADD R 3 ,R 0 ,R 0 , L S L #+ 1
LDR. W R 0 ,=_SEGGER_RTT / / p R i n g = & _ S E G G E R _ R T T . a U p [ B u f f e r I n d e x ] ;
ADD R 0 ,R 0 ,R 3 , L S L #+ 3
ADD R 6 ,R 0 ,#+ 24
LDR R 0 ,[ R 6 , #+ 16 ] / / R d O f f = p R i n g - > R d O f f ;
LDR R 7 ,[ R 6 , #+ 12 ] / / W r O f f = p R i n g - > W r O f f ;
LDR R 5 ,[ R 6 , #+ 4 ] / / p R i n g - > p B u f f e r
CMP R 7 ,R 0
BCC. N _ C h e c k C a s e 4 / / i f ( R d O f f < = W r O f f ) { = > C a s e 1 ) , 2 ) o r 3 )
/ /
/ / Handling f o r c a s e 1 , l a t e r o n i d e n t i c a l t o c a s e 4
/ /
LDR R 3 ,[ R 6 , #+ 8 ] / / A v a i l = p R i n g - > S i z e O f B u f f e r - W r O f f - 1 u ; => Space until wrap-around (assume 1 byte not usable for case that RdOff == 0)
SUBS R 4 ,R 3 ,R 7 / / < R e m > ( U s e d i n c a s e w e j u m p i n t o c a s e 2 a f t e r w a r d s )
SUBS R 3 ,R 4 ,#+ 1 / / < A v a i l >
CMP R 3 ,R 2
BCC. N _ C h e c k C a s e 2 / / i f ( A v a i l > = N u m B y t e s ) { = > C a s e 1 ) ?
_Case4 :
ADDS R 5 ,R 7 ,R 5 / / p B u f f e r + = W r O f f
ADDS R 0 ,R 2 ,R 7 / / v = W r O f f + N u m B y t e s
/ /
/ / 2 x u n r o l l i n g f o r t h e c o p y l o o p t h a t i s u s e d m o s t o f t h e t i m e
/ / This i s a s p e c i a l o p t i m i z a t i o n f o r s m a l l S y s t e m V i e w p a c k e t s a n d m a k e s t h e m e v e n f a s t e r
/ /
_ ALIGN( 2 )
_LoopCopyStraight : / / memcpy( p R i n g - > p B u f f e r + W r O f f , p D a t a , N u m B y t e s ) ;
LDRB R 3 ,[ R 1 ] , #+ 1
STRB R 3 ,[ R 5 ] , #+ 1 / / * p D e s t + + = * p S r c + +
SUBS R 2 ,R 2 ,#+ 1
BEQ _ C S D o n e
LDRB R 3 ,[ R 1 ] , #+ 1
STRB R 3 ,[ R 5 ] , #+ 1 / / * p D e s t + + = * p S r c + +
SUBS R 2 ,R 2 ,#+ 1
BNE _ L o o p C o p y S t r a i g h t
_CSDone :
2023-06-06 19:07:58 +02:00
# if _ C O R E _ N E E D S _ D M B / / D o n o t s l o w d o w n c o r e s t h a t d o n o t n e e d a D M B i n s t r u c t i o n h e r e
DMB / / C o r t e x - M 7 m a y d e l a y m e m o r y w r i t e s a n d a l s o c h a n g e t h e o r d e r i n w h i c h t h e w r i t e s h a p p e n . T h e r e f o r e , m a k e s u r e t h a t a l l b u f f e r w r i t e s a r e f i n i s h e d , b e f o r e u p d a t i n g t h e < W r O f f > i n t h e s t r u c t
# endif
2020-04-21 18:20:01 +02:00
STR R 0 ,[ R 6 , #+ 12 ] / / p R i n g - > W r O f f = W r O f f + N u m B y t e s ;
MOVS R 0 ,#+ 1
POP { R 4 - R 7 }
BX L R / / R e t u r n 1
_CheckCase2 :
ADDS R 0 ,R 0 ,R 3 / / A v a i l + = R d O f f ; => Space incl. wrap-around
CMP R 0 ,R 2
BCC. N _ C a s e 3 / / i f ( A v a i l > = N u m B y t e s ) { = > C a s e 2 ? = > I f n o t , w e h a v e c a s e 3 ) ( d o e s n o t f i t )
/ /
/ / Handling f o r c a s e 2
/ /
ADDS R 0 ,R 7 ,R 5 / / v = p R i n g - > p B u f f e r + W r O f f = > D o n o t c h a n g e p R i n g - > p B u f f e r h e r e b e c a u s e 2 n d c h u n k n e e d s o r g . v a l u e
SUBS R 2 ,R 2 ,R 4 / / N u m B y t e s - = R e m ; (Rem = pRing->SizeOfBuffer - WrOff; => Space until end of buffer)
_LoopCopyBeforeWrapAround : / / memcpy( p R i n g - > p B u f f e r + W r O f f , p D a t a , R e m ) ; => Copy 1st chunk
LDRB R 3 ,[ R 1 ] , #+ 1
STRB R 3 ,[ R 0 ] , #+ 1 / / * p D e s t + + = * p S r c + +
SUBS R 4 ,R 4 ,#+ 1
BNE _ L o o p C o p y B e f o r e W r a p A r o u n d
/ /
/ / Special c a s e : F i r s t c h e c k t h a t a s s u m e d R d O f f = = 0 c a l c u l a t e d t h a t l a s t e l e m e n t b e f o r e w r a p - a r o u n d c o u l d n o t b e u s e d
/ / But 2 n d c h e c k ( c o n s i d e r i n g s p a c e u n t i l w r a p - a r o u n d a n d u n t i l R d O f f ) r e v e a l e d t h a t R d O f f i s n o t 0 , s o w e c a n u s e t h e l a s t e l e m e n t
/ / In t h i s c a s e , w e m a y u s e a c o p y s t r a i g h t u n t i l b u f f e r e n d a n y w a y w i t h o u t n e e d i n g t o c o p y 2 c h u n k s
/ / Therefore, c h e c k i f 2 n d m e m c p y i s n e c e s s a r y a t a l l
/ /
ADDS R 4 ,R 2 ,#+ 0 / / S a v e < N u m B y t e s > ( n e e d e d a s c o u n t e r i n l o o p b u t m u s t b e w r i t t e n t o < W r O f f > a f t e r t h e l o o p ) . A l s o u s e t h i s i n s t t o u p d a t e t h e f l a g s t o s k i p 2 n d l o o p i f p o s s i b l e
BEQ. N _ N o 2 C h u n k N e e d e d / / i f ( N u m B y t e s ) {
_LoopCopyAfterWrapAround : / / memcpy( p R i n g - > p B u f f e r , p D a t a + R e m , N u m B y t e s ) ;
LDRB R 3 ,[ R 1 ] , #+ 1 / / p D a t a a l r e a d y p o i n t s t o t h e n e x t s r c b y t e d u e t o c o p y l o o p i n c r e m e n t b e f o r e t h i s l o o p
STRB R 3 ,[ R 5 ] , #+ 1 / / * p D e s t + + = * p S r c + +
SUBS R 2 ,R 2 ,#+ 1
BNE _ L o o p C o p y A f t e r W r a p A r o u n d
_No2ChunkNeeded :
2023-06-06 19:07:58 +02:00
# if _ C O R E _ N E E D S _ D M B / / D o n o t s l o w d o w n c o r e s t h a t d o n o t n e e d a D M B i n s t r u c t i o n h e r e
DMB / / C o r t e x - M 7 m a y d e l a y m e m o r y w r i t e s a n d a l s o c h a n g e t h e o r d e r i n w h i c h t h e w r i t e s h a p p e n . T h e r e f o r e , m a k e s u r e t h a t a l l b u f f e r w r i t e s a r e f i n i s h e d , b e f o r e u p d a t i n g t h e < W r O f f > i n t h e s t r u c t
# endif
2020-04-21 18:20:01 +02:00
STR R 4 ,[ R 6 , #+ 12 ] / / p R i n g - > W r O f f = N u m B y t e s ; => Must be written after copying data because J-Link may read control block asynchronously while writing into buffer
MOVS R 0 ,#+ 1
POP { R 4 - R 7 }
BX L R / / R e t u r n 1
_CheckCase4 :
SUBS R 0 ,R 0 ,R 7
SUBS R 0 ,R 0 ,#+ 1 / / A v a i l = R d O f f - W r O f f - 1 u ;
CMP R 0 ,R 2
BCS. N _ C a s e 4 / / i f ( A v a i l > = N u m B y t e s ) { = > C a s e 4 ) = = 1 ) ? = > I f n o t , w e h a v e c a s e 5 ) = = 3 ) ( d o e s n o t f i t )
_Case3 :
MOVS R 0 ,#+ 0
POP { R 4 - R 7 }
BX L R / / R e t u r n 0
_ PLACE_ L I T S
# endif / / d e f i n e d ( R T T _ U S E _ A S M ) & & ( R T T _ U S E _ A S M = = 1 )
_ END
/*************************** End of file ****************************/