Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
usb_ser_hw.c File Reference
#include <string.h>
#include "std.h"
#include <stdbool.h>
#include "LPC21xx.h"
#include "armVIC.h"
#include "mcu_periph/usb_serial.h"
#include <BOARD_CONFIG>
#include "lpcusb/usbapi.h"
+ Include dependency graph for usb_ser_hw.c:

Go to the source code of this file.

Data Structures

struct  fifo_t
 
struct  TLineCoding
 

Macros

#define USB_VIC_SLOT   10
 
#define INT_IN_EP   0x81
 
#define BULK_OUT_EP   0x05
 
#define BULK_IN_EP   0x82
 
#define MAX_PACKET_SIZE   64
 
#define LE_WORD(x)   ((x)&0xFF),((x)>>8)
 
#define CS_INTERFACE   0x24
 
#define CS_ENDPOINT   0x25
 
#define SET_LINE_CODING   0x20
 
#define GET_LINE_CODING   0x21
 
#define SET_CONTROL_LINE_STATE   0x22
 
#define VCOM_FIFO_SIZE   128
 
#define EOF   (-1)
 
#define ASSERT(x)
 

Functions

static void USBIntHandler (void)
 Interrupt handler. More...
 
static void BulkOut (U8 bEP, U8 bEPStatus)
 Local function to handle incoming bulk data. More...
 
void fifo_init (fifo_t *fifo, U8 *buf)
 
BOOL fifo_put (fifo_t *fifo, U8 c)
 
BOOL fifo_get (fifo_t *fifo, U8 *pc)
 
int fifo_avail (fifo_t *fifo)
 
int fifo_free (fifo_t *fifo)
 
int VCOM_putchar (int c)
 Writes one character to VCOM port. More...
 
int VCOM_getchar (void)
 Reads one character from VCOM port. More...
 
bool VCOM_check_free_space (uint16_t len)
 Checks if buffer free in VCOM buffer. More...
 
int VCOM_check_available (void)
 Checks if data available in VCOM buffer. More...
 
static void BulkIn (U8 bEP, U8 bEPStatus)
 Local function to handle outgoing bulk data. More...
 
static BOOL HandleClassRequest (TSetupPacket *pSetup, int *piLen, U8 **ppbData)
 Local function to handle the USB-CDC class requests. More...
 
static void USBFrameHandler (U16 wFrame)
 
static int usb_serial_check_free_space (struct usb_serial_periph *p, long *fd, uint16_t len)
 
static void usb_serial_transmit (struct usb_serial_periph *p, long fd, uint8_t byte)
 
static void usb_serial_transmit_buffer (struct usb_serial_periph *p, long fd, uint8_t *data, uint16_t len)
 
static void usb_serial_send (struct usb_serial_periph *p, long fd)
 
void VCOM_event (void)
 
void VCOM_send_message (void)
 
static int usb_serial_char_available (struct usb_serial_periph *p)
 
static uint8_t usb_serial_getch (struct usb_serial_periph *p)
 
void VCOM_init (void)
 

Variables

int allow_line_coding = 0
 
static TLineCoding LineCoding = {115200, 0, 0, 8}
 
static uint8_t abBulkBuf [64]
 
static uint8_t abClassReqData [8]
 
static uint8_t txdata [VCOM_FIFO_SIZE]
 
static uint8_t rxdata [VCOM_FIFO_SIZE]
 
static fifo_t txfifo
 
static fifo_t rxfifo
 
static bool BulkOut_is_blocked = false
 
static const uint8_t abDescriptors []
 
struct usb_serial_periph usb_serial
 

Data Structure Documentation

◆ fifo_t

struct fifo_t

Definition at line 90 of file usb_ser_hw.c.

Data Fields
uint8_t * buf
int head
size_t size
int tail

◆ TLineCoding

struct TLineCoding

Definition at line 97 of file usb_ser_hw.c.

Data Fields
uint8_t bCharFormat
uint8_t bDataBits
uint8_t bParityType
uint32_t dwDTERate

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   x)

Definition at line 88 of file usb_ser_hw.c.

◆ BULK_IN_EP

#define BULK_IN_EP   0x82

Definition at line 71 of file usb_ser_hw.c.

◆ BULK_OUT_EP

#define BULK_OUT_EP   0x05

Definition at line 70 of file usb_ser_hw.c.

◆ CS_ENDPOINT

#define CS_ENDPOINT   0x25

Definition at line 79 of file usb_ser_hw.c.

◆ CS_INTERFACE

#define CS_INTERFACE   0x24

Definition at line 78 of file usb_ser_hw.c.

◆ EOF

#define EOF   (-1)

Definition at line 87 of file usb_ser_hw.c.

◆ GET_LINE_CODING

#define GET_LINE_CODING   0x21

Definition at line 82 of file usb_ser_hw.c.

◆ INT_IN_EP

#define INT_IN_EP   0x81

Definition at line 69 of file usb_ser_hw.c.

◆ LE_WORD

#define LE_WORD (   x)    ((x)&0xFF),((x)>>8)

Definition at line 75 of file usb_ser_hw.c.

◆ MAX_PACKET_SIZE

