Esempio n. 1
0
int main(void) {
    char c;

    INTCON1bits.NSTDIS = 1;
    openQEI();
    OpenUART();
//    openPWM();
//    InitTMR2();

    Clock_Init();
//    enablePWM;
//    ch1Run;
//    ch2Run;

    initInterpreter();
    initOdometrie();
    initAsservissement();
    initPIDs();

    while(1)
    {
        c = (char)ReadUART1();

        if(buildCommande())
        {
            interpreteCommande();
            clearCommande();
        }
    }

    return 0;
}
Esempio n. 2
0
// UART1 RX ISR
void __attribute__ ((interrupt,no_auto_psv)) _U1RXInterrupt(void)
{
    char c;
    
    // Clear the interrupt status of UART1 RX
    U1RX_Clear_Intr_Status_Bit;

    // Get the character from the GSM UART
    c = gsmRead();

    // If a character comes in from the GSM module...
    if (c)
    {    
        while(BusyUART3());
        WriteUART3((unsigned int)c);      // Print the incoming character to USB UART

        // Clear out any garbage characters
        while(DataRdyUART1())
            ReadUART1();
    }

    // Detect if GSM antenna is ready
    if(newSINDreceived() && gsmReady()) {
//        gsmCall(HOME_NUMBER);
//        gsmText(HOME_NUMBER, "Hey Matt!");
//
//MS: add parser
    }
}
Esempio n. 3
0
void _ISR_PSV _U1RXInterrupt(void)	// UART RX [6b]
{   __builtin_disi(0x3FFF); //disable interrupts up to priority 6 for n cycles
    InterruptTest7++;
    _U1RXIF = 0; 	// interrupt flag reset
    ClrWdt();		// [1]
    unsigned char DatoRx;
    DatoRx = ReadUART1();
    if(StatoSeriale[PORT_COM1] == WAIT_MESSAGE)
    {   //  time-out dei dati in ricezione non sia scaduto, altrimenti
        if (!TimerOutRxModbus[PORT_COM1])
        {   FreeRxBuffer(PORT_COM1);
        }
        TimerOutRxModbus[PORT_COM1] = TIME_OUT_MODBUS;
        *RxPointer[PORT_COM1] = DatoRx; //  Salva nel buffer il dato ricevuto
        RxPointer[PORT_COM1]++;
        RxNByte[PORT_COM1]++;
        if (RxNByte[PORT_COM1] >= MODBUS_N_BYTE_RX)     //  se ricevuti più caratteri della lunghezza del buffer
        {   RxPointer[PORT_COM1] = ModbusRxBuff[PORT_COM1]; //  azzera il puntatore di ricezione
            RxNByte[PORT_COM1] = 0;                 //  e il numero di byte ricevuti
        }
    }

    InterruptTest7--;
    DISICNT = 0; //re-enable interrupts
}
Esempio n. 4
0
void __attribute__((interrupt, auto_psv)) _U1RXInterrupt  (void)
{
    ledr = ledr^1;
    ReadUART1();

    IFS0bits.U1RXIF = 0;
    return;
}
Esempio n. 5
0
//-----------------------------------------------------------------
// Interrupts
//-----------------------------------------------------------------
// UART1 -> IR signal
void __attribute__((__interrupt__)) _U1RXInterrupt(void)
{
	unsigned char buffer;
	IFS0bits.U1RXIF = 0;
	while( DataRdyUART1() )
	{
		buffer=ReadUART1();
	}
	if (buffer == current_TRANSMITTER) //check if the received signal is the current slave's adress
	{
		receive_flag[current_state]=buffer;
	}
}
Esempio n. 6
0
void __ISR(_UART1_VECTOR, ipl2) IntUart1Handler(void)
{
    // Is this an RX interrupt?
    if (mU2RXGetIntFlag())
    {
        // Clear the RX interrupt Flag
        mU2RXClearIntFlag();

        char change = (char) ReadUART1();

        if (change == ']')
        {
            width++;
            if (width > 32)
            {
                width = width - 32;
            }
        }

        if (change == '[')
        {
            width--;
            if (width < 1)
            {
                width = width + 32;
            }
        }

        // Echo what we just received.
        sprintf(RS232_Out_Buffer, "Width: %d \r\n", width);
        putsUART1(RS232_Out_Buffer);

        //reset chip to new width
        nrf24l01_initialize_debug(true, width, false);
    }

    // We don't care about TX interrupt
    if (mU2TXGetIntFlag())
    {
        mU2TXClearIntFlag();
    }
}
void __attribute__((interrupt, auto_psv)) _U1RXInterrupt(void) {
    IFS0bits.U1RXIF = 0; // clear RX interrupt flag

    /* get the data */
    if (U1STAbits.URXDA == 1) {
        if (decode_pkgs(ReadUART1())) {
            PARSER_FLAG = 1; //if correct packet parse command start interrupt flag
        }
    } else {
        /* check for receive errors */
        if (U1STAbits.FERR == 1) {
            pkg_error(ERROR_FRAMMING);
        }
        /* must clear the overrun error to keep uart receiving */
        if (U1STAbits.OERR == 1) {
            U1STAbits.OERR = 0;
            pkg_error(ERROR_OVERRUN);
        }
    }
}
Esempio n. 8
0
//*******************************************************************************************
// UART 1 interrupt handler
// it is set at priority level 2
//*******************************************************************************************
void __ISR(_UART1_VECTOR, ipl2) IntUart1Handler(void)
{
unsigned char theChar;

	// Is this an RX interrupt?
	if (mU1RXGetIntFlag())
	{

		theChar	=	ReadUART1();
		store_char(theChar, &rx_buffer1);

		// Clear the RX interrupt Flag (must be AFTER the read)
	    mU1RXClearIntFlag();
	}

	// We don't care about TX interrupt
	if ( mU1TXGetIntFlag() )
	{
		mU1TXClearIntFlag();
	}
}
Esempio n. 9
0
/* Read GSM data */
char gsmRead(void) {
  char c = 0;

  /* Grab data from GSM if available */
  if (!DataRdyUART1()) {
    return c;
  } else {
      c = ReadUART1();
  }

  if (c == '+') {

    gsmCurrentLine[gsmLineIdx] = 0;
    gsmLineIdx = 0;
  }
  if (c == '\n') {
    gsmCurrentLine[gsmLineIdx] = 0;

    if (gsmCurrentLine == gsmLine1) {
      gsmCurrentLine = gsmLine2;
      gsmLastLine = gsmLine1;
    } else {
      gsmCurrentLine = gsmLine1;
      gsmLastLine = gsmLine2;
    }

    gsmLineIdx = 0;
    gsmRcvdFlag = true;
  }

  gsmCurrentLine[gsmLineIdx++] = c;
  if (gsmLineIdx >= SINDMAXLINELENGTH)
    gsmLineIdx = SINDMAXLINELENGTH-1;

  return c;

}
Esempio n. 10
0
void InterruptAX() {
    while(DataRdyUART1()) {
        byte b = ReadUART1();

        if(posAX == -5 && b == 0xFF)
            posAX = -4;
        else if(posAX == -4 && b == 0xFF) {
            posAX = -3;
            checksumAX = 0;
            responseAX.len = 1;
        }
        else if(posAX == -3) {
            posAX = -2;
            responseAX.id = b;
        }
        else if(posAX == -2 && b < 2 + 4 /*taille de ax.parameters*/) {
            posAX = -1;
            checksumAX = responseAX.id + b;
            responseAX.len = b - 2;
        }
        else if(posAX == -1) {
            posAX = 0;
            responseAX.error = *((errorAX*)&b);
            //checksumAX += b;
        }
        else if(0 <= posAX && posAX < responseAX.len) {
            ((byte*)&responseAX.params)[posAX++] = b;
            checksumAX += b;
        }
        else if(posAX == responseAX.len && (b & checksumAX) == 0) {
            responseReadyAX = 1;
            posAX = -5;
        }
        else
            posAX = -5; // Erreur.
    }
}
Esempio n. 11
0
//read data from the UART, and call the proper function based on the Xbee code
void __attribute__((__interrupt__, no_auto_psv)) _U1RXInterrupt(void)
{
    static unsigned char uart_rx_state = UART_RX_WAITING;
    static unsigned char uart_rx_cnt = 0;
    static Payload uart_pld;
    static WordVal uart_pld_len;
    static byte    uart_checksum;
    static unsigned char packet_type = 0;
    static unsigned char test;
    
    unsigned char c;

    if(U1STAbits.OERR)
    {
        U1STAbits.OERR = 0;
    }

    c = ReadUART1();
    if (uart_rx_state == UART_RX_WAITING && c == RX_START)
    {
        uart_rx_state = UART_RX_ON;
        packet_type = 0;
        uart_rx_cnt = 1;
        uart_checksum = 0x00;
    }else if (uart_rx_state == UART_RX_ON)
    {
        switch (uart_rx_cnt)
        {
            //XBee interface uses two bytes for payload length, despite the
            //fact that packets can't be longer than 128 bytes. The high byte
            //is extracted, but never used here.
            case LEN_HB_POS:
                uart_pld_len.byte.HB = c;
                uart_rx_cnt++;
                break;
            case LEN_LB_POS:
                uart_pld_len.byte.LB = c;
                //We create a payload structure to store the data incoming from the uart
                uart_pld = payCreateEmpty(uart_pld_len.byte.LB-PAYLOAD_HEADER_LENGTH);
                test = uart_pld_len.byte.LB;
                uart_rx_cnt++;
                break;
            case API_ID_POS:
                //Currently, we're only supporting the 16-bit TX/RX API, 
                //and the AT command mode
                packet_type = c;
                uart_checksum += c;
                uart_rx_cnt++;
                break;
            default:
            if (uart_rx_cnt == (uart_pld_len.byte.LB + RX_DATA_OFFSET-1))
            {
                if (uart_checksum + c == 0xFF) //We have a legit packet
                {
                    //Check for type of packet and call relevant function
                    switch (packet_type)
                    {
                        case AT_COMMAND_MODE:
                            xbeeHandleAt(uart_pld);
                            break;

                        case TX_16BIT:
                            xbeeHandleTx(uart_pld);
                            break;

                        default:
                            //do nothing, but probably should send an error
                            break;
                    }
                    payDelete(uart_pld);

                }else //Start over
                {
                    payDelete(uart_pld);
                }

                uart_rx_state = UART_RX_WAITING;
            }else
            {
                uart_pld->pld_data[uart_rx_cnt-RX_DATA_OFFSET] = c;
                uart_checksum += c;
                uart_rx_cnt++;
            }
            break;
        }
            
    }
    _U1RXIF = 0;
}
Esempio n. 12
0
void test_uart_read()
{
    TEST_ASSERT_TRUE(U1RXREG == ReadUART1());
}
Esempio n. 13
0
void vLogicAnalizer(void){

    unsigned int keepGoing = 0;             // Determina si debe seguir o no el muestreo
    unsigned int triggerType;               // Tipo de trigger
    unsigned int samplingFrequency;         // Frecuencia de muestreo
    unsigned int channelMask;               // Máscara para filtrar los canales (un 1 en el canal que se desea el trigger, 0 de otro modo)

    TRISB |= 0xFF00;                        // Parte alta del puerto B como entrada (hacemos una OR sino modificamos los pines
                                            // UART y deja de funcionar)
    TRISAbits.TRISA1 = 0;                   // Pin de dirección del buffer
    PORTAbits.RA1 = 0;                      // Puerto B del buffer como entrada y A como salida (A <- B)
    CNPU1 = CNPU2 = 0;                      // Deshabilito pull-ups
    CLKDIVbits.DOZEN = 0;                   // CPU a 40 MIPS

    disableUARTInt();
    writeUART1(LOGIC_ANALIZER);             // Envío el modo

    debug("\r\nAnalizador Logico");
    // Elimino datos que puedan quedar en el UART
    while(DataRdyUART1()){
        printNumericDebug("\r\nDatos disponibles en el UART: ", ReadUART1());
    }

    // Leo el estado para saber si debo continuar o detenerme
    sleepWait();
    keepGoing = mReadUART1();
    printNumericDebug("\r\nKeepGoing recibido: ", keepGoing);

    while(keepGoing != 0){
        
        if(keepGoing != 0){
            debug("\r\nKeep Going!");
            samplingFrequency = mReadUART1();   // Obtengo la frecuencia de muestreo
            triggerType = mReadUART1();         // Obtengo el tipo de trigger
            channelMask = mReadUART1();         // Obtengo la máscara

            printCharDebug("\r\nSampling Frequency: ", samplingFrequency);
            printNumericDebug("\r\nTrigger Type: ", triggerType);
            printNumericDebug("\r\nChannel Mask: ", channelMask);

            CNEN1 = CNEN2 = 0;
            if(channelMask == 0) triggerType = noTrigger;

            // De acuerdo al bit seteado en el Mask detecto o no el cambio de estado
            // en el pin correspondiente
            if(bitTest(channelMask, 7)) CNEN1bits.CN11IE = 1;
            if(bitTest(channelMask, 6)) CNEN1bits.CN12IE = 1;
            if(bitTest(channelMask, 5)) CNEN1bits.CN13IE = 1;
            if(bitTest(channelMask, 4)) CNEN1bits.CN14IE = 1;
            if(bitTest(channelMask, 3)) CNEN1bits.CN15IE = 1;
            if(bitTest(channelMask, 2)) CNEN2bits.CN16IE = 1;
            if(bitTest(channelMask, 1)) CNEN2bits.CN21IE = 1;
            if(bitTest(channelMask, 0)) CNEN2bits.CN22IE = 1;

            // Habilito interrupciones por cambio de estado en caso de usarlas
            if(triggerType == simpleTrigger){
                IEC1bits.CNIE = 1;
                IFS1bits.CNIF = 0;
            }
            else IEC1bits.CNIE = 0;
        }
        else{
            debug("\r\nAnalizador Logico BREAK");
            break;
        }

        switch(samplingFrequency){
            case F40MHz:
                debug("\r\nSampling 40MHz");
                if(triggerType == noTrigger) vSample40MHz((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE);
                else if(triggerType == simpleTrigger) vSample40MHzTriggerSimple((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE, channelMask);
                break;

            case F20MHz:
                debug("\r\nSampling 20MHz");
                if(triggerType == noTrigger) vSample20MHz((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE);
                else if(triggerType == simpleTrigger) vSample20MHzTriggerSimple((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE, channelMask);
                break;

            case F10MHz:
                debug("\r\nSampling 10MHz");
                if(triggerType == noTrigger) vSample10MHz((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE);
                else if(triggerType == simpleTrigger) vSample10MHzTriggerSimple((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE, channelMask);
                break;

            case F4MHz:
                debug("\r\nSampling 4MHz");
                if(triggerType == noTrigger) vSample4MHz((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE);
                else if(triggerType == simpleTrigger) vSample4MHzTriggerSimple((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE, channelMask);
                break;

            case F400KHz:
                debug("\r\nSampling 400KHz");
                if(triggerType == noTrigger) vSample400KHz((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE);
                else if(triggerType == simpleTrigger) vSample400KHzTriggerSimple((unsigned char *)&PORTB+1, Buffer, BUFFER_SIZE, channelMask);
                break;

            case F2KHz:
                debug("\r\nSampling 2KHz");
                //vSample2KHz((char *)&PORTB+1, &Buffer, BUFFER_SIZE);
                break;

            case F10Hz:
                debug("\r\nSampling 10Hz");
                //vSample10Hz((char *)&PORTB+1, &Buffer, BUFFER_SIZE);
                break;

            default:
                debug("\r\nSampling Default");
                break;
        }

        debug("\r\nSending data");
        writeUART1(START_BYTE);             // Envío byte de Start
        writeUART1(LOGIC_ANALIZER);         // Envío proveniencia del dato

        // Envío el buffer comprimido
        RLEncodeSendBuffer(Buffer, BUFFER_SIZE);
        // Dos 0xFF indican la terminación
        writeUART1(0xFF);
        writeUART1(0xFF);

        sleepWait();
        keepGoing = mReadUART1();
        printNumericDebug("\r\nKeepGoing recibido: ", keepGoing);
    }
    debug("\r\nSale de Analizador Logico");
    enableUARTInt();        // Habilito nuevamente las interrupciones UART
}
Esempio n. 14
0
/**
 * Espero un byte desde el USART 1 y lo devuelvo
 * @return byte leido desde el USART
 */
unsigned int mReadUART1 (void){
    while(!DataRdyUART1());
    return ReadUART1();
}
Esempio n. 15
0
void __attribute__ ((interrupt,no_auto_psv)) _U1RXInterrupt(void) {
  U1RX_Clear_Intr_Status_Bit;
  csk_uart0_inchar(ReadUART1());
  OSSignalSem(SEM_CMD_CHAR_P); // commands normally come from Rx0 (terminal port on Dev Board)
}