サンプルプログラム

マルチタスク環境での割り込み方式シリアル通信のサンプルプログラムです。このままあらゆるCPU上でご利用いただけます。

/*
SEROUT.C

Interrupt driven serial communication with embOS real time operating system
Sample program that can be used without changes in applications

Needs definitions similar to the following in MAIN.H :

#define INTHANDLERST interrupt [0] void IntHandlerSR(void)
#define _WriteSIO(c) U0TB = c;

Declares the following functions for other modules :

void SEROUT_Write(char c);
void SEROUT_Init(void);
*/

#include "MAIN.H" // include file for all modules, incl. RTOS.H
#include "HWDEF.H" // include for hardware definitions

#ifndef SIZEOF_SO
#define SIZEOF_SO (50)
#endif

MAILBOX MBSO; // Mailbox for transmission

char BufferSO[SIZEOF_SO];
char Sending;

//
// Defines the interrupt routine for serial transmission.
// Basic operation is as follows :
// If there is one character in Buffer it is send
// Otherwise the global variable Sending is cleared
//

INTHANDLERST
{
char c;
EnterInterrupt();
if (!GetMailCond1(&MBSO, &c)) {
_WriteSIO(c);
} else
Sending =0;
LeaveInterrupt();
}

//
// Writes one character to the SIO
// Basic operation is as follows :
//
// If transmission already in progress, put character in buffer
// Where the interrupt routine will get it
// Otherwise set global variable Sending and write into register
//

void SEROUT_Write(char c) {
SDI(); // disable interrupts
if (Sending)
PutMail1(&MBSO, &c);
else {
Sending =1;
_WriteSIO(c);
}
RI(); // restore former status of IE-flag
}

void SEROUT_Init(void) {
CREATEMB(&MBSO, 1, SIZEOF_SO, &BufferSO);
}


サンプルプログラム関連ページ 
SEGGER
RTOS&Middleware