Compare commits
569 Commits
v3.0.0
...
meier/deve
Author | SHA1 | Date | |
---|---|---|---|
b0b75b85a9 | |||
bc994595da | |||
de2d4da161 | |||
19bd26d998 | |||
80cb0e682f | |||
8ee26f81f9 | |||
3556eca8e8 | |||
a9041b84a3 | |||
83d9dbc052 | |||
2220120d54 | |||
15eb22f9ee | |||
7f6c8b8b12 | |||
1a07864a5f | |||
3e9d6bdbb9 | |||
c295539c79 | |||
cddf16f941 | |||
a3dee05fe3 | |||
8edf4c3c8d | |||
8cc94a55ab | |||
daffb6b666 | |||
789668ae50 | |||
7cfb1e6076 | |||
cc36baff78 | |||
4c65109ac0 | |||
861bd15eda | |||
7b979eadff | |||
16714ceb40 | |||
fea301bcc9 | |||
77450eb4b7 | |||
28015c4735 | |||
7d61e67d20 | |||
afcbc8be0a | |||
7760b3063e | |||
d04f88bee0 | |||
e867d09111 | |||
7a2269262b | |||
9731dc1e61 | |||
43aad11859 | |||
3225a8e350 | |||
1c4ea6dd0d | |||
e2eb4bfea4 | |||
29b0a352fc | |||
41682aab3f | |||
8642b13fd1 | |||
6aa72892ed | |||
70f0a72f1b | |||
b5d890eedd | |||
50b1b48678 | |||
0e0dbc74aa | |||
8c34051d8b | |||
b00d83cb1a | |||
17e609c3a5 | |||
64f0166b64 | |||
c80f06fbcb | |||
70eb8325a0 | |||
e796f82203 | |||
5b7ca8c13c | |||
d61fe7db93 | |||
c1be1fe232 | |||
ec2e274f22 | |||
c5a7b98a7d | |||
6a8da303fb | |||
3d047f9629 | |||
1739edd9b0 | |||
466a3639a5 | |||
900ef5b912 | |||
031739ef51 | |||
80be937d9d | |||
b8516b15cb | |||
ac5a54b5da | |||
29015b340b | |||
64274acbeb | |||
ff98c42514 | |||
126ac52975 | |||
70d3197212 | |||
dd90980520 | |||
280b641cbc | |||
24ef96d1b8 | |||
18f9958332 | |||
68231db9a1 | |||
85e849ca00 | |||
617d41c7d5 | |||
cccdced74d | |||
750369b0a6 | |||
539e01deee | |||
4079edc80e | |||
a569990ca2 | |||
9c7eba4431 | |||
513ae9dc10 | |||
effecd4662 | |||
b951cb736a | |||
7e1aed6ad9 | |||
07155e2546 | |||
8c6c8ad3c0 | |||
befaca78c6 | |||
af4f002a25 | |||
9f7b9be800 | |||
2c0f3b52e9 | |||
aa1ea33647 | |||
9798b6b4ab | |||
f0d7eaf35a | |||
b128ef9da9 | |||
085213c60f | |||
613dbe9592 | |||
e949368b06 | |||
4d49cb6a3c | |||
935a8e13a5 | |||
5ff88129b8 | |||
ce17be63f4 | |||
2734d9d758 | |||
352ab43c1f | |||
07f5dbb9ac | |||
97e98eae24 | |||
5ac88f2b15 | |||
b03a6684f9 | |||
afce942bf8 | |||
7c2e50b665 | |||
c04ca704d2 | |||
6aa54fe1d4 | |||
a1d7a56dfa | |||
cb78fefbb3 | |||
c55925959b | |||
4f0669c574 | |||
f0d996ffd2 | |||
f4d05c2c9c | |||
d1151ca707 | |||
82f46992f6 | |||
9947a648df | |||
c45328b34d | |||
478b305fbe | |||
28e93696df | |||
942d1e5e4b | |||
c0f80680ef | |||
7761b66fe2 | |||
acc4c8d975 | |||
fe739aa81a | |||
afe006e234 | |||
95f018a0b0 | |||
8c2105ae0a | |||
ed2c2af4a0 | |||
17771c0497 | |||
82df132e7d | |||
a02619e5a2 | |||
6ce09e968d | |||
290db6ccad | |||
94ed582297 | |||
47ced1efac | |||
85a6e4b129 | |||
f94bc02b6c | |||
5bda877d97 | |||
51e7f1c2f2 | |||
a11d7455df | |||
4dc903fe20 | |||
3325cc18fc | |||
43917d98c0 | |||
e3ffcae3e0 | |||
0677de39aa | |||
aded4fae1e | |||
a011e70665 | |||
7df51f7202 | |||
7530c44849 | |||
e4c6a69f77 | |||
761a0c9bac | |||
c05184e1c4 | |||
b2252bdc0b | |||
7e61ce1ed2 | |||
518666f822 | |||
318cd8e244 | |||
1bc7a91869 | |||
8e26e287c3 | |||
ce2f7c4fdf | |||
b3d2d440d7 | |||
fbf9626fde | |||
fcb6437388 | |||
6c1db8473b | |||
29cf8c9009 | |||
61d0815de8 | |||
127fbeb980 | |||
b42987059a | |||
c2581ff4f5 | |||
7b6f68c509 | |||
532607bf8f | |||
a230dc4313 | |||
a3930dafc5 | |||
4f9797af3b | |||
1a530633ca | |||
8037e8074b | |||
d07e0e5576 | |||
5525466b52 | |||
c2a89bf709 | |||
8dd0b2608d | |||
05495077ec | |||
8ff9eadf30 | |||
082c86ea18 | |||
2800d6f28c | |||
b4effe7a46 | |||
e6e71436c2 | |||
4be45adae6 | |||
a887f852c8 | |||
0d7d2203d2 | |||
cde184f428 | |||
0b3255e463 | |||
df3794dfd8 | |||
d02d5c351d | |||
631a531212 | |||
febecd4b30 | |||
964e311d8b | |||
d43caa8296 | |||
916ed3f56a | |||
3ea9f999b7 | |||
79f3c7324a | |||
23af170229 | |||
b32d1da421 | |||
6f0362b956 | |||
60972228ef | |||
6ea1eabb2d | |||
283a37dccc | |||
acf0cdfba3 | |||
a01002aa5d | |||
b52f19254b | |||
665d8cd479 | |||
10398855a9 | |||
79615e47e4 | |||
e6130263ef | |||
6895dbcc81 | |||
d0fec93dc3 | |||
59ab54b2fb | |||
7095999bd2 | |||
7ffb4107d2 | |||
d9d9a28ef8 | |||
d95582b81b | |||
c60aa68d00 | |||
4b5e3e70f7 | |||
9ce59d3c75 | |||
a0dfdfab2c | |||
3e17011087 | |||
f441505476 | |||
7c64797f03 | |||
bbe21e7e89 | |||
2823420c46 | |||
6dd6f28db0 | |||
d791fc87b7 | |||
16f2fa9327 | |||
927041209b | |||
bac8b40880 | |||
caf78835b2 | |||
b6ed45a85c | |||
ddc1cdb1f5 | |||
543daaa95a | |||
38c87fdeb2 | |||
5ca5fe4040 | |||
1b7e0371c3 | |||
e08bdd3e35 | |||
d2dd16aef3 | |||
b7a617dab3 | |||
bc95e7c886 | |||
fca43b3d34 | |||
48c5c3fbd5 | |||
b694aea100 | |||
6998626ad4 | |||
d4ade5e885 | |||
24ad858b64 | |||
288d453978 | |||
522cbc7f3d | |||
ce5bcc5897 | |||
97c93afeff | |||
8704b9ab06 | |||
5a1585bd00 | |||
5d6de90859 | |||
378c6c8006 | |||
f4922a8686 | |||
0bdcb40609 | |||
fec5f83f4f | |||
17262a1da9 | |||
e684680d60 | |||
aa5d1042f0 | |||
b5d6b9745f | |||
60639f56dc | |||
3aa0bbde68 | |||
14ac852b7e | |||
6b1a81ee92 | |||
3779b44813 | |||
949549178a | |||
7daa9812ff | |||
97bc71a3ff | |||
06577ed78a | |||
ca508bfe61 | |||
b27f3b84aa | |||
345a799031 | |||
9509847b84 | |||
45b51f9ac8 | |||
445d5dd6f0 | |||
d5ff6da40b | |||
e498136273 | |||
238baa8597 | |||
47d158156b | |||
d63c01b96f | |||
3b497dbb8d | |||
bf733162eb | |||
7932afc315 | |||
d1e3dc4d49 | |||
73f0b9c0dc | |||
b5e55f64b0 | |||
77e5fba7fd | |||
ca70c8c614 | |||
7ca6d1a695 | |||
cc3210f366 | |||
155d66e534 | |||
d4c76a7e46 | |||
dba3c27b99 | |||
202cfc6dbb | |||
84f95e8d76 | |||
6de4798805 | |||
82a645deba | |||
8b1c277c58 | |||
14620fdd72 | |||
89c1878622 | |||
d6856fc54a | |||
e5a9cab34e | |||
5f23f709cc | |||
a4f97a7ba7 | |||
8b1af232c3 | |||
983fa346b3 | |||
32f420c4f0 | |||
41a82e923c | |||
5ddac36314 | |||
d06eecf9b0 | |||
a7cb2d4354 | |||
7571987a1d | |||
d6c1041133 | |||
5912ddd2a2 | |||
7db11588b4 | |||
c88b931ef1 | |||
10ffa2f44a | |||
dbe31dd339 | |||
14b44f8bb2 | |||
117747970d | |||
3c53e2c259 | |||
45f0d7fd45 | |||
c6540650e2 | |||
aebab4c73c | |||
c3c2e1c0dd | |||
4e6c1cb72a | |||
f659f13759 | |||
e2eb6a46b6 | |||
75c56280ad | |||
0ccaf27fcb | |||
95078e1103 | |||
e05e203c83 | |||
8920255565 | |||
ac036b2a70 | |||
2d12618c96 | |||
2d9216ba19 | |||
2fed161eff | |||
68ca6fd122 | |||
33e9592659 | |||
19d217e3b9 | |||
af286d3bc6 | |||
4cf2a384f3 | |||
27267b7cb0 | |||
20928732ec | |||
505e00c067 | |||
68225586d2 | |||
6d825a1aa6 | |||
a8426750f2 | |||
2635f39344 | |||
89327463e3 | |||
fa73ad6731 | |||
cf45eca100 | |||
c0fa365f8f | |||
9d9f19781d | |||
f4520ea346 | |||
331aa9442d | |||
bbacdc5cac | |||
28b28b5684 | |||
afd3a942e2 | |||
729bcc4aaf | |||
a6c0f3fef5 | |||
6e0b90696d | |||
eacb4ac407 | |||
09c1918c1f | |||
123f2ff360 | |||
0e8328fca3 | |||
1ef3dae72e | |||
32381a7872 | |||
09815f5cce | |||
f6357b4531 | |||
a10e5c6ed4 | |||
d6d13eec95 | |||
457bc6609e | |||
e75155c329 | |||
d4e48006f2 | |||
d6508e23b6 | |||
2cb254a556 | |||
f99f5ed730 | |||
7ce2c1b624 | |||
5f7e384442 | |||
56d0c8c616 | |||
5ff0f8ea10 | |||
4747e54c5d | |||
2e230daa14 | |||
e909c6b6f7 | |||
d88d7c938f | |||
fdc8a3d4f7 | |||
389641f8fd | |||
e5e85bcff9 | |||
4862edfdb5 | |||
a50b52df51 | |||
eac7e6db07 | |||
0c4835bfb5 | |||
aebd4817b8 | |||
9c2ceb4a9f | |||
b440c30223 | |||
68ace0b74a | |||
d119479c0a | |||
6739890d53 | |||
90b8ad1e6d | |||
025f79fcb4 | |||
3966b656e9 | |||
6fb64f9ada | |||
3a5881a0cb | |||
2f1b923009 | |||
1e982ec00b | |||
701135e2a6 | |||
19f8e41c7f | |||
c4a055986c | |||
d74a373f1d | |||
cf69af4e7e | |||
45ea09291a | |||
b7f3eff742 | |||
508979d32d | |||
0d66569687 | |||
a5871ed0b1 | |||
a12e98d948 | |||
bd05afbddd | |||
b3482eba24 | |||
9e92afbf07 | |||
0d6d44f72f | |||
a274d6598e | |||
c3d78120ea | |||
f24de22e9b | |||
918783774f | |||
6744a55b9b | |||
a612fb446c | |||
a5adeb333c | |||
7788cada54 | |||
074ef29b86 | |||
d4f059d639 | |||
22bc300902 | |||
0d38ac62d8 | |||
d81257a91c | |||
d53c7e1190 | |||
e312cd094a | |||
9e958e752e | |||
3bcd71598d | |||
2602d4fed1 | |||
805538ec6e | |||
120750f22a | |||
9897f51307 | |||
4f87e24f60 | |||
2dcf896cca | |||
81f5b0c3bf | |||
cdf2a90f90 | |||
b25555a533 | |||
062e93fd88 | |||
bc0100ee08 | |||
c6d152a01d | |||
f4f1174849 | |||
9df8722c10 | |||
7208139630 | |||
54f3d7bd2d | |||
7a83289b3d | |||
136524424f | |||
793b97f651 | |||
2e4cd80556 | |||
a4f57a38fa | |||
6dc34fc1f0 | |||
9e6948a8d7 | |||
9b17b282c6 | |||
5f48d77c64 | |||
8ab8c57f9c | |||
c7b9df5e40 | |||
7b8019c621 | |||
baddbf7340 | |||
c20bf31d5d | |||
3c06d2dbbb | |||
018d814f29 | |||
c0648a789b | |||
9579e94a71 | |||
235fd79dfb | |||
80a610141a | |||
f93c173715 | |||
620841a9e5 | |||
bd29688307 | |||
43b7a314b6 | |||
1b41153ee6 | |||
83635d3667 | |||
581ae4c990 | |||
32a9e0c704 | |||
940c53eba6 | |||
0d4bd856bd | |||
b7f6a6961b | |||
a910a05541 | |||
973996e102 | |||
b3aee76d91 | |||
b3151a0ba0 | |||
fca48257b7 | |||
8f95b03e6a | |||
f08d291e3e | |||
06ffe27fcc | |||
e9b0951a95 | |||
348274c145 | |||
40329a33b2 | |||
2d52042ed6 | |||
79936a3335 | |||
527dba9a9d | |||
22cd38fffd | |||
1a518109d0 | |||
8030d9ac1b | |||
992c05df56 | |||
6698d283b6 | |||
33386550cf | |||
3a65c0db91 | |||
41614303d7 | |||
783176848a | |||
07cb980e06 | |||
d8c5bd125e | |||
51add8a8ad | |||
ad5bb4c694 | |||
bf5a11cbd3 | |||
ddcac2bbac | |||
70b593df65 | |||
e5cc7069a6 | |||
98dbaf03e0 | |||
e0c50477cb | |||
30687f84c8 | |||
fed39defd3 | |||
acbc2cd749 | |||
368481f88b | |||
d2b561ba2f | |||
990e8672a8 | |||
9cde8c7f45 | |||
751de7accc | |||
74ae3f1371 | |||
02ac92a6b3 | |||
b83b2e8f89 | |||
8a39971a1c | |||
1ead156c64 | |||
5b968f7e5a | |||
b98127cea6 | |||
eba9abfc9a | |||
bf7fabd7ba | |||
cf3d4d8de3 | |||
8414c9d471 | |||
386843e3e7 | |||
441b3b83c8 | |||
c453af5911 | |||
fe95c3337a | |||
bc5a6b4a51 | |||
371ff931bf | |||
6c63d82f5c | |||
78ddce249c | |||
d93f2c5055 | |||
d39e0c8bb6 | |||
7a84dff7d6 | |||
6a6f6011ba | |||
602fa3a956 | |||
c3a0aabfb8 | |||
5907f8ee9d |
175
CHANGELOG
175
CHANGELOG
@ -1,175 +0,0 @@
|
||||
# Changed from ASTP 1.1.0 to 1.2.0
|
||||
|
||||
## API Changes
|
||||
|
||||
### FSFW Architecture
|
||||
|
||||
- New src folder which contains all source files except the HAL, contributed code and test code
|
||||
- External and internal API mostly stayed the same
|
||||
- Folder names are now all smaller case: internalError was renamed to internalerror and
|
||||
FreeRTOS was renamed to freertos
|
||||
- Warning if optional headers are used but the modules was not added to the source files to compile
|
||||
|
||||
### HAL
|
||||
|
||||
- HAL added back into FSFW. It is tightly bound to the FSFW, and compiling it as a static library
|
||||
made using it more complicated than necessary
|
||||
|
||||
## Bugfixes
|
||||
|
||||
### FreeRTOS QueueMapManager
|
||||
|
||||
- Fixed a bug which causes the first generated Queue ID to be invalid
|
||||
|
||||
## Enhancements
|
||||
|
||||
### FSFW Architecture
|
||||
|
||||
- See API changes chapter. This change will keep the internal API consistent in the future
|
||||
|
||||
# Changes from ASTP 1.0.0 to 1.1.0
|
||||
|
||||
## API Changes
|
||||
|
||||
### PUS
|
||||
|
||||
- Added PUS C support
|
||||
- SUBSYSTEM_IDs added for PUS Services
|
||||
- Added new Parameter which must be defined in config: fsfwconfig::FSFW_MAX_TM_PACKET_SIZE
|
||||
|
||||
### ObjectManager
|
||||
|
||||
- ObjectManager is now a singelton
|
||||
|
||||
|
||||
### Configuration
|
||||
|
||||
- Additional configuration option fsfwconfig::FSFW_MAX_TM_PACKET_SIZE which
|
||||
need to be specified in FSFWConfig.h
|
||||
|
||||
### CMake
|
||||
|
||||
- Changed Cmake FSFW_ADDITIONAL_INC_PATH to FSFW_ADDITIONAL_INC_PATHS
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- timemanager/TimeStamperIF.h: Timestamp config was not used correctly, leading to different timestamp sizes than configured in fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE
|
||||
- TCP server fixes
|
||||
|
||||
## Enhancements
|
||||
|
||||
### FreeRTOS Queue Handles
|
||||
|
||||
- Fixed an internal issue how FreeRTOS MessageQueues were handled
|
||||
|
||||
### Linux OSAL
|
||||
|
||||
- Better printf error messages
|
||||
|
||||
### CMake
|
||||
|
||||
- Check for C++11 as mininimum required Version
|
||||
|
||||
### Debug Output
|
||||
|
||||
- Changed Warning color to magenta, which is well readable on both dark and light mode IDEs
|
||||
|
||||
|
||||
# Changes from ASTP 0.0.1 to 1.0.0
|
||||
|
||||
### Host OSAL
|
||||
|
||||
- Bugfix in MessageQueue, which caused the sender not to be set properly
|
||||
|
||||
### FreeRTOS OSAL
|
||||
|
||||
- vRequestContextSwitchFromISR is declared extern "C" so it can be defined in
|
||||
a C file without issues
|
||||
|
||||
### PUS Services
|
||||
|
||||
- It is now possible to change the message queue depth for the telecommand verification service (PUS1)
|
||||
- The same is possible for the event reporting service (PUS5)
|
||||
- PUS Health Service added, which allows to command and retrieve health via PUS packets
|
||||
|
||||
|
||||
### EnhancedControllerBase
|
||||
|
||||
- New base class for a controller which also implements HasActionsIF and HasLocalDataPoolIF
|
||||
|
||||
### Local Pool
|
||||
|
||||
- Interface of LocalPools has changed. LocalPool is not a template anymore. Instead the size and
|
||||
bucket number of the pools per page and the number of pages are passed to the ctor instead of
|
||||
two ctor arguments and a template parameter
|
||||
|
||||
### Parameter Service
|
||||
|
||||
- The API of the parameter service has been changed to prevent inconsistencies
|
||||
between documentation and actual code and to clarify usage.
|
||||
- The parameter ID now consists of:
|
||||
1. Domain ID (1 byte)
|
||||
2. Unique Identifier (1 byte)
|
||||
3. Linear Index (2 bytes)
|
||||
The linear index can be used for arrays as well as matrices.
|
||||
The parameter load command now explicitely expects the ECSS PTC and PFC
|
||||
information as well as the rows and column number. Rows and column will
|
||||
default to one, which is equivalent to one scalar parameter (the most
|
||||
important use-case)
|
||||
|
||||
### File System Interface
|
||||
|
||||
- A new interfaces specifies the functions for a software object which exposes the file system of
|
||||
a given hardware to use message based file handling (e.g. PUS commanding)
|
||||
|
||||
### Internal Error Reporter
|
||||
|
||||
- The new internal error reporter uses the local data pools. The pool IDs for
|
||||
the exisiting three error values and the new error set will be hardcoded for
|
||||
now, the the constructor for the internal error reporter just takes an object
|
||||
ID for now.
|
||||
|
||||
### Device Handler Base
|
||||
|
||||
- There is an additional `PERFORM_OPERATION` step for the device handler base. It is important
|
||||
that DHB users adapt their polling sequence tables to perform this step. This steps allows for
|
||||
a clear distinction between operation and communication steps
|
||||
- setNormalDatapoolEntriesInvalid is not an abstract method and a default implementation was provided
|
||||
- getTransitionDelayMs is now an abstract method
|
||||
|
||||
### DeviceHandlerIF
|
||||
|
||||
- Typo for UNKNOWN_DEVICE_REPLY
|
||||
|
||||
### Events
|
||||
|
||||
- makeEvent function: Now takes three input parameters instead of two and
|
||||
allows setting a unique ID. Event.cpp source file removed, functions now
|
||||
defined in header directly. Namespaces renamed. Functions declared `constexpr`
|
||||
now
|
||||
|
||||
### Commanding Service Base
|
||||
|
||||
- CSB uses the new fsfwconfig::FSFW_CSB_FIFO_DEPTH variable to determine the FIFO depth for each
|
||||
CSB instance. This variable has to be set in the FSFWConfig.h file
|
||||
|
||||
### Service Interface
|
||||
|
||||
- Proper printf support contained in ServiceInterfacePrinter.h
|
||||
- CPP ostream support now optional (can reduce executable size by 150 - 250 kB)
|
||||
- Amalagated header which determines automatically which service interface to use depending on FSFWConfig.h configuration.
|
||||
Users can just use #include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
- If CPP streams are excluded, sif:: calls won't work anymore and need to be replaced by their printf counterparts.
|
||||
For the fsfw, this can be done by checking the processor define FSFW_CPP_OSTREAM_ENABLED from FSFWConfig.h.
|
||||
For mission code, developers need to replace sif:: calls by the printf counterparts, but only if the CPP stream are excluded.
|
||||
If this is not the case, everything should work as usual.
|
||||
|
||||
### ActionHelper and ActionMessage
|
||||
|
||||
- ActionHelper finish function and ActionMessage::setCompletionReply now expects explicit
|
||||
information whether to report a success or failure message instead of deriving it implicitely
|
||||
from returnvalue
|
||||
|
||||
### PUS Parameter Service 20
|
||||
|
||||
Added PUS parameter service 20 (only custom subservices available).
|
449
CHANGELOG.md
Normal file
449
CHANGELOG.md
Normal file
@ -0,0 +1,449 @@
|
||||
Change Log
|
||||
=======
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v5.0.0]
|
||||
|
||||
## Changes
|
||||
|
||||
- HAL Linux SPI: Set the Clock Default State when setting new SPI speed
|
||||
and mode
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/573
|
||||
- GPIO HAL: `Direction`, `GpioOperation` and `Levels` are enum classes now, which prevents
|
||||
name clashes with Windows defines.
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
|
||||
- New CMake option `FSFW_HAL_LINUX_ADD_LIBGPIOD` to specifically exclude `gpiod` code.
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
|
||||
- HAL Devicehandlers: Periodic printout is run-time configurable now
|
||||
- `oneShotAction` flag in the `TestTask` class is not static anymore
|
||||
- HAL Linux Uart: Baudrate and bits per word are enums now, avoiding misconfigurations
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/585
|
||||
- Major update for version handling, using `git describe` to fetch version information with git.
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/601
|
||||
- Place `Version` class outside of `fsfw` namespace. It is generic
|
||||
- Add helper functions provided by [`cmake-modules`](https://github.com/bilke/cmake-modules)
|
||||
manually now. Those should not change too often and only a small subset is needed
|
||||
- Separate folder for easier update and for distinction
|
||||
- LICENSE file included
|
||||
- use `int` for version numbers to allow unset or uninitialized version
|
||||
- Initialize Version object with numbers set to -1
|
||||
- Instead of hardcoding the git hash, it is now retrieved from git
|
||||
- `Version` now allows specifying additional version information like the git SHA1 hash and the
|
||||
versions since the last tag
|
||||
- Additional information is set to the last part of the git describe output for `FSFW_VERSION` now.
|
||||
- Version still need to be hand-updated if the FSFW is not included as a submodule for now.
|
||||
- IPC Message Queue Handling: Allow passing an optional `MqArgs` argument into the MessageQueue
|
||||
creation call. It allows passing context information and an arbitrary user argument into
|
||||
the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/583
|
||||
- Clock:
|
||||
- `timeval` to `TimeOfDay_t`
|
||||
- Added Mutex for gmtime calls: (compare http://www.opengate.at/blog/2020/01/timeless/)
|
||||
- Moved the statics used by Clock in ClockCommon.cpp to this file
|
||||
- Better check for leap seconds
|
||||
- Added Unittests for Clock (only getter)
|
||||
|
||||
## Removed
|
||||
|
||||
- Removed the `HkSwitchHelper`. This module should not be needed anymore, now that the local
|
||||
datapools have been implemented.
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/557
|
||||
|
||||
## Additions
|
||||
|
||||
- Linux HAL: Add wiretapping option for I2C. Enabled with `FSFW_HAL_I2C_WIRETAPPING` defined to 1
|
||||
- Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information
|
||||
inside `fsfw/version.h`
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/559
|
||||
- Added ETL dependency and improved library dependency management
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/592
|
||||
|
||||
## Fixed
|
||||
|
||||
- Small bugfix in STM32 HAL for SPI
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/599
|
||||
- HAL GPIO: Improved error checking in `LinuxLibgpioIF::configureGpios(...)`. If a GPIO
|
||||
configuration fails, the function will exit prematurely with a dedicated error code
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/602
|
||||
|
||||
# [v4.0.0]
|
||||
|
||||
## Additions
|
||||
|
||||
- CFDP Packet Stack and related tests added. It also refactors the existing TMTC infastructure to
|
||||
allow sending of CFDP packets to the CCSDS handlers.
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/528
|
||||
- added virtual function to print datasets
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/544
|
||||
- doSendRead Hook
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/545
|
||||
- Dockumentation for DHB
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/551
|
||||
|
||||
### HAL additions
|
||||
|
||||
- Linux Command Executor, which can execute shell commands in blocking and non-blocking mode
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/536
|
||||
- uio Mapper
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/543
|
||||
|
||||
## Changes
|
||||
|
||||
- Applied the `clang-format` auto-formatter to all source code
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/534
|
||||
- Updated Catch2 to v3.0.0-preview4
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/538
|
||||
- Changed CI to use prebuilt docker image
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/549
|
||||
|
||||
## Bugfix
|
||||
|
||||
- CMake fixes in PR https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/533 , was problematic
|
||||
if the uppermost user `CMakeLists.txt` did not have the include paths set up properly, which
|
||||
could lead to compile errors that `#include "fsfw/FSFW.h"` was not found.
|
||||
- Fix for build regression in Catch2 v3.0.0-preview4
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/548
|
||||
- Fix in unittest which failed on CI
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/552
|
||||
- Fix in helper script
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/553
|
||||
|
||||
## API Changes
|
||||
|
||||
- Aforementioned changes to existing TMTC stack
|
||||
|
||||
## Known bugs
|
||||
|
||||
-
|
||||
|
||||
# [v3.0.1]
|
||||
|
||||
## API Changes
|
||||
|
||||
*
|
||||
|
||||
## Bugfixes
|
||||
|
||||
* Version number was not updated for v3.0.0 #542
|
||||
|
||||
## Enhancement
|
||||
|
||||
*
|
||||
|
||||
## Known bugs
|
||||
|
||||
*
|
||||
|
||||
# [v3.0.0]
|
||||
|
||||
## API Changes
|
||||
|
||||
#### TCP Socket Changes
|
||||
|
||||
* Keep Open TCP Implementation #496
|
||||
* The socket will now kept open after disconnect. This allows reconnecting.
|
||||
* Only one connection is allowed
|
||||
* No internal influence but clients need to change their Code.
|
||||
|
||||
### GPIO IF
|
||||
|
||||
* Add feature to open GPIO by line name #506
|
||||
|
||||
### Bitutil
|
||||
|
||||
* Unittests for Op Divider and Bitutility #510
|
||||
|
||||
### Filesystem IF changed
|
||||
|
||||
* Filesystem Base Interface: Use IF instead of void pointer #511
|
||||
|
||||
### STM32
|
||||
|
||||
* STM32 SPI Updates #518
|
||||
|
||||
## Bugfixes
|
||||
|
||||
* Small bugfix for LIS3 handler #504
|
||||
* Spelling fixed for function names #509
|
||||
* CMakeLists fixes #517
|
||||
* Out of bound reads and writes in unittests #519
|
||||
* Bug in TmPacketStoredPusC (#478)
|
||||
* Windows ifdef fixed #529
|
||||
|
||||
## Enhancement
|
||||
|
||||
* FSFW.h.in more default values #491
|
||||
* Minor updates for PUS services #498
|
||||
* HasReturnvaluesIF naming for parameter #499
|
||||
* Tests can now be built as part of FSFW and versioning moved to CMake #500
|
||||
* Added integration test code #508
|
||||
* More printouts for rejected TC packets #505
|
||||
* Arrayprinter format improvements #514
|
||||
* Adding code for CI with docker and jenkins #520
|
||||
* Added new function in SerializeAdapter #513
|
||||
* Enables simple deSerialize if you keep track of the buffer position yourself
|
||||
* `` static ReturnValue_t deSerialize(T *object, const uint8_t* buffer,
|
||||
size_t* deserSize, SerializeIF::Endianness streamEndianness) ``
|
||||
* Unittest helper scripts has a new Parameter to open the coverage html in the webrowser #525
|
||||
* ``'-o', '--open', Open coverage data in webbrowser``
|
||||
* Documentation updated. Sphinx Documentation can now be build with python script #526
|
||||
|
||||
## Known bugs
|
||||
|
||||
* Version number was not updated for v3.0.0 #542
|
||||
|
||||
|
||||
All Pull Requests:
|
||||
|
||||
Milestone: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/milestone/19
|
||||
|
||||
# [v2.0.0]
|
||||
|
||||
## API Changes
|
||||
|
||||
|
||||
### File Structure changed to fit more common structure
|
||||
|
||||
* See pull request (#445)
|
||||
* HAL is now part of the main project
|
||||
* **See Instructions below:**
|
||||
|
||||
#### Instruction how to update existing / user code
|
||||
|
||||
* Changes in `#include`:
|
||||
* Rename `internalError` in includes to `internalerror`
|
||||
* Rename `fsfw/hal` to `fsfw_hal`
|
||||
* Rename `fsfw/tests` to `fsfw_tests`
|
||||
* Rename `osal/FreeRTOS` to `osal/freertos`
|
||||
|
||||
* Changes in `CMakeLists.txt`:
|
||||
* Rename `OS_FSFW` to `FSFW_OSAL`
|
||||
|
||||
* Changes in `DleEncoder.cpp`
|
||||
* Create an instance of the `DleEncoder` first before calling the `encode` and `decode` functions
|
||||
|
||||
### Removed osal/linux/Timer (#486)
|
||||
|
||||
* Was redundant to timemanager/Countdown
|
||||
|
||||
#### Instruction how to update existing / user code
|
||||
|
||||
* Use timemanager/Countdown instead
|
||||
|
||||
## Bugfixes
|
||||
|
||||
### TM Stack
|
||||
|
||||
* Increased TM stack robustness by introducing `nullptr` checks and more printouts (#483)
|
||||
|
||||
#### Host OSAL / FreeRTOS
|
||||
|
||||
* QueueMapManager Bugfix (NO_QUEUE was used as MessageQueueId) (#444)
|
||||
|
||||
#### Events
|
||||
|
||||
* Event output is now consistent (#447)
|
||||
|
||||
#### DLE Encoder
|
||||
|
||||
* Fixed possible out of bounds access in DLE Encoder (#492)
|
||||
|
||||
## Enhancment
|
||||
|
||||
* HAL as major new feature, also includes three MEMS devicehandlers as part of #481
|
||||
* Linux HAL updates (#456)
|
||||
* FreeRTOS Header cleaning update and Cmake tweaks (#442)
|
||||
* Printer updates (#453)
|
||||
* New returnvalue for for empty PST (#485)
|
||||
* TMTC Bridge: Increase limit of packets stored (#484)
|
||||
|
||||
## Known bugs
|
||||
|
||||
* Bug in TmPacketStoredPusC (#478)
|
||||
|
||||
|
||||
All Pull Requests:
|
||||
|
||||
Milestone: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/milestone/5
|
||||
|
||||
# [v1.2.0]
|
||||
|
||||
## API Changes
|
||||
|
||||
### FSFW Architecture
|
||||
|
||||
- New src folder which contains all source files except the HAL, contributed code and test code
|
||||
- External and internal API mostly stayed the same
|
||||
- Folder names are now all smaller case: internalError was renamed to internalerror and
|
||||
FreeRTOS was renamed to freertos
|
||||
- Warning if optional headers are used but the modules was not added to the source files to compile
|
||||
|
||||
### HAL
|
||||
|
||||
- HAL added back into FSFW. It is tightly bound to the FSFW, and compiling it as a static library
|
||||
made using it more complicated than necessary
|
||||
|
||||
## Bugfixes
|
||||
|
||||
### FreeRTOS QueueMapManager
|
||||
|
||||
- Fixed a bug which causes the first generated Queue ID to be invalid
|
||||
|
||||
## Enhancements
|
||||
|
||||
### FSFW Architecture
|
||||
|
||||
- See API changes chapter. This change will keep the internal API consistent in the future
|
||||
|
||||
# [v1.1.0]
|
||||
|
||||
## API Changes
|
||||
|
||||
### PUS
|
||||
|
||||
- Added PUS C support
|
||||
- SUBSYSTEM_IDs added for PUS Services
|
||||
- Added new Parameter which must be defined in config: fsfwconfig::FSFW_MAX_TM_PACKET_SIZE
|
||||
|
||||
### ObjectManager
|
||||
|
||||
- ObjectManager is now a singelton
|
||||
|
||||
|
||||
### Configuration
|
||||
|
||||
- Additional configuration option fsfwconfig::FSFW_MAX_TM_PACKET_SIZE which
|
||||
need to be specified in FSFWConfig.h
|
||||
|
||||
### CMake
|
||||
|
||||
- Changed Cmake FSFW_ADDITIONAL_INC_PATH to FSFW_ADDITIONAL_INC_PATHS
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- timemanager/TimeStamperIF.h: Timestamp config was not used correctly, leading to different timestamp sizes than configured in fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE
|
||||
- TCP server fixes
|
||||
|
||||
## Enhancements
|
||||
|
||||
### FreeRTOS Queue Handles
|
||||
|
||||
- Fixed an internal issue how FreeRTOS MessageQueues were handled
|
||||
|
||||
### Linux OSAL
|
||||
|
||||
- Better printf error messages
|
||||
|
||||
### CMake
|
||||
|
||||
- Check for C++11 as mininimum required Version
|
||||
|
||||
### Debug Output
|
||||
|
||||
- Changed Warning color to magenta, which is well readable on both dark and light mode IDEs
|
||||
|
||||
|
||||
# Changes from ASTP 0.0.1 to 1.0.0
|
||||
|
||||
### Host OSAL
|
||||
|
||||
- Bugfix in MessageQueue, which caused the sender not to be set properly
|
||||
|
||||
### FreeRTOS OSAL
|
||||
|
||||
- vRequestContextSwitchFromISR is declared extern "C" so it can be defined in
|
||||
a C file without issues
|
||||
|
||||
### PUS Services
|
||||
|
||||
- It is now possible to change the message queue depth for the telecommand verification service (PUS1)
|
||||
- The same is possible for the event reporting service (PUS5)
|
||||
- PUS Health Service added, which allows to command and retrieve health via PUS packets
|
||||
|
||||
|
||||
### EnhancedControllerBase
|
||||
|
||||
- New base class for a controller which also implements HasActionsIF and HasLocalDataPoolIF
|
||||
|
||||
### Local Pool
|
||||
|
||||
- Interface of LocalPools has changed. LocalPool is not a template anymore. Instead the size and
|
||||
bucket number of the pools per page and the number of pages are passed to the ctor instead of
|
||||
two ctor arguments and a template parameter
|
||||
|
||||
### Parameter Service
|
||||
|
||||
- The API of the parameter service has been changed to prevent inconsistencies
|
||||
between documentation and actual code and to clarify usage.
|
||||
- The parameter ID now consists of:
|
||||
1. Domain ID (1 byte)
|
||||
2. Unique Identifier (1 byte)
|
||||
3. Linear Index (2 bytes)
|
||||
The linear index can be used for arrays as well as matrices.
|
||||
The parameter load command now explicitely expects the ECSS PTC and PFC
|
||||
information as well as the rows and column number. Rows and column will
|
||||
default to one, which is equivalent to one scalar parameter (the most
|
||||
important use-case)
|
||||
|
||||
### File System Interface
|
||||
|
||||
- A new interfaces specifies the functions for a software object which exposes the file system of
|
||||
a given hardware to use message based file handling (e.g. PUS commanding)
|
||||
|
||||
### Internal Error Reporter
|
||||
|
||||
- The new internal error reporter uses the local data pools. The pool IDs for
|
||||
the exisiting three error values and the new error set will be hardcoded for
|
||||
now, the the constructor for the internal error reporter just takes an object
|
||||
ID for now.
|
||||
|
||||
### Device Handler Base
|
||||
|
||||
- There is an additional `PERFORM_OPERATION` step for the device handler base. It is important
|
||||
that DHB users adapt their polling sequence tables to perform this step. This steps allows for
|
||||
a clear distinction between operation and communication steps
|
||||
- setNormalDatapoolEntriesInvalid is not an abstract method and a default implementation was provided
|
||||
- getTransitionDelayMs is now an abstract method
|
||||
|
||||
### DeviceHandlerIF
|
||||
|
||||
- Typo for UNKNOWN_DEVICE_REPLY
|
||||
|
||||
### Events
|
||||
|
||||
- makeEvent function: Now takes three input parameters instead of two and
|
||||
allows setting a unique ID. Event.cpp source file removed, functions now
|
||||
defined in header directly. Namespaces renamed. Functions declared `constexpr`
|
||||
now
|
||||
|
||||
### Commanding Service Base
|
||||
|
||||
- CSB uses the new fsfwconfig::FSFW_CSB_FIFO_DEPTH variable to determine the FIFO depth for each
|
||||
CSB instance. This variable has to be set in the FSFWConfig.h file
|
||||
|
||||
### Service Interface
|
||||
|
||||
- Proper printf support contained in ServiceInterfacePrinter.h
|
||||
- CPP ostream support now optional (can reduce executable size by 150 - 250 kB)
|
||||
- Amalagated header which determines automatically which service interface to use depending on FSFWConfig.h configuration.
|
||||
Users can just use #include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
- If CPP streams are excluded, sif:: calls won't work anymore and need to be replaced by their printf counterparts.
|
||||
For the fsfw, this can be done by checking the processor define FSFW_CPP_OSTREAM_ENABLED from FSFWConfig.h.
|
||||
For mission code, developers need to replace sif:: calls by the printf counterparts, but only if the CPP stream are excluded.
|
||||
If this is not the case, everything should work as usual.
|
||||
|
||||
### ActionHelper and ActionMessage
|
||||
|
||||
- ActionHelper finish function and ActionMessage::setCompletionReply now expects explicit
|
||||
information whether to report a success or failure message instead of deriving it implicitely
|
||||
from returnvalue
|
||||
|
||||
### PUS Parameter Service 20
|
||||
|
||||
Added PUS parameter service 20 (only custom subservices available).
|
157
CMakeLists.txt
157
CMakeLists.txt
@ -1,11 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(${LIB_FSFW_NAME})
|
||||
|
||||
set(FSFW_VERSION 2)
|
||||
set(FSFW_SUBVERSION 0)
|
||||
set(FSFW_REVISION 0)
|
||||
set(FSFW_VERSION_IF_GIT_FAILS 4)
|
||||
set(FSFW_SUBVERSION_IF_GIT_FAILS 0)
|
||||
set(FSFW_REVISION_IF_GIT_FAILS 0)
|
||||
|
||||
# Add the cmake folder so the FindSphinx module is found
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules")
|
||||
set(MSG_PREFIX "fsfw |")
|
||||
|
||||
set(FSFW_ETL_LIB_MAJOR_VERSION 20 CACHE STRING
|
||||
"ETL library major version requirement"
|
||||
)
|
||||
set(FSFW_ETL_LIB_VERSION ${FSFW_ETL_LIB_MAJOR_VERSION}.27.3 CACHE STRING
|
||||
"ETL library exact version requirement"
|
||||
)
|
||||
set(FSFW_ETL_LINK_TARGET etl::etl)
|
||||
|
||||
set(FSFW_CATCH2_LIB_MAJOR_VERSION 3 CACHE STRING
|
||||
"Catch2 library major version requirement"
|
||||
)
|
||||
set(FSFW_CATCH2_LIB_VERSION v${FSFW_CATCH2_LIB_MAJOR_VERSION}.0.0-preview5 CACHE STRING
|
||||
"Catch2 library exact version requirement"
|
||||
)
|
||||
|
||||
set(FSFW_ETL_LIB_NAME etl)
|
||||
|
||||
option(FSFW_GENERATE_SECTIONS
|
||||
"Generate function and data sections. Required to remove unused code" ON
|
||||
@ -42,24 +62,56 @@ set(LIB_FSFW_NAME fsfw)
|
||||
set(FSFW_TEST_TGT fsfw-tests)
|
||||
set(FSFW_DUMMY_TGT fsfw-dummy)
|
||||
|
||||
project(${LIB_FSFW_NAME})
|
||||
add_library(${LIB_FSFW_NAME})
|
||||
|
||||
set(FSFW_GIT_VER_HANDLING_OK FALSE)
|
||||
# Version handling
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
|
||||
message(STATUS "${MSG_PREFIX} Determining version information with git")
|
||||
include(FsfwHelpers)
|
||||
determine_version_with_git("--exclude" "docker_*")
|
||||
if(GIT_INFO)
|
||||
set(FSFW_GIT_INFO ${GIT_INFO} CACHE STRING "Version information retrieved with git describe")
|
||||
list(GET FSFW_GIT_INFO 1 FSFW_VERSION)
|
||||
list(GET FSFW_GIT_INFO 2 FSFW_SUBVERSION)
|
||||
list(GET FSFW_GIT_INFO 3 FSFW_REVISION)
|
||||
list(GET FSFW_GIT_INFO 4 FSFW_VERSION_CST_GIT_SHA1)
|
||||
if(NOT FSFW_VERSION)
|
||||
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS})
|
||||
endif()
|
||||
if(NOT FSFW_SUBVERSION)
|
||||
set(FSFW_SUBVERSION ${FSFW_SUBVERSION_IF_GIT_FAILS})
|
||||
endif()
|
||||
if(NOT FSFW_REVISION)
|
||||
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS})
|
||||
endif()
|
||||
set(FSFW_GIT_VER_HANDLING_OK TRUE)
|
||||
else()
|
||||
set(FSFW_GIT_VER_HANDLING_OK FALSE)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT FSFW_GIT_VER_HANDLING_OK)
|
||||
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS})
|
||||
set(FSFW_SUBVERSION ${FSFW_SUBVERSION_IF_GIT_FAILS})
|
||||
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS})
|
||||
endif()
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
message(STATUS "Building the FSFW unittests in addition to the static library")
|
||||
message(STATUS "${MSG_PREFIX} Building the FSFW unittests in addition to the static library")
|
||||
# Check whether the user has already installed Catch2 first
|
||||
find_package(Catch2 3)
|
||||
find_package(Catch2 ${FSFW_CATCH2_LIB_MAJOR_VERSION} CONFIG QUIET)
|
||||
# Not installed, so use FetchContent to download and provide Catch2
|
||||
if(NOT Catch2_FOUND)
|
||||
message(STATUS "${MSG_PREFIX} Catch2 installation not found. Downloading Catch2 library with FetchContent")
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.0.0-preview3
|
||||
GIT_TAG ${FSFW_CATCH2_LIB_VERSION}
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
list(APPEND FSFW_FETCH_CONTENT_TARGETS Catch2)
|
||||
endif()
|
||||
|
||||
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
|
||||
@ -70,19 +122,46 @@ if(FSFW_BUILD_UNITTESTS)
|
||||
add_executable(${FSFW_TEST_TGT})
|
||||
|
||||
if(FSFW_TESTS_GEN_COV)
|
||||
message(STATUS "Generating coverage data for the library")
|
||||
message(STATUS "Targets linking against ${LIB_FSFW_NAME} "
|
||||
message(STATUS "${MSG_PREFIX} Generating coverage data for the library")
|
||||
message(STATUS "${MSG_PREFIX} Targets linking against ${LIB_FSFW_NAME} "
|
||||
"will be compiled with coverage data as well"
|
||||
)
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
include(CodeCoverage)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Finding and/or providing etl library with version ${FSFW_ETL_LIB_MAJOR_VERSION}")
|
||||
|
||||
# Check whether the user has already installed ETL first
|
||||
find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET)
|
||||
# Not installed, so use FetchContent to download and provide etl
|
||||
if(NOT ${FSFW_ETL_LIB_NAME}_FOUND)
|
||||
message(STATUS
|
||||
"No ETL installation was found with find_package. Installing and providing "
|
||||
"etl with FindPackage"
|
||||
)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cmake-modules
|
||||
GIT_REPOSITORY https://github.com/bilke/cmake-modules.git
|
||||
${FSFW_ETL_LIB_NAME}
|
||||
GIT_REPOSITORY https://github.com/ETLCPP/etl
|
||||
GIT_TAG ${FSFW_ETL_LIB_VERSION}
|
||||
)
|
||||
FetchContent_MakeAvailable(cmake-modules)
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
list(APPEND CMAKE_MODULE_PATH ${cmake-modules_SOURCE_DIR})
|
||||
include(CodeCoverage)
|
||||
list(APPEND FSFW_FETCH_CONTENT_TARGETS ${FSFW_ETL_LIB_NAME})
|
||||
endif()
|
||||
|
||||
# The documentation for FetchContent recommends declaring all the dependencies
|
||||
# before making them available. We make all declared dependency available here
|
||||
# after their declaration
|
||||
if(FSFW_FETCH_CONTENT_TARGETS)
|
||||
FetchContent_MakeAvailable(${FSFW_FETCH_CONTENT_TARGETS})
|
||||
if(TARGET ${FSFW_ETL_LIB_NAME})
|
||||
add_library(${FSFW_ETL_LINK_TARGET} ALIAS ${FSFW_ETL_LIB_NAME})
|
||||
endif()
|
||||
if(TARGET Catch2)
|
||||
# Fixes regression -preview4, to be confirmed in later releases
|
||||
# Related GitHub issue: https://github.com/catchorg/Catch2/issues/2417
|
||||
set_target_properties(Catch2 PROPERTIES DEBUG_POSTFIX "")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -90,7 +169,7 @@ set(FSFW_CORE_INC_PATH "inc")
|
||||
|
||||
set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos)
|
||||
|
||||
# Configure Files
|
||||
# For configure files
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
@ -102,17 +181,17 @@ if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
elseif(${CMAKE_CXX_STANDARD} LESS 11)
|
||||
message(FATAL_ERROR "Compiling the FSFW requires a minimum of C++11 support")
|
||||
message(FATAL_ERROR "${MSG_PREFIX} Compiling the FSFW requires a minimum of C++11 support")
|
||||
endif()
|
||||
|
||||
# Backwards comptability
|
||||
if(OS_FSFW AND NOT FSFW_OSAL)
|
||||
message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
|
||||
message(WARNING "${MSG_PREFIX} Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
|
||||
set(FSFW_OSAL OS_FSFW)
|
||||
endif()
|
||||
|
||||
if(NOT FSFW_OSAL)
|
||||
message(STATUS "No OS for FSFW via FSFW_OSAL set. Assuming host OS")
|
||||
message(STATUS "${MSG_PREFIX} No OS for FSFW via FSFW_OSAL set. Assuming host OS")
|
||||
# Assume host OS and autodetermine from OS_FSFW
|
||||
if(UNIX)
|
||||
set(FSFW_OSAL "linux"
|
||||
@ -146,21 +225,16 @@ elseif(FSFW_OSAL STREQUAL rtems)
|
||||
set(FSFW_OSAL_RTEMS ON)
|
||||
else()
|
||||
message(WARNING
|
||||
"Invalid operating system for FSFW specified! Setting to host.."
|
||||
"${MSG_PREFIX} Invalid operating system for FSFW specified! Setting to host.."
|
||||
)
|
||||
set(FSFW_OS_NAME "Host")
|
||||
set(OS_FSFW "host")
|
||||
endif()
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS OR FSFW_BUILD_DOCS)
|
||||
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
|
||||
else()
|
||||
configure_file(src/fsfw/FSFW.h.in FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h)
|
||||
endif()
|
||||
|
||||
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
|
||||
message(STATUS "${MSG_PREFIX} Compiling FSFW for the ${FSFW_OS_NAME} operating system")
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
||||
@ -197,13 +271,13 @@ if(FSFW_BUILD_UNITTESTS)
|
||||
"--exclude-unreachable-branches"
|
||||
)
|
||||
set(COVERAGE_EXCLUDES
|
||||
"/c/msys64/mingw64/*"
|
||||
"/c/msys64/mingw64/*" "*/fsfw_hal/*"
|
||||
)
|
||||
elseif(UNIX)
|
||||
set(COVERAGE_EXCLUDES
|
||||
"/usr/include/*" "/usr/bin/*" "Catch2/*"
|
||||
"/usr/local/include/*" "*/fsfw_tests/*"
|
||||
"*/catch2-src/*"
|
||||
"*/catch2-src/*" "*/fsfw_hal/*"
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -244,8 +318,8 @@ endif()
|
||||
if(NOT FSFW_CONFIG_PATH)
|
||||
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
||||
if(NOT FSFW_BUILD_DOCS)
|
||||
message(WARNING "Flight Software Framework configuration path not set!")
|
||||
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||
message(WARNING "${MSG_PREFIX} Flight Software Framework configuration path not set")
|
||||
message(WARNING "${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||
endif()
|
||||
add_subdirectory(${DEF_CONF_PATH})
|
||||
set(FSFW_CONFIG_PATH ${DEF_CONF_PATH})
|
||||
@ -284,6 +358,24 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
-Wimplicit-fallthrough=1
|
||||
-Wno-unused-parameter
|
||||
-Wno-psabi
|
||||
-Wduplicated-cond # check for duplicate conditions
|
||||
-Wduplicated-branches # check for duplicate branches
|
||||
-Wlogical-op # Search for bitwise operations instead of logical
|
||||
-Wnull-dereference # Search for NULL dereference
|
||||
-Wundef # Warn if undefind marcos are used
|
||||
-Wformat=2 # Format string problem detection
|
||||
-Wformat-overflow=2 # Formatting issues in printf
|
||||
-Wformat-truncation=2 # Formatting issues in printf
|
||||
-Wformat-security # Search for dangerous printf operations
|
||||
-Wstrict-overflow=3 # Warn if integer overflows might happen
|
||||
-Warray-bounds=2 # Some array bounds violations will be found
|
||||
-Wshift-overflow=2 # Search for bit left shift overflows (<c++14)
|
||||
-Wcast-qual # Warn if the constness is cast away
|
||||
-Wstringop-overflow=4
|
||||
# -Wstack-protector # Emits a few false positives for low level access
|
||||
# -Wconversion # Creates many false positives
|
||||
# -Warith-conversion # Use with Wconversion to find more implicit conversions
|
||||
# -fanalyzer # Should be used to look through problems
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -334,6 +426,7 @@ target_compile_options(${LIB_FSFW_NAME} PRIVATE
|
||||
)
|
||||
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
${FSFW_ETL_LINK_TARGET}
|
||||
${FSFW_ADDITIONAL_LINK_LIBS}
|
||||
)
|
||||
|
||||
|
85
README.md
85
README.md
@ -11,9 +11,15 @@ with Airbus Defence and Space GmbH.
|
||||
|
||||
## Quick facts
|
||||
|
||||
The framework is designed for systems, which communicate with external devices, perform control loops, receive telecommands and send telemetry, and need to maintain a high level of availability. Therefore, a mode and health system provides control over the states of the software and the controlled devices. In addition, a simple mechanism of event based fault detection, isolation and recovery is implemented as well.
|
||||
The framework is designed for systems, which communicate with external devices, perform control loops,
|
||||
receive telecommands and send telemetry, and need to maintain a high level of availability. Therefore,
|
||||
a mode and health system provides control over the states of the software and the controlled devices.
|
||||
In addition, a simple mechanism of event based fault detection, isolation and recovery is implemented as well.
|
||||
|
||||
The FSFW provides abstraction layers for operating systems to provide a uniform operating system abstraction layer (OSAL). Some components of this OSAL are required internally by the FSFW but is also very useful for developers to implement the same application logic on different operating systems with a uniform interface.
|
||||
The FSFW provides abstraction layers for operating systems to provide a uniform operating system
|
||||
abstraction layer (OSAL). Some components of this OSAL are required internally by the FSFW but is
|
||||
also very useful for developers to implement the same application logic on different operating
|
||||
systems with a uniform interface.
|
||||
|
||||
Currently, the FSFW provides the following OSALs:
|
||||
|
||||
@ -45,6 +51,28 @@ A template configuration folder was provided and can be copied into the project
|
||||
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||
information about the possible options.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
The Embedded Template Library (etl) is a dependency of the FSFW which is automatically
|
||||
installed and provided by the build system unless the correction version was installed.
|
||||
The current recommended version can be found inside the fsfw `CMakeLists.txt` file or by using
|
||||
`ccmake` and looking up the `FSFW_ETL_LIB_MAJOR_VERSION` variable.
|
||||
|
||||
You can install the ETL library like this. On Linux, it might be necessary to add `sudo` before
|
||||
the install call:
|
||||
|
||||
```cpp
|
||||
git clone https://github.com/ETLCPP/etl
|
||||
cd etl
|
||||
git checkout <currentRecommendedVersion>
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
cmake --install .
|
||||
```
|
||||
|
||||
It is recommended to install `20.27.2` or newer for the package version handling of
|
||||
ETL to work.
|
||||
|
||||
## Adding the library
|
||||
|
||||
The following steps show how to add and use FSFW components. It is still recommended to
|
||||
@ -72,7 +100,7 @@ add and link against the FSFW library in general.
|
||||
4. Link against the FSFW library
|
||||
|
||||
```cmake
|
||||
target_link_libraries(<YourProjectName> PRIVATE fsfw)
|
||||
target_link_libraries(${YourProjectName} PRIVATE fsfw)
|
||||
```
|
||||
|
||||
5. It should now be possible use the FSFW as a static library from the user code.
|
||||
@ -83,6 +111,19 @@ The FSFW also has unittests which use the [Catch2 library](https://github.com/ca
|
||||
These are built by setting the CMake option `FSFW_BUILD_UNITTESTS` to `ON` or `TRUE`
|
||||
from your project `CMakeLists.txt` file or from the command line.
|
||||
|
||||
You can install the Catch2 library, which prevents the build system to avoid re-downloading
|
||||
the dependency if the unit tests are completely rebuilt. The current recommended version
|
||||
can be found inside the fsfw `CMakeLists.txt` file or by using `ccmake` and looking up
|
||||
the `FSFW_CATCH2_LIB_VERSION` variable.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/catchorg/Catch2.git
|
||||
cd Catch2
|
||||
git checkout <currentRecommendedVersion>
|
||||
cmake -Bbuild -H. -DBUILD_TESTING=OFF
|
||||
sudo cmake --build build/ --target install
|
||||
```
|
||||
|
||||
The fsfw-tests binary will be built as part of the static library and dropped alongside it.
|
||||
If the unittests are built, the library and the tests will be built with coverage information by
|
||||
default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`.
|
||||
@ -91,7 +132,7 @@ You can use the following commands inside the `fsfw` folder to set up the build
|
||||
|
||||
```sh
|
||||
mkdir build-Unittest && cd build-Unittest
|
||||
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host ..
|
||||
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug ..
|
||||
```
|
||||
|
||||
You can also use `-DFSFW_OSAL=linux` on Linux systems.
|
||||
@ -107,6 +148,42 @@ cmake --build . -- fsfw-tests_coverage -j
|
||||
|
||||
The `coverage.py` script located in the `script` folder can also be used to do this conveniently.
|
||||
|
||||
## Building the documentations
|
||||
|
||||
The FSFW documentation is built using the tools Sphinx, doxygen and breathe based on the
|
||||
instructions provided in [this blogpost](https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/). If you
|
||||
want to do this locally, set up the prerequisites first. This requires a ``python3``
|
||||
installation as well. Example here is for Ubuntu.
|
||||
|
||||
```sh
|
||||
sudo apt-get install doxygen graphviz
|
||||
```
|
||||
|
||||
And the following Python packages
|
||||
|
||||
```sh
|
||||
python3 -m pip install sphinx breathe
|
||||
```
|
||||
|
||||
You can set up a documentation build system using the following commands
|
||||
|
||||
```sh
|
||||
mkdir build-docs && cd build-docs
|
||||
cmake -DFSFW_BUILD_DOCS=ON -DFSFW_OSAL=host ..
|
||||
```
|
||||
|
||||
Then you can generate the documentation using
|
||||
|
||||
```sh
|
||||
cmake --build . -j
|
||||
```
|
||||
|
||||
You can find the generated documentation inside the `docs/sphinx` folder inside the build
|
||||
folder. Simply open the `index.html` in the webbrowser of your choice.
|
||||
|
||||
The `helper.py` script located in the script` folder can also be used to create, build
|
||||
and open the documentation conveniently. Try `helper.py -h for more information.
|
||||
|
||||
## Formatting the sources
|
||||
|
||||
The formatting is done by the `clang-format` tool. The configuration is contained within the
|
||||
|
@ -5,4 +5,10 @@ RUN apt-get --yes upgrade
|
||||
|
||||
#tzdata is a dependency, won't install otherwise
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano
|
||||
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano iputils-ping
|
||||
|
||||
RUN git clone https://github.com/catchorg/Catch2.git && \
|
||||
cd Catch2 && \
|
||||
git checkout v3.0.0-preview5 && \
|
||||
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
|
||||
cmake --build build/ --target install
|
||||
|
43
automation/Jenkinsfile
vendored
43
automation/Jenkinsfile
vendored
@ -1,28 +1,17 @@
|
||||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
BUILDDIR = 'build-unittests'
|
||||
BUILDDIR = 'build-tests'
|
||||
}
|
||||
agent {
|
||||
docker { image 'fsfw-ci:d2'}
|
||||
}
|
||||
stages {
|
||||
stage('Create Docker') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
additionalBuildArgs '--no-cache'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
stage('Clean') {
|
||||
steps {
|
||||
sh 'rm -rf $BUILDDIR'
|
||||
}
|
||||
}
|
||||
stage('Configure') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
|
||||
@ -30,38 +19,20 @@ pipeline {
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake --build . -j'
|
||||
sh 'cmake --build . -j4'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Unittests') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake --build . -- fsfw-tests_coverage -j'
|
||||
sh 'cmake --build . -- fsfw-tests_coverage -j4'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Valgrind') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
|
||||
|
28
cmake/FsfwHelpers.cmake
Normal file
28
cmake/FsfwHelpers.cmake
Normal file
@ -0,0 +1,28 @@
|
||||
# Determines the git version with git describe and returns it by setting
|
||||
# the GIT_INFO list in the parent scope. The list has the following entries
|
||||
# 1. Full version string
|
||||
# 2. Major version
|
||||
# 3. Minor version
|
||||
# 4. Revision
|
||||
# 5. git SHA hash and commits since tag
|
||||
function(determine_version_with_git)
|
||||
include(GetGitRevisionDescription)
|
||||
git_describe(VERSION ${ARGN})
|
||||
string(FIND ${VERSION} "." VALID_VERSION)
|
||||
if(VALID_VERSION EQUAL -1)
|
||||
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
|
||||
return()
|
||||
endif()
|
||||
# Parse the version information into pieces.
|
||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" _VERSION_MAJOR "${VERSION}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" _VERSION_MINOR "${VERSION}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" _VERSION_PATCH "${VERSION}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
|
||||
set(GIT_INFO ${VERSION})
|
||||
list(APPEND GIT_INFO ${_VERSION_MAJOR})
|
||||
list(APPEND GIT_INFO ${_VERSION_MINOR})
|
||||
list(APPEND GIT_INFO ${_VERSION_PATCH})
|
||||
list(APPEND GIT_INFO ${VERSION_SHA1})
|
||||
set(GIT_INFO ${GIT_INFO} PARENT_SCOPE)
|
||||
message(STATUS "${MSG_PREFIX} Set git version info into GIT_INFO from the git tag ${VERSION}")
|
||||
endfunction()
|
719
cmake/cmake-modules/CodeCoverage.cmake
Normal file
719
cmake/cmake-modules/CodeCoverage.cmake
Normal file
@ -0,0 +1,719 @@
|
||||
# Copyright (c) 2012 - 2017, Lars Bilke
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# CHANGES:
|
||||
#
|
||||
# 2012-01-31, Lars Bilke
|
||||
# - Enable Code Coverage
|
||||
#
|
||||
# 2013-09-17, Joakim Söderberg
|
||||
# - Added support for Clang.
|
||||
# - Some additional usage instructions.
|
||||
#
|
||||
# 2016-02-03, Lars Bilke
|
||||
# - Refactored functions to use named parameters
|
||||
#
|
||||
# 2017-06-02, Lars Bilke
|
||||
# - Merged with modified version from github.com/ufz/ogs
|
||||
#
|
||||
# 2019-05-06, Anatolii Kurotych
|
||||
# - Remove unnecessary --coverage flag
|
||||
#
|
||||
# 2019-12-13, FeRD (Frank Dana)
|
||||
# - Deprecate COVERAGE_LCOVR_EXCLUDES and COVERAGE_GCOVR_EXCLUDES lists in favor
|
||||
# of tool-agnostic COVERAGE_EXCLUDES variable, or EXCLUDE setup arguments.
|
||||
# - CMake 3.4+: All excludes can be specified relative to BASE_DIRECTORY
|
||||
# - All setup functions: accept BASE_DIRECTORY, EXCLUDE list
|
||||
# - Set lcov basedir with -b argument
|
||||
# - Add automatic --demangle-cpp in lcovr, if 'c++filt' is available (can be
|
||||
# overridden with NO_DEMANGLE option in setup_target_for_coverage_lcovr().)
|
||||
# - Delete output dir, .info file on 'make clean'
|
||||
# - Remove Python detection, since version mismatches will break gcovr
|
||||
# - Minor cleanup (lowercase function names, update examples...)
|
||||
#
|
||||
# 2019-12-19, FeRD (Frank Dana)
|
||||
# - Rename Lcov outputs, make filtered file canonical, fix cleanup for targets
|
||||
#
|
||||
# 2020-01-19, Bob Apthorpe
|
||||
# - Added gfortran support
|
||||
#
|
||||
# 2020-02-17, FeRD (Frank Dana)
|
||||
# - Make all add_custom_target()s VERBATIM to auto-escape wildcard characters
|
||||
# in EXCLUDEs, and remove manual escaping from gcovr targets
|
||||
#
|
||||
# 2021-01-19, Robin Mueller
|
||||
# - Add CODE_COVERAGE_VERBOSE option which will allow to print out commands which are run
|
||||
# - Added the option for users to set the GCOVR_ADDITIONAL_ARGS variable to supply additional
|
||||
# flags to the gcovr command
|
||||
#
|
||||
# 2020-05-04, Mihchael Davis
|
||||
# - Add -fprofile-abs-path to make gcno files contain absolute paths
|
||||
# - Fix BASE_DIRECTORY not working when defined
|
||||
# - Change BYPRODUCT from folder to index.html to stop ninja from complaining about double defines
|
||||
#
|
||||
# 2021-05-10, Martin Stump
|
||||
# - Check if the generator is multi-config before warning about non-Debug builds
|
||||
#
|
||||
# 2022-02-22, Marko Wehle
|
||||
# - Change gcovr output from -o <filename> for --xml <filename> and --html <filename> output respectively.
|
||||
# This will allow for Multiple Output Formats at the same time by making use of GCOVR_ADDITIONAL_ARGS, e.g. GCOVR_ADDITIONAL_ARGS "--txt".
|
||||
#
|
||||
# USAGE:
|
||||
#
|
||||
# 1. Copy this file into your cmake modules path.
|
||||
#
|
||||
# 2. Add the following line to your CMakeLists.txt (best inside an if-condition
|
||||
# using a CMake option() to enable it just optionally):
|
||||
# include(CodeCoverage)
|
||||
#
|
||||
# 3. Append necessary compiler flags for all supported source files:
|
||||
# append_coverage_compiler_flags()
|
||||
# Or for specific target:
|
||||
# append_coverage_compiler_flags_to_target(YOUR_TARGET_NAME)
|
||||
#
|
||||
# 3.a (OPTIONAL) Set appropriate optimization flags, e.g. -O0, -O1 or -Og
|
||||
#
|
||||
# 4. If you need to exclude additional directories from the report, specify them
|
||||
# using full paths in the COVERAGE_EXCLUDES variable before calling
|
||||
# setup_target_for_coverage_*().
|
||||
# Example:
|
||||
# set(COVERAGE_EXCLUDES
|
||||
# '${PROJECT_SOURCE_DIR}/src/dir1/*'
|
||||
# '/path/to/my/src/dir2/*')
|
||||
# Or, use the EXCLUDE argument to setup_target_for_coverage_*().
|
||||
# Example:
|
||||
# setup_target_for_coverage_lcov(
|
||||
# NAME coverage
|
||||
# EXECUTABLE testrunner
|
||||
# EXCLUDE "${PROJECT_SOURCE_DIR}/src/dir1/*" "/path/to/my/src/dir2/*")
|
||||
#
|
||||
# 4.a NOTE: With CMake 3.4+, COVERAGE_EXCLUDES or EXCLUDE can also be set
|
||||
# relative to the BASE_DIRECTORY (default: PROJECT_SOURCE_DIR)
|
||||
# Example:
|
||||
# set(COVERAGE_EXCLUDES "dir1/*")
|
||||
# setup_target_for_coverage_gcovr_html(
|
||||
# NAME coverage
|
||||
# EXECUTABLE testrunner
|
||||
# BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/src"
|
||||
# EXCLUDE "dir2/*")
|
||||
#
|
||||
# 5. Use the functions described below to create a custom make target which
|
||||
# runs your test executable and produces a code coverage report.
|
||||
#
|
||||
# 6. Build a Debug build:
|
||||
# cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||
# make
|
||||
# make my_coverage_target
|
||||
#
|
||||
|
||||
include(CMakeParseArguments)
|
||||
|
||||
option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)
|
||||
|
||||
# Check prereqs
|
||||
find_program( GCOV_PATH gcov )
|
||||
find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
|
||||
find_program( FASTCOV_PATH NAMES fastcov fastcov.py )
|
||||
find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat )
|
||||
find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
|
||||
find_program( CPPFILT_PATH NAMES c++filt )
|
||||
|
||||
if(NOT GCOV_PATH)
|
||||
message(FATAL_ERROR "gcov not found! Aborting...")
|
||||
endif() # NOT GCOV_PATH
|
||||
|
||||
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
list(GET LANGUAGES 0 LANG)
|
||||
|
||||
if("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
||||
if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3)
|
||||
message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
|
||||
endif()
|
||||
elseif(NOT CMAKE_COMPILER_IS_GNUCXX)
|
||||
if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "[Ff]lang")
|
||||
# Do nothing; exit conditional without error if true
|
||||
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
|
||||
# Do nothing; exit conditional without error if true
|
||||
else()
|
||||
message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(COVERAGE_COMPILER_FLAGS "-g -fprofile-arcs -ftest-coverage"
|
||||
CACHE INTERNAL "")
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag(-fprofile-abs-path HAVE_fprofile_abs_path)
|
||||
if(HAVE_fprofile_abs_path)
|
||||
set(COVERAGE_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_Fortran_FLAGS_COVERAGE
|
||||
${COVERAGE_COMPILER_FLAGS}
|
||||
CACHE STRING "Flags used by the Fortran compiler during coverage builds."
|
||||
FORCE )
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE
|
||||
${COVERAGE_COMPILER_FLAGS}
|
||||
CACHE STRING "Flags used by the C++ compiler during coverage builds."
|
||||
FORCE )
|
||||
set(CMAKE_C_FLAGS_COVERAGE
|
||||
${COVERAGE_COMPILER_FLAGS}
|
||||
CACHE STRING "Flags used by the C compiler during coverage builds."
|
||||
FORCE )
|
||||
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||
""
|
||||
CACHE STRING "Flags used for linking binaries during coverage builds."
|
||||
FORCE )
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
||||
""
|
||||
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
|
||||
FORCE )
|
||||
mark_as_advanced(
|
||||
CMAKE_Fortran_FLAGS_COVERAGE
|
||||
CMAKE_CXX_FLAGS_COVERAGE
|
||||
CMAKE_C_FLAGS_COVERAGE
|
||||
CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
|
||||
|
||||
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG))
|
||||
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
|
||||
endif() # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)
|
||||
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
||||
link_libraries(gcov)
|
||||
endif()
|
||||
|
||||
# Defines a target for running and collection code coverage information
|
||||
# Builds dependencies, runs the given executable and outputs reports.
|
||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
||||
# the coverage generation will not complete.
|
||||
#
|
||||
# setup_target_for_coverage_lcov(
|
||||
# NAME testrunner_coverage # New target name
|
||||
# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
||||
# DEPENDENCIES testrunner # Dependencies to build first
|
||||
# BASE_DIRECTORY "../" # Base directory for report
|
||||
# # (defaults to PROJECT_SOURCE_DIR)
|
||||
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
|
||||
# # to BASE_DIRECTORY, with CMake 3.4+)
|
||||
# NO_DEMANGLE # Don't demangle C++ symbols
|
||||
# # even if c++filt is found
|
||||
# )
|
||||
function(setup_target_for_coverage_lcov)
|
||||
|
||||
set(options NO_DEMANGLE)
|
||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS GENHTML_ARGS)
|
||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT LCOV_PATH)
|
||||
message(FATAL_ERROR "lcov not found! Aborting...")
|
||||
endif() # NOT LCOV_PATH
|
||||
|
||||
if(NOT GENHTML_PATH)
|
||||
message(FATAL_ERROR "genhtml not found! Aborting...")
|
||||
endif() # NOT GENHTML_PATH
|
||||
|
||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
||||
if(DEFINED Coverage_BASE_DIRECTORY)
|
||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
||||
else()
|
||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
||||
set(LCOV_EXCLUDES "")
|
||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_LCOV_EXCLUDES})
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.4)
|
||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
||||
endif()
|
||||
list(APPEND LCOV_EXCLUDES "${EXCLUDE}")
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES LCOV_EXCLUDES)
|
||||
|
||||
# Conditional arguments
|
||||
if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
|
||||
set(GENHTML_EXTRA_ARGS "--demangle-cpp")
|
||||
endif()
|
||||
|
||||
# Setting up commands which will be run to generate coverage data.
|
||||
# Cleanup lcov
|
||||
set(LCOV_CLEAN_CMD
|
||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -directory .
|
||||
-b ${BASEDIR} --zerocounters
|
||||
)
|
||||
# Create baseline to make sure untouched files show up in the report
|
||||
set(LCOV_BASELINE_CMD
|
||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -c -i -d . -b
|
||||
${BASEDIR} -o ${Coverage_NAME}.base
|
||||
)
|
||||
# Run tests
|
||||
set(LCOV_EXEC_TESTS_CMD
|
||||
${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
|
||||
)
|
||||
# Capturing lcov counters and generating report
|
||||
set(LCOV_CAPTURE_CMD
|
||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory . -b
|
||||
${BASEDIR} --capture --output-file ${Coverage_NAME}.capture
|
||||
)
|
||||
# add baseline counters
|
||||
set(LCOV_BASELINE_COUNT_CMD
|
||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -a ${Coverage_NAME}.base
|
||||
-a ${Coverage_NAME}.capture --output-file ${Coverage_NAME}.total
|
||||
)
|
||||
# filter collected data to final coverage report
|
||||
set(LCOV_FILTER_CMD
|
||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --remove
|
||||
${Coverage_NAME}.total ${LCOV_EXCLUDES} --output-file ${Coverage_NAME}.info
|
||||
)
|
||||
# Generate HTML output
|
||||
set(LCOV_GEN_HTML_CMD
|
||||
${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o
|
||||
${Coverage_NAME} ${Coverage_NAME}.info
|
||||
)
|
||||
|
||||
|
||||
if(CODE_COVERAGE_VERBOSE)
|
||||
message(STATUS "Executed command report")
|
||||
message(STATUS "Command to clean up lcov: ")
|
||||
string(REPLACE ";" " " LCOV_CLEAN_CMD_SPACED "${LCOV_CLEAN_CMD}")
|
||||
message(STATUS "${LCOV_CLEAN_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to create baseline: ")
|
||||
string(REPLACE ";" " " LCOV_BASELINE_CMD_SPACED "${LCOV_BASELINE_CMD}")
|
||||
message(STATUS "${LCOV_BASELINE_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to run the tests: ")
|
||||
string(REPLACE ";" " " LCOV_EXEC_TESTS_CMD_SPACED "${LCOV_EXEC_TESTS_CMD}")
|
||||
message(STATUS "${LCOV_EXEC_TESTS_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to capture counters and generate report: ")
|
||||
string(REPLACE ";" " " LCOV_CAPTURE_CMD_SPACED "${LCOV_CAPTURE_CMD}")
|
||||
message(STATUS "${LCOV_CAPTURE_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to add baseline counters: ")
|
||||
string(REPLACE ";" " " LCOV_BASELINE_COUNT_CMD_SPACED "${LCOV_BASELINE_COUNT_CMD}")
|
||||
message(STATUS "${LCOV_BASELINE_COUNT_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to filter collected data: ")
|
||||
string(REPLACE ";" " " LCOV_FILTER_CMD_SPACED "${LCOV_FILTER_CMD}")
|
||||
message(STATUS "${LCOV_FILTER_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to generate lcov HTML output: ")
|
||||
string(REPLACE ";" " " LCOV_GEN_HTML_CMD_SPACED "${LCOV_GEN_HTML_CMD}")
|
||||
message(STATUS "${LCOV_GEN_HTML_CMD_SPACED}")
|
||||
endif()
|
||||
|
||||
# Setup target
|
||||
add_custom_target(${Coverage_NAME}
|
||||
COMMAND ${LCOV_CLEAN_CMD}
|
||||
COMMAND ${LCOV_BASELINE_CMD}
|
||||
COMMAND ${LCOV_EXEC_TESTS_CMD}
|
||||
COMMAND ${LCOV_CAPTURE_CMD}
|
||||
COMMAND ${LCOV_BASELINE_COUNT_CMD}
|
||||
COMMAND ${LCOV_FILTER_CMD}
|
||||
COMMAND ${LCOV_GEN_HTML_CMD}
|
||||
|
||||
# Set output files as GENERATED (will be removed on 'make clean')
|
||||
BYPRODUCTS
|
||||
${Coverage_NAME}.base
|
||||
${Coverage_NAME}.capture
|
||||
${Coverage_NAME}.total
|
||||
${Coverage_NAME}.info
|
||||
${Coverage_NAME}/index.html
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
DEPENDS ${Coverage_DEPENDENCIES}
|
||||
VERBATIM # Protect arguments to commands
|
||||
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
|
||||
)
|
||||
|
||||
# Show where to find the lcov info report
|
||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
||||
COMMAND ;
|
||||
COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info."
|
||||
)
|
||||
|
||||
# Show info where to find the report
|
||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
||||
COMMAND ;
|
||||
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
|
||||
)
|
||||
|
||||
endfunction() # setup_target_for_coverage_lcov
|
||||
|
||||
# Defines a target for running and collection code coverage information
|
||||
# Builds dependencies, runs the given executable and outputs reports.
|
||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
||||
# the coverage generation will not complete.
|
||||
#
|
||||
# setup_target_for_coverage_gcovr_xml(
|
||||
# NAME ctest_coverage # New target name
|
||||
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
||||
# DEPENDENCIES executable_target # Dependencies to build first
|
||||
# BASE_DIRECTORY "../" # Base directory for report
|
||||
# # (defaults to PROJECT_SOURCE_DIR)
|
||||
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
|
||||
# # to BASE_DIRECTORY, with CMake 3.4+)
|
||||
# )
|
||||
# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
|
||||
# GCVOR command.
|
||||
function(setup_target_for_coverage_gcovr_xml)
|
||||
|
||||
set(options NONE)
|
||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT GCOVR_PATH)
|
||||
message(FATAL_ERROR "gcovr not found! Aborting...")
|
||||
endif() # NOT GCOVR_PATH
|
||||
|
||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
||||
if(DEFINED Coverage_BASE_DIRECTORY)
|
||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
||||
else()
|
||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
||||
set(GCOVR_EXCLUDES "")
|
||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.4)
|
||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
||||
endif()
|
||||
list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
|
||||
|
||||
# Combine excludes to several -e arguments
|
||||
set(GCOVR_EXCLUDE_ARGS "")
|
||||
foreach(EXCLUDE ${GCOVR_EXCLUDES})
|
||||
list(APPEND GCOVR_EXCLUDE_ARGS "-e")
|
||||
list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
|
||||
endforeach()
|
||||
|
||||
# Set up commands which will be run to generate coverage data
|
||||
# Run tests
|
||||
set(GCOVR_XML_EXEC_TESTS_CMD
|
||||
${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
|
||||
)
|
||||
# Running gcovr
|
||||
set(GCOVR_XML_CMD
|
||||
${GCOVR_PATH} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
|
||||
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
if(CODE_COVERAGE_VERBOSE)
|
||||
message(STATUS "Executed command report")
|
||||
|
||||
message(STATUS "Command to run tests: ")
|
||||
string(REPLACE ";" " " GCOVR_XML_EXEC_TESTS_CMD_SPACED "${GCOVR_XML_EXEC_TESTS_CMD}")
|
||||
message(STATUS "${GCOVR_XML_EXEC_TESTS_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to generate gcovr XML coverage data: ")
|
||||
string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}")
|
||||
message(STATUS "${GCOVR_XML_CMD_SPACED}")
|
||||
endif()
|
||||
|
||||
add_custom_target(${Coverage_NAME}
|
||||
COMMAND ${GCOVR_XML_EXEC_TESTS_CMD}
|
||||
COMMAND ${GCOVR_XML_CMD}
|
||||
|
||||
BYPRODUCTS ${Coverage_NAME}.xml
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
DEPENDS ${Coverage_DEPENDENCIES}
|
||||
VERBATIM # Protect arguments to commands
|
||||
COMMENT "Running gcovr to produce Cobertura code coverage report."
|
||||
)
|
||||
|
||||
# Show info where to find the report
|
||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
||||
COMMAND ;
|
||||
COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
|
||||
)
|
||||
endfunction() # setup_target_for_coverage_gcovr_xml
|
||||
|
||||
# Defines a target for running and collection code coverage information
|
||||
# Builds dependencies, runs the given executable and outputs reports.
|
||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
||||
# the coverage generation will not complete.
|
||||
#
|
||||
# setup_target_for_coverage_gcovr_html(
|
||||
# NAME ctest_coverage # New target name
|
||||
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
||||
# DEPENDENCIES executable_target # Dependencies to build first
|
||||
# BASE_DIRECTORY "../" # Base directory for report
|
||||
# # (defaults to PROJECT_SOURCE_DIR)
|
||||
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
|
||||
# # to BASE_DIRECTORY, with CMake 3.4+)
|
||||
# )
|
||||
# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
|
||||
# GCVOR command.
|
||||
function(setup_target_for_coverage_gcovr_html)
|
||||
|
||||
set(options NONE)
|
||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT GCOVR_PATH)
|
||||
message(FATAL_ERROR "gcovr not found! Aborting...")
|
||||
endif() # NOT GCOVR_PATH
|
||||
|
||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
||||
if(DEFINED Coverage_BASE_DIRECTORY)
|
||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
||||
else()
|
||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
||||
set(GCOVR_EXCLUDES "")
|
||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.4)
|
||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
||||
endif()
|
||||
list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
|
||||
|
||||
# Combine excludes to several -e arguments
|
||||
set(GCOVR_EXCLUDE_ARGS "")
|
||||
foreach(EXCLUDE ${GCOVR_EXCLUDES})
|
||||
list(APPEND GCOVR_EXCLUDE_ARGS "-e")
|
||||
list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
|
||||
endforeach()
|
||||
|
||||
# Set up commands which will be run to generate coverage data
|
||||
# Run tests
|
||||
set(GCOVR_HTML_EXEC_TESTS_CMD
|
||||
${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
|
||||
)
|
||||
# Create folder
|
||||
set(GCOVR_HTML_FOLDER_CMD
|
||||
${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${Coverage_NAME}
|
||||
)
|
||||
# Running gcovr
|
||||
set(GCOVR_HTML_CMD
|
||||
${GCOVR_PATH} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
|
||||
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
if(CODE_COVERAGE_VERBOSE)
|
||||
message(STATUS "Executed command report")
|
||||
|
||||
message(STATUS "Command to run tests: ")
|
||||
string(REPLACE ";" " " GCOVR_HTML_EXEC_TESTS_CMD_SPACED "${GCOVR_HTML_EXEC_TESTS_CMD}")
|
||||
message(STATUS "${GCOVR_HTML_EXEC_TESTS_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to create a folder: ")
|
||||
string(REPLACE ";" " " GCOVR_HTML_FOLDER_CMD_SPACED "${GCOVR_HTML_FOLDER_CMD}")
|
||||
message(STATUS "${GCOVR_HTML_FOLDER_CMD_SPACED}")
|
||||
|
||||
message(STATUS "Command to generate gcovr HTML coverage data: ")
|
||||
string(REPLACE ";" " " GCOVR_HTML_CMD_SPACED "${GCOVR_HTML_CMD}")
|
||||
message(STATUS "${GCOVR_HTML_CMD_SPACED}")
|
||||
endif()
|
||||
|
||||
add_custom_target(${Coverage_NAME}
|
||||
COMMAND ${GCOVR_HTML_EXEC_TESTS_CMD}
|
||||
COMMAND ${GCOVR_HTML_FOLDER_CMD}
|
||||
COMMAND ${GCOVR_HTML_CMD}
|
||||
|
||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html # report directory
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
DEPENDS ${Coverage_DEPENDENCIES}
|
||||
VERBATIM # Protect arguments to commands
|
||||
COMMENT "Running gcovr to produce HTML code coverage report."
|
||||
)
|
||||
|
||||
# Show info where to find the report
|
||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
||||
COMMAND ;
|
||||
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
|
||||
)
|
||||
|
||||
endfunction() # setup_target_for_coverage_gcovr_html
|
||||
|
||||
# Defines a target for running and collection code coverage information
|
||||
# Builds dependencies, runs the given executable and outputs reports.
|
||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
||||
# the coverage generation will not complete.
|
||||
#
|
||||
# setup_target_for_coverage_fastcov(
|
||||
# NAME testrunner_coverage # New target name
|
||||
# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
||||
# DEPENDENCIES testrunner # Dependencies to build first
|
||||
# BASE_DIRECTORY "../" # Base directory for report
|
||||
# # (defaults to PROJECT_SOURCE_DIR)
|
||||
# EXCLUDE "src/dir1/" "src/dir2/" # Patterns to exclude.
|
||||
# NO_DEMANGLE # Don't demangle C++ symbols
|
||||
# # even if c++filt is found
|
||||
# SKIP_HTML # Don't create html report
|
||||
# POST_CMD perl -i -pe s!${PROJECT_SOURCE_DIR}/!!g ctest_coverage.json # E.g. for stripping source dir from file paths
|
||||
# )
|
||||
function(setup_target_for_coverage_fastcov)
|
||||
|
||||
set(options NO_DEMANGLE SKIP_HTML)
|
||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES FASTCOV_ARGS GENHTML_ARGS POST_CMD)
|
||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT FASTCOV_PATH)
|
||||
message(FATAL_ERROR "fastcov not found! Aborting...")
|
||||
endif()
|
||||
|
||||
if(NOT Coverage_SKIP_HTML AND NOT GENHTML_PATH)
|
||||
message(FATAL_ERROR "genhtml not found! Aborting...")
|
||||
endif()
|
||||
|
||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
||||
if(Coverage_BASE_DIRECTORY)
|
||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
||||
else()
|
||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# Collect excludes (Patterns, not paths, for fastcov)
|
||||
set(FASTCOV_EXCLUDES "")
|
||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_FASTCOV_EXCLUDES})
|
||||
list(APPEND FASTCOV_EXCLUDES "${EXCLUDE}")
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES FASTCOV_EXCLUDES)
|
||||
|
||||
# Conditional arguments
|
||||
if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
|
||||
set(GENHTML_EXTRA_ARGS "--demangle-cpp")
|
||||
endif()
|
||||
|
||||
# Set up commands which will be run to generate coverage data
|
||||
set(FASTCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS})
|
||||
|
||||
set(FASTCOV_CAPTURE_CMD ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
|
||||
--search-directory ${BASEDIR}
|
||||
--process-gcno
|
||||
--output ${Coverage_NAME}.json
|
||||
--exclude ${FASTCOV_EXCLUDES}
|
||||
--exclude ${FASTCOV_EXCLUDES}
|
||||
)
|
||||
|
||||
set(FASTCOV_CONVERT_CMD ${FASTCOV_PATH}
|
||||
-C ${Coverage_NAME}.json --lcov --output ${Coverage_NAME}.info
|
||||
)
|
||||
|
||||
if(Coverage_SKIP_HTML)
|
||||
set(FASTCOV_HTML_CMD ";")
|
||||
else()
|
||||
set(FASTCOV_HTML_CMD ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS}
|
||||
-o ${Coverage_NAME} ${Coverage_NAME}.info
|
||||
)
|
||||
endif()
|
||||
|
||||
set(FASTCOV_POST_CMD ";")
|
||||
if(Coverage_POST_CMD)
|
||||
set(FASTCOV_POST_CMD ${Coverage_POST_CMD})
|
||||
endif()
|
||||
|
||||
if(CODE_COVERAGE_VERBOSE)
|
||||
message(STATUS "Code coverage commands for target ${Coverage_NAME} (fastcov):")
|
||||
|
||||
message(" Running tests:")
|
||||
string(REPLACE ";" " " FASTCOV_EXEC_TESTS_CMD_SPACED "${FASTCOV_EXEC_TESTS_CMD}")
|
||||
message(" ${FASTCOV_EXEC_TESTS_CMD_SPACED}")
|
||||
|
||||
message(" Capturing fastcov counters and generating report:")
|
||||
string(REPLACE ";" " " FASTCOV_CAPTURE_CMD_SPACED "${FASTCOV_CAPTURE_CMD}")
|
||||
message(" ${FASTCOV_CAPTURE_CMD_SPACED}")
|
||||
|
||||
message(" Converting fastcov .json to lcov .info:")
|
||||
string(REPLACE ";" " " FASTCOV_CONVERT_CMD_SPACED "${FASTCOV_CONVERT_CMD}")
|
||||
message(" ${FASTCOV_CONVERT_CMD_SPACED}")
|
||||
|
||||
if(NOT Coverage_SKIP_HTML)
|
||||
message(" Generating HTML report: ")
|
||||
string(REPLACE ";" " " FASTCOV_HTML_CMD_SPACED "${FASTCOV_HTML_CMD}")
|
||||
message(" ${FASTCOV_HTML_CMD_SPACED}")
|
||||
endif()
|
||||
if(Coverage_POST_CMD)
|
||||
message(" Running post command: ")
|
||||
string(REPLACE ";" " " FASTCOV_POST_CMD_SPACED "${FASTCOV_POST_CMD}")
|
||||
message(" ${FASTCOV_POST_CMD_SPACED}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Setup target
|
||||
add_custom_target(${Coverage_NAME}
|
||||
|
||||
# Cleanup fastcov
|
||||
COMMAND ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
|
||||
--search-directory ${BASEDIR}
|
||||
--zerocounters
|
||||
|
||||
COMMAND ${FASTCOV_EXEC_TESTS_CMD}
|
||||
COMMAND ${FASTCOV_CAPTURE_CMD}
|
||||
COMMAND ${FASTCOV_CONVERT_CMD}
|
||||
COMMAND ${FASTCOV_HTML_CMD}
|
||||
COMMAND ${FASTCOV_POST_CMD}
|
||||
|
||||
# Set output files as GENERATED (will be removed on 'make clean')
|
||||
BYPRODUCTS
|
||||
${Coverage_NAME}.info
|
||||
${Coverage_NAME}.json
|
||||
${Coverage_NAME}/index.html # report directory
|
||||
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
DEPENDS ${Coverage_DEPENDENCIES}
|
||||
VERBATIM # Protect arguments to commands
|
||||
COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report."
|
||||
)
|
||||
|
||||
set(INFO_MSG "fastcov code coverage info report saved in ${Coverage_NAME}.info and ${Coverage_NAME}.json.")
|
||||
if(NOT Coverage_SKIP_HTML)
|
||||
string(APPEND INFO_MSG " Open ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html in your browser to view the coverage report.")
|
||||
endif()
|
||||
# Show where to find the fastcov info report
|
||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E echo ${INFO_MSG}
|
||||
)
|
||||
|
||||
endfunction() # setup_target_for_coverage_fastcov
|
||||
|
||||
function(append_coverage_compiler_flags)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
|
||||
endfunction() # append_coverage_compiler_flags
|
||||
|
||||
# Setup coverage for specific library
|
||||
function(append_coverage_compiler_flags_to_target name)
|
||||
target_compile_options(${name}
|
||||
PRIVATE ${COVERAGE_COMPILER_FLAGS})
|
||||
endfunction()
|
141
cmake/cmake-modules/GetGitRevisionDescription.cmake
Normal file
141
cmake/cmake-modules/GetGitRevisionDescription.cmake
Normal file
@ -0,0 +1,141 @@
|
||||
# - Returns a version string from Git
|
||||
#
|
||||
# These functions force a re-configure on each git commit so that you can
|
||||
# trust the values of the variables in your build system.
|
||||
#
|
||||
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the refspec and sha hash of the current head revision
|
||||
#
|
||||
# git_describe(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the source tree, and adjusting
|
||||
# the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe --exact-match on the source tree,
|
||||
# and adjusting the output so that it tests false if there was no exact
|
||||
# matching tag.
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(__get_git_revision_description)
|
||||
return()
|
||||
endif()
|
||||
set(__get_git_revision_description YES)
|
||||
|
||||
# We must run the following at "include" time, not at function call time,
|
||||
# to find the path to this module rather than the path to a calling list file
|
||||
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
|
||||
function(get_git_head_revision _refspecvar _hashvar)
|
||||
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
|
||||
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
|
||||
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
|
||||
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
|
||||
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
|
||||
# We have reached the root directory, we are not in git
|
||||
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
|
||||
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
|
||||
endwhile()
|
||||
# check if this is a submodule
|
||||
if(NOT IS_DIRECTORY ${GIT_DIR})
|
||||
file(READ ${GIT_DIR} submodule)
|
||||
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
|
||||
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
|
||||
|
||||
if (IS_ABSOLUTE ${GIT_DIR_RELATIVE})
|
||||
set(GIT_DIR ${GIT_DIR_RELATIVE})
|
||||
else()
|
||||
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
||||
if(NOT EXISTS "${GIT_DATA}")
|
||||
file(MAKE_DIRECTORY "${GIT_DATA}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${GIT_DIR}/HEAD")
|
||||
return()
|
||||
endif()
|
||||
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
||||
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
|
||||
|
||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
||||
"${GIT_DATA}/grabRef.cmake"
|
||||
@ONLY)
|
||||
include("${GIT_DATA}/grabRef.cmake")
|
||||
|
||||
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
|
||||
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# TODO sanitize
|
||||
#if((${ARGN}" MATCHES "&&") OR
|
||||
# (ARGN MATCHES "||") OR
|
||||
# (ARGN MATCHES "\\;"))
|
||||
# message("Please report the following error to the project!")
|
||||
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
|
||||
#endif()
|
||||
|
||||
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
||||
|
||||
execute_process(COMMAND
|
||||
${GIT_EXECUTABLE}
|
||||
describe
|
||||
${hash}
|
||||
${ARGN}
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
RESULT_VARIABLE
|
||||
res
|
||||
OUTPUT_VARIABLE
|
||||
out
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var} "${out}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_get_exact_tag _var)
|
||||
git_describe(out --exact-match ${ARGN})
|
||||
set(${_var} "${out}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_get_tag _var)
|
||||
git_describe(out --tags ${ARGN})
|
||||
set(${_var} "${out}" PARENT_SCOPE)
|
||||
endfunction()
|
38
cmake/cmake-modules/GetGitRevisionDescription.cmake.in
Normal file
38
cmake/cmake-modules/GetGitRevisionDescription.cmake.in
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# Internal file for GetGitRevisionDescription.cmake
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
set(HEAD_HASH)
|
||||
|
||||
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
||||
|
||||
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
||||
if(HEAD_CONTENTS MATCHES "ref")
|
||||
# named branch
|
||||
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
||||
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
set(HEAD_HASH "${HEAD_REF}")
|
||||
endif()
|
||||
else()
|
||||
# detached HEAD
|
||||
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
endif()
|
||||
|
||||
if(NOT HEAD_HASH)
|
||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||
endif()
|
23
cmake/cmake-modules/LICENSE_1_0.txt
Normal file
23
cmake/cmake-modules/LICENSE_1_0.txt
Normal file
@ -0,0 +1,23 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
5
cmake/cmake-modules/README.md
Normal file
5
cmake/cmake-modules/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
The files in these folder were manually copy and pasted from the
|
||||
[cmake-modules repository](https://github.com/bilke/cmake-modules). It was decided to do
|
||||
this because only a small subset of its provided functions are needed.
|
||||
|
||||
The license file in included here as well.
|
@ -1,3 +1,110 @@
|
||||
.. _dhb-prim-doc:
|
||||
|
||||
Device Handlers
|
||||
==================
|
||||
|
||||
Device handler components represent, control and monitor equipment, for example sensors or actuators
|
||||
of a spacecraft or the payload.
|
||||
|
||||
Most device handlers have the same common functionality or
|
||||
requirements, which are fulfilled by implementing certain interfaces:
|
||||
|
||||
- The handler/device needs to be commandable: :cpp:class:`HasActionsIF`
|
||||
- The handler needs to communicate with the physical device via a dedicated
|
||||
communication bus, for example SpaceWire, UART or SPI: :cpp:class:`DeviceCommunicationIF`
|
||||
- The handler has housekeeping data which has to be exposed to the operator and/or other software
|
||||
components: :cpp:class:`HasLocalDataPoolIF`
|
||||
- The handler has configurable parameters: :cpp:class:`ReceivesParameterMessagesIF` which
|
||||
also implements :cpp:class:`HasParametersIF`
|
||||
- The handler has health states, for example to indicate a broken device:
|
||||
:cpp:class:`HasHealthIF`
|
||||
- The handler has modes. For example there are the core modes `MODE_ON`, `MODE_OFF`
|
||||
and `MODE_NORMAL` provided by the FSFW. `MODE_ON` means that a device is physically powered
|
||||
but that it is not periodically polling data from the
|
||||
physical device, `MODE_NORMAL` means that it is able to do that: :cpp:class:`HasModesIF`
|
||||
|
||||
The device handler base therefore provides abstractions for a lot of common
|
||||
functionality, which can potentially avoid high amounts or logic and code duplication.
|
||||
|
||||
Template Device Handler Base File
|
||||
----------------------------------
|
||||
|
||||
This is an example template device handler header file with all necessary
|
||||
functions implemented:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#ifndef __TESTDEVICEHANDLER_H_
|
||||
#define __TESTDEVICEHANDLER_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
|
||||
class TestDeviceHandler: DeviceHandlerBase {
|
||||
public:
|
||||
TestDeviceHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie);
|
||||
private:
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId,
|
||||
size_t* foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) override;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
};
|
||||
|
||||
#endif /* __TESTDEVICEHANDLER_H_ */
|
||||
|
||||
and the respective source file with sensible default return values:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include "TestDeviceHandler.h"
|
||||
|
||||
TestDeviceHandler::TestDeviceHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie)
|
||||
: DeviceHandlerBase(objectId, comIF, cookie) {}
|
||||
|
||||
void TestDeviceHandler::doStartUp() {}
|
||||
|
||||
void TestDeviceHandler::doShutDown() {}
|
||||
|
||||
ReturnValue_t TestDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TestDeviceHandler::fillCommandAndReplyMap() {}
|
||||
|
||||
ReturnValue_t TestDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDeviceHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t* packet) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t TestDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
||||
return 10000;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDeviceHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -19,6 +19,29 @@ A template configuration folder was provided and can be copied into the project
|
||||
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||
information about the possible options.
|
||||
|
||||
Prerequisites
|
||||
-------------------
|
||||
|
||||
The Embedded Template Library (etl) is a dependency of the FSFW which is automatically
|
||||
installed and provided by the build system unless the correction version was installed.
|
||||
The current recommended version can be found inside the fsfw ``CMakeLists.txt`` file or by using
|
||||
``ccmake`` and looking up the ``FSFW_ETL_LIB_MAJOR_VERSION`` variable.
|
||||
|
||||
You can install the ETL library like this. On Linux, it might be necessary to add ``sudo`` before
|
||||
the install call:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
git clone https://github.com/ETLCPP/etl
|
||||
cd etl
|
||||
git checkout <currentRecommendedVersion>
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
cmake --install .
|
||||
|
||||
It is recommended to install ``20.27.2`` or newer for the package version handling of
|
||||
ETL to work.
|
||||
|
||||
Adding the library
|
||||
-------------------
|
||||
|
||||
@ -60,6 +83,20 @@ The FSFW also has unittests which use the `Catch2 library`_.
|
||||
These are built by setting the CMake option ``FSFW_BUILD_UNITTESTS`` to ``ON`` or `TRUE`
|
||||
from your project `CMakeLists.txt` file or from the command line.
|
||||
|
||||
You can install the Catch2 library, which prevents the build system to avoid re-downloading
|
||||
the dependency if the unit tests are completely rebuilt. The current recommended version
|
||||
can be found inside the fsfw ``CMakeLists.txt`` file or by using ``ccmake`` and looking up
|
||||
the ``FSFW_CATCH2_LIB_VERSION`` variable.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
git clone https://github.com/catchorg/Catch2.git
|
||||
cd Catch2
|
||||
git checkout <currentRecommendedVersion>
|
||||
cmake -Bbuild -H. -DBUILD_TESTING=OFF
|
||||
sudo cmake --build build/ --target install
|
||||
|
||||
|
||||
The fsfw-tests binary will be built as part of the static library and dropped alongside it.
|
||||
If the unittests are built, the library and the tests will be built with coverage information by
|
||||
default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`.
|
||||
@ -90,8 +127,21 @@ Building the documentation
|
||||
----------------------------
|
||||
|
||||
The FSFW documentation is built using the tools Sphinx, doxygen and breathe based on the
|
||||
instructions provided in `this blogpost <https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/>`_. You can set up a
|
||||
documentation build system using the following commands
|
||||
instructions provided in `this blogpost <https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/>`_. If you
|
||||
want to do this locally, set up the prerequisites first. This requires a ``python3``
|
||||
installation as well. Example here is for Ubuntu.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
sudo apt-get install doxygen graphviz
|
||||
|
||||
And the following Python packages
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
python3 -m pip install sphinx breathe
|
||||
|
||||
You can set up a documentation build system using the following commands
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
@ -110,6 +160,14 @@ folder. Simply open the ``index.html`` in the webbrowser of your choice.
|
||||
The ``helper.py`` script located in the ``script`` folder can also be used to create, build
|
||||
and open the documentation conveniently. Try ``helper.py -h`` for more information.
|
||||
|
||||
Formatting the source
|
||||
-----------------------
|
||||
|
||||
The formatting is done by the ``clang-format`` tool. The configuration is contained within the
|
||||
``.clang-format`` file in the repository root. As long as ``clang-format`` is installed, you
|
||||
can run the ``apply-clang-format.sh`` helper script to format all source files consistently.
|
||||
|
||||
|
||||
.. _`Hosted FSFW example`: https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted
|
||||
.. _`Catch2 library`: https://github.com/catchorg/Catch2
|
||||
.. _`Code coverage`: https://github.com/bilke/cmake-modules/tree/master
|
||||
|
@ -118,7 +118,7 @@ The DH has mechanisms to monitor the communication with the physical device whic
|
||||
for FDIR reaction. Device Handlers can be created by implementing ``DeviceHandlerBase``.
|
||||
A standard FDIR component for the DH will be created automatically but can
|
||||
be overwritten by the user. More information on DeviceHandlers can be found in the
|
||||
related [documentation section](doc/README-devicehandlers.md#top).
|
||||
related :ref:`documentation section <dhb-prim-doc>`.
|
||||
|
||||
Modes and Health
|
||||
--------------------
|
||||
|
@ -3,7 +3,14 @@ cmake_minimum_required(VERSION 3.13)
|
||||
# Can also be changed by upper CMakeLists.txt file
|
||||
find_library(LIB_FSFW_NAME fsfw REQUIRED)
|
||||
|
||||
option(FSFW_HAL_ADD_LINUX "Add the Linux HAL to the sources. Required gpiod library" OFF)
|
||||
option(FSFW_HAL_ADD_LINUX "Add the Linux HAL to the sources. Requires gpiod library" OFF)
|
||||
# On by default for now because I did not have an issue including and compiling those files
|
||||
# and libraries on a Desktop Linux system and the primary target of the FSFW is still embedded
|
||||
# Linux. The only exception from this is the gpiod library which requires a dedicated installation,
|
||||
# but CMake is able to determine whether this library is installed with find_library.
|
||||
option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add peripheral drivers for embedded Linux" ON)
|
||||
option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Target implements libgpiod" ON)
|
||||
|
||||
option(FSFW_HAL_ADD_RASPBERRY_PI "Add Raspberry Pi specific code to the sources" OFF)
|
||||
option(FSFW_HAL_ADD_STM32H7 "Add the STM32H7 HAL to the sources" OFF)
|
||||
option(FSFW_HAL_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
||||
|
@ -1,7 +1,7 @@
|
||||
add_subdirectory(devicehandlers)
|
||||
add_subdirectory(common)
|
||||
|
||||
if(FSFW_HAL_ADD_LINUX)
|
||||
if(UNIX)
|
||||
add_subdirectory(linux)
|
||||
endif()
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
GpioCookie::GpioCookie() {
|
||||
}
|
||||
GpioCookie::GpioCookie() {}
|
||||
|
||||
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
||||
if (gpioConfig == nullptr) {
|
||||
@ -19,8 +19,8 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
||||
if (statusPair.second == false) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId <<
|
||||
" to GPIO map" << std::endl;
|
||||
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << " to GPIO map"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
|
||||
#endif
|
||||
@ -39,9 +39,7 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
GpioMap GpioCookie::getGpioMap() const {
|
||||
return gpioMap;
|
||||
}
|
||||
GpioMap GpioCookie::getGpioMap() const { return gpioMap; }
|
||||
|
||||
GpioCookie::~GpioCookie() {
|
||||
for (auto& config : gpioMap) {
|
||||
|
@ -1,12 +1,12 @@
|
||||
#ifndef COMMON_GPIO_GPIOCOOKIE_H_
|
||||
#define COMMON_GPIO_GPIOCOOKIE_H_
|
||||
|
||||
#include "GpioIF.h"
|
||||
#include "gpioDefinitions.h"
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#include "GpioIF.h"
|
||||
#include "gpioDefinitions.h"
|
||||
|
||||
/**
|
||||
* @brief Cookie for the GpioIF. Allows the GpioIF to determine which
|
||||
* GPIOs to initialize and whether they should be configured as in- or
|
||||
@ -19,7 +19,6 @@
|
||||
*/
|
||||
class GpioCookie : public CookieIF {
|
||||
public:
|
||||
|
||||
GpioCookie();
|
||||
|
||||
virtual ~GpioCookie();
|
||||
|
@ -1,9 +1,10 @@
|
||||
#ifndef COMMON_GPIO_GPIOIF_H_
|
||||
#define COMMON_GPIO_GPIOIF_H_
|
||||
|
||||
#include "gpioDefinitions.h"
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#include "gpioDefinitions.h"
|
||||
|
||||
class GpioCookie;
|
||||
|
||||
@ -14,7 +15,6 @@ class GpioCookie;
|
||||
*/
|
||||
class GpioIF : public HasReturnvaluesIF {
|
||||
public:
|
||||
|
||||
virtual ~GpioIF(){};
|
||||
|
||||
/**
|
||||
@ -46,9 +46,9 @@ public:
|
||||
* an ouput or input gpio.
|
||||
*
|
||||
* @param gpioId A unique number which specifies the GPIO to read.
|
||||
* @param gpioState State of GPIO will be written to this pointer.
|
||||
* @param gpioState State of GPIO will be written to this reference
|
||||
*/
|
||||
virtual ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) = 0;
|
||||
virtual ReturnValue_t readGpio(gpioId_t gpioId, gpio::Levels& gpioState) = 0;
|
||||
};
|
||||
|
||||
#endif /* COMMON_GPIO_GPIOIF_H_ */
|
||||
|
@ -1,29 +1,19 @@
|
||||
#ifndef COMMON_GPIO_GPIODEFINITIONS_H_
|
||||
#define COMMON_GPIO_GPIODEFINITIONS_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
using gpioId_t = uint16_t;
|
||||
|
||||
namespace gpio {
|
||||
|
||||
enum Levels: uint8_t {
|
||||
LOW = 0,
|
||||
HIGH = 1,
|
||||
NONE = 99
|
||||
};
|
||||
enum class Levels : int { LOW = 0, HIGH = 1, FAILED = -1, NONE = 99 };
|
||||
|
||||
enum Direction: uint8_t {
|
||||
IN = 0,
|
||||
OUT = 1
|
||||
};
|
||||
enum class Direction : int { IN = 0, OUT = 1 };
|
||||
|
||||
enum GpioOperation {
|
||||
READ,
|
||||
WRITE
|
||||
};
|
||||
enum class GpioOperation { READ, WRITE };
|
||||
|
||||
enum class GpioTypes {
|
||||
NONE,
|
||||
@ -38,7 +28,7 @@ static constexpr gpioId_t NO_GPIO = -1;
|
||||
using gpio_cb_t = void (*)(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
|
||||
void* args);
|
||||
|
||||
}
|
||||
} // namespace gpio
|
||||
|
||||
/**
|
||||
* @brief Struct containing information about the GPIO to use. This is
|
||||
@ -56,12 +46,11 @@ using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::L
|
||||
*/
|
||||
class GpioBase {
|
||||
public:
|
||||
|
||||
GpioBase() = default;
|
||||
|
||||
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||
gpio::Levels initValue):
|
||||
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
||||
gpio::Levels initValue)
|
||||
: gpioType(gpioType), consumer(consumer), direction(direction), initValue(initValue) {}
|
||||
|
||||
virtual ~GpioBase(){};
|
||||
|
||||
@ -75,14 +64,13 @@ public:
|
||||
class GpiodRegularBase : public GpioBase {
|
||||
public:
|
||||
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||
gpio::Levels initValue, int lineNum):
|
||||
GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {
|
||||
}
|
||||
gpio::Levels initValue, int lineNum)
|
||||
: GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {}
|
||||
|
||||
// line number will be configured at a later point for the open by line name configuration
|
||||
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||
gpio::Levels initValue): GpioBase(gpioType, consumer, direction, initValue) {
|
||||
}
|
||||
gpio::Levels initValue)
|
||||
: GpioBase(gpioType, consumer, direction, initValue) {}
|
||||
|
||||
int lineNum = 0;
|
||||
struct gpiod_line* lineHandle = nullptr;
|
||||
@ -90,23 +78,20 @@ public:
|
||||
|
||||
class GpiodRegularByChip : public GpiodRegularBase {
|
||||
public:
|
||||
GpiodRegularByChip() :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
||||
std::string(), gpio::Direction::IN, gpio::LOW, 0) {
|
||||
}
|
||||
GpiodRegularByChip()
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, std::string(), gpio::Direction::IN,
|
||||
gpio::Levels::LOW, 0) {}
|
||||
|
||||
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
|
||||
gpio::Direction direction_, gpio::Levels initValue_) :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
||||
consumer_, direction_, initValue_, lineNum_),
|
||||
chipname(chipname_){
|
||||
}
|
||||
gpio::Direction direction_, gpio::Levels initValue_)
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, direction_, initValue_,
|
||||
lineNum_),
|
||||
chipname(chipname_) {}
|
||||
|
||||
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_) :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_,
|
||||
gpio::Direction::IN, gpio::LOW, lineNum_),
|
||||
chipname(chipname_) {
|
||||
}
|
||||
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_)
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, gpio::Direction::IN,
|
||||
gpio::Levels::LOW, lineNum_),
|
||||
chipname(chipname_) {}
|
||||
|
||||
std::string chipname;
|
||||
};
|
||||
@ -114,17 +99,15 @@ public:
|
||||
class GpiodRegularByLabel : public GpiodRegularBase {
|
||||
public:
|
||||
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
|
||||
gpio::Direction direction_, gpio::Levels initValue_) :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
||||
direction_, initValue_, lineNum_),
|
||||
label(label_) {
|
||||
}
|
||||
gpio::Direction direction_, gpio::Levels initValue_)
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, direction_, initValue_,
|
||||
lineNum_),
|
||||
label(label_) {}
|
||||
|
||||
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_) :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
||||
gpio::Direction::IN, gpio::LOW, lineNum_),
|
||||
label(label_) {
|
||||
}
|
||||
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_)
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, gpio::Direction::IN,
|
||||
gpio::Levels::LOW, lineNum_),
|
||||
label(label_) {}
|
||||
|
||||
std::string label;
|
||||
};
|
||||
@ -137,15 +120,15 @@ public:
|
||||
class GpiodRegularByLineName : public GpiodRegularBase {
|
||||
public:
|
||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
|
||||
gpio::Levels initValue_) :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
||||
initValue_), lineName(lineName_) {
|
||||
}
|
||||
gpio::Levels initValue_)
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
||||
initValue_),
|
||||
lineName(lineName_) {}
|
||||
|
||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_) :
|
||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_,
|
||||
gpio::Direction::IN, gpio::LOW), lineName(lineName_) {
|
||||
}
|
||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_)
|
||||
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, gpio::Direction::IN,
|
||||
gpio::Levels::LOW),
|
||||
lineName(lineName_) {}
|
||||
|
||||
std::string lineName;
|
||||
};
|
||||
@ -153,15 +136,15 @@ public:
|
||||
class GpioCallback : public GpioBase {
|
||||
public:
|
||||
GpioCallback(std::string consumer, gpio::Direction direction_, gpio::Levels initValue_,
|
||||
gpio::gpio_cb_t callback, void* callbackArgs):
|
||||
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||
callback(callback), callbackArgs(callbackArgs) {}
|
||||
gpio::gpio_cb_t callback, void* callbackArgs)
|
||||
: GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||
callback(callback),
|
||||
callbackArgs(callbackArgs) {}
|
||||
|
||||
gpio::gpio_cb_t callback = nullptr;
|
||||
void* callbackArgs = nullptr;
|
||||
};
|
||||
|
||||
|
||||
using GpioMap = std::map<gpioId_t, GpioBase*>;
|
||||
using GpioUnorderedMap = std::unordered_map<gpioId_t, GpioBase*>;
|
||||
using GpioMapIter = GpioMap::iterator;
|
||||
|
@ -5,12 +5,7 @@
|
||||
|
||||
namespace spi {
|
||||
|
||||
enum SpiModes: uint8_t {
|
||||
MODE_0,
|
||||
MODE_1,
|
||||
MODE_2,
|
||||
MODE_3
|
||||
};
|
||||
enum SpiModes : uint8_t { MODE_0, MODE_1, MODE_2, MODE_3 };
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,14 @@
|
||||
#include "GyroL3GD20Handler.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
||||
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, uint32_t transitionDelayMs):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
transitionDelayMs(transitionDelayMs), dataset(this) {
|
||||
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
||||
debugDivider = new PeriodicOperationDivider(3);
|
||||
#endif
|
||||
}
|
||||
CookieIF *comCookie, uint32_t transitionDelayMs)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
transitionDelayMs(transitionDelayMs),
|
||||
dataset(this) {}
|
||||
|
||||
GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
|
||||
|
||||
@ -32,8 +29,7 @@ void GyroHandlerL3GD20H::doStartUp() {
|
||||
internalState = InternalState::NORMAL;
|
||||
if (goNormalModeImmediately) {
|
||||
setMode(MODE_NORMAL);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
commandExecuted = false;
|
||||
@ -41,9 +37,7 @@ void GyroHandlerL3GD20H::doStartUp() {
|
||||
}
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::doShutDown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
void GyroHandlerL3GD20H::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
switch (internalState) {
|
||||
@ -69,9 +63,11 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
/* Might be a configuration error. */
|
||||
sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state!" << std::endl;
|
||||
"Unknown internal state!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printDebug("GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||
sif::printDebug(
|
||||
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state!\n");
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -84,8 +80,8 @@ ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (L3GD20H::READ_REGS): {
|
||||
@ -112,11 +108,9 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
||||
|
||||
if (not fsH and not fsL) {
|
||||
sensitivity = L3GD20H::SENSITIVITY_00;
|
||||
}
|
||||
else if(not fsH and fsL) {
|
||||
} else if (not fsH and fsL) {
|
||||
sensitivity = L3GD20H::SENSITIVITY_01;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sensitivity = L3GD20H::SENSITIVITY_11;
|
||||
}
|
||||
|
||||
@ -131,8 +125,7 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
||||
break;
|
||||
}
|
||||
case (L3GD20H::READ_CTRL_REGS): {
|
||||
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK |
|
||||
L3GD20H::READ_MASK;
|
||||
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK;
|
||||
|
||||
std::memset(commandBuffer + 1, 0, 5);
|
||||
rawPacket = commandBuffer;
|
||||
@ -167,8 +160,7 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
packet[3] == ctrlReg3Value and packet[4] == ctrlReg4Value and
|
||||
packet[5] == ctrlReg5Value) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Attempt reconfiguration
|
||||
internalState = InternalState::CONFIGURE;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
@ -180,8 +172,7 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
packet[3] != ctrlReg3Value and packet[4] != ctrlReg4Value and
|
||||
packet[5] != ctrlReg5Value) {
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (internalState == InternalState::CHECK_REGS) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
@ -198,8 +189,8 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
|
||||
int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX];
|
||||
float temperature = 25.0 + temperaturOffset;
|
||||
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
||||
if(debugDivider->checkAndIncrement()) {
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.checkAndIncrement()) {
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl;
|
||||
@ -213,31 +204,28 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
sif::printInfo("Z: %f\n", angVelocZ);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PoolReadGuard readSet(&dataset);
|
||||
if (readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
if (std::abs(angVelocX) < this->absLimitX) {
|
||||
dataset.angVelocX = angVelocX;
|
||||
dataset.angVelocX.setValid(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataset.angVelocX.setValid(false);
|
||||
}
|
||||
|
||||
if (std::abs(angVelocY) < this->absLimitY) {
|
||||
dataset.angVelocY = angVelocY;
|
||||
dataset.angVelocY.setValid(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataset.angVelocY.setValid(false);
|
||||
}
|
||||
|
||||
if (std::abs(angVelocZ) < this->absLimitZ) {
|
||||
dataset.angVelocZ = angVelocZ;
|
||||
dataset.angVelocZ.setValid(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataset.angVelocZ.setValid(false);
|
||||
}
|
||||
|
||||
@ -252,17 +240,14 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return this->transitionDelayMs;
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) {
|
||||
this->goNormalModeImmediately = true;
|
||||
}
|
||||
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) { this->goNormalModeImmediately = true; }
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry<float>({0.0}));
|
||||
@ -276,12 +261,15 @@ void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1);
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::modeChanged() {
|
||||
internalState = InternalState::NONE;
|
||||
}
|
||||
void GyroHandlerL3GD20H::modeChanged() { internalState = InternalState::NONE; }
|
||||
|
||||
void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) {
|
||||
this->absLimitX = limitX;
|
||||
this->absLimitY = limitY;
|
||||
this->absLimitZ = limitZ;
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
||||
periodicPrintout = enable;
|
||||
debugDivider.setDivider(divider);
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "devicedefinitions/GyroL3GD20Definitions.h"
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
||||
|
||||
#include "devicedefinitions/GyroL3GD20Definitions.h"
|
||||
|
||||
/**
|
||||
* @brief Device Handler for the L3GD20H gyroscope sensor
|
||||
* (https://www.st.com/en/mems-and-sensors/l3gd20h.html)
|
||||
@ -18,10 +17,12 @@
|
||||
*/
|
||||
class GyroHandlerL3GD20H : public DeviceHandlerBase {
|
||||
public:
|
||||
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF* comCookie, uint32_t transitionDelayMs);
|
||||
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||
uint32_t transitionDelayMs);
|
||||
virtual ~GyroHandlerL3GD20H();
|
||||
|
||||
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
||||
|
||||
/**
|
||||
* Set the absolute limit for the values on the axis in degrees per second.
|
||||
* The dataset values will be marked as invalid if that limit is exceeded
|
||||
@ -35,22 +36,18 @@ public:
|
||||
* @brief Configure device handler to go to normal mode immediately
|
||||
*/
|
||||
void setToGoToNormalMode(bool enable);
|
||||
protected:
|
||||
|
||||
protected:
|
||||
/* DeviceHandlerBase overrides */
|
||||
ReturnValue_t buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(
|
||||
DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||
size_t *foundLen) override;
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||
|
||||
void fillCommandAndReplyMap() override;
|
||||
void modeChanged() override;
|
||||
@ -66,12 +63,7 @@ private:
|
||||
float absLimitY = L3GD20H::RANGE_DPS_00;
|
||||
float absLimitZ = L3GD20H::RANGE_DPS_00;
|
||||
|
||||
enum class InternalState {
|
||||
NONE,
|
||||
CONFIGURE,
|
||||
CHECK_REGS,
|
||||
NORMAL
|
||||
};
|
||||
enum class InternalState { NONE, CONFIGURE, CHECK_REGS, NORMAL };
|
||||
InternalState internalState = InternalState::NONE;
|
||||
bool commandExecuted = false;
|
||||
|
||||
@ -89,11 +81,8 @@ private:
|
||||
// Set default value
|
||||
float sensitivity = L3GD20H::SENSITIVITY_00;
|
||||
|
||||
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
||||
PeriodicOperationDivider* debugDivider = nullptr;
|
||||
#endif
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */
|
||||
|
@ -1,31 +1,23 @@
|
||||
#include "MgmLIS3MDLHandler.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
||||
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF* comCookie, uint32_t transitionDelay):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
dataset(this), transitionDelay(transitionDelay) {
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
debugDivider = new PeriodicOperationDivider(3);
|
||||
#endif
|
||||
CookieIF *comCookie, uint32_t transitionDelay)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
dataset(this),
|
||||
transitionDelay(transitionDelay) {
|
||||
// Set to default values right away
|
||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||
registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT;
|
||||
registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {
|
||||
}
|
||||
|
||||
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {}
|
||||
|
||||
void MgmLIS3MDLHandler::doStartUp() {
|
||||
switch (internalState) {
|
||||
@ -51,8 +43,7 @@ void MgmLIS3MDLHandler::doStartUp() {
|
||||
commandExecuted = false;
|
||||
if (goToNormalMode) {
|
||||
setMode(MODE_NORMAL);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
}
|
||||
@ -61,15 +52,11 @@ void MgmLIS3MDLHandler::doStartUp() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::doShutDown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
void MgmLIS3MDLHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
switch (internalState) {
|
||||
case (InternalState::STATE_NONE):
|
||||
case (InternalState::STATE_NORMAL): {
|
||||
@ -90,14 +77,13 @@ ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(
|
||||
default: {
|
||||
/* might be a configuration error. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!" <<
|
||||
std::endl;
|
||||
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
}
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
@ -119,7 +105,6 @@ uint8_t MgmLIS3MDLHandler::writeCommand(uint8_t command, bool continuousCom) {
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::setupMgm() {
|
||||
|
||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||
@ -129,24 +114,21 @@ void MgmLIS3MDLHandler::setupMgm() {
|
||||
prepareCtrlRegisterWrite();
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
// Data/config register will be read in an alternating manner.
|
||||
if (communicationStep == CommunicationStep::DATA) {
|
||||
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||
communicationStep = CommunicationStep::TEMPERATURE;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*id = MGMLIS3MDL::READ_TEMPERATURE;
|
||||
communicationStep = CommunicationStep::DATA;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (MGMLIS3MDL::READ_CONFIG_AND_DATA): {
|
||||
@ -195,16 +177,15 @@ ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
|
||||
size_t len, DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
*foundLen = len;
|
||||
if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) {
|
||||
*foundLen = len;
|
||||
*foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||
// Check validity by checking config registers
|
||||
if (start[1] != registers[0] or start[2] != registers[1] or
|
||||
start[3] != registers[2] or start[4] != registers[3] or
|
||||
start[5] != registers[4]) {
|
||||
if (start[1] != registers[0] or start[2] != registers[1] or start[3] != registers[2] or
|
||||
start[4] != registers[3] or start[5] != registers[4]) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
|
||||
@ -218,16 +199,13 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
|
||||
commandExecuted = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
|
||||
} else if (len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = MGMLIS3MDL::READ_TEMPERATURE;
|
||||
}
|
||||
else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
|
||||
} else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = MGMLIS3MDL::SETUP_MGM;
|
||||
}
|
||||
else if (len == SINGLE_COMMAND_ANSWER_LEN) {
|
||||
} else if (len == SINGLE_COMMAND_ANSWER_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = getPendingCommand();
|
||||
if (*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
|
||||
@ -235,9 +213,11 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: "
|
||||
"Device identification failed!" << std::endl;
|
||||
"Device identification failed!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("MGMHandlerLIS3MDL::scanForReply: "
|
||||
sif::printWarning(
|
||||
"MGMHandlerLIS3MDL::scanForReply: "
|
||||
"Device identification failed!\n");
|
||||
#endif
|
||||
#endif
|
||||
@ -248,23 +228,18 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
|
||||
commandExecuted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
/* Data with SPI Interface always has this answer */
|
||||
if (start[0] == 0b11111111) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
}
|
||||
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case MGMLIS3MDL::IDENTIFY_DEVICE: {
|
||||
break;
|
||||
@ -276,26 +251,27 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
// TODO: Store configuration in new local datasets.
|
||||
float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2]));
|
||||
|
||||
int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::X_LOWBYTE_IDX] ;
|
||||
int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ;
|
||||
int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ;
|
||||
int16_t mgmMeasurementRawX =
|
||||
packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::X_LOWBYTE_IDX];
|
||||
int16_t mgmMeasurementRawY =
|
||||
packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Y_LOWBYTE_IDX];
|
||||
int16_t mgmMeasurementRawZ =
|
||||
packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Z_LOWBYTE_IDX];
|
||||
|
||||
/* Target value in microtesla */
|
||||
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
// Target value in microtesla
|
||||
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor *
|
||||
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor *
|
||||
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor *
|
||||
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
if(debugDivider->checkAndIncrement()) {
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.checkAndIncrement()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MGMHandlerLIS3: Magnetic field strength in"
|
||||
" microtesla:" << std::endl;
|
||||
" microtesla:"
|
||||
<< std::endl;
|
||||
sif::info << "X: " << mgmX << " uT" << std::endl;
|
||||
sif::info << "Y: " << mgmY << " uT" << std::endl;
|
||||
sif::info << "Z: " << mgmZ << " uT" << std::endl;
|
||||
@ -306,30 +282,28 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
sif::printInfo("Z: %f uT\n", mgmZ);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
|
||||
}
|
||||
#endif /* OBSW_VERBOSE_LEVEL >= 1 */
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
if (std::abs(mgmX) < absLimitX) {
|
||||
dataset.fieldStrengthX = mgmX;
|
||||
dataset.fieldStrengthX.setValid(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataset.fieldStrengthX.setValid(false);
|
||||
}
|
||||
|
||||
if (std::abs(mgmY) < absLimitY) {
|
||||
dataset.fieldStrengthY = mgmY;
|
||||
dataset.fieldStrengthY.setValid(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataset.fieldStrengthY.setValid(false);
|
||||
}
|
||||
|
||||
if (std::abs(mgmZ) < absLimitZ) {
|
||||
dataset.fieldStrengthZ = mgmZ;
|
||||
dataset.fieldStrengthZ.setValid(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataset.fieldStrengthZ.setValid(false);
|
||||
}
|
||||
}
|
||||
@ -339,16 +313,16 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
case MGMLIS3MDL::READ_TEMPERATURE: {
|
||||
int16_t tempValueRaw = packet[2] << 8 | packet[1];
|
||||
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
if(debugDivider->check()) {
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.check()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" <<
|
||||
std::endl;
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl;
|
||||
#else
|
||||
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ReturnValue_t result = dataset.read();
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
dataset.temperature = tempValue;
|
||||
@ -360,7 +334,6 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
default: {
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -400,16 +373,18 @@ float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if (commandData == nullptr) {
|
||||
return INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
|
||||
uint32_t size = 2;
|
||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1);
|
||||
if (commandDataLen > 1) {
|
||||
return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
switch (*commandData) {
|
||||
switch (commandData[0]) {
|
||||
case (MGMLIS3MDL::ON): {
|
||||
commandBuffer[1] = registers[0] | (1 << 7);
|
||||
break;
|
||||
@ -471,9 +446,7 @@ void MgmLIS3MDLHandler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1);
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) {
|
||||
this->goToNormalMode = enable;
|
||||
}
|
||||
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) { this->goToNormalMode = enable; }
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true);
|
||||
@ -489,27 +462,19 @@ ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||
|
||||
DeviceHandlerBase::doTransition(modeFrom, subModeFrom);
|
||||
}
|
||||
|
||||
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return transitionDelay;
|
||||
}
|
||||
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { return transitionDelay; }
|
||||
|
||||
void MgmLIS3MDLHandler::modeChanged(void) {
|
||||
internalState = InternalState::STATE_NONE;
|
||||
}
|
||||
void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE_NONE; }
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS,
|
||||
new PoolEntry<float>({0.0}));
|
||||
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0}));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -518,3 +483,8 @@ void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLim
|
||||
this->absLimitY = yLimit;
|
||||
this->absLimitZ = zLimit;
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
||||
periodicPrintout = enable;
|
||||
debugDivider.setDivider(divider);
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "events/subsystemIdRanges.h"
|
||||
#include "devicedefinitions/MgmLIS3HandlerDefs.h"
|
||||
|
||||
#include "events/subsystemIdRanges.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
|
||||
class PeriodicOperationDivider;
|
||||
|
||||
@ -20,10 +19,7 @@ class PeriodicOperationDivider;
|
||||
*/
|
||||
class MgmLIS3MDLHandler : public DeviceHandlerBase {
|
||||
public:
|
||||
enum class CommunicationStep {
|
||||
DATA,
|
||||
TEMPERATURE
|
||||
};
|
||||
enum class CommunicationStep { DATA, TEMPERATURE };
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL;
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL;
|
||||
@ -34,6 +30,7 @@ public:
|
||||
uint32_t transitionDelay);
|
||||
virtual ~MgmLIS3MDLHandler();
|
||||
|
||||
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
||||
/**
|
||||
* Set the absolute limit for the values on the axis in microtesla. The dataset values will
|
||||
* be marked as invalid if that limit is exceeded
|
||||
@ -45,21 +42,17 @@ public:
|
||||
void setToGoToNormalMode(bool enable);
|
||||
|
||||
protected:
|
||||
|
||||
/** DeviceHandlerBase overrides */
|
||||
void doShutDown() override;
|
||||
void doStartUp() override;
|
||||
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
||||
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
||||
ReturnValue_t buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildNormalDeviceCommand(
|
||||
DeviceCommandId_t *id) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||
size_t *foundLen) override;
|
||||
/**
|
||||
* This implementation is tailored towards space applications and will flag values larger
|
||||
* than 100 microtesla on X,Y and 150 microtesla on Z as invalid
|
||||
@ -67,8 +60,7 @@ protected:
|
||||
* @param packet
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) override;
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
void modeChanged(void) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
@ -159,16 +151,14 @@ private:
|
||||
* @param commandData On or Off
|
||||
* @param length of the commandData: has to be 1
|
||||
*/
|
||||
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData,
|
||||
size_t commandDataLen);
|
||||
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData, size_t commandDataLen);
|
||||
|
||||
/**
|
||||
* Sets the accuracy of the measurement of the axis. The noise is changing.
|
||||
* @param commandData LOW, MEDIUM, HIGH, ULTRA
|
||||
* @param length of the command, has to be 1
|
||||
*/
|
||||
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData,
|
||||
size_t commandDataLen);
|
||||
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData, size_t commandDataLen);
|
||||
|
||||
/**
|
||||
* We always update all registers together, so this method updates
|
||||
@ -178,9 +168,8 @@ private:
|
||||
*/
|
||||
ReturnValue_t prepareCtrlRegisterWrite();
|
||||
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
PeriodicOperationDivider* debugDivider;
|
||||
#endif
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */
|
||||
|
@ -1,20 +1,16 @@
|
||||
#include "MgmRM3100Handler.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
|
||||
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId,
|
||||
object_id_t deviceCommunication, CookieIF* comCookie, uint32_t transitionDelay):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
primaryDataset(this), transitionDelay(transitionDelay) {
|
||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||
debugDivider = new PeriodicOperationDivider(3);
|
||||
#endif
|
||||
}
|
||||
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, uint32_t transitionDelay)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
primaryDataset(this),
|
||||
transitionDelay(transitionDelay) {}
|
||||
|
||||
MgmRM3100Handler::~MgmRM3100Handler() {}
|
||||
|
||||
@ -45,8 +41,7 @@ void MgmRM3100Handler::doStartUp() {
|
||||
internalState = InternalState::NORMAL;
|
||||
if (goToNormalModeAtStartup) {
|
||||
setMode(MODE_NORMAL);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
}
|
||||
@ -58,12 +53,9 @@ void MgmRM3100Handler::doStartUp() {
|
||||
}
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::doShutDown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
void MgmRM3100Handler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
size_t commandLen = 0;
|
||||
switch (internalState) {
|
||||
case (InternalState::NONE):
|
||||
@ -93,9 +85,11 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// Might be a configuration error
|
||||
sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state" << std::endl;
|
||||
"Unknown internal state"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||
sif::printWarning(
|
||||
"MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state\n");
|
||||
#endif
|
||||
#endif
|
||||
@ -106,7 +100,8 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (RM3100::CONFIGURE_CMM): {
|
||||
commandBuffer[0] = RM3100::CMM_REGISTER;
|
||||
@ -154,16 +149,13 @@ ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t device
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
*id = RM3100::READ_DATA;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start,
|
||||
size_t len, DeviceCommandId_t *foundId,
|
||||
size_t *foundLen) {
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
// For SPI, ID will always be the one of the last sent command
|
||||
*foundId = this->getPendingCommand();
|
||||
*foundLen = len;
|
||||
@ -189,8 +181,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
||||
bitutil::clear(&cmmValue, 6);
|
||||
if (cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Attempt reconfiguration
|
||||
internalState = InternalState::CONFIGURE_CMM;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
@ -204,8 +195,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
||||
if (mode != _MODE_START_UP) {
|
||||
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Attempt reconfiguration
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
@ -239,7 +229,8 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if (commandData == nullptr) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
@ -247,11 +238,9 @@ ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t
|
||||
// Set cycle count
|
||||
if (commandDataLen == 2) {
|
||||
handleCycleCommand(true, commandData, commandDataLen);
|
||||
}
|
||||
else if(commandDataLen == 6) {
|
||||
} else if (commandDataLen == 6) {
|
||||
handleCycleCommand(false, commandData, commandDataLen);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
@ -264,11 +253,11 @@ ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
RM3100::CycleCountCommand command(oneCycleValue);
|
||||
ReturnValue_t result = command.deSerialize(&commandData, &commandDataLen,
|
||||
SerializeIF::Endianness::BIG);
|
||||
ReturnValue_t result =
|
||||
command.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -289,7 +278,8 @@ ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if (commandData == nullptr or commandDataLen != 1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
@ -315,12 +305,10 @@ void MgmRM3100Handler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::modeChanged(void) {
|
||||
internalState = InternalState::NONE;
|
||||
}
|
||||
void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; }
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||
@ -331,9 +319,7 @@ uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return this->transitionDelay;
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::setToGoToNormalMode(bool enable) {
|
||||
goToNormalModeAtStartup = enable;
|
||||
}
|
||||
void MgmRM3100Handler::setToGoToNormalMode(bool enable) { goToNormalModeAtStartup = enable; }
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||
// Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift
|
||||
@ -347,11 +333,12 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||
float fieldStrengthY = fieldStrengthRawY * scaleFactorX;
|
||||
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
|
||||
|
||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||
if(debugDivider->checkAndIncrement()) {
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.checkAndIncrement()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MgmRM3100Handler: Magnetic field strength in"
|
||||
" microtesla:" << std::endl;
|
||||
" microtesla:"
|
||||
<< std::endl;
|
||||
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
|
||||
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
|
||||
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
|
||||
@ -362,7 +349,7 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||
sif::printInfo("Z: %f uT\n", fieldStrengthZ);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO: Sanity check on values?
|
||||
PoolReadGuard readGuard(&primaryDataset);
|
||||
@ -374,3 +361,8 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
||||
periodicPrintout = enable;
|
||||
debugDivider.setDivider(divider);
|
||||
}
|
||||
|
@ -1,13 +1,9 @@
|
||||
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "devicedefinitions/MgmRM3100HandlerDefs.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
|
||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Device Handler for the RM3100 geomagnetic magnetometer sensor
|
||||
@ -21,19 +17,19 @@ public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_RM3100;
|
||||
|
||||
//! [EXPORT] : [COMMENT] P1: TMRC value which was set, P2: 0
|
||||
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100,
|
||||
0x00, severity::INFO);
|
||||
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x00, severity::INFO);
|
||||
|
||||
//! [EXPORT] : [COMMENT] Cycle counter set. P1: First two bytes new Cycle Count X
|
||||
//! P1: Second two bytes new Cycle Count Y
|
||||
//! P2: New cycle count Z
|
||||
static constexpr Event cycleCountersSet = event::makeEvent(
|
||||
SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
|
||||
static constexpr Event cycleCountersSet =
|
||||
event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
|
||||
|
||||
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF* comCookie, uint32_t transitionDelay);
|
||||
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||
uint32_t transitionDelay);
|
||||
virtual ~MgmRM3100Handler();
|
||||
|
||||
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
||||
/**
|
||||
* Configure device handler to go to normal mode after startup immediately
|
||||
* @param enable
|
||||
@ -41,17 +37,15 @@ public:
|
||||
void setToGoToNormalMode(bool enable);
|
||||
|
||||
protected:
|
||||
|
||||
/* DeviceHandlerBase overrides */
|
||||
ReturnValue_t buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||
size_t *foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||
|
||||
void fillCommandAndReplyMap() override;
|
||||
@ -61,7 +55,6 @@ protected:
|
||||
LocalDataPoolManager &poolManager) override;
|
||||
|
||||
private:
|
||||
|
||||
enum class InternalState {
|
||||
NONE,
|
||||
CONFIGURE_CMM,
|
||||
@ -95,16 +88,16 @@ private:
|
||||
|
||||
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen);
|
||||
ReturnValue_t handleCycleCommand(bool oneCycleValue,
|
||||
const uint8_t *commandData, size_t commandDataLen);
|
||||
ReturnValue_t handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
||||
size_t commandDataLen);
|
||||
|
||||
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,size_t commandDataLen);
|
||||
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen);
|
||||
|
||||
ReturnValue_t handleDataReadout(const uint8_t *packet);
|
||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||
PeriodicOperationDivider* debugDivider;
|
||||
#endif
|
||||
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ */
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace L3GD20H {
|
||||
@ -36,8 +37,8 @@ static constexpr uint8_t SET_Z_ENABLE = 1 << 2;
|
||||
static constexpr uint8_t SET_X_ENABLE = 1 << 1;
|
||||
static constexpr uint8_t SET_Y_ENABLE = 1;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE |
|
||||
SET_Y_ENABLE | SET_X_ENABLE;
|
||||
static constexpr uint8_t CTRL_REG_1_VAL =
|
||||
SET_POWER_NORMAL_MODE | SET_Z_ENABLE | SET_Y_ENABLE | SET_X_ENABLE;
|
||||
|
||||
/* Register 2 */
|
||||
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
|
||||
@ -104,40 +105,29 @@ static constexpr DeviceCommandId_t READ_CTRL_REGS = 2;
|
||||
|
||||
static constexpr uint32_t GYRO_DATASET_ID = READ_REGS;
|
||||
|
||||
enum GyroPoolIds: lp_id_t {
|
||||
ANG_VELOC_X,
|
||||
ANG_VELOC_Y,
|
||||
ANG_VELOC_Z,
|
||||
TEMPERATURE
|
||||
};
|
||||
enum GyroPoolIds : lp_id_t { ANG_VELOC_X, ANG_VELOC_Y, ANG_VELOC_Z, TEMPERATURE };
|
||||
|
||||
}
|
||||
} // namespace L3GD20H
|
||||
|
||||
class GyroPrimaryDataset : public StaticLocalDataSet<5> {
|
||||
public:
|
||||
|
||||
/** Constructor for data users like controllers */
|
||||
GyroPrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
|
||||
GyroPrimaryDataset(object_id_t mgmId)
|
||||
: StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
|
||||
setAllVariablesReadOnly();
|
||||
}
|
||||
|
||||
/* Angular velocities in degrees per second (DPS) */
|
||||
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId,
|
||||
L3GD20H::ANG_VELOC_X, this);
|
||||
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId,
|
||||
L3GD20H::ANG_VELOC_Y, this);
|
||||
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId,
|
||||
L3GD20H::ANG_VELOC_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
||||
L3GD20H::TEMPERATURE, this);
|
||||
private:
|
||||
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_X, this);
|
||||
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_Y, this);
|
||||
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, L3GD20H::TEMPERATURE, this);
|
||||
|
||||
private:
|
||||
friend class GyroHandlerL3GD20H;
|
||||
/** Constructor for the data creator */
|
||||
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
|
||||
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner)
|
||||
: StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
|
||||
};
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */
|
||||
|
@ -1,26 +1,18 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
||||
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace MGMLIS3MDL {
|
||||
|
||||
enum Set {
|
||||
ON, OFF
|
||||
};
|
||||
enum OpMode {
|
||||
LOW, MEDIUM, HIGH, ULTRA
|
||||
};
|
||||
enum Set { ON, OFF };
|
||||
enum OpMode { LOW, MEDIUM, HIGH, ULTRA };
|
||||
|
||||
enum Sensitivies: uint8_t {
|
||||
GAUSS_4 = 4,
|
||||
GAUSS_8 = 8,
|
||||
GAUSS_12 = 12,
|
||||
GAUSS_16 = 16
|
||||
};
|
||||
enum Sensitivies : uint8_t { GAUSS_4 = 4, GAUSS_8 = 8, GAUSS_12 = 12, GAUSS_16 = 16 };
|
||||
|
||||
/* Actually 15, we just round up a bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
||||
@ -114,8 +106,8 @@ static const uint8_t DO2 = 4; // Output data rate bit 4
|
||||
static const uint8_t OM0 = 5; // XY operating mode bit 5
|
||||
static const uint8_t OM1 = 6; // XY operating mode bit 6
|
||||
static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1
|
||||
static const uint8_t CTRL_REG1_DEFAULT = (1 << TEMP_EN) | (1 << OM1) |
|
||||
(1 << DO0) | (1 << DO1) | (1 << DO2);
|
||||
static const uint8_t CTRL_REG1_DEFAULT =
|
||||
(1 << TEMP_EN) | (1 << OM1) | (1 << DO0) | (1 << DO1) | (1 << DO2);
|
||||
|
||||
/* CTRL_REG2 bits */
|
||||
// reset configuration registers and user registers
|
||||
@ -156,23 +148,16 @@ enum MgmPoolIds: lp_id_t {
|
||||
|
||||
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
|
||||
public:
|
||||
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
|
||||
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
|
||||
|
||||
MgmPrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
||||
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
||||
|
||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_X, this);
|
||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_Y, this);
|
||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
||||
TEMPERATURE_CELCIUS, this);
|
||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
|
||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
|
||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace MGMLIS3MDL
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ */
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <fsfw/serialize/SerialLinkedListAdapter.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace RM3100 {
|
||||
@ -24,8 +25,8 @@ static constexpr uint8_t SET_CMM_DRDM = 1 << 2;
|
||||
static constexpr uint8_t SET_CMM_START = 1;
|
||||
static constexpr uint8_t CMM_REGISTER = 0x01;
|
||||
|
||||
static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX |
|
||||
SET_CMM_DRDM | SET_CMM_START;
|
||||
static constexpr uint8_t CMM_VALUE =
|
||||
SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX | SET_CMM_DRDM | SET_CMM_START;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Cycle count register */
|
||||
@ -33,8 +34,7 @@ static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX |
|
||||
// Default value (200)
|
||||
static constexpr uint8_t CYCLE_COUNT_VALUE = 0xC8;
|
||||
|
||||
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) /
|
||||
100 * 38;
|
||||
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) / 100 * 38;
|
||||
static constexpr uint8_t CYCLE_COUNT_START_REGISTER = 0x04;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -75,8 +75,7 @@ public:
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override {
|
||||
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer,
|
||||
size, streamEndianness);
|
||||
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer, size, streamEndianness);
|
||||
if (oneCycleCount) {
|
||||
cycleCountY = cycleCountX;
|
||||
cycleCountZ = cycleCountX;
|
||||
@ -110,23 +109,16 @@ enum MgmPoolIds: lp_id_t {
|
||||
|
||||
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
|
||||
public:
|
||||
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
|
||||
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
|
||||
|
||||
Rm3100PrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
||||
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
||||
|
||||
// Field strengths in micro Tesla.
|
||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_X, this);
|
||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_Y, this);
|
||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_Z, this);
|
||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
|
||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
|
||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace RM3100
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */
|
||||
|
@ -4,10 +4,22 @@ endif()
|
||||
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
UnixFileGuard.cpp
|
||||
CommandExecutor.cpp
|
||||
utility.cpp
|
||||
)
|
||||
|
||||
if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS)
|
||||
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
|
||||
add_subdirectory(gpio)
|
||||
add_subdirectory(spi)
|
||||
add_subdirectory(i2c)
|
||||
endif()
|
||||
add_subdirectory(uart)
|
||||
# Adding those does not really make sense on Apple systems which
|
||||
# are generally host systems. It won't even compile as the headers
|
||||
# are missing
|
||||
if(NOT APPLE)
|
||||
add_subdirectory(i2c)
|
||||
add_subdirectory(spi)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(uio)
|
||||
|
207
hal/src/fsfw_hal/linux/CommandExecutor.cpp
Normal file
207
hal/src/fsfw_hal/linux/CommandExecutor.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
#include "CommandExecutor.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw/container/DynamicFIFO.h"
|
||||
#include "fsfw/container/SimpleRingBuffer.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
|
||||
CommandExecutor::CommandExecutor(const size_t maxSize) : readVec(maxSize) {
|
||||
waiter.events = POLLIN;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
|
||||
if (state == States::PENDING) {
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
|
||||
currentCmd = command;
|
||||
this->blocking = blocking;
|
||||
this->printOutput = printOutput;
|
||||
if (state == States::IDLE) {
|
||||
state = States::COMMAND_LOADED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::execute() {
|
||||
if (state == States::IDLE) {
|
||||
return NO_COMMAND_LOADED_OR_PENDING;
|
||||
} else if (state == States::PENDING) {
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
currentCmdFile = popen(currentCmd.c_str(), "r");
|
||||
if (currentCmdFile == nullptr) {
|
||||
lastError = errno;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (blocking) {
|
||||
ReturnValue_t result = executeBlocking();
|
||||
state = States::IDLE;
|
||||
return result;
|
||||
} else {
|
||||
currentFd = fileno(currentCmdFile);
|
||||
waiter.fd = currentFd;
|
||||
}
|
||||
state = States::PENDING;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::close() {
|
||||
if (state == States::PENDING) {
|
||||
// Attempt to close process, irrespective of if it is running or not
|
||||
if (currentCmdFile != nullptr) {
|
||||
pclose(currentCmdFile);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CommandExecutor::printLastError(std::string funcName) const {
|
||||
if (lastError != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << funcName << " pclose failed with code " << lastError << ": "
|
||||
<< strerror(lastError) << std::endl;
|
||||
#else
|
||||
sif::printError("%s pclose failed with code %d: %s\n", funcName, lastError,
|
||||
strerror(lastError));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void CommandExecutor::setRingBuffer(SimpleRingBuffer* ringBuffer,
|
||||
DynamicFIFO<uint16_t>* sizesFifo) {
|
||||
this->ringBuffer = ringBuffer;
|
||||
this->sizesFifo = sizesFifo;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
||||
if (blocking) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
switch (state) {
|
||||
case (States::IDLE):
|
||||
case (States::COMMAND_LOADED): {
|
||||
return NO_COMMAND_LOADED_OR_PENDING;
|
||||
}
|
||||
case (States::PENDING): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int result = poll(&waiter, 1, 0);
|
||||
switch (result) {
|
||||
case (0): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
break;
|
||||
}
|
||||
case (1): {
|
||||
if (waiter.revents & POLLIN) {
|
||||
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
||||
if (readBytes == 0) {
|
||||
// Should not happen
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CommandExecutor::check: No bytes read "
|
||||
"after poll event.."
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
|
||||
#endif
|
||||
break;
|
||||
} else if (readBytes > 0) {
|
||||
replyReceived = true;
|
||||
if (printOutput) {
|
||||
// It is assumed the command output is line terminated
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << currentCmd << " | " << readVec.data();
|
||||
#else
|
||||
sif::printInfo("%s | %s", currentCmd, readVec.data());
|
||||
#endif
|
||||
}
|
||||
if (ringBuffer != nullptr) {
|
||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(readVec.data()), readBytes);
|
||||
}
|
||||
if (sizesFifo != nullptr) {
|
||||
if (not sizesFifo->full()) {
|
||||
sizesFifo->insert(readBytes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Should also not happen
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CommandExecutor::check: Error " << errno << ": " << strerror(errno)
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (waiter.revents & POLLERR) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
||||
#else
|
||||
sif::printWarning("CommandExecuter::check: Poll error\n");
|
||||
#endif
|
||||
return COMMAND_ERROR;
|
||||
}
|
||||
if (waiter.revents & POLLHUP) {
|
||||
result = pclose(currentCmdFile);
|
||||
ReturnValue_t retval = EXECUTION_FINISHED;
|
||||
if (result != 0) {
|
||||
lastError = result;
|
||||
retval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
state = States::IDLE;
|
||||
currentCmdFile = nullptr;
|
||||
currentFd = 0;
|
||||
return retval;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CommandExecutor::reset() {
|
||||
CommandExecutor::close();
|
||||
currentCmdFile = nullptr;
|
||||
currentFd = 0;
|
||||
state = States::IDLE;
|
||||
}
|
||||
|
||||
int CommandExecutor::getLastError() const {
|
||||
// See:
|
||||
// https://stackoverflow.com/questions/808541/any-benefit-in-using-wexitstatus-macro-in-c-over-division-by-256-on-exit-statu
|
||||
return WEXITSTATUS(this->lastError);
|
||||
}
|
||||
|
||||
CommandExecutor::States CommandExecutor::getCurrentState() const { return state; }
|
||||
|
||||
ReturnValue_t CommandExecutor::executeBlocking() {
|
||||
while (fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
||||
std::string output(readVec.data());
|
||||
if (printOutput) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << currentCmd << " | " << output;
|
||||
#else
|
||||
sif::printInfo("%s | %s", currentCmd, output);
|
||||
#endif
|
||||
}
|
||||
if (ringBuffer != nullptr) {
|
||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
||||
}
|
||||
if (sizesFifo != nullptr) {
|
||||
if (not sizesFifo->full()) {
|
||||
sizesFifo->insert(output.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
int result = pclose(currentCmdFile);
|
||||
if (result != 0) {
|
||||
lastError = result;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
129
hal/src/fsfw_hal/linux/CommandExecutor.h
Normal file
129
hal/src/fsfw_hal/linux/CommandExecutor.h
Normal file
@ -0,0 +1,129 @@
|
||||
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||
|
||||
#include <poll.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class SimpleRingBuffer;
|
||||
template <typename T>
|
||||
class DynamicFIFO;
|
||||
|
||||
/**
|
||||
* @brief Helper class to execute shell commands in blocking and non-blocking mode
|
||||
* @details
|
||||
* This class is able to execute processes by using the Linux popen call. It also has the
|
||||
* capability of writing the read output of a process into a provided ring buffer.
|
||||
*
|
||||
* The executor works by first loading the command which should be executed and specifying
|
||||
* whether it should be executed blocking or non-blocking. After that, execution can be started
|
||||
* with the execute command. In blocking mode, the execute command will block until the command
|
||||
* has finished
|
||||
*/
|
||||
class CommandExecutor {
|
||||
public:
|
||||
enum class States { IDLE, COMMAND_LOADED, PENDING };
|
||||
|
||||
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
||||
static constexpr ReturnValue_t EXECUTION_FINISHED =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
|
||||
|
||||
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
|
||||
//! to load another command but a command is still pending
|
||||
static constexpr ReturnValue_t COMMAND_PENDING = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
||||
static constexpr ReturnValue_t BYTES_READ = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||
//! [EXPORT] : [COMMENT] Command execution failed
|
||||
static constexpr ReturnValue_t COMMAND_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
|
||||
//! [EXPORT] : [COMMENT]
|
||||
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
|
||||
static constexpr ReturnValue_t PCLOSE_CALL_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
|
||||
|
||||
/**
|
||||
* Constructor. Is initialized with maximum size of internal buffer to read data from the
|
||||
* executed process.
|
||||
* @param maxSize
|
||||
*/
|
||||
CommandExecutor(const size_t maxSize);
|
||||
|
||||
/**
|
||||
* Load a new command which should be executed
|
||||
* @param command
|
||||
* @param blocking
|
||||
* @param printOutput
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t load(std::string command, bool blocking, bool printOutput = true);
|
||||
/**
|
||||
* Execute the loaded command.
|
||||
* @return
|
||||
* - In blocking mode, it will return RETURN_FAILED if
|
||||
* the result of the system call was not 0. The error value can be accessed using
|
||||
* getLastError
|
||||
* - In non-blocking mode, this call will start
|
||||
* the execution and then return RETURN_OK
|
||||
*/
|
||||
ReturnValue_t execute();
|
||||
/**
|
||||
* Only used in non-blocking mode. Checks the currently running command.
|
||||
* @param bytesRead Will be set to the number of bytes read, if bytes have been read
|
||||
* @return
|
||||
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
||||
* check again after this
|
||||
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
|
||||
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
|
||||
* - EXECUTION_FINISHED if the process was executed successfully
|
||||
* - NO_COMMAND_LOADED_OR_PENDING self-explanatory
|
||||
* - COMMAND_ERROR internal poll error
|
||||
*/
|
||||
ReturnValue_t check(bool& replyReceived);
|
||||
/**
|
||||
* Abort the current command. Should normally not be necessary, check can be used to find
|
||||
* out whether command execution was successful
|
||||
* @return RETURN_OK
|
||||
*/
|
||||
ReturnValue_t close();
|
||||
|
||||
States getCurrentState() const;
|
||||
int getLastError() const;
|
||||
void printLastError(std::string funcName) const;
|
||||
|
||||
/**
|
||||
* Assign a ring buffer and a FIFO which will be filled by the executor with the output
|
||||
* read from the started process
|
||||
* @param ringBuffer
|
||||
* @param sizesFifo
|
||||
*/
|
||||
void setRingBuffer(SimpleRingBuffer* ringBuffer, DynamicFIFO<uint16_t>* sizesFifo);
|
||||
|
||||
/**
|
||||
* Reset the executor. This calls close internally and then reset the state machine so new
|
||||
* commands can be loaded and executed
|
||||
*/
|
||||
void reset();
|
||||
|
||||
private:
|
||||
std::string currentCmd;
|
||||
bool blocking = true;
|
||||
FILE* currentCmdFile = nullptr;
|
||||
int currentFd = 0;
|
||||
bool printOutput = true;
|
||||
std::vector<char> readVec;
|
||||
struct pollfd waiter {};
|
||||
SimpleRingBuffer* ringBuffer = nullptr;
|
||||
DynamicFIFO<uint16_t>* sizesFifo = nullptr;
|
||||
|
||||
States state = States::IDLE;
|
||||
int lastError = 0;
|
||||
|
||||
ReturnValue_t executeBlocking();
|
||||
};
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_ */
|
@ -1,13 +1,14 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
|
||||
UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
||||
std::string diagnosticPrefix):
|
||||
fileDescriptor(fileDescriptor) {
|
||||
std::string diagnosticPrefix)
|
||||
: fileDescriptor(fileDescriptor) {
|
||||
if (fileDescriptor == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -15,11 +16,11 @@ UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
||||
if (*fileDescriptor < 0) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << diagnosticPrefix << ": Opening device failed with error code " <<
|
||||
errno << ": " << strerror(errno) << std::endl;
|
||||
sif::warning << diagnosticPrefix << ": Opening device failed with error code " << errno << ": "
|
||||
<< strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printWarning("%s: Opening device failed with error code %d: %s\n",
|
||||
diagnosticPrefix, errno, strerror(errno));
|
||||
sif::printWarning("%s: Opening device failed with error code %d: %s\n", diagnosticPrefix, errno,
|
||||
strerror(errno));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
openStatus = OPEN_FILE_FAILED;
|
||||
@ -32,6 +33,4 @@ UnixFileGuard::~UnixFileGuard() {
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t UnixFileGuard::getOpenResult() const {
|
||||
return openStatus;
|
||||
}
|
||||
ReturnValue_t UnixFileGuard::getOpenResult() const { return openStatus; }
|
||||
|
@ -1,13 +1,11 @@
|
||||
#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_
|
||||
#define LINUX_UTILITY_UNIXFILEGUARD_H_
|
||||
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class UnixFileGuard {
|
||||
public:
|
||||
@ -23,11 +21,10 @@ public:
|
||||
virtual ~UnixFileGuard();
|
||||
|
||||
ReturnValue_t getOpenResult() const;
|
||||
|
||||
private:
|
||||
int* fileDescriptor = nullptr;
|
||||
ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */
|
||||
|
@ -1,12 +1,16 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
LinuxLibgpioIF.cpp
|
||||
)
|
||||
|
||||
# This abstraction layer requires the gpiod library. You can install this library
|
||||
# with "sudo apt-get install -y libgpiod-dev". If you are cross-compiling, you need
|
||||
# to install the package before syncing the sysroot to your host computer.
|
||||
find_library(LIB_GPIO gpiod REQUIRED)
|
||||
find_library(LIB_GPIO gpiod)
|
||||
|
||||
if(${LIB_GPIO} MATCHES LIB_GPIO-NOTFOUND)
|
||||
message(STATUS "gpiod library not found, not linking against it")
|
||||
else()
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
LinuxLibgpioIF.cpp
|
||||
)
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
${LIB_GPIO}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
27
hal/src/fsfw_hal/linux/gpio/Gpio.h
Normal file
27
hal/src/fsfw_hal/linux/gpio/Gpio.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef FSFW_HAL_SRC_FSFW_HAL_LINUX_GPIO_GPIO_H_
|
||||
#define FSFW_HAL_SRC_FSFW_HAL_LINUX_GPIO_GPIO_H_
|
||||
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||
|
||||
/**
|
||||
* @brief Additional abstraction layer for handling GPIOs.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class Gpio {
|
||||
public:
|
||||
Gpio(gpioId_t gpioId, GpioIF* gpioIF) : gpioId(gpioId), gpioIF(gpioIF) {
|
||||
if (gpioIF == nullptr) {
|
||||
sif::error << "Gpio::Gpio: Invalid GpioIF" << std::endl;
|
||||
}
|
||||
}
|
||||
ReturnValue_t pullHigh() { return gpioIF->pullHigh(gpioId); }
|
||||
ReturnValue_t pullLow() { return gpioIF->pullLow(gpioId); }
|
||||
|
||||
private:
|
||||
gpioId_t gpioId = gpio::NO_GPIO;
|
||||
GpioIF* gpioIF = nullptr;
|
||||
};
|
||||
|
||||
#endif /* FSFW_HAL_SRC_FSFW_HAL_LINUX_GPIO_GPIO_H_ */
|
@ -1,16 +1,15 @@
|
||||
#include "LinuxLibgpioIF.h"
|
||||
|
||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include <gpiod.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <utility>
|
||||
#include <unistd.h>
|
||||
#include <gpiod.h>
|
||||
|
||||
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {
|
||||
}
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||
|
||||
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {}
|
||||
|
||||
LinuxLibgpioIF::~LinuxLibgpioIF() {
|
||||
for (auto& config : gpioMap) {
|
||||
@ -45,6 +44,7 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
for (auto& gpioConfig : mapToAdd) {
|
||||
auto& gpioType = gpioConfig.second->gpioType;
|
||||
switch (gpioType) {
|
||||
@ -56,7 +56,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||
if (regularGpio == nullptr) {
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
configureGpioByChip(gpioConfig.first, *regularGpio);
|
||||
result = configureGpioByChip(gpioConfig.first, *regularGpio);
|
||||
break;
|
||||
}
|
||||
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): {
|
||||
@ -64,7 +64,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||
if (regularGpio == nullptr) {
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
configureGpioByLabel(gpioConfig.first, *regularGpio);
|
||||
result = configureGpioByLabel(gpioConfig.first, *regularGpio);
|
||||
break;
|
||||
}
|
||||
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
||||
@ -72,7 +72,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||
if (regularGpio == nullptr) {
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
configureGpioByLineName(gpioConfig.first, *regularGpio);
|
||||
result = configureGpioByLineName(gpioConfig.first, *regularGpio);
|
||||
break;
|
||||
}
|
||||
case (gpio::GpioTypes::CALLBACK): {
|
||||
@ -84,8 +84,11 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||
gpioCallback->initValue, gpioCallback->callbackArgs);
|
||||
}
|
||||
}
|
||||
if (result != RETURN_OK) {
|
||||
return GPIO_INIT_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
|
||||
@ -96,19 +99,17 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
|
||||
sif::warning << "LinuxLibgpioIF::configureGpioByLabel: Failed to open gpio from gpio "
|
||||
<< "group with label " << label << ". Gpio ID: " << gpioId << std::endl;
|
||||
return RETURN_FAILED;
|
||||
|
||||
}
|
||||
std::string failOutput = "label: " + label;
|
||||
return configureRegularGpio(gpioId, chip, gpioByLabel, failOutput);
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId,
|
||||
GpiodRegularByChip &gpioByChip) {
|
||||
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip) {
|
||||
std::string& chipname = gpioByChip.chipname;
|
||||
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str());
|
||||
if (chip == nullptr) {
|
||||
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip "
|
||||
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
||||
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip " << chipname
|
||||
<< ". Gpio ID: " << gpioId << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
std::string failOutput = "chipname: " + chipname;
|
||||
@ -121,8 +122,8 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
||||
char chipname[MAX_CHIPNAME_LENGTH];
|
||||
unsigned int lineOffset;
|
||||
|
||||
int result = gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH,
|
||||
&lineOffset);
|
||||
int result =
|
||||
gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH, &lineOffset);
|
||||
if (result != LINE_FOUND) {
|
||||
parseFindeLineResult(result, lineName);
|
||||
return RETURN_FAILED;
|
||||
@ -132,8 +133,8 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
||||
|
||||
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname);
|
||||
if (chip == nullptr) {
|
||||
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip "
|
||||
<< chipname << ". <Gpio ID: " << gpioId << std::endl;
|
||||
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip " << chipname
|
||||
<< ". <Gpio ID: " << gpioId << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
std::string failOutput = "line name: " + lineName;
|
||||
@ -141,7 +142,8 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
||||
GpiodRegularBase& regularGpio, std::string failOutput) {
|
||||
GpiodRegularBase& regularGpio,
|
||||
std::string failOutput) {
|
||||
unsigned int lineNum;
|
||||
gpio::Direction direction;
|
||||
std::string consumer;
|
||||
@ -152,8 +154,8 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
|
||||
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
||||
if (!lineHandle) {
|
||||
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
|
||||
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
|
||||
", " << failOutput << std::endl;
|
||||
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum << ", " << failOutput
|
||||
<< std::endl;
|
||||
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
|
||||
gpiod_chip_close(chip);
|
||||
return RETURN_FAILED;
|
||||
@ -163,33 +165,33 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
|
||||
consumer = regularGpio.consumer;
|
||||
/* Configure direction and add a description to the GPIO */
|
||||
switch (direction) {
|
||||
case(gpio::OUT): {
|
||||
case (gpio::Direction::OUT): {
|
||||
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
||||
regularGpio.initValue);
|
||||
static_cast<int>(regularGpio.initValue));
|
||||
break;
|
||||
}
|
||||
case(gpio::IN): {
|
||||
case (gpio::Direction::IN): {
|
||||
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified"
|
||||
<< std::endl;
|
||||
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified" << std::endl;
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " <<
|
||||
lineNum << " from GPIO instance with ID: " << gpioId << std::endl;
|
||||
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum
|
||||
<< " from GPIO instance with ID: " << gpioId << std::endl;
|
||||
#else
|
||||
sif::printError("LinuxLibgpioIF::configureRegularGpio: "
|
||||
"Failed to request line %d from GPIO instance with ID: %d\n", lineNum, gpioId);
|
||||
sif::printError(
|
||||
"LinuxLibgpioIF::configureRegularGpio: "
|
||||
"Failed to request line %d from GPIO instance with ID: %d\n",
|
||||
lineNum, gpioId);
|
||||
#endif
|
||||
gpiod_line_release(lineHandle);
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Write line handle to GPIO configuration instance so it can later be used to set or
|
||||
@ -207,22 +209,21 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
||||
}
|
||||
|
||||
auto gpioType = gpioMapIter->second->gpioType;
|
||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
|
||||
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
|
||||
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||
if (regularGpio == nullptr) {
|
||||
return GPIO_TYPE_FAILURE;
|
||||
}
|
||||
return driveGpio(gpioId, *regularGpio, gpio::HIGH);
|
||||
}
|
||||
else {
|
||||
return driveGpio(gpioId, *regularGpio, gpio::Levels::HIGH);
|
||||
} else {
|
||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||
if (gpioCallback->callback == nullptr) {
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||
gpio::Levels::HIGH, gpioCallback->callbackArgs);
|
||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::HIGH,
|
||||
gpioCallback->callbackArgs);
|
||||
return RETURN_OK;
|
||||
}
|
||||
return GPIO_TYPE_FAILURE;
|
||||
@ -240,37 +241,38 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
||||
}
|
||||
|
||||
auto& gpioType = gpioMapIter->second->gpioType;
|
||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
|
||||
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
|
||||
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||
if (regularGpio == nullptr) {
|
||||
return GPIO_TYPE_FAILURE;
|
||||
}
|
||||
return driveGpio(gpioId, *regularGpio, gpio::LOW);
|
||||
}
|
||||
else {
|
||||
return driveGpio(gpioId, *regularGpio, gpio::Levels::LOW);
|
||||
} else {
|
||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||
if (gpioCallback->callback == nullptr) {
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||
gpio::Levels::LOW, gpioCallback->callbackArgs);
|
||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::LOW,
|
||||
gpioCallback->callbackArgs);
|
||||
return RETURN_OK;
|
||||
}
|
||||
return GPIO_TYPE_FAILURE;
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
||||
GpiodRegularBase& regularGpio, gpio::Levels logicLevel) {
|
||||
int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel);
|
||||
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
|
||||
gpio::Levels logicLevel) {
|
||||
int result = gpiod_line_set_value(regularGpio.lineHandle, static_cast<int>(logicLevel));
|
||||
if (result < 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId <<
|
||||
" to logic level " << logicLevel << std::endl;
|
||||
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId
|
||||
<< " to logic level " << static_cast<int>(logicLevel) << std::endl;
|
||||
#else
|
||||
sif::printWarning("LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
|
||||
"logic level %d\n", gpioId, logicLevel);
|
||||
sif::printWarning(
|
||||
"LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
|
||||
"logic level %d\n",
|
||||
gpioId, logicLevel);
|
||||
#endif
|
||||
return DRIVE_GPIO_FAILURE;
|
||||
}
|
||||
@ -278,7 +280,7 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
||||
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, gpio::Levels& gpioState) {
|
||||
gpioMapIter = gpioMap.find(gpioId);
|
||||
if (gpioMapIter == gpioMap.end()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
@ -290,22 +292,24 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
||||
}
|
||||
|
||||
auto gpioType = gpioMapIter->second->gpioType;
|
||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
|
||||
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
|
||||
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||
if (regularGpio == nullptr) {
|
||||
return GPIO_TYPE_FAILURE;
|
||||
}
|
||||
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
||||
gpioState = static_cast<gpio::Levels>(gpiod_line_get_value(regularGpio->lineHandle));
|
||||
if (gpioState == gpio::Levels::FAILED) {
|
||||
return GPIO_GET_VALUE_FAILED;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||
if (gpioCallback->callback == nullptr) {
|
||||
return GPIO_INVALID_INSTANCE;
|
||||
}
|
||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ,
|
||||
gpio::Levels::NONE, gpioCallback->callbackArgs);
|
||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, gpio::Levels::NONE,
|
||||
gpioCallback->callbackArgs);
|
||||
return RETURN_OK;
|
||||
}
|
||||
return RETURN_OK;
|
||||
@ -336,8 +340,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
||||
return GPIO_TYPE_FAILURE;
|
||||
}
|
||||
// Check for conflicts and remove duplicates if necessary
|
||||
result = checkForConflictsById(gpioConfig.first,
|
||||
gpioConfig.second->gpioType, mapToAdd);
|
||||
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
@ -345,8 +348,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
||||
}
|
||||
default: {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first
|
||||
<< std::endl;
|
||||
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first << std::endl;
|
||||
#else
|
||||
sif::printWarning("Invalid GPIO type detected for GPIO ID %d\n", gpioConfig.first);
|
||||
#endif
|
||||
@ -358,7 +360,8 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
||||
}
|
||||
|
||||
ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
||||
gpio::GpioTypes expectedType, GpioMap& mapToAdd) {
|
||||
gpio::GpioTypes expectedType,
|
||||
GpioMap& mapToAdd) {
|
||||
// Cross check with private map
|
||||
gpioMapIter = gpioMap.find(gpioIdToCheck);
|
||||
if (gpioMapIter != gpioMap.end()) {
|
||||
@ -385,11 +388,13 @@ ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
||||
if (eraseDuplicateDifferentType) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||
"different GPIO type " << gpioIdToCheck <<
|
||||
". Removing duplicate from map to add" << std::endl;
|
||||
"different GPIO type "
|
||||
<< gpioIdToCheck << ". Removing duplicate from map to add" << std::endl;
|
||||
#else
|
||||
sif::printWarning("LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||
"different GPIO type %d. Removing duplicate from map to add\n", gpioIdToCheck);
|
||||
sif::printWarning(
|
||||
"LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||
"different GPIO type %d. Removing duplicate from map to add\n",
|
||||
gpioIdToCheck);
|
||||
#endif
|
||||
mapToAdd.erase(gpioIdToCheck);
|
||||
return GPIO_DUPLICATE_DETECTED;
|
||||
@ -398,11 +403,14 @@ ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
||||
// Remove element from map to add because a entry for this GPIO already exists
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO "
|
||||
"definition with ID " << gpioIdToCheck << " detected. " <<
|
||||
"Duplicate will be removed from map to add" << std::endl;
|
||||
"definition with ID "
|
||||
<< gpioIdToCheck << " detected. "
|
||||
<< "Duplicate will be removed from map to add" << std::endl;
|
||||
#else
|
||||
sif::printWarning("LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
|
||||
"with ID %d detected. Duplicate will be removed from map to add\n", gpioIdToCheck);
|
||||
sif::printWarning(
|
||||
"LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
|
||||
"with ID %d detected. Duplicate will be removed from map to add\n",
|
||||
gpioIdToCheck);
|
||||
#endif
|
||||
mapToAdd.erase(gpioIdToCheck);
|
||||
return GPIO_DUPLICATE_DETECTED;
|
||||
@ -415,28 +423,32 @@ void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
case LINE_NOT_EXISTS:
|
||||
case LINE_ERROR: {
|
||||
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName <<
|
||||
" does not exist" << std::endl;
|
||||
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName
|
||||
<< " does not exist" << std::endl;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||
"with name " << lineName << std::endl;
|
||||
"with name "
|
||||
<< lineName << std::endl;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
case LINE_NOT_EXISTS:
|
||||
case LINE_ERROR: {
|
||||
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
|
||||
"does not exist\n", lineName);
|
||||
sif::printWarning(
|
||||
"LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
|
||||
"does not exist\n",
|
||||
lineName);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||
"with name %s\n", lineName);
|
||||
sif::printWarning(
|
||||
"LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||
"with name %s\n",
|
||||
lineName);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
|
||||
class GpioCookie;
|
||||
class GpiodRegularIF;
|
||||
@ -17,7 +17,6 @@ class GpiodRegularIF;
|
||||
*/
|
||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
||||
public:
|
||||
|
||||
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
|
||||
|
||||
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
||||
@ -30,17 +29,20 @@ public:
|
||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4);
|
||||
static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED =
|
||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 5);
|
||||
|
||||
static constexpr ReturnValue_t GPIO_INIT_FAILED =
|
||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 6);
|
||||
// Will be returned if getting the line value failed. Error type will be set to errno in this case
|
||||
static constexpr ReturnValue_t GPIO_GET_VALUE_FAILED =
|
||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 7);
|
||||
LinuxLibgpioIF(object_id_t objectId);
|
||||
virtual ~LinuxLibgpioIF();
|
||||
|
||||
ReturnValue_t addGpios(GpioCookie* gpioCookie) override;
|
||||
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
||||
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
||||
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
||||
ReturnValue_t readGpio(gpioId_t gpioId, gpio::Levels& gpioState) override;
|
||||
|
||||
private:
|
||||
|
||||
static const size_t MAX_CHIPNAME_LENGTH = 11;
|
||||
static const int LINE_NOT_EXISTS = 0;
|
||||
static const int LINE_ERROR = -1;
|
||||
@ -56,13 +58,11 @@ private:
|
||||
* @param gpioId The GPIO ID of the GPIO to drive.
|
||||
* @param logiclevel The logic level to set. O or 1.
|
||||
*/
|
||||
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
|
||||
gpio::Levels logicLevel);
|
||||
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio, gpio::Levels logicLevel);
|
||||
|
||||
ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel);
|
||||
ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip);
|
||||
ReturnValue_t configureGpioByLineName(gpioId_t gpioId,
|
||||
GpiodRegularByLineName &gpioByLineName);
|
||||
ReturnValue_t configureGpioByLineName(gpioId_t gpioId, GpiodRegularByLineName& gpioByLineName);
|
||||
ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
||||
GpiodRegularBase& regularGpio, std::string failOutput);
|
||||
|
||||
@ -77,8 +77,7 @@ private:
|
||||
*/
|
||||
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
||||
|
||||
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
|
||||
GpioMap& mapToAdd);
|
||||
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type, GpioMap& mapToAdd);
|
||||
|
||||
/**
|
||||
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
||||
|
@ -1,35 +1,41 @@
|
||||
#include "fsfw_hal/linux/i2c/I2cComIF.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
#include "I2cComIF.h"
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
||||
I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){
|
||||
}
|
||||
I2cComIF::I2cComIF(object_id_t objectId) : SystemObject(objectId) {}
|
||||
|
||||
I2cComIF::~I2cComIF() {}
|
||||
|
||||
ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
|
||||
|
||||
address_t i2cAddress;
|
||||
std::string deviceFile;
|
||||
|
||||
if (cookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||
if (i2cCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
@ -41,28 +47,32 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
|
||||
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
|
||||
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
|
||||
if (not statusPair.second) {
|
||||
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
|
||||
i2cAddress << "to I2C device " << "map" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address "
|
||||
<< i2cAddress << "to I2C device "
|
||||
<< "map" << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress <<
|
||||
"already in use" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress
|
||||
<< "already in use" << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
|
||||
const uint8_t *sendData, size_t sendLen) {
|
||||
|
||||
ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||
ReturnValue_t result;
|
||||
int fd;
|
||||
std::string deviceFile;
|
||||
|
||||
if (sendData == nullptr) {
|
||||
sif::error << "I2cComIF::sendMessage: Send Data is nullptr"
|
||||
<< std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -72,15 +82,19 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
|
||||
|
||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||
if (i2cCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
address_t i2cAddress = i2cCookie->getAddress();
|
||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not "
|
||||
<< "registered in i2cDeviceMap" << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -94,21 +108,25 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
|
||||
return result;
|
||||
}
|
||||
|
||||
if (write(fd, sendData, sendLen) != (int)sendLen) {
|
||||
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
|
||||
"device with error code " << errno << ". Error description: "
|
||||
<< strerror(errno) << std::endl;
|
||||
"device with error code "
|
||||
<< errno << ". Error description: " << strerror(errno) << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
||||
sif::info << "Sent I2C data to bus " << deviceFile << ":" << std::endl;
|
||||
arrayprinter::print(sendData, sendLen);
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cComIF::getSendSuccess(CookieIF *cookie) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ReturnValue_t I2cComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||
|
||||
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) {
|
||||
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||
ReturnValue_t result;
|
||||
int fd;
|
||||
std::string deviceFile;
|
||||
@ -119,7 +137,9 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
||||
|
||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||
if (i2cCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl;
|
||||
#endif
|
||||
i2cDeviceMapIter->second.replyLen = 0;
|
||||
return NULLPOINTER;
|
||||
}
|
||||
@ -127,8 +147,10 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
||||
address_t i2cAddress = i2cCookie->getAddress();
|
||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not "
|
||||
<< "registered in i2cDeviceMap" << std::endl;
|
||||
#endif
|
||||
i2cDeviceMapIter->second.replyLen = 0;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
@ -148,35 +170,48 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
||||
|
||||
int readLen = read(fd, replyBuffer, requestLen);
|
||||
if (readLen != static_cast<int>(requestLen)) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
||||
<< "device failed with error code " << errno <<". Description"
|
||||
<< " of error: " << strerror(errno) << std::endl;
|
||||
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
if (readLen < 0) {
|
||||
sif::warning << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
||||
<< "device failed with error code " << errno << " | " << strerror(errno)
|
||||
<< std::endl;
|
||||
} else {
|
||||
sif::warning << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
|
||||
<< requestLen << " bytes" << std::endl;
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
i2cDeviceMapIter->second.replyLen = 0;
|
||||
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen << " bytes" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
||||
sif::info << "I2C read bytes from bus " << deviceFile << ":" << std::endl;
|
||||
arrayprinter::print(replyBuffer, requestLen);
|
||||
#endif
|
||||
|
||||
i2cDeviceMapIter->second.replyLen = requestLen;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **buffer, size_t* size) {
|
||||
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||
if (i2cCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
address_t i2cAddress = i2cCookie->getAddress();
|
||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not "
|
||||
<< "found in i2cDeviceMap" << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*buffer = i2cDeviceMapIter->second.replyBuffer.data();
|
||||
@ -185,9 +220,8 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cComIF::openDevice(std::string deviceFile,
|
||||
address_t i2cAddress, int* fileDescriptor) {
|
||||
|
||||
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
|
||||
int* fileDescriptor) {
|
||||
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
|
@ -1,13 +1,14 @@
|
||||
#ifndef LINUX_I2C_I2COMIF_H_
|
||||
#define LINUX_I2C_I2COMIF_H_
|
||||
|
||||
#include "I2cCookie.h"
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "I2cCookie.h"
|
||||
|
||||
/**
|
||||
* @brief This is the communication interface for I2C devices connected
|
||||
* to a system running a Linux OS.
|
||||
@ -23,16 +24,12 @@ public:
|
||||
virtual ~I2cComIF();
|
||||
|
||||
ReturnValue_t initializeInterface(CookieIF *cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
|
||||
size_t sendLen) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
|
||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
|
||||
|
||||
private:
|
||||
|
||||
struct I2cInstance {
|
||||
std::vector<uint8_t> replyBuffer;
|
||||
size_t replyLen;
|
||||
@ -54,8 +51,7 @@ private:
|
||||
* @param fileDescriptor Pointer to device descriptor.
|
||||
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
|
||||
*/
|
||||
ReturnValue_t openDevice(std::string deviceFile,
|
||||
address_t i2cAddress, int* fileDescriptor);
|
||||
ReturnValue_t openDevice(std::string deviceFile, address_t i2cAddress, int *fileDescriptor);
|
||||
};
|
||||
|
||||
#endif /* LINUX_I2C_I2COMIF_H_ */
|
||||
|
@ -1,20 +1,12 @@
|
||||
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
||||
|
||||
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
|
||||
std::string deviceFile_) :
|
||||
i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {
|
||||
}
|
||||
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_)
|
||||
: i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {}
|
||||
|
||||
address_t I2cCookie::getAddress() const {
|
||||
return i2cAddress;
|
||||
}
|
||||
address_t I2cCookie::getAddress() const { return i2cAddress; }
|
||||
|
||||
size_t I2cCookie::getMaxReplyLen() const {
|
||||
return maxReplyLen;
|
||||
}
|
||||
size_t I2cCookie::getMaxReplyLen() const { return maxReplyLen; }
|
||||
|
||||
std::string I2cCookie::getDeviceFile() const {
|
||||
return deviceFile;
|
||||
}
|
||||
std::string I2cCookie::getDeviceFile() const { return deviceFile; }
|
||||
|
||||
I2cCookie::~I2cCookie() {}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define LINUX_I2C_I2CCOOKIE_H_
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
@ -11,7 +12,6 @@
|
||||
*/
|
||||
class I2cCookie : public CookieIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructor for the I2C cookie.
|
||||
* @param i2cAddress_ The i2c address of the target device.
|
||||
@ -19,8 +19,7 @@ public:
|
||||
* target device.
|
||||
* @param devicFile_ The device file specifying the i2c interface to use. E.g. "/dev/i2c-0".
|
||||
*/
|
||||
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
|
||||
std::string deviceFile_);
|
||||
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_);
|
||||
|
||||
virtual ~I2cCookie();
|
||||
|
||||
@ -29,7 +28,6 @@ public:
|
||||
std::string getDeviceFile() const;
|
||||
|
||||
private:
|
||||
|
||||
address_t i2cAddress = 0;
|
||||
size_t maxReplyLen = 0;
|
||||
std::string deviceFile;
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
|
||||
#include "fsfw_hal/linux/rpi/GpioRPi.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
|
||||
ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
|
||||
std::string consumer, gpio::Direction direction, int initValue) {
|
||||
std::string consumer, gpio::Direction direction,
|
||||
gpio::Levels initValue) {
|
||||
if (cookie == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define BSP_RPI_GPIO_GPIORPI_H_
|
||||
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#include "../../common/gpio/gpioDefinitions.h"
|
||||
|
||||
class GpioCookie;
|
||||
@ -20,7 +21,8 @@ namespace gpio {
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
|
||||
std::string consumer, gpio::Direction direction, int initValue);
|
||||
}
|
||||
std::string consumer, gpio::Direction direction,
|
||||
gpio::Levels initValue);
|
||||
} // namespace gpio
|
||||
|
||||
#endif /* BSP_RPI_GPIO_GPIORPI_H_ */
|
||||
|
@ -1,22 +1,22 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw_hal/linux/spi/SpiComIF.h"
|
||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
|
||||
#include <fsfw/ipc/MutexFactory.h>
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
#include <fsfw/ipc/MutexFactory.h>
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
|
||||
SystemObject(objectId), gpioComIF(gpioComIF) {
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
|
||||
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF)
|
||||
: SystemObject(objectId), gpioComIF(gpioComIF) {
|
||||
if (gpioComIF == nullptr) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
@ -47,11 +47,13 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
if (not statusPair.second) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " <<
|
||||
spiAddress << "to SPI device map" << std::endl;
|
||||
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address "
|
||||
<< spiAddress << "to SPI device map" << std::endl;
|
||||
#else
|
||||
sif::printError("SpiComIF::initializeInterface: Failed to insert device with address "
|
||||
"%lu to SPI device map\n", static_cast<unsigned long>(spiAddress));
|
||||
sif::printError(
|
||||
"SpiComIF::initializeInterface: Failed to insert device with address "
|
||||
"%lu to SPI device map\n",
|
||||
static_cast<unsigned long>(spiAddress));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -59,8 +61,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
/* Now we emplaced the read buffer in the map, we still need to assign that location
|
||||
to the SPI driver transfer struct */
|
||||
spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "SpiComIF::initializeInterface: SPI address already exists!" << std::endl;
|
||||
@ -123,7 +124,8 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
if (params.bitsPerWord != 8) {
|
||||
retval = ioctl(fileDescriptor, SPI_IOC_WR_BITS_PER_WORD, ¶ms.bitsPerWord);
|
||||
if (retval != 0) {
|
||||
utility::handleIoctlError("SpiComIF::initializeInterface: "
|
||||
utility::handleIoctlError(
|
||||
"SpiComIF::initializeInterface: "
|
||||
"Could not write bits per word!");
|
||||
}
|
||||
}
|
||||
@ -141,11 +143,14 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
||||
if (sendLen > spiCookie->getMaxBufferSize()) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen <<
|
||||
"larger than maximum buffer length " << spiCookie->getMaxBufferSize() << std::endl;
|
||||
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen
|
||||
<< "larger than maximum buffer length " << spiCookie->getMaxBufferSize()
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger "
|
||||
"than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen),
|
||||
sif::printWarning(
|
||||
"SpiComIF::sendMessage: Too much data sent, send length %lu larger "
|
||||
"than maximum buffer length %lu!\n",
|
||||
static_cast<unsigned long>(sendLen),
|
||||
static_cast<unsigned long>(spiCookie->getMaxBufferSize()));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
@ -154,8 +159,7 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
||||
|
||||
if (spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
|
||||
result = performRegularSendOperation(spiCookie, sendData, sendLen);
|
||||
}
|
||||
else if(spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
|
||||
} else if (spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
|
||||
spi::send_callback_function_t sendFunc = nullptr;
|
||||
void* funcArgs = nullptr;
|
||||
spiCookie->getCallback(&sendFunc, &funcArgs);
|
||||
@ -230,14 +234,12 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
||||
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||
performSpiWiretapping(spiCookie);
|
||||
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* We write with a blocking half-duplex transfer here */
|
||||
if (write(fileDescriptor, sendData, sendLen) != static_cast<ssize_t>(sendLen)) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" <<
|
||||
std::endl;
|
||||
sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("SpiComIF::sendMessage: Half-Duplex write operation failed!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
@ -259,9 +261,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||
|
||||
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||
@ -276,13 +276,11 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
|
||||
return performHalfDuplexReception(spiCookie);
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
std::string device = spiCookie->getSpiDevice();
|
||||
int fileDescriptor = 0;
|
||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
|
||||
"SpiComIF::requestReceiveMessage");
|
||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
|
||||
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return OPENING_FILE_FAILED;
|
||||
}
|
||||
@ -391,9 +389,7 @@ ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
GpioIF* SpiComIF::getGpioInterface() {
|
||||
return gpioComIF;
|
||||
}
|
||||
GpioIF* SpiComIF::getGpioInterface() { return gpioComIF; }
|
||||
|
||||
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
|
||||
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
||||
@ -405,4 +401,12 @@ void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed)
|
||||
if (retval != 0) {
|
||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
||||
}
|
||||
// This updates the SPI clock default polarity. Only setting the mode does not update
|
||||
// the line state, which can be an issue on mode switches because the clock line will
|
||||
// switch the state after the chip select is pulled low
|
||||
clockUpdateTransfer.len = 0;
|
||||
retval = ioctl(spiFd, SPI_IOC_MESSAGE(1), &clockUpdateTransfer);
|
||||
if (retval != 0) {
|
||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Updating SPI default clock failed");
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
#ifndef LINUX_SPI_SPICOMIF_H_
|
||||
#define LINUX_SPI_SPICOMIF_H_
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "spiDefinitions.h"
|
||||
#include "returnvalues/classIds.h"
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
#include "returnvalues/classIds.h"
|
||||
#include "spiDefinitions.h"
|
||||
|
||||
class SpiCookie;
|
||||
|
||||
@ -36,13 +35,10 @@ public:
|
||||
SpiComIF(object_id_t objectId, GpioIF* gpioComIF);
|
||||
|
||||
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
|
||||
size_t sendLen) override;
|
||||
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||
|
||||
/**
|
||||
* @brief This function returns the mutex which can be used to protect the spi bus when
|
||||
@ -68,7 +64,6 @@ public:
|
||||
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
||||
|
||||
private:
|
||||
|
||||
struct SpiInstance {
|
||||
SpiInstance(size_t maxRecvSize) : replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
||||
std::vector<uint8_t> replyBuffer;
|
||||
@ -79,6 +74,7 @@ private:
|
||||
MutexIF* spiMutex = nullptr;
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
||||
uint32_t timeoutMs = 20;
|
||||
spi_ioc_transfer clockUpdateTransfer = {};
|
||||
|
||||
using SpiDeviceMap = std::unordered_map<address_t, SpiInstance>;
|
||||
using SpiDeviceMapIter = SpiDeviceMap::iterator;
|
||||
|
@ -1,35 +1,34 @@
|
||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||
#include "SpiCookie.h"
|
||||
|
||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed):
|
||||
SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
||||
spiSpeed, nullptr, nullptr) {
|
||||
|
||||
}
|
||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed)
|
||||
: SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
||||
spiSpeed, nullptr, nullptr) {}
|
||||
|
||||
SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize,
|
||||
spi::SpiModes spiMode, uint32_t spiSpeed):
|
||||
SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {
|
||||
}
|
||||
spi::SpiModes spiMode, uint32_t spiSpeed)
|
||||
: SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {}
|
||||
|
||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
||||
spi::send_callback_function_t callback, void *args):
|
||||
SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize,
|
||||
spiMode, spiSpeed, callback, args) {
|
||||
}
|
||||
spi::send_callback_function_t callback, void* args)
|
||||
: SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
||||
spiSpeed, callback, args) {}
|
||||
|
||||
SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
|
||||
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
||||
spi::send_callback_function_t callback, void* args):
|
||||
spiAddress(spiAddress), chipSelectPin(chipSelect), spiDevice(spiDev),
|
||||
comIfMode(comIfMode), maxSize(maxSize), spiMode(spiMode), spiSpeed(spiSpeed),
|
||||
sendCallback(callback), callbackArgs(args) {
|
||||
}
|
||||
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode,
|
||||
uint32_t spiSpeed, spi::send_callback_function_t callback, void* args)
|
||||
: spiAddress(spiAddress),
|
||||
chipSelectPin(chipSelect),
|
||||
spiDevice(spiDev),
|
||||
comIfMode(comIfMode),
|
||||
maxSize(maxSize),
|
||||
spiMode(spiMode),
|
||||
spiSpeed(spiSpeed),
|
||||
sendCallback(callback),
|
||||
callbackArgs(args) {}
|
||||
|
||||
spi::SpiComIfModes SpiCookie::getComIfMode() const {
|
||||
return this->comIfMode;
|
||||
}
|
||||
spi::SpiComIfModes SpiCookie::getComIfMode() const { return this->comIfMode; }
|
||||
|
||||
void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
||||
UncommonParameters* parameters) const {
|
||||
@ -45,41 +44,25 @@ void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
||||
}
|
||||
}
|
||||
|
||||
gpioId_t SpiCookie::getChipSelectPin() const {
|
||||
return chipSelectPin;
|
||||
}
|
||||
gpioId_t SpiCookie::getChipSelectPin() const { return chipSelectPin; }
|
||||
|
||||
size_t SpiCookie::getMaxBufferSize() const {
|
||||
return maxSize;
|
||||
}
|
||||
size_t SpiCookie::getMaxBufferSize() const { return maxSize; }
|
||||
|
||||
address_t SpiCookie::getSpiAddress() const {
|
||||
return spiAddress;
|
||||
}
|
||||
address_t SpiCookie::getSpiAddress() const { return spiAddress; }
|
||||
|
||||
std::string SpiCookie::getSpiDevice() const {
|
||||
return spiDevice;
|
||||
}
|
||||
std::string SpiCookie::getSpiDevice() const { return spiDevice; }
|
||||
|
||||
void SpiCookie::setThreeWireSpi(bool enable) {
|
||||
uncommonParameters.threeWireSpi = enable;
|
||||
}
|
||||
void SpiCookie::setThreeWireSpi(bool enable) { uncommonParameters.threeWireSpi = enable; }
|
||||
|
||||
void SpiCookie::setLsbFirst(bool enable) {
|
||||
uncommonParameters.lsbFirst = enable;
|
||||
}
|
||||
void SpiCookie::setLsbFirst(bool enable) { uncommonParameters.lsbFirst = enable; }
|
||||
|
||||
void SpiCookie::setNoCs(bool enable) {
|
||||
uncommonParameters.noCs = enable;
|
||||
}
|
||||
void SpiCookie::setNoCs(bool enable) { uncommonParameters.noCs = enable; }
|
||||
|
||||
void SpiCookie::setBitsPerWord(uint8_t bitsPerWord) {
|
||||
uncommonParameters.bitsPerWord = bitsPerWord;
|
||||
}
|
||||
|
||||
void SpiCookie::setCsHigh(bool enable) {
|
||||
uncommonParameters.csHigh = enable;
|
||||
}
|
||||
void SpiCookie::setCsHigh(bool enable) { uncommonParameters.csHigh = enable; }
|
||||
|
||||
void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) {
|
||||
spiTransferStruct.cs_change = deselectCs;
|
||||
@ -98,47 +81,29 @@ void SpiCookie::assignWriteBuffer(const uint8_t* tx) {
|
||||
}
|
||||
}
|
||||
|
||||
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback,
|
||||
void *args) {
|
||||
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback, void* args) {
|
||||
this->comIfMode = spi::SpiComIfModes::CALLBACK;
|
||||
this->sendCallback = callback;
|
||||
this->callbackArgs = args;
|
||||
}
|
||||
|
||||
void SpiCookie::setCallbackArgs(void *args) {
|
||||
this->callbackArgs = args;
|
||||
}
|
||||
void SpiCookie::setCallbackArgs(void* args) { this->callbackArgs = args; }
|
||||
|
||||
spi_ioc_transfer* SpiCookie::getTransferStructHandle() {
|
||||
return &spiTransferStruct;
|
||||
}
|
||||
spi_ioc_transfer* SpiCookie::getTransferStructHandle() { return &spiTransferStruct; }
|
||||
|
||||
void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) {
|
||||
this->halfDuplex = halfDuplex;
|
||||
}
|
||||
void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) { this->halfDuplex = halfDuplex; }
|
||||
|
||||
bool SpiCookie::isFullDuplex() const {
|
||||
return not this->halfDuplex;
|
||||
}
|
||||
bool SpiCookie::isFullDuplex() const { return not this->halfDuplex; }
|
||||
|
||||
void SpiCookie::setTransferSize(size_t transferSize) {
|
||||
spiTransferStruct.len = transferSize;
|
||||
}
|
||||
void SpiCookie::setTransferSize(size_t transferSize) { spiTransferStruct.len = transferSize; }
|
||||
|
||||
size_t SpiCookie::getCurrentTransferSize() const {
|
||||
return spiTransferStruct.len;
|
||||
}
|
||||
size_t SpiCookie::getCurrentTransferSize() const { return spiTransferStruct.len; }
|
||||
|
||||
void SpiCookie::setSpiSpeed(uint32_t newSpeed) {
|
||||
this->spiSpeed = newSpeed;
|
||||
}
|
||||
void SpiCookie::setSpiSpeed(uint32_t newSpeed) { this->spiSpeed = newSpeed; }
|
||||
|
||||
void SpiCookie::setSpiMode(spi::SpiModes newMode) {
|
||||
this->spiMode = newMode;
|
||||
}
|
||||
void SpiCookie::setSpiMode(spi::SpiModes newMode) { this->spiMode = newMode; }
|
||||
|
||||
void SpiCookie::getCallback(spi::send_callback_function_t *callback,
|
||||
void **args) {
|
||||
void SpiCookie::getCallback(spi::send_callback_function_t* callback, void** args) {
|
||||
*callback = this->sendCallback;
|
||||
*args = this->callbackArgs;
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
#ifndef LINUX_SPI_SPICOOKIE_H_
|
||||
#define LINUX_SPI_SPICOOKIE_H_
|
||||
|
||||
#include "spiDefinitions.h"
|
||||
#include "../../common/gpio/gpioDefinitions.h"
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
|
||||
#include "../../common/gpio/gpioDefinitions.h"
|
||||
#include "spiDefinitions.h"
|
||||
|
||||
/**
|
||||
* @brief This cookie class is passed to the SPI communication interface
|
||||
* @details
|
||||
@ -30,8 +29,8 @@ public:
|
||||
* @param spiDev
|
||||
* @param maxSize
|
||||
*/
|
||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed);
|
||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||
spi::SpiModes spiMode, uint32_t spiSpeed);
|
||||
|
||||
/**
|
||||
* Like constructor above, but without a dedicated GPIO CS. Can be used for hardware
|
||||
@ -141,8 +140,8 @@ public:
|
||||
void activateCsDeselect(bool deselectCs, uint16_t delayUsecs);
|
||||
|
||||
spi_ioc_transfer* getTransferStructHandle();
|
||||
private:
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal constructor which initializes every field
|
||||
* @param spiAddress
|
||||
@ -178,6 +177,4 @@ private:
|
||||
UncommonParameters uncommonParameters;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* LINUX_SPI_SPICOOKIE_H_ */
|
||||
|
@ -1,28 +1,25 @@
|
||||
#ifndef LINUX_SPI_SPIDEFINITONS_H_
|
||||
#define LINUX_SPI_SPIDEFINITONS_H_
|
||||
|
||||
#include "../../common/gpio/gpioDefinitions.h"
|
||||
#include "../../common/spi/spiCommon.h"
|
||||
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include <linux/spi/spidev.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "../../common/gpio/gpioDefinitions.h"
|
||||
#include "../../common/spi/spiCommon.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class SpiCookie;
|
||||
class SpiComIF;
|
||||
|
||||
namespace spi {
|
||||
|
||||
enum SpiComIfModes {
|
||||
REGULAR,
|
||||
CALLBACK
|
||||
};
|
||||
|
||||
enum SpiComIfModes { REGULAR, CALLBACK };
|
||||
|
||||
using send_callback_function_t = ReturnValue_t (*)(SpiComIF* comIf, SpiCookie* cookie,
|
||||
const uint8_t *sendData, size_t sendLen, void* args);
|
||||
const uint8_t* sendData, size_t sendLen,
|
||||
void* args);
|
||||
|
||||
}
|
||||
} // namespace spi
|
||||
|
||||
#endif /* LINUX_SPI_SPIDEFINITONS_H_ */
|
||||
|
@ -1,22 +1,21 @@
|
||||
#include "UartComIF.h"
|
||||
#include "OBSWConfig.h"
|
||||
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
UartComIF::UartComIF(object_id_t objectId): SystemObject(objectId){
|
||||
}
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
|
||||
UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {}
|
||||
|
||||
UartComIF::~UartComIF() {}
|
||||
|
||||
ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
||||
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
|
||||
@ -26,7 +25,9 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
||||
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
@ -42,14 +43,17 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
||||
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
|
||||
auto status = uartDeviceMap.emplace(deviceFile, uartElements);
|
||||
if (status.second == false) {
|
||||
sif::warning << "UartComIF::initializeInterface: Failed to insert device " <<
|
||||
deviceFile << "to UART device map" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
|
||||
<< "to UART device map" << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile <<
|
||||
" already in use" << std::endl;
|
||||
} else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile
|
||||
<< " already in use" << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -57,7 +61,6 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
||||
}
|
||||
|
||||
int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||
|
||||
struct termios options = {};
|
||||
|
||||
std::string deviceFile = uartCookie->getDeviceFile();
|
||||
@ -70,15 +73,19 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||
int fd = open(deviceFile.c_str(), flags);
|
||||
|
||||
if (fd < 0) {
|
||||
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile <<
|
||||
"with error code " << errno << strerror(errno) << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile
|
||||
<< "with error code " << errno << strerror(errno) << std::endl;
|
||||
#endif
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Read in existing settings */
|
||||
if (tcgetattr(fd, &options) != 0) {
|
||||
sif::warning << "UartComIF::configureUartPort: Error " << errno << "from tcgetattr: "
|
||||
<< strerror(errno) << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::configureUartPort: Error " << errno
|
||||
<< "from tcgetattr: " << strerror(errno) << std::endl;
|
||||
#endif
|
||||
return fd;
|
||||
}
|
||||
|
||||
@ -99,8 +106,10 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||
|
||||
/* Save option settings */
|
||||
if (tcsetattr(fd, TCSANOW, &options) != 0) {
|
||||
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " <<
|
||||
errno << ": " << strerror(errno);
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << errno
|
||||
<< ": " << strerror(errno);
|
||||
#endif
|
||||
return fd;
|
||||
}
|
||||
return fd;
|
||||
@ -139,20 +148,22 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook
|
||||
/* Clear size bits */
|
||||
options->c_cflag &= ~CSIZE;
|
||||
switch (uartCookie->getBitsPerWord()) {
|
||||
case 5:
|
||||
case BitsPerWord::BITS_5:
|
||||
options->c_cflag |= CS5;
|
||||
break;
|
||||
case 6:
|
||||
case BitsPerWord::BITS_6:
|
||||
options->c_cflag |= CS6;
|
||||
break;
|
||||
case 7:
|
||||
case BitsPerWord::BITS_7:
|
||||
options->c_cflag |= CS7;
|
||||
break;
|
||||
case 8:
|
||||
case BitsPerWord::BITS_8:
|
||||
options->c_cflag |= CS8;
|
||||
break;
|
||||
default:
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -182,90 +193,137 @@ void UartComIF::setFixedOptions(struct termios* options) {
|
||||
|
||||
void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCookie) {
|
||||
switch (uartCookie->getBaudrate()) {
|
||||
case 50:
|
||||
case UartBaudRate::RATE_50:
|
||||
cfsetispeed(options, B50);
|
||||
cfsetospeed(options, B50);
|
||||
break;
|
||||
case 75:
|
||||
case UartBaudRate::RATE_75:
|
||||
cfsetispeed(options, B75);
|
||||
cfsetospeed(options, B75);
|
||||
break;
|
||||
case 110:
|
||||
case UartBaudRate::RATE_110:
|
||||
cfsetispeed(options, B110);
|
||||
cfsetospeed(options, B110);
|
||||
break;
|
||||
case 134:
|
||||
case UartBaudRate::RATE_134:
|
||||
cfsetispeed(options, B134);
|
||||
cfsetospeed(options, B134);
|
||||
break;
|
||||
case 150:
|
||||
case UartBaudRate::RATE_150:
|
||||
cfsetispeed(options, B150);
|
||||
cfsetospeed(options, B150);
|
||||
break;
|
||||
case 200:
|
||||
case UartBaudRate::RATE_200:
|
||||
cfsetispeed(options, B200);
|
||||
cfsetospeed(options, B200);
|
||||
break;
|
||||
case 300:
|
||||
case UartBaudRate::RATE_300:
|
||||
cfsetispeed(options, B300);
|
||||
cfsetospeed(options, B300);
|
||||
break;
|
||||
case 600:
|
||||
case UartBaudRate::RATE_600:
|
||||
cfsetispeed(options, B600);
|
||||
cfsetospeed(options, B600);
|
||||
break;
|
||||
case 1200:
|
||||
case UartBaudRate::RATE_1200:
|
||||
cfsetispeed(options, B1200);
|
||||
cfsetospeed(options, B1200);
|
||||
break;
|
||||
case 1800:
|
||||
case UartBaudRate::RATE_1800:
|
||||
cfsetispeed(options, B1800);
|
||||
cfsetospeed(options, B1800);
|
||||
break;
|
||||
case 2400:
|
||||
case UartBaudRate::RATE_2400:
|
||||
cfsetispeed(options, B2400);
|
||||
cfsetospeed(options, B2400);
|
||||
break;
|
||||
case 4800:
|
||||
case UartBaudRate::RATE_4800:
|
||||
cfsetispeed(options, B4800);
|
||||
cfsetospeed(options, B4800);
|
||||
break;
|
||||
case 9600:
|
||||
case UartBaudRate::RATE_9600:
|
||||
cfsetispeed(options, B9600);
|
||||
cfsetospeed(options, B9600);
|
||||
break;
|
||||
case 19200:
|
||||
case UartBaudRate::RATE_19200:
|
||||
cfsetispeed(options, B19200);
|
||||
cfsetospeed(options, B19200);
|
||||
break;
|
||||
case 38400:
|
||||
case UartBaudRate::RATE_38400:
|
||||
cfsetispeed(options, B38400);
|
||||
cfsetospeed(options, B38400);
|
||||
break;
|
||||
case 57600:
|
||||
case UartBaudRate::RATE_57600:
|
||||
cfsetispeed(options, B57600);
|
||||
cfsetospeed(options, B57600);
|
||||
break;
|
||||
case 115200:
|
||||
case UartBaudRate::RATE_115200:
|
||||
cfsetispeed(options, B115200);
|
||||
cfsetospeed(options, B115200);
|
||||
break;
|
||||
case 230400:
|
||||
case UartBaudRate::RATE_230400:
|
||||
cfsetispeed(options, B230400);
|
||||
cfsetospeed(options, B230400);
|
||||
break;
|
||||
case 460800:
|
||||
#ifndef __APPLE__
|
||||
case UartBaudRate::RATE_460800:
|
||||
cfsetispeed(options, B460800);
|
||||
cfsetospeed(options, B460800);
|
||||
break;
|
||||
case UartBaudRate::RATE_500000:
|
||||
cfsetispeed(options, B500000);
|
||||
cfsetospeed(options, B500000);
|
||||
break;
|
||||
case UartBaudRate::RATE_576000:
|
||||
cfsetispeed(options, B576000);
|
||||
cfsetospeed(options, B576000);
|
||||
break;
|
||||
case UartBaudRate::RATE_921600:
|
||||
cfsetispeed(options, B921600);
|
||||
cfsetospeed(options, B921600);
|
||||
break;
|
||||
case UartBaudRate::RATE_1000000:
|
||||
cfsetispeed(options, B1000000);
|
||||
cfsetospeed(options, B1000000);
|
||||
break;
|
||||
case UartBaudRate::RATE_1152000:
|
||||
cfsetispeed(options, B1152000);
|
||||
cfsetospeed(options, B1152000);
|
||||
break;
|
||||
case UartBaudRate::RATE_1500000:
|
||||
cfsetispeed(options, B1500000);
|
||||
cfsetospeed(options, B1500000);
|
||||
break;
|
||||
case UartBaudRate::RATE_2000000:
|
||||
cfsetispeed(options, B2000000);
|
||||
cfsetospeed(options, B2000000);
|
||||
break;
|
||||
case UartBaudRate::RATE_2500000:
|
||||
cfsetispeed(options, B2500000);
|
||||
cfsetospeed(options, B2500000);
|
||||
break;
|
||||
case UartBaudRate::RATE_3000000:
|
||||
cfsetispeed(options, B3000000);
|
||||
cfsetospeed(options, B3000000);
|
||||
break;
|
||||
case UartBaudRate::RATE_3500000:
|
||||
cfsetispeed(options, B3500000);
|
||||
cfsetospeed(options, B3500000);
|
||||
break;
|
||||
case UartBaudRate::RATE_4000000:
|
||||
cfsetispeed(options, B4000000);
|
||||
cfsetospeed(options, B4000000);
|
||||
break;
|
||||
#endif // ! __APPLE__
|
||||
default:
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
|
||||
const uint8_t *sendData, size_t sendLen) {
|
||||
ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||
int fd = 0;
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
@ -275,38 +333,44 @@ ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
|
||||
}
|
||||
|
||||
if (sendData == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile <<
|
||||
"not in UART map" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
|
||||
if (write(fd, sendData, sendLen) != (int)sendLen) {
|
||||
sif::error << "UartComIF::sendMessage: Failed to send data with error code " <<
|
||||
errno << ": Error description: " << strerror(errno) << std::endl;
|
||||
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
|
||||
<< ": Error description: " << strerror(errno) << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::getSendSuccess(CookieIF *cookie) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return RETURN_OK; }
|
||||
|
||||
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||
std::string deviceFile;
|
||||
@ -314,7 +378,9 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestL
|
||||
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
@ -327,18 +393,18 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestL
|
||||
}
|
||||
|
||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile
|
||||
<< " not in uart map" << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
if (uartMode == UartModes::CANONICAL) {
|
||||
return handleCanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
|
||||
}
|
||||
else if (uartMode == UartModes::NON_CANONICAL) {
|
||||
} else if (uartMode == UartModes::NON_CANONICAL) {
|
||||
return handleNoncanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
@ -364,14 +430,14 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
||||
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("UartComIF::requestReceiveMessage: "
|
||||
sif::printWarning(
|
||||
"UartComIF::requestReceiveMessage: "
|
||||
"Next read would cause overflow!");
|
||||
#endif
|
||||
#endif
|
||||
result = UART_RX_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
allowedReadSize = maxReplySize - currentBytesRead;
|
||||
}
|
||||
|
||||
@ -381,18 +447,17 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
||||
if (errno != EAGAIN) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" <<
|
||||
errno << ": " << strerror(errno) << std::endl;
|
||||
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" << errno << ": "
|
||||
<< strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n",
|
||||
errno, strerror(errno));
|
||||
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n", errno,
|
||||
strerror(errno));
|
||||
#endif
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
else if(bytesRead > 0) {
|
||||
} else if (bytesRead > 0) {
|
||||
iter->second.replyLen += bytesRead;
|
||||
bufferPtr += bytesRead;
|
||||
currentBytesRead += bytesRead;
|
||||
@ -408,12 +473,13 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
|
||||
auto bufferPtr = iter->second.replyBuffer.data();
|
||||
// Size check to prevent buffer overflow
|
||||
if (requestLen > uartCookie.getMaxReplyLen()) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("UartComIF::requestReceiveMessage: "
|
||||
sif::printWarning(
|
||||
"UartComIF::requestReceiveMessage: "
|
||||
"Next read would cause overflow!");
|
||||
#endif
|
||||
#endif
|
||||
@ -422,11 +488,12 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
|
||||
int bytesRead = read(fd, bufferPtr, requestLen);
|
||||
if (bytesRead < 0) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
else if (bytesRead != static_cast<int>(requestLen)) {
|
||||
} else if (bytesRead != static_cast<int>(requestLen)) {
|
||||
if (uartCookie.isReplySizeFixed()) {
|
||||
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead <<
|
||||
" of " << requestLen << " bytes" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of "
|
||||
<< requestLen << " bytes" << std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
@ -434,23 +501,25 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **buffer, size_t* size) {
|
||||
|
||||
ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile <<
|
||||
" not in uart map" << std::endl;
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -468,7 +537,9 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
@ -486,7 +557,9 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
@ -504,7 +577,9 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
@ -522,8 +597,7 @@ void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {
|
||||
if (uartMode == UartModes::NON_CANONICAL) {
|
||||
/* Disable canonical mode */
|
||||
options->c_lflag &= ~ICANON;
|
||||
}
|
||||
else if(uartMode == UartModes::CANONICAL) {
|
||||
} else if (uartMode == UartModes::CANONICAL) {
|
||||
options->c_lflag |= ICANON;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_
|
||||
#define BSP_Q7S_COMIF_UARTCOMIF_H_
|
||||
|
||||
#include "UartCookie.h"
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "UartCookie.h"
|
||||
|
||||
/**
|
||||
* @brief This is the communication interface to access serial ports on linux based operating
|
||||
* systems.
|
||||
@ -33,13 +34,10 @@ public:
|
||||
virtual ~UartComIF();
|
||||
|
||||
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
|
||||
size_t sendLen) override;
|
||||
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||
|
||||
/**
|
||||
* @brief This function discards all data received but not read in the UART buffer.
|
||||
@ -57,7 +55,6 @@ public:
|
||||
ReturnValue_t flushUartTxAndRxBuf(CookieIF* cookie);
|
||||
|
||||
private:
|
||||
|
||||
using UartDeviceFile_t = std::string;
|
||||
|
||||
struct UartElements {
|
||||
@ -119,7 +116,6 @@ private:
|
||||
size_t requestLen);
|
||||
ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
|
||||
size_t requestLen);
|
||||
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_COMIF_UARTCOMIF_H_ */
|
||||
|
@ -1,97 +1,51 @@
|
||||
#include "fsfw_hal/linux/uart/UartCookie.h"
|
||||
#include "UartCookie.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/serviceinterface.h>
|
||||
|
||||
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
||||
uint32_t baudrate, size_t maxReplyLen):
|
||||
handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode),
|
||||
baudrate(baudrate), maxReplyLen(maxReplyLen) {
|
||||
}
|
||||
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
|
||||
size_t maxReplyLen, UartModes uartMode)
|
||||
: handlerId(handlerId),
|
||||
deviceFile(deviceFile),
|
||||
uartMode(uartMode),
|
||||
baudrate(baudrate),
|
||||
maxReplyLen(maxReplyLen) {}
|
||||
|
||||
UartCookie::~UartCookie() {}
|
||||
|
||||
uint32_t UartCookie::getBaudrate() const {
|
||||
return baudrate;
|
||||
}
|
||||
UartBaudRate UartCookie::getBaudrate() const { return baudrate; }
|
||||
|
||||
size_t UartCookie::getMaxReplyLen() const {
|
||||
return maxReplyLen;
|
||||
}
|
||||
size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; }
|
||||
|
||||
std::string UartCookie::getDeviceFile() const {
|
||||
return deviceFile;
|
||||
}
|
||||
std::string UartCookie::getDeviceFile() const { return deviceFile; }
|
||||
|
||||
void UartCookie::setParityOdd() {
|
||||
parity = Parity::ODD;
|
||||
}
|
||||
void UartCookie::setParityOdd() { parity = Parity::ODD; }
|
||||
|
||||
void UartCookie::setParityEven() {
|
||||
parity = Parity::EVEN;
|
||||
}
|
||||
void UartCookie::setParityEven() { parity = Parity::EVEN; }
|
||||
|
||||
Parity UartCookie::getParity() const {
|
||||
return parity;
|
||||
}
|
||||
Parity UartCookie::getParity() const { return parity; }
|
||||
|
||||
void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) {
|
||||
switch(bitsPerWord_) {
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
break;
|
||||
default:
|
||||
sif::debug << "UartCookie::setBitsPerWord: Invalid bits per word specified" << std::endl;
|
||||
return;
|
||||
}
|
||||
bitsPerWord = bitsPerWord_;
|
||||
}
|
||||
void UartCookie::setBitsPerWord(BitsPerWord bitsPerWord_) { bitsPerWord = bitsPerWord_; }
|
||||
|
||||
uint8_t UartCookie::getBitsPerWord() const {
|
||||
return bitsPerWord;
|
||||
}
|
||||
BitsPerWord UartCookie::getBitsPerWord() const { return bitsPerWord; }
|
||||
|
||||
StopBits UartCookie::getStopBits() const {
|
||||
return stopBits;
|
||||
}
|
||||
StopBits UartCookie::getStopBits() const { return stopBits; }
|
||||
|
||||
void UartCookie::setTwoStopBits() {
|
||||
stopBits = StopBits::TWO_STOP_BITS;
|
||||
}
|
||||
void UartCookie::setTwoStopBits() { stopBits = StopBits::TWO_STOP_BITS; }
|
||||
|
||||
void UartCookie::setOneStopBit() {
|
||||
stopBits = StopBits::ONE_STOP_BIT;
|
||||
}
|
||||
void UartCookie::setOneStopBit() { stopBits = StopBits::ONE_STOP_BIT; }
|
||||
|
||||
UartModes UartCookie::getUartMode() const {
|
||||
return uartMode;
|
||||
}
|
||||
UartModes UartCookie::getUartMode() const { return uartMode; }
|
||||
|
||||
void UartCookie::setReadCycles(uint8_t readCycles) {
|
||||
this->readCycles = readCycles;
|
||||
}
|
||||
void UartCookie::setReadCycles(uint8_t readCycles) { this->readCycles = readCycles; }
|
||||
|
||||
void UartCookie::setToFlushInput(bool enable) {
|
||||
this->flushInput = enable;
|
||||
}
|
||||
void UartCookie::setToFlushInput(bool enable) { this->flushInput = enable; }
|
||||
|
||||
uint8_t UartCookie::getReadCycles() const {
|
||||
return readCycles;
|
||||
}
|
||||
uint8_t UartCookie::getReadCycles() const { return readCycles; }
|
||||
|
||||
bool UartCookie::getInputShouldBeFlushed() {
|
||||
return this->flushInput;
|
||||
}
|
||||
bool UartCookie::getInputShouldBeFlushed() { return this->flushInput; }
|
||||
|
||||
object_id_t UartCookie::getHandlerId() const {
|
||||
return this->handlerId;
|
||||
}
|
||||
object_id_t UartCookie::getHandlerId() const { return this->handlerId; }
|
||||
|
||||
void UartCookie::setNoFixedSizeReply() {
|
||||
replySizeFixed = false;
|
||||
}
|
||||
void UartCookie::setNoFixedSizeReply() { replySizeFixed = false; }
|
||||
|
||||
bool UartCookie::isReplySizeFixed() {
|
||||
return replySizeFixed;
|
||||
}
|
||||
bool UartCookie::isReplySizeFixed() { return replySizeFixed; }
|
||||
|
@ -6,20 +6,45 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class Parity {
|
||||
NONE,
|
||||
EVEN,
|
||||
ODD
|
||||
};
|
||||
enum class Parity { NONE, EVEN, ODD };
|
||||
|
||||
enum class StopBits {
|
||||
ONE_STOP_BIT,
|
||||
TWO_STOP_BITS
|
||||
};
|
||||
enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS };
|
||||
|
||||
enum class UartModes {
|
||||
CANONICAL,
|
||||
NON_CANONICAL
|
||||
enum class UartModes { CANONICAL, NON_CANONICAL };
|
||||
|
||||
enum class BitsPerWord { BITS_5, BITS_6, BITS_7, BITS_8 };
|
||||
|
||||
enum class UartBaudRate {
|
||||
RATE_50,
|
||||
RATE_75,
|
||||
RATE_110,
|
||||
RATE_134,
|
||||
RATE_150,
|
||||
RATE_200,
|
||||
RATE_300,
|
||||
RATE_600,
|
||||
RATE_1200,
|
||||
RATE_1800,
|
||||
RATE_2400,
|
||||
RATE_4800,
|
||||
RATE_9600,
|
||||
RATE_19200,
|
||||
RATE_38400,
|
||||
RATE_57600,
|
||||
RATE_115200,
|
||||
RATE_230400,
|
||||
RATE_460800,
|
||||
RATE_500000,
|
||||
RATE_576000,
|
||||
RATE_921600,
|
||||
RATE_1000000,
|
||||
RATE_1152000,
|
||||
RATE_1500000,
|
||||
RATE_2000000,
|
||||
RATE_2500000,
|
||||
RATE_3000000,
|
||||
RATE_3500000,
|
||||
RATE_4000000
|
||||
};
|
||||
|
||||
/**
|
||||
@ -31,32 +56,29 @@ enum class UartModes {
|
||||
*/
|
||||
class UartCookie : public CookieIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructor for the uart cookie.
|
||||
* @param deviceFile The device file specifying the uart to use, e.g. "/dev/ttyPS1"
|
||||
* @param uartMode Specify the UART mode. The canonical mode should be used if the
|
||||
* messages are separated by a delimited character like '\n'. See the
|
||||
* termios documentation for more information
|
||||
* @param baudrate The baudrate to use for input and output. Possible Baudrates are: 50,
|
||||
* 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, B19200,
|
||||
* 38400, 57600, 115200, 230400, 460800
|
||||
* @param baudrate The baudrate to use for input and output.
|
||||
* @param maxReplyLen The maximum size an object using this cookie expects
|
||||
* @details
|
||||
* Default configuration: No parity
|
||||
* 8 databits (number of bits transfered with one uart frame)
|
||||
* One stop bit
|
||||
*/
|
||||
UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
||||
uint32_t baudrate, size_t maxReplyLen);
|
||||
UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
|
||||
size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL);
|
||||
|
||||
virtual ~UartCookie();
|
||||
|
||||
uint32_t getBaudrate() const;
|
||||
UartBaudRate getBaudrate() const;
|
||||
size_t getMaxReplyLen() const;
|
||||
std::string getDeviceFile() const;
|
||||
Parity getParity() const;
|
||||
uint8_t getBitsPerWord() const;
|
||||
BitsPerWord getBitsPerWord() const;
|
||||
StopBits getStopBits() const;
|
||||
UartModes getUartMode() const;
|
||||
object_id_t getHandlerId() const;
|
||||
@ -87,7 +109,7 @@ public:
|
||||
/**
|
||||
* Function two set number of bits per UART frame.
|
||||
*/
|
||||
void setBitsPerWord(uint8_t bitsPerWord_);
|
||||
void setBitsPerWord(BitsPerWord bitsPerWord_);
|
||||
|
||||
/**
|
||||
* Function to specify the number of stopbits.
|
||||
@ -104,15 +126,14 @@ public:
|
||||
bool isReplySizeFixed();
|
||||
|
||||
private:
|
||||
|
||||
const object_id_t handlerId;
|
||||
std::string deviceFile;
|
||||
const UartModes uartMode;
|
||||
bool flushInput = false;
|
||||
uint32_t baudrate;
|
||||
UartBaudRate baudrate;
|
||||
size_t maxReplyLen = 0;
|
||||
Parity parity = Parity::NONE;
|
||||
uint8_t bitsPerWord = 8;
|
||||
BitsPerWord bitsPerWord = BitsPerWord::BITS_8;
|
||||
uint8_t readCycles = 1;
|
||||
StopBits stopBits = StopBits::ONE_STOP_BIT;
|
||||
bool replySizeFixed = true;
|
||||
|
3
hal/src/fsfw_hal/linux/uio/CMakeLists.txt
Normal file
3
hal/src/fsfw_hal/linux/uio/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
target_sources(${LIB_FSFW_NAME} PUBLIC
|
||||
UioMapper.cpp
|
||||
)
|
86
hal/src/fsfw_hal/linux/uio/UioMapper.cpp
Normal file
86
hal/src/fsfw_hal/linux/uio/UioMapper.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include "UioMapper.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "fsfw/serviceinterface.h"
|
||||
|
||||
const char UioMapper::UIO_PATH_PREFIX[] = "/sys/class/uio/";
|
||||
const char UioMapper::MAP_SUBSTR[] = "/maps/map";
|
||||
const char UioMapper::SIZE_FILE_PATH[] = "/size";
|
||||
|
||||
UioMapper::UioMapper(std::string uioFile, int mapNum) : uioFile(uioFile), mapNum(mapNum) {}
|
||||
|
||||
UioMapper::~UioMapper() {}
|
||||
|
||||
ReturnValue_t UioMapper::getMappedAdress(uint32_t** address, Permissions permissions) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
int fd = open(uioFile.c_str(), O_RDWR);
|
||||
if (fd < 1) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "PtmeAxiConfig::initialize: Invalid UIO device file" << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
size_t size = 0;
|
||||
result = getMapSize(&size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
*address = static_cast<uint32_t*>(
|
||||
mmap(NULL, size, static_cast<int>(permissions), MAP_SHARED, fd, mapNum * getpagesize()));
|
||||
|
||||
if (*address == MAP_FAILED) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "UioMapper::getMappedAdress: Failed to map physical address of uio device "
|
||||
<< uioFile.c_str() << " and map" << static_cast<int>(mapNum) << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UioMapper::getMapSize(size_t* size) {
|
||||
std::stringstream namestream;
|
||||
namestream << UIO_PATH_PREFIX << uioFile.substr(5, std::string::npos) << MAP_SUBSTR << mapNum
|
||||
<< SIZE_FILE_PATH;
|
||||
FILE* fp;
|
||||
fp = fopen(namestream.str().c_str(), "r");
|
||||
if (fp == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "UioMapper::getMapSize: Failed to open file " << namestream.str() << std::endl;
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
char hexstring[SIZE_HEX_STRING] = "";
|
||||
int items = fscanf(fp, "%s", hexstring);
|
||||
if (items != 1) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "UioMapper::getMapSize: Failed with error code " << errno
|
||||
<< " to read size "
|
||||
"string from file "
|
||||
<< namestream.str() << std::endl;
|
||||
#endif
|
||||
fclose(fp);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
uint32_t sizeTmp = 0;
|
||||
items = sscanf(hexstring, "%x", &sizeTmp);
|
||||
if (size != nullptr) {
|
||||
*size = sizeTmp;
|
||||
}
|
||||
if (items != 1) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "UioMapper::getMapSize: Failed with error code " << errno << "to convert "
|
||||
<< "size of map" << mapNum << " to integer" << std::endl;
|
||||
#endif
|
||||
fclose(fp);
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
fclose(fp);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
58
hal/src/fsfw_hal/linux/uio/UioMapper.h
Normal file
58
hal/src/fsfw_hal/linux/uio/UioMapper.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef FSFW_HAL_SRC_FSFW_HAL_LINUX_UIO_UIOMAPPER_H_
|
||||
#define FSFW_HAL_SRC_FSFW_HAL_LINUX_UIO_UIOMAPPER_H_
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* @brief Class to help opening uio device files and mapping the physical addresses into the user
|
||||
* address space.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class UioMapper {
|
||||
public:
|
||||
enum class Permissions : int {
|
||||
READ_ONLY = PROT_READ,
|
||||
WRITE_ONLY = PROT_WRITE,
|
||||
READ_WRITE = PROT_READ | PROT_WRITE
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param uioFile The device file of the uiO to open
|
||||
* @param uioMap Number of memory map. Most UIO drivers have only one map which has than 0.
|
||||
*/
|
||||
UioMapper(std::string uioFile, int mapNum = 0);
|
||||
virtual ~UioMapper();
|
||||
|
||||
/**
|
||||
* @brief Maps the physical address into user address space and returns the mapped address
|
||||
*
|
||||
* @address The mapped user space address
|
||||
* @permissions Specifies the read/write permissions of the address region
|
||||
*/
|
||||
ReturnValue_t getMappedAdress(uint32_t** address, Permissions permissions);
|
||||
|
||||
private:
|
||||
static const char UIO_PATH_PREFIX[];
|
||||
static const char MAP_SUBSTR[];
|
||||
static const char SIZE_FILE_PATH[];
|
||||
static constexpr int SIZE_HEX_STRING = 10;
|
||||
|
||||
std::string uioFile;
|
||||
int mapNum = 0;
|
||||
|
||||
/**
|
||||
* @brief Reads the map size from the associated sysfs size file
|
||||
*
|
||||
* @param size The read map size
|
||||
*/
|
||||
ReturnValue_t getMapSize(size_t* size);
|
||||
};
|
||||
|
||||
#endif /* FSFW_HAL_SRC_FSFW_HAL_LINUX_UIO_UIOMAPPER_H_ */
|
@ -1,18 +1,18 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
void utility::handleIoctlError(const char* const customPrintout) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
if (customPrintout != nullptr) {
|
||||
sif::warning << customPrintout << std::endl;
|
||||
}
|
||||
sif::warning << "handleIoctlError: Error code " << errno << ", "<< strerror(errno) <<
|
||||
std::endl;
|
||||
sif::warning << "handleIoctlError: Error code " << errno << ", " << strerror(errno) << std::endl;
|
||||
#else
|
||||
if (customPrintout != nullptr) {
|
||||
sif::printWarning("%s\n", customPrintout);
|
||||
@ -20,7 +20,4 @@ void utility::handleIoctlError(const char* const customPrintout) {
|
||||
sif::printWarning("handleIoctlError: Error code %d, %s\n", errno, strerror(errno));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define FSFW_HAL_STM32H7_DEFINITIONS_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "stm32h7xx.h"
|
||||
|
||||
namespace stm32h7 {
|
||||
@ -13,13 +14,13 @@ namespace stm32h7 {
|
||||
struct GpioCfg {
|
||||
GpioCfg() : port(nullptr), pin(0), altFnc(0){};
|
||||
|
||||
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0):
|
||||
port(port), pin(pin), altFnc(altFnc) {};
|
||||
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0)
|
||||
: port(port), pin(pin), altFnc(altFnc){};
|
||||
GPIO_TypeDef* port;
|
||||
uint16_t pin;
|
||||
uint8_t altFnc;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace stm32h7
|
||||
|
||||
#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */
|
||||
|
@ -1,29 +1,26 @@
|
||||
#include "fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h"
|
||||
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||
|
||||
#include "fsfw/tasks/TaskFactory.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
#include "stm32h7xx_hal_rcc.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw/tasks/TaskFactory.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||
#include "stm32h7xx_hal_rcc.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
alignas(32) std::array<uint8_t, GyroL3GD20H::recvBufferSize> GyroL3GD20H::rxBuffer;
|
||||
alignas(32) std::array<uint8_t, GyroL3GD20H::txBufferSize>
|
||||
GyroL3GD20H::txBuffer __attribute__((section(".dma_buffer")));
|
||||
alignas(32) std::array<uint8_t, GyroL3GD20H::txBufferSize> GyroL3GD20H::txBuffer
|
||||
__attribute__((section(".dma_buffer")));
|
||||
|
||||
TransferStates transferState = TransferStates::IDLE;
|
||||
spi::TransferModes GyroL3GD20H::transferMode = spi::TransferModes::POLLING;
|
||||
|
||||
|
||||
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_):
|
||||
spiHandle(spiHandle) {
|
||||
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_)
|
||||
: spiHandle(spiHandle) {
|
||||
txDmaHandle = new DMA_HandleTypeDef();
|
||||
rxDmaHandle = new DMA_HandleTypeDef();
|
||||
spi::setSpiHandle(spiHandle);
|
||||
@ -34,16 +31,15 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf
|
||||
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
|
||||
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
|
||||
stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
||||
IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS);
|
||||
IrqPriorities::HIGHEST_FREERTOS,
|
||||
IrqPriorities::HIGHEST_FREERTOS);
|
||||
spi::setSpiDmaMspFunctions(typedCfg);
|
||||
}
|
||||
else if(transferMode == spi::TransferModes::INTERRUPT) {
|
||||
} else if (transferMode == spi::TransferModes::INTERRUPT) {
|
||||
mspCfg = new spi::MspIrqConfigStruct();
|
||||
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
|
||||
stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
||||
spi::setSpiIrqMspFunctions(typedCfg);
|
||||
}
|
||||
else if(transferMode == spi::TransferModes::POLLING) {
|
||||
} else if (transferMode == spi::TransferModes::POLLING) {
|
||||
mspCfg = new spi::MspPollingConfigStruct();
|
||||
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct *>(mspCfg);
|
||||
stm32h7::h743zi::standardPollingCfg(*typedCfg);
|
||||
@ -155,8 +151,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
||||
case (TransferStates::SUCCESS): {
|
||||
uint8_t whoAmIVal = rxBuffer[1];
|
||||
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
||||
sif::printDebug("GyroL3GD20H::initialize: "
|
||||
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
|
||||
sif::printDebug(
|
||||
"GyroL3GD20H::initialize: "
|
||||
"Read WHO AM I value %d not equal to expected value!\n",
|
||||
whoAmIVal);
|
||||
}
|
||||
transferState = TransferStates::IDLE;
|
||||
break;
|
||||
@ -203,7 +201,6 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||
std::memset(txBuffer.data() + 1, 0, 5);
|
||||
result = performDmaTransfer(6);
|
||||
@ -222,8 +219,7 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
||||
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
||||
rxBuffer[5] != configRegs[4]) {
|
||||
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
||||
}
|
||||
transferState = TransferStates::IDLE;
|
||||
@ -293,8 +289,10 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
||||
sif::printInfo("GyroL3GD20H::initialize: Polling transfer success\n");
|
||||
uint8_t whoAmIVal = rxBuffer[1];
|
||||
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
||||
sif::printDebug("GyroL3GD20H::performOperation: "
|
||||
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
|
||||
sif::printDebug(
|
||||
"GyroL3GD20H::performOperation: "
|
||||
"Read WHO AM I value %d not equal to expected value!\n",
|
||||
whoAmIVal);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -348,8 +346,7 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
||||
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
||||
rxBuffer[5] != configRegs[4]) {
|
||||
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
||||
}
|
||||
break;
|
||||
@ -408,8 +405,10 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
||||
|
||||
uint8_t whoAmIVal = rxBuffer[1];
|
||||
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
||||
sif::printDebug("GyroL3GD20H::initialize: "
|
||||
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
|
||||
sif::printDebug(
|
||||
"GyroL3GD20H::initialize: "
|
||||
"Read WHO AM I value %d not equal to expected value!\n",
|
||||
whoAmIVal);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -457,8 +456,7 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
||||
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
||||
rxBuffer[5] != configRegs[4]) {
|
||||
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
||||
}
|
||||
break;
|
||||
@ -516,7 +514,8 @@ uint8_t GyroL3GD20H::readRegPolling(uint8_t reg) {
|
||||
txBuf[0] = reg | STM_READ_MASK;
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuf, rxBuf, 2, 1000);
|
||||
if(result) {};
|
||||
if (result) {
|
||||
};
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
return rxBuf[1];
|
||||
}
|
||||
@ -535,7 +534,6 @@ void GyroL3GD20H::handleSensorReadout() {
|
||||
sif::printInfo("Gyro Z: %f\n", gyroZ);
|
||||
}
|
||||
|
||||
|
||||
void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void *args) {
|
||||
transferState = TransferStates::SUCCESS;
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
|
@ -1,22 +1,16 @@
|
||||
#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
||||
#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../spi/mspInit.h"
|
||||
#include "../spi/spiDefinitions.h"
|
||||
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
enum class TransferStates {
|
||||
IDLE,
|
||||
WAIT,
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
};
|
||||
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
|
||||
|
||||
class GyroL3GD20H {
|
||||
public:
|
||||
@ -27,7 +21,6 @@ public:
|
||||
ReturnValue_t performOperation();
|
||||
|
||||
private:
|
||||
|
||||
const uint8_t WHO_AM_I_REG = 0b00001111;
|
||||
const uint8_t STM_READ_MASK = 0b10000000;
|
||||
const uint8_t STM_AUTO_INCREMENT_MASK = 0b01000000;
|
||||
@ -57,11 +50,9 @@ private:
|
||||
static void spiTransferCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||
static void spiTransferErrorCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||
|
||||
|
||||
void prepareConfigRegs(uint8_t* configRegs);
|
||||
void handleSensorReadout();
|
||||
|
||||
|
||||
DMA_HandleTypeDef* txDmaHandle = {};
|
||||
DMA_HandleTypeDef* rxDmaHandle = {};
|
||||
spi::MspCfgBase* mspCfg = {};
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <fsfw_hal/stm32h7/dma.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
user_handler_t DMA_1_USER_HANDLERS[8];
|
||||
user_args_t DMA_1_USER_ARGS[8];
|
||||
@ -14,8 +14,7 @@ void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
|
||||
if (dma_idx == DMA_1) {
|
||||
DMA_1_USER_HANDLERS[stream_idx] = user_handler;
|
||||
DMA_1_USER_ARGS[stream_idx] = user_args;
|
||||
}
|
||||
else if(dma_idx == DMA_2) {
|
||||
} else if (dma_idx == DMA_2) {
|
||||
DMA_2_USER_HANDLERS[stream_idx] = user_handler;
|
||||
DMA_2_USER_ARGS[stream_idx] = user_args;
|
||||
}
|
||||
@ -31,54 +30,22 @@ defined in the startup_stm32h743xx.s files! */
|
||||
DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX](DMA_##DMA_IDX##_USER_ARGS[STREAM_IDX]); \
|
||||
return; \
|
||||
} \
|
||||
Default_Handler() \
|
||||
Default_Handler()
|
||||
|
||||
extern"C" void DMA1_Stream0_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 0);
|
||||
}
|
||||
extern"C" void DMA1_Stream1_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 1);
|
||||
}
|
||||
extern"C" void DMA1_Stream2_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 2);
|
||||
}
|
||||
extern"C" void DMA1_Stream3_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 3);
|
||||
}
|
||||
extern"C" void DMA1_Stream4_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 4);
|
||||
}
|
||||
extern"C" void DMA1_Stream5_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 5);
|
||||
}
|
||||
extern"C" void DMA1_Stream6_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 6);
|
||||
}
|
||||
extern"C" void DMA1_Stream7_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(1, 7);
|
||||
}
|
||||
extern "C" void DMA1_Stream0_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 0); }
|
||||
extern "C" void DMA1_Stream1_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 1); }
|
||||
extern "C" void DMA1_Stream2_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 2); }
|
||||
extern "C" void DMA1_Stream3_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 3); }
|
||||
extern "C" void DMA1_Stream4_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 4); }
|
||||
extern "C" void DMA1_Stream5_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 5); }
|
||||
extern "C" void DMA1_Stream6_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 6); }
|
||||
extern "C" void DMA1_Stream7_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 7); }
|
||||
|
||||
extern"C" void DMA2_Stream0_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 0);
|
||||
}
|
||||
extern"C" void DMA2_Stream1_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 1);
|
||||
}
|
||||
extern"C" void DMA2_Stream2_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 2);
|
||||
}
|
||||
extern"C" void DMA2_Stream3_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 3);
|
||||
}
|
||||
extern"C" void DMA2_Stream4_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 4);
|
||||
}
|
||||
extern"C" void DMA2_Stream5_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 5);
|
||||
}
|
||||
extern"C" void DMA2_Stream6_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 6);
|
||||
}
|
||||
extern"C" void DMA2_Stream7_IRQHandler() {
|
||||
GENERIC_DMA_IRQ_HANDLER(2, 7);
|
||||
}
|
||||
extern "C" void DMA2_Stream0_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 0); }
|
||||
extern "C" void DMA2_Stream1_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 1); }
|
||||
extern "C" void DMA2_Stream2_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 2); }
|
||||
extern "C" void DMA2_Stream3_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 3); }
|
||||
extern "C" void DMA2_Stream4_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 4); }
|
||||
extern "C" void DMA2_Stream5_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 5); }
|
||||
extern "C" void DMA2_Stream6_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 6); }
|
||||
extern "C" void DMA2_Stream7_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 7); }
|
||||
|
@ -5,20 +5,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "interrupts.h"
|
||||
#include <cstdint>
|
||||
|
||||
#include "interrupts.h"
|
||||
|
||||
namespace dma {
|
||||
|
||||
enum DMAType {
|
||||
TX = 0,
|
||||
RX = 1
|
||||
};
|
||||
enum DMAType { TX = 0, RX = 1 };
|
||||
|
||||
enum DMAIndexes: uint8_t {
|
||||
DMA_1 = 1,
|
||||
DMA_2 = 2
|
||||
};
|
||||
enum DMAIndexes : uint8_t { DMA_1 = 1, DMA_2 = 2 };
|
||||
|
||||
enum DMAStreams {
|
||||
STREAM_0 = 0,
|
||||
@ -37,10 +32,10 @@ enum DMAStreams {
|
||||
* @param user_handler
|
||||
* @param user_args
|
||||
*/
|
||||
void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
|
||||
user_handler_t user_handler, user_args_t user_args);
|
||||
void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx, user_handler_t user_handler,
|
||||
user_args_t user_args);
|
||||
|
||||
}
|
||||
} // namespace dma
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -15,11 +15,7 @@ extern void Default_Handler();
|
||||
typedef void (*user_handler_t)(void*);
|
||||
typedef void* user_args_t;
|
||||
|
||||
enum IrqPriorities: uint8_t {
|
||||
HIGHEST = 0,
|
||||
HIGHEST_FREERTOS = 6,
|
||||
LOWEST = 15
|
||||
};
|
||||
enum IrqPriorities : uint8_t { HIGHEST = 0, HIGHEST_FREERTOS = 6, LOWEST = 15 };
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include "fsfw_hal/stm32h7/spi/SpiComIF.h"
|
||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||
|
||||
#include "fsfw/tasks/SemaphoreFactory.h"
|
||||
#include "fsfw_hal/stm32h7/gpio/gpio.h"
|
||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/gpio/gpio.h"
|
||||
|
||||
// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete
|
||||
// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently
|
||||
@ -13,8 +13,8 @@
|
||||
#if defined FSFW_OSAL_RTEMS
|
||||
#include "fsfw/osal/rtems/BinarySemaphore.h"
|
||||
#elif defined FSFW_OSAL_FREERTOS
|
||||
#include "fsfw/osal/freertos/TaskManagement.h"
|
||||
#include "fsfw/osal/freertos/BinarySemaphore.h"
|
||||
#include "fsfw/osal/freertos/TaskManagement.h"
|
||||
#endif
|
||||
|
||||
#include "stm32h7xx_hal_gpio.h"
|
||||
@ -35,9 +35,7 @@ void SpiComIF::addDmaHandles(DMA_HandleTypeDef *txHandle, DMA_HandleTypeDef *rxH
|
||||
spi::setDmaHandles(txHandle, rxHandle);
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::initialize() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ReturnValue_t SpiComIF::initialize() { return HasReturnvaluesIF::RETURN_OK; }
|
||||
|
||||
ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
|
||||
@ -61,8 +59,8 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
}
|
||||
}
|
||||
// This semaphore ensures thread-safety for a given bus
|
||||
spiSemaphore = dynamic_cast<BinarySemaphore*>(
|
||||
SemaphoreFactory::instance()->createBinarySemaphore());
|
||||
spiSemaphore =
|
||||
dynamic_cast<BinarySemaphore *>(SemaphoreFactory::instance()->createBinarySemaphore());
|
||||
address_t spiAddress = spiCookie->getDeviceAddress();
|
||||
|
||||
auto iter = spiDeviceMap.find(spiAddress);
|
||||
@ -72,11 +70,13 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
if (not statusPair.second) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " <<
|
||||
spiAddress << "to SPI device map" << std::endl;
|
||||
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address "
|
||||
<< spiAddress << "to SPI device map" << std::endl;
|
||||
#else
|
||||
sif::printError("SpiComIF::initializeInterface: Failed to insert device with address "
|
||||
"%lu to SPI device map\n", static_cast<unsigned long>(spiAddress));
|
||||
sif::printError(
|
||||
"SpiComIF::initializeInterface: Failed to insert device with address "
|
||||
"%lu to SPI device map\n",
|
||||
static_cast<unsigned long>(spiAddress));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -92,13 +92,11 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
#ifdef SPI1
|
||||
spiHandle.Instance = SPI1;
|
||||
#endif
|
||||
}
|
||||
else if(spiIdx == spi::SpiBus::SPI_2) {
|
||||
} else if (spiIdx == spi::SpiBus::SPI_2) {
|
||||
#ifdef SPI2
|
||||
spiHandle.Instance = SPI2;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printCfgError("SPI Bus Index");
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
@ -112,16 +110,14 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
spi::setSpiPollingMspFunctions(typedCfg);
|
||||
}
|
||||
else if(transferMode == spi::TransferModes::INTERRUPT) {
|
||||
} else if (transferMode == spi::TransferModes::INTERRUPT) {
|
||||
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
|
||||
if (typedCfg == nullptr) {
|
||||
printCfgError("IRQ MSP");
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
spi::setSpiIrqMspFunctions(typedCfg);
|
||||
}
|
||||
else if(transferMode == spi::TransferModes::DMA) {
|
||||
} else if (transferMode == spi::TransferModes::DMA) {
|
||||
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
|
||||
if (typedCfg == nullptr) {
|
||||
printCfgError("DMA MSP");
|
||||
@ -201,9 +197,7 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||
|
||||
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -253,7 +247,8 @@ void SpiComIF::setDefaultPollingTimeout(dur_millis_t timeout) {
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
|
||||
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||
size_t sendLen) {
|
||||
auto gpioPort = spiCookie.getChipSelectGpioPort();
|
||||
auto gpioPin = spiCookie.getChipSelectGpioPin();
|
||||
auto returnval = spiSemaphore->acquire(timeoutType, timeoutMs);
|
||||
@ -265,8 +260,8 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t*>(sendData),
|
||||
recvPtr, sendLen, defaultPollingTimeout);
|
||||
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t *>(sendData), recvPtr,
|
||||
sendLen, defaultPollingTimeout);
|
||||
if (gpioPort != nullptr) {
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||
}
|
||||
@ -279,8 +274,8 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
||||
case (HAL_TIMEOUT): {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "SpiComIF::sendMessage: Polling Mode | Timeout for SPI device" <<
|
||||
spiCookie->getDeviceAddress() << std::endl;
|
||||
sif::warning << "SpiComIF::sendMessage: Polling Mode | Timeout for SPI device"
|
||||
<< spiCookie->getDeviceAddress() << std::endl;
|
||||
#else
|
||||
sif::printWarning("SpiComIF::sendMessage: Polling Mode | Timeout for SPI device %d\n",
|
||||
spiCookie.getDeviceAddress());
|
||||
@ -293,8 +288,8 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
||||
default: {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "SpiComIF::sendMessage: Polling Mode | HAL error for SPI device" <<
|
||||
spiCookie->getDeviceAddress() << std::endl;
|
||||
sif::warning << "SpiComIF::sendMessage: Polling Mode | HAL error for SPI device"
|
||||
<< spiCookie->getDeviceAddress() << std::endl;
|
||||
#else
|
||||
sif::printWarning("SpiComIF::sendMessage: Polling Mode | HAL error for SPI device %d\n",
|
||||
spiCookie.getDeviceAddress());
|
||||
@ -308,17 +303,20 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::handleInterruptSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) {
|
||||
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||
size_t sendLen) {
|
||||
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::handleDmaSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) {
|
||||
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||
size_t sendLen) {
|
||||
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||
}
|
||||
|
||||
ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
|
||||
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||
size_t sendLen) {
|
||||
ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
@ -330,15 +328,13 @@ ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeD
|
||||
if (cacheMaintenanceOnTxBuffer) {
|
||||
/* Clean D-cache. Make sure the address is 32-byte aligned and add 32-bytes to length,
|
||||
in case it overlaps cacheline */
|
||||
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t) sendData ) & ~(uint32_t)0x1F),
|
||||
sendLen + 32);
|
||||
SCB_CleanDCache_by_Addr((uint32_t *)(((uint32_t)sendData) & ~(uint32_t)0x1F), sendLen + 32);
|
||||
}
|
||||
status = HAL_SPI_TransmitReceive_DMA(&spiHandle, const_cast<uint8_t *>(sendData),
|
||||
currentRecvPtr, sendLen);
|
||||
}
|
||||
else {
|
||||
status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast<uint8_t*>(sendData),
|
||||
currentRecvPtr, sendLen);
|
||||
} else {
|
||||
status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast<uint8_t *>(sendData), currentRecvPtr,
|
||||
sendLen);
|
||||
}
|
||||
switch (status) {
|
||||
case (HAL_OK): {
|
||||
@ -355,12 +351,10 @@ ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferM
|
||||
char modeString[10];
|
||||
if (transferMode == spi::TransferModes::DMA) {
|
||||
std::snprintf(modeString, sizeof(modeString), "Dma");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::snprintf(modeString, sizeof(modeString), "Interrupt");
|
||||
}
|
||||
sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString,
|
||||
status);
|
||||
sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString, status);
|
||||
switch (status) {
|
||||
case (HAL_BUSY): {
|
||||
return spi::HAL_BUSY_RETVAL;
|
||||
@ -377,9 +371,9 @@ ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferM
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
|
||||
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||
size_t sendLen) {
|
||||
currentRecvPtr = recvPtr;
|
||||
currentRecvBuffSize = sendLen;
|
||||
|
||||
@ -387,8 +381,10 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef&
|
||||
ReturnValue_t result = spiSemaphore->acquire(SemaphoreIF::TimeoutType::WAITING, timeoutMs);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// Configuration error
|
||||
sif::printWarning("SpiComIF::handleInterruptSendOperation: Semaphore "
|
||||
"could not be acquired after %d ms\n", timeoutMs);
|
||||
sif::printWarning(
|
||||
"SpiComIF::handleInterruptSendOperation: Semaphore "
|
||||
"could not be acquired after %d ms\n",
|
||||
timeoutMs);
|
||||
return result;
|
||||
}
|
||||
// Cache the current SPI handle in any case
|
||||
@ -441,12 +437,11 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt
|
||||
GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
|
||||
#if defined FSFW_OSAL_FREERTOS
|
||||
// Release the task semaphore
|
||||
BaseType_t taskWoken = pdFALSE;
|
||||
ReturnValue_t result = BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(),
|
||||
&taskWoken);
|
||||
ReturnValue_t result =
|
||||
BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(), &taskWoken);
|
||||
#elif defined FSFW_OSAL_RTEMS
|
||||
ReturnValue_t result = comIF->spiSemaphore->release();
|
||||
#endif
|
||||
@ -458,8 +453,7 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt
|
||||
// Perform cache maintenance operation for DMA transfers
|
||||
if (spiCookie->getTransferMode() == spi::TransferModes::DMA) {
|
||||
// Invalidate cache prior to access by CPU
|
||||
SCB_InvalidateDCache_by_Addr ((uint32_t *) comIF->currentRecvPtr,
|
||||
comIF->currentRecvBuffSize);
|
||||
SCB_InvalidateDCache_by_Addr((uint32_t *)comIF->currentRecvPtr, comIF->currentRecvBuffSize);
|
||||
}
|
||||
#if defined FSFW_OSAL_FREERTOS
|
||||
/* Request a context switch if the SPI ComIF task was woken up and has a higher priority
|
||||
|
@ -1,16 +1,15 @@
|
||||
#ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
|
||||
#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
|
||||
|
||||
#include "fsfw/tasks/SemaphoreIF.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
|
||||
#include "fsfw/tasks/SemaphoreIF.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
#include "stm32h743xx.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
class SpiCookie;
|
||||
class BinarySemaphore;
|
||||
@ -28,9 +27,7 @@ class BinarySemaphore;
|
||||
* implementation limits the transfer mode for a given SPI bus.
|
||||
* @author R. Mueller
|
||||
*/
|
||||
class SpiComIF:
|
||||
public SystemObject,
|
||||
public DeviceCommunicationIF {
|
||||
class SpiComIF : public SystemObject, public DeviceCommunicationIF {
|
||||
public:
|
||||
/**
|
||||
* Create a SPI communication interface for the given SPI peripheral (spiInstance)
|
||||
@ -63,16 +60,14 @@ public:
|
||||
|
||||
// DeviceCommunicationIF overrides
|
||||
virtual ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||
virtual ReturnValue_t sendMessage(CookieIF *cookie,
|
||||
const uint8_t * sendData, size_t sendLen) override;
|
||||
virtual ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData,
|
||||
size_t sendLen) override;
|
||||
virtual ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) override;
|
||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **buffer, size_t *size) override;
|
||||
virtual ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||
virtual ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
||||
size_t* size) override;
|
||||
|
||||
protected:
|
||||
|
||||
struct SpiInstance {
|
||||
SpiInstance(size_t maxRecvSize) : replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
||||
std::vector<uint8_t> replyBuffer;
|
||||
@ -103,13 +98,17 @@ protected:
|
||||
SpiDeviceMap spiDeviceMap;
|
||||
|
||||
ReturnValue_t handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
||||
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||
size_t sendLen);
|
||||
ReturnValue_t handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
||||
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||
size_t sendLen);
|
||||
ReturnValue_t handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
||||
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||
size_t sendLen);
|
||||
ReturnValue_t handleIrqSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
||||
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||
size_t sendLen);
|
||||
ReturnValue_t genericIrqSendSetup(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||
SpiCookie& spiCookie, const uint8_t* sendData, size_t sendLen);
|
||||
ReturnValue_t halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode);
|
||||
@ -124,6 +123,4 @@ protected:
|
||||
void printCfgError(const char* const type);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ */
|
||||
|
@ -1,12 +1,16 @@
|
||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||
|
||||
|
||||
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio):
|
||||
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
|
||||
transferMode(transferMode), csGpio(csGpio),
|
||||
mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio)
|
||||
: deviceAddress(deviceAddress),
|
||||
spiIdx(spiIdx),
|
||||
spiSpeed(spiSpeed),
|
||||
spiMode(spiMode),
|
||||
transferMode(transferMode),
|
||||
csGpio(csGpio),
|
||||
mspCfg(mspCfg),
|
||||
maxRecvSize(maxRecvSize) {
|
||||
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
@ -23,41 +27,23 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM
|
||||
spiHandle.Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), spiSpeed);
|
||||
}
|
||||
|
||||
uint16_t SpiCookie::getChipSelectGpioPin() const {
|
||||
return csGpio.pin;
|
||||
}
|
||||
uint16_t SpiCookie::getChipSelectGpioPin() const { return csGpio.pin; }
|
||||
|
||||
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
|
||||
return csGpio.port;
|
||||
}
|
||||
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() { return csGpio.port; }
|
||||
|
||||
address_t SpiCookie::getDeviceAddress() const {
|
||||
return deviceAddress;
|
||||
}
|
||||
address_t SpiCookie::getDeviceAddress() const { return deviceAddress; }
|
||||
|
||||
spi::SpiBus SpiCookie::getSpiIdx() const {
|
||||
return spiIdx;
|
||||
}
|
||||
spi::SpiBus SpiCookie::getSpiIdx() const { return spiIdx; }
|
||||
|
||||
spi::SpiModes SpiCookie::getSpiMode() const {
|
||||
return spiMode;
|
||||
}
|
||||
spi::SpiModes SpiCookie::getSpiMode() const { return spiMode; }
|
||||
|
||||
uint32_t SpiCookie::getSpiSpeed() const {
|
||||
return spiSpeed;
|
||||
}
|
||||
uint32_t SpiCookie::getSpiSpeed() const { return spiSpeed; }
|
||||
|
||||
size_t SpiCookie::getMaxRecvSize() const {
|
||||
return maxRecvSize;
|
||||
}
|
||||
size_t SpiCookie::getMaxRecvSize() const { return maxRecvSize; }
|
||||
|
||||
SPI_HandleTypeDef& SpiCookie::getSpiHandle() {
|
||||
return spiHandle;
|
||||
}
|
||||
SPI_HandleTypeDef& SpiCookie::getSpiHandle() { return spiHandle; }
|
||||
|
||||
spi::MspCfgBase* SpiCookie::getMspCfg() {
|
||||
return mspCfg;
|
||||
}
|
||||
spi::MspCfgBase* SpiCookie::getMspCfg() { return mspCfg; }
|
||||
|
||||
void SpiCookie::deleteMspCfg() {
|
||||
if (mspCfg != nullptr) {
|
||||
@ -65,14 +51,10 @@ void SpiCookie::deleteMspCfg() {
|
||||
}
|
||||
}
|
||||
|
||||
spi::TransferModes SpiCookie::getTransferMode() const {
|
||||
return transferMode;
|
||||
}
|
||||
spi::TransferModes SpiCookie::getTransferMode() const { return transferMode; }
|
||||
|
||||
void SpiCookie::setTransferState(spi::TransferStates transferState) {
|
||||
this->transferState = transferState;
|
||||
}
|
||||
|
||||
spi::TransferStates SpiCookie::getTransferState() const {
|
||||
return this->transferState;
|
||||
}
|
||||
spi::TransferStates SpiCookie::getTransferState() const { return this->transferState; }
|
||||
|
@ -1,16 +1,14 @@
|
||||
#ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
||||
#define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
||||
|
||||
#include "spiDefinitions.h"
|
||||
#include "mspInit.h"
|
||||
#include "../definitions.h"
|
||||
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
|
||||
#include "stm32h743xx.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../definitions.h"
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
#include "mspInit.h"
|
||||
#include "spiDefinitions.h"
|
||||
#include "stm32h743xx.h"
|
||||
|
||||
/**
|
||||
* @brief SPI cookie implementation for the STM32H7 device family
|
||||
* @details
|
||||
@ -20,8 +18,8 @@
|
||||
*/
|
||||
class SpiCookie : public CookieIF {
|
||||
friend class SpiComIF;
|
||||
public:
|
||||
|
||||
public:
|
||||
/**
|
||||
* Allows construction of a SPI cookie for a connected SPI device
|
||||
* @param deviceAddress
|
||||
@ -39,8 +37,8 @@ public:
|
||||
* @param csGpio Optional CS GPIO definition.
|
||||
*/
|
||||
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
|
||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, size_t maxRecvSize,
|
||||
stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
|
||||
|
||||
uint16_t getChipSelectGpioPin() const;
|
||||
GPIO_TypeDef* getChipSelectGpioPort();
|
||||
@ -75,6 +73,4 @@ private:
|
||||
spi::TransferStates getTransferState() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ */
|
||||
|
@ -1,15 +1,15 @@
|
||||
#include "fsfw_hal/stm32h7/dma.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
|
||||
#include "stm32h743xx.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
||||
#include "stm32h7xx_hal_def.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "fsfw_hal/stm32h7/dma.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "stm32h743xx.h"
|
||||
#include "stm32h7xx_hal_def.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
spi::msp_func_t mspInitFunc = nullptr;
|
||||
spi::MspCfgBase* mspInitArgs = nullptr;
|
||||
|
||||
@ -73,8 +73,7 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */
|
||||
// Assign the interrupt handler
|
||||
dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream,
|
||||
&spi::dmaTxIrqHandler, hdma_tx);
|
||||
dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream, &spi::dmaTxIrqHandler, hdma_tx);
|
||||
HAL_NVIC_SetPriority(cfg->txDmaIrqNumber, cfg->txPreEmptPriority, cfg->txSubpriority);
|
||||
HAL_NVIC_EnableIRQ(cfg->txDmaIrqNumber);
|
||||
}
|
||||
@ -98,8 +97,7 @@ void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
spi::getDmaHandles(&hdma_tx, &hdma_rx);
|
||||
if (hdma_tx == NULL || hdma_rx == NULL) {
|
||||
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Disable the DMA
|
||||
/* De-Initialize the DMA associated to transmission process */
|
||||
HAL_DMA_DeInit(hdma_tx);
|
||||
@ -110,7 +108,6 @@ void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
// Disable the NVIC for DMA
|
||||
HAL_NVIC_DisableIRQ(cfg->txDmaIrqNumber);
|
||||
HAL_NVIC_DisableIRQ(cfg->rxDmaIrqNumber);
|
||||
|
||||
}
|
||||
|
||||
void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
@ -188,8 +185,8 @@ void spi::getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args) {
|
||||
}
|
||||
}
|
||||
|
||||
void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg,
|
||||
msp_func_t initFunc, msp_func_t deinitFunc) {
|
||||
void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, msp_func_t initFunc,
|
||||
msp_func_t deinitFunc) {
|
||||
mspInitFunc = initFunc;
|
||||
mspDeinitFunc = deinitFunc;
|
||||
mspInitArgs = cfg;
|
||||
@ -225,8 +222,7 @@ void spi::setSpiPollingMspFunctions(MspPollingConfigStruct *cfg, msp_func_t init
|
||||
extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
|
||||
if (mspInitFunc != NULL) {
|
||||
mspInitFunc(hspi, mspInitArgs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("HAL_SPI_MspInit: Please call set_msp_functions to assign SPI MSP functions\n");
|
||||
}
|
||||
}
|
||||
@ -242,8 +238,7 @@ extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) {
|
||||
extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) {
|
||||
if (mspDeinitFunc != NULL) {
|
||||
mspDeinitFunc(hspi, mspDeinitArgs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("HAL_SPI_MspDeInit: Please call set_msp_functions to assign SPI MSP functions\n");
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
#ifndef FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
||||
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
||||
|
||||
#include "spiDefinitions.h"
|
||||
#include <cstdint>
|
||||
|
||||
#include "../definitions.h"
|
||||
#include "../dma.h"
|
||||
|
||||
#include "spiDefinitions.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -22,11 +21,10 @@ using mspCb = void (*) (void);
|
||||
namespace spi {
|
||||
|
||||
struct MspCfgBase {
|
||||
MspCfgBase();
|
||||
MspCfgBase() {}
|
||||
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb),
|
||||
setupCb(setupCb) {}
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||
: sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb), setupCb(setupCb) {}
|
||||
|
||||
virtual ~MspCfgBase() = default;
|
||||
|
||||
@ -41,8 +39,8 @@ struct MspCfgBase {
|
||||
struct MspPollingConfigStruct : public MspCfgBase {
|
||||
MspPollingConfigStruct() : MspCfgBase(){};
|
||||
MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||
: MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
};
|
||||
|
||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||
@ -50,8 +48,8 @@ argument */
|
||||
struct MspIrqConfigStruct : public MspPollingConfigStruct {
|
||||
MspIrqConfigStruct() : MspPollingConfigStruct(){};
|
||||
MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||
: MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
|
||||
SpiBus spiBus = SpiBus::SPI_1;
|
||||
user_handler_t spiIrqHandler = nullptr;
|
||||
@ -68,8 +66,8 @@ argument */
|
||||
struct MspDmaConfigStruct : public MspIrqConfigStruct {
|
||||
MspDmaConfigStruct() : MspIrqConfigStruct(){};
|
||||
MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||
: MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
void (*dmaClkEnableWrapper)(void) = nullptr;
|
||||
|
||||
dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1;
|
||||
@ -87,7 +85,6 @@ struct MspDmaConfigStruct: public MspIrqConfigStruct {
|
||||
|
||||
using msp_func_t = void (*)(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
||||
|
||||
|
||||
void getMspInitFunction(msp_func_t* init_func, MspCfgBase** args);
|
||||
void getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args);
|
||||
|
||||
@ -107,23 +104,17 @@ void halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
||||
* @param deinit_func
|
||||
* @param deinit_args
|
||||
*/
|
||||
void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg,
|
||||
msp_func_t initFunc = &spi::halMspInitDma,
|
||||
msp_func_t deinitFunc= &spi::halMspDeinitDma
|
||||
);
|
||||
void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg,
|
||||
msp_func_t initFunc = &spi::halMspInitInterrupt,
|
||||
msp_func_t deinitFunc= &spi::halMspDeinitInterrupt
|
||||
);
|
||||
void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, msp_func_t initFunc = &spi::halMspInitDma,
|
||||
msp_func_t deinitFunc = &spi::halMspDeinitDma);
|
||||
void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg, msp_func_t initFunc = &spi::halMspInitInterrupt,
|
||||
msp_func_t deinitFunc = &spi::halMspDeinitInterrupt);
|
||||
void setSpiPollingMspFunctions(MspPollingConfigStruct* cfg,
|
||||
msp_func_t initFunc = &spi::halMspInitPolling,
|
||||
msp_func_t deinitFunc= &spi::halMspDeinitPolling
|
||||
);
|
||||
msp_func_t deinitFunc = &spi::halMspDeinitPolling);
|
||||
|
||||
void mspErrorHandler(const char* const function, const char* const message);
|
||||
|
||||
}
|
||||
|
||||
} // namespace spi
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
|
||||
SPI_HandleTypeDef* spiHandle = nullptr;
|
||||
DMA_HandleTypeDef* hdmaTx = nullptr;
|
||||
DMA_HandleTypeDef* hdmaRx = nullptr;
|
||||
@ -21,16 +22,15 @@ void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMA
|
||||
void mapSpiBus(DMA_HandleTypeDef* handle, dma::DMAType dmaType, spi::SpiBus spiBus);
|
||||
|
||||
void spi::configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, dma::DMAType dmaType,
|
||||
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber,
|
||||
uint32_t dmaMode, uint32_t dmaPriority) {
|
||||
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream,
|
||||
IRQn_Type* dmaIrqNumber, uint32_t dmaMode, uint32_t dmaPriority) {
|
||||
using namespace dma;
|
||||
mapIndexAndStream(handle, dmaType, dmaIdx, dmaStream, dmaIrqNumber);
|
||||
mapSpiBus(handle, dmaType, spiBus);
|
||||
|
||||
if (dmaType == DMAType::TX) {
|
||||
handle->Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
handle->Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
}
|
||||
|
||||
@ -85,11 +85,7 @@ void spi::assignTransferErrorCallback(spi_transfer_cb_t callback, void *userArgs
|
||||
errorArgs = userArgs;
|
||||
}
|
||||
|
||||
SPI_HandleTypeDef* spi::getSpiHandle() {
|
||||
return spiHandle;
|
||||
}
|
||||
|
||||
|
||||
SPI_HandleTypeDef* spi::getSpiHandle() { return spiHandle; }
|
||||
|
||||
/**
|
||||
* @brief TxRx Transfer completed callback.
|
||||
@ -98,8 +94,7 @@ SPI_HandleTypeDef* spi::getSpiHandle() {
|
||||
extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||
if (rxTxCb != NULL) {
|
||||
rxTxCb(hspi, rxTxArgs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("HAL_SPI_TxRxCpltCallback: No user callback specified\n");
|
||||
}
|
||||
}
|
||||
@ -111,8 +106,7 @@ extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
|
||||
extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||
if (txCb != NULL) {
|
||||
txCb(hspi, txArgs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("HAL_SPI_TxCpltCallback: No user callback specified\n");
|
||||
}
|
||||
}
|
||||
@ -124,8 +118,7 @@ extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
|
||||
extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||
if (rxCb != nullptr) {
|
||||
rxCb(hspi, rxArgs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("HAL_SPI_RxCpltCallback: No user callback specified\n");
|
||||
}
|
||||
}
|
||||
@ -140,8 +133,7 @@ extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
|
||||
extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef* hspi) {
|
||||
if (errorCb != nullptr) {
|
||||
errorCb(hspi, rxArgs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("HAL_SPI_ErrorCallback: No user callback specified\n");
|
||||
}
|
||||
}
|
||||
@ -227,8 +219,7 @@ void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMA
|
||||
}
|
||||
if (dmaType == DMAType::TX) {
|
||||
handle->Init.Request = DMA_REQUEST_SPI1_TX;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
handle->Init.Request = DMA_REQUEST_SPI1_RX;
|
||||
}
|
||||
#endif /* DMA1 */
|
||||
@ -319,20 +310,17 @@ void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiB
|
||||
#ifdef DMA_REQUEST_SPI1_TX
|
||||
handle->Init.Request = DMA_REQUEST_SPI1_TX;
|
||||
#endif
|
||||
}
|
||||
else if(spiBus == spi::SpiBus::SPI_2) {
|
||||
} else if (spiBus == spi::SpiBus::SPI_2) {
|
||||
#ifdef DMA_REQUEST_SPI2_TX
|
||||
handle->Init.Request = DMA_REQUEST_SPI2_TX;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (spiBus == spi::SpiBus::SPI_1) {
|
||||
#ifdef DMA_REQUEST_SPI1_RX
|
||||
handle->Init.Request = DMA_REQUEST_SPI1_RX;
|
||||
#endif
|
||||
}
|
||||
else if(spiBus == spi::SpiBus::SPI_2) {
|
||||
} else if (spiBus == spi::SpiBus::SPI_2) {
|
||||
#ifdef DMA_REQUEST_SPI2_RX
|
||||
handle->Init.Request = DMA_REQUEST_SPI2_RX;
|
||||
#endif
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "fsfw_hal/stm32h7/dma.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
||||
|
||||
@ -15,10 +14,9 @@ using spi_transfer_cb_t = void (*) (SPI_HandleTypeDef *hspi, void* userArgs);
|
||||
|
||||
namespace spi {
|
||||
|
||||
void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus,
|
||||
dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
|
||||
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber, uint32_t dmaMode = DMA_NORMAL,
|
||||
uint32_t dmaPriority = DMA_PRIORITY_LOW);
|
||||
void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, dma::DMAType dmaType,
|
||||
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber,
|
||||
uint32_t dmaMode = DMA_NORMAL, uint32_t dmaPriority = DMA_PRIORITY_LOW);
|
||||
|
||||
/**
|
||||
* Assign DMA handles. Required to use DMA for SPI transfers.
|
||||
@ -45,7 +43,7 @@ void assignTransferErrorCallback(spi_transfer_cb_t callback, void* userArgs);
|
||||
*/
|
||||
SPI_HandleTypeDef* getSpiHandle();
|
||||
|
||||
}
|
||||
} // namespace spi
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -30,20 +30,14 @@ uint32_t spi::getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps) {
|
||||
uint32_t spi_clk = clock_src_freq;
|
||||
uint32_t presc = 0;
|
||||
static const uint32_t baudrate[] = {
|
||||
SPI_BAUDRATEPRESCALER_2,
|
||||
SPI_BAUDRATEPRESCALER_4,
|
||||
SPI_BAUDRATEPRESCALER_8,
|
||||
SPI_BAUDRATEPRESCALER_16,
|
||||
SPI_BAUDRATEPRESCALER_32,
|
||||
SPI_BAUDRATEPRESCALER_64,
|
||||
SPI_BAUDRATEPRESCALER_128,
|
||||
SPI_BAUDRATEPRESCALER_256,
|
||||
SPI_BAUDRATEPRESCALER_2, SPI_BAUDRATEPRESCALER_4, SPI_BAUDRATEPRESCALER_8,
|
||||
SPI_BAUDRATEPRESCALER_16, SPI_BAUDRATEPRESCALER_32, SPI_BAUDRATEPRESCALER_64,
|
||||
SPI_BAUDRATEPRESCALER_128, SPI_BAUDRATEPRESCALER_256,
|
||||
};
|
||||
|
||||
while (spi_clk > baudrate_mbps) {
|
||||
presc = baudrate[divisor];
|
||||
if (++divisor > 7)
|
||||
break;
|
||||
if (++divisor > 7) break;
|
||||
|
||||
spi_clk = (spi_clk >> 1);
|
||||
}
|
||||
|
@ -2,37 +2,24 @@
|
||||
#define FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_
|
||||
|
||||
#include "../../common/spi/spiCommon.h"
|
||||
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
namespace spi {
|
||||
|
||||
static constexpr uint8_t HAL_SPI_ID = CLASS_ID::HAL_SPI;
|
||||
static constexpr ReturnValue_t HAL_TIMEOUT_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 0);
|
||||
static constexpr ReturnValue_t HAL_TIMEOUT_RETVAL =
|
||||
HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 0);
|
||||
static constexpr ReturnValue_t HAL_BUSY_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 1);
|
||||
static constexpr ReturnValue_t HAL_ERROR_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 2);
|
||||
|
||||
enum class TransferStates {
|
||||
IDLE,
|
||||
WAIT,
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
};
|
||||
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
|
||||
|
||||
enum SpiBus {
|
||||
SPI_1,
|
||||
SPI_2
|
||||
};
|
||||
enum SpiBus { SPI_1, SPI_2 };
|
||||
|
||||
enum TransferModes {
|
||||
POLLING,
|
||||
INTERRUPT,
|
||||
DMA
|
||||
};
|
||||
enum TransferModes { POLLING, INTERRUPT, DMA };
|
||||
|
||||
void assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle);
|
||||
|
||||
@ -44,7 +31,6 @@ void assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle);
|
||||
*/
|
||||
uint32_t getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps);
|
||||
|
||||
}
|
||||
|
||||
} // namespace spi
|
||||
|
||||
#endif /* FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_ */
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
user_handler_t spi1UserHandler = &spi::spiIrqHandler;
|
||||
user_args_t spi1UserArgs = nullptr;
|
||||
|
||||
@ -55,8 +55,7 @@ void spi::assignSpiUserHandler(spi::SpiBus spiIdx, user_handler_t userHandler,
|
||||
if (spiIdx == spi::SpiBus::SPI_1) {
|
||||
spi1UserHandler = userHandler;
|
||||
spi1UserArgs = userArgs;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
spi2UserHandler = userHandler;
|
||||
spi2UserArgs = userArgs;
|
||||
}
|
||||
@ -70,8 +69,7 @@ void spi::getSpiUserHandler(spi::SpiBus spiBus, user_handler_t *userHandler,
|
||||
if (spiBus == spi::SpiBus::SPI_1) {
|
||||
*userArgs = spi1UserArgs;
|
||||
*userHandler = spi1UserHandler;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*userArgs = spi2UserArgs;
|
||||
*userHandler = spi2UserHandler;
|
||||
}
|
||||
@ -80,8 +78,7 @@ void spi::getSpiUserHandler(spi::SpiBus spiBus, user_handler_t *userHandler,
|
||||
void spi::assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs) {
|
||||
if (spiBus == spi::SpiBus::SPI_1) {
|
||||
spi1UserArgs = userArgs;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
spi2UserArgs = userArgs;
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,8 @@ void assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs);
|
||||
* @param user_handler
|
||||
* @param user_args
|
||||
*/
|
||||
void assignSpiUserHandler(spi::SpiBus spiBus, user_handler_t user_handler,
|
||||
user_args_t user_args);
|
||||
void getSpiUserHandler(spi::SpiBus spiBus, user_handler_t* user_handler,
|
||||
user_args_t* user_args);
|
||||
void assignSpiUserHandler(spi::SpiBus spiBus, user_handler_t user_handler, user_args_t user_args);
|
||||
void getSpiUserHandler(spi::SpiBus spiBus, user_handler_t* user_handler, user_args_t* user_args);
|
||||
|
||||
/**
|
||||
* Generic interrupt handlers supplied for convenience. Do not call these directly! Set them
|
||||
@ -32,7 +30,7 @@ void dmaRxIrqHandler(void* dma_handle);
|
||||
void dmaTxIrqHandler(void* dma_handle);
|
||||
void spiIrqHandler(void* spi_handle);
|
||||
|
||||
}
|
||||
} // namespace spi
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_rcc.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_rcc.h"
|
||||
|
||||
void spiSetupWrapper() {
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
@ -18,9 +18,7 @@ void spiCleanUpWrapper() {
|
||||
__HAL_RCC_SPI1_RELEASE_RESET();
|
||||
}
|
||||
|
||||
void spiDmaClockEnableWrapper() {
|
||||
__HAL_RCC_DMA2_CLK_ENABLE();
|
||||
}
|
||||
void spiDmaClockEnableWrapper() { __HAL_RCC_DMA2_CLK_ENABLE(); }
|
||||
|
||||
void stm32h7::h743zi::standardPollingCfg(spi::MspPollingConfigStruct& cfg) {
|
||||
cfg.setupCb = &spiSetupWrapper;
|
||||
@ -56,8 +54,9 @@ void stm32h7::h743zi::standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPrio
|
||||
}
|
||||
|
||||
void stm32h7::h743zi::standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio,
|
||||
IrqPriorities txSubprio, IrqPriorities rxSubprio) {
|
||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
|
||||
IrqPriorities spiSubprio, IrqPriorities txSubprio,
|
||||
IrqPriorities rxSubprio) {
|
||||
cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper;
|
||||
cfg.rxDmaIndex = dma::DMAIndexes::DMA_2;
|
||||
cfg.txDmaIndex = dma::DMAIndexes::DMA_2;
|
||||
|
@ -10,13 +10,11 @@ namespace h743zi {
|
||||
void standardPollingCfg(spi::MspPollingConfigStruct& cfg);
|
||||
void standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities spiSubprio = HIGHEST);
|
||||
void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
|
||||
IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST,
|
||||
IrqPriorities rxSubprio = HIGHEST);
|
||||
void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, IrqPriorities txIrqPrio,
|
||||
IrqPriorities rxIrqPrio, IrqPriorities spiSubprio = HIGHEST,
|
||||
IrqPriorities txSubPrio = HIGHEST, IrqPriorities rxSubprio = HIGHEST);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace h743zi
|
||||
} // namespace stm32h7
|
||||
|
||||
#endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
namespace addresses {
|
||||
/* Logical addresses have uint32_t datatype */
|
||||
enum logicalAddresses: address_t {
|
||||
enum LogAddr: address_t {
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -9,36 +9,44 @@ import webbrowser
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from shutil import which
|
||||
from typing import List
|
||||
|
||||
|
||||
UNITTEST_FOLDER_NAME = 'build-tests'
|
||||
DOCS_FOLDER_NAME = 'build-docs'
|
||||
UNITTEST_FOLDER_NAME = "build-tests"
|
||||
DOCS_FOLDER_NAME = "build-docs"
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description="FSFW helper script")
|
||||
choices = ('docs', 'tests')
|
||||
choices = ("docs", "tests")
|
||||
parser.add_argument(
|
||||
'type', metavar='type', choices=choices,
|
||||
help=f'Target type. Choices: {choices}'
|
||||
"type", metavar="type", choices=choices, help=f"Target type. Choices: {choices}"
|
||||
)
|
||||
parser.add_argument(
|
||||
'-a', '--all', action='store_true',
|
||||
help='Create, build and open specified type'
|
||||
"-a", "--all", action="store_true", help="Create, build and open specified type"
|
||||
)
|
||||
parser.add_argument(
|
||||
'-c', '--create', action='store_true',
|
||||
help='Create docs or test build configuration'
|
||||
"-c",
|
||||
"--create",
|
||||
action="store_true",
|
||||
help="Create docs or test build configuration",
|
||||
)
|
||||
parser.add_argument(
|
||||
'-b', '--build', action='store_true',
|
||||
help='Build the specified type'
|
||||
"-b", "--build", action="store_true", help="Build the specified type"
|
||||
)
|
||||
parser.add_argument(
|
||||
'-o', '--open', action='store_true',
|
||||
help='Open test or documentation data in webbrowser'
|
||||
"-o",
|
||||
"--open",
|
||||
action="store_true",
|
||||
help="Open test or documentation data in webbrowser",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--valgrind",
|
||||
action="store_true",
|
||||
help="Run valgrind on generated test binary",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
@ -46,26 +54,26 @@ def main():
|
||||
args.build = True
|
||||
args.create = True
|
||||
args.open = True
|
||||
elif not args.build and not args.create and not args.open:
|
||||
elif not args.build and not args.create and not args.open and not args.valgrind:
|
||||
print(
|
||||
'Please select at least one operation to perform. '
|
||||
'Use helper.py -h for more information'
|
||||
"Please select at least one operation to perform. "
|
||||
"Use helper.py -h for more information"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
# This script can be called from root and from script folder
|
||||
if not os.path.isfile('README.md'):
|
||||
os.chdir('..')
|
||||
if not os.path.isfile("README.md"):
|
||||
os.chdir("..")
|
||||
build_dir_list = []
|
||||
if not args.create:
|
||||
build_dir_list = build_build_dir_list()
|
||||
|
||||
if args.type == 'tests':
|
||||
if args.type == "tests":
|
||||
handle_tests_type(args, build_dir_list)
|
||||
elif args.type == 'docs':
|
||||
elif args.type == "docs":
|
||||
handle_docs_type(args, build_dir_list)
|
||||
else:
|
||||
print('Invalid or unknown type')
|
||||
print("Invalid or unknown type")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -76,7 +84,9 @@ def handle_docs_type(args, build_dir_list: list):
|
||||
create_docs_build_cfg()
|
||||
build_directory = DOCS_FOLDER_NAME
|
||||
elif len(build_dir_list) == 0:
|
||||
print('No valid CMake docs build directory found. Trying to set up docs build system')
|
||||
print(
|
||||
"No valid CMake docs build directory found. Trying to set up docs build system"
|
||||
)
|
||||
shutil.rmtree(DOCS_FOLDER_NAME)
|
||||
create_docs_build_cfg()
|
||||
build_directory = DOCS_FOLDER_NAME
|
||||
@ -87,18 +97,18 @@ def handle_docs_type(args, build_dir_list: list):
|
||||
build_directory = determine_build_dir(build_dir_list)
|
||||
os.chdir(build_directory)
|
||||
if args.build:
|
||||
os.system('cmake --build . -j')
|
||||
cmd_runner("cmake --build . -j")
|
||||
if args.open:
|
||||
if not os.path.isfile('docs/sphinx/index.html'):
|
||||
if not os.path.isfile("docs/sphinx/index.html"):
|
||||
# try again..
|
||||
os.system('cmake --build . -j')
|
||||
if not os.path.isfile('docs/sphinx/index.html'):
|
||||
cmd_runner("cmake --build . -j")
|
||||
if not os.path.isfile("docs/sphinx/index.html"):
|
||||
print(
|
||||
"No Sphinx documentation file detected. "
|
||||
"Try to build it first with the -b argument"
|
||||
)
|
||||
sys.exit(1)
|
||||
webbrowser.open('docs/sphinx/index.html')
|
||||
webbrowser.open("docs/sphinx/index.html")
|
||||
|
||||
|
||||
def handle_tests_type(args, build_dir_list: list):
|
||||
@ -109,8 +119,8 @@ def handle_tests_type(args, build_dir_list: list):
|
||||
build_directory = UNITTEST_FOLDER_NAME
|
||||
elif len(build_dir_list) == 0:
|
||||
print(
|
||||
'No valid CMake tests build directory found. '
|
||||
'Trying to set up test build system'
|
||||
"No valid CMake tests build directory found. "
|
||||
"Trying to set up test build system"
|
||||
)
|
||||
create_tests_build_cfg()
|
||||
build_directory = UNITTEST_FOLDER_NAME
|
||||
@ -123,24 +133,32 @@ def handle_tests_type(args, build_dir_list: list):
|
||||
if args.build:
|
||||
perform_lcov_operation(build_directory, False)
|
||||
if args.open:
|
||||
if not os.path.isdir('fsfw-tests_coverage'):
|
||||
print("No Unittest folder detected. Try to build them first with the -b argument")
|
||||
if not os.path.isdir("fsfw-tests_coverage"):
|
||||
print(
|
||||
"No Unittest folder detected. Try to build them first with the -b argument"
|
||||
)
|
||||
sys.exit(1)
|
||||
webbrowser.open('fsfw-tests_coverage/index.html')
|
||||
webbrowser.open("fsfw-tests_coverage/index.html")
|
||||
if args.valgrind:
|
||||
if which("valgrind") is None:
|
||||
print("Please install valgrind first")
|
||||
sys.exit(1)
|
||||
cmd_runner("valgrind --leak-check=full ./fsfw-tests")
|
||||
os.chdir("..")
|
||||
|
||||
|
||||
def create_tests_build_cfg():
|
||||
os.mkdir(UNITTEST_FOLDER_NAME)
|
||||
os.chdir(UNITTEST_FOLDER_NAME)
|
||||
os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..')
|
||||
os.chdir('..')
|
||||
cmd_runner("cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..")
|
||||
os.chdir("..")
|
||||
|
||||
|
||||
def create_docs_build_cfg():
|
||||
os.mkdir(DOCS_FOLDER_NAME)
|
||||
os.chdir(DOCS_FOLDER_NAME)
|
||||
os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_DOCS=ON ..')
|
||||
os.chdir('..')
|
||||
cmd_runner("cmake -DFSFW_OSAL=host -DFSFW_BUILD_DOCS=ON ..")
|
||||
os.chdir("..")
|
||||
|
||||
|
||||
def build_build_dir_list() -> list:
|
||||
@ -162,7 +180,7 @@ def check_for_cmake_build_dir(build_dir_list: list) -> list:
|
||||
def perform_lcov_operation(directory: str, chdir: bool):
|
||||
if chdir:
|
||||
os.chdir(directory)
|
||||
os.system("cmake --build . -- fsfw-tests_coverage -j")
|
||||
cmd_runner("cmake --build . -- fsfw-tests_coverage -j")
|
||||
|
||||
|
||||
def determine_build_dir(build_dir_list: List[str]):
|
||||
@ -184,5 +202,10 @@ def determine_build_dir(build_dir_list: List[str]):
|
||||
return build_directory
|
||||
|
||||
|
||||
def cmd_runner(cmd: str):
|
||||
print(f"Executing command: {cmd}")
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -7,12 +7,3 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
)
|
||||
|
||||
add_subdirectory(fsfw)
|
||||
|
||||
# Configure File
|
||||
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
@ -1,6 +1,11 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
version.cpp
|
||||
)
|
||||
|
||||
# Core
|
||||
|
||||
add_subdirectory(action)
|
||||
add_subdirectory(cfdp)
|
||||
add_subdirectory(container)
|
||||
add_subdirectory(controller)
|
||||
add_subdirectory(datapool)
|
||||
|
@ -18,6 +18,10 @@
|
||||
|
||||
// FSFW core defines
|
||||
|
||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_CPP_OSTREAM_ENABLED
|
||||
#define FSFW_CPP_OSTREAM_ENABLED 1
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED */
|
||||
@ -26,6 +30,10 @@
|
||||
#define FSFW_VERBOSE_LEVEL 1
|
||||
#endif /* FSFW_VERBOSE_LEVEL */
|
||||
|
||||
#ifndef FSFW_DISABLE_PRINTOUT
|
||||
#define FSFW_DISABLE_PRINTOUT 0
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_USE_REALTIME_FOR_LINUX
|
||||
#define FSFW_USE_REALTIME_FOR_LINUX 0
|
||||
#endif /* FSFW_USE_REALTIME_FOR_LINUX */
|
||||
@ -42,6 +50,10 @@
|
||||
#define FSFW_USE_PUS_C_TELECOMMANDS 1
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
// FSFW HAL defines
|
||||
|
||||
// Can be used for low-level debugging of the SPI bus
|
||||
@ -49,16 +61,9 @@
|
||||
#define FSFW_HAL_SPI_WIRETAPPING 0
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG
|
||||
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
|
||||
#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */
|
||||
|
||||
#ifndef FSFW_HAL_RM3100_MGM_DEBUG
|
||||
#define FSFW_HAL_RM3100_MGM_DEBUG 0
|
||||
#endif /* FSFW_HAL_RM3100_MGM_DEBUG */
|
||||
|
||||
#ifndef FSFW_HAL_LIS3MDL_MGM_DEBUG
|
||||
#define FSFW_HAL_LIS3MDL_MGM_DEBUG 0
|
||||
#endif /* FSFW_HAL_LIS3MDL_MGM_DEBUG */
|
||||
// Can be used for low-level debugging of the I2C bus
|
||||
#ifndef FSFW_HAL_I2C_WIRETAPPING
|
||||
#define FSFW_HAL_I2C_WIRETAPPING 0
|
||||
#endif
|
||||
|
||||
#endif /* FSFW_FSFW_H_ */
|
||||
|
@ -1,9 +1,11 @@
|
||||
#ifndef FSFW_VERSION_H_
|
||||
#define FSFW_VERSION_H_
|
||||
|
||||
// Versioning is kept in project CMakeLists.txt file
|
||||
#define FSFW_VERSION @FSFW_VERSION@
|
||||
#define FSFW_SUBVERSION @FSFW_SUBVERSION@
|
||||
#define FSFW_REVISION @FSFW_REVISION@
|
||||
// Versioning is managed in project CMakeLists.txt file
|
||||
static constexpr int FSFW_VERSION_MAJOR = @FSFW_VERSION@;
|
||||
static constexpr int FSFW_VERSION_MINOR = @FSFW_SUBVERSION@;
|
||||
static constexpr int FSFW_VERSION_REVISION = @FSFW_REVISION@;
|
||||
// Also contains CST (Commits since tag) information
|
||||
static const char FSFW_VERSION_CST_GIT_SHA1[] = "@FSFW_VERSION_CST_GIT_SHA1@";
|
||||
|
||||
#endif /* FSFW_VERSION_H_ */
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include "fsfw/action/ActionHelper.h"
|
||||
#include "fsfw/action/ActionMessage.h"
|
||||
#include "fsfw/action/CommandActionHelper.h"
|
||||
#include "fsfw/action/HasActionsIF.h"
|
||||
#include "fsfw/action/CommandsActionsIF.h"
|
||||
#include "fsfw/action/HasActionsIF.h"
|
||||
#include "fsfw/action/SimpleActionHelper.h"
|
||||
|
||||
#endif /* FSFW_INC_FSFW_ACTION_H_ */
|
||||
|
@ -1,22 +1,17 @@
|
||||
#include "fsfw/action.h"
|
||||
|
||||
#include "fsfw/ipc/MessageQueueSenderIF.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
ActionHelper::ActionHelper(HasActionsIF* setOwner,
|
||||
MessageQueueIF* useThisQueue) :
|
||||
owner(setOwner), queueToUse(useThisQueue) {
|
||||
}
|
||||
ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue)
|
||||
: owner(setOwner), queueToUse(useThisQueue) {}
|
||||
|
||||
ActionHelper::~ActionHelper() {
|
||||
}
|
||||
ActionHelper::~ActionHelper() {}
|
||||
|
||||
ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) {
|
||||
if (command->getCommand() == ActionMessage::EXECUTE_ACTION) {
|
||||
ActionId_t currentAction = ActionMessage::getActionId(command);
|
||||
prepareExecution(command->getSender(), currentAction,
|
||||
ActionMessage::getStoreId(command));
|
||||
prepareExecution(command->getSender(), currentAction, ActionMessage::getStoreId(command));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return CommandMessage::UNKNOWN_COMMAND;
|
||||
@ -46,8 +41,8 @@ ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo,
|
||||
ActionId_t commandId, ReturnValue_t result) {
|
||||
void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId,
|
||||
ReturnValue_t result) {
|
||||
CommandMessage reply;
|
||||
ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result);
|
||||
queueToUse->sendMessage(reportTo, &reply);
|
||||
@ -60,12 +55,10 @@ void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t co
|
||||
queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
void ActionHelper::setQueueToUse(MessageQueueIF* queue) {
|
||||
queueToUse = queue;
|
||||
}
|
||||
void ActionHelper::setQueueToUse(MessageQueueIF* queue) { queueToUse = queue; }
|
||||
|
||||
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
ActionId_t actionId, store_address_t dataAddress) {
|
||||
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
||||
store_address_t dataAddress) {
|
||||
const uint8_t* dataPtr = NULL;
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
|
||||
@ -90,8 +83,8 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
ActionId_t replyId, SerializeIF* data, bool hideSender) {
|
||||
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t replyId,
|
||||
SerializeIF* data, bool hideSender) {
|
||||
CommandMessage reply;
|
||||
store_address_t storeAddress;
|
||||
uint8_t* dataPtr;
|
||||
@ -101,20 +94,19 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize,
|
||||
&dataPtr);
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize, &dataPtr);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "ActionHelper::reportData: Getting free element from IPC store failed!" <<
|
||||
std::endl;
|
||||
sif::warning << "ActionHelper::reportData: Getting free element from IPC store failed!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("ActionHelper::reportData: Getting free element from IPC "
|
||||
sif::printWarning(
|
||||
"ActionHelper::reportData: Getting free element from IPC "
|
||||
"store failed!\n");
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
result = data->serialize(&dataPtr, &size, maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
result = data->serialize(&dataPtr, &size, maxSize, SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ipcStore->deleteData(storeAddress);
|
||||
return result;
|
||||
@ -128,8 +120,7 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
as unrequested reply, this will be done here. */
|
||||
if (hideSender) {
|
||||
result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
result = queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
@ -139,12 +130,10 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
return result;
|
||||
}
|
||||
|
||||
void ActionHelper::resetHelper() {
|
||||
}
|
||||
void ActionHelper::resetHelper() {}
|
||||
|
||||
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
ActionId_t replyId, const uint8_t *data, size_t dataSize,
|
||||
bool hideSender) {
|
||||
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t replyId,
|
||||
const uint8_t* data, size_t dataSize, bool hideSender) {
|
||||
CommandMessage reply;
|
||||
store_address_t storeAddress;
|
||||
ReturnValue_t result = ipcStore->addData(&storeAddress, data, dataSize);
|
||||
@ -165,8 +154,7 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
|
||||
as unrequested reply, this will be done here. */
|
||||
if (hideSender) {
|
||||
result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
result = queueToUse->sendMessage(reportTo, &reply);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef FSFW_ACTION_ACTIONHELPER_H_
|
||||
#define FSFW_ACTION_ACTIONHELPER_H_
|
||||
|
||||
#include "ActionMessage.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
#include "ActionMessage.h"
|
||||
/**
|
||||
* @brief Action Helper is a helper class which handles action messages
|
||||
*
|
||||
@ -57,8 +57,7 @@ public:
|
||||
* @param commandId ID of the executed command
|
||||
* @param result Result of the execution
|
||||
*/
|
||||
void step(uint8_t step, MessageQueueId_t reportTo,
|
||||
ActionId_t commandId,
|
||||
void step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId,
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
/**
|
||||
* Function to be called by the owner to send a action completion message
|
||||
@ -78,8 +77,8 @@ public:
|
||||
* @param data Pointer to the data
|
||||
* @return Returns RETURN_OK if successful, otherwise failure code
|
||||
*/
|
||||
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
|
||||
SerializeIF* data, bool hideSender = false);
|
||||
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, SerializeIF* data,
|
||||
bool hideSender = false);
|
||||
/**
|
||||
* Function to be called by the owner if an action does report data.
|
||||
* Takes the raw data and writes it into the IPC store.
|
||||
@ -89,8 +88,8 @@ public:
|
||||
* @param data Pointer to the data
|
||||
* @return Returns RETURN_OK if successful, otherwise failure code
|
||||
*/
|
||||
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
|
||||
const uint8_t* data, size_t dataSize, bool hideSender = false);
|
||||
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, const uint8_t* data,
|
||||
size_t dataSize, bool hideSender = false);
|
||||
/**
|
||||
* Function to setup the MessageQueueIF* of the helper. Can be used to
|
||||
* set the MessageQueueIF* if message queue is unavailable at construction
|
||||
@ -98,6 +97,7 @@ public:
|
||||
* @param queue Queue to be used by the helper
|
||||
*/
|
||||
void setQueueToUse(MessageQueueIF* queue);
|
||||
|
||||
protected:
|
||||
//! Increase of value of this per step
|
||||
static const uint8_t STEP_OFFSET = 1;
|
||||
@ -115,8 +115,8 @@ protected:
|
||||
* @param actionId ID of action to be done
|
||||
* @param dataAddress Address of additional data in IPC Store
|
||||
*/
|
||||
virtual void prepareExecution(MessageQueueId_t commandedBy,
|
||||
ActionId_t actionId, store_address_t dataAddress);
|
||||
virtual void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
||||
store_address_t dataAddress);
|
||||
/**
|
||||
* @brief Default implementation is empty.
|
||||
*/
|
||||
|
@ -1,13 +1,10 @@
|
||||
#include "fsfw/action.h"
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||
|
||||
ActionMessage::ActionMessage() {
|
||||
}
|
||||
ActionMessage::ActionMessage() {}
|
||||
|
||||
ActionMessage::~ActionMessage() {
|
||||
}
|
||||
ActionMessage::~ActionMessage() {}
|
||||
|
||||
void ActionMessage::setCommand(CommandMessage* message, ActionId_t fid,
|
||||
store_address_t parameters) {
|
||||
@ -52,12 +49,11 @@ void ActionMessage::setDataReply(CommandMessage* message, ActionId_t actionId,
|
||||
message->setParameter2(data.raw);
|
||||
}
|
||||
|
||||
void ActionMessage::setCompletionReply(CommandMessage* message,
|
||||
ActionId_t fid, bool success, ReturnValue_t result) {
|
||||
void ActionMessage::setCompletionReply(CommandMessage* message, ActionId_t fid, bool success,
|
||||
ReturnValue_t result) {
|
||||
if (success) {
|
||||
message->setCommand(COMPLETION_SUCCESS);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message->setCommand(COMPLETION_FAILED);
|
||||
}
|
||||
message->setParameter(fid);
|
||||
@ -68,8 +64,8 @@ void ActionMessage::clear(CommandMessage* message) {
|
||||
switch (message->getCommand()) {
|
||||
case EXECUTE_ACTION:
|
||||
case DATA_REPLY: {
|
||||
StorageManagerIF *ipcStore = ObjectManager::instance()->get<StorageManagerIF>(
|
||||
objects::IPC_STORE);
|
||||
StorageManagerIF* ipcStore =
|
||||
ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore != NULL) {
|
||||
ipcStore->deleteData(getStoreId(message));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ using ActionId_t = uint32_t;
|
||||
class ActionMessage {
|
||||
private:
|
||||
ActionMessage();
|
||||
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = messagetypes::ACTION;
|
||||
static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1);
|
||||
@ -26,20 +27,18 @@ public:
|
||||
static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(6);
|
||||
|
||||
virtual ~ActionMessage();
|
||||
static void setCommand(CommandMessage* message, ActionId_t fid,
|
||||
store_address_t parameters);
|
||||
static void setCommand(CommandMessage* message, ActionId_t fid, store_address_t parameters);
|
||||
|
||||
static ActionId_t getActionId(const CommandMessage* message);
|
||||
static store_address_t getStoreId(const CommandMessage* message);
|
||||
|
||||
static void setStepReply(CommandMessage* message, ActionId_t fid,
|
||||
uint8_t step, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
static void setStepReply(CommandMessage* message, ActionId_t fid, uint8_t step,
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
static uint8_t getStep(const CommandMessage* message);
|
||||
static ReturnValue_t getReturnCode(const CommandMessage* message);
|
||||
static void setDataReply(CommandMessage* message, ActionId_t actionId,
|
||||
store_address_t data);
|
||||
static void setCompletionReply(CommandMessage* message, ActionId_t fid,
|
||||
bool success, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
static void setDataReply(CommandMessage* message, ActionId_t actionId, store_address_t data);
|
||||
static void setCompletionReply(CommandMessage* message, ActionId_t fid, bool success,
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
|
||||
|
||||
static void clear(CommandMessage* message);
|
||||
};
|
||||
|
@ -1,17 +1,13 @@
|
||||
#include "fsfw/action.h"
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
|
||||
CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner) :
|
||||
owner(setOwner), queueToUse(NULL), ipcStore(
|
||||
NULL), commandCount(0), lastTarget(0) {
|
||||
}
|
||||
CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner)
|
||||
: owner(setOwner), queueToUse(NULL), ipcStore(NULL), commandCount(0), lastTarget(0) {}
|
||||
|
||||
CommandActionHelper::~CommandActionHelper() {
|
||||
}
|
||||
CommandActionHelper::~CommandActionHelper() {}
|
||||
|
||||
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, SerializeIF *data) {
|
||||
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, ActionId_t actionId,
|
||||
SerializeIF *data) {
|
||||
HasActionsIF *receiver = ObjectManager::instance()->get<HasActionsIF>(commandTo);
|
||||
if (receiver == NULL) {
|
||||
return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS;
|
||||
@ -19,22 +15,20 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
|
||||
store_address_t storeId;
|
||||
uint8_t *storePointer;
|
||||
size_t maxSize = data->getSerializedSize();
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize,
|
||||
&storePointer);
|
||||
ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize, &storePointer);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
size_t size = 0;
|
||||
result = data->serialize(&storePointer, &size, maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
result = data->serialize(&storePointer, &size, maxSize, SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return sendCommand(receiver->getCommandQueue(), actionId, storeId);
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, const uint8_t *data, uint32_t size) {
|
||||
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, ActionId_t actionId,
|
||||
const uint8_t *data, uint32_t size) {
|
||||
// if (commandCount != 0) {
|
||||
// return CommandsFunctionsIF::ALREADY_COMMANDING;
|
||||
// }
|
||||
@ -50,8 +44,8 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
|
||||
return sendCommand(receiver->getCommandQueue(), actionId, storeId);
|
||||
}
|
||||
|
||||
ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId,
|
||||
ActionId_t actionId, store_address_t storeId) {
|
||||
ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId, ActionId_t actionId,
|
||||
store_address_t storeId) {
|
||||
CommandMessage command;
|
||||
ActionMessage::setCommand(&command, actionId, storeId);
|
||||
ReturnValue_t result = queueToUse->sendMessage(queueId, &command);
|
||||
@ -96,22 +90,18 @@ ReturnValue_t CommandActionHelper::handleReply(CommandMessage *reply) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case ActionMessage::STEP_FAILED:
|
||||
commandCount--;
|
||||
owner->stepFailedReceived(ActionMessage::getActionId(reply),
|
||||
ActionMessage::getStep(reply),
|
||||
owner->stepFailedReceived(ActionMessage::getActionId(reply), ActionMessage::getStep(reply),
|
||||
ActionMessage::getReturnCode(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
case ActionMessage::DATA_REPLY:
|
||||
extractDataForOwner(ActionMessage::getActionId(reply),
|
||||
ActionMessage::getStoreId(reply));
|
||||
extractDataForOwner(ActionMessage::getActionId(reply), ActionMessage::getStoreId(reply));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CommandActionHelper::getCommandCount() const {
|
||||
return commandCount;
|
||||
}
|
||||
uint8_t CommandActionHelper::getCommandCount() const { return commandCount; }
|
||||
|
||||
void CommandActionHelper::extractDataForOwner(ActionId_t actionId, store_address_t storeId) {
|
||||
const uint8_t *data = NULL;
|
||||
|
@ -2,26 +2,27 @@
|
||||
#define COMMANDACTIONHELPER_H_
|
||||
|
||||
#include "ActionMessage.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/objectmanager/ObjectManagerIF.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
|
||||
class CommandsActionsIF;
|
||||
|
||||
class CommandActionHelper {
|
||||
friend class CommandsActionsIF;
|
||||
|
||||
public:
|
||||
CommandActionHelper(CommandsActionsIF* owner);
|
||||
virtual ~CommandActionHelper();
|
||||
ReturnValue_t commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, const uint8_t* data, uint32_t size);
|
||||
ReturnValue_t commandAction(object_id_t commandTo,
|
||||
ActionId_t actionId, SerializeIF* data);
|
||||
ReturnValue_t commandAction(object_id_t commandTo, ActionId_t actionId,
|
||||
const uint8_t* data = nullptr, uint32_t size = 0);
|
||||
ReturnValue_t commandAction(object_id_t commandTo, ActionId_t actionId, SerializeIF* data);
|
||||
ReturnValue_t initialize();
|
||||
ReturnValue_t handleReply(CommandMessage* reply);
|
||||
uint8_t getCommandCount() const;
|
||||
|
||||
private:
|
||||
CommandsActionsIF* owner;
|
||||
MessageQueueIF* queueToUse;
|
||||
@ -29,8 +30,7 @@ private:
|
||||
uint8_t commandCount;
|
||||
MessageQueueId_t lastTarget;
|
||||
void extractDataForOwner(ActionId_t actionId, store_address_t storeId);
|
||||
ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId,
|
||||
store_address_t storeId);
|
||||
ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId, store_address_t storeId);
|
||||
};
|
||||
|
||||
#endif /* COMMANDACTIONHELPER_H_ */
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef FSFW_ACTION_COMMANDSACTIONSIF_H_
|
||||
#define FSFW_ACTION_COMMANDSACTIONSIF_H_
|
||||
|
||||
#include "CommandActionHelper.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "CommandActionHelper.h"
|
||||
|
||||
/**
|
||||
* Interface to separate commanding actions of other objects.
|
||||
@ -16,22 +16,20 @@
|
||||
*/
|
||||
class CommandsActionsIF {
|
||||
friend class CommandActionHelper;
|
||||
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::COMMANDS_ACTIONS_IF;
|
||||
static const ReturnValue_t OBJECT_HAS_NO_FUNCTIONS = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t ALREADY_COMMANDING = MAKE_RETURN_CODE(2);
|
||||
virtual ~CommandsActionsIF() {}
|
||||
virtual MessageQueueIF* getCommandQueuePtr() = 0;
|
||||
|
||||
protected:
|
||||
virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) = 0;
|
||||
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step,
|
||||
ReturnValue_t returnCode) = 0;
|
||||
virtual void dataReceived(ActionId_t actionId, const uint8_t* data,
|
||||
uint32_t size) = 0;
|
||||
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) = 0;
|
||||
virtual void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) = 0;
|
||||
virtual void completionSuccessfulReceived(ActionId_t actionId) = 0;
|
||||
virtual void completionFailedReceived(ActionId_t actionId,
|
||||
ReturnValue_t returnCode) = 0;
|
||||
virtual void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_ACTION_COMMANDSACTIONSIF_H_ */
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef FSFW_ACTION_HASACTIONSIF_H_
|
||||
#define FSFW_ACTION_HASACTIONSIF_H_
|
||||
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "ActionHelper.h"
|
||||
#include "ActionMessage.h"
|
||||
#include "SimpleActionHelper.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
|
||||
/**
|
||||
* @brief
|
||||
@ -55,9 +55,8 @@ public:
|
||||
* -@c EXECUTION_FINISHED Finish reply will be generated
|
||||
* -@c Not RETURN_OK Step failure reply will be generated
|
||||
*/
|
||||
virtual ReturnValue_t executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size) = 0;
|
||||
virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_ACTION_HASACTIONSIF_H_ */
|
||||
|
@ -1,18 +1,14 @@
|
||||
#include "fsfw/action.h"
|
||||
|
||||
SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner,
|
||||
MessageQueueIF* useThisQueue) :
|
||||
ActionHelper(setOwner, useThisQueue), isExecuting(false) {
|
||||
}
|
||||
SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue)
|
||||
: ActionHelper(setOwner, useThisQueue), isExecuting(false) {}
|
||||
|
||||
SimpleActionHelper::~SimpleActionHelper() {
|
||||
}
|
||||
SimpleActionHelper::~SimpleActionHelper() {}
|
||||
|
||||
void SimpleActionHelper::step(ReturnValue_t result) {
|
||||
// STEP_OFFESET is subtracted to compensate for adding offset in base
|
||||
// method, which is not necessary here.
|
||||
ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction,
|
||||
result);
|
||||
ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction, result);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
resetHelper();
|
||||
}
|
||||
@ -34,13 +30,12 @@ void SimpleActionHelper::resetHelper() {
|
||||
lastCommander = 0;
|
||||
}
|
||||
|
||||
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
ActionId_t actionId, store_address_t dataAddress) {
|
||||
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
||||
store_address_t dataAddress) {
|
||||
CommandMessage reply;
|
||||
if (isExecuting) {
|
||||
ipcStore->deleteData(dataAddress);
|
||||
ActionMessage::setStepReply(&reply, actionId, 0,
|
||||
HasActionsIF::IS_BUSY);
|
||||
ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::IS_BUSY);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
}
|
||||
const uint8_t* dataPtr = NULL;
|
||||
@ -61,8 +56,7 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
stepCount++;
|
||||
break;
|
||||
case HasActionsIF::EXECUTION_FINISHED:
|
||||
ActionMessage::setCompletionReply(&reply, actionId,
|
||||
true, HasReturnvaluesIF::RETURN_OK);
|
||||
ActionMessage::setCompletionReply(&reply, actionId, true, HasReturnvaluesIF::RETURN_OK);
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
break;
|
||||
default:
|
||||
@ -70,5 +64,4 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
||||
queueToUse->sendMessage(commandedBy, &reply);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ protected:
|
||||
void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
||||
store_address_t dataAddress);
|
||||
virtual void resetHelper();
|
||||
|
||||
private:
|
||||
bool isExecuting;
|
||||
MessageQueueId_t lastCommander = MessageQueueIF::NO_QUEUE;
|
||||
|
59
src/fsfw/cfdp/CFDPHandler.cpp
Normal file
59
src/fsfw/cfdp/CFDPHandler.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "fsfw/cfdp/CFDPHandler.h"
|
||||
|
||||
#include "fsfw/cfdp/CFDPMessage.h"
|
||||
#include "fsfw/ipc/CommandMessage.h"
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/storagemanager/storeAddress.h"
|
||||
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
||||
|
||||
object_id_t CFDPHandler::packetSource = 0;
|
||||
object_id_t CFDPHandler::packetDestination = 0;
|
||||
|
||||
CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist)
|
||||
: SystemObject(setObjectId) {
|
||||
auto mqArgs = MqArgs(setObjectId, static_cast<void*>(this));
|
||||
requestQueue = QueueFactory::instance()->createMessageQueue(
|
||||
CFDP_HANDLER_MAX_RECEPTION, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
||||
distributor = dist;
|
||||
}
|
||||
|
||||
CFDPHandler::~CFDPHandler() {}
|
||||
|
||||
ReturnValue_t CFDPHandler::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->distributor->registerHandler(this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPHandler::handleRequest(store_address_t storeId) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "CFDPHandler::handleRequest" << std::endl;
|
||||
#else
|
||||
sif::printDebug("CFDPHandler::handleRequest\n");
|
||||
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif
|
||||
|
||||
// TODO read out packet from store using storeId
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPHandler::performOperation(uint8_t opCode) {
|
||||
ReturnValue_t status = RETURN_OK;
|
||||
CommandMessage currentMessage;
|
||||
for (status = this->requestQueue->receiveMessage(¤tMessage); status == RETURN_OK;
|
||||
status = this->requestQueue->receiveMessage(¤tMessage)) {
|
||||
store_address_t storeId = CFDPMessage::getStoreId(¤tMessage);
|
||||
this->handleRequest(storeId);
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uint16_t CFDPHandler::getIdentifier() { return 0; }
|
||||
|
||||
MessageQueueId_t CFDPHandler::getRequestQueue() { return this->requestQueue->getId(); }
|
63
src/fsfw/cfdp/CFDPHandler.h
Normal file
63
src/fsfw/cfdp/CFDPHandler.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef FSFW_CFDP_CFDPHANDLER_H_
|
||||
#define FSFW_CFDP_CFDPHANDLER_H_
|
||||
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw/tcdistribution/CFDPDistributor.h"
|
||||
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
|
||||
|
||||
namespace Factory {
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
class CFDPHandler : public ExecutableObjectIF,
|
||||
public AcceptsTelecommandsIF,
|
||||
public SystemObject,
|
||||
public HasReturnvaluesIF {
|
||||
friend void(Factory::setStaticFrameworkObjectIds)();
|
||||
|
||||
public:
|
||||
CFDPHandler(object_id_t setObjectId, CFDPDistributor* distributor);
|
||||
/**
|
||||
* The destructor is empty.
|
||||
*/
|
||||
virtual ~CFDPHandler();
|
||||
|
||||
virtual ReturnValue_t handleRequest(store_address_t storeId);
|
||||
|
||||
virtual ReturnValue_t initialize() override;
|
||||
virtual uint16_t getIdentifier() override;
|
||||
MessageQueueId_t getRequestQueue() override;
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This is a complete instance of the telecommand reception queue
|
||||
* of the class. It is initialized on construction of the class.
|
||||
*/
|
||||
MessageQueueIF* requestQueue = nullptr;
|
||||
|
||||
CFDPDistributor* distributor = nullptr;
|
||||
|
||||
/**
|
||||
* The current CFDP packet to be processed.
|
||||
* It is deleted after handleRequest was executed.
|
||||
*/
|
||||
CFDPPacketStored currentPacket;
|
||||
|
||||
static object_id_t packetSource;
|
||||
|
||||
static object_id_t packetDestination;
|
||||
|
||||
private:
|
||||
/**
|
||||
* This constant sets the maximum number of packets accepted per call.
|
||||
* Remember that one packet must be completely handled in one
|
||||
* #handleRequest call.
|
||||
*/
|
||||
static const uint8_t CFDP_HANDLER_MAX_RECEPTION = 100;
|
||||
};
|
||||
|
||||
#endif /* FSFW_CFDP_CFDPHANDLER_H_ */
|
17
src/fsfw/cfdp/CFDPMessage.cpp
Normal file
17
src/fsfw/cfdp/CFDPMessage.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "CFDPMessage.h"
|
||||
|
||||
CFDPMessage::CFDPMessage() {}
|
||||
|
||||
CFDPMessage::~CFDPMessage() {}
|
||||
|
||||
void CFDPMessage::setCommand(CommandMessage *message, store_address_t cfdpPacket) {
|
||||
message->setParameter(cfdpPacket.raw);
|
||||
}
|
||||
|
||||
store_address_t CFDPMessage::getStoreId(const CommandMessage *message) {
|
||||
store_address_t storeAddressCFDPPacket;
|
||||
storeAddressCFDPPacket = message->getParameter();
|
||||
return storeAddressCFDPPacket;
|
||||
}
|
||||
|
||||
void CFDPMessage::clear(CommandMessage *message) {}
|
23
src/fsfw/cfdp/CFDPMessage.h
Normal file
23
src/fsfw/cfdp/CFDPMessage.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef FSFW_CFDP_CFDPMESSAGE_H_
|
||||
#define FSFW_CFDP_CFDPMESSAGE_H_
|
||||
|
||||
#include "fsfw/ipc/CommandMessage.h"
|
||||
#include "fsfw/objectmanager/ObjectManagerIF.h"
|
||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||
|
||||
class CFDPMessage {
|
||||
private:
|
||||
CFDPMessage();
|
||||
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = messagetypes::CFDP;
|
||||
|
||||
virtual ~CFDPMessage();
|
||||
static void setCommand(CommandMessage* message, store_address_t cfdpPacket);
|
||||
|
||||
static store_address_t getStoreId(const CommandMessage* message);
|
||||
|
||||
static void clear(CommandMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FSFW_CFDP_CFDPMESSAGE_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user