/*! ******************************************************************************* * Initializate all modules ******************************************************************************/ void init(void) { //! Calibrate the internal RC Oszillator //! \todo test calibrate_rco(); //! set Clock to 4 Mhz CLKPR = (1<<CLKPCE); // prescaler change enable CLKPR = (1<<CLKPS0); // prescaler = 2 (internal RC runs @ 8MHz) //! Disable Analog Comparator (power save) ACSR = (1<<ACD); //! Disable Digital input on PF0-7 (power save) DIDR0 = 0xFF; //! digital I/O port direction DDRB = (1<<PB4)|(1<<PB7); // PB4, PB7 Motor out DDRG = (1<<PG3)|(1<<PG4); // PG3, PG4 Motor out DDRE = (1<<PE3); // PE3 activate lighteye DDRF = (1<<PF3); // PF3 activate tempsensor //! enable pullup on all inputs (keys and m_wheel) //! ATTENTION: no pullup on lighteye input watch circuit diagram PORTB = (1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB5)|(1<<PB6); //! remark for PCMSK0: //! PCINT0 for lighteye (motor monitor) is activated in motor.c using //! mask register PCMSK0: PCMSK0=(1<<PCINT4) and PCMSK0&=~(1<<PCINT4) //! PCMSK1 for keyactions PCMSK1 = (1<<PCINT8)|(1<<PCINT9)|(1<<PCINT10)|(1<<PCINT11)|(1<<PCINT13); //! activate PCINT0 + PCINT1 EIMSK = (1<<PCIE1)|(1<<PCIE0); //! Initialize the USART COM_Init(COM_BAUD_RATE); //1 Initialize the LCD LCD_Init(); //! Initialize the RTC, pass pointer to timer callback function RTC_Init(callback_settemp); //! Initialize the motor MOTOR_Init(); // Init Engine e_Init(); }
static int st_motor_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { switch (cmd) { case MOTOR_Forward : { OSTIMER_OFF; MOTOR_Init(); Motor_Direction( Forward ); MOTOR_ReSetting(motor_speed); // 100us (default clk) = 10Hz break; } case MOTOR_Reverse : { OSTIMER_OFF; MOTOR_Init(); Motor_Direction( Reverse ); MOTOR_ReSetting(motor_speed); // 100us (default clk) = 10Hz break; } case MOTOR_SpeedUp : { if(motor_speed > 200){ motor_speed -= 50; // Speed Up printk("Speed up %d\n", motor_speed); } break; } case MOTOR_SpeedDown : { motor_speed += 50; // Speed Down break; } case MOTOR_STOP : { Motor_Stop(); break; } default: return 0; } return 0; }