[En-Nut-Discussion] External interrupts on Ethernut 3
Petri Hyötylä
phyotyla at gmail.com
Mon Mar 30 13:53:42 CEST 2009
Hello again
On Fri, Mar 27, 2009 at 6:56 PM, Ole Reinhardt <ole.reinhardt at embedded-it.de
> wrote:
> If you want you may send me some code example and I'd take a look on it.
> Btw: I'd be happy if you would contribute your code, as I'll need the
> MCP2515 in an upcomming project as well...
>
Here's the interrupt related code in its current form. The interrupt is
re-enabled in the threads handling the actual reception.
As far as the contributing goes, I'm not my own boss but I'm for the idea of
publishing the code. Getting acceptance from the appropriate people may take
a while but there are also slight hurdles in using this code in other
projects. Currently the code also depends on some helper functions and
macros that we are using but that should not take long to replace the prints
with standard ones and the final version will probably use very few prints
anyway because the speed is very important in our case. Furthermore, the
driver currently does not adhere to the device model of the Nut/OS but it
does use the CANFRAME as defined in the can_dev.h.
static void CAN_Interrupt(void *arg)
{
#ifdef ETHERNUT2
sbi(PORTF,0);
#endif
NutIrqDisable(&CAN_SIGNAL);
NutEventPostFromIrq(&can_rx_queue);
#ifdef ETHERNUT2
cbi(PORTF,0);
#endif
}
void CAN_Init(unsigned int filter_mode, unsigned long filter_id, unsigned
long filter_mask)
{
...
//Enabled interrupts: ERRIF, RX1IF, RX0IF
CAN_ByteWrite(CANINTE,0x23);
//Register the interrupt to Nut/OS
NutRegisterIrqHandler(&CAN_SIGNAL, CAN_Interrupt, NULL);
// Set Interrupt mode to low level sensitive
NutIrqSetMode(&CAN_SIGNAL, NUT_IRQMODE_LOWLEVEL);
//NutIrqSetMode(&CAN_SIGNAL, NUT_IRQMODE_FALLINGEDGE);
// Disable just in case
NutIrqDisable(&CAN_SIGNAL);
//Set NORMAL mode
CAN_RequestMode(REQOP_NORMAL);
//Verify device entered Normal mode
if (OPMODE_NORMAL != CAN_GetMode())
CAN_RequestMode(REQOP_NORMAL);
// If the second attempt fails, notify the user
if (OPMODE_NORMAL != CAN_GetMode()){
SLFATAL("MCP2515: Failed to set operation mode");
SLFATAL("MCP2515: CAN Controller unusable");
}else{
SLINFO("CAN controller mode normal");
}
/* Start the threads */
NutThreadCreate ("CAN_Rx",CAN_Rx,NULL,1024);
NutThreadCreate ("CAN_Process",CAN_Process,NULL,1024);
NutIrqEnable(&CAN_SIGNAL);
}
More information about the En-Nut-Discussion
mailing list