Home/Support/Support Forum/how to create and run interrupt as one task and other tasks running simultaneously in uCOS tasks
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

how to create and run interrupt as one task and other tasks running simultaneously in uCOS tasks

0 votes
Thank you for your technical help it solved some of my reuirements.
I have the follwing following reuirement using uCOS having 2 tasks, one running at 500usec and other slower tasks both are running simultanesously.I have tried the 500usec TimerC Interrupt and it is working fine and with in that 500usec my total functionality of the code is not fitting. so I started to use uCOS multi tasking with one task at 500usec and other with lower time rates. I tried to achive lower prioty task till 1 msec only, which will not meet my reuirement. so I tried to use TimerC interrupt as one of the tasks of high priority which I can run at 500usec rate but I am unable to find the first TimerC code as a interrupt in the multi tasking.
please find the below code
Please find the attached files.
**************************************************************************************
#define TIMERC_MS 1UL
#if CPU_ID_MASK(_CPU_ID_) >= R6000 && defined PLL_DEFAULT_PLL_SPEED_MHz
#define MAIN_PCLK_FREQUENCY (PLL_DEFAULT_PLL_SPEED_MHz * 1000000UL / 2UL)
#else

#if CLOCK_DOUBLED
#define MAIN_PCLK_FREQUENCY (_CRYSTAL_SPEED_ * 2UL)
#else
#define MAIN_PCLK_FREQUENCY (_CRYSTAL_SPEED_ * 1UL)
#endif

#endif

#define TIMERC_DIVIDER_IDEAL \
(TIMERC_MS * MAIN_PCLK_FREQUENCY / 16. / 2000. - 1.)

#define TIMERC_DIVIDER ((unsigned long) (TIMERC_DIVIDER_IDEAL + 0.5))

#if TIMERC_DIVIDER > 65535UL
#undef TIMERC_DIVIDER
#define TIMERC_DIVIDER 65535UL
#warns "Out of range TIMERC_DIVIDER redefined to the maximum value (65535)."
#warns "Reduce the TIMERC_MS macro value to an achievable setting."
#endif

#define TCDLR_SETTING (int)(0xff & TIMERC_DIVIDER)
#define TCDHR_SETTING (int)(0xff & (TIMERC_DIVIDER/0x100))
#undef THRESHOLD
#define THRESHOLD 18.00
#class auto
#use "BLxS2xx.lib"
#use "COSTATE.LIB"
#define FINBUFSIZE 255
#define FOUTBUFSIZE 1023
#ifndef _232BAUD
#define _232BAUD 19200
#endif

unsigned short usTemp = 0x00;
unsigned long timerc_count;
int ct=0x00,ch,channel=0,dpcnt=0,blinc=0,i=0;
float cosval[40],sinval[40],cosval_2n[40],sinval_2n[40],cosval_3n[40],sinval_3n[40],cosval_4n[40],sinval_4n[40],cosval_5n[40],sinval_5n[40];
float sdiff,fac=0.0,fas=0.0,fac_2n=0.0,fas_2n=0.0,fac_3n=0.0,fas_3n=0.0,fac_4n=0.0,fas_4n=0.0,fac_5n=0.0,fas_5n=0.0,olda[40],ias,ia=0.0,ia_2n=0.0,ia_3n=0.0,ia_4n=0.0,ia_5n=0.0;
float idc1=0.0,idc2=0.0;
char strig[22],temp1[30],setval[50];
unsigned long int temp, n=0,n1=0,n2=0;


xmem ocuc()
{
digOut(0,0);

ias = anaInVolts(1,0); /*input from channel 1 */

digOut(0,1);

sdiff = (olda[n1] - ias);

idc1 = (idc1 + sdiff);

idc2 = -idc1/40;


olda[n1] = ias;

n1 = (n1+1)% 40;
dpcnt++;


}

#asm
timerC_isr::
push af ; save all used registers
push bcde
push jkhl
ioi ld a, (TCCSR) ; clear the interrupt request and get status
; handle all interrupts flagged in TCCSR here
ld bcde, (timerc_count)
ld jkhl, 1
add jkhl, bcde
ld (timerc_count), jkhl
pop jkhl ; restore all used registers
pop bcde
pop af
ipres
ret
#endasm


int main(void)
{
int waitFlag;

/******** ANALOG INPUT VARIABLES ********/
for (n=0;n<40;n++)
{
olda[n] = 0.0; /*setting initialially values to zero */
}

brdInit(); /*initialises system I/O ports */

serFopen(_232BAUD);
serMode(0);
for(channel = 0; channel < 8; ++channel)
{
setDigOut(channel, 0);
}
anaInConfig(1, SE1_MODE); /*configures an A/D converter input channel 1 for single ended bipolar mode of operation . */
anaInConfig(2, SE1_MODE); /* configures an A/D converter input channel 2 for single ended bipolar mode of operation.*/
digOut(0, 0); /* digout from channel 0 */

// ensure timer C is disabled
WrPortI(TCCSR, &TCCSRShadow, 0x00);
// set up timer C to use pclk/16
WrPortI(TCCR, &TCCRShadow, 0x09);
WrPortI(TCDLR, NULL, TCDLR_SETTING);
WrPortI(TCDHR, NULL, TCDHR_SETTING);
// install timer C's ISR
SetVectIntern(TIMERC_OFS / 0x10, timerC_isr);
// enable timer C
WrPortI(TCCSR, &TCCSRShadow, 0x01);

timerc_count = 0;
while (1)
{
if( timerc_count )
{
timerc_count = 0;
ocuc( );
}

}
}

***********************************************************************************************
how to include this as a high priority task along with the below code:
#class auto


#define OS_TASK_CREATE_EXT_EN 1 // Enable extended task creation
#define OS_SEM_EN 1 // Enable semaphores
#define OS_SEM_POST_EN 1 // Enable old style post to semaphore

#define OS_MAX_TASKS 6 // Maximum number of tasks system can create (less stat and idle tasks)
#define OS_TIME_DLY_HMSM_EN 1
#define OS_MBOX_EN 1

#define OS_MAX_EVENTS 4

#define STACK_CNT_256 2
#define STACK_CNT_512 3
#define STACK_CNT_1K 1
#define STACK_CNT_2K 1
#define STACK_CNT_4K 2
#use "BLxS2xx.lib"
#use "ucos2.lib"

#define INVALID_COMMAND "$INVALID_COMMAND;\r"
#define USER_BLOCK_HEADER 0x55555555


void task1(void);
void task2(void);
void task3(void);
void task4(void);



int channel=0,blinc=0;

void main()
{

brdInit();

for(channel = 0; channel < 8; ++channel)
{
setDigOut(channel, 0);
}

OSInit();


OSTaskCreateExt(task1, \
(void *)0, \
0, \
10, \
2048, \
(void *)0, \
OS_TASK_OPT_STK_CHK);

OSStart(); // start uC/OS
while(1)
{
}

}

void task1()
{
while(1)
{

blinc = !blinc;

digOut(0,blinc);

OSTimeDlyHMSM(0,0,0,1);

}
}

****************
you answer will help me a lot please help me
asked Sep 21 in Rabbit by dhanunjay New to the Community (1 point)
Thank you for your technical help. the function that I am running in interrupt is having data acquisition using adcInVolts() which is taking around 110 micro seconds and remaining thing is taking 120 micro seconds, and I have some more functionality need to be implemented with that functionality added to this existing function the total time is crossing 500 micro seconds. But I need to take samples strictly at 500 micro seconds for My DFT operation, so my interrupt total time is exceeding that is why I am trying to use interrupt and uCOSII combinely so that sampling I can do in interrupt at 500 micro seconds and other operations at higher time UCOS tasks.

Please log in or register to answer this question.

1 Answer

0 votes
Based on what you're trying to do, I'd say that you don't need uC/OS-II.

You need to code your TimerC interrupt to call ocuc() directly, and to be more efficient, so it can complete it's work in <500us to allow the main program time to run. You might need to have it save and restore all registers on the stack if you need to run C code from the interrupt. There's code in STDVDRIVER.LIB that shows how to push/pop ALL registers (including the alternate registers).

How long does the current TimerC code take to run? You can toggle a spare output pin on when it starts and off when it ends, and then use a scope or a logic probe to measure how long it takes. Have the interrupt fire every 5ms to start, just to ensure you're giving it enough time to complete, so you can get solid measurements.
answered Sep 22 by TomCollins Veteran of the Digi Community (2,051 points)
...