rng90 1.0
rng90 driver library
Loading...
Searching...
No Matches
rng90.h
Go to the documentation of this file.
1
18
19#ifndef RNG90_H_
20#define RNG90_H_
21
22 #ifndef RNG90_HAL_PLATFORM
34 #define RNG90_HAL_PLATFORM avr0
35 #endif
36
37 #ifndef RNG90_ADDRESS
47 #define RNG90_ADDRESS 0x40
48 #endif
49
50 #ifndef RNG90_RESET_COMMAND
60 #define RNG90_RESET_COMMAND 0x00
61 #endif
62
63 #ifndef RNG90_SLEEP_COMMAND1
74 #define RNG90_SLEEP_COMMAND1 0x01
75 #endif
76
77 #ifndef RNG90_SLEEP_COMMAND2
87 #define RNG90_SLEEP_COMMAND2 0x02
88 #endif
89
90 #ifndef RNG90_EXECUTE_COMMAND
100 #define RNG90_EXECUTE_COMMAND 0x03
101 #endif
102
103 #ifndef RNG90_OPERATION_INFO
113 #define RNG90_OPERATION_INFO 0x30
114
115 #ifndef RNG90_OPERATION_INFO_PARAM1
125 #define RNG90_OPERATION_INFO_PARAM1 0x00
126 #endif
127
128 #ifndef RNG90_OPERATION_INFO_PARAM2
138 #define RNG90_OPERATION_INFO_PARAM2 0x0000
139 #endif
140 #endif
141
142 #ifndef RNG90_OPERATION_RANDOM
152 #define RNG90_OPERATION_RANDOM 0x16
153
154 #ifndef RNG90_OPERATION_RANDOM_PARAM1
164 #define RNG90_OPERATION_RANDOM_PARAM1 0x00
165 #endif
166
167 #ifndef RNG90_OPERATION_RANDOM_PARAM2
177 #define RNG90_OPERATION_RANDOM_PARAM2 0x0000
178 #endif
179
180 #ifndef RNG90_OPERATION_RANDOM_DATA_SIZE
190 #define RNG90_OPERATION_RANDOM_DATA_SIZE 20UL
191
192 #ifndef RNG90_OPERATION_RANDOM_DATA
202 #define RNG90_OPERATION_RANDOM_DATA 0x00
203 #endif
204 #endif
205
206 #ifndef RNG90_OPERATION_RANDOM_RNG_SIZE
216 #define RNG90_OPERATION_RANDOM_RNG_SIZE 32UL
217 #endif
218 #endif
219
220 #ifndef RNG90_OPERATION_READ
230 #define RNG90_OPERATION_READ 0x02
231
232 #ifndef RNG90_OPERATION_READ_PARAM1
242 #define RNG90_OPERATION_READ_PARAM1 0x01
243 #endif
244
245 #ifndef RNG90_OPERATION_READ_PARAM2
255 #define RNG90_OPERATION_READ_PARAM2 0x0000
256 #endif
257
258 #ifndef RNG90_OPERATION_READ_DATA_SIZE
268 #define RNG90_OPERATION_READ_DATA_SIZE 16UL
269 #endif
270
271 #ifndef RNG90_OPERATION_READ_SERIAL_SIZE
281 #define RNG90_OPERATION_READ_SERIAL_SIZE 8UL
282 #endif
283 #endif
284
285 #ifndef RNG90_OPERATION_SELF_TEST
295 #define RNG90_OPERATION_SELF_TEST 0x77
296
297 #ifndef RNG90_OPERATION_SELF_TEST_PARAM1_READ
307 #define RNG90_OPERATION_SELF_TEST_PARAM1_READ 0x00
308 #endif
309
310 #ifndef RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG
320 #define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG 0x01
321 #endif
322
323 #ifndef RNG90_OPERATION_SELF_TEST_PARAM1_RUN_SHA256
333 #define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_SHA256 0x20
334 #endif
335
336 #ifndef RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG_AND_SHA256
348 #define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG_AND_SHA256 0x21
349 #endif
350
351 #ifndef RNG90_OPERATION_SELF_TEST_PARAM2
364 #define RNG90_OPERATION_SELF_TEST_PARAM2 0x0000
365 #endif
366 #endif
367
368 #ifndef RNG90_NEW_BUS_TRANSMISSION_US
378 #define RNG90_NEW_BUS_TRANSMISSION_US 2UL
379 #endif
380
381 #ifndef RNG90_STATUS_SUCCESSFUL_COMMAND_EXECUTION
391 #define RNG90_STATUS_SUCCESSFUL_COMMAND_EXECUTION 0x00
392 #endif
393
394 #ifndef RNG90_STATUS_PARSE_ERROR
404 #define RNG90_STATUS_PARSE_ERROR 0x03
405 #endif
406
407 #ifndef RNG90_STATUS_SELF_TEST_ERROR
417 #define RNG90_STATUS_SELF_TEST_ERROR 0x07
418 #endif
419
420 #ifndef RNG90_STATUS_HEALTH_TEST_ERROR
430 #define RNG90_STATUS_HEALTH_TEST_ERROR 0x08
431 #endif
432
433 #ifndef RNG90_STATUS_EXECUTION_ERROR
443 #define RNG90_STATUS_EXECUTION_ERROR 0x0F
444 #endif
445
446 #ifndef RNG90_STATUS_AFTER_WAKE
456 #define RNG90_STATUS_AFTER_WAKE 0x11
457 #endif
458
459 #ifndef RNG90_STATUS_TWI_ERROR
469 #define RNG90_STATUS_TWI_ERROR 0xF0
470 #endif
471
472 #ifndef RNG90_STATUS_CRC_OR_COMMUNICATION_ERROR
482 #define RNG90_STATUS_CRC_OR_COMMUNICATION_ERROR 0xFF
483 #endif
484
485 #ifndef RNG90_SELFTEST_STATUS_PASSED_SUCCESSFULLY
495 #define RNG90_SELFTEST_STATUS_PASSED_SUCCESSFULLY 0x00
496 #endif
497
498 #ifndef RNG90_SELFTEST_STATUS_DRBG_SELFTEST_FAIL
508 #define RNG90_SELFTEST_STATUS_DRBG_SELFTEST_FAIL 0x01
509 #endif
510
511 #ifndef RNG90_SELFTEST_STATUS_SHA256_SELFTEST_FAIL
521 #define RNG90_SELFTEST_STATUS_SHA256_SELFTEST_FAIL 0x20
522 #endif
523
524 #ifndef RNG90_SELFTEST_STATUS_DRBG_SHA256_SELFTEST_FAIL
534 #define RNG90_SELFTEST_STATUS_DRBG_SHA256_SELFTEST_FAIL 0x21
535 #endif
536
537 #ifndef RNG90_SELFTEST_STATUS_DRBG_SELFTEST_NOT_RUN
547 #define RNG90_SELFTEST_STATUS_DRBG_SELFTEST_NOT_RUN 0x02
548 #endif
549
550 #ifndef RNG90_SELFTEST_STATUS_SHA256_SELFTEST_NOT_RUN
560 #define RNG90_SELFTEST_STATUS_SHA256_SELFTEST_NOT_RUN 0x10
561 #endif
562
563 #ifndef RNG90_SELFTEST_STATUS_NEITHER_SELFTEST_NOT_RUN
573 #define RNG90_SELFTEST_STATUS_NEITHER_SELFTEST_NOT_RUN 0x12
574 #endif
575
576 #ifndef RNG90_SELFTEST_STATUS_ERROR
586 #define RNG90_SELFTEST_STATUS_ERROR 0xFF
587 #endif
588
589 #ifndef RNG90_INFO_EXECUTION_TIME_MS
599 #define RNG90_INFO_EXECUTION_TIME_MS 1UL
600 #endif
601
602 #ifndef RNG90_RANDOM_EXECUTION_TIME_MS
612 #define RNG90_RANDOM_EXECUTION_TIME_MS 75UL
613 #endif
614
615 #ifndef RNG90_READ_EXECUTION_TIME_MS
625 #define RNG90_READ_EXECUTION_TIME_MS 1UL
626 #endif
627
628 #ifndef RNG90_SELFTEST_EXECUTION_TIME_MS
638 #define RNG90_SELFTEST_EXECUTION_TIME_MS 32UL
639 #endif
640
641 #ifndef RNG90_WDT_RESET_TIME_MS
651 #define RNG90_WDT_RESET_TIME_MS 1300UL
652 #endif
653
654 #ifndef RNG90_CRC_POLYNOMIAL
664 #define RNG90_CRC_POLYNOMIAL 0x8005
665 #endif
666
667 #ifndef RNG90_CRC_SIZE
677 #define RNG90_CRC_SIZE 2UL
678 #endif
679
680 #ifndef RNG90_STANDARD_FRAME_SIZE
690 #define RNG90_STANDARD_FRAME_SIZE 4UL
691 #endif
692
693 #ifndef RNG90_INFO_FRAME_SIZE
703 #define RNG90_INFO_FRAME_SIZE 7UL
704 #endif
705
706 #ifndef RNG90_NUMBER_FRAME_SIZE
716 #define RNG90_NUMBER_FRAME_SIZE 35UL
717 #endif
718
719 #ifndef RNG90_SERIAL_FRAME_SIZE
729 #define RNG90_SERIAL_FRAME_SIZE 19UL
730 #endif
731
733
734 #include _STR(../../../hal/RNG90_HAL_PLATFORM/twi/twi.h)
735
738
757
763
777
783
806
812
821 {
822 unsigned char RFU;
823 unsigned char DeviceID;
824 unsigned char SiliconID;
825 unsigned char Revision;
826 };
827
832 typedef struct RNG90_Info_t RNG90_Info;
833
842 {
843 unsigned char count;
844 unsigned char opcode;
845 unsigned char param1;
846 unsigned int param2;
847 unsigned int crc;
848 };
849
855
868
874
883 {
884 unsigned char length;
886 };
887
893
897 RNG90_Status rng90_random(unsigned char *numbers);
898 RNG90_Status rng90_serial(unsigned char *serial);
899
900#endif /* RNG90_H_ */
Header file with declarations and macros for CRC16 checksum calculation.
#define RNG90_SELFTEST_STATUS_DRBG_SELFTEST_FAIL
Defines the self-test status code indicating the DRBG self-test failed on the RNG90 device.
Definition rng90.h:508
RNG90_Run_SelfTest_t
Selects which self-test routine to run on the RNG90 device.
Definition rng90.h:772
@ RNG90_Run_SHA256_SelfTest
Definition rng90.h:774
@ RNG90_Run_DBRG_SHA256_SelfTest
Definition rng90.h:775
@ RNG90_Run_DRBG_SelfTest
Definition rng90.h:773
RNG90_Status rng90_init(void)
#define RNG90_STATUS_TWI_ERROR
Defines the status code for a TWI/I2C communication error with the RNG90 device.
Definition rng90.h:469
enum RNG90_Run_SelfTest_t RNG90_Run_SelfTest
Alias for enum RNG90_Run_SelfTest_t representing RNG90 self-test selections.
Definition rng90.h:782
enum RNG90_SelfTest_Status_t RNG90_SelfTest_Status
Alias for enum RNG90_SelfTest_Status_t representing RNG90 self-test result codes.
Definition rng90.h:811
struct RNG90_Packet_t RNG90_Packet
Alias for struct RNG90_Packet_t representing an RNG90 packet.
Definition rng90.h:854
#define RNG90_SELFTEST_STATUS_DRBG_SELFTEST_NOT_RUN
Defines the self-test status code indicating the DRBG self-test was not run on the RNG90 device.
Definition rng90.h:547
struct RNG90_Info_t RNG90_Info
Alias for struct RNG90_Info_t representing RNG90 device information.
Definition rng90.h:832
RNG90_Status_t
Represents status codes returned by the RNG90 device.
Definition rng90.h:747
@ RNG90_Status_Success
Definition rng90.h:748
@ RNG90_Status_Execution_Error
Definition rng90.h:752
@ RNG90_Status_AfterWake_Indication
Definition rng90.h:753
@ RNG90_Status_HealthTest_Error
Definition rng90.h:751
@ RNG90_Status_SelfTest_Error
Definition rng90.h:750
@ RNG90_Status_Parse_Error
Definition rng90.h:749
@ RNG90_Status_Other_Error
Definition rng90.h:755
@ RNG90_Status_TWI_Error
Definition rng90.h:754
RNG90_Data_Status_t
Indicates whether received RNG90 data is valid.
Definition rng90.h:864
@ RNG90_Data_Status_Invalid
Definition rng90.h:866
@ RNG90_Data_Status_Valid
Definition rng90.h:865
#define RNG90_STATUS_EXECUTION_ERROR
Defines the status code for an execution error on the RNG90 device.
Definition rng90.h:443
enum RNG90_Data_Status_t RNG90_Data_Status
Alias for enum RNG90_Data_Status_t representing RNG90 data validity status.
Definition rng90.h:873
enum RNG90_Status_t RNG90_Status
Alias for enum RNG90_Status_t representing RNG90 status codes.
Definition rng90.h:762
#define RNG90_STATUS_CRC_OR_COMMUNICATION_ERROR
Defines the status code for a CRC or communication error with the RNG90 device.
Definition rng90.h:482
#define RNG90_SELFTEST_STATUS_NEITHER_SELFTEST_NOT_RUN
Defines the self-test status code indicating neither DRBG nor SHA-256 self-tests were run on the RNG9...
Definition rng90.h:573
#define RNG90_STATUS_PARSE_ERROR
Defines the status code for a parse error on the RNG90 device.
Definition rng90.h:404
#define RNG90_STATUS_HEALTH_TEST_ERROR
Defines the status code for a health test error on the RNG90 device.
Definition rng90.h:430
RNG90_Status rng90_info(RNG90_Info *info)
Requests device information from the RNG90 and fills an info structure.
Definition rng90.c:178
struct RNG90_Frame_t RNG90_Frame
Alias for struct RNG90_Frame_t representing an RNG90 data frame.
Definition rng90.h:892
#define RNG90_STATUS_SUCCESSFUL_COMMAND_EXECUTION
Defines the status code for a successfully executed command on the RNG90 device.
Definition rng90.h:391
#define RNG90_SELFTEST_STATUS_ERROR
Defines the self-test status code indicating an error occurred during self-testing on the RNG90 devic...
Definition rng90.h:586
#define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG
Parameter for running the DRBG self-test on the RNG90 device.
Definition rng90.h:320
#define RNG90_STATUS_SELF_TEST_ERROR
Defines the status code for a self-test error on the RNG90 device.
Definition rng90.h:417
#define RNG90_SELFTEST_STATUS_SHA256_SELFTEST_NOT_RUN
Defines the self-test status code indicating the SHA-256 self-test was not run on the RNG90 device.
Definition rng90.h:560
RNG90_SelfTest_Status_t
Represents the result status of self-test routines on the RNG90 device.
Definition rng90.h:796
@ RNG90_SelfTest_Error
Definition rng90.h:804
@ RNG90_SelfTest_Fail_DBRG
Definition rng90.h:798
@ RNG90_SelfTest_Success
Definition rng90.h:797
@ RNG90_SelfTest_Not_Run_SHA256
Definition rng90.h:800
@ RNG90_SelfTest_Fail_SHA256
Definition rng90.h:802
@ RNG90_SelfTest_Fail_DBRG_SHA256
Definition rng90.h:803
@ RNG90_SelfTest_Not_Run_Neither
Definition rng90.h:801
@ RNG90_SelfTest_Not_Run_DBRG
Definition rng90.h:799
#define RNG90_STATUS_AFTER_WAKE
Defines the status code indicating the RNG90 device has just woken up from sleep mode.
Definition rng90.h:456
RNG90_Status rng90_serial(unsigned char *serial)
Reads the device serial number from the RNG90 and stores it in a buffer.
Definition rng90.c:285
#define RNG90_SELFTEST_STATUS_SHA256_SELFTEST_FAIL
Defines the self-test status code indicating the SHA-256 self-test failed on the RNG90 device.
Definition rng90.h:521
RNG90_SelfTest_Status rng90_selftest(RNG90_Run_SelfTest test)
Initializes the RNG90 device by running a self-test.
Definition rng90.c:136
RNG90_Status rng90_random(unsigned char *numbers)
Requests random numbers from the RNG90 device and stores them in a buffer.
Definition rng90.c:224
#define RNG90_SELFTEST_STATUS_PASSED_SUCCESSFULLY
Defines the self-test status code indicating all tests passed successfully on the RNG90 device.
Definition rng90.h:495
#define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_SHA256
Parameter for running the SHA-256 self-test on the RNG90 device.
Definition rng90.h:333
#define RNG90_SELFTEST_STATUS_DRBG_SHA256_SELFTEST_FAIL
Defines the self-test status code indicating both DRBG and SHA-256 self-tests failed on the RNG90 dev...
Definition rng90.h:534
#define RNG90_OPERATION_SELF_TEST_PARAM1_RUN_DRBG_AND_SHA256
Parameter for running both DRBG and SHA-256 self-tests on the RNG90 device.
Definition rng90.h:348
Helper macros for stringification in C preprocessor.
Describes a processed data frame received from the RNG90 device.
Definition rng90.h:883
unsigned char length
Definition rng90.h:884
RNG90_Data_Status status
Definition rng90.h:885
Holds basic identification and revision information for the RNG90 device.
Definition rng90.h:821
unsigned char Revision
Definition rng90.h:825
unsigned char DeviceID
Definition rng90.h:823
unsigned char RFU
Definition rng90.h:822
unsigned char SiliconID
Definition rng90.h:824
Represents a generic command or response packet for the RNG90 device.
Definition rng90.h:842
unsigned int crc
Definition rng90.h:847
unsigned char opcode
Definition rng90.h:844
unsigned char param1
Definition rng90.h:845
unsigned char count
Definition rng90.h:843
unsigned int param2
Definition rng90.h:846
Header file with declarations and macros for systick utility.