Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Example Return Values #317

Merged
merged 18 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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