aboutsummaryrefslogtreecommitdiffstats
path: root/src/vfs/inc/ant_rx_chardev.h
blob: a3481b088f2651bc8cefee0eaf4c569cdba9c3b7 (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
/*
 * ANT Stack
 *
 * Copyright 2011 Dynastream Innovations
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*******************************************************************************\
*
*   FILE NAME:      ant_rx_chardev.h
*
*   BRIEF:
*      This file defines the receive thread function, the ant_rx_thread_info_t
*      type for storing the -configuration- <state> of the receive thread, the
*      ant_channel_info_t type for storing a channel's (transport path)
*      configuration, and an enumeration of all ANT channels (transport paths).
*
*
\*******************************************************************************/

#ifndef __ANT_RX_NATIVE_H
#define __ANT_RX_NATIVE_H

#include "ant_native.h"
#include "ant_hci_defines.h"

/* same as HCI_MAX_EVENT_SIZE from hci.h, but hci.h is not included for vfs */
#define ANT_HCI_MAX_MSG_SIZE 260

#define ANT_MSG_SIZE_OFFSET     ((ANT_U8)0)
#define ANT_MSG_ID_OFFSET       ((ANT_U8)1)
#define ANT_MSG_DATA_OFFSET     ((ANT_U8)2)

/* This struct defines the info passed to an rx thread */
typedef struct {
   /* Device path */
   const char *pcDevicePath;
   /* File descriptor to read from */
   int iFd;
   /* Callback to call with ANT packet */
   ANTNativeANTEventCb fnRxCallback;
   /* Flow control response if channel supports it */
   ANT_U8 ucFlowControlResp;
   /* Handle to flow control condition */
   pthread_cond_t *pstFlowControlCond;
   /* Handle to flow control mutex */
   pthread_mutex_t *pstFlowControlLock;
#ifdef ANT_FLOW_RESEND
   /* Length of message to resend on request from chip */
   ANT_U8 ucResendMessageLength;
   /* The message to resend on request from chip */
   ANT_U8 *pucResendMessage;
#endif // ANT_FLOW_RESEND
} ant_channel_info_t;

typedef enum {
#ifdef ANT_DEVICE_NAME // Single transport path
   SINGLE_CHANNEL,
#else // Separate data/command paths
   DATA_CHANNEL,
   COMMAND_CHANNEL,
#endif // Separate data/command paths
   NUM_ANT_CHANNELS
} ant_channel_type;

typedef struct {
   /* Thread handle */
   pthread_t stRxThread;
   /* Exit condition */
   ANT_U8 ucRunThread;
   /* Set state as resetting override */
   ANT_U8 ucChipResetting;
   /* Handle to state change lock for crash cleanup */
   pthread_mutex_t *pstEnabledStatusLock;
   /* ANT channels */
   ant_channel_info_t astChannels[NUM_ANT_CHANNELS];
   /* Event file descriptor used to interrupt the poll() loop in the rx thread. */
   int iRxShutdownEventFd;
} ant_rx_thread_info_t;

extern ANTNativeANTStateCb g_fnStateCallback;  // TODO State callback should be inside ant_rx_thread_info_t.

/* This is the rx thread function. It loops reading ANT packets until told to
 * exit */
void *fnRxThread(void *ant_rx_thread_info);

#endif /* ifndef __ANT_RX_NATIVE_H */