Pumpkin, Inc.

Pumpkin User Forums

OS_waitbinsem not context_switch

If you can't make Salvo do what you want it to do, post it here.

OS_waitbinsem not context_switch

Postby memorymem » Tue Dec 22, 2009 4:48 am

My program time slice is set to 2ms, the following procedure for the task only in the high priority both in the switch, but can not enter into the following two tasks, and why?
my salvocfg.h is:

code:
#define OSCOMPILER 					OSHT_PICC
#define OSTARGET OSPIC16

#define OSBYTES_OF_DELAYS 2 //¶¨ÒådelayΪ16λ

#define OSTASKS 4
#define OSEVENTS 2
#define OSENABLE_BINARY_SEMAPHORES TRUE
#define OSLOC_ECB bank2
#define OSLOC_TCB bank1

#include <pic.h>
#include <salvo.h>
#include "DS1302.c"
#include "LCD1602.c"
#include "I2C.c"

#define _PIC16F887_EXTCLK

#ifdef _PIC16F887_INTCLK
//ÄÚ²¿Õñµ´8MHz
__CONFIG(WDTDIS & INTIO & BOREN & LVPDIS & PWRTEN & UNPROTECT &
MCLREN & BORV40 & FCMEN ); //PIC16F887ÄÚ²¿¾§Õñ²»Êä³ö
#endif

#ifdef _PIC16F887_EXTCLK
// XT=4Mhz
__CONFIG(WDTDIS & XT & BOREN & LVPDIS & PWRTEN & UNPROTECT &
MCLREN & BORV40 & FCMEN ); //PIC16F887ÍⲿXT
#endif

#ifdef _PIC16F877A
__CONFIG(WDTDIS & XT & BOREN & LVPDIS & PWRTEN & UNPROTECT); //PIC16F877(A)
#endif

#define TASK_DS1302_P OSTCBP(1) /* task #1 */
#define TASK_DISPLCD_P OSTCBP(2) /* task #2 */
#define TASK_KEY_P OSTCBP(3) /* task #3 */
#define TASK_CHANGE_TIME_P OSTCBP(4) /* task #4 */

#define PRIO_DS1302 1 /* ʱÖÓÓÅÏȼ¶*/
#define PRIO_DISPLCD 2 /*Òº¾§ÏÔʾÓÅÏȼ¶*/
#define PRIO_KEY 3 /*°´¼ü¼üÅÌÓÅÏȼ¶*/
#define PRIO_CHANGE_TIME 4 /*ÐÞ¸Äʱ¼äÓÅÏȼ¶*/


#define BINSEM_DISP_LCD OSECBP(1) //¶¨ÒåÏÔʾ binsem
#define BINSEM_CHANGE_DS1302 OSECBP(2) /* binsem #1 */
//#define BINMSG_KEYVALUE OSECBP(3) //¶¨ÒåÏûϢʼþbinmeg

_OSLabel(TaskDs13021)
_OSLabel(TaskDisplcd1)
_OSLabel(TaskDisplcd2)
_OSLabel(TaskKey1)
_OSLabel(TaskKey2)
_OSLabel(TaskChangeTime1)
_OSLabel(TaskChangeTime2)
_OSLabel(TaskChangeTime3)

//===================================================================
//¶¨Òå²ÎÊý¡¢

SYSTEMTIME CurrentTime;
unsigned char Write_Clock[8];
unsigned char Clock_Input[13];
static unsigned char keyvalue=0,keyfunction=0xff;

//===================================================================
//ÑÓʱ×Ó³ÌÐò
void delayus(unsigned char us_count) //ÑÓʱus
{
while(us_count--)
{
NOP();
// NOP();
}
}

void delayms(unsigned char cnt) //ÑÓʱms
{
unsigned char ms_count;
do {
ms_count = 4;
do {
delayus(250);
} while(--ms_count);
} while(--cnt);
}

void delays(unsigned int cnt) //ÑÓʱs
{
unsigned char s_count;
do {
s_count = 4;
do {
delayms(250);
} while(--s_count);
} while(--cnt);
}

//===================================================================
//ÆÕͨ-³ÌÐò¶Î
void Init_Timer0(void)
{
T0CS=0; //TIMER0Ñ¡ÔñÄÚ²¿Ê±ÖÓ
PSA=0; //8λԤ·ÖƵÆ÷¸øTimer0,WDTû·ÖÅäÔ¤·ÖƵÆ÷
PS2=0; //Timer0Ô¤·ÖƵ±ÈΪ1£º32=100;Ô¤·ÖƵ±ÈΪ1£º16=011
PS1=1; //Ô¤·ÖƵ±ÈΪ1£º64=101£¬Ô¤·ÖƵ±ÈΪ1£º128=110
PS0=1;
TMR0=131; //±¶ÂÊΪ4000£¬TMR0=131£»±¶ÂÊΪ8000,TMR0=6.
T0IE=1;
}


