Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Is there any one can help provide the source code for RealTime scheduler in operating system, implemented in C++, Thanks. so appreciated.
Posted 17-Nov-12 16:07pm
Comments
Sergey Alexandrovich Kryukov at 17-Nov-12 22:23pm
   
Not really a question. If there is one, what this person should write to you? The implementation of the Scheduler, or what? --SA
Kevin Stlip at 17-Nov-12 22:34pm
   
yes i want to have a look at the source code of implementing of the RealTime Scheduler.
Sergey Alexandrovich Kryukov at 17-Nov-12 22:39pm
   
It does not make it a question... I used to write something like that, but it does not mean you can see that source code, sorry... --SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Perfectly valid question.
 
There are many RTOS-es available with source code in C
 
The problem is that if you are looking for bare bones one, it is hard to find as most will have TCP/IP implemented in the OS.
 
Here is a classic RTOS - XINU, the advantage being it has a great book explaining it step by step.
 
https://sites.google.com/site/avrxinu/the-team[^]
 
Here is the reschedule code from it as an example of what you get when you download it from the above link:
#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <q.h>
#include <inttypes.h>

extern void panic();
extern int insert();
extern int getlast();
extern void ctxsw();
char * getSP(void);
 
/*------------------------------------------------------------------------
 * resched  --  reschedule processor to highest priority ready process
 *
 * Notes:	Upon entry, currpid gives current process id.
 *		Proctab[currpid].pstate gives correct NEXT state for
 *			current process if other than PRREADY.
 *------------------------------------------------------------------------
 */
 
int resched(void)
{
	register struct	pentry volatile *optr;	/* pointer to old process entry */
	register struct	pentry volatile *nptr;	/* pointer to new process entry */
	int newpid;
 
	preempt = QUANTUM;		/* reset preemption counter	*/
 
	/* no switch needed if current process priority higher than next */
	
	if ( ( (optr= &proctab[currpid])->pstate == PRCURR) &&
             ( lastkey(rdytail) < optr->pprio) )	{
//		kprintf("resched: No Switch currpid=%d\n", currpid);
		return(OK);
	}
	
	/* force context switch */
	if (optr->pstate == PRCURR) {
		optr->pstate = PRREADY;
		insert(currpid,rdyhead,optr->pprio);
	}
 
	/* remove highest priority process at end of ready list */
	
	if ( (newpid = getlast(rdytail)) == EMPTY )
		return(EMPTY);
	
	nptr = &proctab[ ( currpid = newpid ) ];
	nptr->pstate = PRCURR;		/* mark it currently running	*/
//	kprintf("resched: Yes Switch currpid=%d\n", currpid);

	ctxsw(&optr->pregs[0],&nptr->pregs[0]);	/* switch context from old to new */
 
	return(OK);
}
 
/*
void dump_Stack(int pid)
{
    struct pentry *p;
    char *saddr;
    int j;
 
    p = &proctab[pid];
    if (pid == currpid)
	saddr = getSP()+8;
    else
	saddr = p->pSP;
    kprintf("\nProcess %d stack %p\n",pid,saddr);
    while ((unsigned)saddr < (unsigned)p->pbase)
    {
	j = *++saddr;
	kprintf("0X%02x\n",j&0xff);
    }
}
*/
 
char *getSP(void)
{
    char * mySP;
 
    asm volatile(
		 "in %A0, __SP_L__" "\n\t"
		 "in %B0, __SP_H__" "\n\t"
		 : "=d" (mySP)
		 :
		 );
 
    return (mySP+2);
}</inttypes.h></q.h></proc.h></kernel.h></conf.h>
 
1) It is an AVR port, but this is irrelevant
2) Any RTOS will have a small amount of assembler as you can see above
 
Enjoy
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 375
1 Abhinav S 333
2 OriginalGriff 330
3 sanket saxena 305
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,497
1 OriginalGriff 4,850
2 Peter Leow 3,839
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid