forked from TMaxElectronics/UD3-Fibernet-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
communication_api.c
123 lines (110 loc) · 3.31 KB
/
communication_api.c
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
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
* File Name: communication_api.c
* Version 1.0
*
* Description:
* This file is created by the author . This contains definitions of APIs
* used in structure 'CyBtldr_CommunicationsData' defined in cybtldr_api.h ,
* using SPI commuincations component
********************************************************************************/
#include "communication_api.h"
#include <xc.h>
#include "UART.h"
#include "FreeRTOS.h"
#include "task.h"
/*******************************************************************************
* Function Name: OpenConnection
********************************************************************************
*
* Summary:
* Initializes the communications component : In this case UART
*
* Parameters:
* void
*
* Return:
* Returns a flag to indicate whether the operation was successful or not
*
*
*******************************************************************************/
int OpenConnection(void)
{
//UART_Start();
return(CYRET_SUCCESS);
}
/*******************************************************************************
* Function Name: CloseConnection
********************************************************************************
*
* Summary:
* Clears the status and stops the communications component (UART).
*
* Parameters:
* void
*
* Return:
* Returns a flag to indicate whether the operation was successful or not
*
*
*******************************************************************************/
int CloseConnection(void)
{
//UART_Stop();
return(CYRET_SUCCESS);
}
/*******************************************************************************
* Function Name: WriteData
********************************************************************************
*
* Summary:
* Writes the specified number of bytes using the communications component (UART)
*
* Parameters:
* wrData - Pointer to write data buffer
* byteCnt - No. of bytes to be written
*
* Return:
* Returns a flag to indicate whether the operation was successful or not
*
*
*******************************************************************************/
int WriteData(uint8_t* wrData, int byteCnt)
{
UART_queBuffer(wrData, byteCnt, 0);
return(CYRET_SUCCESS);
}
/*******************************************************************************
* Function Name: ReadData
********************************************************************************
*
* Summary:
* Reads the specified number of bytes usign the communications component (UART)
*
* Parameters:
* rdData - Pointer to read data buffer
* byteCnt - No. of bytes to be read
*
* Return:
* Returns a flag to indicate whether the operation was successful or not
*
*
*******************************************************************************/
int ReadData(uint8_t* rdData, int byteCnt)
{
int bytesRead=0;
uint32_t timeout = 400;
while(bytesRead < byteCnt && timeout){
while(lastScanPosition != DCH3DPTR){
*rdData = UART_rxBuffer[lastScanPosition];
rdData++;
bytesRead++;
if(++lastScanPosition >= DCH3DSIZ) lastScanPosition = 0;
if(bytesRead == byteCnt) break;
}
timeout--;
if(!timeout) return(CYRET_ERR_COMM_MASK);
vTaskDelay(1);
}
return(CYRET_SUCCESS);
}
/* [] END OF FILE */