-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
param.h
112 lines (91 loc) · 3.39 KB
/
param.h
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
/**
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2011-2012 Bitcraze AB
*
* 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, in version 3.
*
* 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/>.
*
* param.h - Crazy parameter system header file.
*/
#ifndef __PARAM_H__
#define __PARAM_H__
#include <stdbool.h>
#include <stdint.h>
/* Public functions */
void paramInit(void);
bool paramTest(void);
/* Internal access of param variables */
int paramGetVarId(char* group, char* name);
int paramGetType(int varid);
void paramGetGroupAndName(int varid, char** group, char** name);
void* paramGetAddress(int varid);
uint8_t paramVarSize(int type);
float paramGetFloat(int varid);
int paramGetInt(int varid);
unsigned int paramGetUint(int varid);
/* Basic parameter structure */
struct param_s {
uint8_t type;
char * name;
void * address;
};
#define PARAM_BYTES_MASK 0x03
#define PARAM_1BYTE 0x00
#define PARAM_2BYTES 0x01
#define PARAM_4BYTES 0x02
#define PARAM_8BYTES 0x03
#define PARAM_TYPE_INT (0x00<<2)
#define PARAM_TYPE_FLOAT (0x01<<2)
#define PARAM_SIGNED (0x00<<3)
#define PARAM_UNSIGNED (0x01<<3)
#define PARAM_VARIABLE (0x00<<7)
#define PARAM_GROUP (0x01<<7)
#define PARAM_RONLY (1<<6)
#define PARAM_START 1
#define PARAM_STOP 0
#define PARAM_SYNC 0x02
// User-friendly macros
#define PARAM_UINT8 (PARAM_1BYTE | PARAM_TYPE_INT | PARAM_UNSIGNED)
#define PARAM_INT8 (PARAM_1BYTE | PARAM_TYPE_INT | PARAM_SIGNED)
#define PARAM_UINT16 (PARAM_2BYTES | PARAM_TYPE_INT | PARAM_UNSIGNED)
#define PARAM_INT16 (PARAM_2BYTES | PARAM_TYPE_INT | PARAM_SIGNED)
#define PARAM_UINT32 (PARAM_4BYTES | PARAM_TYPE_INT | PARAM_UNSIGNED)
#define PARAM_INT32 (PARAM_4BYTES | PARAM_TYPE_INT | PARAM_SIGNED)
#define PARAM_FLOAT (PARAM_4BYTES | PARAM_TYPE_FLOAT | PARAM_SIGNED)
/* Macros */
#define PARAM_ADD(TYPE, NAME, ADDRESS) \
{ .type = TYPE, .name = #NAME, .address = (void*)(ADDRESS), },
#define PARAM_ADD_GROUP(TYPE, NAME, ADDRESS) \
{ \
.type = TYPE, .name = #NAME, .address = (void*)(ADDRESS), },
// Fix to make unit tests run on MacOS
#ifdef __APPLE__
#define PARAM_GROUP_START(NAME) \
static const struct param_s __params_##NAME[] __attribute__((section("__DATA,__.param." #NAME), used)) = { \
PARAM_ADD_GROUP(PARAM_GROUP | PARAM_START, NAME, 0x0)
#else
#define PARAM_GROUP_START(NAME) \
static const struct param_s __params_##NAME[] __attribute__((section(".param." #NAME), used)) = { \
PARAM_ADD_GROUP(PARAM_GROUP | PARAM_START, NAME, 0x0)
#endif
//#define PARAM_GROUP_START_SYNC(NAME, LOCK) PARAM_ADD_GROUP(PARAM_GROUP | PARAM_START, NAME, LOCK);
#define PARAM_GROUP_STOP(NAME) \
PARAM_ADD_GROUP(PARAM_GROUP | PARAM_STOP, stop_##NAME, 0x0) \
};
#endif /* __PARAM_H__ */