KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ipmux.h
Go to the documentation of this file.
1 /*
2  * ipmux.h
3  *
4  * Created on: 8 aug. 2013
5  * Author: vincentb
6  */
7 
8 #ifndef IPMUX_H_
9 #define IPMUX_H_
10 
11 /**
12  * @file
13  *
14  * @ingroup wbdrivers
15  *
16  * IPMUX Driver for CLBv2. This implements all required functionality for configuring and
17  * controlling the IPMux.
18  */
19 
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include "util/macro.h"
23 
24 /**
25  * IPMux configuration structure. Same structure for
26  * both local and remote settings.
27  */
28 typedef struct
29 {
30  uint32_t ip; //!< IP address
31  uint16_t mac[3]; //!< MAC address
32  uint16_t prt[4]; //!< Port numbers
33 } IpMuxCfg;
34 
35 #define IPMUX_CH_0 BIT(0) //!< Channel 1
36 #define IPMUX_CH_1 BIT(1) //!< Channel 2
37 #define IPMUX_CH_2 BIT(2) //!< Channel 3
38 #define IPMUX_CH_3 BIT(3) //!< Channel 4
39 #define IPMUX_CH_CPU BIT(4) //!< CPU channel
40 
41 /**
42  * Initializes the IPMux local (module) only.
43  *
44  * @param modCfg Module configuration
45  * @param flush Flush IPMux CPU pipe.
46  */
47 void ipMuxInit(IpMuxCfg * modCfg, bool flush);
48 
49 /**
50  * Configure IPmux with remote settings.
51  */
52 void ipMuxCfgRemote(IpMuxCfg * svrCfg);
53 
54 /**
55  * Set the mux destination (server / destination)
56  *
57  * @param destIp The IP address, as a char array of 4 bytes.
58  */
59 void ipMuxSetDest(uint8_t * destIp);
60 
61 /**
62  * Returns whether or not there is data available for reception.
63  *
64  * @retval true There is at least one packet ready to be read
65  * @retval false The CPU FIFO is empty.
66  */
67 bool ipMuxRxAvail();
68 
69 /**
70  * Received data from the IPMux's CPU interface.
71  *
72  * @param buf The buffer to write into
73  * @param buflen The length of the buffer
74  * @param rxlen Pointer to int32 to fill with actual number of bytes read
75  *
76  * @retval true On success
77  * @retval false If reception failed, check errCode() for more info.
78  *
79  * Possible errors:
80  * - E_TIMEOUT If the reception of the packet takes too much time
81  * - E_OUTOFMEM If the packet is bigger than the supplied buffer.
82  */
83 bool ipMuxRx(void * buf, uint32_t buflen, uint32_t * rxlen);
84 
85 /**
86  * Sends data to the IPMux's CPU interface.
87  *
88  * @param buf The buffer with data to send
89  * @param buflen The length of the data to send
90  *
91  * @retval true On success
92  * @retval false If reception failed, check errCode() for more info.
93  */
94 bool ipMuxTx(void * buf, uint32_t txlen, bool done);
95 
96 
97 
98 #define IPMUX_FLUSH_OP_START 0x1
99 #define IPMUX_FLUSH_OP_END 0x2
100 #define IPMUX_FLUSH_OP_TOGGLE (IPMUX_FLUSH_OP_START | IPMUX_FLUSH_OP_END)
101 
102 /**
103  * Flushes the IPMUX's FIFO's.
104  *
105  * Good to use if recovering from an error.
106  *
107  * For example:
108  * @code
109  * ipMuxFluch(IPMUX_CH_0 | IPMUX_CH_1);
110  * @endcode
111  * Flushes channel 0 and 1.
112  *
113  * @param channelMask The channels to flush
114  */
115 void ipMuxFlush(uint32_t channelMask, uint8_t ipmFlushOp);
116 
117 /**
118  * Flushes the
119  */
120 static inline void ipMuxFlushCPU() {
121  ipMuxFlush(IPMUX_CH_CPU, IPMUX_FLUSH_OP_TOGGLE);
122 }
123 
124 /**
125  * Debug function to see whats inside.
126  */
127 void ipMuxDumpRegs();
128 
129 
130 #endif /* IPMUX_H_ */
131 
void ipMuxCfgRemote(IpMuxCfg *svrCfg)
Configure IPmux with remote settings.
Definition: ipmux.c:71
uint32_t ip
IP address.
Definition: ipmux.h:30
bool ipMuxTx(void *buf, uint32_t txlen, bool done)
Sends data to the IPMux&#39;s CPU interface.
Definition: ipmux.c:151
#define IPMUX_CH_CPU
CPU channel.
Definition: ipmux.h:39
IPMux configuration structure.
Definition: ipmux.h:28
bool ipMuxRx(void *buf, uint32_t buflen, uint32_t *rxlen)
Received data from the IPMux&#39;s CPU interface.
Definition: ipmux.c:96
void ipMuxFlush(uint32_t channelMask, uint8_t ipmFlushOp)
Flushes the IPMUX&#39;s FIFO&#39;s.
Definition: ipmux.c:191
void ipMuxDumpRegs()
Debug function to see whats inside.
Definition: ipmux.c:205
static void ipMuxFlushCPU()
Flushes the.
Definition: ipmux.h:120
bool ipMuxRxAvail()
Returns whether or not there is data available for reception.
Definition: ipmux.c:77
void ipMuxSetDest(uint8_t *destIp)
Set the mux destination (server / destination)
void ipMuxInit(IpMuxCfg *modCfg, bool flush)
Initializes the IPMux local (module) only.
Definition: ipmux.c:65
Provides common macros.