Segger Logo Embedded Software Solutions
Software productsHardware productsDownloadsPricesCustomersOur PartnersSitemapForumAbout us
embOS: Sample program for interrupt driven serial communication
| General Info | Supported CPUs | Frame Program | Sample Program | Context switiching time | Interrupt latency | embOS Simulation | embOS IAR Plugin |

Sample program for interrupt driven serial transmission in multitasking environment. It can be used without change in real applications on any 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); }

Copyright SEGGER Microcontroller GmbH & Co.KG. All rights reserved.
For more information, please visit our web site www.segger.com or contact us at info@segger.com
Last update: December 7, 2007