#include
<avr/io.h>
#include
<avr/interrupt.h>
#include
<inttypes.h>
#include
<stdlib.h>
#include
"cocoos.h"
#include
"clock.h"
#include
"drive.h"
static int flag;
static void
system_init(void);
int randNumber (void)
{
uint8_t rndN;
rndN = (uint8_t) rand();
rndN = rndN & 0x0F;
if (rndN > 6)
rndN -= 9;
return rndN;
}
static int task1(void)
{
OS_BEGIN;
for (;;)
{
if (flag == 1)
{
Drive (randNumber ());
OS_WAIT_TICKS( 2000 );
Drive (STOP);
OS_WAIT_TICKS( 1500 );
}
OS_WAIT_TICKS( 50 );
}
OS_END;
return 0;
}
static int task2(void)
{
OS_BEGIN;
for (;;)
{
PORTB |= _BV(PD5);
OS_WAIT_TICKS( 5000 );
PORTB
&= ~_BV(PD5);
OS_WAIT_TICKS( 1000 );
}
OS_END;
return 0;
}
static int task3(void)
{
OS_BEGIN;
for (;;)
{
if (bit_is_clear(PINC, 0))
{
if (flag==0)
{
flag=1;
OS_WAIT_TICKS( 1000 );
}
else
{
flag=0;
OS_WAIT_TICKS( 1000 );
}
}
OS_WAIT_TICKS( 50 );
}
OS_END;
return 0;
}
int main(void)
{
system_init();
os_init();
os_task_create( task1, 1 );
os_task_create( task2, 1 );
os_task_create( task3, 1 );
/* Setup clock with 1 ms tick */
clock_init(1000);
os_start();
return 0;
}
static void
system_init(void)
{
DDRB = 0xff; // все выводы порта B сконфигурировать
как выходы
DDRD = 0xff; // все выводы порта D сконфигурировать
как выходы
DDRC = 0x00; // все выводы порта C сконфигурировать
как входы
PORTC = 1;
flag =0;
}