Example #1
0
// Write a string over the serial port
int SendString(int id, const char *string)
{
    UART_MODULE uartX;
    switch(id)
    {
        case 1:
            uartX = UART1;
            break;
        case 2:
            uartX = UART2;
            break;
        case 3:
            uartX = UART3;
            break;
        case 4:
            uartX = UART4;
            break;
        default:
            uartX = UART1;
    }
    while(*string != '\0')
    {
      while(!UARTTransmitterIsReady(uartX));
      UARTSendDataByte(uartX, (char) *string);
      string++;
      while(!UARTTransmissionHasCompleted(uartX));
    }
    return 1;
}
Example #2
0
// Write a string over the serial port
void WriteString(UART_MODULE id, const char *string) {
  while(*string != '\0') {
  while(!UARTTransmitterIsReady(id));
  UARTSendDataByte(id, *string);
  string++;
  while(!UARTTransmissionHasCompleted(id));
  }
}
Example #3
0
void Serial2Write(uint8 data) // write to UART directly and wait to finish (hangs execution until finished)
{
	if(SerialConnected) // dont write anything to serial until connection made from client
	{
    UARTSendDataByte(UART2, data);
    while(!UARTTransmissionHasCompleted(UART2));
	}
}
Example #4
0
void PutCharacterBluetooth(const char character)
{
        while(!UARTTransmitterIsReady(UART_MODULE_ID2));

        UARTSendDataByte(UART_MODULE_ID2, character);

        while(!UARTTransmissionHasCompleted(UART_MODULE_ID2));
}
Example #5
0
void uart_print(BYTE *string)
{
    while(!string)
    {
        while(!UARTTransmitterIsReady(UART1));
        UARTSendDataByte(UART1, *string);
        string++;
        while(!UARTTransmissionHasCompleted(UART1));
    }
}
/*
*	Function Name:	void UARTiWriteBinaryData(void)
*	Description:	Writes a block of binary data to he selected uart.
*	Initiator: 		Keith Suhoza
*	Date: 			01/23/2012
*/
void UARTiWriteBinaryData(unsigned char *data_block, int length, UART_MODULE iUART)
{
  while( length)
  {
      while(!UARTTransmitterIsReady(iUART));
      UARTSendDataByte(iUART, *data_block++);
      while(!UARTTransmissionHasCompleted(iUART));
      length--;
  }
}
Example #7
0
// *****************************************************************************
// void SendDataBuffer(const UARTx, const char *buffer)
// Envoie sur le port serie la chaine de caractère
// @param    : UARTx : choix du port  
//                    UART1,UART2,UART3,UART4,UART5,UART6
//              buffer : chaine de caractère
// *****************************************************************************
void SendDataBuffer(const UARTx, const char *buffer)
{
    while(*buffer != '\n')
    {
        while(!UARTTransmitterIsReady(UARTx));
        UARTSendDataByte(UARTx, *buffer);
        buffer++; 
    }
    while(!UARTTransmissionHasCompleted(UARTx));
}
void WriteString(const char *string)
{
    while(*string != '\0')
    {
        while(!UARTTransmitterIsReady(UART_CMD_MODULE_ID));
        UARTSendDataByte(UART_CMD_MODULE_ID, *string);
        string++;
        while(!UARTTransmissionHasCompleted(UART_CMD_MODULE_ID));
    }
}
void PutCharacter(const char character)
{
        while(!UARTTransmitterIsReady(UART2))
            ;

        UARTSendDataByte(UART2, character);


        while(!UARTTransmissionHasCompleted(UART2))
            ;
}
Example #10
0
void UARTSendString(UART_MODULE uart, const char *string)
{
    while(*string)
    {
        if (UARTTransmitterIsReady(uart))//Case where it doesn't matter whether if or while because location is only incremented when the byte is sent
        {
            UARTSendDataByte(uart, *string);
            while(!UARTTransmissionHasCompleted(uart)){}
            string++; //increment through the string
        }
    }
}
Example #11
0
void serialPutc(unsigned char serialPortIndex, char c) {
    UART_MODULE uart = getUartModule(serialPortIndex);

    while (!UARTTransmitterIsReady(uart)) {
    
    }
    
    UARTSendDataByte(uart, c);

    while (!UARTTransmissionHasCompleted(uart)) {
    
    }
}
/*
*	Function Name:	void UARTiWriteString(void)
*	Description:	Writes a full string out the selected uart.
*	Initiator: 		Robert Scaccia
*	Date: 			10/19/2011
*/
void UARTiWriteString(const char *ccpString, UART_MODULE iUART)
{
    static int ready_high_water = 0, completed_high_water = 0;
    int ready_count = 0, completed_count = 0;
    while(*ccpString != '\0')
    {
        while(!UARTTransmitterIsReady(iUART)) ready_count++;
        UARTSendDataByte(iUART, *ccpString);
        ccpString++;
        while(!UARTTransmissionHasCompleted(iUART)) completed_count++;
    }

    if(ready_count     > ready_high_water)     ready_high_water     = ready_count;
    if(completed_count > completed_high_water) completed_high_water = completed_count;
}
Example #13
0
// *****************************************************************************
// void UARTTxBuffer(char *buffer, UINT32 size)
// *****************************************************************************
void SendDataBuffer(const char *buffer, UINT32 size)
{
    while(size)
    {
        while(!UARTTransmitterIsReady(UART2))
            ;

        UARTSendDataByte(UART2, *buffer);

        buffer++;
        size--;
    }

    while(!UARTTransmissionHasCompleted(UART2))
        ;
}
Example #14
0
void WriteStringBluetooth2(const char *string)
{
    int i=0;
    while(i<17)
    {
        while(!UARTTransmitterIsReady(UART_MODULE_ID2));

        UARTSendDataByte(UART_MODULE_ID2, *string);

        string++;

        i++;

        while(!UARTTransmissionHasCompleted(UART_MODULE_ID2));
    }

}
Example #15
0
int SendCharacter(int id, const char character)
{
    UART_MODULE uartX;
    switch(id)
    {
        case 1:
            uartX = UART1;
            break;
        case 2:
            uartX = UART2;
            break;
        case 3:
            uartX = UART3;
            break;
        case 4:
            uartX = UART4;
            break;
        default:
            uartX = UART1;
    }
    while(!UARTTransmitterIsReady(uartX));
    UARTSendDataByte(uartX, character);
    while(!UARTTransmissionHasCompleted(uartX));
}
Example #16
0
// Put a character over the serial port, called by WriteString
void PutCharacter(UART_MODULE id, const char character) {
  while(!UARTTransmitterIsReady(id));
  UARTSendDataByte(id, character);
  while(!UARTTransmissionHasCompleted(id));
}
Example #17
0
bool hal_uart_transmission_has_completed(hal_uart_port port){
    assert(port >= HAL_UART_PORT_1 && port <= HAL_UART_NUMBER_OF_PORTS );
    UART_MODULE uart = logic_uart2phy_uart(port);
    return UARTTransmissionHasCompleted(uart);
}
Example #18
0
int main(void)
{
    int  value;
    int junk;
    millisec = 0;
    value = SYSTEMConfigWaitStatesAndPB( GetSystemClock() );

    // Enable the cache for the best performance
    CheKseg0CacheOn();

    //Setupt input for inteface button JF8 (RA01) (0x02)
    TRISASET = 0x02;
    //RED LED - JF9 (RA04)  (0x10)
    TRISACLR = 0x10;
    ODCACLR = 0x10;
    LATASET = 0x10;
    //Green LED -JF7 (RE9)  (0x200)
    TRISECLR = 0x200;
    ODCECLR = 0x200;
    LATESET = 0x200;
    //Setupt Input for DataFlag Button - JF10 - RA5 0x20
    TRISASET = 0x20;
    //Setup Output for Clutch Hold (Launch) JE1 RD14 0x4000
    //This function is active low, driving the FET on the PDU
    TRISDCLR = 0x4000;
    ODCDCLR = 0x4000;
    LATDSET = 0x4000; //Default state is high (off)

    CAN1Init();//CAN1 ACCL 500kbs
    CAN2Init();//Motec 1mbs
    DelayInit();

    initUART2(); // GPS UART
    prevButton1 = 0;
    prevButton2 = 0;
    millisec = 0;

   // Configure Timer 2 to request a real-time interrupt once per millisecond.
   // The period of Timer 2 is (16 * 5000)/(80 MHz) = 1 ms.
   OpenTimer2(T2_ON | T2_IDLE_CON | T2_SOURCE_INT | T2_PS_1_16 | T2_GATE_OFF, 5000);

   // Configure the CPU to respond to Timer 2's interrupt requests.
   INTEnableSystemMultiVectoredInt();
   INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_2);
   INTClearFlag(INT_T2);
   INTEnable(INT_T2, INT_ENABLED);

   //UART GPS Interrupts
   INTSetVectorPriority(INT_UART_2_VECTOR ,INT_PRIORITY_LEVEL_1); //Make sure UART interrupt is top priority
   INTClearFlag(INT_U2RX);
   INTEnable(INT_U2RX, INT_ENABLED);


    value = OSCCON;
    while (!(value & 0x00000020))
    {
        value = OSCCON;    // Wait for PLL lock to stabilize
    }

    deviceAttached = FALSE;

    //Initialize the stack
    USBInitialize(0);

    shouldLog = FALSE;
    shouldStop = FALSE;
    //count = 0;
    angularRateInfoRec = FALSE;
    accelerationSensorRec = FALSE;
    HRaccelerationSensorRec = FALSE;

       //init tim er 3 to convert adc at 100hz
    OpenTimer3(T3_ON|T3_PS_1_256|T3_SOURCE_INT, 1562);

    //initialize i2c for the psoc
    initI2CPSoC();
    
    state = wait;
    logNum = 0;

    initI2CEEPROM();
    short addy = 0x0000;
    BYTE num = 0x00;
    logNum = readEEPROM(addy);
    if(logNum >= 0xEF)  //Address stored in EEPROM  if greater than 0xEF reset to zero, limited to a single byte with current code configuration
    {
        writeEEPROM(addy, 0x00);
    }
    char GroupString[550];//Group Names (Line1)
    char UnitString[550];//Units (line2)
    char ParamString[650];//Paramater Names (line3)
    sprintf(GroupString,"Time,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Drivetrain,Drivetrain,Electrical,Drivetrain,Drivetrain,Drivetrain,Drivetrain,Engine,Engine,Engine,Engine,Electrical,Electrical,Electrical,Electrical,Electrical,Electrical,Suspension,Suspension,Suspension,Suspension,Suspension,Drivetrain,Driver\n");
    sprintf(UnitString,"ms,deg/s,deg/s,deg/s,m/s^2,m/s^2,m/s^2,m/s^2,m/s^2,m/s^2,rpm,%,kpa,degF,degF,lambda,psi,degF,na,na,psi,psi,V,mph,mph,mph,mph,s,gal,degF,degBTDC,mV,mV,mV,mV,mV,mV,mV,mV,mV,mV,mV,mV,\n");
    sprintf(ParamString, "Millisec,pitch(deg/sec),roll(deg/sec),yaw(deg/sec),lat(m/s^2),long(m/s^2),vert(m/s^2),latHR(m/s^2),longHR(m/s^2),vertHR(m/s^2),rpm,tps(percent),MAP(kpa),AT(degF),ect(degF),lambda,fuel pres,egt(degF),launch,neutral,brake pres,brake pres filtered,BattVolt(V),ld speed(mph), lg speed(mph),rd speed(mph),rg speed(mph),run time(s),fuel used,Oil Temp (deg F), Ignition Adv (degBTDC),Overall Consumption(mV),Overall Production(mV),Fuel Pump(mV),Fuel Injector(mV),Ignition(mV),Vref(mV),Back Left(mV),Back Right(mV),Front Left(mV),Front Right(mV),Steering Angle(mV),Brake Temp(mV),Data Flag,GPRMC,Time,Valid,Lat,N/S,Long,E/W,Speed,Course,Date,Variation,E/W\n");

    LATACLR = 0x10; //Turn on Red LED
   // LATECLR = 0x200;

    UARTSendString(UART2,PMTK_HOT_RESTART);
    int i = 0;
    while(!UARTTransmissionHasCompleted(UART2)){
        i++;
    }

    while(1)
    {
        GPSDataRead();
        GPSSentenceParse();
        ClutchHold(); //This function handles the venting direction of the clutch actuator
        DataFlagFunc(); //This function handles the updates of the data flag variable
        //USB stack process function
        USBTasks();

        switch(state){
            case wait:
                USBTasks();
                millisec = 0;
                if(CheckLogStateChange() == 1){ //start the transition from wait to log
                    state = startLog;
                }
                break;
            case startLog:
                //if thumbdrive is plugged in
                if(USBHostMSDSCSIMediaDetect())
                {
                    deviceAttached = TRUE;
                    //now a device is attached
                    //See if the device is attached and in the right format
                    if(FSInit())
                    {
                        //Opening a file in mode "w" will create the file if it doesn't
                        //  exist.  If the file does exist it will delete the old file
                        //  and create a new one that is blank.
                        logNum = readEEPROM(addy);
                        sprintf(nameString, "test%d.csv", logNum);
                        myFile = FSfopen(nameString,"w");
                        FSfwrite(GroupString,1,strlen(GroupString),myFile);
                        FSfwrite(UnitString,1,strlen(UnitString),myFile);
                        FSfwrite(ParamString,1, strlen(ParamString),myFile);
                        millisec = 0;
                        //LATDSET = 0x4000; //Send sync pulse (aeroprobe)
                       // while(millisec < 1000){} //Wait 1s then move to log, the aeroprobe ADC waits 1s.
                            state = log;
                        LATECLR = 0x200; //Turn on Green
                        LATASET = 0x10; //Turn off Red
                    }
                }
                break;
            case log:
                //This uses MOTEC as the master timer.  Data is only written to the USB after all the motec Data is received
                if(motec0Read && motec1Read && motec2Read && motec3Read && motec4Read && motec5Read){
                    WriteToUSB();
                }
                else{}//Wait for motec data to write the next row
                if(CheckLogStateChange() == 2){ //Start the transition from log to wait
                    state = stopLog;
                }
                if(millisec > 2000){
                    LATDCLR = 0x4000; //After 2 seconds pass no need to keep output high
                }
                //Add a function to check for a flag button and set a variable
                break;
            case stopLog:
                //Always make sure to close the file so that the data gets written to the drive.
                FSfwrite("endFile", 1, 7, myFile);
                FSfclose(myFile);
                state = wait;
                logNum++;
                writeEEPROM(addy, logNum);
                LATACLR = 0x10; //Turn on Red
                LATESET = 0x200; //Turn off Green
                break;
            default:
                state = wait;
                break;
        }


        //CAN Handlers
        CANRxMessageBuffer* CAN1RxMessage = CAN1RxMsgProcess();
        if(CAN1RxMessage){
            WriteAccelData(CAN1RxMessage); //Accel is on CAN 1
        }
        CANRxMessageBuffer* CAN2RxMessage = CAN2RxMsgProcess();
        if(CAN2RxMessage){
            writeCan2Msg(CAN2RxMessage); //Motec is on CAN 2
        }
    }
    return 0;
}