summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/drivers/include/vcpVirtualUsart.h
blob: 0c54d8d1a251b2ce9119aad3dce6f282194c30ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/****************************************************************************//**
  \file vcpVirtualUsart.h

  \brief The header file describes the interface of the virtual uart based on USB

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
  History:
    05/09/08 A. Khromykh - Created
*******************************************************************************/
#ifndef _VCPVIRTUALUART_H
#define _VCPVIRTUALUART_H

/******************************************************************************
                   Includes section
******************************************************************************/
#include <types.h>
#include <usart.h>

/******************************************************************************
                   Define(s) section
******************************************************************************/
#define USART_CHANNEL_VCP  ((UsartChannel_t)5)
#define VCP_TRANSMIT_PIPE      2
#define VCP_RECEIVE_PIPE       1

/******************************************************************************
                   Prototypes section
******************************************************************************/
/**************************************************************************//**
\brief Registers uart's event handlers.

\param[in]
  descriptor - pointer to HAL_UartDescriptor_t structure

\return
  Returns positive uart descriptor on success or -1 in cases: \n
    - bad uart channel; \n
    - there are not enough resources; \n
    - receiving buffer is less bulk endpoint size;
******************************************************************************/
int VCP_OpenUsart(HAL_UsartDescriptor_t *descriptor);

/*************************************************************************//**
\brief Releases the uart channel.

\param[in]
  descriptor - pointer to HAL_UartDescriptor_t structure

\return
 -1 - bad descriptor; \n
  0 - success.
*****************************************************************************/
int VCP_CloseUsart(HAL_UsartDescriptor_t *descriptor);

/**************************************************************************//**
\brief Writes a number of bytes to uart channel.
txCallback function will be used to notify when the transmission is finished.

\param[in]
  descriptor - pointer to HAL_UartDescriptor_t structure;

\param[in]
  buffer - pointer to the application data buffer;

\param[in]
  length - number of bytes to transfer;

\return
  -1 - bad descriptor; \n
   Number of bytes placed to the buffer - success.
******************************************************************************/
int VCP_WriteUsart(HAL_UsartDescriptor_t *descriptor, uint8_t *buffer, uint16_t length);

/*************************************************************************//**
\brief Reads a number of bytes from uart and places them to the buffer.

\param[in]
  descriptor - pointer to HAL_UartDescriptor_t structure;

\param[in]
  buffer - pointer to the application buffer;

\param[in]
  length - number of bytes to be placed to the buffer;

\return
  -1 - bad descriptor, or bad number of bytes to read; \n
  Number of bytes placed to the buffer - success.
*****************************************************************************/
int VCP_ReadUsart(HAL_UsartDescriptor_t *descriptor, uint8_t *buffer, uint16_t length);

/**************************************************************************//**
\brief Checks the status of tx buffer (for polling mode).

\param[in]
  descriptor - pointer to HAL_UsartDescriptor_t structure;
\return
  -1 - bad descriptor, no tx buffer; \n
   1 - tx buffer is empty; \n
   0 - tx buffer is not empty;
******************************************************************************/
int VCP_IsTxEmpty(HAL_UsartDescriptor_t *descriptor);

#endif /* _VCPVIRTUALUART_H */