Joaquin Verastegui / jro

Dependents:   JRO_CR2 frdm_test

Fork of jro by Miguel Urco

JroSerial.cpp

Committer:
miguelcordero191
Date:
2015-02-05
Revision:
2:3d8d52e9751c

File content as of revision 2:3d8d52e9751c:

#include "JroSerial.h"

JroSerial::JroSerial(PinName tx, PinName rx, SerialDriver *screen) : SerialDriver(tx,rx)
{
    //;
    this->device_irqn = UART3_RX_TX_IRQn;
    this->screen = screen;
    // attach the interrupts
}

int JroSerial::Init(int baudrate)
{
    this->baud(baudrate);
    //this->screen->baud(baudrate);
    
    //attach(this, &JroSerial::Rx_interrupt, RxIrq);
    //NVIC_DisableIRQ(this->device_irqn);
    //disableRxInterrupt();
    
    return 1;
}


// This function is called when a character goes into the RX buffer.

void JroSerial::Rx_interrupt() {
    
    disableRxInterrupt();
    //NVIC_DisableIRQ(this->device_irqn);
    //uart.attach(NULL, Serial::RxIrq);
    //uint32_t IRR3 = UART3->IIR;
    //UART_3_RBR = K64F_UART3->RBR;
    
    //ser_thread_ptr->signal_set(0x01);
    //this->rx_sem.release();
    return;
}
int JroSerial::ReadData(char* rx_buffer)
{
    int tmp;
    unsigned short i=0;
    unsigned short time_counter=0;
    
    //NVIC_EnableIRQ(this->device_irqn);
    //enableRxInterrupt();
    this->screen->putc(0x34);
    this->screen->putc(0x31);
    //this->rx_sem.wait();
    this->screen->putc(0x34);
    this->screen->putc(0x32);
    while(true){
        /*
        if(this->readable()==0){
            time_counter++;
            if (time_counter > 3)
                break;
            Thread::wait(300);
            continue;
        }
        */
        
        tmp = this->getc(200);
        if (tmp == -1)
            break;
        
        rx_buffer[i] = (unsigned char) tmp;
        
        //Don't delete the next line screen.putc();
        this->screen->putc(0x34);
        this->screen->putc(0x33);
        this->screen->putc(rx_buffer[i]);
        
        i++;
        time_counter = 0;
    }
    
    this->putc(i);
    
    this->screen->putc(0x34);
    this->screen->putc(0x34);
    
    if (i==0x28){
        this->putc(0x37);
        this->putc(0x37);
    }
    this->putc(0x10);
    this->putc(0x13);
    
    return i;
}