// Built with BFTC Rev. 1.0.0, mer 13 agosto 2014 14:39:02

 

/*

    Copyright 2014 Digital Technology Art SRL

    This file is part of Blackfin Toolchain (BFTC) project.

 

    BFTC is free software: you can redistribute it and/or modify

    it under the terms of the GNU General Public License as published by

    the Free Software Foundation, either version 3 of the License, or

    (at your option) any later version.

 

    BFTC is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    GNU General Public License for more details.

 

    You should have received a copy of the GNU General Public License

    along with Nome-Programma.  If not, see <http://www.gnu.org/licenses/>.

*/

 

#include "main.h"

 

#define ST st = Get_TimerCounter(TIMER_0)

#define ET et = Get_TimerCounter(TIMER_0)

 

#define TIMEBASE 0xFFFFFFFF

 

void Sum()

{

    volatile int        i, a = 0;

    for(i = 0; i < 1000000; i++)

        a += 1;

}

 

void Mul()

{

    volatile int        i, a = 1;

    for(i = 0; i < 1000000; i++)

        a *= 3;

}

 

void Div()

{

    volatile int        i, a = 1;

    for(i = 0; i < 1000000; i++)

        a /= 3;

}

 

void Dbl()

{

    volatile int        i;

    volatile double     a = 1;

    for(i = 0; i < 1000000; i++)

        a += 1.0;

}

 

void Trg()

{

    volatile int        i;

    volatile double     a = 0;

    for(i = 0; i < 1000000; i++)

        a += sin(3.14);

}

 

void display(const char * header, unsigned int et, unsigned int st)

{

    double tx;

    if(st > et) tx = TIMEBASE - st + et;

    else tx = et - st;

    printf("%s Test, Elapsed time: %10.3f ms\n", header, tx / 100000.0);

}

 

int main(void)

{

    unsigned int st, et;

    Set_PLL(16, 4); // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz

    Set_Port();

    Set_Uart0(115200);

    Set_TimerCounter(TIMER_0);

    Set_TimerEnable(TIMER_0, true);

    while(1)

    {

        ST; Sum(); ET; display("Sum", et, st);

        ST; Mul(); ET; display("Mul", et, st);

        ST; Div(); ET; display("Div", et, st);

        ST; Dbl(); ET; display("Dbl", et, st);

        ST; Trg(); ET; display("Sin", et, st);

    }

    return 0;

}