void wakeup() { blip(); // serial interrupt detected a char if (wakeup_mode == WAKEON_COM_A) { // while an RTC wakeup has not occured while (wakeup_mode != WAKEON_RTC){ // flash LED blip(); // if serial wake-up is good if (serial_wakeup()){ sleep_mode = FALSE; start_heartbeat(); init_hardware(); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); bit_set(INTCON,PEIE); // Set Peripheral Interrupt Enable bit sprintf(event_str, ",serial wake-up,SD initialized\r\n"); record_event(); if(sd_status>0) msg_card_fail(); return; } else { // if serial_wakeup() == FALSE, then false alarm wakeup_mode = WAKEON_BAD; blip(); blip(); shutdown(); go_to_sleep(); } } } }
void Radar::Draw( SpriteManager &sprites ) { short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129; short int radar_mid_y = RADAR_MIDDLE_Y + 5; int radarSize; const list<Sprite*>& spriteList = sprites.GetSprites(); for( list<Sprite*>::const_iterator iter = spriteList.begin(); iter != spriteList.end(); iter++) { Coordinate blip( -(RADAR_HEIGHT / 2.0), (RADAR_WIDTH / 2.0), (RADAR_HEIGHT / 2.0), -(RADAR_WIDTH / 2.0) ); Sprite *sprite = *iter; if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue; // Calculate the blip coordinate for this sprite Coordinate wpos = sprite->GetWorldPosition(); WorldToBlip( wpos, blip ); if( blip.ViolatesBoundary() == false ) { /* blip is on the radar */ /* Convert to screen coords */ blip.SetX( blip.GetX() + radar_mid_x ); blip.SetY( blip.GetY() + radar_mid_y ); radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0)); Video::DrawCircle( blip, (radarSize>=1) ?radarSize: 1, 1, sprite->GetRadarColor() ); } } }
void main(void) { char c; signed char length; unsigned char msgtype; unsigned char last_reg_recvd; i2c_comm ic; unsigned char msgbuffer[MSGLEN + 1]; unsigned char i; uart_thread_struct uthread_data; // info for uart_lthread timer1_thread_struct t1thread_data; // info for timer1_lthread timer0_thread_struct t0thread_data; // info for timer0_lthread t1thread_data.new_move_msg=0; #ifdef __USE18F2680 OSCCON = 0xFC; // see datasheet // We have enough room below the Max Freq to enable the PLL for this chip OSCTUNEbits.PLLEN = 1; // 4x the clock speed in the previous line #else #ifdef __USE18F45J10 OSCCON = 0x82; // see datasheeet OSCTUNEbits.PLLEN = 0; // Makes the clock exceed the PIC's rated speed if the PLL is on #else #ifdef __USE18F26J50 OSCCON = 0xE0; // see datasheeet OSCTUNEbits.PLLEN = 1; #else #ifdef __USE18F46J50 OSCCON = 0xE0; //see datasheet //Alex: //OSCCON : OSCILLATOR CONTROL REGISTER //OSCCON[7] : IDLEN = ( 1 = Device enters Idle mode on SLEEP instruction ) or ( 0 = Device enters Sleep mode on SLEEP instruction ) //OSCCON[6:4] : IRCF; 111 = 8 MHz, 110 = 4 MHz(2), 101 = 2 MHz, 100 = 1 MHz, 011 = 500 kHz, 010 = 250 kHz, 001 = 125 kHz, 000 = 31 kHz //OSCCON[3] : OSTS = Oscillator Start-up Time-out Status bit = ( 1 = Oscillator Start-up Timer time-out has expired; primary oscillator is running ) or ( 0 = Oscillator Start-up Timer time-out is running; primary oscillator is not ready ) //OSCCON[2] : ( Unimplemented: Read as ?1? ) ?????? //OSCCON[0:1] : SCS = System Clock Select bits OSCTUNEbits.PLLEN = 1; #else Something is messed up. The PIC selected is not supported or the preprocessor directives are wrong. #endif #endif #endif #endif // initialize my uart recv handling code //init_uart_recv(&uc); // initialize the i2c code //Alex: //Essentially just sets error and status flags to intial values ( ic is a struct ) init_i2c(&ic); // init the timer1 lthread init_timer1_lthread(&t1thread_data); // initialize message queues before enabling any interrupts init_queues(); #ifndef __USE18F26J50 // set direction for PORTB to output TRISB = 0x0; LATB = 0x0; #endif // how to set up PORTA for input (for the V4 board with the PIC2680) /* PORTA = 0x0; // clear the port LATA = 0x0; // clear the output latch ADCON1 = 0x0F; // turn off the A2D function on these pins // Only for 40-pin version of this chip CMCON = 0x07; // turn the comparator off TRISA = 0x0F; // set RA3-RA0 to inputs */ // initialize Timers OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_128); #ifdef __USE18F26J50 // MTJ added second argument for OpenTimer1() OpenTimer1(TIMER_INT_ON & T1_SOURCE_FOSC_4 & T1_PS_1_8 & T1_16BIT_RW & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF,0x0); #else #ifdef __USE18F46J50 OpenTimer1(TIMER_INT_ON & T1_SOURCE_FOSC_4 & T1_PS_1_8 & T1_16BIT_RW & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF,0x0); //configure Timer 3 /* TRISAbits.TRISA5 = 1; T3CON = 0x00; T3CONbits.TMR3CS = 0x2; T3CONbits.T3CKPS = 0x0; T3CONbits.RD16 = 0; T3CONbits.T3SYNC = 0; T3CONbits.TMR3ON = 1; RPINR6 = 0x02; */ #else OpenTimer1(TIMER_INT_ON & T1_PS_1_8 & T1_16BIT_RW & T1_SOURCE_INT & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF); #endif #endif // Decide on the priority of the enabled peripheral interrupts // 0 is low, 1 is high // Timer1 interrupt IPR1bits.TMR1IP = 0; // Timer3 interrupt IPR2bits.TMR3IP = 0; // USART RX interrupt IPR1bits.RCIP = 0; // I2C interrupt IPR1bits.SSPIP = 1; // configure the hardware i2c device as a slave (0x9E -> 0x4F) or (0x9A -> 0x4D) #if 1 // Note that the temperature sensor Address bits (A0, A1, A2) are also the // least significant bits of LATB -- take care when changing them // They *are* changed in the timer interrupt handlers if those timers are // enabled. They are just there to make the lights blink and can be // disabled. //i2c_configure_slave(0x9E); i2c_configure_master(I2C_DEFAULT_PIC_ADDRESS); #else // If I want to test the temperature sensor from the ARM, I just make // sure this PIC does not have the same address and configure the // temperature sensor address bits and then just stay in an infinite loop i2c_configure_slave(0x9A); for (;;); #endif // must specifically enable the I2C interrupts PIE1bits.SSPIE = 1; /* // configure the hardware USART device #ifdef __USE18F26J50 Open1USART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 0x19); #else #ifdef __USE18F46J50 Open1USART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 0x19); #else OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 0x19); #endif #endif */ // Alex: Set registers for debug output #ifdef DEBUG_MODE debug_configure(); blip(); blip1(); blip2(); blip3(); blip4(); #endif //uart_send_byte( 0x50 ); //uart_send_byte( 0x54 ); // Peripheral interrupts can have their priority set to high or low // enable high-priority interrupts and low-priority interrupts enable_interrupts(); /* Junk to force an I2C interrupt in the simulator (if you wanted to) PIR1bits.SSPIF = 1; _asm goto 0x08 _endasm; */ //Alex: Configure UART for transmit and recieve uart_configure(); // Initialize snesor data buffer unsigned char sensor_data[MSGLEN]; sensor_data[0] = MSGID_SENSOR_RESPONSE; for(i=1;i<MSGLEN;i++) { sensor_data[i] = 0x00; } // Initialize motor data buffer unsigned char motor_data[MSGLEN]; motor_data[0] = MSGID_MOTOR_RESPONSE; for(i=1;i<MSGLEN;i++) { motor_data[i] = 0x00; } // printf() is available, but is not advisable. It goes to the UART pin // on the PIC and then you must hook something up to that to view it. // It is also slow and is blocking, so it will perturb your code's operation // Here is how it looks: printf("Hello\r\n"); // loop forever // This loop is responsible for "handing off" messages to the subroutines // that should get them. Although the subroutines are not threads, but // they can be equated with the tasks in your task diagram if you // structure them properly. while (1) { // Call a routine that blocks until either on the incoming // messages queues has a message (this may put the processor into // an idle mode) block_on_To_msgqueues(); // At this point, one or both of the queues has a message. It // makes sense to check the high-priority messages first -- in fact, // you may only want to check the low-priority messages when there // is not a high priority message. That is a design decision and // I haven't done it here. length = ToMainHigh_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer); if (length < 0) { // no message, check the error code to see if it is concern if (length != MSGQUEUE_EMPTY) { // This case be handled by your code. } } else { switch (msgtype) { case MSGT_TIMER0: { timer0_lthread(&t0thread_data, msgtype, length, msgbuffer); break; }; case MSGT_I2C_DATA: { switch(msgbuffer[0]) { case MSGID_SENSOR_RESPONSE: { for(i=2;i<MSGLEN-2;i++) { sensor_data[i] = msgbuffer[i]; } send_uart_message( sensor_data ); break; } case MSGID_MOTOR_RESPONSE: { for(i=2;i<MSGLEN-2;i++) { motor_data[i] = msgbuffer[i]; } //motor_data[3] = 3; send_uart_message( motor_data ); break; } default: { break; } } } case MSGT_I2C_DBG: { // Here is where you could handle debugging, if you wanted // keep track of the first byte received for later use (if desired) last_reg_recvd = msgbuffer[0]; break; }; case MSGT_I2C_RQST: { // Generally, this is *NOT* how I recommend you handle an I2C slave request // I recommend that you handle it completely inside the i2c interrupt handler // by reading the data from a queue (i.e., you would not send a message, as is done // now, from the i2c interrupt handler to main to ask for data). // // The last byte received is the "register" that is trying to be read // The response is dependent on the register. break; }; default: { // Your code should handle this error // Sometimes the best course of action is to do nothing break; }; }; } // Check the low priority queue length = ToMainLow_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer); if (length < 0) { // no message, check the error code to see if it is concern if (length != MSGQUEUE_EMPTY) { // Your code should handle this situation } } else { unsigned char uart_response[UART_DATA_LENGTH]; int jjj; for(jjj=0;jjj<UART_DATA_LENGTH;jjj++) { uart_response[jjj] = 0; } switch (msgtype) { case MSGT_TIMER1: { timer1_lthread(&t1thread_data, msgtype, length, msgbuffer); break; }; case MSGT_OVERRUN: {} case MSGT_UART_BAD_CHECKSUM: { uart_response[0] = MSGID_UART_BAD_CHECKSUM; //Set Message ID uart_response[1] = msgbuffer[0]; send_uart_message( uart_response ); break; } case MSGT_UART_BAD_COUNTER: { uart_response[0] = MSGID_UART_BAD_COUNTER; //Set Message ID uart_response[1] = msgbuffer[0]; uart_response[2] = msgbuffer[1]; send_uart_message( uart_response ); break; } case MSGT_UART_BAD_START: { uart_response[0] = MSGID_UART_BAD_START; //Set Message ID uart_response[1] = msgbuffer[0]; send_uart_message( uart_response ); break; } case MSGT_UART_BAD_END: { uart_response[0] = MSGID_UART_BAD_END; //Set Message ID uart_response[1] = msgbuffer[0]; send_uart_message( uart_response ); break; } case MSGT_UART_ACK_DATA: { uart_response[0] = MSGID_UART_ACK; //Set Message ID uart_response[1] = msgbuffer[0]; send_uart_message( uart_response ); break; } case MSGT_UART_DATA: { //uart_lthread(&uthread_data, msgtype, length, msgbuffer); switch( msgbuffer[0] ) { case MSGID_STATUS_REQUEST: { //send_uart_message( sensor_data ); break; } case MSGID_SENSOR_REQUEST: { send_uart_message( sensor_data ); break; } case MSGID_MOTOR_REQUEST: { send_uart_message( motor_data ); motor_data[1] = 0; break; } case MSGID_MOVE: { // Copy msgbuffer over for timer 1 to deal with for(i=0;i<UART_DATA_LENGTH;i++) { t1thread_data.move_msg[i] = msgbuffer[i]; } t1thread_data.new_move_msg = 1; break; } default: { break; } } break; }; default: { // Your code should handle this error // Sometimes the best course of action is to do nothing break; }; }; } } }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // disable WDT initMSP430(); blip(); _delay_cycles(160000); // wait initLCD(); while (1) { _delay_cycles(1600000); blip(); clearScreen(1); set_font(&font_5x7); // FONT_SM setColor(COLOR_16_RED); draw_string(5, 5, "Texas Instruments"); set_font(&font_8x12); // FONT_MD setColor(COLOR_16_WHITE); draw_string(5, 20, "2.2\" 320x240 BoosterPack"); setColor(COLOR_16_BLUE); draw_string(5, 40, "& MSP430F5529 LaunchPad"); setColor(COLOR_16_ORANGE); draw_string(5, 60, "RobG's graphics library"); setColor(COLOR_16_PURPLE); draw_string(5, 80, "Works with:"); setColor(COLOR_16_YELLOW); /* set_font(&font_11x16); // FONT_LG draw_string(5, 100, "F5172 F5510 F5529"); setColor(COLOR_16_GREEN_YELLOW); draw_string(5, 120, "G2553 G2955 & more"); */ set_font(&font_Dyson_8x9); draw_string(5, 120, "DYSON FONT ABC..."); blip(); _delay_cycles(40000000); clearScreen(1); drawTILogo(56, 56, COLOR_16_RED); drawTILogo(55, 56, COLOR_16_RED); drawTILogo(56, 55, COLOR_16_RED); drawTILogo(55, 55, COLOR_16_RED); drawTILogo(50, 50, COLOR_16_WHITE); _delay_cycles(32000000); blip(); shesGotColors(100); _delay_cycles(12000000); blip(); clearScreen(1); drawLogicLines(8); _delay_cycles(16000000); blip(); /*!!sz: drawSpirograph(40, 20, 15); _delay_cycles(16000000); !!*/ setOrientation(++orientation & 0x03); } }
bool Nim::checkInput() { while (!_vm->shouldQuit()) { _vm->_graphics->refreshScreen(); Common::Event event; while (_vm->getEvent(event)) { if (event.type == Common::EVENT_LBUTTONUP) { Common::Point cursorPos = _vm->getMousePos(); int8 newRow = (cursorPos.y / 2 - 38) / 35 - 1; if ((newRow < 0) || (newRow > 2)) { blip(); return false; } int8 newNum = _stones[newRow] - ((cursorPos.x - 64) / 64); if ((newNum < 1) || (newNum > _stones[newRow])) { blip(); return false; } _number = newNum; _row = newRow; return true; } else if (event.type == Common::EVENT_KEYDOWN) { switch (event.kbd.keycode) { case Common::KEYCODE_LEFT: case Common::KEYCODE_KP_PLUS: if (_stones[_row] > _number) _number++; return false; case Common::KEYCODE_RIGHT: case Common::KEYCODE_KP_MINUS: if (_number > 1) _number--; return false; case Common::KEYCODE_1: _number = 1; return false; case Common::KEYCODE_2: if (_stones[_row] >= 2) _number = 2; return false; case Common::KEYCODE_3: if (_stones[_row] >= 3) _number = 3; else _number = _stones[_row]; return false; case Common::KEYCODE_4: if (_stones[_row] >= 4) _number = 4; else _number = _stones[_row]; return false; case Common::KEYCODE_5: if (_stones[_row] == 5) _number = 5; else _number = _stones[_row]; return false; case Common::KEYCODE_HOME: _number = _stones[_row]; return false; case Common::KEYCODE_END: _number = 1; return false; case Common::KEYCODE_UP: _row--; if (_row < 0) _row = 2; findNextUp(); return false; case Common::KEYCODE_DOWN: _row++; if (_row > 2) _row = 0; findNextDown(); return false; case Common::KEYCODE_a: if (_stones[0] != 0) { _row = 0; if (_number > _stones[_row]) _number = _stones[_row]; } return false; case Common::KEYCODE_b: if (_stones[1] != 0) { _row = 1; if (_number > _stones[_row]) _number = _stones[_row]; } return false; case Common::KEYCODE_c: if (_stones[2] != 0) { _row = 2; if (_number > _stones[_row]) _number = _stones[_row]; } return false; case Common::KEYCODE_PAGEUP: _row = 0; findNextDown(); return false; case Common::KEYCODE_PAGEDOWN: _row = 2; findNextUp(); return false; case Common::KEYCODE_RETURN: return true; default: break; } } } } return false; }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }
static void ScanConflicts(char *path, unsigned inx, int argc, char **argv) { DIR *dp; struct dirent *de; struct stat sb; int j; unsigned k; #if SYS_MSDOS || SYS_OS2 || SYS_WIN32 || SYS_OS2_EMX char save_wd[MAXPATHLEN]; #endif /* * When scanning a directory, we first chdir to it, mostly to make * the scan+stat work faster, but also because some systems don't * scan properly otherwise. * * MSDOS and OS/2 are a little more complicated, because each drive * has its own current directory. */ #if SYS_MSDOS || SYS_OS2 || SYS_WIN32 || SYS_OS2_EMX (void) strcpy(save_wd, dot); if (!strcmp(".", path)) { path = dot; } else if (!same_drive(dot, path)) { if (!set_drive(path)) return; getwd(save_wd); } #endif if (v_opt > 2) printf("ScanConflicts \"%s\"\n", path); if (set_directory(path) && (dp = opendir(path)) != NULL) { while ((de = readdir(dp)) != NULL) { register type_t ok = 0; int found = FALSE; char buffer[MAXPATHLEN]; char *the_name; char *the_NAME; if (do_blips) blip('.'); (void) sprintf(buffer, "%.*s", (int) NAMLEN(de), de->d_name); the_name = MakeString(DOS_upper(buffer)); the_NAME = ToCompare(the_name); /* If arguments are given, restrict search to them */ if (argc > optind) { for (j = optind; j < argc; j++) { if (SameName(argv[j], the_name)) { found = TRUE; break; } } if (!found) continue; } /* Verify that the name is a file, and executable */ if (stat(the_name, &sb) < 0) continue; if ((sb.st_mode & S_IFMT) != S_IFREG) continue; #if SYS_UNIX || SYS_OS2 || SYS_OS2_EMX if (access(the_name, acc_mask) < 0) continue; ok = 1; #endif if (FileTypes != 0) { if ((ok = LookupType(the_name)) == 0) continue; } /* Find the name in our array of all names */ found = FALSE; for (k = 0; k < total; k++) { if (SameName(inpath[k].ip_NAME, the_NAME)) { FoundNode(&inpath[k], inx); found = TRUE; break; } } /* If not there, add it */ if (found) { if (the_NAME != the_name) { FreeString(the_NAME); } } else { if (!(total & CHUNK)) { size_t need = (((total * 3) / 2) | CHUNK) + 1; if (inpath != 0) inpath = TypeRealloc(INPATH, inpath, need); else inpath = TypeAlloc(INPATH, need); } j = (int) total++; inpath[j].ip_name = the_name; inpath[j].ip_NAME = the_NAME; inpath[j].node = TypeAlloc(NODE, path_len); FoundNode(&inpath[j], inx); } if (v_opt > 2) { (void) printf("%c %s%c%s\n", found ? '+' : '*', path, PATHNAME_SEP, buffer); } } (void) closedir(dp); } #if SYS_MSDOS || SYS_OS2 || SYS_WIN32 || SYS_OS2_EMX if (strcmp(dot, save_wd)) { chdir(save_wd); } #endif (void) set_directory(dot); }