@ -107,35 +107,35 @@ definitions. */
CODE
portUPDATE_ M T I M E R _ C O M P A R E _ R E G I S T E R M A C R O
load_ x t 0, p u l l M a c h i n e T i m e r C o m p a r e R e g i s t e r / * L o a d a d d r e s s o f c o m p a r e r e g i s t e r i n t o t 0. * /
load_ x t 1, p u l l N e x t T i m e / * L o a d t h e a d d r e s s o f u l l N e x t T i m e i n t o t 1. * /
load_ x a 0, p u l l M a c h i n e T i m e r C o m p a r e R e g i s t e r / * L o a d a d d r e s s o f c o m p a r e r e g i s t e r i n t o a 0. * /
load_ x a 1, p u l l N e x t T i m e / * L o a d t h e a d d r e s s o f u l l N e x t T i m e i n t o a 1. * /
# if( _ _ r i s c v _ x l e n = = 3 2 )
/* Update the 64-bit mtimer compare match value in two 32-bit writes. */
li t 4, - 1
lw t 2 , 0 ( t 1) / * L o a d t h e l o w w o r d o f u l l N e x t T i m e i n t o t 2. * /
lw t 3 , 4 ( t 1) / * L o a d t h e h i g h w o r d o f u l l N e x t T i m e i n t o t 3. * /
sw t 4 , 0 ( t 0) / * L o w w o r d n o s m a l l e r t h a n o l d v a l u e t o s t a r t w i t h - w i l l b e o v e r w r i t t e n b e l o w . * /
sw t 3 , 4 ( t 0) / * S t o r e h i g h w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . N o s m a l l e r t h a n n e w v a l u e . * /
sw t 2 , 0 ( t 0) / * S t o r e l o w w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
li a 4, - 1
lw a2 , 0 ( a 1) / * L o a d t h e l o w w o r d o f u l l N e x t T i m e i n t o a 2. * /
lw a3 , 4 ( a 1) / * L o a d t h e h i g h w o r d o f u l l N e x t T i m e i n t o a 3. * /
sw a4 , 0 ( a 0) / * L o w w o r d n o s m a l l e r t h a n o l d v a l u e t o s t a r t w i t h - w i l l b e o v e r w r i t t e n b e l o w . * /
sw a3 , 4 ( a 0) / * S t o r e h i g h w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . N o s m a l l e r t h a n n e w v a l u e . * /
sw a2 , 0 ( a 0) / * S t o r e l o w w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
lw t 0 , u x T i m e r I n c r e m e n t s F o r O n e T i c k / * L o a d t h e v a l u e o f u l l T i m e r I n c r e m e n t F o r O n e T i c k i n t o t 0 ( c o u l d t h i s b e o p t i m i z e d b y s t o r i n g i n a n a r r a y n e x t t o p u l l N e x t T i m e ? ) . * /
add t 4 , t 0 , t 2 / * A d d t h e l o w w o r d o f u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k ( a s s u m e s t i m e r i n c r e m e n t f o r o n e t i c k f i t s i n 3 2 - b i t s ) . * /
sltu t 5, t 4 , t 2 / * S e e i f t h e s u m o f l o w w o r d s o v e r f l o w e d ( w h a t a b o u t t h e z e r o c a s e ? ) . * /
add t 6, t 3 , t 5 / * A d d o v e r f l o w t o h i g h w o r d o f u l l N e x t T i m e . * /
sw t 4 , 0 ( t 1) / * S t o r e n e w l o w w o r d o f u l l N e x t T i m e . * /
sw t 6, 4 ( t 1) / * S t o r e n e w h i g h w o r d o f u l l N e x t T i m e . * /
add a4 , t 0 , a 2 / * A d d t h e l o w w o r d o f u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k ( a s s u m e s t i m e r i n c r e m e n t f o r o n e t i c k f i t s i n 3 2 - b i t s ) . * /
sltu t 1, a4 , a 2 / * S e e i f t h e s u m o f l o w w o r d s o v e r f l o w e d ( w h a t a b o u t t h e z e r o c a s e ? ) . * /
add t 2, a3 , t 1 / * A d d o v e r f l o w t o h i g h w o r d o f u l l N e x t T i m e . * /
sw a4 , 0 ( a 1) / * S t o r e n e w l o w w o r d o f u l l N e x t T i m e . * /
sw t 2, 4 ( a 1) / * S t o r e n e w h i g h w o r d o f u l l N e x t T i m e . * /
# endif / * _ _ r i s c v _ x l e n = = 3 2 * /
# if( _ _ r i s c v _ x l e n = = 6 4 )
/* Update the 64-bit mtimer compare match value. */
ld t 2 , 0 ( t 1) / * L o a d u l l N e x t T i m e i n t o t 2 . * /
sd t 2 , 0 ( t 0) / * S t o r e u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
ld t 2 , 0 ( a 1) / * L o a d u l l N e x t T i m e i n t o t 2 . * /
sd t 2 , 0 ( a 0) / * S t o r e u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
ld t 0 , u x T i m e r I n c r e m e n t s F o r O n e T i c k / * L o a d t h e v a l u e o f u l l T i m e r I n c r e m e n t F o r O n e T i c k i n t o t 0 ( c o u l d t h i s b e o p t i m i z e d b y s t o r i n g i n a n a r r a y n e x t t o p u l l N e x t T i m e ? ) . * /
add t 4 , t 0 , t 2 / * A d d u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k . * /
sd t 4 , 0 ( t 1) / * S t o r e u l l N e x t T i m e . * /
sd t 4 , 0 ( a 1) / * S t o r e u l l N e x t T i m e . * /
# endif / * _ _ r i s c v _ x l e n = = 6 4 * /
ENDM
@ -205,7 +205,7 @@ portUPDATE_MTIMER_COMPARE_REGISTER MACRO
* pxCode
* /
pxPortInitialiseStack :
csrr t 0 , C S R _ M S T A T U S / * O b t a i n c u r r e n t m s t a t u s v a l u e . * /
csrr t 0 , C S R _ M S T A T U S / * O b t a i n c u r r e n t m s t a t u s v a l u e . * /
andi t 0 , t 0 , ~ 0 x8 / * E n s u r e i n t e r r u p t s a r e d i s a b l e d w h e n t h e s t a c k i s r e s t o r e d w i t h i n a n I S R . R e q u i r e d w h e n a t a s k i s c r e a t e d a f t e r t h e s c h e d u l r e h a s b e e n s t a r t e d , o t h e r w i s e i n t e r r u p t s w o u l d b e d i s a b l e d a n y w a y . * /
addi t 1 , x0 , 0 x18 8 / * G e n e r a t e t h e v a l u e 0 x18 8 0 , w h i c h a r e t h e M P I E a n d M P P b i t s t o s e t i n m s t a t u s . * /
slli t 1 , t 1 , 4
@ -215,9 +215,13 @@ pxPortInitialiseStack:
store_ x t 0 , 0 ( a0 ) / * m s t a t u s o n t o t h e s t a c k . * /
addi a0 , a0 , - p o r t W O R D _ S I Z E / * S p a c e f o r c r i t i c a l n e s t i n g c o u n t . * /
store_ x x0 , 0 ( a0 ) / * C r i t i c a l n e s t i n g c o u n t s t a r t s a t 0 f o r e v e r y t a s k . * /
addi a0 , a0 , - ( 2 2 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x11 - x31 . * /
# ifdef _ _ r i s c v _ 3 2 e
addi a0 , a0 , - ( 6 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x10 - 1 5 . * /
# else
addi a0 , a0 , - ( 2 2 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x10 - x31 . * /
# endif
store_ x a2 , 0 ( a0 ) / * T a s k p a r a m e t e r s ( p v P a r a m e t e r s p a r a m e t e r ) g o e s i n t o r e g i s t e r X 1 0 / a0 o n t h e s t a c k . * /
addi a0 , a0 , - ( 6 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x5 - x9 . * /
addi a0 , a0 , - ( 6 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x5 - x9 + t a s k R e t u r n A d d r e s s . * /
load_ x t 0 , x T a s k R e t u r n A d d r e s s
store_ x t 0 , 0 ( a0 ) / * R e t u r n a d d r e s s o n t o t h e s t a c k . * /
addi t 0 , x0 , p o r t a s m A D D I T I O N A L _ C O N T E X T _ S I Z E / * T h e n u m b e r o f c h i p s p e c i f i c a d d i t i o n a l r e g i s t e r s . * /
@ -250,6 +254,7 @@ xPortStartFirstTask:
load_ x x13 , 1 0 * p o r t W O R D _ S I Z E ( s p ) / * a3 * /
load_ x x14 , 1 1 * p o r t W O R D _ S I Z E ( s p ) / * a4 * /
load_ x x15 , 1 2 * p o r t W O R D _ S I Z E ( s p ) / * a5 * /
# ifndef _ _ r i s c v _ 3 2 e
load_ x x16 , 1 3 * p o r t W O R D _ S I Z E ( s p ) / * a6 * /
load_ x x17 , 1 4 * p o r t W O R D _ S I Z E ( s p ) / * a7 * /
load_ x x18 , 1 5 * p o r t W O R D _ S I Z E ( s p ) / * s2 * /
@ -266,12 +271,13 @@ xPortStartFirstTask:
load_ x x29 , 2 6 * p o r t W O R D _ S I Z E ( s p ) / * t 4 * /
load_ x x30 , 2 7 * p o r t W O R D _ S I Z E ( s p ) / * t 5 * /
load_ x x31 , 2 8 * p o r t W O R D _ S I Z E ( s p ) / * t 6 * /
# endif
load_ x x5 , 29 * p o r t W O R D _ S I Z E ( s p ) / * O b t a i n x C r i t i c a l N e s t i n g v a l u e f o r t h i s t a s k f r o m t a s k ' s s t a c k . * /
load_ x x5 , po r t C R I T I C A L _ N E S T I N G _ O F F S E T * p o r t W O R D _ S I Z E ( s p ) / * O b t a i n x C r i t i c a l N e s t i n g v a l u e f o r t h i s t a s k f r o m t a s k ' s s t a c k . * /
load_ x x6 , p x C r i t i c a l N e s t i n g / * L o a d t h e a d d r e s s o f x C r i t i c a l N e s t i n g i n t o x6 . * /
store_ x x5 , 0 ( x6 ) / * R e s t o r e t h e c r i t i c a l n e s t i n g v a l u e f o r t h i s t a s k . * /
load_ x x5 , 30 * p o r t W O R D _ S I Z E ( s p ) / * I n i t i a l m s t a t u s i n t o x5 ( t 0 ) . * /
load_ x x5 , po r t M S T A T U S _ O F F S E T * p o r t W O R D _ S I Z E ( s p ) / * I n i t i a l m s t a t u s i n t o x5 ( t 0 ) . * /
addi x5 , x5 , 0 x08 / * S e t M I E b i t s o t h e f i r s t t a s k s t a r t s w i t h i n t e r r u p t s e n a b l e d - r e q u i r e d a s r e t u r n s w i t h r e t n o t e r e t . * /
csrrw x0 , C S R _ M S T A T U S , x5 / * I n t e r r u p t s e n a b l e d f r o m h e r e ! * /