/*
 * Copyright (c) 2015-2019, Texas Instruments Incorporated
 * All rights reserved.
 *
 * 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.
 */

/*
 *  ======== bigtime.cpp ========
 */

/* XDC module Headers */
#include <xdc/std.h>
#include <xdc/runtime/System.h>

/* BIOS module Headers */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>

/* Example/Board Header files */
#include <ti/drivers/Board.h>

#include "Driver/TRF7970A.h"

#include <vector>

/* Global clock objects */
Clock cl0(0);  /* idle loop clock */
Clock cl1(1);  /* periodic clock, period = 1 ms */
Clock cl2(2);  /* periodic clock, period = 1 sec */
Clock cl3(3);  /* task clock */
Clock cl4(4);  /* task clock */

Task_Struct task0Struct, task1Struct;
Char task0Stack[TASKSTACKSIZE], task1Stack[TASKSTACKSIZE];
Semaphore_Struct sem0Struct, sem1Struct;
Semaphore_Handle sem0Handle, sem1Handle;
Clock_Struct clk0Struct, clk1Struct;

/*
 *  ======== main ========
 */
int main()
{

    /* Construct BIOS objects */
    Task_Params taskParams;
    Semaphore_Params semParams;
    Clock_Params clkParams;

    /* Construct clock Task thread */
    Task_Params_init(&taskParams);
    taskParams.arg0 = (UArg)&cl3;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)clockTask, &taskParams, NULL);

    taskParams.stack = &task1Stack;
    taskParams.arg0 = (UArg)&cl4;
    Task_construct(&task1Struct, (Task_FuncPtr)clockTask, &taskParams, NULL);

    /* Construct Semaphores for clock thread to pend on, initial count 1 */
    Semaphore_Params_init(&semParams);
    Semaphore_construct(&sem0Struct, 1, &semParams);
    /* Re-use default params */
    Semaphore_construct(&sem1Struct, 1, &semParams);

    /* Obtain instance handles */
    sem0Handle = Semaphore_Handle(&sem0Struct);
    sem1Handle = Semaphore_Handle(&sem1Struct);

    Clock_Params_init(&clkParams);
    clkParams.period = 100;
    clkParams.startFlag = true;
    clkParams.arg = (UArg)&cl1;
    Clock_construct(&clk0Struct, (Clock_FuncPtr)clockPrd,
                    1, &clkParams);

    clkParams.period = 1000;
    clkParams.startFlag = true;
    clkParams.arg = (UArg)&cl2;
    Clock_construct(&clk1Struct, (Clock_FuncPtr)clockPrd,
                    1, &clkParams);

    System_printf("bigTime started.\n");

    const std::vector<char> test(10, 0xFF);

    BIOS_start();    /* does not return */
    return(0);
}

