Sample SPI drivers for a number of the Adesto Technologies flash devices.
helper_functions.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2018 Adesto Technologies Corporation, Inc
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted (subject to the limitations in the disclaimer below) provided
8  * that the following conditions are met:
9  *
10  * o Redistributions of source code must retain the above copyright notice, this list
11  * of conditions and the following disclaimer.
12  *
13  * o Redistributions in binary form must reproduce the above copyright notice, this
14  * list of conditions and the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  *
17  * o Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
42 #ifndef HELPER_FUNCTIONS_H_
43 #define HELPER_FUNCTIONS_H_
44 
45 #include <stdint.h>
46 #include <stdbool.h>
47 #include <stdio.h>
48 #include <stdlib.h>
58 void displayByteArray(uint8_t *byteArray, uint32_t numBytes);
59 
70 void fillArrayPattern(uint8_t * byteArray, uint32_t numBytes, int seedNumber);
71 
81 void fillArrayConst(uint8_t * byteArray, uint32_t numBytes, int constantNum);
82 
95 bool compareByteArrays(uint8_t *arr1, uint8_t *arr2, uint32_t arrLength);
96 
103 void load4BytesToTxBuffer(uint8_t *txBuffer, uint8_t opcode, uint32_t address);
104 
120 void printSPIExchange(uint8_t *txBuffer,
121  uint32_t txNumBytes,
122  uint8_t *rxBuffer,
123  uint32_t rxNumBytes);
124 
125 #endif /* HELPER_FUNCTIONS_H_ */
void load4BytesToTxBuffer(uint8_t *txBuffer, uint8_t opcode, uint32_t address)
Loads 1 byte of opcode followed by 3 address bytes into the txBuffer. The data is stored at the first...
void printSPIExchange(uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes)
Prints the byte array in hexadecimal with a formatted output. Indicates what bytes were sent...
void displayByteArray(uint8_t *byteArray, uint32_t numBytes)
Helper function to display a byte array/buffer. This function uses the printSPIExchange() function in...
void fillArrayPattern(uint8_t *byteArray, uint32_t numBytes, int seedNumber)
Helper function to display fill a byte array/buffer with a pattern based on a seedNumber. The seed will be incremented by the index of the array.
bool compareByteArrays(uint8_t *arr1, uint8_t *arr2, uint32_t arrLength)
Helper function to compare 2 byte arrays and print an error message if they do not match...
void fillArrayConst(uint8_t *byteArray, uint32_t numBytes, int constantNum)
Helper function to display fill a byte array/buffer with a constant number.