/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <avr/io.h>


//
// NOPs
//
#define NOP1()  __asm__ __volatile__ ( "nop \n\t" )
#define NOP2()  NOP1 (); NOP1 ()
#define NOP3()  NOP2 (); NOP1 ()
#define NOP4()  NOP3 (); NOP1 ()
#define NOP5()  NOP4 (); NOP1 ()
#define NOP6()  NOP5 (); NOP1 ()
#define NOP7()  NOP6 (); NOP1 ()
#define NOP8()  NOP7 (); NOP1 ()
#define NOP9()  NOP8 (); NOP1 ()
#define NOP10() NOP9 (); NOP1 ()
#define NOP20() NOP10(); NOP10()
#define NOP30() NOP20(); NOP10()
#define NOP40() NOP30(); NOP10()
#define NOP50() NOP40(); NOP10()
#define NOP60() NOP50(); NOP10()
#define NOP70() NOP60(); NOP10()
#define NOP80() NOP70(); NOP10()
#define NOP90() NOP80(); NOP10()


//
// Test application
//
int main()
{
    // Output
    DDRB  |=  _BV(5);
    PORTB |=  _BV(5);
    PORTB &= ~_BV(5);

    // NOPs
    NOP1 (); NOP2 (); NOP3 (); NOP4 (); NOP5 (); NOP6 (); NOP7 (); NOP8 (); NOP9 ();
    NOP10(); NOP20(); NOP30(); NOP40(); NOP50(); NOP60(); NOP70(); NOP80(); NOP90();

    // Input with pull-up
    DDRB  &= ~_BV(5);
    PORTB |=  _BV(5);
    return static_cast<bool>( PINB & _BV(5) );
}
