8 #include <avr/interrupt.h>
11 #include <avr/sleep.h>
69 set_sleep_mode( SLEEP_MODE_IDLE );
92 "push r0\npush r1\npush r2\npush r3\npush r4\npush r5\npush r6\npush r7\npush r8\npush r9\npush r10\npush r11\npush r12\npush r13\npush r14\npush r15\npush r16\npush r17\npush r18\npush r19\npush r20\npush r21\npush r22\npush r23\npush r24\npush r25\npush r26\npush r27\npush r28\npush r29\npush r30\npush r31\n" \
94 "sts pp_stack, r0\n" \
96 "sts pp_stack+1, r0\n" \
103 "lds r0, pp_stack \n" \
104 "out __SP_L__, r0 \n" \
105 "lds r0, pp_stack+1\n" \
106 "out __SP_H__, r0\n" \
108 "pop r31\npop r30\npop r29\npop r28\npop r27\npop r26\npop r25\npop r24\npop r23\npop r22\npop r21\npop r20\npop r19\npop r18\npop r17\npop r16\npop r15\npop r14\npop r13\npop r12\npop r11\npop r10\npop r9\npop r8\npop r7\npop r6\npop r5\npop r4\npop r3\npop r2\npop r1\npop r0\n" \
109 "out __SREG__, r0\n" \
122 while( p->
tid != akttask ) {
128 if( p->
pnext!=NULL ) {
133 akttask=pTaskRdy->
tid;
137 akttask=pTaskRdy->
tid;
140 else akttask=pTaskRdy->
tid;
147 asm volatile (
"ret" );
152 if( pTaskRdy ) akttask=pTaskRdy->
tid;
158 asm volatile(
"ret" );
196 static __inline__
void insertat(
s_tcd *pthis,
s_tcd *newone ) {
198 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
212 static __inline__
void removeat(
s_tcd *pthis ) {
213 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
214 if( pthis==NULL || pthis==&tcd[0] ) {
218 if( pthis->
pnext==NULL ) {
221 pTaskRdy=pthis->
pnext;
243 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
247 insertat( pthis, &tcd[tid] );
250 }
while( ( pthis=pthis->
pnext ) );
259 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
261 if( pthis->
tid==tid ) {
265 }
while( ( pthis=pthis->
pnext ) );
271 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
297 static inline __attribute__((__always_inline__)) uint8_t xch ( uint8_t volatile *p, uint8_t x ) {
300 register uint8_t tmp;
301 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
311 while( xch( &sema[semaid], 1 ) ) {
319 xch( &sema[semaid], 0 ) ;
372 uint8_t
n,
prio, index;
388 pTaskRdy=(
s_tcd * )&tcd[0];
389 pTaskRdy->
pnext=NULL;
392 char hit[VANZTASK+1];
393 memset( hit, 0,
sizeof hit );
394 for( task=1; task<VANZTASK+1; task++ ) {
397 for( n=1; n<VANZTASK+1; n++ ) {
398 if( tcd[n].prio>=prio && !hit[n] ) {
407 for( n=0; n<VANZTASK+1; n++ ) {
408 for( uint16_t f=0; f<
ERTK_STACKSIZE/4; f++ ) memcpy( stack[n]+4*f,
"\xde\xad\xbe\xef", 4 );
416 void ( *task )( uint16_t param0,
void *param1 );
417 void ( *tvoid )( void );
418 void ( *tbeef )(
tsys );
420 memset( &taddr, 0,
sizeof taddr );
426 else taddr.tvoid=eRTK_Idle;
462 register uint16_t val;
463 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
474 __inline__
void __attribute__ ( ( always_inline ) ) eRTK_timertick(
void ) {
489 eRTK_perfcounter[ ( eRTK_iperf++ ) ]=eRTK_perfcount;
490 if( eRTK_perfcount<1 ) {
494 else eRTK_cnt_overload=0;
497 if( eRTK_up ) eRTK_scheduler();
501 #if defined (__AVR_ATmega2560__)
502 ISR( TIMER0_OVF_vect ) {
508 static void timer0_init(
void ) {
509 TCCR0B=(1<<CS01)|(1<<CS00);
516 #if defined (__AVR_ATmega2560__)
518 #elif defined (__AVR_ATxmega128A1U__)
526 uint16_t loop1, loop2;
527 void TMain1( uint16_t param0,
void *param1 ) {
531 uint8_t now=eRTK_GetTimer();
533 for( cnt=0; cnt<1000; cnt++ );
538 write0( ( uint8_t* )
"1234567890", 10 );
543 strcpy( tmp,
"12345678901234567890123456789012345678901234567890" );
553 void TMain2( uint16_t param0,
void *param1 ) {
558 write0( ( uint8_t* )
"abcdefghij", 10 );
563 strcpy( tmp,
"abcdefghijklabcdefghijklabcdefghijklabcdefghijkl" );
volatile uint8_t timer8[2]
uint8_t eRTK_GetTimer8(void)
#define eRTK_MAX_OVERLOAD
uint8_t eRTK_GetTid(void)
push r0 npush r1 npush r2 npush r3 npush r4 npush r5 npush r6 npush r7 npush r8 npush r9 npush r10 npush r11 npush r12 npush r13 npush r14 npush r15 npush r16 npush r17 npush r18 npush r19 npush r20 npush r21 npush r22 npush r23 npush r24 npush r25 npush r26 npush r27 npush r28 npush r29 npush r30 npush r31 n in __SP_L__ n sts r0 n in __SP_H__ n sts r0 n
void eRTK_Sleep_ms(uint16_t ms)
void eRTK_wefet(uint8_t timeout)
volatile uint8_t eRTK_iperf
void eRTK_get_sema(uint8_t semaid)
volatile uint16_t eRTK_ticks
volatile uint16_t eRTK_perfcount
void(* task)(uint16_t param0, void *param1)
void eRTK_WaitUntil(uint8_t then)
volatile uint8_t eRTK_cnt_overload
void eRTK_SetReady(uint8_t tid)
void deadbeef(tsys reason)
uint8_t stack[VANZTASK+1][ERTK_STACKSIZE] __attribute__((aligned(256)))
void eRTK_SetSuspended(uint8_t tid)
void eRTK_timer_init(void)
volatile uint16_t eRTK_perfcounter[256]
const t_eRTK_tcb rom_tcb[VANZTASK]
void * stackptr[VANZTASK+1]
void eRTK_free_sema(uint8_t semaid)
uint8_t adc_sequencer(void)
uint16_t eRTK_GetTimer16(void)
volatile uint16_t timer16