This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F280039C:随机数生成

Guru**** 2796425 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1338757/tms320f280039c-random-number-generation

器件型号:TMS320F280039C

亲爱的香榭丽舍大街,

我是为我们的客户提出这个问题的。

用户希望从集合生成一个随机数。

例如、拾取整数1到1000之间的一个随机数。

这个示例从 C28x 运行。

F28003x 是否有相应的硬件加速器?

2.如果没有、TI 会怎么做?

3.底线是用户是否可以使用标准 C 库函数  int rand (void)、该函数应在  

#包含 
#包含 
#包含 
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    韦恩、您好!

    F28003x 是否有相应的硬件加速器?

    [/报价]

    2.如果没有、TI 会怎么做?

    [/报价]

    这里有一篇相关文章 介绍了我们如何建议从集合中生成随机数。

    3.底线是用户是否可以使用标准 C 库函数  int rand (void)、该函数应在  

    [/报价]

    用户可以使用标准 C 库。 这里是另一个与此相关的帖子  

    此致!

    马瑞安

    [/quote]
    [/quote][/quote]
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Ryan:

    好的、我尝试了标准 C、它可以正常工作。

    这里列出了对本主题感兴趣的人员的测试代码。

    //#############################################################################
    //
    // FILE:   main.c
    //
    // TITLE:  Universal LED Project
    //
    // Universal LED Project Example
    //
    // This example demonstrates how to blink an LED using the **Universal Project**.
    // In order to migrate the project within syscfg, click the swtich button under 
    // the device view and select your corresponding device to migrate, saving the
    // project will auto-migrate your project settings.
    //
    //#############################################################################
    //
    //
    // $Copyright:
    // Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include "board.h"
    #include "c2000ware_libraries.h"
    
    #include <stdlib.h>
    #include <time.h>
    
    
    // Main
    //
    void main(void)
    {
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pull-ups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // PinMux and Peripheral Initialization
        //
        Board_init();
    
        //
        // C2000Ware Library initialization
        //
        C2000Ware_libraries_init();
    
    
        srand( time(NULL) );
    
        int x = rand();
        int y = rand() % 1000;
        //
        // Enable Global Interrupt (INTM) and real time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop Forever
        //
        for(;;)
        {
            //
            // Turn on LED
            //
            GPIO_writePin(myBoardLED0_GPIO, 0);
    
            //
            // Delay for a bit.
            //
            DEVICE_DELAY_US(500000);
    
            //
            // Turn off LED
            //
            GPIO_writePin(myBoardLED0_GPIO, 1);
    
            //
            // Delay for a bit.
            //
            DEVICE_DELAY_US(500000);
        }
    }
    
    //
    // End of File
    //