int main(void) { setClock(); lcdPortConfig(); lcdInit(); clearLCD(black); while(1) { if(boxes._1) makeOpenBox(220,80,yellow); else makeBox(220,80,yellow); if(boxes._2) makeOpenBox(120,80,green); else makeBox(120,80,green); if(boxes._3) makeOpenBox(20,80,red); else makeBox(20,80,red); } }
void Clock::stopwatch() { mvprintw(4, 80, "Setting stopwatch..."); is24 = true; setClock(); int input = 0; Colon colon1(5, 30), colon2(5, 55); bool oneSec = true; while((input = kbinput()) != 268 && !(hr == 0 && min == 0 && sec == 0)) { if(oneSec) lessSec(1); oneSec = !oneSec; colon1.display(true); colon2.display(true); display(true); } if(hr == 0 && min == 0 && sec == 0) { mvprintw(4, 80, "Time's up!!"); for(int i = 0; i<7; i++) std::cout<<(char)7; } else mvprintw(4, 80, "Exiting timer"); clrtoeol(); }
void UI::initializeGame () { score = 0; level = 0; fallInterval = 1000 - (10 * level); totalLines = 0; lineProgress = 0; timeEvent = true; keyEvent = false; setClock (); updateClock (); engine = new GameEngine (); nextPiece = new GameEngine (2, 2, 7, 6); nextPieceCode = rand()%7; if (nextPieceCode<3) engine->placeNewPiece(nextPieceCode, 4, 19); else engine->placeNewPiece(nextPieceCode, 5, 19); nextPieceCode = rand()%7; nextPiece->placeNewPiece (nextPieceCode, 3, 3); }
void TwoWire::begin(void) { //serial_begin(BAUD2DIV(115200)); //serial_print("\nWire Begin\n"); slave_mode = 0; SIM_SCGC4 |= SIM_SCGC4_I2C0; // TODO: use bitband I2C0_C1 = 0; // On Teensy 3.0 external pullup resistors *MUST* be used // the PORT_PCR_PE bit is ignored when in I2C mode // I2C will not work at all without pullup resistors // It might seem like setting PORT_PCR_PE & PORT_PCR_PS // would enable pullup resistors. However, there seems // to be a bug in chip while I2C is enabled, where setting // those causes the port to be driven strongly high. if (sda_pin_num == 18) { CORE_PIN18_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE; } else if (sda_pin_num == 17) { CORE_PIN17_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE; } if (scl_pin_num == 19) { CORE_PIN19_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE; } else if (scl_pin_num == 16) { CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE; } setClock(100000); I2C0_C2 = I2C_C2_HDRS; I2C0_C1 = I2C_C1_IICEN; //pinMode(3, OUTPUT); //pinMode(4, OUTPUT); }
// Public Methods ////////////////////////////////////////////////////////////// void TwoWire::begin(uint8_t address) { rxBufferIndex = 0; rxBufferLength = 0; txBufferIndex = 0; txBufferLength = 0; slaveBufferIndex = 0; slaveBufferLength = 0; transmitting_master = false; transmitting_slave = false; receiving_slave = false; SIM_HAL_EnableClock(SIM, gate_name); PORT_CLOCK_ENABLE(sda); PORT_CLOCK_ENABLE(scl); PORT_BWR_PCR_ODE(PERIPH_PORT(sda), PINS_PIN(sda), true); //set as open drain PORT_BWR_PCR_ODE(PERIPH_PORT(scl), PINS_PIN(scl), true); //set as open drain PORT_SET_MUX_I2C(sda); PORT_SET_MUX_I2C(scl); I2C_HAL_Init(instance); I2C_HAL_SetAddress7bit(instance, address); I2C_HAL_SetStartStopIntCmd(instance, true); I2C_HAL_SetIntCmd(instance, true); NVIC_EnableIRQ(irqNumber); I2C_HAL_Enable(instance); setClock(100000); }
// // Constructor // // The pins are not activated until begin() is called. // SoftwareWire::SoftwareWire(uint8_t sdaPin, uint8_t sclPin, boolean pullups, boolean detectClockStretch) { _sdaPin = sdaPin; _sclPin = sclPin; _pullups = pullups; _stretch = detectClockStretch; setClock( 100000UL); // set default 100kHz // Set default timeout to 1000 ms. // 1 second is very long, 10ms would be more appropriate. // However, the Arduino libraries use often a default timeout of 1 second. setTimeout( 1000L); // Turn Arduino pin numbers into PORTx, DDRx, and PINx uint8_t port; port = digitalPinToPort(_sdaPin); _sdaBitMask = digitalPinToBitMask(_sdaPin); _sdaPortReg = portOutputRegister(port); _sdaDirReg = portModeRegister(port); _sdaPinReg = portInputRegister(port); // PinReg is the input register, not the Arduino pin. port = digitalPinToPort(_sclPin); _sclBitMask = digitalPinToBitMask(_sclPin); _sclPortReg = portOutputRegister(port); _sclDirReg = portModeRegister(port); _sclPinReg = portInputRegister(port); }
Stage::Stage():_statUpdate(0), _statRender(0), _clipOuter(false), _viewport(0,0,0,0) { spClock clock = new Clock(); setClock(clock); setName("Stage"); //addEventHandler(new EventHandler()); }
void UI::inGameLoop () { initializeGame(); bool quit = false; while (!quit) { if (keyEvent || timeEvent) { string canvas = buildLayout(); system ("cls"); cout << canvas; } updateClock (); timeEvent = false; keyEvent = false; if (timePassed >= fallInterval) { if (engine->translatePiece (0, -1) ); else { int cleared = engine->clearCompleteLines(); if (cleared > 0) { totalLines += cleared; lineProgress += cleared; score += 15 * (level+1) * (calculateExpo(2 , cleared) ); } if (lineProgress >= 10) { lineProgress = lineProgress - 10; level++; fallInterval = 1000 - (100 * level); } if (engine->placeNewPiece(nextPieceCode, 4, 19) ) { nextPiece->clearPiece (); nextPieceCode = rand()%7; nextPiece->placeNewPiece (nextPieceCode, 3, 3); } else quit = true; } timeEvent = true; setClock (); updateClock (); } keyEvent = keyHandler(); Sleep (1); } }
parallelDo() { cls(); Program_Num = 4; CurrentPCBno = 1; freeAll(); initPro(); setClock(); do2(); }
/** \param[in] busNumber The number of the SPI bus to open (0 or 1) \param[in] mode The SPI mode (clock polarity and phase: 0, 1, 2 or 3) \param[in] clockKhz The clock speed to use for the SPI bus \param[in] dataBits The size of an SPI transfer in bits \return HRESULT success or error code. */ HRESULT QuarkSpiControllerClass::begin(ULONG busNumber, ULONG mode, ULONG clockKhz, ULONG dataBits) { HRESULT hr = S_OK; PWCHAR deviceName = nullptr; PVOID baseAddress = nullptr; // If this object does not yet have the SPI bus open: if (m_hController == INVALID_HANDLE_VALUE) { // Get the name of the PCI device that describes the SPI controller. switch (busNumber) { case ADC_SPI_BUS: deviceName = galileoSpi0DeviceName; break; case EXTERNAL_SPI_BUS: deviceName = galileoSpi1DeviceName; break; default: // Only support the two SPI busses hr = DMAP_E_SPI_BUS_REQUESTED_DOES_NOT_EXIST; } if (SUCCEEDED(hr)) { // Open the Dmap device for the SPI controller. hr = GetControllerBaseAddress(deviceName, m_hController, baseAddress); if (SUCCEEDED(hr)) { m_registers = (PSPI_CONTROLLER)baseAddress; } } if (SUCCEEDED(hr)) { // We now "own" the SPI controller, intialize it. m_registers->SSCR0.ALL_BITS = 0; // Disable controller (and also clear other bits) m_registers->SSCR0.DSS = dataBits - 1; // Use the specified data width m_registers->SSCR1.ALL_BITS = 0; // Clear all register bits m_registers->SSSR.ROR = 1; // Clear any RX Overrun Status bit currently set hr = setMode(mode); } if (SUCCEEDED(hr)) { hr = setClock(clockKhz); } } return hr; }
void Clock::initialize() { bool toggle = true; int input = 0; while((input = kbinput()) != 270) { display(toggle); toggle = !toggle; if(toggle) addSec(1); } display(true); setClock(); }
Stage::Stage(bool autoReset) : _statUpdate(0), _statRender(0), _clipOuter(false), _viewport(0, 0, 0, 0) //, _active(true) { spClock clock = new Clock(); setClock(clock); setName("Stage"); //each mobile application should handle focus lost //and free/restore GPU resources if (autoReset) { addEventListener(Stage::DEACTIVATE, CLOSURE(this, &Stage::onDeactivate)); addEventListener(Stage::ACTIVATE, CLOSURE(this, &Stage::onActivate)); } _stage = this; #ifdef OXYGINE_SDL _window = 0; #endif }
//run the clock state machine. call this function frequently from the main loop. void GoldieClock::run(time_t utc) { static clockStates_t CLOCK_STATE; btnSet.read(); btnIncr.read(); switch ( CLOCK_STATE) { case RUN_CLOCK: if ( btnSet.pressedFor(SET_LONGPRESS) ) { CLOCK_STATE = SET_CLOCK; } else if ( btnIncr.wasReleased() ) //toggle the quarter-hour rainbows { if ( _showRainbows = !_showRainbows ) { rainbowCycle(2, 1); //show a rainbow if rainbow mode is on } else { clear(); //else just blank the display for a second show(); delay(1000); } } else { displayClock(utc); } break; case SET_CLOCK: if ( setClock() ) //returns true when setting complete { CLOCK_STATE = RUN_CLOCK; } break; } }
void checkSwing(float div, float del){ setDivide(div); setDelay(del); setDelayMode(); loop(); int cycles = divider.value*2+1; int time = delay.value/2+1; int ticks = delay.value-time; int i; for(i=0; clockIsHigh() == combinedIsHigh() && i<1000; ++i) toggleClock(); BOOST_CHECK_EQUAL(i, cycles); BOOST_CHECK(swinger.running == true); BOOST_CHECK(clockIsHigh()); callTimer(time); setClock(false); for(i=0; !combinedIsHigh() && i<1000; ++i) callTimer(); BOOST_CHECK_EQUAL(i, ticks); for(i=0; combinedIsHigh() && i<1000; ++i) callTimer(); BOOST_CHECK_EQUAL(i, time); }
void TwoWire::begin(void) { //serial_begin(BAUD2DIV(115200)); //serial_print("\nWire Begin\n"); rxBufferIndex = 0; rxBufferLength = 0; txBufferIndex = 0; txBufferLength = 0; transmitting = 0; user_onRequest = NULL; user_onReceive = NULL; slave_mode = 0; hardware.clock_gate_register |= hardware.clock_gate_mask; port().C1 = 0; // On Teensy 3.0 external pullup resistors *MUST* be used // the PORT_PCR_PE bit is ignored when in I2C mode // I2C will not work at all without pullup resistors // It might seem like setting PORT_PCR_PE & PORT_PCR_PS // would enable pullup resistors. However, there seems // to be a bug in chip while I2C is enabled, where setting // those causes the port to be driven strongly high. uint32_t mux; volatile uint32_t *reg; reg = portConfigRegister(hardware.sda_pin[sda_pin_index]); mux = PORT_PCR_MUX(hardware.sda_mux[sda_pin_index]); *reg = mux|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE; reg = portConfigRegister(hardware.scl_pin[scl_pin_index]); mux = PORT_PCR_MUX(hardware.scl_mux[scl_pin_index]); *reg = mux|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE; setClock(100000); port().C2 = I2C_C2_HDRS; port().C1 = I2C_C1_IICEN; //pinMode(3, OUTPUT); //pinMode(4, OUTPUT); }
void setHours(const uint08 hours) { setClock(hours, getMinutes(), getSeconds()); }
void cci_process() { CCI_DISPLAY_ENV = request_msg_env(); MsgEnv *cci_env = request_msg_env(); MsgEnv* a_env = request_msg_env(); // this wont be released as process A will release it later char formatted_msg[1000]; int retVal; while(1) { const int twait = 500000; cci_print("CCI: "); //cci_env = request_msg_env(); get_console_chars(cci_env); cci_env = receive_message(); while(cci_env->msg_type != CONSOLE_INPUT) { release_message_env(cci_env); cci_env = receive_message(); } //Obtained keyboard input char command [MAXCHAR]; int offset = sprintf(command, cci_env->data); // Check atleast 2 characters even if user entered 1. if (offset < 2) offset = 2; // Send a message to process A. This only happens once. If it has already been sent, then prompt user. if (strncasecmp(command, "s", offset) == 0) { if (a_env != NULL) { retVal = send_message(PROCA_ID, a_env); if (retVal != SUCCESS) cci_print("Failed to send message envlope and start A\n"); a_env = NULL; } else { cci_print("A has already started.\n"); } } else if(strncasecmp(command, "ps", offset ) == 0) { retVal = request_process_status(cci_env); if (retVal != SUCCESS) cci_print("Failed to request process status"); sprintf(formatted_msg, cci_env->data); cci_print(formatted_msg); } else if(strncasecmp(command, "cd", offset) == 0) { displayClock(1); } else if(strncasecmp(command, "ct", offset) == 0) { displayClock(0); } // Display Trace Buffers else if(strncasecmp(command, "b", offset) == 0) { retVal = get_trace_buffers(cci_env); if (retVal != SUCCESS) cci_print("Failed to get trace buffers"); sprintf(formatted_msg, "%s", cci_env->data); cci_print(formatted_msg); } else if(strncasecmp(command, "c", 2) == 0) { if(command[4] != ':' || command[7] != ':' || strlen(command) != 10) { sprintf(formatted_msg, "Invalid format for command %s. It should be: c <hh>:<mm>:<ss>\n", "c"); cci_print(formatted_msg); } else { const char * rawTimeString = command+2; char hourString [3] = { '0', '0', '\0'}; char minString [3] = { '0', '0', '\0'}; char secString [3] = { '0', '0', '\0'}; int i, hr, min, sec; for (i=0;i<2;i++) { hourString[i] =rawTimeString[i]; minString[i]=rawTimeString[3+i]; secString[i]=rawTimeString[6+i]; } hour = atoi(hourString); min = atoi(minString); sec = atoi(secString); if (hour>23 || min>59 || sec > 59) { sprintf(formatted_msg, "Invalid input." " Ensure hh not greater than 23, mm not greater than 59, ss not greater than 59.\n"); cci_print(formatted_msg); } else setClock(hour, min, sec); // offset the "c " (c-space) } } else if(strncasecmp(command, "n", 1) == 0) { int priority, pid; // extract priority and pid from the command if (sscanf(command, "%*s %i %i", &priority, &pid)!=2) { sprintf(formatted_msg, "Invalid format for command %s. It should be: n <priority> <process id>\n", "n"); cci_print(formatted_msg); } else { retVal = change_priority(priority, pid); sprintf(formatted_msg, "Priority: %i, Pid: %i\n", priority, pid); cci_print(formatted_msg); if (retVal == ILLEGAL_ARGUMENT) { sprintf(formatted_msg, "Invalid arguments. Ensure that the priority is between [0-3], and the process ID is a valid" "process ID other than the NULL process ID\n"); cci_print(formatted_msg); } else if (retVal != SUCCESS) { cci_print("Priority of specified process could not be changed\n"); } } } else if(strncasecmp(command, "t", offset) == 0) { // no need to release envelopes as terminate will free all memory from MSG_LIST terminate(); } // debugging function. find where all the envelopes are. else if(strncasecmp(command, "en", offset) == 0) { int offset = sprintf(formatted_msg, "\nEnvelope Num\tHeld By\n"); int i; for (i = 0; i < MSG_ENV_COUNT; ++i) { const char* pcb_name; switch(MSG_LIST[i]->dest_pid) { case(-1): pcb_name = "NONE\0"; break; default: pcb_name = PCB_LIST[MSG_LIST[i]->dest_pid]->name; } offset += sprintf(formatted_msg+offset, "%i\t\t%s\n", i+1, pcb_name); } cci_print(formatted_msg); } // debugging, check all queues else if(strncasecmp(command, "cq", offset) == 0) { int offset = 0; offset += sprintf(formatted_msg, "\nREADY QUEUE"); int rdy_queues = proc_pq_get_num_prorities(RDY_PROC_QUEUE); int i; for (i = 0; i < rdy_queues; ++i) { offset+= sprintf(formatted_msg+offset, "\nPriority %i: ", i); pcb* head = RDY_PROC_QUEUE->priority_queues[i]->head; while (head != NULL) { offset += sprintf(formatted_msg+offset, "%s->", head->name); head = head->next; } } offset += sprintf(formatted_msg+offset, "\n\nBLOCKED QUEUE: "); pcb* head = BLOCKED_QUEUE->head; while(head!=NULL) { offset += sprintf(formatted_msg+offset, "%s->", head->name); head = head->next; } offset += sprintf(formatted_msg + offset, "\n\n"); cci_print(formatted_msg); } // One space and enter results in CCI: being printed again else if(strncasecmp(command, " ", offset) == 0) { } // If enter is directly pressed, display a different error else if(strcmp(command, "") == 0) { cci_print("Enter a command!\n"); } // Default error message else { sprintf(formatted_msg, "The command %s is not supported\n", command); cci_print(formatted_msg); } //printf("releasing %p\n", cci_env); //release_message_env(cci_env); } fflush(stdout); printf("=====================WTH! CCI came out of while loop!"); fflush(stdout); terminate(); }
int GPSDriverAshtech::handleMessage(int len) { char *endp; if (len < 7) { return 0; } int uiCalcComma = 0; for (int i = 0 ; i < len; i++) { if (_rx_buffer[i] == ',') { uiCalcComma++; } } char *bufptr = (char *)(_rx_buffer + 6); int ret = 0; if ((memcmp(_rx_buffer + 3, "ZDA,", 3) == 0) && (uiCalcComma == 6)) { /* UTC day, month, and year, and local time zone offset An example of the ZDA message string is: $GPZDA,172809.456,12,07,1996,00,00*45 ZDA message fields Field Meaning 0 Message ID $GPZDA 1 UTC 2 Day, ranging between 01 and 31 3 Month, ranging between 01 and 12 4 Year 5 Local time zone offset from GMT, ranging from 00 through 13 hours 6 Local time zone offset from GMT, ranging from 00 through 59 minutes 7 The checksum data, always begins with * Fields 5 and 6 together yield the total offset. For example, if field 5 is -5 and field 6 is +15, local time is 5 hours and 15 minutes earlier than GMT. */ double ashtech_time = 0.0; int day = 0, month = 0, year = 0, local_time_off_hour __attribute__((unused)) = 0, local_time_off_min __attribute__((unused)) = 0; if (bufptr && *(++bufptr) != ',') { ashtech_time = strtod(bufptr, &endp); bufptr = endp; } if (bufptr && *(++bufptr) != ',') { day = strtol(bufptr, &endp, 10); bufptr = endp; } if (bufptr && *(++bufptr) != ',') { month = strtol(bufptr, &endp, 10); bufptr = endp; } if (bufptr && *(++bufptr) != ',') { year = strtol(bufptr, &endp, 10); bufptr = endp; } if (bufptr && *(++bufptr) != ',') { local_time_off_hour = strtol(bufptr, &endp, 10); bufptr = endp; } if (bufptr && *(++bufptr) != ',') { local_time_off_min = strtol(bufptr, &endp, 10); bufptr = endp; } int ashtech_hour = static_cast<int>(ashtech_time / 10000); int ashtech_minute = static_cast<int>((ashtech_time - ashtech_hour * 10000) / 100); double ashtech_sec = static_cast<float>(ashtech_time - ashtech_hour * 10000 - ashtech_minute * 100); /* * convert to unix timestamp */ struct tm timeinfo; timeinfo.tm_year = year - 1900; timeinfo.tm_mon = month - 1; timeinfo.tm_mday = day; timeinfo.tm_hour = ashtech_hour; timeinfo.tm_min = ashtech_minute; timeinfo.tm_sec = int(ashtech_sec); #ifndef NO_MKTIME time_t epoch = mktime(&timeinfo); if (epoch > GPS_EPOCH_SECS) { uint64_t usecs = static_cast<uint64_t>((ashtech_sec - static_cast<uint64_t>(ashtech_sec))) * 1000000; // FMUv2+ boards have a hardware RTC, but GPS helps us to configure it // and control its drift. Since we rely on the HRT for our monotonic // clock, updating it from time to time is safe. timespec ts; ts.tv_sec = epoch; ts.tv_nsec = usecs * 1000; setClock(ts); _gps_position->time_utc_usec = static_cast<uint64_t>(epoch) * 1000000ULL; _gps_position->time_utc_usec += usecs; } else { _gps_position->time_utc_usec = 0; } #else _gps_position->time_utc_usec = 0; #endif _last_timestamp_time = gps_absolute_time(); }
void VideoStateInfo::setClockSpeed(Clock *c, double speed) { setClock(c, getClock(c), c->serial); c->speed = speed; }
void VideoStateInfo::initClock(Clock *c, int *queue_serial) { c->speed = 1.0; c->paused = 0; c->queue_serial = queue_serial; setClock(c, NAN, -1); }
/* 测试大对象 ,loop小于 500000*/ VOID testBig(WORD page, WORD field, DWORD loop) { _DB_RET ret; _db_tuple_no tupleNo; DWORD mem, time; _db_t_object_handle objectHandle; initDb(page); ret = initTable(field); if (_DB_SUCCESS != ret) { printf("%d, init initTable error ret= %x\n", __LINE__, ret); dropDb(); return; } /* test new */ setClock(); setMem(); for (tupleNo = 0; tupleNo < loop; ++tupleNo) { ret = _db_put_tuple(tranHandle, dbHandle, tableHandle, (BYTE*) record); if (ret != _DB_SUCCESS) { printf("_db_put_tuple error ret= %x\n", ret); break; } } time = getUsedTimes(); mem = getUsedMem(); writeLog("testNew: ", page, field, tupleNo, mem >> 10, time); /*delete given no object */ setClock(); for (tupleNo = 0; tupleNo < loop; ++tupleNo) { ret = _db_delete_tuple_by_tupleno(tranHandle, dbHandle, tableHandle, tupleNo); if (ret != _DB_SUCCESS) { printf("_db_delete_tuple_by_tupleno= %x\n", ret); break; } } time = getUsedTimes(); mem = getUsedMem(); writeLog("testDelGiven: ", page, field, tupleNo, mem >> 10, time); /*test new given */ setClock(); setMem(); for (tupleNo = 0; tupleNo < loop; ++tupleNo) { ret = _db_put_tuple_by_tupleno(tranHandle, dbHandle, tableHandle, (BYTE*) record, tupleNo); if (ret != _DB_SUCCESS) { printf("_db_put_tuple_by_tupleno error ret= %x\n", ret); break; } } time = getUsedTimes(); mem = getUsedMem(); writeLog("testNewGiven: ", page, field, tupleNo, mem >> 10, time); /* get given no object */ setClock(); for (tupleNo = 0; tupleNo < loop; ++tupleNo) { ret = _db_get_tuplehandle_by_tupleno(dbHandle, tableHandle, tupleNo, &objectHandle); if (ret != _DB_FOUND) { printf("_db_get_tuplehandle_by_tupleno error ret= %x, objectNo=%d\n", ret, tupleNo); break; } } time = getUsedTimes(); writeLog("testGetGiven: ", page, field, tupleNo, mem >> 10, time); dropDb(); }
void VideoStateInfo::updateVideoPts(double pts, int64_t pos, int serial) { /* update current video pts */ setClock(vidClk, pts, serial); syncClock2Slave(extClk, vidClk); }
void VideoStateInfo::syncClock2Slave(Clock *c, Clock *slave) { double clock = getClock(c); double slave_clock = getClock(slave); if (!isnan(slave_clock) && (isnan(clock) || fabs(clock - slave_clock) > AV_NOSYNC_THRESHOLD)) setClock(c, slave_clock, slave->serial); }
int main(void) { int spiFd; int fdPot; uint32_t updateUserTick = 0; ftmCfg_t ftmPWM = { .mode = FTM_MODE_PWM, .mod = 0, .initCount = 0, .channels = { FTM_CH_0, FTM_CH_1, FTM_CH_2, FTM_CH_3, FTM_CH_4, FTM_CH_5, FTM_CH_NONE}, .pwmFreq = PWM_FREQ, .pwmCfgBits = FTM_PWM_CFG_COMBINED_MODE_CHS_0_1 | FTM_PWM_CFG_COMBINED_MODE_CHS_2_3 | FTM_PWM_CFG_COMBINED_MODE_CHS_4_5 | FTM_PWM_CFG_COMPLEMENTARY_CH_0_1 | FTM_PWM_CFG_COMPLEMENTARY_CH_2_3 | FTM_PWM_CFG_COMPLEMENTARY_CH_4_5 | FTM_PWM_CFG_OUTPUT_MASK | FTM_PWM_CFG_CENTER_ALINGNED , .triggerBits = FTM_TRIGGER_INIT, /* TODO setup PDB off this trigger * to run ADC captures of current. */ .deadTime = 1, /* 1/10 uSec */ .dutyScaled = { 0.6 * UNITY, 0.6 * UNITY , 0.6 * UNITY , 0.6 * UNITY, 0.6 * UNITY , 0.6 * UNITY}, .activeLow = { TRUE, FALSE, TRUE, FALSE, TRUE, FALSE }, }; ftmCfg_t ftmCh2QD = { .mode = FTM_MODE_QUADRATURE_DECODE, .mod = QUAD_CALL_BACK_COUNT, .initCount = 0, .quadCfg = FTM_QUAD_CONFIG_FILTER_MED, }; setClock(); uart_install(); spi_install(); adc_install(); /* * Register the standard I/O streams with a particular deivce driver. */ int fd1 = fdevopen(stdout, "uart3", 0, 0); ioctl(fd1, IO_IOCTL_UART_BAUD_SET, 115200); assert(fd1 != -1); gpioConfig(FET_DRIVER_ENABLE_PORT, FET_DRIVER_ENABLE_PIN, GPIO_OUTPUT | GPIO_DSE | GPIO_PULLUP); gpioClear(FET_DRIVER_ENABLE_PORT, FET_DRIVER_ENABLE_PIN); gpioConfig(FET_DRIVER_RESET_PORT, FET_DRIVER_RESET_PIN, GPIO_OUTPUT | GPIO_DSE | GPIO_PULLUP); gpioClear(FET_DRIVER_RESET_PORT, FET_DRIVER_RESET_PIN); gpioConfig(ENCODER_INDEX_PORT, ENCODER_INDEX_PIN, GPIO_INPUT | GPIO_PULLUP); #if 0 gpioConfig(HALL_A_PORT, HALL_A_PIN, GPIO_INPUT | GPIO_PULLDOWN); gpioConfig(HALL_B_PORT, HALL_B_PIN, GPIO_INPUT | GPIO_PULLDOWN); gpioConfig(HALL_C_PORT, HALL_C_PIN, GPIO_INPUT | GPIO_PULLDOWN); #endif gpioConfig(IRQ_PORT, IRQ_PIN, GPIO_INPUT | GPIO_PULLDOWN); /* Install irq handler for driver and over current interrupts (PTA27) * and phase B,C Hall sensors */ PORT_PCR(IRQ_PORT, IRQ_PIN) |= PORT_IRQC_INT_RISING_EDGE; PORT_PCR(ENCODER_INDEX_PORT, ENCODER_INDEX_PIN) |= PORT_IRQC_INT_RISING_EDGE; #if 0 PORT_PCR(HALL_A_PORT, HALL_A_PIN) |= PORT_IRQC_INT_EITHER_EDGE; PORT_PCR(HALL_B_PORT, HALL_B_PIN) |= PORT_IRQC_INT_EITHER_EDGE; PORT_PCR(HALL_C_PORT, HALL_C_PIN) |= PORT_IRQC_INT_EITHER_EDGE; #endif hwInstallISRHandler(ISR_GPIO_A, portAIsr); hwInstallISRHandler(ISR_GPIO_B, indexIsr); #if 0 hwInstallISRHandler(ISR_GPIO_D, portAIsr); #endif /* LEDs */ gpioConfig(N_LED_ORANGE_PORT, N_LED_ORANGE_PIN, GPIO_OUTPUT | GPIO_LOW); gpioConfig(N_LED_YELLOW_PORT, N_LED_YELLOW_PIN, GPIO_OUTPUT | GPIO_LOW); gpioConfig(N_LED_GREEN_PORT, N_LED_GREEN_PIN, GPIO_OUTPUT | GPIO_LOW); gpioConfig(N_LED_BLUE_PORT, N_LED_BLUE_PIN, GPIO_OUTPUT | GPIO_LOW); /* setup pit */ pitInit(PIT_0, pit0ISR, 5000); hwSetISRPriority(IRQ_PIT0, 0x0F); /* setup ftm */ ftmInit(FTM_0, callBackFtm0, &ftmPWM); #if 0 ftmInit(FTM_2, callBackFtm2, &ftmCh2QD); #else ftmInit(FTM_2, 0, &ftmCh2QD); #endif hwSetISRPriority(IRQ_FTM0, 0x0F); hwSetISRPriority(IRQ_FTM2, 0x0F); ftmWrite(FTM_2, 1000, 0); /* Install spi into the device table before using it */ spiFd = open("spi2", 0, 0); assert(spiFd != -1); ioctl(spiFd, IO_IOCTL_SPI_SET_PORT_PCRS, 0); ioctl(spiFd, IO_IOCTL_SPI_SET_BAUD, SPI_BAUDRATE_CLKDIV_32); ioctl(spiFd, IO_IOCTL_SPI_SET_SCLK_MODE, SPI_SCLK_MODE_2); ioctl(spiFd, IO_IOCTL_SPI_SET_FMSZ, 8); ioctl(spiFd, IO_IOCTL_SPI_SET_OPTS, SPI_OPTS_MASTER); ioctl(spiFd, IO_IOCTL_SPI_SET_CS, SPI_CS_0); ioctl(spiFd, IO_IOCTL_SPI_SET_CS_INACT_STATE, SPI_CS_0_INACT_HIGH); ioctl(spiFd, IO_IOCTL_SPI_SET_METHOD, SPI_METHOD_POLLED); initFetPreDriver(FTM_0, spiFd); /* ADC Setup */ fdPot = open("adc0", 0, 0); if (fdPot==-1) { assert(0); } ioctl(fdPot, IO_IOCTL_ADC_CALIBRATE, TRUE); ioctl(fdPot, IO_IOCTL_ADC_SAMPLE_SIZE_SET, 1); ioctl(fdPot, IO_IOCTL_ADC_CALL_BACK_SET, (int)potCallBackHandler); ioctl(fdPot, IO_IOCTL_ADC_VREF_SELECT, IO_IOCTL_ADC_VREF_FLAGS_DEFAULT); ioctl(fdPot, IO_IOCTL_ADC_TRIGGER_SELECT, IO_IOCTL_ADC_TRIGGER_SELECT_SW); ioctl(fdPot, IO_IOCTL_ADC_CONVERSION_CONTINUOUS, TRUE); ioctl(fdPot, IO_IOCTL_ADC_CONVERSION_TIME_SELECT, IO_IOCTL_ADC_CONVERSION_TIME_FLAGS_ADLSTS_ADCK_2); ioctl(fdPot, IO_IOCTL_ADC_AVERAGE_SELECT, IO_IOCTL_ADC_FLAGS_AVGS_4); ioctl(fdPot, IO_IOCTL_ADC_RESOLUTION_SELECT, IO_IOCTL_ADC_RES_FLAGS_12_BIT); ioctl(fdPot, IO_IOCTL_ADC_CLOCK_SELECT, IO_IOCTL_ADC_FLAGS_ADICLK_BUS); ioctl(fdPot, IO_IOCTL_ADC_DIFFERENTIAL_SET, (IO_IOCTL_ADC_CHANNEL_FLAGS_REGISTER_A | IO_IOCTL_ADC_DIFF_FLAGS_SINGLE_ENDED)); ioctl(fdPot, IO_IOCTL_ADC_CHANNEL_SELECT, (IO_IOCTL_ADC_CHANNEL_FLAGS_REGISTER_A | (IO_IOCTL_ADC0_CHANNEL_FLAGS_ADC0_DP0 // | (IO_IOCTL_ADC1_CHANNEL_FLAGS_ADC1_DM1 & IO_IOCTL_ADC_CHANNEL_FLAGS_CH_MASK))); hwSetISRPriority(IRQ_ADC0, 0x0A); while(1){ switch (motorState) { default: /* Do nothing */ break; case MOTOR_STATE_OFF: /* Turn off motor outputs */ ftmSetOutputMask(FTM_0, MASK_ALL_OUTPUTS, TRUE); taskDelay(1000); motorState = MOTOR_STATE_ALIGN; break; case MOTOR_STATE_ALIGN: { svm_t svmAlign; svmAlign = resolveSVM(MOTOR_ALIGN_DRIVE, 0); ftmPwmWrite(FTM_0, FTM_CH_1, svmAlign.pwmADuty, FALSE); ftmPwmWrite(FTM_0, FTM_CH_3, svmAlign.pwmBDuty, FALSE); ftmPwmWrite(FTM_0, FTM_CH_5, svmAlign.pwmCDuty, FALSE); /* Turn on motor outputs */ ftmSetOutputMask(FTM_0, MASK_NO_OUTPUTS, TRUE); taskDelay(250); printf("Aligning %f %f %f \n", svmAlign.pwmADuty / 32768.0, svmAlign.pwmBDuty /32768.0, svmAlign.pwmCDuty / 32768.0); printf("Set encoder count %d \n", ftmWrite(FTM_2, 1000, 0)); motorOutput = MOTOR_ALIGN_DRIVE; motorState = MOTOR_STATE_RUN; } break; } if (updateFlags & UPDATE_HALT) { updateFlags &= ~UPDATE_HALT; break; } #if 0 if (tickGet() > updateStatusTick) { updateStatusTick = tickGet() + 5; #if 0 if (pwmRampUp) { motorOutput += 0.0005 * UNITY; } else { motorOutput -= 0.0005 * UNITY; } if (motorOutput > 0.4 * UNITY) { motorOutput = 0.4 * UNITY; updateStatusTick = tickGet() + 1000; pwmRampUp = FALSE; } else if (motorOutput < 0.1 * UNITY) { motorOutput = 0.1 * UNITY; pwmRampUp = TRUE; updateStatusTick = tickGet() + 1000; } #endif } #endif if (tickGet() > updateUserTick) { int count = ftmRead(FTM_2); printf("%d,[%3.2f], %3.2f, %3.2f, 0000, " "%d, <<%3.2f>>%3.2f, %3.2f, %3.2f\n", // angleSetPoint / 32768.0, count, angleSetPoint / 32768.0, mechTheta / 32768.0, theta / 32768.0, svmOutput.sinLUTIdx, motorOutput / 32768.0, svmOutput.pwmADuty/32768.0, svmOutput.pwmBDuty/32768.0, svmOutput.pwmCDuty/32768.0); updateUserTick = tickGet() + 20; } } close(fdPot); printf("Application Fatal Error! \n"); while(1) {}; return 0; }
void setPerf(short cpu, short mem, short gpu ) { switch(cpu) { case 0: setClock(k1008MHz_CPU); break; case 1: setClock(k800MHz_CPU); break; default: setClock(k1008MHz_CPU); } switch(mem) { case 0: setClock(k200MHz_L3); setClock(k400MHz_DDR); break; case 1: setClock(k100MHz_L3); setClock(k200MHz_DDR); break; default: setClock(k200MHz_L3); setClock(k400MHz_DDR); } switch(gpu) { case 0: setClock(k307MHz_SGX); break; case 1: setClock(k192MHz_SGX); break; default: setClock(k307MHz_SGX); } // system("omapconf opp"); }
void initTimer(void) { registerISR(8, timerISR); /* register ISR i vector table */ setClock(50,40); /* set clock to 200ms */ startClock(); /* start clock */ }
/** \param[in] busNumber The number of the SPI bus to open (0 or 1) \param[in] mode The SPI mode (clock polarity and phase: 0, 1, 2 or 3) \param[in] clockKhz The clock speed to use for the SPI bus \param[in] dataBits The size of an SPI transfer in bits \return HRESULT success or error code. */ HRESULT BtSpiControllerClass::begin(ULONG busNumber, ULONG mode, ULONG clockKhz, ULONG dataBits) { HRESULT hr = S_OK; PWCHAR deviceName = nullptr; PVOID baseAddress = nullptr; _SSCR0 sscr0; _SSSR sssr; // If this object does not yet have the SPI bus open: if (m_hController == INVALID_HANDLE_VALUE) { // Get the name of the PCI device that describes the SPI controller. switch (busNumber) { case EXTERNAL_SPI_BUS: deviceName = mbmSpiDeviceName; break; default: // Only support one SPI bus hr = DMAP_E_SPI_BUS_REQUESTED_DOES_NOT_EXIST; } if (SUCCEEDED(hr)) { // Open the Dmap device for the SPI controller. hr = GetControllerBaseAddress(deviceName, m_hController, baseAddress); if (SUCCEEDED(hr)) { m_registers = (PSPI_CONTROLLER)baseAddress; m_registersUpper = (PSPI_CONTROLLER_UPPER)(((PBYTE)baseAddress) + SPI_CONTROLLER_UPPER_OFFSET); } } if (SUCCEEDED(hr)) { // We now "own" the SPI controller, intialize it. sscr0.ALL_BITS = 0; m_registers->SSCR0.ALL_BITS = sscr0.ALL_BITS; // Disable controller sscr0.DSS = (dataBits - 1) & 0x0F; // Data width ls4bits sscr0.EDSS = ((dataBits - 1) >> 4) & 0x01; // Data width msbit sscr0.RIM = 1; // Mask RX FIFO Over Run interrupts sscr0.TIM = 1; // Mask TX FIFO Under Run interrupts m_registers->SSCR0.ALL_BITS = sscr0.ALL_BITS; m_registers->SSCR1.ALL_BITS = 0; // Master mode, interrupts disabled sssr.ALL_BITS = 0; sssr.ROR = 1; // Clear any Receive Overrun int sssr.PINT = 1; // Clear any Peripheral Trailing Byte int sssr.TINT = 1; // Clear any Receive Time-out int sssr.EOC = 1; // Clear any End of Chain int sssr.TUR = 1; // Clear any Transmit FIFO Under Run int sssr.BCE = 1; // Clear any Bit Count Error m_registers->SSSR.ALL_BITS = sssr.ALL_BITS; hr = setMode(mode); } if (SUCCEEDED(hr)) { hr = setClock(clockKhz); } } return hr; }
void setMinutes(const uint08 minutes) { setClock(getHours(), minutes, getSeconds()); }
void setSeconds(const uint08 seconds) { setClock(getHours(), getMinutes(), seconds); }
/** \param[in] busNumber The number of the SPI bus to open (0 or 1) \param[in] mode The SPI mode (clock polarity and phase: 0, 1, 2 or 3) \param[in] clockKhz The clock speed to use for the SPI bus \param[in] dataBits The size of an SPI transfer in bits \return HRESULT success or error code. */ HRESULT BcmSpiControllerClass::begin(ULONG busNumber, ULONG mode, ULONG clockKhz, ULONG dataBits) { HRESULT hr = S_OK; PWCHAR deviceName = nullptr; PVOID baseAddress = nullptr; _CS cs; // If this object does not yet have the SPI bus open: if (m_hController == INVALID_HANDLE_VALUE) { // Get the name of the PCI device that describes the SPI controller. switch (busNumber) { case EXTERNAL_SPI_BUS: deviceName = pi2Spi0DeviceName; break; case SECOND_EXTERNAL_SPI_BUS: deviceName = pi2Spi1DeviceName; break; default: // Only support two SPI buses hr = DMAP_E_SPI_BUS_REQUESTED_DOES_NOT_EXIST; } if (SUCCEEDED(hr)) { // Open the Dmap device for the SPI controller for exclusive access. hr = GetControllerBaseAddress(deviceName, m_hController, baseAddress); if (SUCCEEDED(hr)) { m_registers = (PSPI_CONTROLLER)baseAddress; } } // // We now "own" the SPI controller, intialize it. // if (SUCCEEDED(hr)) { hr = setClock(clockKhz); } if (SUCCEEDED(hr)) { hr = setMode(mode); } if (SUCCEEDED(hr)) { cs.ALL_BITS = 0; cs.CPHA = m_clockPhase; cs.CPOL = m_clockPolarity; cs.CLEAR = 3; // Clear both FIFOs, cs.TA = 1; // then start transfers. m_registers->CS.ALL_BITS = cs.ALL_BITS; } } return hr; }