Sarah Marsh / Mbed 2 deprecated Test_Serial_Api_Interrupt

Dependencies:   mbed

Fork of Test_Serial_Api_Interrupt by Jens Altenburg

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003  
00004 //#define nSerialPatch    /* compiler switch for workaround */
00005  
00006 DigitalOut myled(LED1);
00007  
00008 Serial     stComX(USBTX,USBRX);/*
00009 * Description :  UART communicatin (Txd(D1)/Rxd(D0)) USART2 to serial PC COM-Port  
00010 */
00011  
00012 unsigned char  bSizeData; /*
00013 * Description : number of transmission data
00014 */
00015  
00016 unsigned char *pUartData; /*
00017 * Description : pointer to data
00018 */
00019  
00020 unsigned char abString[] = "Hello World!\n\r"; /*
00021 * Description : test string
00022 */
00023 
00024 void vIsrTxComX(void);
00025  
00026 /* new data to UART */
00027 unsigned char SYS_vStartComX( unsigned char *pData, unsigned char bSize ){    /* new data to UART */
00028     unsigned char i;
00029     if(bSizeData) i = 0; 
00030     else{
00031         bSizeData = bSize;                                  /* number of transmission data */
00032         pUartData = pData;                      
00033         //Attach TX Interrupt
00034         stComX.attach(&vIsrTxComX, Serial::TxIrq);
00035         i = 1;
00036         }
00037     return i;
00038     }
00039  
00040 /* TX ISR */
00041 void vIsrTxComX( void ){                       
00042     if(stComX.writeable()){                                 /* check stComX */
00043         if(bSizeData){                                      /* further data available */
00044             stComX.putc(*pUartData);                        /* next data */
00045             pUartData++;
00046             bSizeData--;
00047             }
00048         else{
00049             //Detach TX interrupt, nothing left to send
00050             stComX.attach(NULL, Serial::TxIrq);               /* disable TXE interrupt */
00051             }
00052         }
00053     }
00054     
00055 /* RX ISR */
00056 void vIsrRxComX( void ){                        
00057     volatile unsigned char i;
00058     if(stComX.readable()){                                  /* check stComX */
00059         i = (unsigned char)stComX.getc();
00060         if(i == 'n'){
00061             SYS_vStartComX( abString, sizeof(abString)-1);
00062             }
00063         }
00064     }
00065  
00066 int main() {
00067 /*  establish serial interrupts */
00068     stComX.attach(&vIsrRxComX, Serial::RxIrq); 
00069  
00070 /* endless loop */
00071     while(1) {
00072         myled = 1;
00073         wait(0.2);
00074         myled = 0;
00075         wait(0.2);
00076     }
00077 }