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 expbrdInit() { if(isInit) return; owInit(); expbrdScan(); #ifndef FORCE_EXP_DETECT if (expbrdIsPresent(EXPBRD_VID_BITCRAZE, EXPBRD_PID_LEDRING)) #endif { neopixelringInit(); DEBUG_PRINT("neopixelringInit ok\n"); } isInit = true; }
void expbrdInit() { if(isInit) return; owInit(); expbrdScan(); #ifndef FORCE_EXP_DETECT if (expbrdIsPresent(EXPBRD_VID_BITCRAZE, EXPBRD_PID_LEDRING)) #endif { #ifndef BRUSHLESS_PROTO_DECK_MAPPING // Can't have LED-ring and brushless breakout at the same time // as they share TIM3 neopixelringInit(); #endif } isInit = true; }
void esc32SetupOw(const GPIO_TypeDef *port, const uint16_t pin, uint8_t mode) { int16_t paramId; int i = 0; owInit((GPIO_TypeDef *)port, pin); // get ESC32 version owData.buf[0] = OW_VERSION; owTransaction(1, 16); if (owData.status != OW_STATUS_NO_PRESENSE) { AQ_PRINTF("ESC32: OW ver: %s\n", owData.buf); paramId = esc32OwGetParamId("STARTUP_MODE"); if (paramId < 0) { AQ_NOTICE("ESC32: OW cannot read parameters\n"); } else if (esc32OwReadParamById(paramId) != (float)mode) { if (esc32OwSetMode(mode) != mode) AQ_NOTICE("ESC32: OW failed to set run mode\n"); if (esc32OwWriteParam(paramId, (float)mode) != (float)mode) AQ_NOTICE("ESC32: OW failed to write parameter\n"); else i++; } i += esc32ReadFile(0, 0); if (i > 0) { esc32OwConfigWrite(); AQ_PRINTF("ESC32: OW updated %d param(s) in flash\n", i); } } else { AQ_NOTICE("ESC32: cannot detect ESC via OW\n"); } }
static void enumerateDecks(void) { uint8_t nDecks = 0; bool noError = true; owInit(); if (owScan(&nDecks)) { DECK_INFO_DBG_PRINT("Found %d deck memor%s.\n", nDecks, nDecks>1?"ies":"y"); } else { DEBUG_PRINT("Error scanning for deck memories, " "no deck drivers will be initialised\n"); nDecks = 0; } #ifndef IGNORE_OW_DECKS for (int i = 0; i < nDecks; i++) { DECK_INFO_DBG_PRINT("Enumerating deck %i\n", i); if (owRead(i, 0, sizeof(deckInfos[0].raw), (uint8_t *)&deckInfos[i])) { if (infoDecode(&deckInfos[i])) { deckInfos[i].driver = findDriver(&deckInfos[i]); printDeckInfo(&deckInfos[i]); } else { #ifdef DEBUG DEBUG_PRINT("Deck %i has corrupt OW memory. " "Ignoring the deck in DEBUG mode.\n", i); deckInfos[i].driver = &dummyDriver; #else DEBUG_PRINT("Deck %i has corrupt OW memory. " "No driver will be initialized!\n", i); noError = false; #endif } } else { DEBUG_PRINT("Reading deck nr:%d [FAILED]. " "No driver will be initialized!\n", i); noError = false; } } #else DEBUG_PRINT("Ignoring all OW decks because of compile flag.\n"); nDecks = 0; #endif // Add build-forced driver if (strlen(deck_force) > 0) { DEBUG_PRINT("DECK_FORCE=%s found\n", deck_force); //split deck_force into multiple, separated by colons, if available char delim[] = ":"; char temp_deck_force[strlen(deck_force)]; strcpy(temp_deck_force, deck_force); char * token = strtok(temp_deck_force, delim); while (token) { deck_force = token; const DeckDriver *driver = deckFindDriverByName(deck_force); if (!driver) { DEBUG_PRINT("WARNING: compile-time forced driver %s not found\n", deck_force); } else if (driver->init || driver->test) { if (nDecks <= DECK_MAX_COUNT) { nDecks++; deckInfos[nDecks - 1].driver = driver; DEBUG_PRINT("compile-time forced driver %s added\n", deck_force); } else { DEBUG_PRINT("WARNING: No room for compile-time forced driver\n"); } } token = strtok(NULL, delim); } } if (noError) { count = nDecks; } return; }
void scu_init() { uchar FamilySN[MAXDEVICES][8]; int current_temp; int c_frac; int i = 0; int j = 0; int cnt = 0; int NumDevices = 0; SMALLINT didRead = 0; uchar read_buffer[32]; uchar write_buffer[32]; owInit(); uart_init(); uart_write_string("SCU\n"); //use port number for 1-wire uchar portnum = ONEWIRE_PORT; j = 0; // Find the device(s) NumDevices = 0; NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x42, MAXDEVICES-NumDevices); NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x20, MAXDEVICES-NumDevices); NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x43, MAXDEVICES-NumDevices); if (NumDevices) { mprintf("\r\n"); // read the temperature and print serial number and temperature for (i = NumDevices; i; i--) { mprintf("(%d) ", j++); DisplaySerialNum(FamilySN[i-1]); if (FamilySN[i-1][0] == 0x43) { // if(!Write43(portnum, FamilySN[i-1], write_buffer)) // mprintf("write failed!\n"); owLevel(portnum, MODE_NORMAL); if (ReadMem43(portnum, FamilySN[i-1], read_buffer)) { for(cnt = 0; cnt < 32; cnt++) { mprintf("read_buffer[%x]: %x\n",cnt, read_buffer[cnt]); } } continue; } if (FamilySN[i-1][0] == 0x42) { didRead = ReadTemperature42(portnum, FamilySN[i-1],¤t_temp,&c_frac); } if (didRead) { mprintf(" %d",current_temp); if (c_frac) mprintf(".5"); else mprintf(".0"); mprintf(" deegree celsius\r\n"); } else { mprintf(" Convert failed. Device is"); if(!owVerify(portnum, FALSE)) mprintf(" not"); mprintf(" present.\r\n"); #ifdef SOCKIT_OWM_ERR_ENABLE while(owHasErrors()) mprintf(" - Error %d\r\n", owGetErrorNum()); #endif } } } else mprintf("No temperature devices found!\r\n"); }
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; } } }