SingingCat 0
application
userconfig.h
1#ifndef USERCONFIG_H
2#define USERCONFIG_H
3
4typedef struct user_config {
5 uint16_t validbytes; // how many bytes in user_config are set?
6 uint32_t checksum; // crc over the bytes
7 uint32_t data_version; // incremented each time it changes. 0 == invalid
8 uint8_t userdata[2048];
10
11/*
12 * \brief receive a (partial) update
13 * commands "userapp-control" with parameter "ucr=n" are sent this way.
14 * n==1 initializes a new receive section, requires pid=P and max=M, where
15 * M is the maximum number of packets
16 * P is a unique ID for this set of packets
17 * n==2 adds data, requires pid=P, pos=X, size=S and data=[bytes], where
18 * X is the index of this data packet [1...n]
19 * S is the size in bytes of data argument
20 * packets must be in order and once last packet is received, flash is updated.
21 */
22int userconfig_receive(struct command *com);
23
24/*
25 * the userconfig:
26 * this is a little unstructured piece of flash set aside for configuration of userapps.
27 * note that this is updated at any time. If the userapp reads flash from interrupts the
28 * flash might change between invokations. if that is a problem the app should copy the
29 * contents into ram from the userloop.
30 */
31/*
32 * return the current size of the userconfig space. 0 means it is invalid, that is "there isn't one"
33 */
34uint32_t userconfig_size();
35/*
36 * each time the config is updated, the version is incremented.
37 * in other words, unless the version is changed, the data remains the same
38 */
39uint32_t userconfig_version();
40/*
41 * this copies the userconfig into a ram buffer, *IF* the version has been updated and *IF* the destination buffer is large enough.
42 * actual_size (if NOT NULL) will contain the actual size of bytes once this completes without an error
43 * RETURN VALUE: 0==ok, anything else is an error (same version is not an error)
44 */
45int userconfig_copy(uint8_t *buf, uint16_t bufsize, uint16_t *actual_size);
46/*
47 * write the userconfig in ram to flash
48 * RETURN VALUE: 0==ok, anything else is an error
49 */
50int write_user_config_to_flash();
51// write but as userconfig
52int userconfig_write(uint8_t *buf, uint32_t size);
53
54#endif