blackbox/main.h

Mon, 14 Nov 2011 21:15:11 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Mon, 14 Nov 2011 21:15:11 +0100
changeset 2
6c59b4293fa9
parent 0
9b7de464f0ea
child 6
2405aff29a51
permissions
-rw-r--r--

finished: rails short circuit check

#ifndef MAIN_H
#define MAIN_H

#include <avr/wdt.h>
#include <stdint.h>

// Hardware config
#define LAP_COUNTER_PORT        PORTB
#define LAP_COUNTER             PB2

#define MODUL_PORT              PORTD
#define MODUL_ST4               PD5
#define MODUL_ST6               PD6

#define I2C_PORT                PORTC
#define I2C_SDA                 PC0
#define I2C_SCL                 PC1

#define LED1_PORT               PORTA
#define LED2_PORT               PORTA
#define LED3_PORT               PORTC
#define LED4_PORT               PORTC
#define LED5_PORT               PORTC
#define LED1                    PA4
#define LED2                    PA5
#define LED3                    PC7
#define LED4                    PC2
#define LED5                    PC3

#define SW_PACECAR_PORT         PORTC
#define SW_START_PORT           PORTB
#define SW_FUEL_PORT            PORTB
#define SW_PACECAR              PC6
#define SW_FUEL                 PB0
#define SW_START                PB1

#define SPEAKER_PORT            PORTD
#define SPEAKER                 PD7

#define RAIL_POWER_PORT         PORTD
#define RAIL_POWER              PD4 // high = rails powered
#define RAIL_DETECT_PORT        PORTA
#define RAIL_DETECT             PA7 // low = short circuit detection

#define CONTROLLER_PORT         PORTB
#define CONTROLLER_MAX          360 // full throttle ADC value
#define CONTROLLER_DIVISOR      (uint8_t)(CONTROLLER_MAX/15)
#define CONTROLLER1_SW          4
#define CONTROLLER2_SW          5
#define CONTROLLER3_SW          6
#define CONTROLLER4_SW          7
#define CONTROLLER1_SPEED       0 // ADC channel #
#define CONTROLLER2_SPEED       1 // ADC channel #
#define CONTROLLER3_SPEED       2 // ADC channel #
#define CONTROLLER4_SPEED       3 // ADC channel #

// TIMING STUFF
/*
#define TIMER0_DIVISOR   8
#define VALUE_50US       0.45e-4
#define TIMER_50US       0xff - (uint8_t)(VALUE_50US * F_CPU/TIMER0_DIVISOR)
*/
/*
#define VALUE_7500NS     0.85e-2
#define TIMER_7500NS     0xffff - (uint16_t)(VALUE_7500NS * F_CPU/TIMER1_DIVISOR)
*/
//#define TIMER_7500NS     (uint16_t)(VALUE_7500NS * F_CPU/TIMER1_DIVISOR)
#define TIMER2_DIVISOR   8
#define VALUE2_50US      0.50e-4
#define TIMER2_50US      (uint8_t)(VALUE2_50US * F_CPU/TIMER2_DIVISOR)

#define TIMER1_DIVISOR   8
#define VALUE1_7500NS     0.75e-2
#define TIMER1_7500NS     (uint16_t)(VALUE1_7500NS * F_CPU/TIMER1_DIVISOR)


#define DDR(x) (*(&x - 1))      // address of data direction register of port x
#define PIN(x) (*(&x - 2))      // address of input register of port x



// MAYBE USELESS STUFF:

#define uchar unsigned char
#define uint unsigned int

// Macro used to write to a single I/O pin
#define writeBit(port,bit,value) { if ((value)>0) (port) |= (1<<bit); else (port) &= ~(1<<bit); } 

// Macro used to read from a single I/O pin
#define readBit(port,bit) (((port) >> (bit)) & 1)

// we have internal AREF...
// #define EXT_AREF 1

#endif

mercurial