int main(void) { wdt_disable(); /* Clear WDRF in MCUSR */ MCUSR &= ~(1<<WDRF); /* Write logical one to WDCE and WDE */ /* Keep old prescaler setting to prevent unintentional time-out */ WDTCSR |= (1<<WDCE) | (1<<WDE); /* Turn off WDT */ WDTCSR = 0x00; DDRC |= 0xC0; eeprom_read_block(&state, &state_ee, sizeof(state)); leds_init(); buttons_init(); adc_init(); power_init(); door_init(); aes_handler_init(); bus_handler_init(); bus_init(); cmd_init(); timer0_init(); sei(); while( 1 ){ if( timer0_timebase ){ timer0_timebase--; bus_tick(); door_tick(); power_tick(); cmd_tick(); buttons_tick(); leds_tick(); } bus_process(); door_process(); power_process(); } }
void OnyxWalker_Task(void) { unsigned short now = MY_GetTicks(); if (now < lastTicks) { ++numWraps; LCD_DrawUint(numWraps, WIDTH-7, 3); } if (now - lastVolts > 15000) { lastVolts = now; ++voltBlink; if ((power_cvolts > 1320 && !power_failure) || (voltBlink & 1)) { LCD_DrawFrac(power_cvolts, 2, 0, 3); LCD_DrawChar(' ', 6, 3); LCD_DrawChar('V', 7, 3); PORTC &= ~(1 << 6); } else { LCD_DrawChar(' ', 0, 3); for (unsigned char i = 1; i != 8; ++i) { LCD_DrawChar('-', i, 3); } if (!(voltBlink & 15) && power_cvolts > 0) { PORTC |= (1 << 6); } else { PORTC &= ~(1 << 6); } } } lastTicks = now; LCD_Flush(); if (lastTicks - last_cvolts > 10000) { power_tick(); last_cvolts = lastTicks; } if (USB_DeviceState != DEVICE_STATE_Configured) { return; } /* see if host has requested data */ Endpoint_SelectEndpoint(DATA_RX_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); epic = Endpoint_IsConfigured(); epiir = epic && Endpoint_IsINReady(); epirwa = epiir && Endpoint_IsReadWriteAllowed(); if (epirwa && (in_packet_ptr || (now - last_flush > FLUSH_TICK_INTERVAL))) { last_flush = now; if (in_packet_ptr == 0) { in_packet_ptr = 1; // repeat the last received serial } // send packet in for (unsigned char ch = 0; ch < in_packet_ptr; ++ch) { Endpoint_Write_8(in_packet[ch]); } Endpoint_ClearIN(); in_packet_ptr = 0; } /* see if there's data from the host */ Endpoint_SelectEndpoint(DATA_TX_EPNUM); Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); MY_SetLed(LED_act, false); if (Endpoint_IsConfigured() && Endpoint_IsOUTReceived() && Endpoint_IsReadWriteAllowed()) { uint8_t n = Endpoint_BytesInEndpoint(); if (n > sizeof(out_packet)) { MY_Failure("OUT too big", n, sizeof(out_packet)); } out_packet_ptr = 0; MY_SetLed(LED_act, true); while (n > 0) { epic = Endpoint_Read_8(); out_packet[out_packet_ptr++] = epic; --n; } Endpoint_ClearOUT(); dispatch_out(); } }