Skip to content

Commit

Permalink
Standardize Return Values for All Examples (#317)
Browse files Browse the repository at this point in the history
* [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 <sadik.ozer@analog.com>

Signed-off-by: Sadik.Ozer <sadik.ozer@analog.com>
Co-authored-by: ANALOG\AKara <anil.kara@analog.com>
Co-authored-by: Jake-Carter <Jake-Carter@users.noreply.github.com>
Co-authored-by: karaanil <karaanil@users.noreply.github.com>
Co-authored-by: Sadik.Ozer <sadik.ozer@analog.com>
  • Loading branch information
5 people authored Jan 19, 2023
1 parent 811f330 commit 2591919
Show file tree
Hide file tree
Showing 228 changed files with 1,743 additions and 1,865 deletions.
9 changes: 4 additions & 5 deletions Examples/MAX32520/AES/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "mxc_device.h"
#include "board.h"
#include "ctb.h"
#include "ctb_regs.h"

/***** Definitions *****/

Expand Down Expand Up @@ -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;
}
36 changes: 21 additions & 15 deletions Examples/MAX32520/CRC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "mxc_device.h"
#include "board.h"
#include "ctb.h"
#include "ctb_regs.h"

/***** Definitions *****/
#define POLY 0xEDB88320
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
61 changes: 27 additions & 34 deletions Examples/MAX32520/DMA/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <string.h>
#include "mxc_device.h"
#include "dma.h"
#include "dma_regs.h"

/***** Definitions *****/

Expand All @@ -54,7 +53,6 @@

/***** Globals *****/
int mychannel = -1;
int fail = 0;
volatile int flag = 0;
int channels[MAX_CHANNEL];
/***** Functions *****/
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -194,42 +190,39 @@ 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");
}

if (MXC_DMA_ReleaseChannel(mychannel) != E_NO_ERROR) {
printf("Failed to release channel 0\n");

while (1) {}
fail += 1;
}

free(srcdata);
free(dstdata);
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;
}
3 changes: 2 additions & 1 deletion Examples/MAX32520/Flash/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion Examples/MAX32520/ICC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 6 additions & 5 deletions Examples/MAX32520/SFE_Host/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions Examples/MAX32520/SPI/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 5 additions & 9 deletions Examples/MAX32572/AES/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
37 changes: 23 additions & 14 deletions Examples/MAX32572/CRC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit 2591919

Please sign in to comment.