From: Nagaraj K <nagaraj.kmurthy@gmail.com>
To: ecos-devel@ecos.sourceware.org
Subject: Cortex-M3 HAL interrupt-priority code bug
Date: Thu, 25 Nov 2010 10:34:00 -0000 [thread overview]
Message-ID: <AANLkTikH4CxinV6F9SNPC1Btr1byV_HuJaOSQMAz1bAX@mail.gmail.com> (raw)
Hi,
I was browsing through the Cortex-M3 HAL port and everything looks
OK except for the function
hal_interrupt_set_level() in hal\cortexm\arch\current\src\hal_misc.c
Here is the original function.
__externC void hal_interrupt_set_level( cyg_uint32 vector, cyg_uint32 level )
{
cyg_uint32 l = (level)+CYGNUM_HAL_CORTEXM_PRIORITY_MAX;
if( l > 0xFF ) l = 0xFF; /* clamp to 0xFF */
if( vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL &&
vector <= CYGNUM_HAL_INTERRUPT_NVIC_MAX )
{
HAL_WRITE_UINT8(
CYGARC_REG_NVIC_BASE+CYGARC_REG_NVIC_PR(vector-CYGNUM_HAL_INTERRUPT_EXTERNAL),
l );
}
else if ( vector == CYGNUM_HAL_INTERRUPT_SYS_TICK )
{
cyg_uint32 shpr2;
HAL_READ_UINT32( CYGARC_REG_NVIC_BASE+CYGARC_REG_NVIC_SHPR2, shpr2 );
shpr2 &= ~0xFF000000;
shpr2 |= (l)<<24;
HAL_WRITE_UINT32( CYGARC_REG_NVIC_BASE+CYGARC_REG_NVIC_SHPR2, shpr2 );
}
HAL_VAR_INTERRUPT_SET_LEVEL( vector, level );
}
I see that this function wrongly implements the priority level in
Cortex-M3 processor. According to the Cortex-M3 data sheet, we need to
write the priority level to the top N bits of the register where N is
the number of priority level bits implemented in this particular
version of the cortex variant. Hence I feel that the right
implementation should be
__externC void hal_interrupt_set_level( cyg_uint32 vector, cyg_uint32 level )
{
cyg_uint32 l = (level)<<(8-CYGNUM_HAL_CORTEXM_PRIORITY_LEVEL_BITS);
if( l > 0xFF ) l = 0xFF; /* clamp to 0xFF */
if( vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL &&
vector <= CYGNUM_HAL_INTERRUPT_NVIC_MAX )
{
HAL_WRITE_UINT8(
CYGARC_REG_NVIC_BASE+CYGARC_REG_NVIC_PR(vector-CYGNUM_HAL_INTERRUPT_EXTERNAL),
l );
}
else if ( vector == CYGNUM_HAL_INTERRUPT_SYS_TICK )
{
cyg_uint32 shpr2;
HAL_READ_UINT32( CYGARC_REG_NVIC_BASE+CYGARC_REG_NVIC_SHPR2, shpr2 );
shpr2 &= ~0xFF000000;
shpr2 |= (level)<<24;
HAL_WRITE_UINT32( CYGARC_REG_NVIC_BASE+CYGARC_REG_NVIC_SHPR2, shpr2 );
}
HAL_VAR_INTERRUPT_SET_LEVEL( vector, level );
}
I am new to this developer forum and I am sorry if this is not the
right mailing list for this discussion. If so, please suggest an
alternate forum.
Thanks & Regards, Nagaraj
next reply other threads:[~2010-11-25 10:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-25 10:34 Nagaraj K [this message]
2010-11-25 11:19 ` Nick Garnett
2010-11-25 11:26 ` Christophe Coutand
2010-11-25 12:03 ` Nick Garnett
2010-11-25 12:10 ` Nick Garnett
2010-11-25 14:29 ` Nagaraj K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTikH4CxinV6F9SNPC1Btr1byV_HuJaOSQMAz1bAX@mail.gmail.com \
--to=nagaraj.kmurthy@gmail.com \
--cc=ecos-devel@ecos.sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).