?? basictest4.c
字號(hào):
#include "hardware.inc"
#define ENABLE_BIT_DEFINITIONS
#define _SFR_ASM_COMPAT 1
#include <avrx-io.h>
#include <avrx-signal.h>
#include "avrx.h"
/*
Basic Tasking Tests #4
Exercises Message API
The following API covered:
AvrXSendMessage
AvrXRecvMessage
AvrXWaitMessage
AvrXAckMessage
AvrXTestMessageAck
AvrXWaitMessageAck
To run: Step through Task 1. Set break points on each of the "AvrXAckMessage()"
calls and in the _Overflow0_ routine and run through making sure each is called.
The sequence is not important as long as all four get called regularly.
Alternatively run this on hardware and check the bits on PortB that are toggled
with each sucessfull run.
*/
#define TCNT0_INIT (0xFF-CPUCLK/256/TICKRATE)
#define TMC8_CK256 (1<<CS02)
/*
One group of task def's will be dropped depending upon which
compiler is being used.
*/
AVRX_GCC_TASK(task1, 20, 3);
AVRX_GCC_TASK(task2, 20, 2);
AVRX_GCC_TASK(task3, 20, 2);
AVRX_IAR_TASK(task1, 14, 6, 3);
AVRX_IAR_TASK(task2, 14, 6, 2);
AVRX_IAR_TASK(task3, 14, 6, 2);
Mutex Sync2, Sync3; // Synchronization semaphores between task1 and 2&3
MessageControlBlock Message1, Message2, Message3;
MessageQueue TestQueue;
AVRX_SIGINT(SIG_OVERFLOW0)
{
IntProlog();
outp(TCNT0_INIT, TCNT0);
// This relies on us "priming the queue" in the main task
if (AvrXTestMessageAck(&Message1) == SEM_DONE)
AvrXIntSendMessage(&TestQueue, &Message1);
Epilog();
}
void main(void)
{
AvrXSetKernelStack(0);
AvrXRunTask(&task1Tcb);
Epilog(); // Switch from AvrX Stack to first task
}
NAKEDFUNC(task1)
{
outp(0xFF, DDRB);
outp(0xFF, PORTB);
// Verify initial condition of empty
if (AvrXRecvMessage(&TestQueue) != NOMESSAGE)
AvrXHalt();
// Send and receive a message
AvrXSendMessage(&TestQueue, &Message1);
if (AvrXRecvMessage(&TestQueue) != &Message1)
AvrXHalt();
// Check to see that queue is empty
if (AvrXRecvMessage(&TestQueue) != NOMESSAGE)
AvrXHalt();
// Acknowledge the message
AvrXAckMessage(&Message1);
if (AvrXTestMessageAck(&Message1) != SEM_DONE)
AvrXHalt();
// Queue up two messages
AvrXSendMessage(&TestQueue, &Message1);
AvrXSendMessage(&TestQueue, &Message2);
if (AvrXWaitMessage(&TestQueue) != &Message1)
AvrXHalt();
AvrXAckMessage(&Message1);
AvrXWaitMessageAck(&Message1);
AvrXWaitMessage(&TestQueue);
// Funky test to verify message queue is empty
if ((unsigned)TestQueue.message || (unsigned)TestQueue.pid)
AvrXHalt();
// Ok, basic static queue mechanism checked out. Now for
// some dynamic stuff.
// Task2 and Task3 jam messages onto the queue. Task 1
// runs low priority flushing the queue.
AvrXRunTask(&task2Tcb);
AvrXRunTask(&task3Tcb);
outp(TCNT0_INIT, TCNT0);
outp(TMC8_CK256 , TCCR0);
outp((1<<TOIE0), TIMSK); // Enable Timer overflow interrupt
AvrXIntSendMessage(&TestQueue, &Message1); //Prime the interrupt queue
while(1)
{
pMessageControlBlock msg;
msg = AvrXWaitMessage(&TestQueue);
AvrXAckMessage(msg);
if ((msg = AvrXRecvMessage(&TestQueue)) != NOMESSAGE)
{
AvrXAckMessage(msg);
outp(inp(PORTB) ^ 1, PORTB); // Toggle bits
}
}
}
NAKEDFUNC(task2)
{
while(1)
{
AvrXSendMessage(&TestQueue, &Message2);
AvrXWaitMessageAck(&Message2);
outp(inp(PORTB) ^ 2, PORTB); // Toggle bits
}
}
NAKEDFUNC(task3)
{
while(1)
{
AvrXSendMessage(&TestQueue, &Message3);
AvrXWaitMessageAck(&Message3);
outp(inp(PORTB) ^ 4, PORTB); // Toggle bits
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -