uart_int.c

Go to the documentation of this file.
00001 
00053 #include <includes.h>
00054 
00055 #define INT_RLS   3
00056 #define INT_RDA   2
00057 #define INT_CTI   5
00058 #define INT_THRE  1
00059 
00060 static char uarti_str[100];
00061 static int uarti_strlen = 0;
00062 
00063 static char * uarti_out_buf;
00064 static volatile int uarti_out_next_idx = 0;
00065 static volatile int uarti_out_len = 0;
00066 static volatile int uarti_out_stall = 1;
00067 static UARTI_CALLBACK_PTR uarti_out_callback;
00068 
00069 void uarti_tx_set_empty_callback(UARTI_CALLBACK_PTR callback){
00070     uarti_out_callback = callback;
00071 }
00072 
00073 int uarti_tx_buf(char * buf, int buflen){
00074   if(uarti_out_next_idx < uarti_out_len){
00075     //Then the prior string has not been fully transmitted.
00076     //The current design would have to be reworked a bit to allow aborting the previous transfer
00077     //and beginning a new one.
00078     return 1;
00079   } else {
00080     uarti_out_buf = buf;
00081     uarti_out_len = buflen;
00082     uarti_out_next_idx = 0;
00083     if(uarti_out_stall) {
00084       uarti_tx_refill();
00085     }
00086     return 0;
00087   }
00088 }
00089 
00090 void uarti_tx_refill(void){
00091   if(uarti_out_next_idx >= uarti_out_len) {
00092     //String finished. Do callback for (optional) refill
00093     if(uarti_out_callback != 0){
00094       uarti_out_callback();
00095     }
00096   }
00097   if(uarti_out_next_idx < uarti_out_len) {
00098     U0THR = uarti_out_buf[uarti_out_next_idx];
00099     uarti_out_next_idx += 1;
00100     uarti_out_stall = 0;
00101   } else {
00102     uarti_out_stall = 1;
00103   }
00104     
00105 }
00106 
00107 __irq void uarti_isr(void){
00108   int iir;
00109   volatile int lsr; //remove volatile later, just to quash warning temporarily
00110   
00111   iir = U0IIR;
00112   lsr = U0LSR;
00113   
00114   if(!(iir&1)){//Interrupt pending bit
00115     switch((iir>>1)&0x7){ //U0IIR 3:1, Interrupt Identification
00116       case INT_RLS: //Receive Line Status
00117         //Respond to rx interrupt as given by the Line Status Register
00118         break;
00119       case INT_RDA: //Receive Data Available
00120         break;
00121       case INT_CTI: //Character Time-Out Indicator
00122         break;
00123       case INT_THRE://THRE Interrupt
00124         uarti_tx_refill();
00125         break;
00126       default:
00127         //should never reach here
00128         break;
00129     }
00130   } else {
00131     //No interrupt is pending
00132   }
00133   //TODO: clear tx interrupt flag(s)
00134   VICVectAddr = 0;
00135 }
00136 
00137 void uarti_print_int2(int i1, int i2){
00138   uarti_strlen = sprintf(uarti_str,"%i\t%i\n\r",i1, i2);
00139   uarti_tx_buf(uarti_str, uarti_strlen);
00140 }
00141 
00142 void uarti_print_int(int i){
00143   uarti_strlen = sprintf(uarti_str,"%i\n\r",i);
00144   uarti_tx_buf(uarti_str, uarti_strlen);
00145 }
00146 
00147 void uarti_print_float(float f){
00148   uarti_strlen = sprintf(uarti_str,"%2.15f\n\r",f);
00149   uarti_tx_buf(uarti_str, uarti_strlen);
00150 }
00151 
00152 void uarti_print_2float(float f1, float f2){
00153   uarti_strlen = sprintf(uarti_str,"%f\t%f\n\r",f1,f2);
00154   uarti_tx_buf(uarti_str, uarti_strlen);
00155 }
00156 
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3