Pumpkin, Inc.

Pumpkin User Forums

Context Switching (problems) and ICCAVR

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

Context Switching (problems) and ICCAVR

Postby Lo_Vaquero » Wed Sep 28, 2005 12:29 am

Is there anything that will prevent context switching from occuring in Slavo 3.2.2 Pro Source Code build using ICCAVR v7.01 and implementing on the ATMega2560?

I am trying to run a simple application that has 2 tasks that output a string through UART0. Each task outputs a 4 character string before the context switch and a 4 character string after so as to verify that the switch is occuring correctly.

I am using OS_Yield(label) to trigger the context switch.

For reasons that I cannot determine, the context switch (1) does not allow the task to resume where it left off [ie - in between printing strings] and (2) only one task ever runs.

Task B never runs and Task A never prints its second string after the context switch.

Here is the code:

code:
#include <iom2560v.h>
#include <macros.h>
#include <salvo.h>
#include <stdlib.h>

#define TASKA_P OSTCBP(1)
#define TASKB_P OSTCBP(2)

_OSLabel(TaskA1)
_OSLabel(TaskB1)

void TaskA( void );
void TaskB( void );

void InitPorts(void);
void InitUart0(void);
void InitDevices(void);

void UART_Transmit(unsigned char data);

void main( void )
{

// Initialize Salvo
InitDevices();
OSInit();

OSCreateTask(TaskA, TASKA_P, 10);
OSCreateTask(TaskB, TASKB_P, 10);

OSEi();

// Start Multitasking
for (; ;)
{
OSSched();
}

} /* main */

void InitDevices(void)
{
CLI(); //disable all interrupts
XMCRA = 0x00; //external memory
InitPorts(); // Setup MCU ports
InitUart0(); // Setup MCU UART0 for debug
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
SEI(); //re-enable interrupts

} /* InitDevices */

void InitPorts(void)
{

PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x00;
DDRC = 0xFF;
PORTD = 0x00;
DDRD = 0xFF;
PORTE = 0xF4;
DDRE = 0x0F;
PORTF = 0x00;
DDRF = 0xFF;
PORTG = 0x00;
DDRG = 0xFF;
PORTH = 0x00;
DDRH = 0xFF;
PORTJ = 0x00;
DDRJ = 0xFF;
PORTK = 0x00;
DDRL = 0x00;
PORTL = 0x0F;
DDRL = 0xFF;

} /* InitPort */

void InitUart0(void)
{

UCSR0B = 0x00;
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x33; //set baud rate lo @16MHz
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x98; //enable

} /* InitUart0 */

void UART_Transmit(unsigned char data)
{
while( !(UCSR0A & (1<<UDRE0)))
{
;
}
UDR0 = data;
} /* UART_Transmit */

unsigned char APreCS[6] = "A1
";
unsigned char APostCS[6] = "A2
";
void TaskA( void )
{
unsigned int j;
for (; ;)
{
for(j = 0; j <= 5; j++)
{
UART_Transmit(APreCS[j]);
}
OS_Yield(TaskA1);
for(j = 0; j <= 5; j++)
{
UART_Transmit(APostCS[j]);
}
}
}

unsigned char BPreCS[6] = "B1
";
unsigned char BPostCS[6] = "B2
";
void TaskB( void )
{
unsigned int j;
for (; ;)
{
for(j = 0; j <= 5; j++)
{
UART_Transmit(BPreCS[j]);
}
OS_Yield(TaskB1);
for(j = 0; j <= 5; j++)
{
UART_Transmit(BPostCS[j]);
}
}
}


Here is the slavocfg.h file (its a source code build):

code:
#define OSBYTES_OF_DELAYS       2
#define OSBYTES_OF_TICKS 2
#define OSENABLE_IDLING_HOOK TRUE
#define OSEVENTS 1
#define OSTASKS 4


[This message has been edited by Lo_Vaquero (edited September 28, 2005).]

Lo_Vaquero
 
Posts: 9
Joined: Tue Sep 27, 2005 11:00 pm

Re: Context Switching (problems) and ICCAVR

Postby aek » Wed Sep 28, 2005 2:50 am

Hmmm ... your code looks fine.

The behavior you describe suggests that the context switch itself simply fails ...

Have you applied the v3.2.4-d patch described from the download area. Go ahead and download v3.2.4 and then apply the patch -- it addressed a particular context-switching issue that might be the root of your problem.

In general, I would approach this problem thusly -- strip out all of the external function calls, and run a "pure" Salvo application in the AVRStudio simulator. It should work without problems. If, even then, it doesn't work, then it's time to send it in to support and we'll figure it out.

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

Re: Context Switching (problems) and ICCAVR

Postby Lo_Vaquero » Wed Sep 28, 2005 3:15 am

aek -

Thanks for the reply.

I have tried this with both the original install of 3.2.4-a and with the 3.2.4-d patch. The result is the same with both.

This problem is actually just a precursor to a larger one that I emailed support about, so I will work through that route.

Lo_Vaquero
 
Posts: 9
Joined: Tue Sep 27, 2005 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 3 guests

cron