Skip to content
Permalink
35214713cf
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
151 lines (128 sloc) 5.83 KB
/******************************************************************************
* File Name: main.c
*
* Description: This is the source code for the XMC MCU: PRNG for ModusToolbox.
*
* Related Document: See README.md
*
******************************************************************************
*
* Copyright (c) 2015-2021, Infineon Technologies AG
* All rights reserved.
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer,
* must be included in all copies of the Software, in whole or in part, and
* all derivative works of the Software, unless such copies or derivative
* works are solely in the form of machine-executable object code generated by
* a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#include "cybsp.h"
#include "cy_utils.h"
#include "cy_retarget_io.h"
/*******************************************************************************
* Macros
********************************************************************************/
#define SCREEN_HEADER "\r\n__________________________________________________"\
"____________________________\r\n*\tXMC MCU: PRNG: "\
"Pseudo Random Number Generation\r\n*\r\n*\tThis code example "\
"demonstrates generating a random numbers\r\n*\tusing the"\
" Pseudo Random Number generation feature of MCU\r\n*\t"\
"cryptography block\r\n*\r\n*\tUART Terminal Settings\tBaud Rate:"\
"115200 bps 8N1 \r\n*"\
"\r\n__________________________________________________"\
"____________________________\r\n\n"
#define SCREEN_HEADER1 "\r\n================================================="\
"=============================\r\n"
/* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
#define CLEAR_SCREEN "\x1b[2J\x1b[;H"
#define PRNG_DELAY_BW_ITERATION 1000
#define PRNG_DELAY 5
#define LEN_RANDOM_NUM 10
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
* This is the main function for CM0 CPU. It configures the PRNG block to
* generate random number. A new Random number is generated every 5 ms.
* This process repeats every 5 seconds
*
* Parameters:
* void
*
* Return:
* int
*
*******************************************************************************/
int main(void)
{
cy_rslt_t result;
/* Initialize the device and board peripherals */
result = cybsp_init();
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/* Note: retarget_io_init API in PDL CAT3 taking different parameter as
* compared to what we have with PSoC 6 and XMC7000.
* Initialize retarget-io to use the debug UART port */
result = cy_retarget_io_init(CYBSP_DEBUG_UART_HW);
/* retarget-io init failed. Stop program execution */
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
printf(CLEAR_SCREEN);
printf(SCREEN_HEADER);
for (;;)
{
printf("\nPRN Generated in BYTES\r\n");
/* Loop for showing the generated random number in BYTES. */
for (uint32_t i = 1U; i <= LEN_RANDOM_NUM; i++)
{
XMC_Delay(PRNG_DELAY);
/* Checks the validity of the generated random data */
if(XMC_PRNG_CheckValidStatus())
{
/* the function gives the generated random number by returning the content of WORD register. */
printf("%02lu: Result in BYTES is 0x%02X \r\n", i, (uint8_t) XMC_PRNG_GetPseudoRandomNumber());
}
}
/* The function sets the random data block size as byte or word */
XMC_PRNG_SetRandomDataBlockSize(XMC_PRNG_RDBS_WORD);
printf("\nPRN Generated in WORDS\r\n");
/* Loop for showing the generated random number in WORDS. */
for (uint32_t j = 1U; j <= LEN_RANDOM_NUM; j++)
{
XMC_Delay(PRNG_DELAY);
/* Checks the validity of the generated random data */
if(XMC_PRNG_CheckValidStatus())
{
/* the function gives the generated random number by returning the content of WORD register. */
printf("%02lu: Result in WORDS is 0x%02X \r\n", j, (uint16_t) XMC_PRNG_GetPseudoRandomNumber());
}
}
printf(SCREEN_HEADER1);
XMC_Delay(PRNG_DELAY_BW_ITERATION);
}
}
/* [] END OF FILE */