Jump to content
Sign in to follow this  
sdujolo

Novo Rtos

Recommended Posts

Hello I am trying the Novo RTOS and i have some problem I like to run some code only if I get someting on the serial port but I cant understand how to do it. Here is the code I trying.

 

#include <system.h>
#include <novocfg_pic18t3e5ts1.h>
#include <novo.h>
#include "serial.h"

#define hTask0 0
#define hTask1 1

#define hSemaphore 0

void interrupt( void )
{
char input;
// update system time every 4ms (actually is 204.8us x 20 = 4.096ms)
static BYTE intDivider;
if( ++intDivider == 20 )
{
	intDivider = 0;
	SysTimerUpdate();
}

// USART received interrupt flag, received a character
if (test_bit(pir1, RCIF) && test_bit(pie1,RCIE))
{		
	if (test_bit(rcsta,OERR))   // comms overrun error
	{
		//temp = rcreg; // read register to throw away, might need to do something else as well?
		clear_bit(rcsta,CREN);
		set_bit(rcsta,CREN);
	}
	else
	{	 
		input = rcreg;	// reads character

		SysSignalSemaphoreIsr( hSemaphore );
	} // else no comms error
} // if received char interrupt flag

intcon.TMR0IF = 0; //clear TMR0 overflow flag
}

void InitTimer()
{
// configure Timer0
t0con.TMR0ON = 1;	//enable timer
t0con.T08BIT = 1;	//set 8-bit mode
t0con.T0CS = 0;		// use internal clock
t0con.PSA = 0;		// use prescaler for timer 0	

// so we get an interrupt around every 204.8us with 40MHz Clock
// set pre-scaler to divide by 8
t0con.T0PS0 = 0;
t0con.T0PS1 = 1;  
t0con.T0PS2 = 0;

// enable interrupts
set_bit( intcon, TMR0IE ); //enable TMR0 overflow bit    
set_bit( intcon, GIE );
}

void InitIo()
{
trisb = 0x01; // leave bit 0 as input for bootloader

lata = 0;
adcon1 = 0x0F; // All ports as digital I/O (not analog I/O)
//cmcon = 0x07; // Comparator mode for PORTA off.
trisa = 0xFF; // PORTA as inputs
// Serial interface
serial_init(0x0A, 1);
serial_printf("Starting...\r\n");

}

void Task0()
{
while( 1 )
{	
	// when semaphore is signalled we flash the LED
	Sys_WaitSemaphore( hSemaphore, EVENT_NO_TIMEOUT );

	serial_printf("Task0\r\n");
	Sys_Yield();	
}
}

void Task1()
{
while( 1 )
{
	serial_printf("Task1\r\n");
	Sys_Sleep( 20 );
	Sys_Yield();
}
}

void main()
{	
InitTimer();
InitIo();

SysInit();
SysCreateTask( hTask0, 2, Task0 );
SysCreateTask( hTask1, 2, Task1 );

SysStartTask( hTask0 );
SysStartTask( hTask1 );

while( 1 )
{	
	Sys_Yield();
}
}

Share this post


Link to post
Share on other sites
Hello I am trying the Novo RTOS and i have some problem I like to run some code only if I get someting on the serial port but I cant understand how to do it. Here is the code I trying.

 

Please ammend the interrupt routine to prevent other sources of interrupt affecting sleep and wait timing:

void interrupt( void )
{
if( intcon.TMR0IF )
{
	static BYTE intDivider;
	// update system time every 1ms (actually is 204.8us x 5 = 1.024ms)
	if( ++intDivider == 5 )
	{
		intDivider = 0;
		SysTimerUpdate();
	}
	intcon.TMR0IF = 0; //clear TMR0 overflow flag
}
.....
}

I only used one source of interrupt TMR0, so did not need to check the source of interrupt.

 

You have an unecessary yield in your task:

void Task0()
{
   while( 1 )
   {    
       // when semaphore is signalled output a message to RS232
       Sys_WaitSemaphore( hSemaphore, EVENT_NO_TIMEOUT );
       serial_printf("Task0\r\n");
   }
}

Sys_WaitSemaphore itself yields.

 

Otherwise it look about right.

Regards

Dave

Share this post


Link to post
Share on other sites

sdujolo,

 

Also make sure that you have the -swcs (software call stack) command line switch for linker, otherwise it wont add the code and required software call stack for Tasks.

 

Regards

Dave

Share this post


Link to post
Share on other sites
sdujolo,

 

Also make sure that you have the -swcs (software call stack) command line switch for linker, otherwise it wont add the code and required software call stack for Tasks.

 

Regards

Dave

 

Thanks Dave :huh:

 

Regards /Jörgen

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...