
Technical discussions about the TI C6000 DSPs (including the c62x, c64x and c67x DSPs).
|
Hi all, My C program contains one interrupt service routine corresponding to serial port interrupt (coming at 8khz,every 125us.) and one Task(created, using DSP/BIOS). The Task writes 240 samples into a buffer of length 400 and the ISR reads one sample from the buffer, each time it is executed. Communication between the Task and the ISR is designed in such a way that, when the ISR has completed reading 230 samples from the Buffer, the Task again fills the Buffer with next 240 samples. My problem is that, The Task is not getting the CPU share when there is no interrupt and ISR is continously reading even after 240 samples ie., it is reading junk values after 240. so how to solve this kind of problem??? I understand that according the heirarchy HWI has higher priority than the Task created using DSP/BIOS. But when there is no HWI, Task should get its CPU share and get its work done. Unfortunately this is not happening in my case. So what could be the possible fault in my program????. Looking forward to your solutions....... Simha |
|
|
|
Hi, what do you do in your Task function (you have defined its name by DSP-BIOS configuration tool)? Generally speaking if a task gets control, it runs (state: TSK_RUNNING) till - it is preemptied - state: TSK_READY - calls a blocking function (e.g. SEM_pend()) - state: TSK_BLOCKED - returns from task function (i.e. task terminated) - state: TSK_TERMINATED So, if you need a task which has periodically something to do, you need an endless loop in your task function which e.g. starts with a blocking call (e.g. SEM_pend()) To reschedule your task function e.g. SEM_post() has been called (e.g. by ISR). See: - SPRU326 TMS320C54x DSP/BIOS User's Guide - SPRU404 TMS320C54x DSP/BIOS API Reference Guide Ciao Gabor > Date: Wed, 24 Apr 2002 04:25:42 -0700 (PDT) > From: simha j <> > Subject: Problem with Task Switching.. > > Hi all, > > My C program contains one interrupt service routine > corresponding to serial port interrupt > (coming at 8khz,every 125us.) and one Task(created, > using DSP/BIOS). The Task writes 240 > samples into a buffer of length 400 and the ISR reads > one sample from the buffer, each > time it is executed. > Communication between the Task and the ISR is designed > in such a way that, when the ISR > has completed reading 230 samples from the Buffer, the > Task again fills the Buffer with > next 240 samples. > My problem is that, The Task is not getting the CPU > share when there is no interrupt and > ISR is continously reading even after 240 samples ie., > it is reading junk values after > 240. > so how to solve this kind of problem??? > > I understand that according the heirarchy HWI has > higher priority than the Task created > using DSP/BIOS. But when there is no HWI, Task should > get its CPU share and get its work > done. Unfortunately this is not happening in my case. > So what could be the possible fault > in my program????. > Looking forward to your solutions....... > > Simha > > ______________________________________________________________ > __________ > ______________________________________________________________ > __________ |
|
Hi, There could be some problem in the design itself. This is because as u go on giving the samples to the serial port, the samples will be transmitted and then the interrupt is trigged.This will make the HWI to be allocated all the times right. What i came to know from ur explanation is that within this serial port isr again u are reading next sample from the buffer and dumping it in to the serial port Right? The way the serial port is configred also matters here. First dump the samples into the buffer from the task first and then give that buffer to the isr wherein that isr will take the sample and send it out(transmit).Only after the buffer of lenght 230 is done then only an interrupt should be generated. Within that isr u should make use of some swi to handle it. WIthin the swi function call that function that dump the new set of samples back in to that buffer from were the isr starts reading that. Other solution can be : 1. One task have a while(1) loop within which a flag and two buffers are used. if the flag is 1 send first buffer else second buffer. 2. Configure the serial port such that interrupt is generated only after the required buffer size is done. with in that isr use the buffer that is sent by the task. and then start dumping the data to the serial port. What is found in ur design is that all the time the isr will be generated,this is Y the task does not get a chance to do the required stuff. Another solution is that u can configure a PRD object that is called at the rate at which the 230 samples transmitted are done.Suppose if it takes X time. Then congiure a PRD with X ticks and call a function that change the buffer or fill the buffer. Hope this will Help a lot............... Praveen DSP Design Engg, Aureole Tech Pvt Ltd, Bangalore. --- simha j <> wrote: > Hi all, > > My C program contains one interrupt service routine > corresponding to serial port interrupt > (coming at 8khz,every 125us.) and one Task(created, > using DSP/BIOS). The Task writes 240 > samples into a buffer of length 400 and the ISR > reads > one sample from the buffer, each > time it is executed. > Communication between the Task and the ISR is > designed > in such a way that, when the ISR > has completed reading 230 samples from the Buffer, > the > Task again fills the Buffer with > next 240 samples. > My problem is that, The Task is not getting the CPU > share when there is no interrupt and > ISR is continously reading even after 240 samples > ie., > it is reading junk values after > 240. > so how to solve this kind of problem??? > > I understand that according the heirarchy HWI has > higher priority than the Task created > using DSP/BIOS. But when there is no HWI, Task > should > get its CPU share and get its work > done. Unfortunately this is not happening in my > case. > So what could be the possible fault > in my program????. > Looking forward to your solutions....... > > Simha > _____________________________________ > ________________________________________________________________________ For live cricket scores download Yahoo! Score Tracker at: http://in.sports.yahoo.com/cricket/tracker.html |
|
Hi simha, go throught the below code: /* Make use of a transmitter counter that will become zero */ /*Below is the isr...*/ int txDone = 0,transmit_Cnt=0; int sampleBuffer[240]; int* sample; void Serial_isr(void) { /* The transmit_Cnt = 240 which is incremented in the task that is the size of the buffer u need to send */ if (transmit_Cnt) { *DXR = *samples++; transmit_Cnt--; if (transmit_Cnt == 0) SEM_post(&WAIT); } } void tsk_fxn(void) { while(1) { if ((txDone = SEM_pend(&WAIT)) == 1) { sample = &sampleBuffer; for(sample_count=0;sample_count<=240;sample_count++) *sample++ = data/*Actual sample info*/ transmit_Cnt = sample_count; } } } --- simha j <> wrote: > > Hello praveen, > Here is a portion of my code. please go through > this. > > I have configured Mcbsp0 for external frame > sync.(8khz) and external > clock(2Mhz). and XINT mode is configured for 'New > Frame'. ie., ISR > gets executed every 125us. > > Serial Port Configuration is working fine. This, I > checked by having > only ISR in my program. ie., I placed > 'call_func_to_dump_samples()' > in the ISR itself and in this case, it returns only > one sample to the > ISR, instead of filling a buffer. > But I don't want to place my function in the ISR. so > I > created a > seperate task. > My intention of this task is that , very first time > it > calls the > function (when there is no serial port interrupt, > bcoz > it has higher priority than the task), without > checking any condition and > fills the buffer with 240 samples. so when the next > time control hits > the ISR, it checks whether there is a vaild data in > the buffer (flag == 1) > and if true it reads one data, increments read > pointer(rd_ptr), checks > whether it is 400 to wrap around and returns. > Now, since there are no higher priority tasks for > next > 125us, control > should come to task1() and checks whether the diff. > between rd_ptr and > wr_ptr is 10 (ie., whether ISR has read 230 samples) > and if this is true, > functon inside the task1() is called and it writes > the > next 240samples > into the buffer. and this goes on... > > I don't understand what is the problem with my code. > looking forward.......... > > > . > . > . > .. > .. > /* Globals */ > short enable_write=1; > short * samples = (short*)0x00008000; > short wr_ptr=0,rd_ptr=0; > short input=0,flag; > > void task1(){ > short i; > > for(i=0;i<400;i++) > *(samples+i)=0; > > enable_write=1; > wr_ptr=0; > input=0; > > for(;;) { > > if(enable_write==1) { > enable_write=0; > > /* This function dumps 240 samples into a > circular buffer of > length 400. */ > call_func_to_dump_240samples(samples,&input,&wr_ptr); > flag =1; > > } > if( (wr_ptr - rd_ptr == 10) || ( rd_ptr - > wr_ptr == 390) { > enable_write=1; > } > } // for ever > } > > //------- ISR > ----------------------------------------- > > void McbspEventHandler(){ > int *DXR = (int *)0X018C0004; > > if(flag ==1){ > > *DXR = *(samples + rd_ptr); > rd_ptr++; > if(rd_ptr == 400) > rd_ptr = 0; > } > } > > --- praveen kumar <> > wrote: > > Hi, > > > > There could be some problem in the design itself. > > This is because as u go on giving the samples to > the > > serial port, the samples will be transmitted and > > then > > the interrupt is trigged.This will make the HWI to > > be > > allocated all the times right. > > > > What i came to know from ur explanation is that > > within this serial port isr again u are reading > next > > sample from the buffer and dumping it in to the > > serial > > port Right? > > > > The way the serial port is configred also matters > > here. > > First dump the samples into the buffer from the > task > > first and then give that buffer to the isr wherein > > that isr will take the sample and send it > > out(transmit).Only after the buffer of lenght 230 > is > > done then only an interrupt should be generated. > > Within that isr u should make use of some swi to > > handle it. WIthin the swi function call that > > function > === message truncated === ________________________________________________________________________ For live cricket scores download Yahoo! Score Tracker at: http://in.sports.yahoo.com/cricket/tracker.html |
|
|
|
Hi Simha, One important point I want to bring u into ur notice is that, the portion of the code that is used to dump the data to the transmittor port also counts a lot. That is the code: *DDX = Sample; 1. can also be called in the ISR what u are doing and 2. in the task also. in the first case u need to do all the pointer modifications in the task, But in the second case that is u need to just change the buffer pointers in the isr and that buffer is then filled from some fxn and the buffer containing samples are then transmitted using the above code in the task. Is it clear......... Praveen Kumar R.P DSP Design Engg, Aureole Tech Pvt Ltd, Bangalore. --- simha j <> wrote: > > Hello praveen, > Here is a portion of my code. please go through > this. > > I have configured Mcbsp0 for external frame > sync.(8khz) and external > clock(2Mhz). and XINT mode is configured for 'New > Frame'. ie., ISR > gets executed every 125us. > > Serial Port Configuration is working fine. This, I > checked by having > only ISR in my program. ie., I placed > 'call_func_to_dump_samples()' > in the ISR itself and in this case, it returns only > one sample to the > ISR, instead of filling a buffer. > But I don't want to place my function in the ISR. so > I > created a > seperate task. > My intention of this task is that , very first time > it > calls the > function (when there is no serial port interrupt, > bcoz > it has higher priority than the task), without > checking any condition and > fills the buffer with 240 samples. so when the next > time control hits > the ISR, it checks whether there is a vaild data in > the buffer (flag == 1) > and if true it reads one data, increments read > pointer(rd_ptr), checks > whether it is 400 to wrap around and returns. > Now, since there are no higher priority tasks for > next > 125us, control > should come to task1() and checks whether the diff. > between rd_ptr and > wr_ptr is 10 (ie., whether ISR has read 230 samples) > and if this is true, > functon inside the task1() is called and it writes > the > next 240samples > into the buffer. and this goes on... > > I don't understand what is the problem with my code. > looking forward.......... > > > . > . > . > .. > .. > /* Globals */ > short enable_write=1; > short * samples = (short*)0x00008000; > short wr_ptr=0,rd_ptr=0; > short input=0,flag; > > void task1(){ > short i; > > for(i=0;i<400;i++) > *(samples+i)=0; > > enable_write=1; > wr_ptr=0; > input=0; > > for(;;) { > > if(enable_write==1) { > enable_write=0; > > /* This function dumps 240 samples into a > circular buffer of > length 400. */ > call_func_to_dump_240samples(samples,&input,&wr_ptr); > flag =1; > > } > if( (wr_ptr - rd_ptr == 10) || ( rd_ptr - > wr_ptr == 390) { > enable_write=1; > } > } // for ever > } > > //------- ISR > ----------------------------------------- > > void McbspEventHandler(){ > int *DXR = (int *)0X018C0004; > > if(flag ==1){ > > *DXR = *(samples + rd_ptr); > rd_ptr++; > if(rd_ptr == 400) > rd_ptr = 0; > } > } > > --- praveen kumar <> > wrote: > > Hi, > > > > There could be some problem in the design itself. > > This is because as u go on giving the samples to > the > > serial port, the samples will be transmitted and > > then > > the interrupt is trigged.This will make the HWI to > > be > > allocated all the times right. > > > > What i came to know from ur explanation is that > > within this serial port isr again u are reading > next > > sample from the buffer and dumping it in to the > > serial > > port Right? > > > > The way the serial port is configred also matters > > here. > > First dump the samples into the buffer from the > task > > first and then give that buffer to the isr wherein > > that isr will take the sample and send it > > out(transmit).Only after the buffer of lenght 230 > is > > done then only an interrupt should be generated. > > Within that isr u should make use of some swi to > > handle it. WIthin the swi function call that > > function > === message truncated === ________________________________________________________________________ For live cricket scores download Yahoo! Score Tracker at: http://in.sports.yahoo.com/cricket/tracker.html |
|
BTW. You will get much more efficient transfers if you use DMA. Andrew E. At 03:48 PM 4/27/2002 +0100, praveen kumar wrote: >Hi simha, >go throught the below code: > >/* > Make use of a transmitter counter that will become >zero >*/ > >/*Below is the isr...*/ > >int txDone = 0,transmit_Cnt=0; >int sampleBuffer[240]; >int* sample; > >void Serial_isr(void) >{ > /* > The transmit_Cnt = 240 which is incremented in the >task that is the > size of the buffer u need to send > */ > if (transmit_Cnt) > { > *DXR = *samples++; > transmit_Cnt--; > if (transmit_Cnt == 0) > SEM_post(&WAIT); > } >} > >void tsk_fxn(void) >{ > while(1) > { > if ((txDone = SEM_pend(&WAIT)) == 1) > { > sample = &sampleBuffer; > >for(sample_count=0;sample_count<=240;sample_count++) > *sample++ = data/*Actual sample info*/ > transmit_Cnt = sample_count; > } > } >} > --- simha j <> wrote: > > > Hello praveen, > > > > > > Here is a portion of my code. please go through > > this. > > > > I have configured Mcbsp0 for external frame > > sync.(8khz) and external > > clock(2Mhz). and XINT mode is configured for 'New > > Frame'. ie., ISR > > gets executed every 125us. > > > > Serial Port Configuration is working fine. This, I > > checked by having > > only ISR in my program. ie., I placed > > 'call_func_to_dump_samples()' > > in the ISR itself and in this case, it returns only > > one sample to the > > ISR, instead of filling a buffer. > > But I don't want to place my function in the ISR. so > > I > > created a > > seperate task. > > My intention of this task is that , very first time > > it > > calls the > > function (when there is no serial port interrupt, > > bcoz > > it has higher priority than the task), without > > checking any condition and > > fills the buffer with 240 samples. so when the next > > time control hits > > the ISR, it checks whether there is a vaild data in > > the buffer (flag == 1) > > and if true it reads one data, increments read > > pointer(rd_ptr), checks > > whether it is 400 to wrap around and returns. > > Now, since there are no higher priority tasks for > > next > > 125us, control > > should come to task1() and checks whether the diff. > > between rd_ptr and > > wr_ptr is 10 (ie., whether ISR has read 230 samples) > > and if this is true, > > functon inside the task1() is called and it writes > > the > > next 240samples > > into the buffer. and this goes on... > > > > I don't understand what is the problem with my code. > > > > > > looking forward.......... > > > > > > > > > > . > > . > > . > > .. > > .. > > /* Globals */ > > short enable_write=1; > > short * samples = (short*)0x00008000; > > short wr_ptr=0,rd_ptr=0; > > short input=0,flag; > > > > void task1(){ > > > > > > short i; > > > > for(i=0;i<400;i++) > > *(samples+i)=0; > > > > enable_write=1; > > wr_ptr=0; > > input=0; > > > > for(;;) { > > > > if(enable_write==1) { > > enable_write=0; > > > > /* This function dumps 240 samples into a > > circular buffer of > > length 400. */ > > > > > > >call_func_to_dump_240samples(samples,&input,&wr_ptr); > > flag =1; > > > > } > > > > > > if( (wr_ptr - rd_ptr == 10) || ( rd_ptr - > > wr_ptr == 390) { > > enable_write=1; > > } > > } // for ever > > } > > > > > > > > //------- ISR > > ----------------------------------------- > > > > void McbspEventHandler(){ > > > > > > int *DXR = (int *)0X018C0004; > > > > if(flag ==1){ > > > > *DXR = *(samples + rd_ptr); > > rd_ptr++; > > if(rd_ptr == 400) > > rd_ptr = 0; > > } > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- praveen kumar <> > > wrote: > > > Hi, > > > > > > There could be some problem in the design itself. > > > This is because as u go on giving the samples to > > the > > > serial port, the samples will be transmitted and > > > then > > > the interrupt is trigged.This will make the HWI to > > > be > > > allocated all the times right. > > > > > > What i came to know from ur explanation is that > > > within this serial port isr again u are reading > > next > > > sample from the buffer and dumping it in to the > > > serial > > > port Right? > > > > > > The way the serial port is configred also matters > > > here. > > > First dump the samples into the buffer from the > > task > > > first and then give that buffer to the isr wherein > > > that isr will take the sample and send it > > > out(transmit).Only after the buffer of lenght 230 > > is > > > done then only an interrupt should be generated. > > > Within that isr u should make use of some swi to > > > handle it. WIthin the swi function call that > > > function > > >=== message truncated === > >________________________________________________________________________ >For live cricket scores download Yahoo! Score Tracker > at: http://in.sports.yahoo.com/cricket/tracker.html >_____________________________________ |