#define MAX_PACKET_SIZE   64

Definition at line 73 of file usb_ser_hw.c.

◆ SET_CONTROL_LINE_STATE

#define SET_CONTROL_LINE_STATE   0x22

Definition at line 83 of file usb_ser_hw.c.

◆ SET_LINE_CODING

#define SET_LINE_CODING   0x20

Definition at line 81 of file usb_ser_hw.c.

◆ USB_VIC_SLOT

#define USB_VIC_SLOT   10

Definition at line 66 of file usb_ser_hw.c.

◆ VCOM_FIFO_SIZE

#define VCOM_FIFO_SIZE   128

Definition at line 85 of file usb_ser_hw.c.

Function Documentation

◆ BulkIn()

static void BulkIn ( U8  bEP,
U8  bEPStatus 
)
static

Local function to handle outgoing bulk data.

Parameters
[in]bEP
[in]bEPStatus

Definition at line 461 of file usb_ser_hw.c.

References abBulkBuf, fifo_avail(), fifo_get(), MAX_PACKET_SIZE, and txfifo.

Referenced by VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BulkOut()

static void BulkOut ( U8  bEP,
U8  bEPStatus 
)
static

Local function to handle incoming bulk data.

Parameters
[in]bEP
[in]bEPStatus

Definition at line 432 of file usb_ser_hw.c.

References abBulkBuf, ASSERT, BulkOut_is_blocked, FALSE, fifo_free(), fifo_put(), MAX_PACKET_SIZE, and rxfifo.

Referenced by VCOM_getchar(), and VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fifo_avail()

static int fifo_avail ( fifo_t fifo)

Definition at line 287 of file usb_ser_hw.c.

References fifo_t::head, fifo_t::tail, and VCOM_FIFO_SIZE.

Referenced by BulkIn(), fifo_free(), fifo_peek(), USBFrameHandler(), VCOM_check_available(), and VCOM_event().

+ Here is the caller graph for this function:

◆ fifo_free()

static int fifo_free ( fifo_t fifo)

Definition at line 292 of file usb_ser_hw.c.

References fifo_avail(), and VCOM_FIFO_SIZE.

Referenced by BulkOut(), VCOM_check_free_space(), and VCOM_getchar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fifo_get()

BOOL fifo_get ( fifo_t fifo,
U8 *  pc 
)

Definition at line 270 of file usb_ser_hw.c.

References fifo_t::buf, FALSE, fifo_t::head, fifo_t::tail, TRUE, and VCOM_FIFO_SIZE.

Referenced by BulkIn(), VCOM_getchar(), and VCOM_send_message().

+ Here is the caller graph for this function:

◆ fifo_init()

void fifo_init ( fifo_t fifo,
U8 *  buf 
)

Definition at line 246 of file usb_ser_hw.c.

References fifo_t::buf, fifo_t::head, and fifo_t::tail.

Referenced by VCOM_init().

+ Here is the caller graph for this function:

◆ fifo_put()

BOOL fifo_put ( fifo_t fifo,
U8  c 
)

Definition at line 253 of file usb_ser_hw.c.

References fifo_t::buf, c(), FALSE, fifo_t::head, fifo_t::tail, TRUE, and VCOM_FIFO_SIZE.

Referenced by BulkOut(), cdcacm_data_rx_cb(), and VCOM_putchar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleClassRequest()

static BOOL HandleClassRequest ( TSetupPacket *  pSetup,
int *  piLen,
U8 **  ppbData 
)
static

Local function to handle the USB-CDC class requests.

Parameters
[in]pSetup
[out]piLen
[out]ppbData

Definition at line 493 of file usb_ser_hw.c.

References allow_line_coding, FALSE, GET_LINE_CODING, LineCoding, SET_CONTROL_LINE_STATE, SET_LINE_CODING, and TRUE.

Referenced by VCOM_init().

+ Here is the caller graph for this function:

◆ usb_serial_char_available()

static int usb_serial_char_available ( struct usb_serial_periph p)
static

Definition at line 576 of file usb_ser_hw.c.

References VCOM_check_available().

Referenced by VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usb_serial_check_free_space()

static int usb_serial_check_free_space ( struct usb_serial_periph p,
long *  fd,
uint16_t  len 
)
static

Definition at line 550 of file usb_ser_hw.c.

References VCOM_check_free_space().

Referenced by VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usb_serial_getch()

static uint8_t usb_serial_getch ( struct usb_serial_periph p)
static

Definition at line 581 of file usb_ser_hw.c.

References VCOM_getchar().

Referenced by VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usb_serial_send()

static void usb_serial_send ( struct usb_serial_periph p,
long  fd 
)
static

Definition at line 568 of file usb_ser_hw.c.

Referenced by VCOM_init().

+ Here is the caller graph for this function:

◆ usb_serial_transmit()

static void usb_serial_transmit ( struct usb_serial_periph p,
long  fd,
uint8_t  byte 
)
static

Definition at line 555 of file usb_ser_hw.c.

References VCOM_putchar().

Referenced by main_periodic_task(), and VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usb_serial_transmit_buffer()