//===================================================================
//ʱ¼ä»ù×¼-ÖÜÆÚÐÔÖжÏ
#pragma interrupt_level 0
void interrupt isr(void) //TIMER0Éè¼ÆΪ2mSÖжÏÖÜÆÚ,ƵÂÊΪ8MHZ
{
if(T0IF)
{
T0IF = 0;
TMR0 -=125;
OSTimer();
}
}

//===================================================================
//¸÷¸öÈÎÎñ-³ÌÐò¶Î

void TaskDs1302( void )
{
Initial_DS1302();
for (; ;)
{
BurstRead1302(Write_Clock);
BurstConvert(&CurrentTime);
DateToStr(&CurrentTime);
TimeToStr(&CurrentTime);
//OSSignalBinSem(BINSEM_DISP_LCD);
OS_Delay(400,TaskDs13021); //ÑÓʱ800ms
}
}

void TaskDisplcd( void )
{
Init_lcd();
for (; ;)
{
OS_WaitBinSem(BINSEM_DISP_LCD,OSNO_TIMEOUT,TaskDisplcd1);

display_str(0,4,(&CurrentTime)->TimeString[0]);
display_str(0,5,(&CurrentTime)->TimeString[1]);
display_str(0,6,(&CurrentTime)->TimeString[2]);
display_str(0,7,(&CurrentTime)->TimeString[3]);
display_str(0,8,(&CurrentTime)->TimeString[4]);
display_str(0,9,(&CurrentTime)->TimeString[5]);
display_str(0,10,(&CurrentTime)->TimeString[6]);
display_str(0,11,(&CurrentTime)->TimeString[7]);

display_str(1,2,'2');
display_str(1,3,'0');

display_str(1,4,(&CurrentTime)->DateString[0]);
display_str(1,5,(&CurrentTime)->DateString[1]);
display_str(1,6,(&CurrentTime)->DateString[2]);
display_str(1,7,(&CurrentTime)->DateString[3]);
display_str(1,8,(&CurrentTime)->DateString[4]);
display_str(1,9,(&CurrentTime)->DateString[5]);
display_str(1,10,(&CurrentTime)->DateString[6]);
display_str(1,11,(&CurrentTime)->DateString[7]);
display_str(1,12,(&CurrentTime)->DateString[8]);
display_str(1,14,(&CurrentTime)->DateString[9]);
OSSignalBinSem(BINSEM_DISP_LCD);
OS_Delay(150,TaskDisplcd2);
}
}

void TaskKey( void )
{
for (; ;)
{
OS_WaitBinSem(BINSEM_DISP_LCD,OSNO_TIMEOUT,TaskKey1);
//OS_Delay(20,TaskKey1);
write_inst(0x0f); //¹â±êÉÁ˸
write_inst(0x83);
//delays(10);
//*
if(INTF)
{
INTF=0;
keyvalue=0;
keyvalue=read_zlg7290_keyvalue(); //¶ÁÆÕͨ°´¼üÖµ
if(keyvalue !=0) //²»ÊǸ´Î»Öµ00H£¬ÔòÊÇÓÐЧֵ
{
switch(keyvalue)
{
case 1: //Êý×Ö1
keyvalue=1;
break;
case 2: //Êý×Ö2
keyvalue=2;
break;
case 3: //Êý×Ö3
keyvalue=3;
break;
case 9: //Êý×Ö4
keyvalue=4;
break;
case 10: //Êý×Ö5
keyvalue=5;
break;
case 11: //Êý×Ö6
keyvalue=6;
break;
case 17: //Êý×Ö7
keyvalue=7;
break;
case 18: //Êý×Ö8
keyvalue=8;
break;
case 19: //Êý×Ö9
keyvalue=9;
break;
case 12: //Êý×Ö0
keyvalue=0;
break;


case 4: //¿Õ¸ñ

break;

case 5: //¡û¼ü

break;
case 6: //¡ú¼ü

break;
case 13: //¡ü¼ü

break;
case 14: //¡ý¼ü

break;

case 7: //ÐÞ¸Äʱ¼äÃüÁî
OSSignalBinSem(BINSEM_CHANGE_DS1302);
break;
case 22: //Ð޸IJÎÊý

break;

case 8: //Ë¢ÐÂÃüÁî

break;

case 24: //È·Èϼü

break;

case 16: //ESC

break;

case 20: //䶨Òå

break;

case 21: //²âÊÔ¼ü£¨Í¬Ê±ÊÇÄÚ²¿ÐźźÍÍⲿÐźÅÇл»¼ü£©

break;
case 23: //¿ª»ú¼ü

break;
case 15: //½øÈë´ý»ú״̬

break;

default:
break;
}

}
keyfunction =0xff;
keyfunction=read_zlg7290_function(); //¶Á¹¦ÄܼüµÄÖµ
if(keyfunction !=0xff) //²»ÊǸ´Î»Öµ0xFFH,ÔòÊÇÓÐЧֵ
{
break;
}
}//*/
OSSignalBinSem(BINSEM_DISP_LCD);
OS_Delay(20,TaskKey2);
}
}

void TaskChangeTime(void)
{
//OStypeMsgP msgp;
for(; ;)
{
OS_WaitBinSem(BINSEM_CHANGE_DS1302, OSNO_TIMEOUT ,TaskChangeTime2);
OS_WaitBinSem(BINSEM_DISP_LCD, OSNO_TIMEOUT, TaskChangeTime1);
OSDi(); //¹ØÖжϣ¬Ò²¹Øʱ¼äÖжÏ
OSSetPrio(1);
write_inst(0x84); //¹â±êλÖÃÉ趨
write_inst(0x0f); //¹â±êÉÁ˸
// write_inst(0x01); //ÇåÆÁ
OSEi(); //¿ªÖжÏ
OSSetPrio(PRIO_CHANGE_TIME);
OSSignalBinSem(BINSEM_DISP_LCD);
OS_Delay(200,TaskChangeTime3);
// OS_Yield(TaskChangeTime1);
}
}

void Init_Intclk(void)
{
IRCF2=1; //ÄÚ²¿Õñµ´Æ÷ƵÂÊÑ¡Ôñ£¬111=8M£¬110=4M£¨Ä¬ÈÏ£©,101=2M
IRCF1=1;
IRCF0=0;
SCS=1; //ϵͳʱÖÓÑ¡Ôñ£¬²ÉÓÃÄÚ²¿Ê±ÖÓ
}

int main( void )
{
#ifdef _PIC16F887_INTCLK
Init_Intclk();
#endif
Init_Timer0();
GIE = 1, PEIE = 1; //ENABLE GLOBAL & PERIPHERAL INTERRUPTS
OSEi();

OSInit();

//½¨Á¢ÈÎÎñ
OSCreateTask(TaskDs1302, TASK_DS1302_P, PRIO_DS1302);
OSCreateTask(TaskDisplcd, TASK_DISPLCD_P, PRIO_DISPLCD);
OSCreateTask(TaskKey, TASK_KEY_P, PRIO_KEY);
OSCreateTask(TaskChangeTime, TASK_CHANGE_TIME_P, PRIO_CHANGE_TIME );

//½¨Á¢¶þ½øÖÆÐźÅÁ¿
OSCreateBinSem(BINSEM_DISP_LCD,1); //Òº¾§ÏÔʾbinsem³õֵΪ0
OSCreateBinSem(BINSEM_CHANGE_DS1302, 0);

//½¨Á¢¶þ½øÖÆÏûÏ¢

// OSCreateMsg(BINMSG_KEYVALUE,(OStypeMsgP) 0);

//Ö÷Ñ­»·³ÌÐò
for (; ;)
// {#include "sched.c"}
OSSched();
}



Requests for help, thank you!

[This message has been edited by aek (edited December 22, 2009).]

memorymem
 
Posts: 3
Joined: Tue May 26, 2009 11:00 pm

Re: OS_waitbinsem not context_switch

Postby aek » Tue Dec 22, 2009 10:20 am

Sorry, I do not quite follow the problem.

A few observations:

1) It doesn't make sense to change a task's priority if you don't have a context switch nearby ... the priority only has an effect after you context switch, since Salvo is cooperative, not preemptive. So, OSSetPrio(1); isn;t doing anything for you.

2) All of your tasks are delayed, and some are also waiting a resource (lock) -- it's quite possible that dynamically, the higher-priority tasks are always the ones that are ready and waiting for the resource once it is released, and so only they appear to run. IOW, i suspect your problem is a runtime side-effect of your task priorities vs. your delays, etc.

3) 2ms is a little short for an 8MHz clock -- we recommend 10ms for a 4MHz clock.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_waitbinsem not context_switch

Postby memorymem » Wed Dec 23, 2009 5:51 am

Thank you for aek.

I am a novice, new to Salvo, has no experience. Corresponding to 1) and 3), I take notice. thanks! For 2), I am more confused that is the priority of the task set and the time delay problem, do not know if there is no experience to draw on.

My program aims to: TaskDs1230 about 800ms read once; Task_Displcd is a liquid crystal display, normal display time,and need other tasks, such as Task_changtime, in order to achieve the clock changes; and Task_Key yes keyboard task, receiving keyboard commands. Since then, I also added to the ADC operation, the operation of the PWM, as well as external count. Hope, aek give me some help or advice. Thanks!
In addition, the task of modifying TaskChangeTime time or other parameters, needs to receive the value of buttons and LCD display to change the situation, but the task TaskDisplcd not affect the change LCD interface, I need to arrange how the procedures and tasks?

[This message has been edited by memorymem (edited December 23, 2009).]

memorymem
 
Posts: 3
Joined: Tue May 26, 2009 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron