View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
How to separate math routines? |
Posted: Thu Aug 06, 2015 9:52 am |
|
|
There's any way to have separate math routines for INTs and Main code? _________________ Electric Blue |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Thu Aug 06, 2015 10:01 am |
|
|
Not too sure what you mean, so please provide an example program that show us. The more you explain the easier and faster we can help.
Also, I'm assuming INTs means Interrupt Service Routines ?
Hmm, which 'math' routines ? If it's simple code, it'd be inline, complex then callable as it becomes more efficient in code space and time.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Thu Aug 06, 2015 12:07 pm |
|
|
@temtronic
I need to use 16bit division and multiplication inside interrupts and in the Main code.
@PCM programmer
I read an tried #org and compile, but the message
Interrupts disabled during call to prevent re-entrancy:
still appear.
I do something like
Code: |
#include <18F67J50.h>
//Several variables definition
//.....
//.....
//.....
#include <Config.h>
#include <usb_cdc.h>
#include <stdlib.h>
// Includes all USB code and interrupts, as well as the CDC API
#include <string.h>
#include <strings2.h>
#include "25LC256.h"
#include "Bits_Rules.h"
//Few prototypes
//....
//....
#org 0x1FF, 0x8000
//Here start all the subroutines and functions that are called by different interrupt handlers
////Some 16 bit division and multiplication here
void CountData()// <---This routine is called from Main once at start and from one interrupt handler
{
//.......
//.......
}
#org DEFAULT
void Main (void)
{
//Some 16 bit division and multiplication here too
}
|
I tried to putt #org DEFAULT before CountData() too and get the same Warning.
So I think is not working, I don't end to understand how #org works.
What I'm doing wrong? _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Thu Aug 06, 2015 1:59 pm |
|
|
The USB code contains one 16bit multiplication. So it'll still give the error.
They accept it, since on a PIC18, it uses the hardware multiplier and is only a handful of instruction times.
So I'd not worry about multiplication, but division really should be avoided, just on the grounds of time. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Thu Aug 06, 2015 2:39 pm |
|
|
I'm not receiving warnings about math yet, I'm asking before implement it to know hot to proceed.
This are all the warning for the current version
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (ReadByteEE)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (FillBufferEE)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (@PSTRINGC_1801)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_token_reset)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (SaveTime)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_cdc_flush_tx_buffer)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_tbe)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_cdc_get_discard)
>>> Warning 216 "GPRS_2.c" Line 11917(1,2): Interrupts disabled during call to prevent re-entrancy: (CountData)
ReadByteEE, FillBufferEE,,SaveTime and CountData are subroutines and functions maked by me, the rest are from CCS USB library. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Aug 07, 2015 2:29 am |
|
|
Yes. These routines are basically 'initialisation'. So (for instance) the routine that clears the buffer is only called in the main code, when USB first wakes. Hence there is no loss really in having interrupts disabled during it. It's used in the interrupts when a bus reset has to take place. You can simply duplicate it if required, but it gains nothing to do so.
I'd worry about anything involving 'EE' in an interrupt though. Given the milliseconds most types of electrically erasable memory take, that has alarm bells ringing.... |
|
|
|