void main(void) { rccInit(); timerInit(); configInit(); adcInit(); fetInit(); serialInit(); runInit(); cliInit(); owInit(); runDisarm(REASON_STARTUP); inputMode = ESC_INPUT_PWM; fetSetDutyCycle(0); fetBeep(200, 100); fetBeep(300, 100); fetBeep(400, 100); fetBeep(500, 100); fetBeep(400, 100); fetBeep(300, 100); fetBeep(200, 100); pwmInit(); statusLed = digitalInit(GPIO_STATUS_LED_PORT, GPIO_STATUS_LED_PIN); digitalHi(statusLed); errorLed = digitalInit(GPIO_ERROR_LED_PORT, GPIO_ERROR_LED_PIN); digitalHi(errorLed); #ifdef ESC_DEBUG tp = digitalInit(GPIO_TP_PORT, GPIO_TP_PIN); digitalLo(tp); #endif // self calibrating idle timer loop { volatile unsigned long cycles; volatile unsigned int *DWT_CYCCNT = (int *)0xE0001004; volatile unsigned int *DWT_CONTROL = (int *)0xE0001000; volatile unsigned int *SCB_DEMCR = (int *)0xE000EDFC; *SCB_DEMCR = *SCB_DEMCR | 0x01000000; *DWT_CONTROL = *DWT_CONTROL | 1; // enable the counter minCycles = 0xffff; while (1) { idleCounter++; NOPS_4; cycles = *DWT_CYCCNT; *DWT_CYCCNT = 0; // reset the counter // record shortest number of instructions for loop totalCycles += cycles; if (cycles < minCycles) minCycles = cycles; } } }
void rcc_init () { #ifdef HAVE_RCC rcc_class classes[] = { {"input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", 0}, {"output", RCC_CLASS_KNOWN, NULL, NULL, "Output Encoding", 0}, {NULL, 0, NULL, NULL, NULL, 0} }; rccInit (); rccInitDefaultContext (NULL, 0, 0, classes, 0); rccLoad (NULL, "moc"); rccSetOption (NULL, RCC_OPTION_TRANSLATE, RCC_OPTION_TRANSLATE_SKIP_PARRENT); rccSetOption (NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1); #endif /* HAVE_RCC */ }
/* * main: initialize and start the system */ int main (void) { rccInit(); nvicInit(); stdioInit(); printf("\nWater Tower Monitor\n"); blinkyInit(); multiPointComInit(); ultrasonicRangingInit(); while (1) { int len = readline(); if (len > 0) { runCommand(); } else if (len < 0) { puts("<INTERRUPT>"); } } }
void main(void) { rccInit(); statusLed = digitalInit(GPIO_STATUS_LED_PORT, GPIO_STATUS_LED_PIN); errorLed = digitalInit(GPIO_ERROR_LED_PORT, GPIO_ERROR_LED_PIN); #ifdef ESC_DEBUG tp = digitalInit(GPIO_TP_PORT, GPIO_TP_PIN); digitalLo(tp); #endif timerInit(); configInit(); adcInit(); fetInit(); serialInit(); canInit(); runInit(); cliInit(); owInit(); runDisarm(REASON_STARTUP); inputMode = ESC_INPUT_PWM; fetSetDutyCycle(0); fetBeep(200, 100); fetBeep(300, 100); fetBeep(400, 100); fetBeep(500, 100); fetBeep(400, 100); fetBeep(300, 100); fetBeep(200, 100); pwmInit(); digitalHi(statusLed); digitalHi(errorLed); // self calibrating idle timer loop { uint32_t lastRunCount; uint32_t thisCycles, lastCycles; volatile uint32_t cycles; volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xE0001004; volatile uint32_t *DWT_CONTROL = (uint32_t *)0xE0001000; volatile uint32_t *SCB_DEMCR = (uint32_t *)0xE000EDFC; *SCB_DEMCR = *SCB_DEMCR | 0x01000000; *DWT_CONTROL = *DWT_CONTROL | 1; // enable the counter minCycles = 0xffff; while (1) { idleCounter++; if (runCount != lastRunCount && !(runCount % (RUN_FREQ / 1000))) { if (commandMode == CLI_MODE) cliCheck(); else binaryCheck(); lastRunCount = runCount; } thisCycles = *DWT_CYCCNT; cycles = thisCycles - lastCycles; lastCycles = thisCycles; // record shortest number of instructions for loop totalCycles += cycles; if (cycles < minCycles) minCycles = cycles; } } }