A simple RTOS for microcontrollers based upon concepts of FreeRTOS

This file is part of SimpleRTOS2

by Isaac Marino Bavaresco

This is file "Test\TestMain-PIC24.c"

/*============================================================================*/
/*
SimpleRTOS - Very simple RTOS for Microcontrollers - PIC24 port
v2.00 (2014-01-21)
isaacbavaresco@yahoo.com.br
*/
/*============================================================================*/
/*
 Copyright (c) 2007-2014, Isaac Marino Bavaresco
 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.
     * Neither the name of the author 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 AUTHOR ''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 AUTHOR 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.
*/
/*============================================================================*/
/*
Set TAB width to 4 characters
*/
/*============================================================================*/
#include <string.h>
#include "../SimpleRTOS/SimpleRTOS.h"
#include "../SimpleRTOS/SerialPIC24.h"

#include "Test.h"

/*============================================================================*/
#define CLOCK       20000000ul
#define BAUD_RATE      19200ul
#define TICK_RATE       1000ul
#define COUNTER_RATE     100ul
/*============================================================================*/
void MainTask( void* );
/*============================================================================*/
unsigned char   Stacks[6][STACK_SIZE];
context_t       Contexts[6]; /* We will have a maximum of 6 simultaneously running tasks. */
/*============================================================================*/
int i, j, k, l;

int aa, bb;

void T1( void *param )
    {
    aa  = (int)param;
    k   = 0;
    while( 1 )
        {
        for( i = 0; i < 3599; i++ )
            k++;

        Yield();
        }
    }

/*============================================================================*/

void T2( void *param )
    {
    bb  = (int)param;
    l   = 0;
    while( 1 )
        {
        for( j = 0; j < 3599; j++ )
            l++;

        Yield();
        }
    }

/*============================================================================*/

int main( void )
    {
    int i;
#if 0
    PORTA   = 0x00;     /* All PORTA pins off. */
    PORTB   = 0x06;
    TRISA   = 0xe0;
    TRISB   = 0x02;
#endif

    for( i = 0; i < sizeof Stacks / sizeof Stacks[0]; i++ )
        memset( Stacks[i], 'A' + i, sizeof Stacks[i] );

    /* Initialize the contexts and the rest of the RTOS. */
    InitRTOS( Contexts, sizeof Contexts / sizeof Contexts[0] );

    /* Create just one task, it will create the others. */

    CreateTask( Stacks[0], sizeof Stacks[0], NULL, GetAddress( MainTask ), 0 );

/*
    CreateTask( Stacks[0], sizeof Stacks[0], (void*)1, GetAddress( T1 ), 0 );
    CreateTask( Stacks[1], sizeof Stacks[1], (void*)2, GetAddress( T2 ), 0 );
*/

    /* From now, the RTOS will take over. */
    StartRTOS( 40000 );

    return 0;
    }
/*============================================================================*/