├── .codecov.yml ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── checks.yml │ └── compile.yml ├── .gitignore ├── .gitmodules ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Inc ├── base64.h ├── bit_manipulation.h ├── crc │ ├── crc16_base.h │ ├── crc16_variants │ │ ├── crc16_a.h │ │ ├── crc16_arc.h │ │ ├── crc16_aug_ccit.h │ │ ├── crc16_buypass.h │ │ ├── crc16_ccit_false.h │ │ ├── crc16_ccit_zero.h │ │ ├── crc16_cdma2000.h │ │ ├── crc16_dds110.h │ │ ├── crc16_dect_r.h │ │ ├── crc16_dect_x.h │ │ ├── crc16_dnp.h │ │ ├── crc16_en_13757.h │ │ ├── crc16_genibus.h │ │ ├── crc16_kermit.h │ │ ├── crc16_maxim.h │ │ ├── crc16_mcrf4xx.h │ │ ├── crc16_modbus.h │ │ ├── crc16_riello.h │ │ ├── crc16_t10_dif.h │ │ ├── crc16_teledisk.h │ │ ├── crc16_tms37157.h │ │ ├── crc16_usb.h │ │ └── crc16_x_25.h │ ├── crc32_base.h │ ├── crc32_variants │ │ ├── crc32.h │ │ ├── crc32_bzip2.h │ │ ├── crc32_c.h │ │ ├── crc32_d.h │ │ ├── crc32_jamcrc.h │ │ ├── crc32_mpeg2.h │ │ ├── crc32_posix.h │ │ ├── crc32_q.h │ │ └── crc32_xfer.h │ ├── crc8_base.h │ └── crc8_variants │ │ ├── crc8.h │ │ ├── crc8_8h2f.h │ │ ├── crc8_cdma2000.h │ │ ├── crc8_darc.h │ │ ├── crc8_dvb_s2.h │ │ ├── crc8_ebu.h │ │ ├── crc8_icode.h │ │ ├── crc8_itu.h │ │ ├── crc8_maxim.h │ │ ├── crc8_rohc.h │ │ ├── crc8_sae_j1850.h │ │ ├── crc8_sae_j1850_zero.h │ │ └── crc8_wcdma.h ├── crypto │ ├── caesar_cipher.h │ ├── chacha20.h │ └── vernam_cipher.h ├── json.h ├── map.h ├── misra_c_2012_doc.h ├── priority_queue.h ├── queue.h ├── scheduler.h ├── sort │ ├── bubble_sort.h │ ├── heap_sort.h │ ├── insertion_sort.h │ ├── merge_sort.h │ ├── quick_sort.h │ └── selection_sort.h ├── typedefs.h └── utils.h ├── LICENSE ├── Makefile ├── README.md ├── Src ├── base64.c ├── bit_manipulation.c ├── crc │ ├── crc16_base.c │ ├── crc16_variants │ │ ├── crc16_a.c │ │ ├── crc16_arc.c │ │ ├── crc16_aug_ccit.c │ │ ├── crc16_buypass.c │ │ ├── crc16_ccit_false.c │ │ ├── crc16_ccit_zero.c │ │ ├── crc16_cdma2000.c │ │ ├── crc16_dds110.c │ │ ├── crc16_dect_r.c │ │ ├── crc16_dect_x.c │ │ ├── crc16_dnp.c │ │ ├── crc16_en_13757.c │ │ ├── crc16_genibus.c │ │ ├── crc16_kermit.c │ │ ├── crc16_maxim.c │ │ ├── crc16_mcrf4xx.c │ │ ├── crc16_modbus.c │ │ ├── crc16_riello.c │ │ ├── crc16_t10_dif.c │ │ ├── crc16_teledisk.c │ │ ├── crc16_tms37157.c │ │ ├── crc16_usb.c │ │ └── crc16_x_25.c │ ├── crc32_base.c │ ├── crc32_variants │ │ ├── crc32.c │ │ ├── crc32_bzip2.c │ │ ├── crc32_c.c │ │ ├── crc32_d.c │ │ ├── crc32_jamcrc.c │ │ ├── crc32_mpeg2.c │ │ ├── crc32_posix.c │ │ ├── crc32_q.c │ │ └── crc32_xfer.c │ ├── crc8_base.c │ └── crc8_variants │ │ ├── crc8.c │ │ ├── crc8_8h2f.c │ │ ├── crc8_cdma2000.c │ │ ├── crc8_darc.c │ │ ├── crc8_dvb_s2.c │ │ ├── crc8_ebu.c │ │ ├── crc8_icode.c │ │ ├── crc8_itu.c │ │ ├── crc8_maxim.c │ │ ├── crc8_rohc.c │ │ ├── crc8_sae_j1850.c │ │ ├── crc8_sae_j1850_zero.c │ │ └── crc8_wcdma.c ├── crypto │ ├── caesar_cipher.c │ ├── chacha20.c │ └── vernam_cipher.c ├── json.c ├── map.c ├── priority_queue.c ├── queue.c ├── scheduler.c ├── sort │ ├── bubble_sort.c │ ├── heap_sort.c │ ├── insertion_sort.c │ ├── merge_sort.c │ ├── quick_sort.c │ └── selection_sort.c └── utils.c ├── Tests ├── helper │ ├── sort_functions.c │ └── sort_functions.h ├── test_base64.c ├── test_bit_manipulation.c ├── test_bubble_sort.c ├── test_caesar_cipher.c ├── test_chacha20.c ├── test_crc16.c ├── test_crc32.c ├── test_crc8.c ├── test_heap_sort.c ├── test_insertion_sort.c ├── test_json.c ├── test_main.c ├── test_map.c ├── test_merge_sort.c ├── test_priority_queue.c ├── test_queue.c ├── test_quick_sort.c ├── test_scheduler.c ├── test_selection_sort.c ├── test_utils.c ├── test_vernam_cipher.c └── unity_config.h ├── Tools └── astyle │ ├── astylerc │ ├── check_code_style.sh │ ├── check_code_style_all.sh │ ├── files_to_check_code_style.sh │ ├── fix_code_style.sh │ └── pre-commit ├── build.sh ├── clean.sh └── prepare.sh /.codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "Tests" # ignore Tests folder 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. Windows, Linux] 28 | - Compiler [e.g. GCC10, Clang] 29 | - Version [e.g. v1.0.1] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | [Describe the purpose of this pull request and the changes you've made. Please include any relevant links or context.] 3 | 4 | ## Related Issues 5 | [If this pull request is related to any GitHub issues, please link to them here.] 6 | 7 | ## Checklist 8 | Please check off the following items by putting an "x" in the box: 9 | 10 | - [ ] I have read and understood the [contribution guidelines](https://github.com/IMProject/IMUtility/blob/main/CONTRIBUTING.md). 11 | - [ ] I have added any necessary documentation (if appropriate). 12 | - [ ] I have added unit tests (if appropriate). 13 | - [ ] I have run `make cppcheck` on my code and fixed any reported issues. 14 | - [ ] I have run `make astyle` on my code and ensured that it adheres to the project's formatting guidelines. 15 | - [ ] Test coverage is at 100% for the modified code. 16 | 17 | ## Additional Notes 18 | [Include any additional notes or context that may be helpful for reviewers.] 19 | -------------------------------------------------------------------------------- /.github/workflows/checks.yml: -------------------------------------------------------------------------------- 1 | name: Checks 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | Static_Analysis: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | container: 17 | image: igormisic/improject:v1.0.1 18 | options: --privileged --ulimit core=-1 --security-opt seccomp=unconfined 19 | 20 | steps: 21 | - name: Change Owner of Container Working Directory 22 | run: chown root:root . 23 | 24 | - uses: actions/checkout@v3 25 | with: 26 | token: ${{ secrets.GITHUB_TOKEN }} 27 | 28 | - name: Check code format 29 | run: make check_format 30 | 31 | - name: Run cppcheck 32 | run: make cppcheck 33 | 34 | - name: Check MISRA C:2012 35 | run: make misra 36 | 37 | 38 | -------------------------------------------------------------------------------- /.github/workflows/compile.yml: -------------------------------------------------------------------------------- 1 | name: Unit tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | config: [ 19 | all 20 | ] 21 | 22 | container: 23 | image: igormisic/improject:v1.0.3 24 | options: --privileged --ulimit core=-1 --security-opt seccomp=unconfined 25 | steps: 26 | - uses: actions/checkout@v4 27 | with: 28 | token: ${{ secrets.GITHUB_TOKEN }} 29 | submodules: 'true' 30 | 31 | - name: Mark repository as safe 32 | run: git config --global --add safe.directory $GITHUB_WORKSPACE 33 | 34 | - name: make ${{matrix.config}} 35 | run: make ${{matrix.config}} 36 | 37 | - name: Upload coverage to Codecov 38 | uses: codecov/codecov-action@v3 39 | with: 40 | gcov: true 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .cproject 3 | .settings/ 4 | *.out 5 | *.gc* 6 | gcovr-report 7 | lcov-report 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Tests/Unity"] 2 | path = Tests/Unity 3 | url = git@github.com:ThrowTheSwitch/Unity.git 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | We are happy to see contributions. You can add utility code that you see is missing, improve existing one, or open issue tickets. 2 | Before you open PR: 3 | - write unit tests for your code 4 | - run `make gcovr-report`, open `gcovr-report/coverage.html`, and make sure you made 100% code coverage for changes 5 | - run `make format` 6 | - run `make cppcheck` 7 | - run `make misra` 8 | 9 | After PR is opened, we will review your code, and after that code can be merged into the main branch. 10 | -------------------------------------------------------------------------------- /Inc/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_BASE64_H_ 2 | #define UTILITY_BASE64_H_ 3 | 4 | #include "typedefs.h" 5 | 6 | #include 7 | 8 | /** 9 | * @brief Base64 encode function. 10 | * 11 | * @param[in] *data Pointer to data that will be encoded. 12 | * @param[in] data_length Data length. 13 | * @param[out] *result Pointer to result, encoded data. 14 | * @param[in] max_result_length Maximum result length. 15 | * 16 | * @return 0 = success, in case of fail value different than 0 is returned. 17 | */ 18 | int32_t Base64_encode(const char* data, size_t data_length, char* result, size_t max_result_length); 19 | 20 | /** 21 | * @brief Base64 decode function. 22 | * 23 | * @param[in] *in Pointer to data that will be decoded. 24 | * @param[in] in_len Input data length. 25 | * @param[out] *out Pointer to result data, decoded data. 26 | * @param[in] max_out_len Maximum output length. 27 | * 28 | * @return 0 = success, in case of fail value different than 0 is returned. 29 | */ 30 | int32_t Base64_decode(const char* in, size_t in_len, uint8_t* out, size_t max_out_len); 31 | 32 | #endif /* UTILITY_BASE64_H_ */ 33 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_a.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_A_H_ 36 | #define UTILITY_CRC16_A_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the A polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_a( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_A_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_arc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_ARC_H_ 36 | #define UTILITY_CRC16_ARC_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the ARC polynomial (0x8005). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8005. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_arc( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_ARC_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_aug_ccit.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_AUG_CCIT_H_ 36 | #define UTILITY_CRC16_AUG_CCIT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the AUG CCIT polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_augCcit( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_AUG_CCIT_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_buypass.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_BUYPASS_H_ 36 | #define UTILITY_CRC16_BUYPASS_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the BUYPASS polynomial (0x8005). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8005. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_buypass( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_BUYPASS_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_ccit_false.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_CCIT_FALSE_H_ 36 | #define UTILITY_CRC16_CCIT_FALSE_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the CCIT FALSE polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_ccitFalse( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_CCIT_FALSE_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_ccit_zero.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_CCIT_ZERO_H_ 36 | #define UTILITY_CRC16_CCIT_ZERO_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the CCIT ZERO 42 | * (also know as XMODEM) polynomial (0x1021). 43 | * 44 | * This function calculates an 16-bit CRC checksum for the given block of data 45 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 46 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 47 | * parameter is the length of the data block in bytes. 48 | * The calculation is performed using a lookup table for efficiency. 49 | * 50 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 51 | * @param[in] crc_length The length of the data block in bytes. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_ccitZero( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | const uint16_t* last_crc_ptr 60 | ); 61 | 62 | #endif /* UTILITY_CRC16_CCIT_ZERO_H_ */ 63 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_cdma2000.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_CDMA2000_H_ 36 | #define UTILITY_CRC16_CDMA2000_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the CDMA2000 polynomial (0xC867). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0xC867. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_cdma2000( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_CDMA2000_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_dds110.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_DDS110_H_ 36 | #define UTILITY_CRC16_DDS110_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the DDS110 polynomial (0x8005). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8005. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_dds110( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_DDS110_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_dect_r.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_DECT_R_H_ 36 | #define UTILITY_CRC16_DECT_R_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the DECT R polynomial (0x0589). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x0589. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_dectR( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_DECT_R_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_dect_x.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_DECT_X_H_ 36 | #define UTILITY_CRC16_DECT_X_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the DECT X polynomial (0x0589). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x0589. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_dectX( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_DECT_X_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_dnp.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_DNP_H_ 36 | #define UTILITY_CRC16_DNP_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the DNP polynomial (0x3D65). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x3D65. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_dnp( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_DNP_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_en_13757.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_EN_13757_H_ 36 | #define UTILITY_CRC16_EN_13757_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the EN 13757 polynomial (0x3D65). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x3D65. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_en13757( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_EN_13757_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_genibus.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_GENIBUS_H_ 36 | #define UTILITY_CRC16_GENIBUS_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the GENIBUS polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_genibus( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_GENIBUS_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_kermit.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_KERMIT_H_ 36 | #define UTILITY_CRC16_KERMIT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the KERMIT polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_kermit( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_KERMIT_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_maxim.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_MAXIM_H_ 36 | #define UTILITY_CRC16_MAXIM_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the MAXIM polynomial (0x8005). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8005. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_maxim( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_MAXIM_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_mcrf4xx.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_MCRF4XX_H_ 36 | #define UTILITY_CRC16_MCRF4XX_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the MCRF4XX polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_mcrf4xx( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_MCRF4XX_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_modbus.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_MODBUS_H_ 36 | #define UTILITY_CRC16_MODBUS_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the MODBUS polynomial (0x8005). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8005. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_modbus( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_MODBUS_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_riello.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_RIELLO_H_ 36 | #define UTILITY_CRC16_RIELLO_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the RIELLO polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_riello( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_RIELLO_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_t10_dif.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_T10_DIF_H_ 36 | #define UTILITY_CRC16_T10_DIF_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the T10 DIF polynomial (0x8BB7). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8BB7. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_t10Dif( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_T10_DIF_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_teledisk.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_TELEDISK_H_ 36 | #define UTILITY_CRC16_TELEDISK_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the TELEDISK polynomial (0xA097). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0xA097. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint16_t Crc16_teledisk( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint16_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC16_TELEDISK_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_tms37157.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_TMS37157_H_ 36 | #define UTILITY_CRC16_TMS37157_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the TMS37157 polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_tms37157( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_TMS37157_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_usb.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_USB_H_ 36 | #define UTILITY_CRC16_USB_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the USB polynomial (0x8005). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x8005. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_usb( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_USB_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc16_variants/crc16_x_25.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC16_X_25_H_ 36 | #define UTILITY_CRC16_X_25_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 16-bit CRC checksum for a block of data using the X 25 polynomial (0x1021). 42 | * 43 | * This function calculates an 16-bit CRC checksum for the given block of data 44 | * using polynomial 0x1021. The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint16_t Crc16_x25( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint16_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC16_X_25_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2021 - 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_H_ 36 | #define UTILITY_CRC32_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 32-bit CRC checksum for a block of data using polynomial (0x4C11DB7). 42 | * 43 | * This function calculates an 32-bit CRC checksum for the given block of data 44 | * using a basic algorithm that uses the polynomial (0x4C11DB7). 45 | * The 'crc_data_ptr' parameter should be a pointer to the block of data to 46 | * calculate the checksum for. The 'crc_length' parameter is the length of the 47 | * data block in bytes. The 'final_crc' parameter indicates whether to perform a final XOR 48 | * and output reflection operation. It shall be used when calculating CRC in chunks. 49 | * The calculation is performed using a lookup table for efficiency. 50 | * 51 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 52 | * @param[in] crc_length The length of the data block in bytes. 53 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 54 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 55 | * 56 | * @return The calculated CRC checksum. 57 | */ 58 | uint32_t Crc32( 59 | const uint8_t* crc_data_ptr, 60 | uint32_t crc_length, 61 | bool final_crc, 62 | const uint32_t* last_crc_ptr 63 | ); 64 | 65 | #endif /* UTILITY_CRC32_H_ */ 66 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_bzip2.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_BZIP2_H_ 36 | #define UTILITY_CRC32_BZIP2_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 32-bit CRC checksum for a block of data using polynomial (0x4C11DB7). 42 | * 43 | * This function calculates an 32-bit CRC checksum for the given block of data 44 | * using a basic algorithm that uses the polynomial (0x4C11DB7). 45 | * The CRC32_BZIP2 function will not perform reflection on its input and output data. 46 | * The 'crc_data_ptr' parameter should be a pointer to the block of data to 47 | * calculate the checksum for. The 'crc_length' parameter is the length of the 48 | * data block in bytes. The 'final_crc' parameter indicates whether to perform a final XOR operation. 49 | * It shall be used when calculating CRC in chunks. 50 | * The calculation is performed using a lookup table for efficiency. 51 | * 52 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 53 | * @param[in] crc_length The length of the data block in bytes. 54 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 55 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 56 | * 57 | * @return The calculated CRC checksum. 58 | */ 59 | uint32_t Crc32_bzip2( 60 | const uint8_t* crc_data_ptr, 61 | uint32_t crc_length, 62 | bool final_crc, 63 | const uint32_t* last_crc_ptr 64 | ); 65 | 66 | #endif /* UTILITY_CRC32_BZIP2_H_ */ 67 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_c.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_C_H_ 36 | #define UTILITY_CRC32_C_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 32-bit CRC checksum for a block of data using polynomial (0x1EDC6F41). 42 | * 43 | * This function calculates an 32-bit CRC checksum for the given block of data 44 | * using a basic algorithm that uses the polynomial (0x1EDC6F41). 45 | * The 'crc_data_ptr' parameter should be a pointer to the block of data to 46 | * calculate the checksum for. The 'crc_length' parameter is the length of the 47 | * data block in bytes. The 'final_crc' parameter indicates whether to perform a final XOR 48 | * and output reflection operation. It shall be used when calculating CRC in chunks. 49 | * The calculation is performed using a lookup table for efficiency. 50 | * 51 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 52 | * @param[in] crc_length The length of the data block in bytes. 53 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 54 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 55 | * 56 | * @return The calculated CRC checksum. 57 | */ 58 | uint32_t Crc32_c( 59 | const uint8_t* crc_data_ptr, 60 | uint32_t crc_length, 61 | bool final_crc, 62 | const uint32_t* last_crc_ptr 63 | ); 64 | 65 | #endif /* UTILITY_CRC32_C_H_ */ 66 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_d.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_D_H_ 36 | #define UTILITY_CRC32_D_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 32-bit CRC checksum for a block of data using polynomial (0x4C11DB7). 42 | * 43 | * This function calculates an 32-bit CRC checksum for the given block of data 44 | * using a basic algorithm that uses the polynomial (0x4C11DB7). 45 | * The 'crc_data_ptr' parameter should be a pointer to the block of data to 46 | * calculate the checksum for. The 'crc_length' parameter is the length of the 47 | * data block in bytes. The 'final_crc' parameter indicates whether to perform a final XOR 48 | * and output reflection operation. It shall be used when calculating CRC in chunks. 49 | * The calculation is performed using a lookup table for efficiency. 50 | * 51 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 52 | * @param[in] crc_length The length of the data block in bytes. 53 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 54 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 55 | * 56 | * @return The calculated CRC checksum. 57 | */ 58 | uint32_t Crc32_d( 59 | const uint8_t* crc_data_ptr, 60 | uint32_t crc_length, 61 | bool final_crc, 62 | const uint32_t* last_crc_ptr 63 | ); 64 | 65 | #endif /* UTILITY_CRC32_D_H_ */ 66 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_jamcrc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_JAMCRC_H_ 36 | #define UTILITY_CRC32_JAMCRC_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-32 checksum using the polynomial (0x4C11DB7). 42 | * 43 | * This function takes a pointer to a block of data and its length, and returns 44 | * the CRC-32 checksum calculated using the polynomial (0x4C11DB7). 45 | * The checksum is returned as an unsigned 32-bit integer. 46 | * The calculation is performed using a lookup table for efficiency. 47 | * 48 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 49 | * @param[in] crc_length The length of the data block in bytes. 50 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC-32 checksum. 54 | */ 55 | uint32_t Crc32_jamcrc( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | bool final_crc, 59 | const uint32_t* last_crc_ptr 60 | ); 61 | 62 | #endif /* UTILITY_CRC32_JAMCRC_H_ */ 63 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_mpeg2.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_MPEG2_H_ 36 | #define UTILITY_CRC32_MPEG2_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-32 checksum using the polynomial (0x4C11DB7). 42 | * 43 | * This function takes a pointer to a block of data and its length, and returns 44 | * the CRC-32 checksum calculated using the polynomial (0x4C11DB7). 45 | * The CRC32_MPEG2 function will not perform reflection on its input and output data. 46 | * The checksum is returned as an unsigned 32-bit integer. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC-32 checksum. 54 | */ 55 | uint32_t Crc32_mpeg2( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint32_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC32_MPEG2_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_posix.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_POSIX_H_ 36 | #define UTILITY_CRC32_POSIX_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 32-bit CRC checksum for a block of data using polynomial (0xA833982B). 42 | * 43 | * This function calculates an 32-bit CRC checksum for the given block of data 44 | * using a basic algorithm that uses the polynomial (0xA833982B). 45 | * The 'crc_data_ptr' parameter should be a pointer to the block of data to 46 | * calculate the checksum for. The 'crc_length' parameter is the length of the 47 | * data block in bytes.The 'final_crc' parameter indicates whether to perform a final XOR operation. 48 | * It shall be used when calculating CRC in chunks. 49 | * The calculation is performed using a lookup table for efficiency. 50 | * 51 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 52 | * @param[in] crc_length The length of the data block in bytes. 53 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 54 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 55 | * 56 | * @return The calculated CRC checksum. 57 | */ 58 | uint32_t Crc32_posix( 59 | const uint8_t* crc_data_ptr, 60 | uint32_t crc_length, 61 | bool final_crc, 62 | const uint32_t* last_crc_ptr 63 | ); 64 | 65 | #endif /* UTILITY_CRC32_POSIX_H_ */ 66 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_q.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_Q_H_ 36 | #define UTILITY_CRC32_Q_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-32 checksum using the polynomial (0xAF). 42 | * 43 | * This function takes a pointer to a block of data and its length, and returns 44 | * the CRC-32 checksum calculated using the polynomial (0x4C11DB7). 45 | * The CRC32_Q function will not perform reflection on its input and output data. 46 | * The checksum is returned as an unsigned 32-bit integer. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC-32 checksum. 54 | */ 55 | uint32_t Crc32_q( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint32_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC32_Q_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc32_variants/crc32_xfer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC32_XFER_H_ 36 | #define UTILITY_CRC32_XFER_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-32 checksum using the polynomial (0x4C11DB7). 42 | * 43 | * This function takes a pointer to a block of data and its length, and returns 44 | * the CRC-32 checksum calculated using the polynomial (0x4C11DB7). 45 | * The CRC32_XFER function will not perform reflection on its input and output data. 46 | * The checksum is returned as an unsigned 32-bit integer. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC-32 checksum. 54 | */ 55 | uint32_t Crc32_xfer( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint32_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC32_XFER_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_H_ 36 | #define UTILITY_CRC8_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 8-bit CRC checksum for a block of data using a basic algorithm. 42 | * 43 | * This function calculates an 8-bit CRC checksum for the given block of data 44 | * using a basic algorithm that uses the polynomial x^8 + x^2 + x^1 + 1 (0x07). 45 | * The 'crc_data_ptr' parameter should be a pointer to the block of data to 46 | * calculate the checksum for. The 'crc_length' parameter is the length of the 47 | * data block in bytes. The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC checksum. 54 | */ 55 | uint8_t Crc8( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_8h2f.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_8H2F_H_ 36 | #define UTILITY_CRC8_8H2F_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 8-bit CRC checksum for a block of data using the 8H2F polynomial (0x2F). 42 | * 43 | * This function calculates an 8-bit CRC checksum for the given block of data 44 | * using the 8H2F polynomial (0x2F). The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint8_t Crc8_8h2f( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | bool final_crc, 60 | const uint8_t* last_crc_ptr 61 | ); 62 | 63 | #endif /* UTILITY_CRC8_8H2F_H_ */ 64 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_cdma2000.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_CDMA2000_H_ 36 | #define UTILITY_CRC8_CDMA2000_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates an 8-bit CRC checksum for a block of data using the polynomial 0x9B. 42 | * 43 | * This function calculates an 8-bit CRC checksum for the given block of data 44 | * using the polynomial x^7 + x^4 + x^3 + x + 1 (0x9B), which is commonly used in 45 | * CDMA2000 systems. The 'crc_data_ptr' parameter should be a pointer to the 46 | * block of data to calculate the checksum for. The 'crc_length' parameter 47 | * is the length of the data block in bytes. 48 | * The calculation is performed using a lookup table for efficiency. 49 | * 50 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 51 | * @param[in] crc_length The length of the data block in bytes. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | * 54 | * @return The calculated CRC checksum. 55 | */ 56 | uint8_t Crc8_cdma2000( 57 | const uint8_t* crc_data_ptr, 58 | uint32_t crc_length, 59 | const uint8_t* last_crc_ptr 60 | ); 61 | 62 | #endif /* UTILITY_CRC8_CDMA2000_H_ */ 63 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_darc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_DARC_H_ 36 | #define UTILITY_CRC8_DARC_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the DARC polynomial (0x39). 42 | * 43 | * This function takes a pointer to a block of data and its length, and returns 44 | * the CRC-8 checksum calculated using the DARC (Data Radio Channel) polynomial (0x39). 45 | * The checksum is returned as an unsigned 8-bit integer. 46 | * The calculation is performed using a lookup table for efficiency. 47 | * 48 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 49 | * @param[in] crc_length The length of the data block in bytes. 50 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 51 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 52 | * 53 | * @return The calculated CRC-8 checksum. 54 | */ 55 | uint8_t Crc8_darc( 56 | const uint8_t* crc_data_ptr, 57 | uint32_t crc_length, 58 | bool final_crc, 59 | const uint8_t* last_crc_ptr 60 | ); 61 | 62 | #endif /* UTILITY_CRC8_DARC_H_ */ 63 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_dvb_s2.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_DVB_S2_H_ 36 | #define UTILITY_CRC8_DVB_S2_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC8-DVB-S2 checksum for the given data. 42 | * 43 | * This function calculates the CRC8-DVB-S2 checksum using the polynomial 0xD5. 44 | * The calculation is performed using a lookup table for efficiency. 45 | * 46 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 47 | * @param[in] crc_length The length of the data block in bytes. 48 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 49 | * 50 | * @return The calculated CRC8-DVB-S2 checksum. 51 | */ 52 | uint8_t Crc8_dvbS2( 53 | const uint8_t* crc_data_ptr, 54 | uint32_t crc_length, 55 | const uint8_t* last_crc_ptr 56 | ); 57 | 58 | #endif /* UTILITY_CRC8_DVB_S2_H_ */ 59 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_ebu.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_EBU_H_ 36 | #define UTILITY_CRC8_EBU_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the EBU polynomial (0x1D). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the EBU 44 | * polynomial (0x1D). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 50 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 51 | * 52 | * @return The calculated CRC-8 checksum. 53 | */ 54 | uint8_t Crc8_ebu( 55 | const uint8_t* crc_data_ptr, 56 | uint32_t crc_length, 57 | bool final_crc, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_EBU_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_icode.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_ICODE_H_ 36 | #define UTILITY_CRC8_ICODE_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the ICODE polynomial (0x1D). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the ICODE 44 | * polynomial (0x1D). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 50 | * 51 | * @return The calculated CRC-8 checksum. 52 | */ 53 | uint8_t Crc8_icode( 54 | const uint8_t* crc_data_ptr, 55 | uint32_t crc_length, 56 | const uint8_t* last_crc_ptr 57 | ); 58 | 59 | #endif /* UTILITY_CRC8_ICODE_H_ */ 60 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_itu.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_ITU_H_ 36 | #define UTILITY_CRC8_ITU_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the ITU polynomial (0x07). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the ITU 44 | * polynomial (0x07). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 50 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 51 | * 52 | * @return The calculated CRC-8 checksum. 53 | */ 54 | uint8_t Crc8_itu( 55 | const uint8_t* crc_data_ptr, 56 | uint32_t crc_length, 57 | bool final_crc, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_ITU_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_maxim.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_MAXIM_H_ 36 | #define UTILITY_CRC8_MAXIM_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the MAXIM polynomial (0x31). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the MAXIM 44 | * polynomial (0x31). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 50 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 51 | * 52 | * @return The calculated CRC-8 checksum. 53 | */ 54 | uint8_t Crc8_maxim( 55 | const uint8_t* crc_data_ptr, 56 | uint32_t crc_length, 57 | bool final_crc, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_MAXIM_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_rohc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_ROHC_H_ 36 | #define UTILITY_CRC8_ROHC_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the MAXIM polynomial (0x07). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the MAXIM 44 | * polynomial (0x07). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 50 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 51 | * 52 | * @return The calculated CRC-8 checksum. 53 | */ 54 | uint8_t Crc8_rohc( 55 | const uint8_t* crc_data_ptr, 56 | uint32_t crc_length, 57 | bool final_crc, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_ROHC_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_sae_j1850.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_SAE_J1850_H_ 36 | #define UTILITY_CRC8_SAE_J1850_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the SAE J1850 polynomial (0x1D). 42 | * 43 | * This function calculates an 8-bit CRC checksum for the given block of data 44 | * using the SAE J1850 polynomial (0x1D). The 'crc_data_ptr' parameter should be 45 | * a pointer to the block of data to calculate the checksum for. The 'crc_length' 46 | * parameter is the length of the data block in bytes. 47 | * The calculation is performed using a lookup table for efficiency. 48 | * 49 | * @param[in] crc_data_ptr A pointer to the data block to calculate the checksum for. 50 | * @param[in] crc_length The length of the data block in bytes. 51 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 52 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 53 | */ 54 | uint8_t Crc8_saeJ1850( 55 | const uint8_t* crc_data_ptr, 56 | uint32_t crc_length, 57 | bool final_crc, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_SAE_J1850_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_sae_j1850_zero.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_SAE_J1850_ZERO_H_ 36 | #define UTILITY_CRC8_SAE_J1850_ZERO_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the SAE J1850_ZERO polynomial (0x1D). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the SAE J1850_ZERO 44 | * polynomial (0x1D). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 50 | * 51 | * @return The calculated CRC-8 checksum. 52 | */ 53 | uint8_t Crc8_saeJ1850Zero( 54 | const uint8_t* crc_data_ptr, 55 | uint32_t crc_length, 56 | const uint8_t* last_crc_ptr 57 | ); 58 | 59 | #endif /* UTILITY_CRC8_SAE_J1850_ZERO_H_ */ 60 | -------------------------------------------------------------------------------- /Inc/crc/crc8_variants/crc8_wcdma.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_CRC8_WCDMA_H_ 36 | #define UTILITY_CRC8_WCDMA_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Calculates the CRC-8 checksum using the WCDMA polynomial (0x9B). 42 | * 43 | * This function calculates the CRC-8 checksum of the given data using the WCDMA 44 | * polynomial (0x9B). The calculation is performed using a lookup table for 45 | * efficiency. 46 | * 47 | * @param[in] crc_data_ptr A pointer to the block of data to calculate the checksum for. 48 | * @param[in] crc_length The length of the data block in bytes. 49 | * @param[in] final_crc Set the flag to 'true' if it is the last or only operation, and 'false' for data chunks. 50 | * @param[in] last_crc_ptr Pointer to the last CRC value for data chunks. Shall be set to NULL_PTR if it is the first or only operation. 51 | * 52 | * @return The calculated CRC-8 checksum. 53 | */ 54 | uint8_t Crc8_wcdma( 55 | const uint8_t* crc_data_ptr, 56 | uint32_t crc_length, 57 | bool final_crc, 58 | const uint8_t* last_crc_ptr 59 | ); 60 | 61 | #endif /* UTILITY_CRC8_WCDMA_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/crypto/caesar_cipher.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2024 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef CAESAR_CIPHER_H_ 36 | #define CAESAR_CIPHER_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Encryption using Caesar cipher algorithm. Time complexity O(N). 42 | * 43 | * @param[in/out] *msg Pointer to message that will be encrypted. 44 | * @param[in] shift Shift value that will be used for encryption. 45 | */ 46 | void CaesarCipher_encrypt(char* msg, uint8_t shift); 47 | 48 | /** 49 | * @brief Decryption using Caesar cipher algorithm. Time complexity O(N). 50 | * 51 | * @param[in/out] *msg Pointer to message that will be decrypted. 52 | * @param[in] shift Shift value that will be used for decryption. 53 | */ 54 | void CaesarCipher_decrypt(char* msg, uint8_t shift); 55 | 56 | #endif /* CAESAR_CIPHER_H_ */ 57 | -------------------------------------------------------------------------------- /Inc/crypto/vernam_cipher.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2024 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef VERNAM_CIPHER_H_ 36 | #define VERNAM_CIPHER_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Encryption using Vernam cipher/One Time Pad algorithm. 42 | * 43 | * @param[in/out] *msg Pointer to message that will be encrypted. 44 | * @param[in] *key Pointer to key string. 45 | * @param[in] key_length Key length. 46 | * 47 | * @return Status of encryption function. True if message size is higher than or equal to key length, otherwise false. 48 | */ 49 | bool VernamCipher_encrypt(char* msg, const char* key, int32_t key_length); 50 | 51 | /** 52 | * @brief Decryption using Vernam cipher/One Time Pad algorithm. 53 | * 54 | * @param[in/out] *msg Pointer to message that will be decrypted. 55 | * @param[in] *key Pointer to key string. 56 | * @param[in] key_length Key length. 57 | * 58 | * @return Status of decryption function. True if message size is higher than or equal to key length, otherwise false. 59 | */ 60 | bool VernamCipher_decrypt(char* msg, const char* key, int32_t key_length); 61 | 62 | #endif /* VERNAM_CIPHER_H_ */ 63 | -------------------------------------------------------------------------------- /Inc/scheduler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_SCHEDULER_H_ 36 | #define UTILITY_SCHEDULER_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | typedef struct { 41 | void (*function)(void); 42 | bool active; 43 | } SchedulerTask_t; 44 | 45 | /** 46 | * @brief Function used to initialize scheduler. 47 | * 48 | * @param[in, out] *tasks Pointer to tasks (tasks are represented as a structure that contains 49 | * pointer to function and status (active/not active)). 50 | * @param[in] num_of_tasks Number of tasks that will be initialized. 51 | */ 52 | void Scheduler_init(SchedulerTask_t* tasks, uint32_t num_of_tasks); 53 | 54 | /** 55 | * @brief Function used to add new task in scheduler. 56 | * 57 | * @param[in, out] *tasks Pointer to tasks (array of tasks). 58 | * @param[in] max_num_tasks Maximum number of tasks that can be added in scheduler. 59 | * @param[in] *new_task Pointer to new task that will be added in scheduler. 60 | * 61 | * @return True if task is successfully added, otherwise false. 62 | */ 63 | bool Scheduler_addTask(SchedulerTask_t* tasks, uint32_t max_num_tasks, const SchedulerTask_t* new_task); 64 | 65 | /** 66 | * @brief Function used to run tasks. Tasks will be performed only once, and only active tasks. 67 | * 68 | * @param[in] *task Pointer to tasks (array of tasks). 69 | * @param[in] num_of_tasks Number of tasks that will be performed. 70 | */ 71 | void Scheduler_run(const SchedulerTask_t* task, uint32_t num_of_tasks); 72 | 73 | #endif /* UTILITY_SCHEDULER_H_ */ 74 | -------------------------------------------------------------------------------- /Inc/sort/bubble_sort.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_BUBBLE_SORT_H_ 36 | #define UTILITY_BUBBLE_SORT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Sort elements using bubble sort algorithm. It compares the adjacent elements and swaps them 42 | * if they are in the wrong order. It is done repeatedly until all elements are sorted. 43 | * Time complexity: O(N^2) 44 | * 45 | * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted. 46 | * @param[in] number_of_elements Number of elements in the buffer. 47 | * @param[in] element_size Size of the element, in bytes. 48 | * @param[in] *compareFun Pointer to compare function. Compare function has two parameters (pointer to 49 | * first element and pointer to second element). As a result, it returns boolean, 50 | * true if first element is greater than second element, otherwise false. 51 | */ 52 | void BubbleSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 53 | bool (*compareFun)(void* first, void* second)); 54 | 55 | #endif /* UTILITY_BUBBLE_SORT_H_ */ 56 | -------------------------------------------------------------------------------- /Inc/sort/heap_sort.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2022 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_HEAP_SORT_H_ 36 | #define UTILITY_HEAP_SORT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Sort elements using heap sort algorithm. It uses heapify to convert array into max heap. 42 | * It deletes the root node of the max heap (one by one) and replaces it with the last node. After that, 43 | * heapify is done again. Whole process is repeated while heap size is greater than 1. 44 | * Time complexity: O(N log N) 45 | * 46 | * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted. 47 | * @param[in] number_of_elements Number of elements in the buffer. 48 | * @param[in] element_size Size of the element, in bytes. 49 | * @param[in] *compareFun Pointer to compare function. Compare function has two parameters (pointer to 50 | * first element and pointer to second element). As a result, it returns boolean, 51 | * true if first element is greater than second element, otherwise false. 52 | */ 53 | void HeapSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 54 | bool (*compareFun)(void* first, void* second)); 55 | 56 | #endif /* UTILITY_HEAP_SORT_H_ */ 57 | -------------------------------------------------------------------------------- /Inc/sort/insertion_sort.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2024 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_INSERTION_SORT_H_ 36 | #define UTILITY_INSERTION_SORT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | #define MAX_ELEMENT_SIZE (64) 41 | 42 | /** 43 | * @brief Sort elements using insertion sort algorithm. Divide given list into sorted and unsorted part 44 | * (first element is considered sorted). Iterate through each element in the unsorted part. Pick one 45 | * element at a time, and insert it into correct position in the sorted part. It is efficient on smaller 46 | * lists, and much less efficient on large lists. 47 | * Time complexity: O(N^2) 48 | * 49 | * NOTE: implemented that the max element size is 64 B. If element size is larger, then 50 | * MAX_ELEMENT_SIZE macro must be updated. 51 | * 52 | * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted. 53 | * @param[in] number_of_elements Number of elements in the buffer. 54 | * @param[in] element_size Size of the element, in bytes. 55 | * @param[in] *compareFun Pointer to compare function. Compare function has two parameters (pointer to 56 | * first element and pointer to second element). As a result, it returns boolean, 57 | * true if first element is greater than second element, otherwise false. 58 | */ 59 | void InsertionSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 60 | bool (*compareFun)(void* first, void* second)); 61 | 62 | #endif /* UTILITY_INSERTION_SORT_H_ */ 63 | -------------------------------------------------------------------------------- /Inc/sort/merge_sort.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2025 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_MERGE_SORT_H_ 36 | #define UTILITY_MERGE_SORT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | #define MAX_HALVES_SIZE (64) 41 | 42 | /** 43 | * @brief Sort elements using merge sort algorithm. Merge sort algorithm works on a principle that it 44 | * divides the list/array into two halves. Sort each one. Merge them back together. Repeat the whole 45 | * process until the entire array is sorted. This algorithm does not use recursion since it is not MISRA 46 | * compliant. 47 | * Time complexity: O(N log N) 48 | * 49 | * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted. 50 | * @param[in] number_of_elements Number of elements in the buffer. 51 | * @param[in] element_size Size of the element, in bytes. 52 | * @param[in] *compareFun Pointer to compare function. Compare function has two parameters (pointer to 53 | * first element and pointer to second element). As a result, it returns boolean, 54 | * true if first element is greater than second element, otherwise false. 55 | */ 56 | void MergeSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 57 | bool (*compareFun)(void* first, void* second)); 58 | 59 | #endif /* UTILITY_MERGE_SORT_H_ */ 60 | -------------------------------------------------------------------------------- /Inc/sort/quick_sort.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2025 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_QUICK_SORT_H_ 36 | #define UTILITY_QUICK_SORT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | #define MAX_NUM_OF_ELEMENTS (64) 41 | 42 | /** 43 | * @brief Sort elements using quick sort algorithm. Quick sort algorithm works on divide and conquer 44 | * principle. Firstly, it selects an element from an array as a pivot. Secondly, partitioning is done 45 | * (array is arranged around the pivot). Elements smaller than the pivot will be on the left side, 46 | * elements that are greater than the pivot will be on the right side. Pivot will be in the correct 47 | * position. Repeat the process until the initial array is not sorted. This algorithm does not use 48 | * recursion since it is not MISRA compliant. 49 | * Time complexity: O(N log N) 50 | * 51 | * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted. 52 | * @param[in] number_of_elements Number of elements in the buffer. 53 | * @param[in] element_size Size of the element, in bytes. 54 | * @param[in] *compareFun Pointer to compare function. Compare function has two parameters (pointer to 55 | * first element and pointer to second element). As a result, it returns boolean, 56 | * true if first element is greater than second element, otherwise false. 57 | */ 58 | void QuickSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 59 | bool (*compareFun)(void* first, void* second)); 60 | 61 | #endif /* UTILITY_QUICK_SORT_H_ */ 62 | -------------------------------------------------------------------------------- /Inc/sort/selection_sort.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_SELECTION_SORT_H_ 36 | #define UTILITY_SELECTION_SORT_H_ 37 | 38 | #include "typedefs.h" 39 | 40 | /** 41 | * @brief Sort elements using selection sort algorithm. It divides the input array into 42 | * two parts, sorted sub-array of items which is built up from left to right and unsorted items 43 | * that occupies the rest of the array. The sorted sub-array is empty and the unsorted sub-array 44 | * is the entire input array. The algorithm proceeds by finding the smallest element in the 45 | * unsorted sub-array, swapping it with the leftmost unsorted element (putting it in sorted order), 46 | * and moving the sub-array boundaries one element to the right. 47 | * Time complexity: O(N^2) 48 | * 49 | * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted. 50 | * @param[in] number_of_elements Number of elements in the buffer. 51 | * @param[in] element_size Size of the element, in bytes. 52 | * @param[in] *compareFun Pointer to compare function. Compare function has two parameters (pointer to 53 | * first element and pointer to second element). As a result, it returns boolean, 54 | * true if first element is greater than second element, otherwise false. 55 | */ 56 | void SelectionSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 57 | bool (*compareFun)(void* first, void* second)); 58 | 59 | #endif /* UTILITY_SELECTION_SORT_H_ */ 60 | -------------------------------------------------------------------------------- /Inc/typedefs.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Igor Misic 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #ifndef UTILITY_TYPEDEFS_H_ 36 | #define UTILITY_TYPEDEFS_H_ 37 | 38 | #include 39 | #include 40 | 41 | #define NULL_PTR ((void*)0) 42 | 43 | typedef float float32_t; 44 | typedef double float64_t; 45 | typedef long double float128_t; 46 | 47 | // More on the topic can be found here: https://gist.github.com/jibsen/da6be27cde4d526ee564 48 | typedef unsigned char byte_t; 49 | 50 | #endif /* UTILITY_TYPEDEFS_H_ */ 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022 - 2024, IMProject Development Team 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Src/crypto/caesar_cipher.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2024 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #include "caesar_cipher.h" 36 | 37 | #include 38 | 39 | #include "utils.h" 40 | 41 | #define MAX_SHIFT (26U) 42 | #define UPPER_A_ASCII (65U) 43 | #define LOWER_A_ASCII (97U) 44 | 45 | void 46 | CaesarCipher_encrypt(char* msg, uint8_t shift) { 47 | const size_t length = strlen(msg); 48 | for (size_t i = 0U; i < length; ++i) { 49 | if (Utils_isAlpha(msg[i])) { 50 | uint8_t ascii_val = LOWER_A_ASCII; 51 | if (Utils_isUpperChar(msg[i])) { 52 | ascii_val = UPPER_A_ASCII; 53 | } 54 | uint8_t encrypted_char = (((uint8_t)msg[i] + shift - ascii_val) % MAX_SHIFT) + ascii_val; 55 | msg[i] = (char)encrypted_char; 56 | } 57 | } 58 | } 59 | 60 | void 61 | CaesarCipher_decrypt(char* msg, uint8_t shift) { 62 | const size_t length = strlen(msg); 63 | for (size_t i = 0U; i < length; ++i) { 64 | if (Utils_isAlpha(msg[i])) { 65 | uint8_t ascii_val = LOWER_A_ASCII; 66 | if (Utils_isUpperChar(msg[i])) { 67 | ascii_val = UPPER_A_ASCII; 68 | } 69 | uint8_t decrypted_char = (((uint8_t)msg[i] - shift - ascii_val) % MAX_SHIFT) + ascii_val; 70 | msg[i] = (char)decrypted_char; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Src/scheduler.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #include "scheduler.h" 36 | 37 | void 38 | Scheduler_init(SchedulerTask_t* tasks, uint32_t num_of_tasks) { 39 | for (uint32_t i = 0U; i < num_of_tasks; ++i) { 40 | tasks[i].function = NULL_PTR; 41 | tasks[i].active = false; 42 | } 43 | } 44 | 45 | bool 46 | Scheduler_addTask(SchedulerTask_t* tasks, uint32_t max_num_tasks, const SchedulerTask_t* new_task) { 47 | bool status = false; 48 | for (uint32_t i = 0U; i < max_num_tasks; ++i) { 49 | if (tasks[i].function == NULL_PTR) { 50 | tasks[i].function = new_task->function; 51 | tasks[i].active = new_task->active; 52 | status = true; 53 | break; 54 | } 55 | } 56 | return status; 57 | } 58 | 59 | void 60 | Scheduler_run(const SchedulerTask_t* task, uint32_t num_of_tasks) { 61 | for (uint32_t i = 0U; i < num_of_tasks; ++i) { 62 | if ((task[i].function != NULL_PTR) && (task[i].active)) { 63 | task[i].function(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Src/sort/bubble_sort.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #include "bubble_sort.h" 36 | 37 | #include "utils.h" 38 | 39 | void 40 | BubbleSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 41 | bool (*compareFun)(void* first, void* second)) { 42 | bool swapped = true; 43 | int32_t i = 0; 44 | while (swapped) { 45 | swapped = false; 46 | for (int32_t j = 0; j < (number_of_elements - i - 1); ++j) { 47 | if (compareFun(&buffer[j * element_size], &buffer[(j + 1) * element_size])) { 48 | Utils_swapElements(&buffer[j * element_size], &buffer[(j + 1) * element_size], (uint32_t)element_size); 49 | swapped = true; 50 | } 51 | } 52 | ++i; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Src/sort/insertion_sort.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2024 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #include "insertion_sort.h" 36 | 37 | #include 38 | 39 | void 40 | InsertionSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 41 | bool (*compareFun)(void* first, void* second)) { 42 | static byte_t max_element[MAX_ELEMENT_SIZE]; 43 | byte_t* element = &max_element[0]; 44 | 45 | for (int32_t i = 1; i < number_of_elements; ++i) { 46 | memcpy(element, &buffer[i * element_size], (size_t)element_size); 47 | 48 | int32_t j = i - 1; 49 | bool compare = compareFun(&buffer[j * element_size], element); 50 | 51 | while ((j >= 0) && compare) { 52 | memcpy(&buffer[(j + 1) * element_size], &buffer[j * element_size], (size_t)element_size); 53 | --j; 54 | compare = compareFun(&buffer[j * element_size], element); 55 | } 56 | memcpy(&buffer[(j + 1) * element_size], element, (size_t)element_size); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Src/sort/selection_sort.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * Copyright (c) 2023 IMProject Development Team. All rights reserved. 4 | * Authors: Juraj Ciberlin 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name IMProject nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************/ 34 | 35 | #include "selection_sort.h" 36 | 37 | #include "utils.h" 38 | 39 | void 40 | SelectionSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_size, 41 | bool (*compareFun)(void* first, void* second)) { 42 | int32_t j; 43 | 44 | for (int32_t i = 0; i < (number_of_elements - 1); ++i) { 45 | int32_t min_index = i; 46 | for (j = i + 1; j < number_of_elements; ++j) { 47 | if (compareFun(&buffer[min_index * element_size], &buffer[j * element_size])) { 48 | min_index = j; 49 | } 50 | } 51 | 52 | if (min_index != i) { 53 | Utils_swapElements(&buffer[min_index * element_size], &buffer[i * element_size], (uint32_t)element_size); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tests/helper/sort_functions.c: -------------------------------------------------------------------------------- 1 | #include "sort_functions.h" 2 | 3 | bool 4 | CompareInt32(void* first, void* second) { 5 | bool ret_val = false; 6 | const int32_t* first_element = first; 7 | const int32_t* second_element = second; 8 | if (*first_element > *second_element) { 9 | ret_val = true; 10 | } 11 | return ret_val; 12 | } 13 | 14 | bool 15 | CompareFloat64(void* first, void* second) { 16 | bool ret_val = false; 17 | const float64_t* first_element = first; 18 | const float64_t* second_element = second; 19 | if (*first_element > *second_element) { 20 | ret_val = true; 21 | } 22 | return ret_val; 23 | } 24 | 25 | bool 26 | CompareUint64(void* first, void* second) { 27 | bool ret_val = false; 28 | const uint64_t* first_element = first; 29 | const uint64_t* second_element = second; 30 | if (*first_element > *second_element) { 31 | ret_val = true; 32 | } 33 | return ret_val; 34 | } 35 | -------------------------------------------------------------------------------- /Tests/helper/sort_functions.h: -------------------------------------------------------------------------------- 1 | #include "typedefs.h" 2 | 3 | bool CompareInt32(void* first, void* second); 4 | bool CompareFloat64(void* first, void* second); 5 | bool CompareUint64(void* first, void* second); 6 | -------------------------------------------------------------------------------- /Tests/test_bubble_sort.c: -------------------------------------------------------------------------------- 1 | #include "bubble_sort.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | #include "helper/sort_functions.h" 7 | 8 | TEST_GROUP(BubbleSort); 9 | 10 | TEST_SETUP(BubbleSort) { 11 | } 12 | 13 | TEST_TEAR_DOWN(BubbleSort) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(BubbleSort) { 17 | RUN_TEST_CASE(BubbleSort, BubbleSort_int32); 18 | RUN_TEST_CASE(BubbleSort, BubbleSort_float64); 19 | RUN_TEST_CASE(BubbleSort, BubbleSort_uint64); 20 | } 21 | 22 | TEST(BubbleSort, BubbleSort_int32) { 23 | int32_t unsorted_array[] = {5, 2, 3, 1000000, 9, 10, 11, 8, 9, 100}; 24 | const int32_t sorted_array[] = {2, 3, 5, 8, 9, 9, 10, 11, 100, 1000000}; 25 | BubbleSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 26 | CompareInt32); 27 | 28 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 29 | TEST_ASSERT_EQUAL_INT32(sorted_array[i], unsorted_array[i]); 30 | } 31 | } 32 | 33 | TEST(BubbleSort, BubbleSort_float64) { 34 | float64_t unsorted_array[] = {5.8, 2.2, 3.1, 1.1, 9.1, 10.3, 11.2, 8.4, 9.2, 100.9}; 35 | const float64_t sorted_array[] = {1.1, 2.2, 3.1, 5.8, 8.4, 9.1, 9.2, 10.3, 11.2, 100.9}; 36 | BubbleSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 37 | CompareFloat64); 38 | 39 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 40 | TEST_ASSERT_EQUAL_DOUBLE(sorted_array[i], unsorted_array[i]); 41 | } 42 | } 43 | 44 | TEST(BubbleSort, BubbleSort_uint64) { 45 | uint64_t unsorted_array[] = {1111111U, 55555555U, 44444U, 10000000000000U, 212121U, 1111U, 1U, 2U, 5U, 3U}; 46 | const uint64_t sorted_array[] = {1U, 2U, 3U, 5U, 1111U, 44444U, 212121U, 1111111U, 55555555U, 10000000000000U}; 47 | BubbleSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 48 | CompareUint64); 49 | 50 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 51 | TEST_ASSERT_EQUAL_UINT64(sorted_array[i], unsorted_array[i]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tests/test_caesar_cipher.c: -------------------------------------------------------------------------------- 1 | #include "caesar_cipher.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | TEST_GROUP(CaesarCipher); 7 | 8 | TEST_SETUP(CaesarCipher) { 9 | } 10 | 11 | TEST_TEAR_DOWN(CaesarCipher) { 12 | } 13 | 14 | TEST_GROUP_RUNNER(CaesarCipher) { 15 | RUN_TEST_CASE(CaesarCipher, CaesarCipher_encryptDecrypt); 16 | } 17 | 18 | TEST(CaesarCipher, CaesarCipher_encryptDecrypt) { 19 | const char expected_result[] = "|Caesar Cipher Test|"; 20 | char message[] = "|Caesar Cipher Test|"; 21 | CaesarCipher_encrypt(message, 6U); 22 | CaesarCipher_decrypt(message, 6U); 23 | TEST_ASSERT_EQUAL_STRING(expected_result, message); 24 | } 25 | -------------------------------------------------------------------------------- /Tests/test_heap_sort.c: -------------------------------------------------------------------------------- 1 | #include "heap_sort.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | #include "helper/sort_functions.h" 7 | 8 | TEST_GROUP(HeapSort); 9 | 10 | TEST_SETUP(HeapSort) { 11 | } 12 | 13 | TEST_TEAR_DOWN(HeapSort) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(HeapSort) { 17 | RUN_TEST_CASE(HeapSort, HeapSort_int32); 18 | RUN_TEST_CASE(HeapSort, HeapSort_float64); 19 | RUN_TEST_CASE(HeapSort, HeapSort_uint64); 20 | } 21 | 22 | TEST(HeapSort, HeapSort_int32) { 23 | int32_t unsorted_array[] = {5, 2, 3, 1000000, 9, 10, 11, 8, 9, 100}; 24 | const int32_t sorted_array[] = {2, 3, 5, 8, 9, 9, 10, 11, 100, 1000000}; 25 | HeapSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 26 | CompareInt32); 27 | 28 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 29 | TEST_ASSERT_EQUAL_INT32(sorted_array[i], unsorted_array[i]); 30 | } 31 | } 32 | 33 | TEST(HeapSort, HeapSort_float64) { 34 | float64_t unsorted_array[] = {5.8, 2.2, 3.1, 1.1, 9.1, 10.3, 11.2, 8.4, 9.2, 100.9}; 35 | const float64_t sorted_array[] = {1.1, 2.2, 3.1, 5.8, 8.4, 9.1, 9.2, 10.3, 11.2, 100.9}; 36 | HeapSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 37 | CompareFloat64); 38 | 39 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 40 | TEST_ASSERT_EQUAL_DOUBLE(sorted_array[i], unsorted_array[i]); 41 | } 42 | } 43 | 44 | TEST(HeapSort, HeapSort_uint64) { 45 | uint64_t unsorted_array[] = {1111111U, 55555555U, 44444U, 10000000000000U, 212121U, 1111U, 1U, 2U, 5U, 3U}; 46 | const uint64_t sorted_array[] = {1U, 2U, 3U, 5U, 1111U, 44444U, 212121U, 1111111U, 55555555U, 10000000000000U}; 47 | HeapSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 48 | CompareUint64); 49 | 50 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 51 | TEST_ASSERT_EQUAL_UINT64(sorted_array[i], unsorted_array[i]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tests/test_insertion_sort.c: -------------------------------------------------------------------------------- 1 | #include "insertion_sort.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | #include "helper/sort_functions.h" 7 | 8 | TEST_GROUP(InsertionSort); 9 | 10 | TEST_SETUP(InsertionSort) { 11 | } 12 | 13 | TEST_TEAR_DOWN(InsertionSort) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(InsertionSort) { 17 | RUN_TEST_CASE(InsertionSort, InsertionSort_int32); 18 | RUN_TEST_CASE(InsertionSort, InsertionSort_float64); 19 | RUN_TEST_CASE(InsertionSort, InsertionSort_uint64); 20 | } 21 | 22 | TEST(InsertionSort, InsertionSort_int32) { 23 | int32_t unsorted_array[] = {5, 2, 3, 1000000, 9, 10, 11, 8, 9, 100}; 24 | const int32_t sorted_array[] = {2, 3, 5, 8, 9, 9, 10, 11, 100, 1000000}; 25 | InsertionSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), 26 | sizeof(unsorted_array[0]), 27 | CompareInt32); 28 | 29 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 30 | TEST_ASSERT_EQUAL_INT32(sorted_array[i], unsorted_array[i]); 31 | } 32 | } 33 | 34 | TEST(InsertionSort, InsertionSort_float64) { 35 | float64_t unsorted_array[] = {5.8, 2.2, 3.1, 1.1, 9.1, 10.3, 11.2, 8.4, 9.2, 100.9}; 36 | const float64_t sorted_array[] = {1.1, 2.2, 3.1, 5.8, 8.4, 9.1, 9.2, 10.3, 11.2, 100.9}; 37 | InsertionSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), 38 | sizeof(unsorted_array[0]), 39 | CompareFloat64); 40 | 41 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 42 | TEST_ASSERT_EQUAL_DOUBLE(sorted_array[i], unsorted_array[i]); 43 | } 44 | } 45 | 46 | TEST(InsertionSort, InsertionSort_uint64) { 47 | uint64_t unsorted_array[] = {1111111U, 55555555U, 44444U, 10000000000000U, 212121U, 1111U, 1U, 2U, 5U, 3U}; 48 | const uint64_t sorted_array[] = {1U, 2U, 3U, 5U, 1111U, 44444U, 212121U, 1111111U, 55555555U, 10000000000000U}; 49 | InsertionSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), 50 | sizeof(unsorted_array[0]), 51 | CompareUint64); 52 | 53 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 54 | TEST_ASSERT_EQUAL_UINT64(sorted_array[i], unsorted_array[i]); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tests/test_main.c: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "unity_fixture.h" 3 | 4 | static void 5 | RunAllTests(void) { 6 | RUN_TEST_GROUP(Base64); 7 | RUN_TEST_GROUP(BitManipulation); 8 | RUN_TEST_GROUP(BubbleSort); 9 | RUN_TEST_GROUP(CaesarCipher); 10 | RUN_TEST_GROUP(Chacha20); 11 | RUN_TEST_GROUP(Crc8); 12 | RUN_TEST_GROUP(Crc16); 13 | RUN_TEST_GROUP(Crc32); 14 | RUN_TEST_GROUP(HeapSort); 15 | RUN_TEST_GROUP(InsertionSort); 16 | RUN_TEST_GROUP(Json); 17 | RUN_TEST_GROUP(Map); 18 | RUN_TEST_GROUP(MergeSort); 19 | RUN_TEST_GROUP(PriorityQueue); 20 | RUN_TEST_GROUP(Queue); 21 | RUN_TEST_GROUP(QuickSort); 22 | RUN_TEST_GROUP(Scheduler); 23 | RUN_TEST_GROUP(SelectionSort); 24 | RUN_TEST_GROUP(Utils); 25 | RUN_TEST_GROUP(VernamCipher); 26 | } 27 | 28 | int 29 | main(int argc, const char* argv[]) { 30 | return UnityMain(argc, argv, RunAllTests); 31 | } 32 | -------------------------------------------------------------------------------- /Tests/test_merge_sort.c: -------------------------------------------------------------------------------- 1 | #include "merge_sort.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | #include "helper/sort_functions.h" 7 | 8 | TEST_GROUP(MergeSort); 9 | 10 | TEST_SETUP(MergeSort) { 11 | } 12 | 13 | TEST_TEAR_DOWN(MergeSort) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(MergeSort) { 17 | RUN_TEST_CASE(MergeSort, MergeSort_int32); 18 | RUN_TEST_CASE(MergeSort, MergeSort_float64); 19 | RUN_TEST_CASE(MergeSort, MergeSort_uint64); 20 | } 21 | 22 | TEST(MergeSort, MergeSort_int32) { 23 | int32_t unsorted_array[] = {5, 2, 3, 1000000, 9, 10, 11, 8, 9, 100}; 24 | const int32_t sorted_array[] = {2, 3, 5, 8, 9, 9, 10, 11, 100, 1000000}; 25 | MergeSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 26 | CompareInt32); 27 | 28 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 29 | TEST_ASSERT_EQUAL_INT32(sorted_array[i], unsorted_array[i]); 30 | } 31 | } 32 | 33 | TEST(MergeSort, MergeSort_float64) { 34 | float64_t unsorted_array[] = {5.8, 2.2, 3.1, 1.1, 9.1, 10.3, 11.2, 8.4, 9.2, 100.9}; 35 | const float64_t sorted_array[] = {1.1, 2.2, 3.1, 5.8, 8.4, 9.1, 9.2, 10.3, 11.2, 100.9}; 36 | MergeSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 37 | CompareFloat64); 38 | 39 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 40 | TEST_ASSERT_EQUAL_DOUBLE(sorted_array[i], unsorted_array[i]); 41 | } 42 | } 43 | 44 | TEST(MergeSort, MergeSort_uint64) { 45 | uint64_t unsorted_array[] = {1111111U, 55555555U, 44444U, 10000000000000U, 212121U, 1111U, 1U, 2U, 5U, 3U}; 46 | const uint64_t sorted_array[] = {1U, 2U, 3U, 5U, 1111U, 44444U, 212121U, 1111111U, 55555555U, 10000000000000U}; 47 | MergeSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 48 | CompareUint64); 49 | 50 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 51 | TEST_ASSERT_EQUAL_UINT64(sorted_array[i], unsorted_array[i]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tests/test_quick_sort.c: -------------------------------------------------------------------------------- 1 | #include "quick_sort.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | #include "helper/sort_functions.h" 7 | 8 | TEST_GROUP(QuickSort); 9 | 10 | TEST_SETUP(QuickSort) { 11 | } 12 | 13 | TEST_TEAR_DOWN(QuickSort) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(QuickSort) { 17 | RUN_TEST_CASE(QuickSort, QuickSort_int32); 18 | RUN_TEST_CASE(QuickSort, QuickSort_float64); 19 | RUN_TEST_CASE(QuickSort, QuickSort_uint64); 20 | } 21 | 22 | TEST(QuickSort, QuickSort_int32) { 23 | int32_t unsorted_array[] = {5, 2, 3, 1000000, 9, 10, 11, 8, 9, 100}; 24 | const int32_t sorted_array[] = {2, 3, 5, 8, 9, 9, 10, 11, 100, 1000000}; 25 | QuickSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 26 | CompareInt32); 27 | 28 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 29 | TEST_ASSERT_EQUAL_INT32(sorted_array[i], unsorted_array[i]); 30 | } 31 | } 32 | 33 | TEST(QuickSort, QuickSort_float64) { 34 | float64_t unsorted_array[] = {5.8, 2.2, 3.1, 1.1, 9.1, 10.3, 11.2, 8.4, 9.2, 100.9}; 35 | const float64_t sorted_array[] = {1.1, 2.2, 3.1, 5.8, 8.4, 9.1, 9.2, 10.3, 11.2, 100.9}; 36 | QuickSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 37 | CompareFloat64); 38 | 39 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 40 | TEST_ASSERT_EQUAL_DOUBLE(sorted_array[i], unsorted_array[i]); 41 | } 42 | } 43 | 44 | TEST(QuickSort, QuickSort_uint64) { 45 | uint64_t unsorted_array[] = {1111111U, 55555555U, 44444U, 10000000000000U, 212121U, 1111U, 1U, 2U, 5U, 3U}; 46 | const uint64_t sorted_array[] = {1U, 2U, 3U, 5U, 1111U, 44444U, 212121U, 1111111U, 55555555U, 10000000000000U}; 47 | QuickSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), sizeof(unsorted_array[0]), 48 | CompareUint64); 49 | 50 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 51 | TEST_ASSERT_EQUAL_UINT64(sorted_array[i], unsorted_array[i]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Tests/test_scheduler.c: -------------------------------------------------------------------------------- 1 | #include "scheduler.h" 2 | 3 | #include 4 | 5 | #include "unity.h" 6 | #include "unity_fixture.h" 7 | 8 | TEST_GROUP(Scheduler); 9 | 10 | TEST_SETUP(Scheduler) { 11 | } 12 | 13 | TEST_TEAR_DOWN(Scheduler) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(Scheduler) { 17 | RUN_TEST_CASE(Scheduler, Scheduler_run); 18 | } 19 | 20 | void 21 | Function1(void) { 22 | printf("\nFunction1 called"); 23 | } 24 | 25 | void 26 | Function2(void) { 27 | printf("\nFunction2 called"); 28 | } 29 | 30 | TEST(Scheduler, Scheduler_run) { 31 | SchedulerTask_t tasks[3]; 32 | SchedulerTask_t new_task; 33 | 34 | Scheduler_init(tasks, sizeof(tasks) / sizeof(tasks[0])); 35 | 36 | new_task.active = true; 37 | new_task.function = &Function1; 38 | TEST_ASSERT_TRUE(Scheduler_addTask(tasks, sizeof(tasks) / sizeof(tasks[0]), &new_task)); 39 | 40 | new_task.active = false; 41 | new_task.function = &Function2; 42 | TEST_ASSERT_TRUE(Scheduler_addTask(tasks, sizeof(tasks) / sizeof(tasks[0]), &new_task)); 43 | 44 | new_task.active = true; 45 | new_task.function = &Function2; 46 | TEST_ASSERT_TRUE(Scheduler_addTask(tasks, sizeof(tasks) / sizeof(tasks[0]), &new_task)); 47 | 48 | TEST_ASSERT_FALSE(Scheduler_addTask(tasks, sizeof(tasks) / sizeof(tasks[0]), &new_task)); 49 | 50 | tasks[2].function = NULL_PTR; 51 | Scheduler_run(tasks, sizeof(tasks) / sizeof(tasks[0])); 52 | } 53 | -------------------------------------------------------------------------------- /Tests/test_selection_sort.c: -------------------------------------------------------------------------------- 1 | #include "selection_sort.h" 2 | 3 | #include "unity.h" 4 | #include "unity_fixture.h" 5 | 6 | #include "helper/sort_functions.h" 7 | 8 | TEST_GROUP(SelectionSort); 9 | 10 | TEST_SETUP(SelectionSort) { 11 | } 12 | 13 | TEST_TEAR_DOWN(SelectionSort) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(SelectionSort) { 17 | RUN_TEST_CASE(SelectionSort, SelectionSort_int32); 18 | RUN_TEST_CASE(SelectionSort, SelectionSort_float64); 19 | RUN_TEST_CASE(SelectionSort, SelectionSort_uint64); 20 | } 21 | 22 | TEST(SelectionSort, SelectionSort_int32) { 23 | int32_t unsorted_array[] = {5, 2, 3, 1000000, 9, 10, 11, 8, 9, 100}; 24 | const int32_t sorted_array[] = {2, 3, 5, 8, 9, 9, 10, 11, 100, 1000000}; 25 | SelectionSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), 26 | sizeof(unsorted_array[0]), 27 | CompareInt32); 28 | 29 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 30 | TEST_ASSERT_EQUAL_INT32(sorted_array[i], unsorted_array[i]); 31 | } 32 | } 33 | 34 | TEST(SelectionSort, SelectionSort_float64) { 35 | float64_t unsorted_array[] = {5.8, 2.2, 3.1, 1.1, 9.1, 10.3, 11.2, 8.4, 9.2, 100.9}; 36 | const float64_t sorted_array[] = {1.1, 2.2, 3.1, 5.8, 8.4, 9.1, 9.2, 10.3, 11.2, 100.9}; 37 | SelectionSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), 38 | sizeof(unsorted_array[0]), 39 | CompareFloat64); 40 | 41 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 42 | TEST_ASSERT_EQUAL_DOUBLE(sorted_array[i], unsorted_array[i]); 43 | } 44 | } 45 | 46 | TEST(SelectionSort, SelectionSort_uint64) { 47 | uint64_t unsorted_array[] = {1111111U, 55555555U, 44444U, 10000000000000U, 212121U, 1111U, 1U, 2U, 5U, 3U}; 48 | const uint64_t sorted_array[] = {1U, 2U, 3U, 5U, 1111U, 44444U, 212121U, 1111111U, 55555555U, 10000000000000U}; 49 | SelectionSort_sort((byte_t*)unsorted_array, sizeof(unsorted_array) / sizeof(unsorted_array[0]), 50 | sizeof(unsorted_array[0]), 51 | CompareUint64); 52 | 53 | for (uint32_t i = 0U; i < (sizeof(unsorted_array) / sizeof(unsorted_array[0])); ++i) { 54 | TEST_ASSERT_EQUAL_UINT64(sorted_array[i], unsorted_array[i]); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tests/test_vernam_cipher.c: -------------------------------------------------------------------------------- 1 | #include "vernam_cipher.h" 2 | 3 | #include 4 | 5 | #include "unity.h" 6 | #include "unity_fixture.h" 7 | 8 | TEST_GROUP(VernamCipher); 9 | 10 | TEST_SETUP(VernamCipher) { 11 | } 12 | 13 | TEST_TEAR_DOWN(VernamCipher) { 14 | } 15 | 16 | TEST_GROUP_RUNNER(VernamCipher) { 17 | RUN_TEST_CASE(VernamCipher, VernamCipher_encryptDecrypt); 18 | } 19 | 20 | TEST(VernamCipher, VernamCipher_encryptDecrypt) { 21 | const char expected_result[] = "ReSuLt1a"; 22 | const char key1[] = "OSIJEK11"; 23 | const char key2[] = "OSijek!/"; 24 | char message[] = "ReSuLt1a"; 25 | TEST_ASSERT_TRUE(VernamCipher_encrypt(message, key1, (int32_t)strlen(key1))); 26 | TEST_ASSERT_TRUE(VernamCipher_decrypt(message, key1, (int32_t)strlen(key1))); 27 | TEST_ASSERT_EQUAL_STRING(expected_result, message); 28 | 29 | TEST_ASSERT_TRUE(VernamCipher_encrypt(message, key2, (int32_t)strlen(key2))); 30 | TEST_ASSERT_TRUE(VernamCipher_decrypt(message, key2, (int32_t)strlen(key2))); 31 | TEST_ASSERT_EQUAL_STRING(expected_result, message); 32 | 33 | TEST_ASSERT_FALSE(VernamCipher_encrypt(message, key1, 3)); 34 | TEST_ASSERT_FALSE(VernamCipher_decrypt(message, key1, 100)); 35 | } 36 | -------------------------------------------------------------------------------- /Tests/unity_config.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTS_UNITY_UNITY_CONFIG_H_ 2 | #define TESTS_UNITY_UNITY_CONFIG_H_ 3 | 4 | #define UNITY_INCLUDE_EXEC_TIME 5 | 6 | #if defined(_WIN32) 7 | #include 8 | #define UNITY_TIME_TYPE clock_t 9 | #define UNITY_GET_TIME(t) t = (clock_t)((clock() * 1000) / CLOCKS_PER_SEC) 10 | #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) 11 | #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) 12 | #define UNITY_PRINT_EXEC_TIME() { \ 13 | UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ 14 | UnityPrint(" ("); \ 15 | UnityPrintNumberUnsigned(execTimeMs); \ 16 | UnityPrint(" ms)"); \ 17 | } 18 | #elif defined(__unix__) || defined(__APPLE__) 19 | #include 20 | #define UNITY_TIME_TYPE struct timespec 21 | #define UNITY_GET_TIME(t) clock_gettime(CLOCK_MONOTONIC, &t) 22 | #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) 23 | #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) 24 | #define UNITY_PRINT_EXEC_TIME() { \ 25 | UNITY_UINT execTimeNs = ((Unity.CurrentTestStopTime.tv_sec - Unity.CurrentTestStartTime.tv_sec) * 1000L); \ 26 | execTimeNs += (Unity.CurrentTestStopTime.tv_nsec - Unity.CurrentTestStartTime.tv_nsec); \ 27 | UnityPrint(" ("); \ 28 | UnityPrintNumberUnsigned(execTimeNs); \ 29 | UnityPrint(" ns)"); \ 30 | } 31 | #endif 32 | 33 | #endif /* TESTS_UNITY_UNITY_CONFIG_H_ */ 34 | -------------------------------------------------------------------------------- /Tools/astyle/astylerc: -------------------------------------------------------------------------------- 1 | style=java 2 | indent=spaces=4 3 | indent-classes 4 | indent-switches 5 | indent-preproc-define 6 | indent-col1-comments 7 | 8 | attach-namespaces 9 | attach-classes 10 | attach-inlines 11 | attach-extern-c 12 | attach-closing-while 13 | 14 | pad-oper 15 | pad-comma 16 | pad-header 17 | 18 | align-pointer=type 19 | align-reference=type 20 | 21 | add-braces 22 | add-one-line-braces 23 | 24 | break-return-type 25 | 26 | convert-tabs 27 | max-code-length=120 28 | min-conditional-indent=0 29 | 30 | attach-closing-while 31 | 32 | mode=c 33 | lineend=windows 34 | suffix=none 35 | preserve-date 36 | formatted 37 | -------------------------------------------------------------------------------- /Tools/astyle/check_code_style.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | FILE=$1 4 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 5 | 6 | if [ -f "$FILE" ]; then 7 | CHECK_FAILED=$(${DIR}/fix_code_style.sh --dry-run --formatted $FILE) 8 | if [ -n "$CHECK_FAILED" ]; then 9 | ${DIR}/fix_code_style.sh --quiet < $FILE > $FILE.pretty 10 | 11 | echo 12 | git --no-pager diff --no-index --minimal --histogram --color=always $FILE $FILE.pretty 13 | rm -f $FILE.pretty 14 | echo 15 | 16 | if [[ $ASTYLE_FIX -eq 1 ]]; then 17 | ${DIR}/fix_code_style.sh $FILE 18 | else 19 | # Make sure this file is not staged for comitting 20 | git reset $FILE 21 | # Provide instructions 22 | echo $FILE 'bad formatting, please run "make format" or "./Tools/astyle/fix_code_style.sh' $FILE'"' 23 | exit 1 24 | fi 25 | fi 26 | fi 27 | -------------------------------------------------------------------------------- /Tools/astyle/check_code_style_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eu 3 | 4 | # Check for the latest astyle version 5 | ASTYLE_VER_REQUIRED_1="Artistic Style Version 2.06" 6 | ASTYLE_VER_REQUIRED_2="Artistic Style Version 3.0" 7 | ASTYLE_VER_REQUIRED_3="Artistic Style Version 3.0.1" 8 | ASTYLE_VER_REQUIRED_4="Artistic Style Version 3.1" 9 | 10 | astyle_ver() { 11 | echo "Project requires at least ${ASTYLE_VER_REQUIRED_1}" 12 | echo "You can get the correct version here: https://sourceforge.net/projects/astyle/files/astyle/astyle%202.06/" 13 | } 14 | 15 | # check if astyle is installed 16 | condition=$(which astyle 2>/dev/null | grep -v "not found" | wc -l) 17 | if [ $condition -eq 0 ]; then 18 | echo "astyle is not installed" 19 | astyle_ver 20 | exit 1 21 | else 22 | 23 | ASTYLE_VER=`astyle --version` 24 | 25 | if [ "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_1" -a \ 26 | "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_2" -a \ 27 | "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_3" -a \ 28 | "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_4" ] 29 | then 30 | echo "Error: you're using ${ASTYLE_VER}" 31 | echo "but should be using ${ASTYLE_VER_REQUIRED_1}, ${ASTYLE_VER_REQUIRED_2}, ${ASTYLE_VER_REQUIRED_3}, or ${ASTYLE_VER_REQUIRED_4} instead" 32 | exit 1 33 | fi 34 | fi 35 | 36 | CI="${CI:-false}" 37 | DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) 38 | 39 | if [[ "$@" == "--fix" ]]; then 40 | export ASTYLE_FIX=1 41 | fi 42 | 43 | 44 | # install git pre-commit hook 45 | HOOK_FILE="$DIR/../../.git/hooks/pre-commit" 46 | if [ ! -f $HOOK_FILE ] && [ "$CI" != "true" ]; then 47 | echo "" 48 | echo -e "\033[31mNinja tip: add a git pre-commit hook to automatically check code style\033[0m" 49 | echo -e "Would you like to install one now? (\033[94mcp ./Tools/astyle/pre-commit .git/hooks/pre-commit\033[0m): [y/\033[1mN\033[0m]" 50 | 51 | read user_cmd 52 | if [ "$user_cmd" == "y" ]; then 53 | echo -e "copying ./Tools/astyle/pre-commit -> .git/hooks/pre-commit" 54 | mkdir -p $DIR/../.git/hooks 55 | cp $DIR/pre-commit $HOOK_FILE 56 | echo -e "\033[94mGreat, hook installed!\033[0m (checking style now)" 57 | else 58 | echo -e "\033[94mOk, I will remind you again later!\033[0m (checking style now)" 59 | fi 60 | fi 61 | 62 | ${DIR}/files_to_check_code_style.sh | xargs -n 1 -P 8 -I % ${DIR}/check_code_style.sh % 63 | 64 | if [ $? -eq 0 ]; then 65 | echo "Format checks passed" 66 | exit 0 67 | fi 68 | -------------------------------------------------------------------------------- /Tools/astyle/files_to_check_code_style.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eu 3 | 4 | PATTERN="-e ." 5 | 6 | if [ $# -gt 0 ]; then 7 | PATTERN="$1" 8 | fi 9 | 10 | exec find Inc Src Tests \ 11 | -path Tests/Unity -prune -o \ 12 | -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) | grep $PATTERN 13 | -------------------------------------------------------------------------------- /Tools/astyle/fix_code_style.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -eq 0 ]] ; then 4 | exit 0 5 | fi 6 | 7 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 8 | astyle \ 9 | --options=$DIR/astylerc \ 10 | --preserve-date \ 11 | $* 12 | -------------------------------------------------------------------------------- /Tools/astyle/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # An example hook script to verify what is about to be committed. 4 | # Called by "git commit" with no arguments. The hook should 5 | # exit with non-zero status after issuing an appropriate message if 6 | # it wants to stop the commit. 7 | # 8 | # To enable this hook, rename this file to "pre-commit". 9 | 10 | if git rev-parse --verify HEAD >/dev/null 2>&1 11 | then 12 | against=HEAD 13 | else 14 | # Initial commit: diff against an empty tree object 15 | against=756d4242b68a1fd80883c578d3a6921f7ce56b9d 16 | fi 17 | 18 | # If you want to allow non-ascii filenames set this variable to true. 19 | allownonascii=$(git config hooks.allownonascii) 20 | 21 | # Redirect output to stderr. 22 | exec 1>&2 23 | 24 | # Cross platform projects tend to avoid non-ascii filenames; prevent 25 | # them from being added to the repository. We exploit the fact that the 26 | # printable range starts at the space character and ends with tilde. 27 | if [ "$allownonascii" != "true" ] && 28 | # Note that the use of brackets around a tr range is ok here, (it's 29 | # even required, for portability to Solaris 10's /usr/bin/tr), since 30 | # the square bracket bytes happen to fall in the designated range. 31 | test $(git diff --cached --name-only --diff-filter=A -z $against | 32 | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 33 | then 34 | echo "Pre-commit style error: Attempt to add a non-ascii file name." 35 | echo 36 | echo "This can cause problems if you want to work" 37 | echo "with people on other platforms." 38 | echo 39 | echo "To be portable it is advisable to rename the file ..." 40 | echo 41 | echo "If you know what you are doing you can disable this" 42 | echo "check using:" 43 | echo 44 | echo " git config hooks.allownonascii true" 45 | echo 46 | exit 1 47 | fi 48 | 49 | # If there are whitespace errors, print the offending file names and fail. 50 | #git diff-index --check --cached $against -- 51 | #if [ $? -ne 0 ]; then 52 | # echo "Pre-commit style error: Whitespace issues" 53 | # exit 1 54 | #fi 55 | 56 | # Check for code style, only in changed files 57 | for i in `git diff --cached --name-only --diff-filter=ACM` 58 | do 59 | ./Tools/astyle/files_to_check_code_style.sh $i | xargs -n 1 -P 8 -I % ./Tools/astyle/check_code_style.sh % 60 | if [ $? -ne 0 ] 61 | then 62 | echo "Pre-commit style error: Bad formatting according to astyle rules" 63 | exit 1 64 | fi 65 | done 66 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | cd "$(dirname "$0")" 6 | 7 | make all 8 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | cd "$(dirname "$0")" 6 | 7 | make clean 8 | -------------------------------------------------------------------------------- /prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | #cd "$(dirname "$0")" 6 | --------------------------------------------------------------------------------