int main(void) { // init GPIO PORTB = 0b11111000; // bits 0-2 are driven externally DDRB = 0b00011000; // data read and data write latches PORTC = 0b11111111; // pullups enabled PORTD = 0b11111111; // pullups enabled // init UART UCSR0B = (1<<TXEN0);//|(1<<RXEN0); UBRR0 = BAUD_MIDI; // init timer TCCR1B |= (1<<WGM12)|(1<<CS10); // timer1 ctc mode, no prescaler TIMSK1 |= (1<<OCIE1A); // enable ctc interrupt OCR1A = F_CPU / RTCFREQ - 1; // ctc value // init emulator MPU401_Init(); // enable interrupts sei(); while(1) // main loop { // do isa i/o if (QueueUsed() && (~PINB & PIN_DSR)) { send_isa_byte(MPU401_ReadData()); // send data if there's any in the buffer } if (PINB & PIN_CRR) { // isa control input latch is full MPU401_WriteCommand(recv_isa_byte()); } if (PINB & PIN_DRR) { // isa data input latch is full MPU401_WriteData(recv_isa_byte()); } // do midi i/o send_midi_byte(); // see if we need to send a byte /* if (UCSR0A & (1<<RXC0)) { // midi uart rx buffer is full process_midi_byte(); } */ } }
int main ( int argc, char **argv ) { extern QueueObject_t *IndexQ; struct sigaction sa; sigset_t sigmsk; uint32 count; GlobalAbort = false; /* Parse the command line options */ MainParseArgs( argc, argv ); mainThreadId = pthread_self(); /* * Setup the sigmasks for this thread (which is the parent to all others). * This will propogate to all children. */ sigfillset( &sigmsk ); sigdelset( &sigmsk, SIGUSR1 ); sigdelset( &sigmsk, SIGUSR2 ); sigdelset( &sigmsk, SIGINT ); sigdelset( &sigmsk, SIGSEGV ); sigdelset( &sigmsk, SIGILL ); sigdelset( &sigmsk, SIGFPE ); pthread_sigmask( SIG_SETMASK, &sigmsk, NULL ); /* Start up the Logging thread */ logging_initialize(FALSE); thread_register( &mainThreadId, "thread_main", NULL ); /* Setup signal handler for SIGUSR1 (toggles Debug) */ sa.sa_sigaction = (sigAction_t)logging_toggle_debug; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGUSR1, &sa, NULL ); /* Setup the exit handler */ atexit( MainDelayExit ); /* Setup signal handler for SIGINT (shut down cleanly) */ sa.sa_sigaction = signal_interrupt; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGINT, &sa, NULL ); /* Setup signal handlers that are to be propogated to all threads */ sa.sa_sigaction = signal_everyone; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGUSR2, &sa, NULL ); /* Setup signal handlers for SEGV, ILL, FPE */ sa.sa_sigaction = signal_death; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGSEGV, &sa, NULL ); sigaction( SIGILL, &sa, NULL ); sigaction( SIGFPE, &sa, NULL ); /* Print the startup log messages */ LogBanner(); /* Setup the CLucene indexer */ clucene_init(1); /* Setup the MySQL connection */ db_setup(); db_check_schema_main(); db_rebuild_clucene(); /* Wait for the clucene thread to finish emptying its queue */ while( (count = QueueUsed( IndexQ )) > 0 ) { LogPrint( LOG_INFO, "%d left", count ); sleep( 1 ); } GlobalAbort = TRUE; return(0); }