aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp_clock/octoclock/common.h
blob: 96acbb30f92ba2fdd210e103068e95c708b6d419 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright 2014 Ettus Research LLC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _OCTOCLOCK_COMMON_H_
#define _OCTOCLOCK_COMMON_H_

#include <stdint.h>

/*
 * C++ macros used for code cleanliness and extern "C" declaration.
 */
#ifdef __cplusplus

#define UHD_OCTOCLOCK_SEND_AND_RECV(xport, pkt_code, pkt_out, len, data) pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; \
                                                                         pkt_out.code = pkt_code; \
                                                                         xport->send(boost::asio::buffer(&pkt_out, sizeof(octoclock_packet_t))); \
                                                                         len = xport->recv(boost::asio::buffer(data), 2);

#define UHD_OCTOCLOCK_PACKET_MATCHES(pkt_code, pkt_out, pkt_in, len) (len > offsetof(octoclock_packet_t, data) and \
                                                                      pkt_in->sequence == pkt_out.sequence and \
                                                                      pkt_in->code == pkt_code)

extern "C" {
#endif

/*
 * This code is used by both the C firmware and C++ host driver, so
 * only valid C code should go in this section.
 */

//These values are placed in the octoclock_packet_t.proto_ver field
#define OCTOCLOCK_BOOTLOADER_PROTO_VER 1234
#define OCTOCLOCK_FW_COMPAT_NUM 2

//UDP ports assigned for different tasks
#define OCTOCLOCK_UDP_CTRL_PORT   50000
#define OCTOCLOCK_UDP_GPSDO_PORT  50001
#define OCTOCLOCK_UDP_FW_PORT     50002
#define OCTOCLOCK_UDP_EEPROM_PORT 50003

typedef enum {
    NO_CODE,

    OCTOCLOCK_QUERY_CMD,
    OCTOCLOCK_QUERY_ACK,

    SEND_EEPROM_CMD,
    SEND_EEPROM_ACK,
    BURN_EEPROM_CMD,
    BURN_EEPROM_SUCCESS_ACK,
    BURN_EEPROM_FAILURE_ACK,
    CLEAR_EEPROM_CMD,
    CLEAR_EEPROM_ACK,

    SEND_STATE_CMD,
    SEND_STATE_ACK,

    RESET_CMD,
    RESET_ACK,

    HOST_SEND_TO_GPSDO_CMD,
    HOST_SEND_TO_GPSDO_ACK,
    SEND_POOLSIZE_CMD,
    SEND_POOLSIZE_ACK,
    SEND_CACHE_STATE_CMD,
    SEND_CACHE_STATE_ACK,
    SEND_GPSDO_CACHE_CMD,
    SEND_GPSDO_CACHE_ACK,

    PREPARE_FW_BURN_CMD,
    FW_BURN_READY_ACK,
    FILE_TRANSFER_CMD,
    FILE_TRANSFER_ACK,
    READ_FW_CMD,
    READ_FW_ACK,
    FINALIZE_BURNING_CMD,
    FINALIZE_BURNING_ACK,
} packet_code_t;

typedef enum {
    NO_REF,
    INTERNAL,
    EXTERNAL
} ref_t;

typedef enum {
    UP,
    DOWN
} switch_pos_t;

#pragma pack(push,1)

// Structure of values in EEPROM, starting in location 0
typedef struct {
    uint8_t mac_addr[6];
    uint32_t ip_addr;
    uint32_t dr_addr;
    uint32_t netmask;
    uint8_t serial[10];
    uint8_t name[10];
    uint8_t revision;
} octoclock_fw_eeprom_t;

typedef struct {
    uint8_t external_detected;
    uint8_t gps_detected;
    uint8_t which_ref;
    uint8_t switch_pos;
} octoclock_state_t;

typedef struct {
    uint8_t num_wraps;
    uint8_t pos;
} gpsdo_cache_state_t;

typedef struct {
    uint32_t proto_ver;
    uint32_t sequence;
    uint8_t code;
    union {
        uint16_t len;
        gpsdo_cache_state_t state;
        uint16_t poolsize;
        uint16_t addr;
    };
    uint8_t data[256];
} octoclock_packet_t;

#pragma pack(pop)

#ifdef __cplusplus
}
#endif

#endif /* _OCTOCLOCK_COMMON_H_ */