From 25919197305f2114a5792a33a8586651aab869c6 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Thu, 19 Jan 2023 13:44:42 -0800 Subject: [PATCH] Standardize Return Values for All Examples (#317) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [MSDK-911] MAX32520 return value update * [MSDK-918] MAX32572 return value update * [MSDK-919] MAX32650 return value update * [MSDK-920] MAX32655 return value update * [MSDK-921] MAX32660 return value update * [MSDK-922] MAX32662 return value update * [MSDK-923] MAX32665 return value update * [MSDK-924] MAX32670 return value update * [MSDK-925] MAX32672 return value update * [MSDK-926] MAX32675 return value update * [MSDK-935] MAX32680 return value update * [MSDK-937 ]MAX32690 return value update * [MSDK-938] MAX78000 return value update * [MSDK-939] MAX78002 return value update * [MSDK-987] Use mxc_errors for return values * MSDK-989: Review examples Signed-off-by: Sadik.Ozer Signed-off-by: Sadik.Ozer Co-authored-by: ANALOG\AKara Co-authored-by: Jake-Carter Co-authored-by: karaanil Co-authored-by: Sadik.Ozer --- Examples/MAX32520/AES/main.c | 9 +- Examples/MAX32520/CRC/main.c | 36 ++-- Examples/MAX32520/DMA/main.c | 61 +++---- Examples/MAX32520/Flash/main.c | 3 +- Examples/MAX32520/ICC/main.c | 3 +- Examples/MAX32520/SFE_Host/main.c | 11 +- Examples/MAX32520/SPI/main.c | 6 +- Examples/MAX32572/AES/main.c | 14 +- Examples/MAX32572/CRC/main.c | 37 ++-- Examples/MAX32572/DES/main.c | 42 +++-- Examples/MAX32572/DMA/main.c | 171 ++++++++---------- Examples/MAX32572/Flash/main.c | 14 +- Examples/MAX32572/Hash/main.c | 37 ++-- Examples/MAX32572/I2C/main.c | 4 +- Examples/MAX32572/ICC/main.c | 12 +- Examples/MAX32572/OWM/main.c | 30 +-- Examples/MAX32572/SDHC_Raw/main.c | 17 +- Examples/MAX32572/SMON/main.c | 1 + Examples/MAX32572/SPI/main.c | 6 +- Examples/MAX32572/SPIXF/main.c | 15 +- Examples/MAX32572/SPIXR/README.md | 2 +- Examples/MAX32572/SPIXR/main.c | 19 +- Examples/MAX32572/SRCC/README.md | 2 +- Examples/MAX32572/SRCC/main.c | 20 +- Examples/MAX32572/UART/README.md | 2 +- Examples/MAX32572/UART/main.c | 22 +-- Examples/MAX32572/WearLeveling/main.c | 8 +- Examples/MAX32650/AES/main.c | 9 +- Examples/MAX32650/CRC/main.c | 12 +- Examples/MAX32650/DES/main.c | 47 ++--- Examples/MAX32650/DMA/main.c | 51 +++--- Examples/MAX32650/EMCC/main.c | 20 +- Examples/MAX32650/Flash/main.c | 8 +- Examples/MAX32650/HBMC/main.c | 3 +- Examples/MAX32650/I2C/main.c | 24 +-- Examples/MAX32650/ICC/README.md | 2 +- Examples/MAX32650/ICC/main.c | 10 +- Examples/MAX32650/OWM/main.c | 9 +- Examples/MAX32650/SDHC_Raw/main.c | 17 +- Examples/MAX32650/SPI/main.c | 15 +- Examples/MAX32650/SPIMSS/main.c | 3 +- Examples/MAX32650/SPIXF/main.c | 16 +- Examples/MAX32650/SPIXF_ICC/main.c | 10 +- Examples/MAX32650/SPIXR/README.md | 1 + Examples/MAX32650/SPIXR/main.c | 29 ++- Examples/MAX32650/SPI_MasterSlave/main.c | 9 +- Examples/MAX32650/TRNG/main.c | 2 +- Examples/MAX32650/UART/README.md | 2 +- Examples/MAX32650/UART/main.c | 26 ++- Examples/MAX32650/WearLeveling/main.c | 6 +- Examples/MAX32655/AES/main.c | 24 +-- Examples/MAX32655/CRC/main.c | 28 ++- Examples/MAX32655/DMA/main.c | 65 +++---- Examples/MAX32655/FTHR_I2C/main.c | 1 - Examples/MAX32655/Flash/main.c | 13 +- Examples/MAX32655/Flash_CLI/main.c | 1 - Examples/MAX32655/I2C/main.c | 22 +-- Examples/MAX32655/I2C_SCAN/main.c | 2 +- Examples/MAX32655/I2S/main.c | 3 +- Examples/MAX32655/I2S_Playback/main.c | 1 - Examples/MAX32655/ICC/README.md | 2 +- Examples/MAX32655/ICC/main.c | 12 +- Examples/MAX32655/LP/main.c | 57 +++--- Examples/MAX32655/Pulse_Train/main.c | 2 +- Examples/MAX32655/SPI/main.c | 8 +- Examples/MAX32655/TMR/main.c | 2 +- Examples/MAX32655/UART/README.md | 2 +- Examples/MAX32655/UART/main.c | 26 ++- Examples/MAX32655/WearLeveling/main.c | 6 +- Examples/MAX32660/DMA/main.c | 51 +++--- Examples/MAX32660/Flash/main.c | 8 +- Examples/MAX32660/I2C/main.c | 21 +-- Examples/MAX32660/I2C_SCAN/main.c | 2 +- Examples/MAX32660/ICC/README.md | 2 +- Examples/MAX32660/ICC/main.c | 10 +- Examples/MAX32660/SPI/main.c | 5 +- Examples/MAX32660/SPIMSS/main.c | 11 +- Examples/MAX32660/SPI_MasterSlave/main.c | 5 +- Examples/MAX32660/UART/README.md | 2 +- Examples/MAX32660/UART/main.c | 27 +-- Examples/MAX32660/WearLeveling/main.c | 6 +- Examples/MAX32662/DMA/main.c | 58 +++--- Examples/MAX32662/Flash/main.c | 15 +- Examples/MAX32662/I2C/main.c | 20 +- Examples/MAX32662/I2C_SCAN/main.c | 2 +- Examples/MAX32662/I2S/main.c | 2 +- Examples/MAX32662/ICC/README.md | 2 +- Examples/MAX32662/ICC/main.c | 11 +- Examples/MAX32662/LP/main.c | 55 +++--- Examples/MAX32662/SPI/main.c | 5 +- Examples/MAX32662/SPI_MasterSlave/README.md | 2 +- Examples/MAX32662/SPI_MasterSlave/main.c | 5 +- Examples/MAX32662/UART/README.md | 2 +- Examples/MAX32662/UART/main.c | 26 +-- Examples/MAX32662/UART_Wakeup/main.c | 2 +- Examples/MAX32662/WearLeveling/main.c | 8 +- Examples/MAX32665/AES/main.c | 20 +- Examples/MAX32665/CRC/main.c | 19 +- Examples/MAX32665/DES/README.md | 2 +- Examples/MAX32665/DES/main.c | 8 +- Examples/MAX32665/DMA/main.c | 57 +++--- Examples/MAX32665/ECC/main.c | 10 +- Examples/MAX32665/Flash/main.c | 14 +- Examples/MAX32665/Flash_CLI/main.c | 1 - Examples/MAX32665/Hash/main.c | 32 ++-- Examples/MAX32665/I2C/main.c | 20 +- Examples/MAX32665/I2C_SCAN/main.c | 2 +- Examples/MAX32665/ICC/README.md | 2 +- Examples/MAX32665/ICC/main.c | 12 +- Examples/MAX32665/LP/main.c | 57 +++--- Examples/MAX32665/MAA/main.c | 15 +- Examples/MAX32665/OWM/main.c | 6 +- Examples/MAX32665/SDHC_Raw/main.c | 17 +- Examples/MAX32665/SPI/main.c | 19 +- Examples/MAX32665/SPIXF/main.c | 18 +- Examples/MAX32665/SPIXF_SFCC/main.c | 3 +- Examples/MAX32665/SPIXR/main.c | 20 +- Examples/MAX32665/SRCC/README.md | 2 +- Examples/MAX32665/SRCC/main.c | 21 ++- Examples/MAX32665/TMR/main.c | 5 +- Examples/MAX32665/UART/main.c | 26 ++- Examples/MAX32665/WearLeveling/main.c | 8 +- Examples/MAX32670/AES/main.c | 12 +- Examples/MAX32670/CRC/main.c | 26 ++- Examples/MAX32670/DMA/main.c | 59 +++--- Examples/MAX32670/Flash/main.c | 8 +- Examples/MAX32670/I2C/main.c | 21 +-- Examples/MAX32670/I2C_SCAN/main.c | 1 + Examples/MAX32670/ICC/README.md | 2 +- Examples/MAX32670/ICC/main.c | 10 +- Examples/MAX32670/LP/main.c | 55 +++--- Examples/MAX32670/SPI/main.c | 6 +- Examples/MAX32670/UART/README.md | 2 +- Examples/MAX32670/UART/main.c | 24 +-- Examples/MAX32670/WearLeveling/main.c | 6 +- Examples/MAX32672/AES/main.c | 20 +- Examples/MAX32672/CRC/main.c | 33 ++-- Examples/MAX32672/CTB_AES/main.c | 27 ++- Examples/MAX32672/DMA/main.c | 60 +++--- Examples/MAX32672/Flash/main.c | 9 +- Examples/MAX32672/I2C/main.c | 21 +-- Examples/MAX32672/ICC/README.md | 2 +- Examples/MAX32672/ICC/main.c | 10 +- Examples/MAX32672/SPI/main.c | 6 +- Examples/MAX32672/SPI_MasterSlave/README.md | 2 +- Examples/MAX32672/SPI_MasterSlave/main.c | 9 +- Examples/MAX32672/UART/README.md | 2 +- Examples/MAX32672/UART/main.c | 23 +-- Examples/MAX32672/WearLeveling/main.c | 6 +- Examples/MAX32675/AES/main.c | 24 +-- Examples/MAX32675/AFE_DAC/main.c | 1 - Examples/MAX32675/CRC/main.c | 30 ++- Examples/MAX32675/DMA/main.c | 59 +++--- Examples/MAX32675/Flash/main.c | 13 +- Examples/MAX32675/Flash_CLI/main.c | 1 - Examples/MAX32675/I2C/main.c | 20 +- Examples/MAX32675/I2C_SCAN/main.c | 1 + Examples/MAX32675/I2S/main.c | 1 - Examples/MAX32675/ICC/README.md | 2 +- Examples/MAX32675/ICC/main.c | 12 +- Examples/MAX32675/LP/main.c | 51 ++---- Examples/MAX32675/SPI/main.c | 19 +- Examples/MAX32675/UART/README.md | 2 +- Examples/MAX32675/UART/main.c | 24 ++- Examples/MAX32675/WearLeveling/main.c | 6 +- Examples/MAX32680/AES/main.c | 14 +- Examples/MAX32680/CRC/main.c | 30 ++- Examples/MAX32680/DMA/main.c | 68 +++---- Examples/MAX32680/Flash/main.c | 14 +- Examples/MAX32680/I2C/main.c | 21 +-- Examples/MAX32680/ICC/README.md | 2 +- Examples/MAX32680/ICC/main.c | 12 +- Examples/MAX32680/SPI/main.c | 6 +- Examples/MAX32680/UART/README.md | 2 +- Examples/MAX32680/UART/main.c | 26 ++- Examples/MAX32680/WearLeveling/main.c | 8 +- Examples/MAX32690/CRC/main.c | 33 ++-- Examples/MAX32690/CTB_AES/main.c | 32 ++-- Examples/MAX32690/DMA/main.c | 60 +++--- Examples/MAX32690/Flash/main.c | 8 +- Examples/MAX32690/Hash/main.c | 29 ++- Examples/MAX32690/I2C/main.c | 24 ++- Examples/MAX32690/ICC/README.md | 2 +- Examples/MAX32690/ICC/main.c | 10 +- Examples/MAX32690/SPI/main.c | 8 +- Examples/MAX32690/UART/README.md | 2 +- Examples/MAX32690/UART/main.c | 24 ++- Examples/MAX32690/WearLeveling/main.c | 6 +- Examples/MAX78000/AES/main.c | 19 +- Examples/MAX78000/CRC/main.c | 26 ++- Examples/MAX78000/DMA/main.c | 57 +++--- Examples/MAX78000/ECC/main.c | 8 +- Examples/MAX78000/Flash/main.c | 12 +- Examples/MAX78000/ICC/README.md | 2 +- Examples/MAX78000/ICC/main.c | 10 +- Examples/MAX78000/SPI/main.c | 18 +- Examples/MAX78000/UART/README.md | 2 +- Examples/MAX78000/UART/main.c | 20 +- Examples/MAX78000/WearLeveling/main.c | 6 +- Examples/MAX78002/AES/main.c | 21 +-- Examples/MAX78002/CRC/main.c | 26 ++- Examples/MAX78002/DMA/main.c | 64 +++---- Examples/MAX78002/ECC/main.c | 8 +- Examples/MAX78002/Flash/main.c | 8 +- Examples/MAX78002/I2C/main.c | 21 +-- Examples/MAX78002/ICC/README.md | 2 +- Examples/MAX78002/ICC/main.c | 10 +- Examples/MAX78002/SDHC_Raw/main.c | 19 +- Examples/MAX78002/SPI/main.c | 18 +- Examples/MAX78002/SPI_MasterSlave/README.md | 2 +- Examples/MAX78002/SPI_MasterSlave/main.c | 5 +- Examples/MAX78002/UART/main.c | 24 +-- Examples/MAX78002/WearLeveling/main.c | 8 +- .../Include/MAX32520/mxc_errors.h | 2 + .../Include/MAX32570/mxc_errors.h | 2 + .../Include/MAX32572/mxc_errors.h | 2 + .../Include/MAX32650/mxc_errors.h | 2 + .../Include/MAX32655/mxc_errors.h | 2 + .../Include/MAX32660/mxc_errors.h | 2 + .../Include/MAX32662/mxc_errors.h | 2 + .../Include/MAX32665/mxc_errors.h | 2 + .../Include/MAX32670/mxc_errors.h | 2 + .../Include/MAX32672/mxc_errors.h | 2 + .../Include/MAX32675/mxc_errors.h | 2 + .../Include/MAX32680/mxc_errors.h | 2 + .../Include/MAX32690/mxc_errors.h | 2 + .../Include/MAX78000/mxc_errors.h | 2 + .../Include/MAX78002/mxc_errors.h | 2 + 228 files changed, 1743 insertions(+), 1865 deletions(-) diff --git a/Examples/MAX32520/AES/main.c b/Examples/MAX32520/AES/main.c index 86929fab39a..413a60a6ea1 100644 --- a/Examples/MAX32520/AES/main.c +++ b/Examples/MAX32520/AES/main.c @@ -44,7 +44,6 @@ #include "mxc_device.h" #include "board.h" #include "ctb.h" -#include "ctb_regs.h" /***** Definitions *****/ @@ -414,11 +413,11 @@ int main(void) fail += AES256_ECB_dec(0); fail += AES256_ECB_dec(1); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32520/CRC/main.c b/Examples/MAX32520/CRC/main.c index fb5d0ba3eb6..245b1518283 100644 --- a/Examples/MAX32520/CRC/main.c +++ b/Examples/MAX32520/CRC/main.c @@ -43,7 +43,6 @@ #include "mxc_device.h" #include "board.h" #include "ctb.h" -#include "ctb_regs.h" /***** Definitions *****/ #define POLY 0xEDB88320 @@ -65,16 +64,7 @@ void Test_Callback(void *req, int result) callback_result = result; } -void Test_Result(int result) -{ - if (result) { - printf(" * Failed *\n"); - } else { - printf(" Passed \n"); - } -} - -void Test_CRC(int asynchronous) +int Test_CRC(int asynchronous) { uint32_t array[101]; int i; @@ -116,15 +106,31 @@ void Test_CRC(int asynchronous) MXC_CTB_CRC_Compute(&crc_req); } - Test_Result(CHECK != crc_req.resultCRC); MXC_CTB_Shutdown(MXC_CTB_FEATURE_CRC | MXC_CTB_FEATURE_DMA); + + if (CHECK != crc_req.resultCRC) { + printf(" * Failed *\n"); + return -1; + } + + printf(" Passed \n"); + return 0; } // ***************************************************************************** int main(void) { - Test_CRC(0); - Test_CRC(1); + int fail = 0; + printf("\n***** CRC Example *****\n"); - return 0; + fail += Test_CRC(0); + fail += Test_CRC(1); + + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32520/DMA/main.c b/Examples/MAX32520/DMA/main.c index 5abd53c08a6..a0c82864772 100644 --- a/Examples/MAX32520/DMA/main.c +++ b/Examples/MAX32520/DMA/main.c @@ -44,7 +44,6 @@ #include #include "mxc_device.h" #include "dma.h" -#include "dma_regs.h" /***** Definitions *****/ @@ -54,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; int channels[MAX_CHANNEL]; /***** Functions *****/ @@ -75,8 +73,9 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { + int fail = 0; printf("Transfer from memory to memory.\n"); int retval; @@ -96,34 +95,31 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { + int fail = 0; printf("\nTransfer with Reload and Callback.\n"); int i, retval; @@ -194,9 +190,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -204,8 +197,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -213,23 +205,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { - printf("\nExample failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32520/Flash/main.c b/Examples/MAX32520/Flash/main.c index 0d1d111a0ab..0f50d57c64b 100644 --- a/Examples/MAX32520/Flash/main.c +++ b/Examples/MAX32520/Flash/main.c @@ -383,7 +383,8 @@ int main(void) printf("\nExample Succeeded\n"); } else { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32520/ICC/main.c b/Examples/MAX32520/ICC/main.c index 93467774ce5..d352b5a0ffd 100644 --- a/Examples/MAX32520/ICC/main.c +++ b/Examples/MAX32520/ICC/main.c @@ -155,7 +155,8 @@ int main(void) printf("\nEXAMPLE SUCCEEDED\n"); } else { printf("\nEXAMPLE FAILED\n"); + return E_FAIL; } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32520/SFE_Host/main.c b/Examples/MAX32520/SFE_Host/main.c index 5dc8896758c..53470f4eca3 100644 --- a/Examples/MAX32520/SFE_Host/main.c +++ b/Examples/MAX32520/SFE_Host/main.c @@ -86,17 +86,17 @@ int main(void) printf("SPI1 pins to SFE Slave device. You can test RAM\n"); printf("or Flash write and read loopback\n"); + int ret = E_NO_ERROR; + // Configure the peripheral if (MXC_SPI_Init(MASTER_SPI, 1, 0, 1, 0, MASTER_SPI_SPEED) != E_NO_ERROR) { printf("\nError configuring SPI\n"); - - while (1) {} + return E_UNINITIALIZED; } if (MXC_SPI_SetDataSize(MASTER_SPI, 8) != E_NO_ERROR) { printf("\nError setting Data size\n"); - - while (1) {} + return E_FAIL; } // Initialize RX buffer to store data @@ -142,9 +142,10 @@ int main(void) printf("\nData Verified\n"); } else { printf("\nData Not Verified\n"); + ret = E_FAIL; } MXC_SPI_Shutdown(MASTER_SPI); - return 0; + return ret; } diff --git a/Examples/MAX32520/SPI/main.c b/Examples/MAX32520/SPI/main.c index 8881d2089f8..3e80a4e7502 100644 --- a/Examples/MAX32520/SPI/main.c +++ b/Examples/MAX32520/SPI/main.c @@ -115,10 +115,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32572/AES/main.c b/Examples/MAX32572/AES/main.c index 26efbf3c275..ef12aedc182 100644 --- a/Examples/MAX32572/AES/main.c +++ b/Examples/MAX32572/AES/main.c @@ -412,15 +412,11 @@ int main(void) fail += AES256_ECB_dec(0); fail += AES256_ECB_dec(1); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/CRC/main.c b/Examples/MAX32572/CRC/main.c index 66025e8e94f..f81750f17ef 100644 --- a/Examples/MAX32572/CRC/main.c +++ b/Examples/MAX32572/CRC/main.c @@ -63,17 +63,9 @@ void Test_Callback(void *req, int result) callback_result = result; } -void Test_Result(int result) -{ - if (result) { - printf(" * Failed *\n"); - } else { - printf(" Passed \n"); - } -} - -void Test_CRC(int asynchronous) +int Test_CRC(int asynchronous) { + int ret; uint32_t array[101]; int i; @@ -114,15 +106,32 @@ void Test_CRC(int asynchronous) MXC_CTB_CRC_Compute(&crc_req); } - Test_Result(CHECK != crc_req.resultCRC); + if (CHECK != crc_req.resultCRC) { + printf(" * Failed *\n"); + ret = -1; + } else { + printf(" Passed \n"); + ret = 0; + } + MXC_CTB_Shutdown(MXC_CTB_FEATURE_CRC | MXC_CTB_FEATURE_DMA); + return ret; } // ***************************************************************************** int main(void) { - Test_CRC(0); - Test_CRC(1); + int fail = 0; + printf("\n***** CRC Example *****\n"); + + fail += Test_CRC(0); + fail += Test_CRC(1); + + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/DES/main.c b/Examples/MAX32572/DES/main.c index 6b5cb8027cc..ea691af7680 100644 --- a/Examples/MAX32572/DES/main.c +++ b/Examples/MAX32572/DES/main.c @@ -122,7 +122,7 @@ int DES_check(char *calculated, char *expected, int len) return -1; } -void DES_ECB_enc(int asynchronous) +int DES_ECB_enc(int asynchronous) { char *xkey = "2f5d4b8c12a4a9c1"; char key[MXC_DES_KEY_LEN]; @@ -162,10 +162,10 @@ void DES_ECB_enc(int asynchronous) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); + return DES_check(result, expected, MXC_DES_DATA_LEN); } -void DES_ECB_dec(int asynchronous) +int DES_ECB_dec(int asynchronous) { char *xkey = "00c3de5446614d35"; char key[MXC_DES_KEY_LEN]; @@ -205,10 +205,10 @@ void DES_ECB_dec(int asynchronous) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); + return DES_check(result, expected, MXC_DES_DATA_LEN); } -void TDES_ECB_enc(int asynchronous) +int TDES_ECB_enc(int asynchronous) { char *xkey = "2f5d4b8c12a4a9c1"; char key[MXC_DES_KEY_LEN]; @@ -248,10 +248,10 @@ void TDES_ECB_enc(int asynchronous) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); + return DES_check(result, expected, MXC_DES_DATA_LEN); } -void TDES_ECB_dec(int asynchronous) +int TDES_ECB_dec(int asynchronous) { char *xkey = "00c3de5446614d35"; char key[MXC_DES_KEY_LEN]; @@ -291,7 +291,7 @@ void TDES_ECB_dec(int asynchronous) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); + return DES_check(result, expected, MXC_DES_DATA_LEN); } // ***************************************************************************** @@ -299,18 +299,26 @@ int main(void) { printf("\n***** DES Example *****\n"); + int fail = 0; + printf("DES ECB Encryption ... "); - DES_ECB_enc(0); - DES_ECB_enc(1); + fail += DES_ECB_enc(0); + fail += DES_ECB_enc(1); printf("DES ECB Decryption ... "); - DES_ECB_dec(0); - DES_ECB_dec(1); + fail += DES_ECB_dec(0); + fail += DES_ECB_dec(1); printf("Triple DES ECB Encryption ... "); - TDES_ECB_enc(0); - TDES_ECB_enc(1); + fail += TDES_ECB_enc(0); + fail += TDES_ECB_enc(1); printf("Triple DES ECB Decryption ... "); - TDES_ECB_dec(0); - TDES_ECB_dec(1); + fail += TDES_ECB_dec(0); + fail += TDES_ECB_dec(1); + + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - printf("\nExample complete.\n"); + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/DMA/main.c b/Examples/MAX32572/DMA/main.c index 7ebd819c38a..5d0062d9a16 100644 --- a/Examples/MAX32572/DMA/main.c +++ b/Examples/MAX32572/DMA/main.c @@ -52,7 +52,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -73,10 +72,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -94,88 +93,84 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - // //Demo of acquiring channels - // for (i = 0; i < MAX_CHANNEL; ++i) { - // retval = MXC_DMA_AcquireChannel(); - // if (retval == E_BAD_STATE) { - // printf("Failed to acquire channel: %d\n", i); - // while(1); - // } - // channels[i] = retval; - // } - - // //Only keeping the first channel [0] for use - // for (i = 1; i < MAX_CHANNEL; ++i) { - // retval = MXC_DMA_ReleaseChannel(channels[i]); - // if (retval != E_NO_ERROR) { - // printf("Failed to release channel %d\n", i); - // while(1); - // } - // } - - // mxc_dma_srcdst_t firstTransfer; - // firstTransfer.ch = channels[0]; - // firstTransfer.source = srcdata; - // firstTransfer.dest = dstdata; - // firstTransfer.len = MAX_SIZE; - - // mxc_dma_config_t config; - // config.ch = channels[0]; - // config.reqsel = MXC_DMA_REQUEST_MEMTOMEM; - // config.srcwd = MXC_DMA_WIDTH_WORD; - // config.dstwd = MXC_DMA_WIDTH_WORD; - // config.srcinc_en = 1; - // config.dstinc_en = 1; - - // retval = MXC_DMA_ConfigChannel(config, firstTransfer); - - // if (retval != E_NO_ERROR) { - // printf("Failed to config channel\n"); - // while(1); - // } - - // printf("Starting transfer\n"); - - // if (MXC_DMA_Start(channels[0]) != E_NO_ERROR) { - // printf("Failed to start.\n"); - // while(1); - // } - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + // //Demo of acquiring channels + // for (i = 0; i < MAX_CHANNEL; ++i) { + // retval = MXC_DMA_AcquireChannel(); + // if (retval == E_BAD_STATE) { + // printf("Failed to acquire channel: %d\n", i); + // while(1); + // } + // channels[i] = retval; + // } + + // //Only keeping the first channel [0] for use + // for (i = 1; i < MAX_CHANNEL; ++i) { + // retval = MXC_DMA_ReleaseChannel(channels[i]); + // if (retval != E_NO_ERROR) { + // printf("Failed to release channel %d\n", i); + // while(1); + // } + // } + + // mxc_dma_srcdst_t firstTransfer; + // firstTransfer.ch = channels[0]; + // firstTransfer.source = srcdata; + // firstTransfer.dest = dstdata; + // firstTransfer.len = MAX_SIZE; + + // mxc_dma_config_t config; + // config.ch = channels[0]; + // config.reqsel = MXC_DMA_REQUEST_MEMTOMEM; + // config.srcwd = MXC_DMA_WIDTH_WORD; + // config.dstwd = MXC_DMA_WIDTH_WORD; + // config.srcinc_en = 1; + // config.dstinc_en = 1; + + // retval = MXC_DMA_ConfigChannel(config, firstTransfer); + + // if (retval != E_NO_ERROR) { + // printf("Failed to config channel\n"); + // while(1); + // } + + // printf("Starting transfer\n"); + + // if (MXC_DMA_Start(channels[0]) != E_NO_ERROR) { + // printf("Failed to start.\n"); + // while(1); + // } + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } + + // if (MXC_DMA_ReleaseChannel(channels[0]) != E_NO_ERROR) { + // printf("Failed to release channel 0\n"); + // while(1); + // } } - // if (MXC_DMA_ReleaseChannel(channels[0]) != E_NO_ERROR) { - // printf("Failed to release channel 0\n"); - // while(1); - // } - free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -244,9 +239,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -254,8 +246,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -263,29 +254,25 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); - - printf("\n"); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example failed\n"); + fail += example1(); + fail += example2(); - while (1) {} + if (fail != 0) { + printf("\nExample failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/Flash/main.c b/Examples/MAX32572/Flash/main.c index c9006731821..8e5cdb08d3a 100644 --- a/Examples/MAX32572/Flash/main.c +++ b/Examples/MAX32572/Flash/main.c @@ -409,15 +409,11 @@ int main(void) MXC_ICC_Enable(); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/Hash/main.c b/Examples/MAX32572/Hash/main.c index a4c90c2a50d..8f26c9273bb 100644 --- a/Examples/MAX32572/Hash/main.c +++ b/Examples/MAX32572/Hash/main.c @@ -62,15 +62,6 @@ void Test_Callback(void *req, int result) callback_result = result; } -void Test_Result(int result) -{ - if (result) { - printf(" * Failed *\n\n"); - } else { - printf(" Passed \n\n"); - } -} - void ascii_to_byte(const char *src, char *dst, int len) { int i; @@ -86,8 +77,9 @@ void ascii_to_byte(const char *src, char *dst, int len) } } -void Test_Hash(int asynchronous) +int Test_Hash(int asynchronous) { + int ret; printf(asynchronous ? "Test Hash Async\n" : "Test Hash Sync\n"); unsigned char sha256_msg[] = @@ -120,20 +112,33 @@ void Test_Hash(int asynchronous) MXC_CTB_Hash_Compute(&hash_req); } - Test_Result(memcmp(sha256_result, destination, 32)); + if (memcmp(sha256_result, destination, 32)) { + printf(" * Failed *\n\n"); + ret = -1; + } else { + printf(" Passed \n\n"); + ret = 0; + } + MXC_CTB_Shutdown(MXC_CTB_FEATURE_HASH); - return; + return ret; } int main(void) { printf("\n\n********** CTB Hash Example **********\n\n"); - Test_Hash(0); - Test_Hash(1); + int fail = 0; + + fail += Test_Hash(0); + fail += Test_Hash(1); - printf("\n*** Done ***\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/I2C/main.c b/Examples/MAX32572/I2C/main.c index a0306203be8..014af8e2248 100644 --- a/Examples/MAX32572/I2C/main.c +++ b/Examples/MAX32572/I2C/main.c @@ -298,9 +298,9 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); LED_On(0); - return PASSED; + return 0; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return -1; } } diff --git a/Examples/MAX32572/ICC/main.c b/Examples/MAX32572/ICC/main.c index 1dabe42910f..59f1cefa4c5 100644 --- a/Examples/MAX32572/ICC/main.c +++ b/Examples/MAX32572/ICC/main.c @@ -150,13 +150,11 @@ int main(void) fail += 1; } - printf("\n\n"); - - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/OWM/main.c b/Examples/MAX32572/OWM/main.c index 8ff28006fe3..a126ea91788 100644 --- a/Examples/MAX32572/OWM/main.c +++ b/Examples/MAX32572/OWM/main.c @@ -39,8 +39,6 @@ #include // Local global variables -int pass; -int fail; uint8_t utilcrc8; static uint8_t dscrc_table[] = { 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, 157, 195, 33, @@ -59,19 +57,6 @@ static uint8_t dscrc_table[] = { 247, 182, 232, 10, 84, 215, 137, 107, 53 }; -void Pass(void) -{ - pass++; -} -void Fail(void) -{ - fail++; -} -void Done(void) -{ - while (1) {} -} - //-------------------------------------------------------------------------- // Reset crc8 to the value passed in // @@ -161,8 +146,6 @@ int32_t ow_romid_test(uint8_t od) int main(void) { - pass = 0; - fail = 0; int retval = 0; printf("***** 1-Wire ROM (DS2401) Example *****\n"); @@ -176,15 +159,12 @@ int main(void) MXC_OWM_Init(&owm_cfg); /* Test overdrive */ - if ((retval = ow_romid_test(1))) { - Fail(); + if (retval = ow_romid_test(1)) { printf("Overdrive results: %d; %08x; %08x \n", retval, MXC_OWM->cfg, MXC_OWM->intfl); - printf("Example Failed\n"); - } else { - Pass(); - printf("Example Succeeded\n"); + printf("\nExample Failed\n"); + return E_FAIL; } - Done(); - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/SDHC_Raw/main.c b/Examples/MAX32572/SDHC_Raw/main.c index 739975c3baf..269324dc9f0 100644 --- a/Examples/MAX32572/SDHC_Raw/main.c +++ b/Examples/MAX32572/SDHC_Raw/main.c @@ -240,6 +240,7 @@ int multi_block_check(unsigned int width) /******************************************************************************/ int main(void) { + int fail = 0; mxc_sdhc_cfg_t cfg; int result; @@ -271,6 +272,7 @@ int main(void) printf("Card Initialized.\n"); } else { printf("No card response!\n"); + fail += 1; } if (MXC_SDHC_Lib_Get_Card_Type() == CARD_SDHC) { @@ -293,18 +295,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -314,18 +319,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -334,9 +342,16 @@ int main(void) if (multi_block_check(MXC_SDHC_LIB_QUAD_DATA)) { printf(" FAIL \n"); + fail += 1; } else { printf(" PASS \n"); } - printf(" *** END OF EXAMPLE *** \n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/SMON/main.c b/Examples/MAX32572/SMON/main.c index d283585d0f9..b85fb5ed29d 100644 --- a/Examples/MAX32572/SMON/main.c +++ b/Examples/MAX32572/SMON/main.c @@ -128,4 +128,5 @@ int main(void) Test2(); printf("\nExample Completed\n\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/SPI/main.c b/Examples/MAX32572/SPI/main.c index 4d55c39de78..ec1f6f76bf1 100644 --- a/Examples/MAX32572/SPI/main.c +++ b/Examples/MAX32572/SPI/main.c @@ -110,10 +110,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32572/SPIXF/main.c b/Examples/MAX32572/SPIXF/main.c index e04d5064e25..1740e449d45 100644 --- a/Examples/MAX32572/SPIXF/main.c +++ b/Examples/MAX32572/SPIXF/main.c @@ -121,7 +121,7 @@ int main(void) if (Ext_Flash_Init() != E_NO_ERROR) { printf("Board Init Failed\n"); printf("Example Failed\n"); - while (1) {} + return -1; } printf("External flash Initialized.\n\n"); @@ -133,7 +133,7 @@ int main(void) } else { printf("Error verifying external flash ID: 0x%x\n", id); printf("Example Failed\n"); - while (1) {} + return -1; } int err; @@ -199,10 +199,11 @@ int main(void) func(); printf("Returned from external flash\n\n"); - if (fail == 0) { - printf("Example Succeeded\n\n"); - } else { - printf("Example Failed\n\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/SPIXR/README.md b/Examples/MAX32572/SPIXR/README.md index cbb05698e99..155b73ea2fa 100644 --- a/Examples/MAX32572/SPIXR/README.md +++ b/Examples/MAX32572/SPIXR/README.md @@ -28,5 +28,5 @@ RX BUFFER: 0 2d cf 46 29 4 b4 78 d8 68 a7 ff 3f 2b f1 fc DATA IS VERIFIED. -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32572/SPIXR/main.c b/Examples/MAX32572/SPIXR/main.c index a627c755cce..4b89fc79415 100644 --- a/Examples/MAX32572/SPIXR/main.c +++ b/Examples/MAX32572/SPIXR/main.c @@ -77,8 +77,7 @@ void setup(void) if (MXC_SPIXR_Init(&init_cfg) != E_NO_ERROR) { printf("\nSPIXR was not initialized properly.\n"); printf("\nExample Failed\n"); - - while (1) {} + return E_UNINITIALIZED; } MXC_GCR->sysctrl |= MXC_F_GCR_SYSCTRL_SRCC_DIS; @@ -104,6 +103,8 @@ void setup(void) MXC_SPIXR_ExMemSetReadCommand(A1024_READ); MXC_SPIXR_ExMemSetWriteCommand(A1024_WRITE); MXC_SPIXR_ExMemEnable(); + + return E_NO_ERROR; } // ***************************************************************************** @@ -126,7 +127,9 @@ int main(void) // Configure the SPIXR printf("\nSetting up the SPIXR\n"); - setup(); + if (E_NO_ERROR != setup()) { + fail += 1; + } // Initialize & write pseudo-random data to be written to the RAM printf("\nTX BUFFER:\t "); @@ -159,11 +162,11 @@ int main(void) printf("\n\nDATA IS VERIFIED.\n\n"); } - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/SRCC/README.md b/Examples/MAX32572/SRCC/README.md index 9c6b42c18c7..cfe1cf6e79e 100644 --- a/Examples/MAX32572/SRCC/README.md +++ b/Examples/MAX32572/SRCC/README.md @@ -17,5 +17,5 @@ The Console UART of the device will output these messages: Running test reads with data cache enabled. Time elapsed: 0.3587 Running test reads with data cache disabled. Time elapsed: 4.2092 -Example complete. +Example Succeeded. ``` diff --git a/Examples/MAX32572/SRCC/main.c b/Examples/MAX32572/SRCC/main.c index 070aacef9d9..8fdf53d2964 100644 --- a/Examples/MAX32572/SRCC/main.c +++ b/Examples/MAX32572/SRCC/main.c @@ -58,6 +58,7 @@ #define ITERATIONS 5000 /***** Globals *****/ +int fail = 0; int s, ss; mxc_spixr_cfg_t init_cfg = { @@ -71,14 +72,14 @@ mxc_spixr_cfg_t init_cfg = { /***** Functions *****/ -void setup(void) +int setup(void) { uint8_t quad_cmd = A1024_EQIO; /* pre-defined command to use quad mode */ // Initialize the desired configuration if (MXC_SPIXR_Init(&init_cfg) != E_NO_ERROR) { printf("FAILED: SPIXR was not initialized properly.\n"); - return; + return E_UNINITIALIZED; } /* Hide this with function in SPIXR.C later */ @@ -103,6 +104,8 @@ void setup(void) MXC_SPIXR_ExMemSetReadCommand(A1024_READ); MXC_SPIXR_ExMemSetWriteCommand(A1024_WRITE); MXC_SPIXR_ExMemEnable(); + + return E_NO_ERROR; } void start_timer(void) @@ -132,7 +135,9 @@ void test_function(void) unsigned int seed = 0; // Configure the SPIXR - setup(); + if (E_NO_ERROR != setup()) { + fail += 1; + } // Initialize & write pseudo-random data to be written to the RAM for (i = 0; i < BUFFER_SIZE; i++) { @@ -153,6 +158,7 @@ void test_function(void) // Verify data being read from RAM if (memcmp(write_buffer, read_buffer, BUFFER_SIZE)) { printf("FAILED: Data was not read properly.\n\n"); + fail += 1; break; } } @@ -178,7 +184,11 @@ int main(void) MXC_SRCC_Disable(); test_function(); - printf("Example complete.\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/UART/README.md b/Examples/MAX32572/UART/README.md index cd849c0c294..d96a34162a7 100644 --- a/Examples/MAX32572/UART/README.md +++ b/Examples/MAX32572/UART/README.md @@ -34,7 +34,7 @@ P1.12 -> P1.21 and P1.13 -> P1.20 -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` The LED (P2.17) will illuminate to indicate the success of the test. diff --git a/Examples/MAX32572/UART/main.c b/Examples/MAX32572/UART/main.c index d655e1a16c2..3499cbd0f89 100644 --- a/Examples/MAX32572/UART/main.c +++ b/Examples/MAX32572/UART/main.c @@ -126,13 +126,13 @@ int main(void) if ((error = MXC_UART_Init(MXC_UART1, UART_BAUD)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return -1; } if ((error = MXC_UART_Init(MXC_UART3, UART_BAUD)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return -1; } printf("-->UART Initialized\n\n"); @@ -165,7 +165,7 @@ int main(void) printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return -1; } error = MXC_UART_Transaction(&write_req); @@ -174,7 +174,7 @@ int main(void) printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return -1; } #ifdef DMA @@ -199,14 +199,12 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - LED_On(0); - printf("-->EXAMPLE SUCCEEDED\n"); - } else { - printf("-->EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + LED_On(0); + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32572/WearLeveling/main.c b/Examples/MAX32572/WearLeveling/main.c index f35f01fc980..e4680bbe904 100644 --- a/Examples/MAX32572/WearLeveling/main.c +++ b/Examples/MAX32572/WearLeveling/main.c @@ -184,11 +184,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/AES/main.c b/Examples/MAX32650/AES/main.c index 2b8a1b5a437..9f6c83a3d8a 100644 --- a/Examples/MAX32650/AES/main.c +++ b/Examples/MAX32650/AES/main.c @@ -42,6 +42,7 @@ #include #include #include "mxc_device.h" +#include "mxc_errors.h" #include "board.h" #include "tpu.h" @@ -272,11 +273,11 @@ int main(void) fail += AES256_ECB_enc(); fail += AES256_ECB_dec(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/CRC/main.c b/Examples/MAX32650/CRC/main.c index 6ecb1d85b66..a58f4ec8721 100644 --- a/Examples/MAX32650/CRC/main.c +++ b/Examples/MAX32650/CRC/main.c @@ -83,7 +83,7 @@ int main(void) if (MXC_TPU_CRC_Config() != E_SUCCESS) { printf("Failed CRYPTO_Crc_Config()\n"); - return -1; + return E_FAIL; } printf("CRC16:\n"); @@ -94,7 +94,7 @@ int main(void) //Generate hardware result if (MXC_TPU_CRC(data, len, MXC_TPU_CRC16, &hw_crc) != E_SUCCESS) { printf("Failed CRYPTO_CRC()\n"); - return -1; + return E_FAIL; } printf("Calculated CRC = 0x%08x\n", hw_crc); @@ -102,6 +102,7 @@ int main(void) if (hw_crc != sw_crc) { printf("CRC Failed!\n"); + return E_FAIL; } else { printf("CRC Passed!\n"); } @@ -111,7 +112,7 @@ int main(void) //Call CRYPTO_Crc_Config() again to reset if (MXC_TPU_CRC_Config() != E_SUCCESS) { printf("Failed CRYPTO_Crc_Config()\n"); - return -1; + return E_FAIL; } printf("CRC32:\n"); @@ -122,7 +123,7 @@ int main(void) //Generate hardware result if (MXC_TPU_CRC(data, len, MXC_TPU_CRC32_ETHERNET, &hw_crc) != E_SUCCESS) { printf("Failed CRYPTO_CRC()\n"); - return -1; + return E_FAIL; } printf("Calculated CRC = 0x%08x\n", hw_crc); @@ -130,11 +131,12 @@ int main(void) if (hw_crc != sw_crc) { printf("CRC Failed!\n"); + return E_FAIL; } else { printf("CRC Passed!\n"); } printf("\nExample complete.\n"); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32650/DES/main.c b/Examples/MAX32650/DES/main.c index b10627e3600..06132e2fd91 100644 --- a/Examples/MAX32650/DES/main.c +++ b/Examples/MAX32650/DES/main.c @@ -77,7 +77,7 @@ void ascii_to_byte(const char *src, char *dst, int len) } /* Verify by comparing calculated to expected */ -void DES_check(char *calculated, char *expected, int len) +int DES_check(char *calculated, char *expected, int len) { int i, fail = 0; @@ -89,14 +89,14 @@ void DES_check(char *calculated, char *expected, int len) if (fail > 0) { printf("Fail.\n"); - } else { - printf("Pass.\n"); + return -1; } - return; + printf("Pass.\n"); + return 0; } -void DES_ECB_enc(void) +int DES_ECB_enc(void) { char *xkey = "2f5d4b8c12a4a9c1"; char key[MXC_DES_KEY_LEN]; @@ -116,11 +116,10 @@ void DES_ECB_enc(void) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); - return; + return DES_check(result, expected, MXC_DES_DATA_LEN); } -void DES_ECB_dec(void) +int DES_ECB_dec(void) { char *xkey = "00c3de5446614d35"; char key[MXC_DES_KEY_LEN]; @@ -142,11 +141,10 @@ void DES_ECB_dec(void) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); - return; + return DES_check(result, expected, MXC_DES_DATA_LEN); } -void TDES_ECB_enc(void) +int TDES_ECB_enc(void) { char *xkey = "0fb5b906471296bc1ab269585e1c99dcf10dd7b047cdee29"; char key[MXC_TDES_KEY_LEN]; @@ -168,11 +166,10 @@ void TDES_ECB_enc(void) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); - return; + return DES_check(result, expected, MXC_DES_DATA_LEN); } -void TDES_ECB_dec(void) +int TDES_ECB_dec(void) { char *xkey = "2e0a67fe76bc3d3c1081c45a48784f49c876033acc85f69c"; char key[MXC_TDES_KEY_LEN]; @@ -192,8 +189,7 @@ void TDES_ECB_dec(void) ascii_to_byte(xexpected, expected, MXC_DES_DATA_LEN); - DES_check(result, expected, MXC_DES_DATA_LEN); - return; + return DES_check(result, expected, MXC_DES_DATA_LEN); } // ***************************************************************************** @@ -201,15 +197,22 @@ int main(void) { printf("\n***** DES Example *****\n"); + int fail = 0; + printf("DES ECB Encryption ... "); - DES_ECB_enc(); + fail += DES_ECB_enc(); printf("DES ECB Decryption ... "); - DES_ECB_dec(); + fail += DES_ECB_dec(); printf("Triple DES ECB Encryption ... "); - TDES_ECB_enc(); + fail += TDES_ECB_enc(); printf("Triple DES ECB Decryption ... "); - TDES_ECB_dec(); + fail += TDES_ECB_dec(); + + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - printf("\nExample complete.\n"); - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/DMA/main.c b/Examples/MAX32650/DMA/main.c index a5b68923052..6cac495023b 100644 --- a/Examples/MAX32650/DMA/main.c +++ b/Examples/MAX32650/DMA/main.c @@ -54,7 +54,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -75,10 +74,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -94,31 +93,31 @@ void example1(void) retval = MXC_DMA_Init(); if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - while (1) {} - } - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -186,7 +185,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { printf("Data verified.\n"); @@ -194,7 +192,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - while (1) {} + fail += 1; } free(srcdata); @@ -202,23 +200,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/EMCC/main.c b/Examples/MAX32650/EMCC/main.c index ecc036afb96..b482bf387ed 100644 --- a/Examples/MAX32650/EMCC/main.c +++ b/Examples/MAX32650/EMCC/main.c @@ -61,6 +61,7 @@ #define ITERATIONS 100 /* **** Globals **** */ +int fail = 0; int s, ss; unsigned int g_seed = 0; @@ -75,7 +76,7 @@ mxc_spixr_cfg_t init_cfg = { /* **** Functions **** */ -void setup(void) +int setup(void) { uint8_t quad_cmd = A1024_EQIO; /* pre-defined command to use quad mode */ @@ -85,7 +86,7 @@ void setup(void) // Initialize the desired configuration if (MXC_SPIXR_Init(&init_cfg) != E_NO_ERROR) { printf("FAILED: SPIXR was not initialized properly.\n"); - return; + return E_UNINITIALIZED; } /* Hide this with function in SPID.C later */ @@ -107,6 +108,8 @@ void setup(void) (A1024_READ << MXC_F_SPIXR_XMEM_CTRL_XMEM_RD_CMD_POS) | (A1024_WRITE << MXC_F_SPIXR_XMEM_CTRL_XMEM_WR_CMD_POS) | MXC_F_SPIXR_XMEM_CTRL_XMEM_EN; + + return E_NO_ERROR; } void start_timer(void) @@ -135,7 +138,9 @@ void test_function(void) int temp, i; // Configure the SPID - setup(); + if (E_NO_ERROR != setup()) { + fail += 1; + } // Initialize & write pseudo-random data to be written to the RAM for (i = 0; i < BUFFER_SIZE; i++) { @@ -155,6 +160,7 @@ void test_function(void) // Verify data being read from RAM if (memcmp(write_buffer, read_buffer, BUFFER_SIZE)) { printf("FAILED: Data was not read properly.\n\n"); + fail += 1; break; } } @@ -179,7 +185,11 @@ int main(void) MXC_EMCC_Disable(); test_function(); - printf("Example complete.\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/Flash/main.c b/Examples/MAX32650/Flash/main.c index 93fb5d8a0b9..5a228d68d31 100644 --- a/Examples/MAX32650/Flash/main.c +++ b/Examples/MAX32650/Flash/main.c @@ -393,11 +393,11 @@ int main(void) } MXC_ICC_Enable(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/HBMC/main.c b/Examples/MAX32650/HBMC/main.c index 7dbd6f999b1..69220047b80 100644 --- a/Examples/MAX32650/HBMC/main.c +++ b/Examples/MAX32650/HBMC/main.c @@ -226,9 +226,10 @@ int main(void) printf("Returned from external flash\n"); } else { printf("MEMORY MIS-COMPARE!\n"); + return E_FAIL; } printf("\nEND OF LINE.\n"); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32650/I2C/main.c b/Examples/MAX32650/I2C/main.c index 121bb582db6..22694f00bce 100644 --- a/Examples/MAX32650/I2C/main.c +++ b/Examples/MAX32650/I2C/main.c @@ -67,8 +67,6 @@ #define I2C_SLAVE_ADDR 0x51 #define I2C_BYTES 255 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -186,11 +184,12 @@ int verifyData() ++fails; } } + if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -208,14 +207,14 @@ int main() error = MXC_I2C_Init(I2C_MASTER, 1, 0); if (error != E_NO_ERROR) { printf("Failed to initialize master.\n"); - return FAILED; + return error; } //Setup the I2CS error = MXC_I2C_Init(I2C_SLAVE, 0, I2C_SLAVE_ADDR); if (error != E_NO_ERROR) { printf("Failed to initialize slave.\n"); - return FAILED; + return error; } MXC_NVIC_SetVector(I2C1_IRQn, I2C1_IRQHandler); @@ -249,7 +248,7 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } #ifdef MASTERDMA @@ -262,13 +261,13 @@ int main() if ((error = MXC_I2C_MasterTransactionDMA(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (DMA_FLAG == 0) {} #else if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -279,9 +278,10 @@ int main() printf("\n"); if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32650/ICC/README.md b/Examples/MAX32650/ICC/README.md index ca09adee434..c911bca53e7 100644 --- a/Examples/MAX32650/ICC/README.md +++ b/Examples/MAX32650/ICC/README.md @@ -83,6 +83,6 @@ With instruction cache disabled: Time Elapsed: 10.160537 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32650/ICC/main.c b/Examples/MAX32650/ICC/main.c index 662128a15fe..bafba0eebce 100644 --- a/Examples/MAX32650/ICC/main.c +++ b/Examples/MAX32650/ICC/main.c @@ -148,11 +148,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/OWM/main.c b/Examples/MAX32650/OWM/main.c index aefd827ab05..7c0ee45d9cf 100644 --- a/Examples/MAX32650/OWM/main.c +++ b/Examples/MAX32650/OWM/main.c @@ -173,12 +173,13 @@ int main(void) MXC_OWM_Init(&owm_cfg); /* Test overdrive */ - if ((retval = ow_romid_test(1))) { + retval = ow_romid_test(1); + if (retval != 0) { printf("Overdrive results: %d; %08x; %08x \n", retval, MXC_OWM->cfg, MXC_OWM->intfl); printf("Example Failed\n"); - } else { - printf("Example Succeeded\n"); + return E_FAIL; } - return 0; + printf("Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/SDHC_Raw/main.c b/Examples/MAX32650/SDHC_Raw/main.c index 4f164d4c517..5f46fbf8382 100644 --- a/Examples/MAX32650/SDHC_Raw/main.c +++ b/Examples/MAX32650/SDHC_Raw/main.c @@ -237,6 +237,7 @@ int multi_block_check(unsigned int width) /******************************************************************************/ int main(void) { + int fail = 0; mxc_sdhc_cfg_t cfg; int result; @@ -266,6 +267,7 @@ int main(void) printf("Card Initialized.\n"); } else { printf("No card response!\n"); + fail += 1; } if (MXC_SDHC_Lib_Get_Card_Type() == CARD_SDHC) { @@ -288,18 +290,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -309,18 +314,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -329,11 +337,16 @@ int main(void) if (multi_block_check(MXC_SDHC_LIB_QUAD_DATA)) { printf(" FAIL \n"); + fail += 1; } else { printf(" PASS \n"); } - printf(" *** END OF EXAMPLE *** \n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/SPI/main.c b/Examples/MAX32650/SPI/main.c index ec029381ce6..51a1ba91446 100644 --- a/Examples/MAX32650/SPI/main.c +++ b/Examples/MAX32650/SPI/main.c @@ -117,10 +117,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -216,12 +216,11 @@ int main(void) if (fail) { printf("Example failed!\n"); - LED_On(0); - return -1; - } else { - printf("Example succeeded!\n"); - LED_On(1); + LED_On(0); // indicates FAIL + return E_FAIL; } + LED_On(1); // indicates SUCCESS + printf("Example succeeded!\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32650/SPIMSS/main.c b/Examples/MAX32650/SPIMSS/main.c index ac1429a7948..87b1b0108c9 100644 --- a/Examples/MAX32650/SPIMSS/main.c +++ b/Examples/MAX32650/SPIMSS/main.c @@ -212,11 +212,12 @@ int main(void) if (fails != 0) { printf("\nTest failed!\n"); LED_On(0); + return E_FAIL; } else { printf("\nTest successful!\n"); LED_Init(); LED_On(1); } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32650/SPIXF/main.c b/Examples/MAX32650/SPIXF/main.c index 12f61418488..ae4e5f23be7 100644 --- a/Examples/MAX32650/SPIXF/main.c +++ b/Examples/MAX32650/SPIXF/main.c @@ -59,8 +59,6 @@ #define BUFF_SIZE 64 -int fail = 0; - /***** Functions *****/ // These are set in the linkerfile and give the starting and ending address of xip_section @@ -108,6 +106,7 @@ void spixf_cfg_setup() /******************************************************************************/ int main(void) { + int fail = 0; uint32_t id; void (*func)(void); uint8_t rx_buf[BUFF_SIZE]; @@ -125,7 +124,7 @@ int main(void) if (Ext_Flash_Init() != E_NO_ERROR) { printf("Board Init Failed\n"); printf("Example Failed\n"); - while (1) {} + return E_FAIL; } printf("External flash Initialized.\n\n"); @@ -137,7 +136,7 @@ int main(void) } else { printf("Error verifying external flash ID: 0x%x\n", id); printf("Example Failed\n"); - while (1) {} + return E_FAIL; } int err; @@ -203,10 +202,11 @@ int main(void) func(); printf("Returned from external flash\n\n"); - if (fail == 0) { - printf("Example Succeeded\n\n"); - } else { + if (fail != 0) { printf("Example Failed\n\n"); + return E_FAIL; } - return 0; + + printf("Example Succeeded\n\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/SPIXF_ICC/main.c b/Examples/MAX32650/SPIXF_ICC/main.c index 27eea2e4444..e30d52483f1 100644 --- a/Examples/MAX32650/SPIXF_ICC/main.c +++ b/Examples/MAX32650/SPIXF_ICC/main.c @@ -57,7 +57,6 @@ #define SEC_REMAIN(sec) (sec % 60) /***** Globals *****/ -int fail = 0; /***** Functions *****/ // These are set in the linkerfile and give the starting and ending address of xip_section @@ -147,6 +146,7 @@ int stop_timer(int test_num) /* ************************************************************************** */ int main(void) { + int fail = 0; int err; uint32_t id; void (*func)(void); @@ -226,11 +226,11 @@ int main(void) test2_et = stop_timer(1); // Compare execution times - if (test1_et < test2_et) { - printf("Example Succeeded\n\n"); - } else { + if (test1_et >= test2_et) { printf("Example Failed\n\n"); + return E_FAIL; } - return 0; + printf("Example Succeeded\n\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/SPIXR/README.md b/Examples/MAX32650/SPIXR/README.md index 22da77d87b3..3b03f540ecd 100644 --- a/Examples/MAX32650/SPIXR/README.md +++ b/Examples/MAX32650/SPIXR/README.md @@ -21,4 +21,5 @@ Initializing & Writing pseudo-random data to be written to RAM Reading data from RAM and store it inside the read_buffer Data is verified. +Example Succeeded ``` diff --git a/Examples/MAX32650/SPIXR/main.c b/Examples/MAX32650/SPIXR/main.c index 3fb2f5c43e4..330ec173ba6 100644 --- a/Examples/MAX32650/SPIXR/main.c +++ b/Examples/MAX32650/SPIXR/main.c @@ -71,15 +71,15 @@ mxc_spixr_cfg_t init_cfg = { /* **** Functions **** */ /* ************************************************************************** */ -void setup(void) +int setup(void) { uint8_t quad_cmd = A1024_EQIO; /* pre-defined command to use quad mode */ - // Initialize the desired configuration - if (MXC_SPIXR_Init(&init_cfg) == E_NO_ERROR) { - printf("SPIXR was initialized properly.\n"); - } else { - printf("SPIXR was not initialized properly.\n"); + // // Initialize the desired configuration + if (MXC_SPIXR_Init(&init_cfg) != E_NO_ERROR) { + printf("\nSPIXR was not initialized properly.\n"); + printf("\nExample Failed\n"); + return E_UNINITIALIZED; } /* Hide this with function in SPIXR.C later */ @@ -102,8 +102,7 @@ void setup(void) (A1024_WRITE << MXC_F_SPIXR_XMEM_CTRL_XMEM_WR_CMD_POS) | MXC_F_SPIXR_XMEM_CTRL_XMEM_EN; - // Do some sort of checking mechanism to see whether it is being initialized properly or no - // Return 1 if success and 0 if not + return E_NO_ERROR; } // ***************************************************************************** @@ -115,13 +114,16 @@ int main(void) /* Variable to store address of RAM */ int temp, i; + int fail = 0; unsigned int seed = 0; printf("\n***** SPIXR Example communicating with RAM in SPI Quad Mode *****\n"); // Configure the SPIXR printf("Setting up the SPIXR to communicate with RAM in Quad Mode \n"); - setup(); + if (E_NO_ERROR != setup()) { + fail += 1; + } // Initialize & write pseudo-random data to be written to the RAM printf("Initializing & Writing pseudo-random data to be written to RAM \n"); @@ -141,6 +143,7 @@ int main(void) // Verify data being read from RAM if (memcmp(write_buffer, read_buffer, BUFFER_SIZE)) { printf("Data is not verified.\n\n"); + fail += 1; } else { printf("Data is verified.\n\n"); } @@ -148,5 +151,11 @@ int main(void) // Disable the SPIXR MXC_SPIXR_Disable(); - return 0; + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/SPI_MasterSlave/main.c b/Examples/MAX32650/SPI_MasterSlave/main.c index 4bf55831df0..282147c27cc 100644 --- a/Examples/MAX32650/SPI_MasterSlave/main.c +++ b/Examples/MAX32650/SPI_MasterSlave/main.c @@ -152,19 +152,18 @@ int main(void) /***** Verify Results *****/ if (memcmp(slave_rx, master_tx, sizeof(master_tx)) != 0) { // Master->Slave printf("\nSlave failed to receive data.\n"); - LED_On(0); + LED_On(0); // indicates FAIL return E_COMM_ERR; } else if (memcmp(master_rx, slave_tx, sizeof(slave_tx)) != 0) { // Slave->Master printf("\nMaster failed to receive data.\n"); - LED_On(0); + LED_On(0); // indicates FAIL return E_COMM_ERR; - } else { - printf("EXAMPLE SUCCEEDED!\n"); - LED_On(1); } MXC_SPI_Shutdown(SPI_MASTER); MXC_SPI_Shutdown(SPI_SLAVE); + LED_On(1); // indicates SUCCESS + printf("Example succeeded!\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32650/TRNG/main.c b/Examples/MAX32650/TRNG/main.c index 9ebb67757d5..3b84ebc92f3 100644 --- a/Examples/MAX32650/TRNG/main.c +++ b/Examples/MAX32650/TRNG/main.c @@ -110,5 +110,5 @@ int main(void) printf("\n\nExample complete.\n"); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32650/UART/README.md b/Examples/MAX32650/UART/README.md index 3fe94f59d7a..89e3d34c173 100644 --- a/Examples/MAX32650/UART/README.md +++ b/Examples/MAX32650/UART/README.md @@ -29,5 +29,5 @@ Test Length : 512 bytes -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` diff --git a/Examples/MAX32650/UART/main.c b/Examples/MAX32650/UART/main.c index 3262360dae3..1e557366706 100644 --- a/Examples/MAX32650/UART/main.c +++ b/Examples/MAX32650/UART/main.c @@ -130,16 +130,14 @@ int main(void) if (error < E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Init(MXC_UART1, UART_BAUD); if (error < E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -171,8 +169,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -184,8 +181,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -210,13 +206,13 @@ int main(void) printf("-->Data verified\n"); } - if (fail == 0) { - printf("\n-->EXAMPLE SUCCEEDED\n"); - LED_On(1); - } else { - printf("\n-->EXAMPLE FAILED\n"); - LED_On(0); + if (fail != 0) { + printf("\n-->Example Failed\n"); + LED_On(0); // indicates FAIL + return E_FAIL; } - return 0; + LED_On(1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32650/WearLeveling/main.c b/Examples/MAX32650/WearLeveling/main.c index 63cb651651c..89bdb58f192 100644 --- a/Examples/MAX32650/WearLeveling/main.c +++ b/Examples/MAX32650/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/AES/main.c b/Examples/MAX32655/AES/main.c index 7a3fc3b9276..ddd0af2d40d 100644 --- a/Examples/MAX32655/AES/main.c +++ b/Examples/MAX32655/AES/main.c @@ -46,7 +46,6 @@ #include "board.h" #include "dma.h" #include "aes.h" -#include "aes_regs.h" /***** Definitions *****/ #define MXC_AES_DATA_LENGTH 8 //4 words @@ -114,14 +113,13 @@ int AES_decrypt(int asynchronous, mxc_aes_keys_t key) MXC_AES_Shutdown(); - if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) == 0) { - printf("\nData Verified"); - return E_NO_ERROR; + if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) != 0) { + printf("\nData Mismatch"); + return 1; } - printf("\nData Mismatch"); - - return 1; + printf("\nData Verified"); + return E_NO_ERROR; } // ***************************************************************************** @@ -145,13 +143,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - printf("\n"); - - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/CRC/main.c b/Examples/MAX32655/CRC/main.c index 451844d698a..8db71fa971a 100644 --- a/Examples/MAX32655/CRC/main.c +++ b/Examples/MAX32655/CRC/main.c @@ -65,16 +65,6 @@ void DMA0_IRQHandler(void) wait = 0; } -void Test_Result(int result) -{ - if (result) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } -} - void Test_CRC(int asynchronous) { uint32_t array[101]; @@ -122,7 +112,13 @@ void Test_CRC(int asynchronous) printf("\nCRC Check Result: %x", crc_req.resultCRC); - Test_Result(CHECK != crc_req.resultCRC); + if (CHECK != crc_req.resultCRC) { + printf(" \n**Test Failed**\n\n"); + fail++; + } else { + printf(" \n**Test Passed**\n\n"); + } + MXC_CRC_Shutdown(); } @@ -139,12 +135,10 @@ int main(void) Test_CRC(1); if (fail) { - printf("\Example Failed"); - } else { - printf("\nExample Succeeded"); + printf("\nExample Failed\n"); + return E_FAIL; } - printf("\n\n"); - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/DMA/main.c b/Examples/MAX32655/DMA/main.c index 2b9273f6f5e..bfd95cf894a 100644 --- a/Examples/MAX32655/DMA/main.c +++ b/Examples/MAX32655/DMA/main.c @@ -45,7 +45,6 @@ #include "mxc_device.h" #include "nvic_table.h" #include "dma.h" -#include "dma_regs.h" /***** Definitions *****/ @@ -54,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -75,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -96,36 +94,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -194,9 +188,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -204,8 +195,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -213,25 +203,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/FTHR_I2C/main.c b/Examples/MAX32655/FTHR_I2C/main.c index 61abb71a4fa..a84becc14e0 100644 --- a/Examples/MAX32655/FTHR_I2C/main.c +++ b/Examples/MAX32655/FTHR_I2C/main.c @@ -47,7 +47,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "dma.h" diff --git a/Examples/MAX32655/Flash/main.c b/Examples/MAX32655/Flash/main.c index 5bda5b1a96e..3a48d11aef4 100644 --- a/Examples/MAX32655/Flash/main.c +++ b/Examples/MAX32655/Flash/main.c @@ -47,7 +47,6 @@ #include "nvic_table.h" #include "flc.h" #include "icc.h" -#include "flc_regs.h" #include "gcr_regs.h" /***** Definitions *****/ @@ -409,13 +408,11 @@ int main(void) MXC_ICC_Enable(MXC_ICC0); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/Flash_CLI/main.c b/Examples/MAX32655/Flash_CLI/main.c index 335ae4b3eeb..ba9cc7fd223 100644 --- a/Examples/MAX32655/Flash_CLI/main.c +++ b/Examples/MAX32655/Flash_CLI/main.c @@ -51,7 +51,6 @@ #include "definitions.h" #include "dma.h" #include "flc.h" -#include "flc_regs.h" #include "gcr_regs.h" #include "icc.h" #include "mxc_assert.h" diff --git a/Examples/MAX32655/I2C/main.c b/Examples/MAX32655/I2C/main.c index f7c8100c894..d81d2c485a3 100644 --- a/Examples/MAX32655/I2C/main.c +++ b/Examples/MAX32655/I2C/main.c @@ -47,7 +47,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "dma.h" @@ -64,8 +63,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 100 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -188,10 +185,10 @@ int verifyData() } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -211,7 +208,7 @@ int main() if (error != E_NO_ERROR) { printf("-->Failed master\n"); - return FAILED; + return E_FAIL; } else { printf("\n-->I2C Master Initialization Complete"); } @@ -221,7 +218,7 @@ int main() if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return E_FAIL; } else { printf("\n-->I2C Slave Initialization Complete"); } @@ -258,12 +255,12 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return E_FAIL; } if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return E_FAIL; } while (I2C_FLAG == 1) {} @@ -276,9 +273,10 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32655/I2C_SCAN/main.c b/Examples/MAX32655/I2C_SCAN/main.c index e7e6e6878de..3da592d2f83 100644 --- a/Examples/MAX32655/I2C_SCAN/main.c +++ b/Examples/MAX32655/I2C_SCAN/main.c @@ -45,7 +45,6 @@ #include #include "mxc_device.h" #include "mxc_delay.h" -#include "i2c_regs.h" #include "i2c.h" #include "board.h" @@ -106,4 +105,5 @@ int main() } printf("\n-->Scan finished. %d devices found\n", counter); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/I2S/main.c b/Examples/MAX32655/I2S/main.c index 41332cd9070..6839dd51384 100644 --- a/Examples/MAX32655/I2S/main.c +++ b/Examples/MAX32655/I2S/main.c @@ -48,7 +48,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2s_regs.h" #include "board.h" #include "i2s.h" @@ -141,5 +140,5 @@ int main() } } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32655/I2S_Playback/main.c b/Examples/MAX32655/I2S_Playback/main.c index 57bb6ae9530..253f8de4cc8 100644 --- a/Examples/MAX32655/I2S_Playback/main.c +++ b/Examples/MAX32655/I2S_Playback/main.c @@ -48,7 +48,6 @@ #include "board.h" #include "dma.h" #include "i2s.h" -#include "i2s_regs.h" #include "icc.h" #include "led.h" #include "max9867.h" diff --git a/Examples/MAX32655/ICC/README.md b/Examples/MAX32655/ICC/README.md index df6889202dc..55b75338822 100644 --- a/Examples/MAX32655/ICC/README.md +++ b/Examples/MAX32655/ICC/README.md @@ -93,6 +93,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32655/ICC/main.c b/Examples/MAX32655/ICC/main.c index 10d01ebb12a..a2b98fd81c6 100644 --- a/Examples/MAX32655/ICC/main.c +++ b/Examples/MAX32655/ICC/main.c @@ -153,13 +153,11 @@ int main(void) fail += 1; } - printf("\n\n"); - - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/LP/main.c b/Examples/MAX32655/LP/main.c index cb803089dd6..9e65f10bdbf 100644 --- a/Examples/MAX32655/LP/main.c +++ b/Examples/MAX32655/LP/main.c @@ -86,6 +86,12 @@ #error "You must select either DO_BACKUP or DO_STORAGE or neither, not both." #endif +#if USE_CONSOLE +#define PRINT(...) printf(__VA_ARGS__) +#else +#define PRINT(...) +#endif + // ***************************************************************************** #if USE_ALARM @@ -164,32 +170,25 @@ void setTrigger(int waitForTrigger) int main(void) { -#if USE_CONSOLE - printf("****Low Power Mode Example****\n\n"); -#endif // USE_CONSOLE + PRINT("****Low Power Mode Example****\n\n"); #if USE_ALARM -#if USE_CONSOLE - printf("This code cycles through the MAX32655 power modes, using the RTC alarm to exit from " - "each mode. The modes will change every %d seconds.\n\n", - DELAY_IN_SEC); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32655 power modes, using the RTC alarm to exit from " + "each mode. The modes will change every %d seconds.\n\n", + DELAY_IN_SEC); MXC_NVIC_SetVector(RTC_IRQn, alarmHandler); #endif // USE_ALARM #if USE_BUTTON -#if USE_CONSOLE - printf("This code cycles through the MAX32655 power modes, using a push button (PB1) to exit " - "from each mode and enter the next.\n\n"); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32655 power modes, using a push button (PB1) to exit " + "from each mode and enter the next.\n\n"); PB_RegisterCallback(0, buttonHandler); #endif // USE_BUTTON -#if USE_CONSOLE - printf("Running in ACTIVE mode.\n"); -#else + PRINT("Running in ACTIVE mode.\n"); +#if !USE_CONSOLE MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_UART0); -#endif // USE_CONSOLE +#endif // !USE_CONSOLE setTrigger(1); #if USE_BUTTON @@ -201,44 +200,34 @@ int main(void) while (1) { #if DO_SLEEP -#if USE_CONSOLE - printf("Entering SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering SLEEP mode.\n"); setTrigger(0); MXC_LP_EnterSleepMode(); - printf("Waking up from SLEEP mode.\n"); + PRINT("Waking up from SLEEP mode.\n"); #endif // DO_SLEEP #if DO_LPM -#if USE_CONSOLE - printf("Entering LPM mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering LPM mode.\n"); setTrigger(0); MXC_LP_EnterLowPowerMode(); - printf("Waking up from LPM mode.\n"); + PRINT("Waking up from LPM mode.\n"); #endif // DO_LPM #if DO_UPM -#if USE_CONSOLE - printf("Entering UPM mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering UPM mode.\n"); setTrigger(0); MXC_LP_EnterMicroPowerMode(); - printf("Waking up from UPM mode.\n"); + PRINT("Waking up from UPM mode.\n"); #endif // DO_UPM #if DO_BACKUP -#if USE_CONSOLE - printf("Entering BACKUP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering BACKUP mode.\n"); setTrigger(0); MXC_LP_EnterBackupMode(); #endif // DO_BACKUP #if DO_STANDBY -#if USE_CONSOLE - printf("Entering STANDBY mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering STANDBY mode.\n"); setTrigger(0); MXC_LP_EnterStandbyMode(); #endif // DO_STANDBY diff --git a/Examples/MAX32655/Pulse_Train/main.c b/Examples/MAX32655/Pulse_Train/main.c index f982b24b831..413787cf929 100644 --- a/Examples/MAX32655/Pulse_Train/main.c +++ b/Examples/MAX32655/Pulse_Train/main.c @@ -123,5 +123,5 @@ int main(void) ContinuousPulseTrain(); SquareWave(); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32655/SPI/main.c b/Examples/MAX32655/SPI/main.c index 65daedfd1a8..185aa7c8230 100644 --- a/Examples/MAX32655/SPI/main.c +++ b/Examples/MAX32655/SPI/main.c @@ -139,10 +139,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -227,7 +227,7 @@ int main(void) // Printf needs the Uart turned on since they share the same pins if (memcmp(rx_data, tx_data, sizeof(tx_data)) != 0) { printf("\n-->%2d Bits Transaction Failed\n", i); - // return E_BAD_STATE; + return E_BAD_STATE; } else { printf("\n-->%2d Bits Transaction Successful\n", i); } diff --git a/Examples/MAX32655/TMR/main.c b/Examples/MAX32655/TMR/main.c index 64758dfe8d8..48eaf67fe3b 100644 --- a/Examples/MAX32655/TMR/main.c +++ b/Examples/MAX32655/TMR/main.c @@ -279,5 +279,5 @@ int main(void) } } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32655/UART/README.md b/Examples/MAX32655/UART/README.md index 5098c940253..ba99fa8413c 100644 --- a/Examples/MAX32655/UART/README.md +++ b/Examples/MAX32655/UART/README.md @@ -41,7 +41,7 @@ P2.6 -> P1.1 and P2.7 -> P1.0 -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` The green LED (P0_25) will illuminate for successful transaction. diff --git a/Examples/MAX32655/UART/main.c b/Examples/MAX32655/UART/main.c index 2d9db173956..02bf2548438 100644 --- a/Examples/MAX32655/UART/main.c +++ b/Examples/MAX32655/UART/main.c @@ -116,13 +116,13 @@ int main(void) if ((error = MXC_UART_Init(MXC_UART3, UART_BAUD, MXC_UART_IBRO_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(MXC_UART2, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -153,8 +153,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -162,8 +161,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -188,15 +186,13 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - LED_On(1); - printf("-->EXAMPLE SUCCEEDED\n"); - } else { - LED_On(0); - printf("-->EXAMPLE FAILED\n"); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - return 0; + LED_On(1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32655/WearLeveling/main.c b/Examples/MAX32655/WearLeveling/main.c index 597bf09088c..4caff9e2446 100644 --- a/Examples/MAX32655/WearLeveling/main.c +++ b/Examples/MAX32655/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32660/DMA/main.c b/Examples/MAX32660/DMA/main.c index 7b038d06595..3b81881bbea 100644 --- a/Examples/MAX32660/DMA/main.c +++ b/Examples/MAX32660/DMA/main.c @@ -53,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -74,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -93,31 +92,31 @@ void example1(void) retval = MXC_DMA_Init(); if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - while (1) {} - } - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -185,7 +184,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { printf("Data verified.\n"); @@ -193,7 +191,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - while (1) {} + fail += 1; } free(srcdata); @@ -201,23 +199,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32660/Flash/main.c b/Examples/MAX32660/Flash/main.c index 8237064b6e3..0b6bf225c3a 100644 --- a/Examples/MAX32660/Flash/main.c +++ b/Examples/MAX32660/Flash/main.c @@ -393,11 +393,11 @@ int main(void) } MXC_ICC_Enable(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32660/I2C/main.c b/Examples/MAX32660/I2C/main.c index 3064aa3e016..9a6a24119a5 100644 --- a/Examples/MAX32660/I2C/main.c +++ b/Examples/MAX32660/I2C/main.c @@ -68,8 +68,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 255 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -191,10 +189,10 @@ int verifyData() } } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -213,14 +211,14 @@ int main() error = MXC_I2C_Init(I2C_MASTER, 1, 0); if (error != E_NO_ERROR) { printf("Failed master\n"); - return FAILED; + return error; } //Setup the I2CS error = MXC_I2C_Init(I2C_SLAVE, 0, I2C_SLAVE_ADDR); if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } MXC_NVIC_SetVector(I2C1_IRQn, I2C1_IRQHandler); @@ -254,7 +252,7 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } #ifdef MASTERDMA @@ -273,7 +271,7 @@ int main() #else if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -284,9 +282,10 @@ int main() printf("\n"); if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32660/I2C_SCAN/main.c b/Examples/MAX32660/I2C_SCAN/main.c index 21b758fe736..c4508113a04 100644 --- a/Examples/MAX32660/I2C_SCAN/main.c +++ b/Examples/MAX32660/I2C_SCAN/main.c @@ -94,5 +94,5 @@ int main() printf("\n-->Scan finished. %d devices found\n", counter); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32660/ICC/README.md b/Examples/MAX32660/ICC/README.md index c9d05c55dac..b77d68f03b5 100644 --- a/Examples/MAX32660/ICC/README.md +++ b/Examples/MAX32660/ICC/README.md @@ -83,7 +83,7 @@ With instruction cache disabled: Time Elapsed: 10.164861 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32660/ICC/main.c b/Examples/MAX32660/ICC/main.c index cde57a8625c..3906cf889cf 100644 --- a/Examples/MAX32660/ICC/main.c +++ b/Examples/MAX32660/ICC/main.c @@ -148,11 +148,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32660/SPI/main.c b/Examples/MAX32660/SPI/main.c index 119c8772763..d8c5abea9ca 100644 --- a/Examples/MAX32660/SPI/main.c +++ b/Examples/MAX32660/SPI/main.c @@ -120,9 +120,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32660/SPIMSS/main.c b/Examples/MAX32660/SPIMSS/main.c index 2fc64221808..3b97a785c5a 100644 --- a/Examples/MAX32660/SPIMSS/main.c +++ b/Examples/MAX32660/SPIMSS/main.c @@ -132,7 +132,7 @@ int main(void) Console_Init(); printf("Error configuring SPI\n"); while (MXC_UART_Busy(MXC_UART_GET_UART(CONSOLE_UART))) {} - while (1) {} + return E_FAIL; } req.tx_data = txData; @@ -150,14 +150,14 @@ int main(void) Console_Init(); printf("SPIMSS Asynchronus Transaction failed with error code : %d", spimssFlag); while (MXC_UART_Busy(MXC_UART_GET_UART(CONSOLE_UART))) {} - while (1) {} + return err; } while (spimssFlag == 1) {} if (spimssFlag != 0) { Console_Init(); printf("SPIMSS Asynchronus Transaction failed with error code : %d", spimssFlag); while (MXC_UART_Busy(MXC_UART_GET_UART(CONSOLE_UART))) {} - while (1) {} + return E_FAIL; } #endif #ifdef SYNC @@ -165,7 +165,7 @@ int main(void) Console_Init(); printf("SPIMSS Transaction failed with error code:%d\n", err); while (MXC_UART_Busy(MXC_UART_GET_UART(CONSOLE_UART))) {} - while (1) {} + return err; } #endif @@ -211,11 +211,12 @@ int main(void) if (fails != 0) { printf("\nTest failed!\n"); + return E_FAIL; } else { printf("\nTest successful!\n"); LED_Init(); LED_On(0); } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32660/SPI_MasterSlave/main.c b/Examples/MAX32660/SPI_MasterSlave/main.c index ae0ba2d78c0..5610286b2c4 100644 --- a/Examples/MAX32660/SPI_MasterSlave/main.c +++ b/Examples/MAX32660/SPI_MasterSlave/main.c @@ -174,13 +174,12 @@ int main(void) } else if (memcmp(master_rx, slave_tx, sizeof(slave_tx)) != 0) { // Slave->Master printf("Master failed to receive data.\n"); return E_COMM_ERR; - } else { - printf("EXAMPLE SUCCEEDED!\n"); - LED_On(0); } MXC_SPIMSS_Shutdown(SPI_MASTER); MXC_SPI_Shutdown(SPI_SLAVE); + LED_On(0); // indicates SUCCESS + printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32660/UART/README.md b/Examples/MAX32660/UART/README.md index 6c5e750409c..9e75d5cb79c 100644 --- a/Examples/MAX32660/UART/README.md +++ b/Examples/MAX32660/UART/README.md @@ -28,6 +28,6 @@ Blinking->Success, Solid->Failure -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` diff --git a/Examples/MAX32660/UART/main.c b/Examples/MAX32660/UART/main.c index 87ddf614cb2..cef1aaf516e 100644 --- a/Examples/MAX32660/UART/main.c +++ b/Examples/MAX32660/UART/main.c @@ -119,13 +119,13 @@ int main(void) if ((error = MXC_UART_Init(UART0, UART_BAUD, MAP_A)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(UART1, UART_BAUD, MAP_A)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -157,7 +157,7 @@ int main(void) printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); LED_On(0); - while (1) {} + return error; } #ifdef DMA @@ -169,7 +169,7 @@ int main(void) printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); LED_On(0); - while (1) {} + return error; } #ifdef DMA @@ -189,21 +189,12 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - if (fail != 0) { - LED_On(0); - printf("-->EXAMPLE FAILED\n"); - } else { - printf("-->EXAMPLE SUCCEEDED\n"); - } - - while (1) { - LED_On(0); - MXC_Delay(500000); // 500ms - LED_Off(0); - MXC_Delay(500000); // 500ms + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - return 0; + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32660/WearLeveling/main.c b/Examples/MAX32660/WearLeveling/main.c index e0f03309c66..96a140e0d85 100644 --- a/Examples/MAX32660/WearLeveling/main.c +++ b/Examples/MAX32660/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32662/DMA/main.c b/Examples/MAX32662/DMA/main.c index 9c770de89aa..3b81881bbea 100644 --- a/Examples/MAX32662/DMA/main.c +++ b/Examples/MAX32662/DMA/main.c @@ -45,7 +45,6 @@ #include "mxc_device.h" #include "nvic_table.h" #include "dma.h" -#include "dma_regs.h" /***** Definitions *****/ @@ -54,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -75,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -94,31 +92,31 @@ void example1(void) retval = MXC_DMA_Init(); if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - while (1) {} - } - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -186,7 +184,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { printf("Data verified.\n"); @@ -194,7 +191,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - while (1) {} + fail += 1; } free(srcdata); @@ -202,25 +199,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - printf("\n"); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); - while (1) {} + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - return 0; + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32662/Flash/main.c b/Examples/MAX32662/Flash/main.c index 1ebced685a3..5ba92850652 100644 --- a/Examples/MAX32662/Flash/main.c +++ b/Examples/MAX32662/Flash/main.c @@ -47,7 +47,6 @@ #include "nvic_table.h" #include "flc.h" #include "icc.h" -#include "flc_regs.h" #include "gcr_regs.h" /***** Definitions *****/ @@ -411,17 +410,13 @@ int main(void) MXC_ICC_Enable(); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } #if !defined(__RAM_FWK__) diff --git a/Examples/MAX32662/I2C/main.c b/Examples/MAX32662/I2C/main.c index fd12c4f7ed3..34c999908d3 100644 --- a/Examples/MAX32662/I2C/main.c +++ b/Examples/MAX32662/I2C/main.c @@ -51,7 +51,6 @@ #include "mxc_delay.h" #include "mxc_errors.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "dma.h" @@ -65,8 +64,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 255 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -188,9 +185,9 @@ int verifyData() } } if (fails > 0) { - return FAILED; + return E_FAIL; } else { - return PASSED; + return E_NO_ERROR; } } @@ -211,14 +208,14 @@ int main() error = MXC_I2C_Init(I2C_MASTER, 1, 0); if (error != E_NO_ERROR) { printf("Failed master\n"); - return FAILED; + return error; } //Setup the I2CS error = MXC_I2C_Init(I2C_SLAVE, 0, I2C_SLAVE_ADDR); if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } MXC_NVIC_SetVector(I2C1_IRQn, I2C1_IRQHandler); @@ -252,7 +249,7 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } #ifdef MASTERDMA @@ -271,7 +268,7 @@ int main() #else if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -282,9 +279,10 @@ int main() printf("\n"); if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32662/I2C_SCAN/main.c b/Examples/MAX32662/I2C_SCAN/main.c index aa603e58583..ede649f8638 100644 --- a/Examples/MAX32662/I2C_SCAN/main.c +++ b/Examples/MAX32662/I2C_SCAN/main.c @@ -46,7 +46,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" /***** Definitions *****/ @@ -102,4 +101,5 @@ int main() } printf("\n-->Scan finished. %d devices found\n", counter); + return E_NO_ERROR; } diff --git a/Examples/MAX32662/I2S/main.c b/Examples/MAX32662/I2S/main.c index 766a0aa8194..0c5c5a7a636 100644 --- a/Examples/MAX32662/I2S/main.c +++ b/Examples/MAX32662/I2S/main.c @@ -133,5 +133,5 @@ int main() printf("I2S Transmission Complete.\n"); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32662/ICC/README.md b/Examples/MAX32662/ICC/README.md index f6934b1c408..bb4bd30704e 100644 --- a/Examples/MAX32662/ICC/README.md +++ b/Examples/MAX32662/ICC/README.md @@ -83,7 +83,7 @@ With instruction cache disabled: Time Elapsed: 10.164861 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32662/ICC/main.c b/Examples/MAX32662/ICC/main.c index 63b60cc60af..3906cf889cf 100644 --- a/Examples/MAX32662/ICC/main.c +++ b/Examples/MAX32662/ICC/main.c @@ -148,12 +148,11 @@ int main(void) fail += 1; } - printf("\n\n"); - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32662/LP/main.c b/Examples/MAX32662/LP/main.c index 14dc4c4912f..f5d788dbf05 100644 --- a/Examples/MAX32662/LP/main.c +++ b/Examples/MAX32662/LP/main.c @@ -86,6 +86,12 @@ is in these modes. #error "You must select either USE_BUTTON or USE_ALARM, not both." #endif +#if USE_CONSOLE +#define PRINT(...) fprintf(stdout, __VA_ARGS__) +#else +#define PRINT(...) +#endif + // ***************************************************************************** #if USE_ALARM @@ -161,34 +167,27 @@ void setTrigger(int waitForTrigger) int main(void) { -#if USE_CONSOLE - printf("****Low Power Mode Example****\n\n"); -#endif // USE_CONSOLE + PRINT("****Low Power Mode Example****\n\n"); #if USE_ALARM -#if USE_CONSOLE - printf("This code cycles through the MAX32662 power modes, using the RTC alarm to exit from " - "each mode. The modes will change every %d seconds.\n\n", - DELAY_IN_SEC); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32662 power modes, using the RTC alarm to exit from " + "each mode. The modes will change every %d seconds.\n\n", + DELAY_IN_SEC); MXC_NVIC_SetVector(RTC_IRQn, alarmHandler); #endif // USE_ALARM #if USE_BUTTON -#if USE_CONSOLE - printf("This code cycles through the MAX32662 power modes, using a push button (SW2) to exit " - "from each mode and enter the next.\n\n"); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32662 power modes, using a push button (SW2) to exit " + "from each mode and enter the next.\n\n"); PB_Init(); PB_RegisterCallback(0, buttonHandler); __enable_irq(); #endif // USE_BUTTON -#if USE_CONSOLE - printf("Running in ACTIVE mode.\n"); -#else + PRINT("Running in ACTIVE mode.\n"); +#if !USE_CONSOLE MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_UART0); -#endif // USE_CONSOLE +#endif // !USE_CONSOLE setTrigger(1); //MXC_LP_ROMLightSleepEnable(); // TODO: Re-enable this? @@ -197,16 +196,12 @@ int main(void) MXC_LP_DisableSysRAMLightSleep(1); MXC_LP_DisableSysRAMLightSleep(0); // Global variables are in RAM0 and RAM1 -#if USE_CONSOLE - printf("All unused RAMs placed in LIGHT SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("All unused RAMs placed in LIGHT SLEEP mode.\n"); setTrigger(1); //MXC_LP_DisableSRAM2(); // Disabling SRAM2 will prevent RSTN from working... -#if USE_CONSOLE - printf("All unused RAMs shutdown.\n"); -#endif // USE_CONSOLE + PRINT("All unused RAMs shutdown.\n"); setTrigger(1); #if USE_BUTTON @@ -218,27 +213,21 @@ int main(void) while (1) { #if DO_SLEEP -#if USE_CONSOLE - printf("Entering SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering SLEEP mode.\n"); setTrigger(0); MXC_LP_EnterSleepMode(); - printf("Waking up from SLEEP mode.\n"); + PRINT("Waking up from SLEEP mode.\n"); #endif // DO_SLEEP #if DO_DEEPSLEEP -#if USE_CONSOLE - printf("Entering DEEPSLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering DEEPSLEEP mode.\n"); setTrigger(0); MXC_LP_EnterDeepSleepMode(); - printf("Waking up from DEEPSLEEP mode.\n"); + PRINT("Waking up from DEEPSLEEP mode.\n"); #endif // DO_DEEPSLEEP #if DO_BACKUP -#if USE_CONSOLE - printf("Entering BACKUP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering BACKUP mode.\n"); setTrigger(0); MXC_LP_EnterBackupMode(); #endif // DO_BACKUP diff --git a/Examples/MAX32662/SPI/main.c b/Examples/MAX32662/SPI/main.c index 02b3166fbba..5a73292b4ce 100644 --- a/Examples/MAX32662/SPI/main.c +++ b/Examples/MAX32662/SPI/main.c @@ -134,9 +134,10 @@ int main(void) spi_pin_init.map_a = true; // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pin_init) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pin_init); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32662/SPI_MasterSlave/README.md b/Examples/MAX32662/SPI_MasterSlave/README.md index c8e2287278b..6b3348ce8c9 100644 --- a/Examples/MAX32662/SPI_MasterSlave/README.md +++ b/Examples/MAX32662/SPI_MasterSlave/README.md @@ -27,5 +27,5 @@ LED will illuminate. Press SW2 to begin transaction. -EXAMPLE SUCCEEDED! +Example Succeeded ``` \ No newline at end of file diff --git a/Examples/MAX32662/SPI_MasterSlave/main.c b/Examples/MAX32662/SPI_MasterSlave/main.c index 1ecffda3917..0e3482dc6b9 100644 --- a/Examples/MAX32662/SPI_MasterSlave/main.c +++ b/Examples/MAX32662/SPI_MasterSlave/main.c @@ -165,13 +165,12 @@ int main(void) } else if (memcmp(master_rx, slave_tx, sizeof(slave_tx)) != 0) { // Slave->Master printf("\nMaster failed to receive data.\n"); return E_COMM_ERR; - } else { - printf("EXAMPLE SUCCEEDED!\n"); - LED_On(0); } MXC_SPI_Shutdown(SPI_MASTER); MXC_SPI_Shutdown(SPI_SLAVE); + LED_On(0); // indicates SUCCESS + printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32662/UART/README.md b/Examples/MAX32662/UART/README.md index 6619f03b0d8..df7313e366b 100644 --- a/Examples/MAX32662/UART/README.md +++ b/Examples/MAX32662/UART/README.md @@ -29,6 +29,6 @@ Blinking->Success, Solid->Failure -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` diff --git a/Examples/MAX32662/UART/main.c b/Examples/MAX32662/UART/main.c index 63889dea513..f9b4ffb8131 100644 --- a/Examples/MAX32662/UART/main.c +++ b/Examples/MAX32662/UART/main.c @@ -138,7 +138,7 @@ int main(void) Console_Init(); printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(READING_UART, UART_BAUD, MXC_UART_APB_CLK, MAP_A)) != E_NO_ERROR) { @@ -146,7 +146,7 @@ int main(void) Console_Init(); printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } mxc_uart_req_t read_req; @@ -177,7 +177,7 @@ int main(void) printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); LED_On(0); - while (1) {} + return error; } #ifdef DMA @@ -191,7 +191,7 @@ int main(void) printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); LED_On(0); - while (1) {} + return error; } #ifdef DMA @@ -213,20 +213,12 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - if (fail != 0) { - LED_On(0); - printf("-->EXAMPLE FAILED\n"); - while (1) {} - } else { - printf("-->EXAMPLE SUCCEEDED\n"); + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - while (1) { - LED_On(0); - MXC_Delay(500000); // 500ms - LED_Off(0); - MXC_Delay(500000); // 500ms - } + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32662/UART_Wakeup/main.c b/Examples/MAX32662/UART_Wakeup/main.c index cc7aec1e8f4..ebecc1fb8dd 100644 --- a/Examples/MAX32662/UART_Wakeup/main.c +++ b/Examples/MAX32662/UART_Wakeup/main.c @@ -146,5 +146,5 @@ int main(void) printf("Example complete!"); while (MXC_UART_GetActive(ConsoleUART)) {} - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32662/WearLeveling/main.c b/Examples/MAX32662/WearLeveling/main.c index 157066fd2cc..ebec72b8f7c 100644 --- a/Examples/MAX32662/WearLeveling/main.c +++ b/Examples/MAX32662/WearLeveling/main.c @@ -183,11 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/AES/main.c b/Examples/MAX32665/AES/main.c index b963aaacad5..93021beaa13 100644 --- a/Examples/MAX32665/AES/main.c +++ b/Examples/MAX32665/AES/main.c @@ -94,11 +94,11 @@ int AES_check(char *calculated, char *expected, int len) } if (fail > 0) { printf("Fail.\n"); - } else { - printf("Pass.\n"); - return 0; + return -1; } - return -1; + + printf("Pass.\n"); + return 0; } int AES128_ECB_enc(void) @@ -272,11 +272,11 @@ int main(void) fail += AES256_ECB_enc(); fail += AES256_ECB_dec(); - printf("\n"); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/CRC/main.c b/Examples/MAX32665/CRC/main.c index ffa93cc150a..01e8ec471d5 100644 --- a/Examples/MAX32665/CRC/main.c +++ b/Examples/MAX32665/CRC/main.c @@ -83,7 +83,7 @@ int main(void) if (MXC_TPU_CRC_Config() != E_SUCCESS) { printf("Failed MXC_TPU_Crc_Config()\n"); - return -1; + return E_FAIL; } printf("CRC16:\n"); @@ -95,7 +95,7 @@ int main(void) //Generate hardware result if (MXC_TPU_CRC(data, len, MXC_TPU_CRC16, &hw_crc) != E_SUCCESS) { printf("Failed MXC_TPU_CRC()\n"); - return -1; + return E_FAIL; } fail += memcmp(&hw_crc, &sw_crc, sizeof(hw_crc)); @@ -106,7 +106,7 @@ int main(void) //Call TPU_Crc_Config() again to reset if (MXC_TPU_CRC_Config() != E_SUCCESS) { printf("Failed MXC_TPU_Crc_Config()\n"); - return -1; + return E_FAIL; } printf("CRC32:\n"); @@ -117,19 +117,18 @@ int main(void) //Generate hardware result if (MXC_TPU_CRC(data, len, MXC_TPU_CRC32_ETHERNET, &hw_crc) != E_SUCCESS) { printf("Failed MXC_TPU_CRC()\n"); - return -1; + return E_FAIL; } fail += memcmp(&hw_crc, &sw_crc, sizeof(hw_crc)); printf("Calculated CRC = 0x%08x\n", hw_crc); printf("Expected CRC = 0x%08x\n", sw_crc); - printf("\n"); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/DES/README.md b/Examples/MAX32665/DES/README.md index 53a3d5b0943..09f92aafe8b 100644 --- a/Examples/MAX32665/DES/README.md +++ b/Examples/MAX32665/DES/README.md @@ -51,6 +51,6 @@ Data verified. Demonstrating 3DES CBC (cipher feedback) decryption... Data verified. -Example Complete. +Example Succeeded. ``` diff --git a/Examples/MAX32665/DES/main.c b/Examples/MAX32665/DES/main.c index 9783b182ff0..78d5fe26596 100644 --- a/Examples/MAX32665/DES/main.c +++ b/Examples/MAX32665/DES/main.c @@ -563,9 +563,11 @@ int main(void) errCnt += TDES_CBC_Decryption_Example(); errCnt += TDES_CFB_Decryption_Example(); - if (errCnt == 0) { - printf("Example Complete.\n"); - } else { + if (errCnt != 0) { printf("%d Operations FAILED!\n", errCnt); + return E_FAIL; } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/DMA/main.c b/Examples/MAX32665/DMA/main.c index f8a406cffcb..ccae7ae3720 100644 --- a/Examples/MAX32665/DMA/main.c +++ b/Examples/MAX32665/DMA/main.c @@ -45,7 +45,6 @@ #include "mxc_device.h" #include "nvic_table.h" #include "dma.h" -#include "dma_regs.h" /***** Definitions *****/ @@ -54,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -80,10 +78,10 @@ void DMA8_IRQHandler() MXC_DMA_Handler(MXC_DMA1); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -99,31 +97,31 @@ void example1(void) retval = MXC_DMA_Init(MXC_DMA0); if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - while (1) {} - } - flag = 0; - MXC_DMA_MemCpy(MXC_DMA0, dstdata, srcdata, MAX_SIZE, memCpyComplete); - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(MXC_DMA0, dstdata, srcdata, MAX_SIZE, memCpyComplete); + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -191,7 +189,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - while (1) {} fail += 1; } else { printf("Data verified.\n"); @@ -199,7 +196,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - while (1) {} + fail += 1; } free(srcdata); @@ -207,31 +204,29 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); __enable_irq(); NVIC_EnableIRQ(DMA0_IRQn); - example1(); + fail += example1(); NVIC_DisableIRQ(DMA0_IRQn); NVIC_EnableIRQ(DMA8_IRQn); - example2(); + fail += example2(); NVIC_DisableIRQ(DMA8_IRQn); - printf("\n"); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); - while (1) {} + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/ECC/main.c b/Examples/MAX32665/ECC/main.c index d308ccfdc0e..de2f1dbb01e 100644 --- a/Examples/MAX32665/ECC/main.c +++ b/Examples/MAX32665/ECC/main.c @@ -201,10 +201,12 @@ int main(void) printf("\n# Passed: %u, # Failed: %u, Test %s\n", test_pass, test_fail, test_fail ? "FAIL!" : "Ok"); - printf("Example Complete\n"); - while (1) { - { - } + if (test_fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/Flash/main.c b/Examples/MAX32665/Flash/main.c index 7ba18f3aa83..8a6a9c40da5 100644 --- a/Examples/MAX32665/Flash/main.c +++ b/Examples/MAX32665/Flash/main.c @@ -47,7 +47,6 @@ #include "nvic_table.h" #include "flc.h" #include "icc.h" -#include "flc_regs.h" #include "gcr_regs.h" /***** Definitions *****/ @@ -419,13 +418,12 @@ int main(void) fail += partial_erase_test(MXC_FLASH1_MEM_BASE); MXC_ICC_Enable(); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); - } - while (1) {} + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/Flash_CLI/main.c b/Examples/MAX32665/Flash_CLI/main.c index 0d8d26ccef3..b25bce5ebf2 100644 --- a/Examples/MAX32665/Flash_CLI/main.c +++ b/Examples/MAX32665/Flash_CLI/main.c @@ -50,7 +50,6 @@ #include "definitions.h" #include "dma.h" #include "flc.h" -#include "flc_regs.h" #include "gcr_regs.h" #include "icc.h" #include "mxc_assert.h" diff --git a/Examples/MAX32665/Hash/main.c b/Examples/MAX32665/Hash/main.c index 6a9268d1159..5c0724c03a4 100644 --- a/Examples/MAX32665/Hash/main.c +++ b/Examples/MAX32665/Hash/main.c @@ -49,14 +49,6 @@ char temp[] = { 0x00, 0x00, 0x00 }; -void Test_Result(int result) -{ - if (result) - printf(" * Failed *\n\n"); - else - printf(" Passed \n\n"); -} - void ascii_to_byte(const char *src, char *dst, int len) { int i; @@ -71,8 +63,9 @@ void ascii_to_byte(const char *src, char *dst, int len) } } -void Test_Hash(void) +int Test_Hash(void) { + int ret; printf("Test Hash\n"); unsigned char sha256_msg[] = @@ -95,20 +88,29 @@ void Test_Hash(void) MXC_TPU_Hash_SHA((char *)sha256_msg, MXC_TPU_HASH_SHA256, msgLen, (char *)destination); - Test_Result(memcmp(sha256_result, destination, 32)); - MXC_TPU_Shutdown(MXC_SYS_PERIPH_CLOCK_TPU); - return; + if (memcmp(sha256_result, destination, 32)) { + printf(" * Failed *\n\n"); + return -1; + } + + printf(" Passed \n\n"); + return 0; } int main(void) { printf("\n\n********** CTB Hash Example **********\n\n"); - Test_Hash(); + int fail = 0; + fail += Test_Hash(); - printf("\n*** Done ***\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/I2C/main.c b/Examples/MAX32665/I2C/main.c index 44c5a9026a6..6ed73dc4c9d 100644 --- a/Examples/MAX32665/I2C/main.c +++ b/Examples/MAX32665/I2C/main.c @@ -51,7 +51,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "dma.h" #include "board.h" @@ -75,8 +74,6 @@ #define I2C_SLAVE_ADDR 0x51 #define I2C_BYTES 255 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Sdata[I2C_BYTES]; static uint8_t txdata[I2C_BYTES]; @@ -190,9 +187,9 @@ int verifyData() } } if (fails > 0) { - return FAILED; + return E_FAIL; } else { - return PASSED; + return E_NO_ERROR; } } @@ -216,14 +213,14 @@ int main() error = MXC_I2C_Init(I2C_MASTER, 1, 0); if (error != E_NO_ERROR) { printf("Failed to initialize master.\n"); - return FAILED; + return error; } //Setup the I2CS error = MXC_I2C_Init(I2C_SLAVE, 0, I2C_SLAVE_ADDR); if (error != E_NO_ERROR) { printf("Failed to initialize slave.\n"); - return FAILED; + return error; } MXC_NVIC_SetVector(I2C_SLAVE_IRQn, I2C_Slave_IRQHandler); @@ -257,7 +254,7 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } MXC_DMA_ReleaseChannel(0); @@ -276,7 +273,7 @@ int main() #else if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -287,9 +284,10 @@ int main() printf("\n"); if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32665/I2C_SCAN/main.c b/Examples/MAX32665/I2C_SCAN/main.c index 01e263d4f71..64f7c330adf 100644 --- a/Examples/MAX32665/I2C_SCAN/main.c +++ b/Examples/MAX32665/I2C_SCAN/main.c @@ -46,7 +46,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "board.h" @@ -112,4 +111,5 @@ int main() } printf("\n-->Scan finished. %d devices found\n", counter); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/ICC/README.md b/Examples/MAX32665/ICC/README.md index 1a09b58603d..c3b3b153b7c 100644 --- a/Examples/MAX32665/ICC/README.md +++ b/Examples/MAX32665/ICC/README.md @@ -83,6 +83,6 @@ With instruction cache disabled: Time Elapsed: 10.160537 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32665/ICC/main.c b/Examples/MAX32665/ICC/main.c index dcf55625ad3..7972d1d99e9 100644 --- a/Examples/MAX32665/ICC/main.c +++ b/Examples/MAX32665/ICC/main.c @@ -148,11 +148,11 @@ int main(void) fail += 1; } - printf("\n\n"); - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/LP/main.c b/Examples/MAX32665/LP/main.c index db97830dd40..3ff1d2870aa 100644 --- a/Examples/MAX32665/LP/main.c +++ b/Examples/MAX32665/LP/main.c @@ -84,6 +84,12 @@ #error "You must select either USE_BUTTON or USE_ALARM, not both." #endif +#if USE_CONSOLE +#define PRINT(...) fprintf(stdout, __VA_ARGS__) +#else +#define PRINT(...) +#endif + // ***************************************************************************** #if USE_ALARM @@ -232,32 +238,25 @@ void recoverFromDeepSleep(void) int main(void) { -#if USE_CONSOLE - printf("\n\n****Low Power Mode Example****\n\n"); -#endif // USE_CONSOLE + PRINT("\n\n****Low Power Mode Example****\n\n"); #if USE_ALARM -#if USE_CONSOLE - printf("This code cycles through the MAX32665 power modes, using the RTC alarm to exit from " - "each mode. The modes will change every %d seconds.\n\n", - DELAY_IN_SEC); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32665 power modes, using the RTC alarm to exit from " + "each mode. The modes will change every %d seconds.\n\n", + DELAY_IN_SEC); MXC_NVIC_SetVector(RTC_IRQn, alarmHandler); #endif // USE_ALARM #if USE_BUTTON -#if USE_CONSOLE - printf("This code cycles through the MAX32665 power modes, using a push button 0 to exit from " - "each mode and enter the next.\n\n"); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32665 power modes, using a push button 0 to exit from " + "each mode and enter the next.\n\n"); PB_RegisterCallback(0, (pb_callback)buttonHandler); #endif // USE_BUTTON -#if USE_CONSOLE - printf("Running in ACTIVE mode.\n"); -#else + PRINT("Running in ACTIVE mode.\n"); +#if !USE_CONSOLE SYS_ClockDisable(SYS_PERIPH_CLOCK_UART0); -#endif // USE_CONSOLE +#endif // !USE_CONSOLE setTrigger(1); /* Prevent SIMO leakage in DS by reducing the SIMO buck clock */ @@ -278,9 +277,8 @@ int main(void) MXC_LP_SysRam1LightSleepDisable(); MXC_LP_SysRam0LightSleepDisable(); // Global variables are in RAM0 and RAM1 -#if USE_CONSOLE - printf("All unused RAMs placed in LIGHT SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("All unused RAMs placed in LIGHT SLEEP mode.\n"); + setTrigger(1); MXC_LP_ROM0Shutdown(); @@ -296,9 +294,8 @@ int main(void) MXC_LP_SysRam1PowerUp(); MXC_LP_SysRam0PowerUp(); // Global variables are in RAM0 and RAM1 -#if USE_CONSOLE - printf("All unused RAMs shutdown.\n"); -#endif // USE_CONSOLE + PRINT("All unused RAMs shutdown.\n"); + setTrigger(1); #if USE_BUTTON @@ -310,29 +307,23 @@ int main(void) while (1) { #if DO_SLEEP -#if USE_CONSOLE - printf("Entering SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering SLEEP mode.\n"); setTrigger(0); MXC_LP_EnterSleepMode(); - printf("Waking up from SLEEP mode.\n"); + PRINT("Waking up from SLEEP mode.\n"); #endif // DO_SLEEP #if DO_DEEPSLEEP -#if USE_CONSOLE - printf("Entering DEEPSLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering DEEPSLEEP mode.\n"); setTrigger(0); prepForDeepSleep(); MXC_LP_EnterDeepSleepMode(); recoverFromDeepSleep(); - printf("Waking up from DEEPSLEEP mode.\n"); + PRINT("Waking up from DEEPSLEEP mode.\n"); #endif // DO_DEEPSLEEP #if DO_BACKUP -#if USE_CONSOLE - printf("Entering BACKUP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering BACKUP mode.\n"); setTrigger(0); prepForDeepSleep(); MXC_LP_EnterBackupMode(NULL); diff --git a/Examples/MAX32665/MAA/main.c b/Examples/MAX32665/MAA/main.c index 1b274520b77..fb236e9c8dd 100644 --- a/Examples/MAX32665/MAA/main.c +++ b/Examples/MAX32665/MAA/main.c @@ -111,7 +111,7 @@ int main(void) if (retval != E_SUCCESS) { printf("Failed MAA_Init().\n"); printf("Example Failed\n"); - while (1) {} + return retval; } len = findLength(len); @@ -121,7 +121,7 @@ int main(void) if (retval != E_SUCCESS) { printf("Failed MAA_Compute().\n"); printf("Example Failed\n"); - while (1) {} + return retval; } //Fit into four byte array @@ -142,12 +142,11 @@ int main(void) fail += memcmp(result, result_data, sizeof(result_data)); - printf("\n"); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/OWM/main.c b/Examples/MAX32665/OWM/main.c index 2041af8faf7..dfedfa24294 100644 --- a/Examples/MAX32665/OWM/main.c +++ b/Examples/MAX32665/OWM/main.c @@ -174,9 +174,9 @@ int main(void) if (retval) { printf("Overdrive results: %d; %08x; %08x \n", retval, MXC_OWM->cfg, MXC_OWM->intfl); printf("Example Failed\n"); - } else { - printf("Example Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/SDHC_Raw/main.c b/Examples/MAX32665/SDHC_Raw/main.c index 654f60ade54..37221619e77 100644 --- a/Examples/MAX32665/SDHC_Raw/main.c +++ b/Examples/MAX32665/SDHC_Raw/main.c @@ -244,6 +244,7 @@ int multi_block_check(unsigned int width) /******************************************************************************/ int main(void) { + int fail = 0; mxc_sdhc_cfg_t cfg; int result; @@ -281,6 +282,7 @@ int main(void) printf("Card Initialized.\n"); } else { printf("No card response!\n"); + fail += 1; } if (MXC_SDHC_Lib_Get_Card_Type() == CARD_SDHC) { @@ -303,18 +305,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -324,18 +329,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -344,9 +352,16 @@ int main(void) if (multi_block_check(MXC_SDHC_LIB_QUAD_DATA)) { printf(" FAIL \n"); + fail += 1; } else { printf(" PASS \n"); } - printf(" *** END OF EXAMPLE *** \n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/SPI/main.c b/Examples/MAX32665/SPI/main.c index 30a33169f00..214d93720f1 100644 --- a/Examples/MAX32665/SPI/main.c +++ b/Examples/MAX32665/SPI/main.c @@ -121,10 +121,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, MAP_A) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, MAP_A); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -218,14 +218,13 @@ int main(void) } } - if (fail) { - printf("Example failed!\n"); - LED_On(0); - return -1; - } else { - printf("Example succeeded!\n"); - LED_On(1); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\nExample Failed\n"); + return E_FAIL; } + LED_On(1); // indicates SUCCESS + printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32665/SPIXF/main.c b/Examples/MAX32665/SPIXF/main.c index d7fec73630d..8e0b83fd48f 100644 --- a/Examples/MAX32665/SPIXF/main.c +++ b/Examples/MAX32665/SPIXF/main.c @@ -59,8 +59,6 @@ #define BUFF_SIZE 64 -int fail = 0; - /***** Functions *****/ // These are set in the linkerfile and give the starting and ending address of xip_section @@ -108,6 +106,7 @@ void spixf_cfg_setup() /******************************************************************************/ int main(void) { + int fail = 0; uint32_t id; void (*func)(void); uint8_t rx_buf[BUFF_SIZE]; @@ -125,7 +124,7 @@ int main(void) if (Ext_Flash_Init() != E_NO_ERROR) { printf("Board Init Failed\n"); printf("Example Failed\n"); - while (1) {} + return E_FAIL; } printf("External flash Initialized.\n\n"); @@ -137,7 +136,7 @@ int main(void) } else { printf("Error verifying external flash ID: 0x%x\n", id); printf("Example Failed\n"); - while (1) {} + return E_FAIL; } int err; @@ -203,10 +202,11 @@ int main(void) func(); printf("Returned from external flash\n\n"); - if (fail == 0) { - printf("Example Succeeded\n\n"); - } else { - printf("Example Failed\n\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/SPIXF_SFCC/main.c b/Examples/MAX32665/SPIXF_SFCC/main.c index 3be8e71a1ff..243cbfce38e 100644 --- a/Examples/MAX32665/SPIXF_SFCC/main.c +++ b/Examples/MAX32665/SPIXF_SFCC/main.c @@ -246,7 +246,8 @@ int main(void) printf("Example Succeeded\n\n"); } else { printf("Example Failed\n\n"); + return E_FAIL; } - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX32665/SPIXR/main.c b/Examples/MAX32665/SPIXR/main.c index 1ce369c87b3..1bfa2a8c05a 100644 --- a/Examples/MAX32665/SPIXR/main.c +++ b/Examples/MAX32665/SPIXR/main.c @@ -72,7 +72,7 @@ mxc_spixr_cfg_t init_cfg = { /***** Functions *****/ /******************************************************************************/ -void setup(void) +int setup(void) { uint8_t quad_cmd = A1024_EQIO; /* pre-defined command to use quad mode */ @@ -80,7 +80,7 @@ void setup(void) if (MXC_SPIXR_Init(&init_cfg) != E_NO_ERROR) { printf("\nSPIXR was not initialized properly.\n"); printf("\nExample Failed\n"); - while (1) {} + return E_UNINITIALIZED; } MXC_GCR->scon |= MXC_F_GCR_SCON_SRCC_DIS; @@ -106,6 +106,8 @@ void setup(void) MXC_SPIXR_ExMemSetReadCommand(A1024_READ); MXC_SPIXR_ExMemSetWriteCommand(A1024_WRITE); MXC_SPIXR_ExMemEnable(); + + return E_NO_ERROR; } // ***************************************************************************** @@ -129,7 +131,9 @@ int main(void) // Configure the SPIXR printf("\nSetting up the SPIXR\n"); - setup(); + if (E_NO_ERROR != setup()) { + fail += 1; + } // Initialize & write pseudo-random data to be written to the RAM printf("\nTX BUFFER:\t "); @@ -160,11 +164,11 @@ int main(void) printf("\n\nDATA IS VERIFIED.\n\n"); } - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/SRCC/README.md b/Examples/MAX32665/SRCC/README.md index da02d19ec5c..be47117bc46 100644 --- a/Examples/MAX32665/SRCC/README.md +++ b/Examples/MAX32665/SRCC/README.md @@ -18,5 +18,5 @@ Connect the jumper (JP7) to SPIRAM. Running test reads with data cache enabled. Time elapsed: 0.3587 Running test reads with data cache disabled. Time elapsed: 4.2092 -Example complete. +Example Succeeded. ``` diff --git a/Examples/MAX32665/SRCC/main.c b/Examples/MAX32665/SRCC/main.c index 0a4e18ceb29..ae1ea071847 100644 --- a/Examples/MAX32665/SRCC/main.c +++ b/Examples/MAX32665/SRCC/main.c @@ -63,6 +63,7 @@ #define ITERATIONS 5000 /***** Globals *****/ +int fail = 0; int s, ss; mxc_spixr_cfg_t init_cfg = { @@ -76,14 +77,14 @@ mxc_spixr_cfg_t init_cfg = { /***** Functions *****/ -void setup(void) +int setup(void) { uint8_t quad_cmd = A1024_EQIO; /* pre-defined command to use quad mode */ // Initialize the desired configuration if (MXC_SPIXR_Init(&init_cfg) != E_NO_ERROR) { printf("FAILED: SPIXR was not initialized properly.\n"); - return; + return E_UNINITIALIZED; } /* Hide this with function in SPIXR.C later */ @@ -107,6 +108,8 @@ void setup(void) MXC_SPIXR_ExMemSetReadCommand(A1024_READ); MXC_SPIXR_ExMemSetWriteCommand(A1024_WRITE); MXC_SPIXR_ExMemEnable(); + + return E_NO_ERROR; } void start_timer(void) @@ -135,7 +138,9 @@ void test_function(void) unsigned int seed = 0; // Configure the SPIXR - setup(); + if (E_NO_ERROR != setup()) { + fail += 1; + } // Initialize & write pseudo-random data to be written to the RAM for (i = 0; i < BUFFER_SIZE; i++) { @@ -155,6 +160,7 @@ void test_function(void) // Verify data being read from RAM if (memcmp(write_buffer, read_buffer, BUFFER_SIZE)) { printf("FAILED: Data was not read properly.\n\n"); + fail += 1; break; } } @@ -180,6 +186,11 @@ int main(void) MXC_SRCC_Disable(); test_function(); - printf("Example complete.\n"); - while (1) {} + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/TMR/main.c b/Examples/MAX32665/TMR/main.c index c7b2d1d4b55..33543471e34 100644 --- a/Examples/MAX32665/TMR/main.c +++ b/Examples/MAX32665/TMR/main.c @@ -220,10 +220,7 @@ int main(void) NVIC_EnableIRQ(OST_TIMER_IRQn); OneshotTimer(); - while (1) { - { - } - } + while (1) {} return 0; } diff --git a/Examples/MAX32665/UART/main.c b/Examples/MAX32665/UART/main.c index cdfb71cca09..1febff015b6 100644 --- a/Examples/MAX32665/UART/main.c +++ b/Examples/MAX32665/UART/main.c @@ -154,14 +154,14 @@ int main(void) if (error < E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } error = MXC_UART_Init(MXC_UART1, UART_BAUD, MAP_A); if (error < E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -193,8 +193,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -206,8 +205,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -232,15 +230,13 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - printf("-->EXAMPLE SUCCEEDED\n"); - LED_On(1); - } else { - printf("-->EXAMPLE FAILED\n"); - LED_On(0); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - while (1) {} + LED_On(1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32665/WearLeveling/main.c b/Examples/MAX32665/WearLeveling/main.c index 4afbe7f5392..9ed7ea1fced 100644 --- a/Examples/MAX32665/WearLeveling/main.c +++ b/Examples/MAX32665/WearLeveling/main.c @@ -183,11 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/AES/main.c b/Examples/MAX32670/AES/main.c index c45e15de7ed..ee3c7f95559 100644 --- a/Examples/MAX32670/AES/main.c +++ b/Examples/MAX32670/AES/main.c @@ -142,13 +142,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - printf("\n"); - - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/CRC/main.c b/Examples/MAX32670/CRC/main.c index 9f59bebd06f..c0aa3ca053d 100644 --- a/Examples/MAX32670/CRC/main.c +++ b/Examples/MAX32670/CRC/main.c @@ -63,16 +63,6 @@ void DMA0_IRQHandler(void) wait = 0; } -void Test_Result(int result) -{ - if (result) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } -} - void Test_CRC(int asynchronous) { uint32_t array[101]; @@ -120,7 +110,13 @@ void Test_CRC(int asynchronous) printf("\nCRC Check Result: %x", crc_req.resultCRC); - Test_Result(CHECK != crc_req.resultCRC); + if (CHECK != crc_req.resultCRC) { + printf(" \n**Test Failed**\n\n"); + fail++; + } else { + printf(" \n**Test Passed**\n\n"); + } + MXC_CRC_Shutdown(); } @@ -136,11 +132,11 @@ int main(void) NVIC_EnableIRQ(DMA0_IRQn); Test_CRC(1); - if (fail) { + if (fail != 0) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/DMA/main.c b/Examples/MAX32670/DMA/main.c index 05e1ad820d2..61327fff60e 100644 --- a/Examples/MAX32670/DMA/main.c +++ b/Examples/MAX32670/DMA/main.c @@ -53,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -74,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -95,36 +94,35 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); + fail += 1; + } else { + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} + while (flag == 0) {} - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); - while (1) {} + while (1) {} - fail += 1; - } else { - printf("Data verified.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -193,9 +191,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -203,8 +198,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -212,23 +206,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/Flash/main.c b/Examples/MAX32670/Flash/main.c index 5f5a639ef59..cc8dd0bb4f7 100644 --- a/Examples/MAX32670/Flash/main.c +++ b/Examples/MAX32670/Flash/main.c @@ -411,11 +411,11 @@ int main(void) MXC_ICC_Enable(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/I2C/main.c b/Examples/MAX32670/I2C/main.c index 816fd2e8cdf..59f43fef2ce 100644 --- a/Examples/MAX32670/I2C/main.c +++ b/Examples/MAX32670/I2C/main.c @@ -67,8 +67,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 100 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -191,10 +189,10 @@ int verifyData() } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -214,7 +212,7 @@ int main() if (error != E_NO_ERROR) { printf("-->Failed master\n"); - return FAILED; + return error; } else { printf("\n-->I2C Master Initialization Complete"); } @@ -224,7 +222,7 @@ int main() if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } else { printf("\n-->I2C Slave Initialization Complete"); } @@ -260,12 +258,12 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -278,9 +276,10 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32670/I2C_SCAN/main.c b/Examples/MAX32670/I2C_SCAN/main.c index f01537142e7..21214dc0bf3 100644 --- a/Examples/MAX32670/I2C_SCAN/main.c +++ b/Examples/MAX32670/I2C_SCAN/main.c @@ -95,4 +95,5 @@ int main() } printf("\n-->Scan finished. %d devices found\n", counter); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/ICC/README.md b/Examples/MAX32670/ICC/README.md index 094cf4c1864..ad04d864bde 100644 --- a/Examples/MAX32670/ICC/README.md +++ b/Examples/MAX32670/ICC/README.md @@ -84,6 +84,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32670/ICC/main.c b/Examples/MAX32670/ICC/main.c index 5204ed4b172..44bf179201e 100644 --- a/Examples/MAX32670/ICC/main.c +++ b/Examples/MAX32670/ICC/main.c @@ -152,11 +152,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/LP/main.c b/Examples/MAX32670/LP/main.c index e2ec45e8658..01616232683 100644 --- a/Examples/MAX32670/LP/main.c +++ b/Examples/MAX32670/LP/main.c @@ -86,6 +86,12 @@ #error "You must select either DO_BACKUP or DO_STORAGE or neither, not both." #endif +#if USE_CONSOLE +#define PRINT(...) fprintf(stdout, __VA_ARGS__) +#else +#define PRINT(...) +#endif + // ***************************************************************************** #if USE_ALARM @@ -186,9 +192,7 @@ int main(void) { MXC_ECC->en = 0; // Disable ECC on Flash, ICC, and SRAM -#if USE_CONSOLE - printf("****Low Power Mode Example****\n\n"); -#endif // USE_CONSOLE + PRINT("****Low Power Mode Example****\n\n"); #if USE_BUTTON MXC_LP_EnableGPIOWakeup((mxc_gpio_cfg_t *)&pb_pin[0]); @@ -198,70 +202,55 @@ int main(void) #endif // USE_ALARM #if USE_ALARM -#if USE_CONSOLE - printf("This code cycles through the MAX32670 power modes, using the RTC alarm to exit from " - "each mode. The modes will change every %d seconds.\n\n", - DELAY_IN_SEC); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32670 power modes, using the RTC alarm to exit from " + "each mode. The modes will change every %d seconds.\n\n", + DELAY_IN_SEC); MXC_NVIC_SetVector(RTC_IRQn, alarmHandler); #endif // USE_ALARM #if USE_BUTTON -#if USE_CONSOLE - printf("This code cycles through the MAX32670 power modes, using a push button (SW3) to exit " - "from each mode and enter the next.\n\n"); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32670 power modes, using a push button (SW3) to exit " + "from each mode and enter the next.\n\n"); PB_RegisterCallback(0, buttonHandler); #endif // USE_BUTTON //Pull down all GPIOs except PB0 and UART0 pins configure_gpio(); -#if USE_CONSOLE - printf("Running in ACTIVE mode.\n"); -#else + PRINT("Running in ACTIVE mode.\n"); +#if !USE_CONSOLE MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_UART0); -#endif // USE_CONSOLE +#endif // !USE_CONSOLE setTrigger(1); MXC_LP_ROMLightSleepEnable(); -#if USE_CONSOLE - printf("ROM placed in LIGHT SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("ROM placed in LIGHT SLEEP mode.\n"); setTrigger(1); while (1) { #if DO_SLEEP -#if USE_CONSOLE - printf("Entering SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering SLEEP mode.\n"); setTrigger(0); MXC_LP_EnterSleepMode(); - printf("Waking up from SLEEP mode.\n"); + PRINT("Waking up from SLEEP mode.\n"); #endif // DO_SLEEP #if DO_DEEPSLEEP -#if USE_CONSOLE - printf("Entering DEEPSLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering DEEPSLEEP mode.\n"); setTrigger(0); MXC_LP_EnterDeepSleepMode(); - printf("Waking up from DEEPSLEEP mode.\n"); + PRINT("Waking up from DEEPSLEEP mode.\n"); #endif // DO_DEEPSLEEP #if DO_BACKUP -#if USE_CONSOLE - printf("Entering BACKUP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering BACKUP mode.\n"); setTrigger(0); MXC_LP_EnterBackupMode(); #endif // DO_BACKUP #if DO_SHUTDOWN -#if USE_CONSOLE - printf("Entering Shutdown mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering Shutdown mode.\n"); setTrigger(0); MXC_LP_EnterShutDownMode(); #endif // DO_STORAGE diff --git a/Examples/MAX32670/SPI/main.c b/Examples/MAX32670/SPI/main.c index dd9d09f8152..1bcc12a4ba7 100644 --- a/Examples/MAX32670/SPI/main.c +++ b/Examples/MAX32670/SPI/main.c @@ -115,10 +115,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32670/UART/README.md b/Examples/MAX32670/UART/README.md index c3450893807..3df3719b30f 100644 --- a/Examples/MAX32670/UART/README.md +++ b/Examples/MAX32670/UART/README.md @@ -34,7 +34,7 @@ P0.28 -> P0.15 and P0.29 -> P0.14 -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` The green LED (P0_23) will illuminate for successful transaction. diff --git a/Examples/MAX32670/UART/main.c b/Examples/MAX32670/UART/main.c index c56c6e9b21c..5dc6ec44aea 100644 --- a/Examples/MAX32670/UART/main.c +++ b/Examples/MAX32670/UART/main.c @@ -123,13 +123,13 @@ int main(void) if ((error = MXC_UART_Init(MXC_UART1, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(MXC_UART2, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -160,8 +160,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -169,8 +168,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -195,15 +193,13 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - LED_On(1); - printf("-->EXAMPLE SUCCEEDED\n"); - } else { + if (fail != 0) { LED_On(0); - printf("-->EXAMPLE FAILED\n"); + printf("\n-->Example Failed\n"); + return E_FAIL; } - return 0; + LED_On(1); + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32670/WearLeveling/main.c b/Examples/MAX32670/WearLeveling/main.c index 9b261b7b972..14660acaedc 100644 --- a/Examples/MAX32670/WearLeveling/main.c +++ b/Examples/MAX32670/WearLeveling/main.c @@ -185,9 +185,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/AES/main.c b/Examples/MAX32672/AES/main.c index bbfed45373e..e0a2e2d0187 100644 --- a/Examples/MAX32672/AES/main.c +++ b/Examples/MAX32672/AES/main.c @@ -46,7 +46,6 @@ #include "board.h" #include "dma.h" #include "aes.h" -#include "aes_regs.h" /***** Definitions *****/ @@ -115,14 +114,13 @@ int AES_decrypt(int asynchronous, mxc_aes_keys_t key) MXC_AES_Shutdown(); - if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) == 0) { - printf("\nData Verified"); - return E_NO_ERROR; + if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) != 0) { + printf("\nData Mismatch"); + return 1; } - printf("\nData Mismatch"); - - return 1; + printf("\nData Verified"); + return E_NO_ERROR; } // ***************************************************************************** @@ -145,11 +143,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/CRC/main.c b/Examples/MAX32672/CRC/main.c index f8616a3746d..c4d590f1f20 100644 --- a/Examples/MAX32672/CRC/main.c +++ b/Examples/MAX32672/CRC/main.c @@ -67,16 +67,7 @@ void Test_Callback(void *req, int result) callback_result = result; } -void Test_Result(int result) -{ - if (result) { - printf(" * Failed *\n\n"); - } else { - printf(" Passed \n\n"); - } -} - -void Test_CRC(int asynchronous) +int Test_CRC(int asynchronous) { uint32_t array[101]; int i; @@ -118,17 +109,31 @@ void Test_CRC(int asynchronous) MXC_CTB_CRC_Compute(&crc_req); } - Test_Result(CHECK != crc_req.resultCRC); MXC_CTB_Shutdown(MXC_CTB_FEATURE_CRC | MXC_CTB_FEATURE_DMA); + + if (CHECK != crc_req.resultCRC) { + printf(" * Failed *\n\n"); + return -1; + } + + printf(" Passed \n\n"); + return 0; } // ***************************************************************************** int main(void) { printf("\n************ CRC Example ***********\n"); - Test_CRC(0); + int fail = 0; + fail += Test_CRC(0); NVIC_EnableIRQ(CRYPTO_IRQn); - Test_CRC(1); + fail += Test_CRC(1); - return 0; + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/CTB_AES/main.c b/Examples/MAX32672/CTB_AES/main.c index d54af206667..955b6de637a 100644 --- a/Examples/MAX32672/CTB_AES/main.c +++ b/Examples/MAX32672/CTB_AES/main.c @@ -114,35 +114,42 @@ int AES_Test(mxc_ctb_cipher_t aesKey) if (memcmp(inputData, (void *)decryptedData, MXC_AES_DATA_LENGTH) == 0) { return E_NO_ERROR; } - return 1; + return E_INVALID; } // ***************************************************************************** int main(void) { printf("\n***** AES Example *****\n"); - int fail = 0; + int ret = 0; // Initialize CTB and TRNG MXC_CTB_Init(MXC_CTB_FEATURE_CIPHER | MXC_CTB_FEATURE_DMA); MXC_TRNG_Init(); // Run AES Test with 128-Bit encryption key printf("AES 128-bit Key Test"); - fail = AES_Test(MXC_CTB_CIPHER_AES128); - printf(" --> %s\n", ((fail == E_NO_ERROR) ? "PASS" : "FAIL")); + ret = AES_Test(MXC_CTB_CIPHER_AES128); + fail += ret; + printf(" --> %s\n", ((ret == E_NO_ERROR) ? "PASS" : "FAIL")); // Run AES Test with 192-Bit encryption key printf("AES 192-bit Key Test"); - fail = AES_Test(MXC_CTB_CIPHER_AES192); - printf(" --> %s\n", ((fail == E_NO_ERROR) ? "PASS" : "FAIL")); + ret = AES_Test(MXC_CTB_CIPHER_AES192); + fail += ret; + printf(" --> %s\n", ((ret == E_NO_ERROR) ? "PASS" : "FAIL")); // Run AES Test with 256-Bit encryption key printf("AES 256-bit Key Test"); - fail = AES_Test(MXC_CTB_CIPHER_AES256); - printf(" --> %s\n", ((fail == E_NO_ERROR) ? "PASS" : "FAIL")); + ret = AES_Test(MXC_CTB_CIPHER_AES256); + fail += ret; + printf(" --> %s\n", ((ret == E_NO_ERROR) ? "PASS" : "FAIL")); - printf("\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/DMA/main.c b/Examples/MAX32672/DMA/main.c index 94266b30bf3..f2572b97acb 100644 --- a/Examples/MAX32672/DMA/main.c +++ b/Examples/MAX32672/DMA/main.c @@ -55,7 +55,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -76,10 +75,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -97,36 +96,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -195,9 +190,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -205,8 +197,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -214,7 +205,7 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } void disableECCforRAM(void) @@ -227,19 +218,20 @@ void disableECCforRAM(void) // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); disableECCforRAM(); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/Flash/main.c b/Examples/MAX32672/Flash/main.c index 4174c613e0e..d4641a18c74 100644 --- a/Examples/MAX32672/Flash/main.c +++ b/Examples/MAX32672/Flash/main.c @@ -428,11 +428,12 @@ int main(void) fail += partial_erase_test(MXC_FLASH1_MEM_BASE); MXC_ICC_Enable(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/I2C/main.c b/Examples/MAX32672/I2C/main.c index 52a730d0449..dc79988884e 100644 --- a/Examples/MAX32672/I2C/main.c +++ b/Examples/MAX32672/I2C/main.c @@ -65,8 +65,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 100 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -187,10 +185,10 @@ int verifyData() } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -213,7 +211,7 @@ int main() if (error != E_NO_ERROR) { printf("-->Failed master\n"); - return FAILED; + return error; } else { printf("\n-->I2C Master Initialization Complete"); } @@ -223,7 +221,7 @@ int main() if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } else { printf("\n-->I2C Slave Initialization Complete"); } @@ -259,12 +257,12 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) { @@ -280,9 +278,10 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32672/ICC/README.md b/Examples/MAX32672/ICC/README.md index d6705fc6f6c..21d5b6c6b4d 100644 --- a/Examples/MAX32672/ICC/README.md +++ b/Examples/MAX32672/ICC/README.md @@ -84,7 +84,7 @@ With instruction cache disabled: Time Elapsed: 9.507815 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32672/ICC/main.c b/Examples/MAX32672/ICC/main.c index 5204ed4b172..44bf179201e 100644 --- a/Examples/MAX32672/ICC/main.c +++ b/Examples/MAX32672/ICC/main.c @@ -152,11 +152,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/SPI/main.c b/Examples/MAX32672/SPI/main.c index 5944639e0bd..1c3efcb4f9e 100644 --- a/Examples/MAX32672/SPI/main.c +++ b/Examples/MAX32672/SPI/main.c @@ -115,10 +115,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32672/SPI_MasterSlave/README.md b/Examples/MAX32672/SPI_MasterSlave/README.md index 46e146a50e4..7a9b070d94d 100644 --- a/Examples/MAX32672/SPI_MasterSlave/README.md +++ b/Examples/MAX32672/SPI_MasterSlave/README.md @@ -27,5 +27,5 @@ green LED will illuminate, otherwise the red LED will illuminate. Press SW3 to begin transaction. -EXAMPLE SUCCEEDED! +Example Succeeded ``` \ No newline at end of file diff --git a/Examples/MAX32672/SPI_MasterSlave/main.c b/Examples/MAX32672/SPI_MasterSlave/main.c index d2ced3b8a6d..3b5e2b7b4fe 100644 --- a/Examples/MAX32672/SPI_MasterSlave/main.c +++ b/Examples/MAX32672/SPI_MasterSlave/main.c @@ -150,19 +150,18 @@ int main(void) /***** Verify Results *****/ if (memcmp(slave_rx, master_tx, sizeof(master_tx)) != 0) { // Master->Slave printf("\nSlave failed to receive data.\n"); - LED_On(0); + LED_On(0); // indicates FAIL return E_COMM_ERR; } else if (memcmp(master_rx, slave_tx, sizeof(slave_tx)) != 0) { // Slave->Master printf("\nMaster failed to receive data.\n"); - LED_On(0); + LED_On(0); // indicates FAIL return E_COMM_ERR; - } else { - printf("EXAMPLE SUCCEEDED!\n"); - LED_On(1); } MXC_SPI_Shutdown(SPI_MASTER); MXC_SPI_Shutdown(SPI_SLAVE); + LED_On(1); // indicates SUCCESS + printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32672/UART/README.md b/Examples/MAX32672/UART/README.md index 4bc6d179cbc..881dc19a7c1 100644 --- a/Examples/MAX32672/UART/README.md +++ b/Examples/MAX32672/UART/README.md @@ -36,7 +36,7 @@ P0.28 -> P0.15 (AIN7) and P0.29 -> P0.14 (AIN6) -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` diff --git a/Examples/MAX32672/UART/main.c b/Examples/MAX32672/UART/main.c index 4cabcdb462d..750e5ed5e8e 100644 --- a/Examples/MAX32672/UART/main.c +++ b/Examples/MAX32672/UART/main.c @@ -122,8 +122,7 @@ int main(void) if (error < E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } else { printf("-->UART Initialized\n\n"); } @@ -154,8 +153,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -163,8 +161,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -189,13 +186,13 @@ int main(void) printf("-->Data verified\n"); } - if (fail == 0) { - LED_On(1); - printf("\n-->EXAMPLE SUCCEEDED\n"); - } else { - LED_On(0); - printf("\n-->EXAMPLE FAILED\n"); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - return 0; + LED_On(1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32672/WearLeveling/main.c b/Examples/MAX32672/WearLeveling/main.c index 5ff2ffd11d4..57fd73df900 100644 --- a/Examples/MAX32672/WearLeveling/main.c +++ b/Examples/MAX32672/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/AES/main.c b/Examples/MAX32675/AES/main.c index 5f77b778d03..7d8d2bdc9fb 100644 --- a/Examples/MAX32675/AES/main.c +++ b/Examples/MAX32675/AES/main.c @@ -46,7 +46,6 @@ #include "board.h" #include "dma.h" #include "aes.h" -#include "aes_regs.h" /***** Definitions *****/ #define MXC_AES_DATA_LENGTH 8 //4 words @@ -114,14 +113,13 @@ int AES_decrypt(int asynchronous, mxc_aes_keys_t key) MXC_AES_Shutdown(); - if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) == 0) { - printf("\nData Verified"); - return E_NO_ERROR; + if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) != 0) { + printf("\nData Mismatch"); + return 1; } - printf("\nData Mismatch"); - - return 1; + printf("\nData Verified"); + return E_NO_ERROR; } // ***************************************************************************** @@ -145,13 +143,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - printf("\n"); - - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/AFE_DAC/main.c b/Examples/MAX32675/AFE_DAC/main.c index a3202fd190a..f1a49e80fdc 100644 --- a/Examples/MAX32675/AFE_DAC/main.c +++ b/Examples/MAX32675/AFE_DAC/main.c @@ -46,7 +46,6 @@ #include "board.h" #include "mxc_delay.h" #include "afe.h" -#include "afe_dac_regs.h" /***** Definitions *****/ diff --git a/Examples/MAX32675/CRC/main.c b/Examples/MAX32675/CRC/main.c index 34399403be3..750dac87c8d 100644 --- a/Examples/MAX32675/CRC/main.c +++ b/Examples/MAX32675/CRC/main.c @@ -65,16 +65,6 @@ void DMA0_IRQHandler(void) wait = 0; } -void Test_Result(int result) -{ - if (result) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } -} - void Test_CRC(int asynchronous) { uint32_t array[101]; @@ -122,7 +112,13 @@ void Test_CRC(int asynchronous) printf("\nCRC Check Result: %x", crc_req.resultCRC); - Test_Result(CHECK != crc_req.resultCRC); + if (CHECK != crc_req.resultCRC) { + printf(" \n**Test Failed**\n\n"); + fail++; + } else { + printf(" \n**Test Passed**\n\n"); + } + MXC_CRC_Shutdown(); } @@ -138,13 +134,11 @@ int main(void) NVIC_EnableIRQ(DMA0_IRQn); Test_CRC(1); - if (fail) { - printf("\nExample Failed"); - } else { - printf("\nExample Succeeded"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - printf("\n\n"); - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/DMA/main.c b/Examples/MAX32675/DMA/main.c index 2b9273f6f5e..01a3d809f02 100644 --- a/Examples/MAX32675/DMA/main.c +++ b/Examples/MAX32675/DMA/main.c @@ -45,7 +45,6 @@ #include "mxc_device.h" #include "nvic_table.h" #include "dma.h" -#include "dma_regs.h" /***** Definitions *****/ @@ -54,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -75,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -96,36 +94,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -213,25 +207,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); - - printf("\n"); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/Flash/main.c b/Examples/MAX32675/Flash/main.c index 6b0502e795d..c63cd5fe6b1 100644 --- a/Examples/MAX32675/Flash/main.c +++ b/Examples/MAX32675/Flash/main.c @@ -47,7 +47,6 @@ #include "nvic_table.h" #include "flc.h" #include "icc.h" -#include "flc_regs.h" #include "gcr_regs.h" /***** Definitions *****/ @@ -409,13 +408,11 @@ int main(void) MXC_ICC_Enable(); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/Flash_CLI/main.c b/Examples/MAX32675/Flash_CLI/main.c index d2e246d4515..951ca037d48 100644 --- a/Examples/MAX32675/Flash_CLI/main.c +++ b/Examples/MAX32675/Flash_CLI/main.c @@ -51,7 +51,6 @@ #include "definitions.h" #include "dma.h" #include "flc.h" -#include "flc_regs.h" #include "gcr_regs.h" #include "icc.h" #include "mxc_assert.h" diff --git a/Examples/MAX32675/I2C/main.c b/Examples/MAX32675/I2C/main.c index 44b89de2f9c..b74642b7de5 100644 --- a/Examples/MAX32675/I2C/main.c +++ b/Examples/MAX32675/I2C/main.c @@ -51,7 +51,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "dma.h" @@ -68,8 +67,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 100 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -192,9 +189,9 @@ int verifyData() } if (fails > 0) { - return FAILED; + return E_FAIL; } else { - return PASSED; + return E_NO_ERROR; } } @@ -215,7 +212,7 @@ int main() if (error != E_NO_ERROR) { printf("-->Failed master\n"); - return FAILED; + return error; } else { printf("\n-->I2C Master Initialization Complete"); } @@ -225,7 +222,7 @@ int main() if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } else { printf("\n-->I2C Slave Initialization Complete"); } @@ -261,12 +258,12 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -279,9 +276,10 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32675/I2C_SCAN/main.c b/Examples/MAX32675/I2C_SCAN/main.c index 12d9aabfcd0..61f1d8353f2 100644 --- a/Examples/MAX32675/I2C_SCAN/main.c +++ b/Examples/MAX32675/I2C_SCAN/main.c @@ -95,4 +95,5 @@ int main() } printf("\n-->Scan finished. %d devices found\n", counter); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/I2S/main.c b/Examples/MAX32675/I2S/main.c index 7c05bb501ed..a54545366fc 100644 --- a/Examples/MAX32675/I2S/main.c +++ b/Examples/MAX32675/I2S/main.c @@ -45,7 +45,6 @@ #include "mxc_device.h" #include "mxc_delay.h" #include "nvic_table.h" -#include "i2s_regs.h" #include "board.h" #include "i2s.h" #include "tmr.h" diff --git a/Examples/MAX32675/ICC/README.md b/Examples/MAX32675/ICC/README.md index 9958813075a..0fcf6955900 100644 --- a/Examples/MAX32675/ICC/README.md +++ b/Examples/MAX32675/ICC/README.md @@ -83,6 +83,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32675/ICC/main.c b/Examples/MAX32675/ICC/main.c index 0cbb576e2c5..44bf179201e 100644 --- a/Examples/MAX32675/ICC/main.c +++ b/Examples/MAX32675/ICC/main.c @@ -152,13 +152,11 @@ int main(void) fail += 1; } - printf("\n\n"); - - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/LP/main.c b/Examples/MAX32675/LP/main.c index 146f65feee8..fbe94919016 100644 --- a/Examples/MAX32675/LP/main.c +++ b/Examples/MAX32675/LP/main.c @@ -75,6 +75,12 @@ #error "You must select either DO_BACKUP or DO_STORAGE or neither, not both." #endif +#if USE_CONSOLE +#define PRINT(...) fprintf(stdout, __VA_ARGS__) +#else +#define PRINT(...) +#endif + // ***************************************************************************** volatile int buttonPressed; void buttonHandler(void *pb) @@ -129,24 +135,19 @@ void configure_gpio(void) int main(void) { -#if USE_CONSOLE - printf("****Low Power Mode Example****\n\n"); -#endif // USE_CONSOLE + PRINT("****Low Power Mode Example****\n\n"); -#if USE_CONSOLE - printf("This code cycles through the MAX32675 power modes, using a push button 0 (SW1) to exit " - "from each mode and enter the next.\n\n"); -#endif // USE_CONSOLE + PRINT("This code cycles through the MAX32675 power modes, using a push button 0 (SW1) to exit " + "from each mode and enter the next.\n\n"); PB_RegisterCallback(0, buttonHandler); //Pull down all GPIOs except PB0 and UART0 pins configure_gpio(); -#if USE_CONSOLE - printf("Running in ACTIVE mode.\n"); -#else + PRINT("Running in ACTIVE mode.\n"); +#if !USE_CONSOLE MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_UART0); -#endif // USE_CONSOLE +#endif // !USE_CONSOLE setTrigger(1); MXC_LP_ROMLightSleepEnable(); @@ -156,9 +157,7 @@ int main(void) MXC_LP_SysRam1LightSleepDisable(); MXC_LP_SysRam0LightSleepDisable(); // Global variables are in RAM0 and RAM1 -#if USE_CONSOLE - printf("All unused RAMs placed in LIGHT SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("All unused RAMs placed in LIGHT SLEEP mode.\n"); setTrigger(1); // MXC_LP_SysRam3Shutdown(); @@ -167,44 +166,34 @@ int main(void) MXC_LP_SysRam1PowerUp(); MXC_LP_SysRam0PowerUp(); // Global variables are in RAM0 and RAM1 -#if USE_CONSOLE - printf("All unused RAMs shutdown.\n"); -#endif // USE_CONSOLE + PRINT("All unused RAMs shutdown.\n"); setTrigger(1); MXC_LP_EnableGPIOWakeup((mxc_gpio_cfg_t *)&pb_pin[0]); while (1) { #if DO_SLEEP -#if USE_CONSOLE - printf("Entering SLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering SLEEP mode.\n"); setTrigger(0); MXC_LP_EnterSleepMode(); - printf("Waking up from SLEEP mode.\n"); + PRINT("Waking up from SLEEP mode.\n"); #endif // DO_SLEEP #if DO_DEEPSLEEP -#if USE_CONSOLE - printf("Entering DEEPSLEEP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering DEEPSLEEP mode.\n"); setTrigger(0); MXC_LP_EnterDeepSleepMode(); - printf("Waking up from DEEPSLEEP mode.\n"); + PRINT("Waking up from DEEPSLEEP mode.\n"); #endif // DO_DEEPSLEEP #if DO_BACKUP -#if USE_CONSOLE - printf("Entering BACKUP mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering BACKUP mode.\n"); setTrigger(0); MXC_LP_EnterBackupMode(); #endif // DO_BACKUP #if DO_SHUTDOWN -#if USE_CONSOLE - printf("Entering Shutdown mode.\n"); -#endif // USE_CONSOLE + PRINT("Entering Shutdown mode.\n"); setTrigger(0); MXC_LP_EnterShutDownMode(); #endif // DO_STORAGE diff --git a/Examples/MAX32675/SPI/main.c b/Examples/MAX32675/SPI/main.c index 4ca639f6116..5db441adf1b 100644 --- a/Examples/MAX32675/SPI/main.c +++ b/Examples/MAX32675/SPI/main.c @@ -117,10 +117,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -219,14 +219,13 @@ int main(void) } } - if (fail) { - printf("\nExample failed!\n"); - LED_On(0); - return -1; - } else { - printf("\nExample succeeded!\n"); - LED_On(1); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\nExample Failed\n"); + return E_FAIL; } + LED_On(1); // indicates SUCCESS + printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32675/UART/README.md b/Examples/MAX32675/UART/README.md index 577ba2b0a47..a49e75ac057 100644 --- a/Examples/MAX32675/UART/README.md +++ b/Examples/MAX32675/UART/README.md @@ -37,7 +37,7 @@ P0.8 -> P0.15 and P0.9 -> P0.14 -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` The green LED1 will illuminate for successful transaction. diff --git a/Examples/MAX32675/UART/main.c b/Examples/MAX32675/UART/main.c index 8d1168d1f0c..3309f659db6 100644 --- a/Examples/MAX32675/UART/main.c +++ b/Examples/MAX32675/UART/main.c @@ -130,13 +130,13 @@ int main(void) if ((error = MXC_UART_Init(READING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(WRITING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } // Max baud rate for most serial ports is 115200 @@ -170,7 +170,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -178,7 +178,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } #ifdef DMA @@ -203,15 +203,13 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - LED_On(1); - printf("-->EXAMPLE SUCCEEDED\n"); - } else { - LED_On(0); - printf("-->EXAMPLE FAILED\n"); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - return 0; + LED_On(1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32675/WearLeveling/main.c b/Examples/MAX32675/WearLeveling/main.c index a1b4f04c7c4..6fdd1701fe6 100644 --- a/Examples/MAX32675/WearLeveling/main.c +++ b/Examples/MAX32675/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/AES/main.c b/Examples/MAX32680/AES/main.c index fe29d78ee59..e9bc75545f3 100644 --- a/Examples/MAX32680/AES/main.c +++ b/Examples/MAX32680/AES/main.c @@ -144,15 +144,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - printf("\n"); - - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/CRC/main.c b/Examples/MAX32680/CRC/main.c index ad35d2997ea..45d61849126 100644 --- a/Examples/MAX32680/CRC/main.c +++ b/Examples/MAX32680/CRC/main.c @@ -65,16 +65,6 @@ void DMA0_IRQHandler(void) wait = 0; } -void Test_Result(int result) -{ - if (result) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } -} - void Test_CRC(int asynchronous) { uint32_t array[101]; @@ -122,7 +112,13 @@ void Test_CRC(int asynchronous) printf("\nCRC Check Result: %x", crc_req.resultCRC); - Test_Result(CHECK != crc_req.resultCRC); + if (CHECK != crc_req.resultCRC) { + printf(" \n**Test Failed**\n\n"); + fail++; + } else { + printf(" \n**Test Passed**\n\n"); + } + MXC_CRC_Shutdown(); } @@ -138,13 +134,11 @@ int main(void) NVIC_EnableIRQ(DMA0_IRQn); Test_CRC(1); - if (fail) { - printf("\nExample Failed"); - } else { - printf("\nExample Succeeded"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - printf("\n\n"); - - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/DMA/main.c b/Examples/MAX32680/DMA/main.c index df524cb03b8..bfd95cf894a 100644 --- a/Examples/MAX32680/DMA/main.c +++ b/Examples/MAX32680/DMA/main.c @@ -53,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -74,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -95,36 +94,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -193,9 +188,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -203,8 +195,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -212,29 +203,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); - - while (1) {} + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/Flash/main.c b/Examples/MAX32680/Flash/main.c index f2c15458fe8..3a48d11aef4 100644 --- a/Examples/MAX32680/Flash/main.c +++ b/Examples/MAX32680/Flash/main.c @@ -408,15 +408,11 @@ int main(void) MXC_ICC_Enable(MXC_ICC0); - printf("\n"); - - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/I2C/main.c b/Examples/MAX32680/I2C/main.c index f0ba8e72c36..7d8831f3564 100644 --- a/Examples/MAX32680/I2C/main.c +++ b/Examples/MAX32680/I2C/main.c @@ -63,8 +63,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 100 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -187,10 +185,10 @@ int verifyData() } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -210,7 +208,7 @@ int main() if (error != E_NO_ERROR) { printf("-->Failed master\n"); - return FAILED; + return error; } else { printf("\n-->I2C Master Initialization Complete"); } @@ -220,7 +218,7 @@ int main() if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } else { printf("\n-->I2C Slave Initialization Complete"); } @@ -257,12 +255,12 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -275,9 +273,10 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32680/ICC/README.md b/Examples/MAX32680/ICC/README.md index ed223d25dff..53e78f47794 100644 --- a/Examples/MAX32680/ICC/README.md +++ b/Examples/MAX32680/ICC/README.md @@ -85,6 +85,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32680/ICC/main.c b/Examples/MAX32680/ICC/main.c index 00ac07e1557..a2b98fd81c6 100644 --- a/Examples/MAX32680/ICC/main.c +++ b/Examples/MAX32680/ICC/main.c @@ -153,13 +153,11 @@ int main(void) fail += 1; } - printf("\n\n"); - - if (fail == 0) { - printf("EXAMPLE SUCCEEDED\n"); - } else { - printf("EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - while (1) {} + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/SPI/main.c b/Examples/MAX32680/SPI/main.c index 40e6e8712ca..266464520ae 100644 --- a/Examples/MAX32680/SPI/main.c +++ b/Examples/MAX32680/SPI/main.c @@ -140,10 +140,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); diff --git a/Examples/MAX32680/UART/README.md b/Examples/MAX32680/UART/README.md index b41d24d2870..f0248a5be5f 100644 --- a/Examples/MAX32680/UART/README.md +++ b/Examples/MAX32680/UART/README.md @@ -34,7 +34,7 @@ P2.6 -> P1.1 and P2.7 -> P1.0 -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` The green LED (P0_25) will illuminate for successful transaction. diff --git a/Examples/MAX32680/UART/main.c b/Examples/MAX32680/UART/main.c index 9f466efb243..02bf2548438 100644 --- a/Examples/MAX32680/UART/main.c +++ b/Examples/MAX32680/UART/main.c @@ -116,13 +116,13 @@ int main(void) if ((error = MXC_UART_Init(MXC_UART3, UART_BAUD, MXC_UART_IBRO_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(MXC_UART2, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -153,8 +153,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -162,8 +161,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -188,15 +186,13 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - LED_On(1); - printf("-->EXAMPLE SUCCEEDED\n"); - } else { - LED_On(0); - printf("-->EXAMPLE FAILED\n"); + if (fail != 0) { + LED_On(0); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - while (1) {} + LED_On(1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32680/WearLeveling/main.c b/Examples/MAX32680/WearLeveling/main.c index 886a9919246..54e5298d094 100644 --- a/Examples/MAX32680/WearLeveling/main.c +++ b/Examples/MAX32680/WearLeveling/main.c @@ -183,11 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/CRC/main.c b/Examples/MAX32690/CRC/main.c index 9e6766496d2..aa1d1aea702 100644 --- a/Examples/MAX32690/CRC/main.c +++ b/Examples/MAX32690/CRC/main.c @@ -66,16 +66,7 @@ void Test_Callback(void *req, int result) callback_result = result; } -void Test_Result(int result) -{ - if (result) { - printf(" * Failed *\n\n"); - } else { - printf(" Passed \n\n"); - } -} - -void Test_CRC(int asynchronous) +int Test_CRC(int asynchronous) { uint32_t array[101]; int i; @@ -117,19 +108,33 @@ void Test_CRC(int asynchronous) MXC_CTB_CRC_Compute(&crc_req); } - Test_Result(CHECK != crc_req.resultCRC); MXC_CTB_Shutdown(MXC_CTB_FEATURE_CRC | MXC_CTB_FEATURE_DMA); + + if (CHECK != crc_req.resultCRC) { + printf(" * Failed *\n\n"); + return -1; + } + + printf(" Passed \n\n"); + return 0; } // ***************************************************************************** int main(void) { + int fail = 0; printf("\n************ CRC Example ***********\n"); - Test_CRC(0); + fail += Test_CRC(0); NVIC_EnableIRQ(CRYPTO_IRQn); - Test_CRC(1); + fail += Test_CRC(1); - return 0; + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/CTB_AES/main.c b/Examples/MAX32690/CTB_AES/main.c index 53152789bc6..829d238324b 100644 --- a/Examples/MAX32690/CTB_AES/main.c +++ b/Examples/MAX32690/CTB_AES/main.c @@ -115,38 +115,46 @@ int AES_Test(mxc_ctb_cipher_t aesKey) !(stat & MXC_F_CTB_CTRL_DONE)); // Compare result of encryption-decryption cycle to original data - if (memcmp(inputData, (void *)decryptedData, MXC_AES_DATA_LENGTH) == 0) { - return E_NO_ERROR; + if (memcmp(inputData, (void *)decryptedData, MXC_AES_DATA_LENGTH) != 0) { + return 1; } - return 1; + + return E_NO_ERROR; } // ***************************************************************************** int main(void) { printf("\n***** AES Example *****\n"); - int fail = 0; + int ret = 0; // Initialize CTB and TRNG MXC_CTB_Init(MXC_CTB_FEATURE_CIPHER | MXC_CTB_FEATURE_DMA); MXC_TRNG_Init(); // Run AES Test with 128-Bit encryption key printf("AES 128-bit Key Test"); - fail = AES_Test(MXC_CTB_CIPHER_AES128); - printf(" --> %s\n", ((fail == E_NO_ERROR) ? "PASS" : "FAIL")); + ret = AES_Test(MXC_CTB_CIPHER_AES128); + fail += ret; + printf(" --> %s\n", ((ret == E_NO_ERROR) ? "PASS" : "FAIL")); // Run AES Test with 192-Bit encryption key printf("AES 192-bit Key Test"); - fail = AES_Test(MXC_CTB_CIPHER_AES192); - printf(" --> %s\n", ((fail == E_NO_ERROR) ? "PASS" : "FAIL")); + ret = AES_Test(MXC_CTB_CIPHER_AES192); + fail += ret; + printf(" --> %s\n", ((ret == E_NO_ERROR) ? "PASS" : "FAIL")); // Run AES Test with 256-Bit encryption key printf("AES 256-bit Key Test"); - fail = AES_Test(MXC_CTB_CIPHER_AES256); - printf(" --> %s\n", ((fail == E_NO_ERROR) ? "PASS" : "FAIL")); + ret = AES_Test(MXC_CTB_CIPHER_AES256); + fail += ret; + printf(" --> %s\n", ((ret == E_NO_ERROR) ? "PASS" : "FAIL")); - printf("\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/DMA/main.c b/Examples/MAX32690/DMA/main.c index 05e1ad820d2..bfd95cf894a 100644 --- a/Examples/MAX32690/DMA/main.c +++ b/Examples/MAX32690/DMA/main.c @@ -53,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -74,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -95,36 +94,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -193,9 +188,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -203,8 +195,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -212,23 +203,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/Flash/main.c b/Examples/MAX32690/Flash/main.c index 9b46f78a145..5e9481cb11f 100644 --- a/Examples/MAX32690/Flash/main.c +++ b/Examples/MAX32690/Flash/main.c @@ -408,11 +408,11 @@ int main(void) MXC_ICC_Enable(MXC_ICC0); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/Hash/main.c b/Examples/MAX32690/Hash/main.c index 9d8dc7f6f7a..2396f8c60cd 100644 --- a/Examples/MAX32690/Hash/main.c +++ b/Examples/MAX32690/Hash/main.c @@ -64,12 +64,14 @@ void Test_Callback(void *req, int result) callback_result = result; } -void Test_Result(int result) +int Test_Result(int result) { if (result) { printf(" * Failed *\n\n"); + return -1; } else { printf(" Passed \n\n"); + return 0; } } @@ -88,7 +90,7 @@ void ascii_to_byte(const char *src, char *dst, int len) } } -void Test_Hash(int asynchronous) +int Test_Hash(int asynchronous) { printf(asynchronous ? "Test Hash Async\n" : "Test Hash Sync\n"); @@ -122,20 +124,29 @@ void Test_Hash(int asynchronous) MXC_CTB_Hash_Compute(&hash_req); } - Test_Result(memcmp(sha256_result, destination, 32)); MXC_CTB_Shutdown(MXC_CTB_FEATURE_HASH); - return; + if (memcmp(sha256_result, destination, 32)) { + printf(" * Failed *\n\n"); + return -1; + } + + printf(" Passed \n\n"); + return 0; } int main(void) { printf("\n\n********** CTB Hash Example **********\n\n"); + int fail = 0; + fail += Test_Hash(0); + fail += Test_Hash(1); - Test_Hash(0); - Test_Hash(1); - - printf("\n*** Done ***\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/I2C/main.c b/Examples/MAX32690/I2C/main.c index fe534e1f08b..247884943e3 100644 --- a/Examples/MAX32690/I2C/main.c +++ b/Examples/MAX32690/I2C/main.c @@ -52,7 +52,6 @@ #include "mxc_delay.h" #include "mxc_errors.h" #include "nvic_table.h" -#include "i2c_regs.h" #include "i2c.h" #include "dma.h" #include "led.h" @@ -70,8 +69,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 255 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -193,10 +190,10 @@ int verifyData() } } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -215,14 +212,14 @@ int main() error = MXC_I2C_Init(I2C_MASTER, 1, 0); if (error != E_NO_ERROR) { printf("Failed master\n"); - return FAILED; + return error; } //Setup the I2CS error = MXC_I2C_Init(I2C_SLAVE, 0, I2C_SLAVE_ADDR); if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } MXC_NVIC_SetVector(I2C2_IRQn, I2C2_IRQHandler); @@ -256,7 +253,7 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } #ifdef MASTERDMA @@ -269,13 +266,13 @@ int main() if ((error = MXC_I2C_MasterTransactionDMA(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (DMA_FLAG == 0) {} #else if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -287,10 +284,11 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); LED_On(LED_GREEN); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); LED_On(LED_RED); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX32690/ICC/README.md b/Examples/MAX32690/ICC/README.md index e2842b45919..e9d4c403665 100644 --- a/Examples/MAX32690/ICC/README.md +++ b/Examples/MAX32690/ICC/README.md @@ -83,6 +83,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX32690/ICC/main.c b/Examples/MAX32690/ICC/main.c index 85439be6e0d..a2b98fd81c6 100644 --- a/Examples/MAX32690/ICC/main.c +++ b/Examples/MAX32690/ICC/main.c @@ -153,11 +153,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/SPI/main.c b/Examples/MAX32690/SPI/main.c index 19e40a14da2..175cfa33be7 100644 --- a/Examples/MAX32690/SPI/main.c +++ b/Examples/MAX32690/SPI/main.c @@ -125,10 +125,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -214,7 +214,7 @@ int main(void) if (memcmp(rx_data, tx_data, sizeof(tx_data)) != 0) { printf("\n-->%2d Bits Transaction Failed\n", i); LED_On(LED_RED); - while (1) {} + return E_INVALID; } else { printf("\n-->%2d Bits Transaction Successful\n", i); } diff --git a/Examples/MAX32690/UART/README.md b/Examples/MAX32690/UART/README.md index 1f35b142021..9b944345f23 100644 --- a/Examples/MAX32690/UART/README.md +++ b/Examples/MAX32690/UART/README.md @@ -40,5 +40,5 @@ Connect UART0 to UART2 (P2.12->P1.9) for this example. -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` diff --git a/Examples/MAX32690/UART/main.c b/Examples/MAX32690/UART/main.c index bd54eb5932f..552c0178403 100644 --- a/Examples/MAX32690/UART/main.c +++ b/Examples/MAX32690/UART/main.c @@ -116,13 +116,13 @@ int main(void) if ((error = MXC_UART_Init(MXC_UART0, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(MXC_UART2, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -153,8 +153,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -162,8 +161,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -188,13 +186,13 @@ int main(void) printf("-->Data verified\n"); } - if (fail == 0) { - LED_On(LED_GREEN); - printf("\n-->EXAMPLE SUCCEEDED\n"); - } else { - LED_On(LED_RED); - printf("\n-->EXAMPLE FAILED\n"); + if (fail != 0) { + LED_On(LED_RED); // indicates FAIL + printf("\n-->Example Failed\n"); + return E_FAIL; } - return 0; + LED_On(LED_GREEN); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX32690/WearLeveling/main.c b/Examples/MAX32690/WearLeveling/main.c index cccf079ec3a..e93427b4ff2 100644 --- a/Examples/MAX32690/WearLeveling/main.c +++ b/Examples/MAX32690/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/AES/main.c b/Examples/MAX78000/AES/main.c index 892957199e9..cb832d546d5 100644 --- a/Examples/MAX78000/AES/main.c +++ b/Examples/MAX78000/AES/main.c @@ -112,14 +112,13 @@ int AES_decrypt(int asynchronous, mxc_aes_keys_t key) MXC_AES_Shutdown(); - if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) == 0) { - printf("\nData Verified"); - return E_NO_ERROR; + if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) != 0) { + printf("\nData Mismatch"); + return 1; } - printf("\nData Mismatch"); - - return 1; + printf("\nData Verified"); + return E_NO_ERROR; } // ***************************************************************************** @@ -143,11 +142,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/CRC/main.c b/Examples/MAX78000/CRC/main.c index 8110cb0b9f9..63aa45c0476 100644 --- a/Examples/MAX78000/CRC/main.c +++ b/Examples/MAX78000/CRC/main.c @@ -66,16 +66,6 @@ void DMA0_IRQHandler(void) wait = 0; } -void Test_Result(int result) -{ - if (result) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } -} - void Test_CRC(int asynchronous) { uint32_t array[101]; @@ -128,8 +118,14 @@ void Test_CRC(int asynchronous) printf("\nCRC Check Result: %x", crc_req.resultCRC); - Test_Result(CHECK != crc_req.resultCRC); MXC_CRC_Shutdown(); + + if (CHECK != crc_req.resultCRC) { + printf(" \n**Test Failed**\n\n"); + fail++; + } else { + printf(" \n**Test Passed**\n\n"); + } } // ***************************************************************************** @@ -146,11 +142,11 @@ int main(void) __enable_irq(); Test_CRC(ASYNC); - if (fail) { + if (fail != 0) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/DMA/main.c b/Examples/MAX78000/DMA/main.c index 78888488b12..2b0f0139dea 100644 --- a/Examples/MAX78000/DMA/main.c +++ b/Examples/MAX78000/DMA/main.c @@ -45,6 +45,7 @@ #include "mxc_device.h" #include "nvic_table.h" #include "dma.h" +#include "dma_regs.h" /***** Definitions *****/ @@ -53,7 +54,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -75,10 +75,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -96,34 +96,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -192,7 +190,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - fail += 1; } else { printf("Data verified.\n"); @@ -200,8 +197,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -209,23 +205,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/ECC/main.c b/Examples/MAX78000/ECC/main.c index 0525f5bfa1f..d69a737dea2 100644 --- a/Examples/MAX78000/ECC/main.c +++ b/Examples/MAX78000/ECC/main.c @@ -175,5 +175,11 @@ int main(void) // Return the ECC back to its POR state (disabled) MXC_MCR->eccen &= ~MXC_F_MCR_ECCEN_RAM0; - return test_fail; + if (test_fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/Flash/main.c b/Examples/MAX78000/Flash/main.c index 65146cad970..8f7e6abbe57 100644 --- a/Examples/MAX78000/Flash/main.c +++ b/Examples/MAX78000/Flash/main.c @@ -282,7 +282,7 @@ int main(void) printf("Flash mass erase is verified.\n"); } else { printf("Failed! Flash mass erase failed.\n"); - return 1; + return E_FAIL; } /* @@ -310,7 +310,7 @@ int main(void) error = MXC_FLC_Write32(testaddr, testval); if (error != E_NO_ERROR) { printf("Failure writing 0x%x to ADDR: 0x%x with error code %i\n", i, testaddr, error); - return 1; + return error; } // Read test data @@ -353,7 +353,7 @@ int main(void) if (error) { printf("Failed to erase page %i (ADDR: 0x%x) with error code %i\n", page, erase_addr, error); - return 1; + return error; } if (check_erased(erase_addr, MXC_FLASH_PAGE_SIZE)) { @@ -362,7 +362,7 @@ int main(void) printf("Erasure of page %i (ADDR: 0x%x) failed... Function call completed, but contents " "were not fully erased.\n", page, erase_addr); - return 1; + return E_FAIL; } // Erase partial pages or wide range of pages and keep the data on the page not inbetween start and end. @@ -378,7 +378,7 @@ int main(void) printf("Successfully verified partial erasure.\n"); } else { printf("Failed to verify partial erasure!\n"); - return 1; + return E_FAIL; } // Flash modifications are complete, so the ICC can be re-enabled. @@ -386,5 +386,5 @@ int main(void) printf("Example succeeded!\n"); - return 0; + return E_NO_ERROR; } diff --git a/Examples/MAX78000/ICC/README.md b/Examples/MAX78000/ICC/README.md index c0c755f5ab7..8dc12a4ade6 100644 --- a/Examples/MAX78000/ICC/README.md +++ b/Examples/MAX78000/ICC/README.md @@ -100,6 +100,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX78000/ICC/main.c b/Examples/MAX78000/ICC/main.c index 28d5ae9c991..a2b98fd81c6 100644 --- a/Examples/MAX78000/ICC/main.c +++ b/Examples/MAX78000/ICC/main.c @@ -153,11 +153,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/SPI/main.c b/Examples/MAX78000/SPI/main.c index 9911bf8acff..d88aa46a3d3 100644 --- a/Examples/MAX78000/SPI/main.c +++ b/Examples/MAX78000/SPI/main.c @@ -154,10 +154,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -179,16 +179,14 @@ int main(void) if (retVal != E_NO_ERROR) { printf("\nSPI SET DATASIZE ERROR: %d\n", retVal); - - while (1) {} + return retVal; } retVal = MXC_SPI_SetWidth(SPI, SPI_WIDTH_STANDARD); if (retVal != E_NO_ERROR) { printf("\nSPI SET WIDTH ERROR: %d\n", retVal); - - while (1) {} + return retVal; } #ifdef MASTERSYNC @@ -243,8 +241,7 @@ int main(void) // Printf needs the Uart turned on since they share the same pins if (memcmp(rx_data, tx_data, sizeof(tx_data)) != 0) { printf("\n-->%2d Bits Transaction Failed\n", i); - - while (1) {} + return E_COMM_ERR; } else { printf("-->%2d Bits Transaction Successful\n", i); } @@ -253,8 +250,7 @@ int main(void) if (retVal != E_NO_ERROR) { printf("\n-->SPI SHUTDOWN ERROR: %d\n", retVal); - - while (1) {} + return retVal; } } diff --git a/Examples/MAX78000/UART/README.md b/Examples/MAX78000/UART/README.md index 99b3e78c70a..2df6b2b382d 100644 --- a/Examples/MAX78000/UART/README.md +++ b/Examples/MAX78000/UART/README.md @@ -44,6 +44,6 @@ Connect the TX pin of UART3 to the RX pin of UART2 for this example. -->Data verified --->EXAMPLE SUCCEEDED +-->Example Succeeded ``` diff --git a/Examples/MAX78000/UART/main.c b/Examples/MAX78000/UART/main.c index 28c531339ec..7d9c595b2e2 100644 --- a/Examples/MAX78000/UART/main.c +++ b/Examples/MAX78000/UART/main.c @@ -126,14 +126,14 @@ int main(void) E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(MXC_UART_GET_UART(WRITING_UART), UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -166,7 +166,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -174,7 +174,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } #ifdef DMA @@ -199,12 +199,12 @@ int main(void) printf("-->Data verified\n"); } - if (fail == 0) { - LED_On(LED1); - printf("\n-->EXAMPLE SUCCEEDED\n"); - } else { - printf("\n-->EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\n-->Example Failed\n"); + return E_FAIL; } - return fail; + LED_On(LED1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78000/WearLeveling/main.c b/Examples/MAX78000/WearLeveling/main.c index ad4ba95b905..886e753472f 100644 --- a/Examples/MAX78000/WearLeveling/main.c +++ b/Examples/MAX78000/WearLeveling/main.c @@ -183,9 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return error_status; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/AES/main.c b/Examples/MAX78002/AES/main.c index c4168428feb..cb832d546d5 100644 --- a/Examples/MAX78002/AES/main.c +++ b/Examples/MAX78002/AES/main.c @@ -112,14 +112,13 @@ int AES_decrypt(int asynchronous, mxc_aes_keys_t key) MXC_AES_Shutdown(); - if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) == 0) { - printf("\nData Verified"); - return E_NO_ERROR; + if (memcmp(inputData, decryptedData, MXC_AES_DATA_LENGTH) != 0) { + printf("\nData Mismatch"); + return 1; } - printf("\nData Mismatch"); - - return 1; + printf("\nData Verified"); + return E_NO_ERROR; } // ***************************************************************************** @@ -143,11 +142,11 @@ int main(void) AES_encrypt(0, MXC_AES_256BITS); fail += AES_decrypt(0, MXC_AES_256BITS); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/CRC/main.c b/Examples/MAX78002/CRC/main.c index 1f85181aeea..8b80a53180e 100644 --- a/Examples/MAX78002/CRC/main.c +++ b/Examples/MAX78002/CRC/main.c @@ -64,16 +64,6 @@ void DMA0_IRQHandler(void) wait = 0; } -void Test_Result(int result) -{ - if (result) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } -} - void Test_CRC(int asynchronous) { uint32_t array[101]; @@ -121,8 +111,14 @@ void Test_CRC(int asynchronous) printf("\nCRC Check Result: %x", crc_req.resultCRC); - Test_Result(CHECK != crc_req.resultCRC); MXC_CRC_Shutdown(); + + if (CHECK != crc_req.resultCRC) { + printf(" \n**Test Failed**\n\n"); + fail++; + } else { + printf(" \n**Test Passed**\n\n"); + } } // ***************************************************************************** @@ -137,11 +133,11 @@ int main(void) NVIC_EnableIRQ(DMA0_IRQn); Test_CRC(1); - if (fail) { + if (fail != 0) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/DMA/main.c b/Examples/MAX78002/DMA/main.c index 17a529f2900..bfd95cf894a 100644 --- a/Examples/MAX78002/DMA/main.c +++ b/Examples/MAX78002/DMA/main.c @@ -53,7 +53,6 @@ /***** Globals *****/ int mychannel = -1; -int fail = 0; volatile int flag = 0; /***** Functions *****/ @@ -74,10 +73,10 @@ void DMA0_IRQHandler() MXC_DMA_Handler(); } -void example1(void) +int example1(void) { printf("Transfer from memory to memory.\n"); - + int fail = 0; int retval; int i = 0; @@ -95,36 +94,32 @@ void example1(void) if (retval != E_NO_ERROR) { printf("Failed MXC_DMA_Init().\n"); - - while (1) {} - } - - flag = 0; - MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); - - while (flag == 0) {} - - //Validate - if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { - printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { - printf("Data verified.\n"); + flag = 0; + MXC_DMA_MemCpy(dstdata, srcdata, MAX_SIZE, memCpyComplete); + + while (flag == 0) {} + + //Validate + if (memcmp(srcdata, dstdata, MAX_SIZE) != 0) { + printf("Data mismatch.\n"); + fail += 1; + } else { + printf("Data verified.\n"); + } } free(srcdata); free(dstdata); - return; + return fail; } -void example2(void) +int example2(void) { printf("\nTransfer with Reload and Callback.\n"); - + int fail = 0; int i, retval; //Init data @@ -193,9 +188,6 @@ void example2(void) // Validate if (memcmp(srcdata, dstdata, MAX_SIZE) != 0 || memcmp(srcdata2, dstdata2, MAX_SIZE) != 0) { printf("Data mismatch.\n"); - - while (1) {} - fail += 1; } else { printf("Data verified.\n"); @@ -203,8 +195,7 @@ void example2(void) if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) { printf("Failed to release channel 0\n"); - - while (1) {} + fail += 1; } free(srcdata); @@ -212,25 +203,24 @@ void example2(void) free(srcdata2); free(dstdata2); - return; + return fail; } // ***************************************************************************** int main(void) { + int fail = 0; printf("***** DMA Example *****\n"); NVIC_EnableIRQ(DMA0_IRQn); - example1(); - example2(); - - printf("\n"); + fail += example1(); + fail += example2(); - if (fail == 0) { - printf("Example Succeeded\n"); - } else { - printf("Example Failed\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/ECC/main.c b/Examples/MAX78002/ECC/main.c index 3b494fd275f..41081b572fa 100644 --- a/Examples/MAX78002/ECC/main.c +++ b/Examples/MAX78002/ECC/main.c @@ -184,5 +184,11 @@ int main(void) test_fail ? "FAIL!" : "Ok"); printf("Example Complete\n"); - return test_fail; + if (test_fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } + + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/Flash/main.c b/Examples/MAX78002/Flash/main.c index 71c5e6a018a..052542c9473 100644 --- a/Examples/MAX78002/Flash/main.c +++ b/Examples/MAX78002/Flash/main.c @@ -361,11 +361,11 @@ int main(void) MXC_ICC_Enable(MXC_ICC0); - if (fail == 0) { - printf("\nExample Succeeded\n"); - } else { + if (fail != 0) { printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/I2C/main.c b/Examples/MAX78002/I2C/main.c index cf2be4b5c2c..e1cbc8a29ce 100644 --- a/Examples/MAX78002/I2C/main.c +++ b/Examples/MAX78002/I2C/main.c @@ -67,8 +67,6 @@ #define I2C_SLAVE_ADDR (0x51) #define I2C_BYTES 100 -typedef enum { FAILED, PASSED } test_t; - /***** Globals *****/ static uint8_t Stxdata[I2C_BYTES]; static uint8_t Srxdata[I2C_BYTES]; @@ -191,10 +189,10 @@ int verifyData() } if (fails > 0) { - return FAILED; - } else { - return PASSED; + return E_FAIL; } + + return E_NO_ERROR; } // ***************************************************************************** @@ -214,7 +212,7 @@ int main() if (error != E_NO_ERROR) { printf("-->Failed master\n"); - return FAILED; + return error; } else { printf("\n-->I2C Master Initialization Complete"); } @@ -224,7 +222,7 @@ int main() if (error != E_NO_ERROR) { printf("Failed slave\n"); - return FAILED; + return error; } else { printf("\n-->I2C Slave Initialization Complete"); } @@ -261,12 +259,12 @@ int main() if ((error = MXC_I2C_SlaveTransactionAsync(I2C_SLAVE, slaveHandler)) != 0) { printf("Error Starting Slave Transaction %d\n", error); - return FAILED; + return error; } if ((error = MXC_I2C_MasterTransaction(&reqMaster)) != 0) { printf("Error writing: %d\n", error); - return FAILED; + return error; } while (I2C_FLAG == 1) {} @@ -279,9 +277,10 @@ int main() if (verifyData()) { printf("\n-->I2C Transaction Successful\n"); - return PASSED; } else { printf("\n-->I2C Transaction Failed\n"); - return FAILED; + return E_FAIL; } + + return E_NO_ERROR; } diff --git a/Examples/MAX78002/ICC/README.md b/Examples/MAX78002/ICC/README.md index 7ecf0a4b108..a464b4ffe79 100644 --- a/Examples/MAX78002/ICC/README.md +++ b/Examples/MAX78002/ICC/README.md @@ -85,6 +85,6 @@ With instruction cache disabled: Time Elapsed: 15.845614 Seconds -EXAMPLE SUCCEEDED +Example Succeeded ``` diff --git a/Examples/MAX78002/ICC/main.c b/Examples/MAX78002/ICC/main.c index 28d5ae9c991..a2b98fd81c6 100644 --- a/Examples/MAX78002/ICC/main.c +++ b/Examples/MAX78002/ICC/main.c @@ -153,11 +153,11 @@ int main(void) fail += 1; } - if (fail == 0) { - printf("\nEXAMPLE SUCCEEDED\n"); - } else { - printf("\nEXAMPLE FAILED\n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; } - return fail; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/SDHC_Raw/main.c b/Examples/MAX78002/SDHC_Raw/main.c index 81419d9e7da..1bdc08bea3b 100644 --- a/Examples/MAX78002/SDHC_Raw/main.c +++ b/Examples/MAX78002/SDHC_Raw/main.c @@ -238,6 +238,7 @@ int multi_block_check(unsigned int width) /******************************************************************************/ int main(void) { + int fail = 0; mxc_sdhc_cfg_t cfg; int result; @@ -267,6 +268,7 @@ int main(void) printf("Card Initialized.\n"); } else { printf("No card response!\n"); + fail += 1; } if (MXC_SDHC_Lib_Get_Card_Type() == CARD_SDHC) { @@ -289,18 +291,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_SINGLE_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -310,18 +315,21 @@ int main(void) if ((result = blocking_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("blocking error %d\n", result); + fail += 1; } else { printf("Passed blocking\n"); } if ((result = erase(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("Erase failed %d\n", result); + fail += 1; } else { printf("Passed erase\n"); } if ((result = async_transactions(MXC_SDHC_LIB_QUAD_DATA)) != 0) { printf("async error %d\n", result); + fail += 1; } else { printf("Passed async\n"); } @@ -329,14 +337,17 @@ int main(void) printf("--> Blocking, 4-bit data bus, multi-block example <--\n"); if (multi_block_check(MXC_SDHC_LIB_QUAD_DATA)) { - result = -1; printf(" FAIL \n"); + fail += 1; } else { - result = 0; printf(" PASS \n"); } - printf(" *** END OF EXAMPLE *** \n"); + if (fail != 0) { + printf("\nExample Failed\n"); + return E_FAIL; + } - return result; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/SPI/main.c b/Examples/MAX78002/SPI/main.c index cfce9187756..c293e90e513 100644 --- a/Examples/MAX78002/SPI/main.c +++ b/Examples/MAX78002/SPI/main.c @@ -142,10 +142,10 @@ int main(void) } // Configure the peripheral - if (MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins) != E_NO_ERROR) { + retVal = MXC_SPI_Init(SPI, 1, 0, 1, 0, SPI_SPEED, spi_pins); + if (retVal != E_NO_ERROR) { printf("\nSPI INITIALIZATION ERROR\n"); - - while (1) {} + return retVal; } memset(rx_data, 0x0, DATA_LEN * sizeof(uint16_t)); @@ -167,16 +167,14 @@ int main(void) if (retVal != E_NO_ERROR) { printf("\nSPI SET DATASIZE ERROR: %d\n", retVal); - - while (1) {} + return retVal; } retVal = MXC_SPI_SetWidth(SPI, SPI_WIDTH_STANDARD); if (retVal != E_NO_ERROR) { printf("\nSPI SET WIDTH ERROR: %d\n", retVal); - - while (1) {} + return retVal; } #ifdef MASTERSYNC @@ -231,8 +229,7 @@ int main(void) // Printf needs the Uart turned on since they share the same pins if (memcmp(rx_data, tx_data, sizeof(tx_data)) != 0) { printf("\n-->%2d Bits Transaction Failed\n", i); - - while (1) {} + return E_COMM_ERR; } else { printf("-->%2d Bits Transaction Successful\n", i); } @@ -241,8 +238,7 @@ int main(void) if (retVal != E_NO_ERROR) { printf("\n-->SPI SHUTDOWN ERROR: %d\n", retVal); - - while (1) {} + return retVal; } } diff --git a/Examples/MAX78002/SPI_MasterSlave/README.md b/Examples/MAX78002/SPI_MasterSlave/README.md index c674fc2ec87..27fd1aafed6 100644 --- a/Examples/MAX78002/SPI_MasterSlave/README.md +++ b/Examples/MAX78002/SPI_MasterSlave/README.md @@ -30,5 +30,5 @@ green LED will illuminate, otherwise the red LED will illuminate. Press PB1 to begin transaction. -EXAMPLE SUCCEEDED! +Example Succeeded ``` \ No newline at end of file diff --git a/Examples/MAX78002/SPI_MasterSlave/main.c b/Examples/MAX78002/SPI_MasterSlave/main.c index 60132b3495a..40be4d73fde 100644 --- a/Examples/MAX78002/SPI_MasterSlave/main.c +++ b/Examples/MAX78002/SPI_MasterSlave/main.c @@ -168,13 +168,12 @@ int main(void) printf("\nMaster failed to receive data.\n"); LED_On(1); return E_COMM_ERR; - } else { - printf("EXAMPLE SUCCEEDED!\n"); - LED_On(0); } MXC_SPI_Shutdown(SPI_MASTER); MXC_SPI_Shutdown(SPI_SLAVE); + LED_On(0); // indicates SUCCESS + printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX78002/UART/main.c b/Examples/MAX78002/UART/main.c index 6b7528ebf68..b18fc4753ef 100644 --- a/Examples/MAX78002/UART/main.c +++ b/Examples/MAX78002/UART/main.c @@ -114,13 +114,13 @@ int main(void) if ((error = MXC_UART_Init(MXC_UART1, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } if ((error = MXC_UART_Init(MXC_UART2, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); - while (1) {} + return error; } printf("-->UART Initialized\n\n"); @@ -153,8 +153,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting async read: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } error = MXC_UART_Transaction(&write_req); @@ -162,8 +161,7 @@ int main(void) if (error != E_NO_ERROR) { printf("-->Error starting sync write: %d\n", error); printf("-->Example Failed\n"); - - while (1) {} + return error; } #ifdef DMA @@ -188,14 +186,12 @@ int main(void) printf("-->Data verified\n"); } - printf("\n"); - - if (fail == 0) { - LED_On(LED1); - printf("-->EXAMPLE SUCCEEDED\n"); - } else { - printf("-->EXAMPLE FAILED\n"); + if (fail != 0) { + printf("\n-->Example Failed\n"); + return E_FAIL; } - while (1) {} + LED_On(LED1); // indicates SUCCESS + printf("\n-->Example Succeeded\n"); + return E_NO_ERROR; } diff --git a/Examples/MAX78002/WearLeveling/main.c b/Examples/MAX78002/WearLeveling/main.c index 11094c43375..e807c5fa2ba 100644 --- a/Examples/MAX78002/WearLeveling/main.c +++ b/Examples/MAX78002/WearLeveling/main.c @@ -183,11 +183,9 @@ int main(void) if (error_status != E_NO_ERROR) { printf("\nExample Failed\n"); - } else { - printf("\nExample Succeeded\n"); + return E_FAIL; } - while (1) {} - - return 0; + printf("\nExample Succeeded\n"); + return E_NO_ERROR; } diff --git a/Libraries/PeriphDrivers/Include/MAX32520/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32520/mxc_errors.h index 526f328c692..cea60ca0d43 100644 --- a/Libraries/PeriphDrivers/Include/MAX32520/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32520/mxc_errors.h @@ -86,6 +86,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32520_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32570/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32570/mxc_errors.h index b49834277a1..613494cb9cc 100644 --- a/Libraries/PeriphDrivers/Include/MAX32570/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32570/mxc_errors.h @@ -86,6 +86,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32572/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32572/mxc_errors.h index 30deb8b71f0..04af0c5a57e 100644 --- a/Libraries/PeriphDrivers/Include/MAX32572/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32572/mxc_errors.h @@ -86,6 +86,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32572_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32650/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32650/mxc_errors.h index 9f7965413ee..9054527026f 100644 --- a/Libraries/PeriphDrivers/Include/MAX32650/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32650/mxc_errors.h @@ -89,6 +89,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32655/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32655/mxc_errors.h index 4d81506cffd..692df06c5f8 100644 --- a/Libraries/PeriphDrivers/Include/MAX32655/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32655/mxc_errors.h @@ -89,6 +89,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32655_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32660/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32660/mxc_errors.h index 6382ed0768c..4abec95d891 100644 --- a/Libraries/PeriphDrivers/Include/MAX32660/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32660/mxc_errors.h @@ -87,6 +87,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32662/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32662/mxc_errors.h index 53b199dbecf..cf5bf251e5e 100644 --- a/Libraries/PeriphDrivers/Include/MAX32662/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32662/mxc_errors.h @@ -86,6 +86,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32665/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32665/mxc_errors.h index b2dd0e0d145..e3efcb1b10e 100644 --- a/Libraries/PeriphDrivers/Include/MAX32665/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32665/mxc_errors.h @@ -89,6 +89,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32670/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32670/mxc_errors.h index 9101bff1f32..941f24debab 100644 --- a/Libraries/PeriphDrivers/Include/MAX32670/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32670/mxc_errors.h @@ -87,6 +87,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32670_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32672/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32672/mxc_errors.h index 4966b85dae4..0a247741d08 100644 --- a/Libraries/PeriphDrivers/Include/MAX32672/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32672/mxc_errors.h @@ -87,6 +87,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32675/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32675/mxc_errors.h index afa528511e0..baa30ba6fbb 100644 --- a/Libraries/PeriphDrivers/Include/MAX32675/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32675/mxc_errors.h @@ -87,6 +87,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32680/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32680/mxc_errors.h index 3ce78df3de4..e0b4ef72a42 100644 --- a/Libraries/PeriphDrivers/Include/MAX32680/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32680/mxc_errors.h @@ -89,6 +89,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX32690/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX32690/mxc_errors.h index 007e0106825..956504b147a 100644 --- a/Libraries/PeriphDrivers/Include/MAX32690/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX32690/mxc_errors.h @@ -89,6 +89,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX78000/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX78000/mxc_errors.h index c8a006ace98..a73cc1ebeae 100644 --- a/Libraries/PeriphDrivers/Include/MAX78000/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX78000/mxc_errors.h @@ -89,6 +89,8 @@ #define E_ABORT -16 /** The requested operation is not supported */ #define E_NOT_SUPPORTED -17 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_MXC_ERRORS_H_ diff --git a/Libraries/PeriphDrivers/Include/MAX78002/mxc_errors.h b/Libraries/PeriphDrivers/Include/MAX78002/mxc_errors.h index 714988bb980..6cfe420403d 100644 --- a/Libraries/PeriphDrivers/Include/MAX78002/mxc_errors.h +++ b/Libraries/PeriphDrivers/Include/MAX78002/mxc_errors.h @@ -93,6 +93,8 @@ #define E_OVERRUN -18 /** Operations resulted in unexpected underrun */ #define E_UNDERRUN -19 +/** The requested operation is failed */ +#define E_FAIL -255 /**@} end of MXC_Error_Codes group */ #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_MXC_ERRORS_H_