CLEON  Version 1
Cloud-Offloaded GPS Receiver
sys_usb.h File Reference

USB related functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  usb_frame_s
 
union  usb_frame_u
 

Macros

#define USB_FRAME_HEADER   0x55
 
#define USB_FRAME_FOOTER   0xAA
 
#define USB_FRAME_DATA_FIELD_LENGTH   29
 
#define USB_FRAME_COMMAND_AND_DATA_FIELD_LENGTH   30
 
#define USB_FRAME_LENGTH   36
 
#define USB_FRAME_COMMAND_CONNECT   0x01
 
#define USB_FRAME_COMMAND_UPDATE_RTC_TIME   0x02
 
#define USB_FRAME_COMMAND_UPDATE_TIME_TICK   0x03
 
#define USB_FRAME_COMMAND_UPDATE_SAMPLE_COUNT   0x04
 
#define USB_FRAME_COMMAND_UPDATE_SAMPLE_GAP   0x05
 
#define USB_FRAME_COMMAND_UPDATE_CHUNK_COUNT   0x06
 
#define USB_FRAME_COMMAND_UPDATE_CHUNK_GAP   0x07
 
#define USB_FRAME_COMMAND_ACK   0xFF
 
#define SYS_USB_IsUSBConnected()   ((USB_STATUS_PORT(IN) & BV(USB_STATUS_PIN)) >> USB_STATUS_PIN)
 

Functions

void SYS_USB_Init (void)
 Initializing USB.
 
void SYS_USB_SendACK (unsigned char ucCommand)
 Sending USB frame ACK.
 
int SYS_USB_Printf (char *format,...)
 Mimic the standard 'printf' with USB as output device.
 
void SYS_USB_ReceiveFrame (unsigned char ucData)
 Receiving a bayte and test whether correct frame has been received.
 
unsigned char SYS_USB_BuildCRC (usb_frame_u *uniUSBFrame)
 Building CRC out of USB frame.
 
void SYS_USB_TransmitSingleByte (unsigned char ucData)
 Transmit a byte vis USB.
 

Detailed Description

USB related functions.

Definition in file sys_usb.h.

Macro Definition Documentation

#define SYS_USB_IsUSBConnected ( )    ((USB_STATUS_PORT(IN) & BV(USB_STATUS_PIN)) >> USB_STATUS_PIN)

Definition at line 42 of file sys_usb.h.

#define USB_FRAME_COMMAND_ACK   0xFF

Definition at line 25 of file sys_usb.h.

#define USB_FRAME_COMMAND_AND_DATA_FIELD_LENGTH   30

Definition at line 15 of file sys_usb.h.

#define USB_FRAME_COMMAND_CONNECT   0x01

Definition at line 18 of file sys_usb.h.

#define USB_FRAME_COMMAND_UPDATE_CHUNK_COUNT   0x06

Definition at line 23 of file sys_usb.h.

#define USB_FRAME_COMMAND_UPDATE_CHUNK_GAP   0x07

Definition at line 24 of file sys_usb.h.

#define USB_FRAME_COMMAND_UPDATE_RTC_TIME   0x02

Definition at line 19 of file sys_usb.h.

#define USB_FRAME_COMMAND_UPDATE_SAMPLE_COUNT   0x04

Definition at line 21 of file sys_usb.h.

#define USB_FRAME_COMMAND_UPDATE_SAMPLE_GAP   0x05

Definition at line 22 of file sys_usb.h.

#define USB_FRAME_COMMAND_UPDATE_TIME_TICK   0x03

Definition at line 20 of file sys_usb.h.

#define USB_FRAME_DATA_FIELD_LENGTH   29

Definition at line 14 of file sys_usb.h.

#define USB_FRAME_FOOTER   0xAA

Definition at line 12 of file sys_usb.h.

#define USB_FRAME_HEADER   0x55

Definition at line 11 of file sys_usb.h.

#define USB_FRAME_LENGTH   36

Definition at line 16 of file sys_usb.h.

Function Documentation

unsigned char SYS_USB_BuildCRC ( usb_frame_u uniUSBFrame)

Building CRC out of USB frame.

Returns
ucCheckOctet - generated CRC
Parameters
void

Definition at line 215 of file sys_usb.c.

{
unsigned char ucCheckOctet = 0;
for ( int i = 3 ; i < (USB_FRAME_LENGTH - 3) ; i++ ){
if( i == 0 ){
ucCheckOctet = (*uniUSBFrame).ucSingleByte[i];
}
if (i >= 1)
{
ucCheckOctet ^= (*uniUSBFrame).ucSingleByte[i];
}
}
ucCheckOctet = ~ucCheckOctet;
return ucCheckOctet;
}

Here is the caller graph for this function:

void SYS_USB_Init ( void  )

Initializing USB.

Returns
void
Parameters
void

Definition at line 37 of file sys_usb.c.

Here is the caller graph for this function:

int SYS_USB_Printf ( char *  format,
  ... 
)

Mimic the standard 'printf' with USB as output device.

      - Sending a byte (stream) to USB
Returns
index - number of bytes sent
Parameters
data- a byte to be sent to USB

Definition at line 91 of file sys_usb.c.

{
// Maximum length of data is 255
char buff[250];
int index = 0;
unsigned char data = 0;
va_list argptr; // Argument list
buff[0] = 0x00;
va_start( argptr,format); // Initializing the function
vsprintf(buff,format,argptr ); // Copying buffer
va_end( argptr ); // Finalizing the function
data = buff[index++]; // Loading data
while(data != 0x00){
//USCI_A1 TX buffer ready?
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA1TXBUF = data;
data = buff[index++];
}
return(index);
}

Here is the caller graph for this function:

void SYS_USB_ReceiveFrame ( unsigned char  ucData)

Receiving a bayte and test whether correct frame has been received.

Returns
void
Parameters
ucData- recived single byte from USB

Definition at line 138 of file sys_usb.c.

{
case 0: case 1:
if(ucData == USB_FRAME_HEADER){
}else{
// request retransmission
}
break;
case 2:
(ucData > 0) && (ucData < USB_FRAME_COMMAND_AND_DATA_FIELD_LENGTH)){
}else{
// request retransmission
}
break;
case 3:
break;
case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13:
case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32:
break;
case 33:
}else{
// request retransmission
}
break;
case 34:
if(ucData == USB_FRAME_FOOTER){
}else{
// request retransmission
}
break;
case 35:
if(ucData == USB_FRAME_FOOTER){
}else{
// request retransmission
}
break;
default:
// request retransmission
break;
}
}
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SYS_USB_SendACK ( unsigned char  ucCommand)

Sending USB frame ACK.

Returns
void
Parameters
ucCommand- command to be sent

Definition at line 59 of file sys_usb.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void SYS_USB_TransmitSingleByte ( unsigned char  ucData)

Transmit a byte vis USB.

Returns
void
Parameters
ucData- data to be transmitted

Definition at line 123 of file sys_usb.c.

{
//USCI_A1 TX buffer ready?
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA1TXBUF = ucData;
}

Here is the caller graph for this function: