void main() { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer (good dog) _disable_interrupt(); cron.seconds = 0; cron.minutes = 0; cron.hours = 0; alarm.seconds = 30; alarm.minutes = 2; alarm.hours = 0; initialize_leds(); initialize_lcd(); initialize_buttons(); initialize_timer_b(); initialize_timer_a1(); _enable_interrupt(); halLcdPrintLine(lcd_line, 0, OVERWRITE_TEXT); write_time_base(); write_cron(); while ( 1 ); }
/************************************** Main Function ********************************************************************/ int main(void) { initialize_lcd(); // initialize configure_lcd(); // Configure write_command8_lcd(0x81); // the first line write_char_lcd(0x53); // S write_char_lcd(0x54); // T write_char_lcd(0x41); // A write_char_lcd(0x47); // G write_char_lcd(0x45); // E write_char_lcd(0x00); write_char_lcd(0x4c); // L write_char_lcd(0x49); // I write_char_lcd(0x52); // R write_char_lcd(0x4d); // M write_char_lcd(0x4d); // M write_command8_lcd(0xc3); // the second line write_char_lcd(0x41); // A write_char_lcd(0x4c); // L write_char_lcd(0x49); // I write_char_lcd(0x00); write_char_lcd(0x44); // D write_char_lcd(0x49); // I write_char_lcd(0x4f); // O write_char_lcd(0x55); // U write_char_lcd(0x52); // R write_char_lcd(0x49); // I return 0; }
static void init8(void) { /* Stop watchdog timer */ WDTCTL = WDTPW + WDTHOLD; /* Configure PMM */ SetVCore(3); /* Set global high power request enable */ { PMMCTL0_H = 0xA5; PMMCTL0_L |= PMMHPMRE; PMMCTL0_H = 0x00; } /* Enable 32kHz ACLK */ initialize_aclk(); /* Configure CPU clock for 12MHz */ initialize_cpu_12mhz(); /* Configure buttons for input */ initialize_buttons(); /* Initialize LCD */ initialize_lcd(); /* Write 'boot' to the screen without using display functions */ LCDM2 = 199; /* 'b' */ LCDM3 = 198; /* 'o' */ LCDM4 = 198; /* 'o' */ LCDM6 = 135; /* 't' */ /* configure watchdog interrupt timer, used for polling buttons */ { /* ACLK timer source, 250ms timer mode, resume watchdog */ WDTCTL = WDT_ADLY_250; /* Enable watchdog timer interrupts */ SFRIE1 |= WDTIE; } /* Enable global interrupts */ __enable_interrupt(); /* loop if no button is pressed, enter RFBSL if backlight is pressed */ do { _BIS_SR(LPM3_bits | GIE); if ((P2IN & ALL_BUTTONS) == BTN_BL_PIN) jump_to_rfbsl(); } while ((P2IN & ALL_BUTTONS) == 0); /* Disable them again, they will be re-enabled later on in main() */ __disable_interrupt(); }
/* It is a 0.5 sec loop. work_index second function 0 0 voltage,capacity 1 0.5 power_button 2 1 vbus 3 1.5 power_button 4 2 temperature 5 2.5 power_button 6 3 vbus 7 3.5 power_button 8 4 current 9 4.5 power_button */ static int low_bat_charge() { u16 v = 0, cap = 0; s16 t = 0, c = 0; int result=0; int voltage=0; int current=0; int temperature=0; int vbus=0; int ms=0; int sec=0; int value=0; int capacity=0; int show_low_bat=0; int show_low_bat_ptw=0; int power_button=0; int work_index=0; while(result==0){ work_index=sec%10; //printf("sec=%d work_index=%d\n",sec,work_index); switch(work_index){ case 0: bq27541_voltage(&v); voltage = v; bq27541_capacity(&cap); capacity = cap; if((voltage >= LOW_BATTERY_VOLTAGE_LIMIT) && (capacity >= LOW_BATTERY_CAPACITY_LIMIT)){ result=1; break; } if( show_low_bat==1){ show_low_bat=2; turn_off_lcd(); } if((voltage > LOW_LCD_VOLTAGE_LIMIT) && (show_low_bat==0)){ show_low_bat=1; initialize_lcd(OTTER_LCD_DISPLAY_LOW_BATT_SCREEN); } printf("Battery voltage=%d capacity=%d \n",voltage,capacity); break; case 4: bq27541_temperature(&t); temperature = t; //printf("Battery temperature=%d\n",temperature); if( (temperature>TEMPERATURE_HOT_LIMIT) || (temperature<TEMPERATURE_COLD_LIMIT)){ printf("shutdown due to temperature protect %d\n",temperature); twl6030_shutdown(); } break; case 8: bq27541_current(&c); current = c; printf("Battery current=%d\n",current); /* * Shutdown if there is drain current, and we've displayed the LCD * and shut it down after 10 seconds */ if(current<0 && (show_low_bat<1 || show_low_bat>15)){ printf("shutdown due to there is discharge %d mA\n",current); twl6030_shutdown(); } smb347_i2c_read_u8(&value,SUMMIT_SMB347_INTSTAT_REG_D); if((PC_TIMEOUT_STATUS & value) || (COMPLETE_CHARGE_TIMEOUT_STATUS & value)){ printf("shutdown due to the charge time out\n"); twl6030_shutdown(); } break; case 2: case 6: vbus=twl6030_get_vbus_status(); //printf("vbus=%d\n",vbus); if(vbus==0){ printf("shutdown due to there is no VBUS\n"); twl6030_shutdown(); } break; default : power_button=twl6030_get_power_button_status(); if( (power_button ==0 )&& (voltage > LOW_LCD_VOLTAGE_LIMIT) && (show_low_bat==2)&& (show_low_bat_ptw==0)){ show_low_bat_ptw=1; initialize_lcd(OTTER_LCD_DISPLAY_LOW_BATT_CHARGING_SCREEN); } if((power_button ==1)&& (show_low_bat_ptw==1)){ show_low_bat_ptw=0; turn_off_lcd(); } break; } //delay 0.5s sec++; mdelay(200); } //check vbus again vbus=twl6030_get_vbus_status(); if((vbus==0)){ run_command("setgreenled ff", 0); run_command("setamberled 0", 0); } return result; }
/* * Application entry point. */ int main(void) { Thread *shelltp = NULL; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Shell manager initialization. */ shellInit(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Initialise SDRAM, board.h has already configured GPIO correctly (except that ST example uses 50MHz not 100MHz?) */ SDRAM_Init(); sdram_bulk_erase(); /* * Activates the LCD-related drivers. */ spiStart(&SPID5, &spi_cfg5); ili9341Start(&ILI9341D1, &ili9341_cfg); initialize_lcd(); ltdcStart(<DCD1, <dc_cfg); /* * Activates the DMA2D-related drivers. */ dma2dStart(&DMA2DD1, &dma2d_cfg); dma2d_test(); /* * Creating the blinker threads. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 10, Thread1, NULL); chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO + 10, Thread2, NULL); /* * Normal main() thread activity, in this demo it just performs * a shell respawn upon its termination. */ while (TRUE) { if (!shelltp) { if (SDU1.config->usbp->state == USB_ACTIVE) { /* Spawns a new shell.*/ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); } } else { /* If the previous shell exited.*/ if (chThdTerminated(shelltp)) { /* Recovers memory of the previous shell.*/ chThdRelease(shelltp); shelltp = NULL; } } chThdSleepMilliseconds(500); } }