static void usb_serial_transmit_buffer ( struct usb_serial_periph p,
long  fd,
uint8_t data,
uint16_t  len 
)
static

Definition at line 560 of file usb_ser_hw.c.

References VCOM_putchar().

Referenced by VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ USBFrameHandler()

static void USBFrameHandler ( U16  wFrame)
static

Definition at line 538 of file usb_ser_hw.c.

References fifo_avail(), and txfifo.

Referenced by VCOM_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ USBIntHandler()

static void USBIntHandler ( void  )
static

Interrupt handler.

Simply calls the USB ISR, then signals end of interrupt to VIC

Definition at line 531 of file usb_ser_hw.c.

References VICVectAddr.

Referenced by VCOM_init().

+ Here is the caller graph for this function:

◆ VCOM_check_available()

int VCOM_check_available ( void  )

Checks if data available in VCOM buffer.

Returns
character read, or EOF if character could not be read

Definition at line 420 of file usb_ser_hw.c.

Referenced by dfu_command_event(), event_usb_serial(), ReadUsbBuffer(), tunnel_event(), and usb_serial_char_available().

+ Here is the caller graph for this function:

◆ VCOM_check_free_space()

bool VCOM_check_free_space ( uint16_t  len)

Checks if buffer free in VCOM buffer.

Returns
TRUE if len bytes are free

Definition at line 409 of file usb_ser_hw.c.

Referenced by dfu_command_event(), tunnel_event(), usb_serial_check_free_space(), and VCOM_putchar().

+ Here is the caller graph for this function:

◆ VCOM_event()

void VCOM_event ( void  )

Definition at line 571 of file usb_ser_hw.c.

Referenced by event_usb_serial(), main(), and mcu_event().

+ Here is the caller graph for this function:

◆ VCOM_getchar()

int VCOM_getchar ( void  )

Reads one character from VCOM port.

Returns
character read, or EOF if character could not be read

Definition at line 386 of file usb_ser_hw.c.

Referenced by dfu_command_event(), event_usb_serial(), ReadUsbBuffer(), tunnel_event(), and usb_serial_getch().

+ Here is the caller graph for this function:

◆ VCOM_init()

void VCOM_init ( void  )

Definition at line 586 of file usb_ser_hw.c.

Referenced by init_usb_serial(), main(), and mcu_init().

+ Here is the caller graph for this function:

◆ VCOM_putchar()

int VCOM_putchar ( int  c)

Writes one character to VCOM port.

Parameters
[in]ccharacter to write
Returns
character written, or EOF if character could not be written

Definition at line 376 of file usb_ser_hw.c.

Referenced by cmd_execute(), periodic_usb_serial(), tunnel_event(), usb_serial_parse_packet(), usb_serial_transmit(), and usb_serial_transmit_buffer().

+ Here is the caller graph for this function:

◆ VCOM_send_message()

void VCOM_send_message ( void  )

Definition at line 574 of file usb_ser_hw.c.

Referenced by cmd_execute(), usb_serial_parse_packet(), usb_serial_send(), VCOM_event(), and VCOM_putchar().

+ Here is the caller graph for this function:

Variable Documentation

◆ abBulkBuf

uint8_t abBulkBuf[64]
static

Definition at line 107 of file usb_ser_hw.c.

Referenced by BulkIn(), and BulkOut().

◆ abClassReqData

uint8_t abClassReqData[8]
static

Definition at line 108 of file usb_ser_hw.c.

Referenced by VCOM_init().

◆ abDescriptors

const uint8_t abDescriptors[]
static

Definition at line 133 of file usb_ser_hw.c.

Referenced by VCOM_init().

◆ allow_line_coding

int allow_line_coding = 0

Definition at line 104 of file usb_ser_hw.c.

Referenced by HandleClassRequest().

◆ BulkOut_is_blocked

bool BulkOut_is_blocked = false
static

Definition at line 116 of file usb_ser_hw.c.

Referenced by BulkOut(), and VCOM_getchar().

◆ LineCoding

TLineCoding LineCoding = {115200, 0, 0, 8}
static

Definition at line 106 of file usb_ser_hw.c.

Referenced by HandleClassRequest(), and VCOM_init().

◆ rxdata

uint8_t rxdata[VCOM_FIFO_SIZE]
static

Definition at line 111 of file usb_ser_hw.c.

Referenced by VCOM_init().

◆ rxfifo

fifo_t rxfifo
static

Definition at line 114 of file usb_ser_hw.c.

Referenced by BulkOut(), VCOM_check_available(), VCOM_getchar(), and VCOM_init().

◆ txdata

uint8_t txdata[VCOM_FIFO_SIZE]
static

Definition at line 110 of file usb_ser_hw.c.

Referenced by VCOM_init().

◆ txfifo

fifo_t txfifo
static

Definition at line 113 of file usb_ser_hw.c.

Referenced by BulkIn(), USBFrameHandler(), VCOM_check_free_space(), VCOM_init(), and VCOM_putchar().

◆ usb_serial

struct usb_serial_periph usb_serial

Definition at line 547 of file usb_ser_hw.c.

Referenced by VCOM_init().