bool IOMapper::start(IOService *provider) { OSObject * obj; if (!super::start(provider)) return false; if (!initHardware(provider)) return false; fPageSize = getPageSize(); if (fIsSystem) { sMapperLock.lock(); IOMapper::gSystem = this; sMapperLock.wakeup(&IOMapper::gSystem); sMapperLock.unlock(); } if (provider) { obj = provider->getProperty("iommu-id"); if (!obj) obj = provider->getProperty("AAPL,phandle"); if (obj) setProperty(gIOMapperIDKey, obj); } return true; }
int main(void) { //Start the HW initHardware(); ciaaWriteOutput(3,0); //create the queue xQueue1 = xQueueCreate( QUEUE1_SIZE, sizeof(uint8_t) ); if (xQueue1==NULL) ciaaWriteOutput(4,1); //if it is not create, turn on the red led //Create task to read the button xTaskCreate(taskReadButton, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); //Create task to blick the led xTaskCreate(taskBlickLed, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); //Start the Scheduler vTaskStartScheduler(); while (1) { } }
int main(void) { //Start the HW uint8_t numLedRGBred; uint8_t numLedRGBgreen; uint8_t numLedRGBblue; initHardware(); ciaaWriteOutput(3,0); // Create a semaphore vSemaphoreCreateBinary(xSemaphore); //xSemaphoreTake(xSemaphore,portMAX_DELAY); //Create task to read the button //xTaskCreate(taskReadButton, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); numLedRGBred=0; //LED RED //Create task to blick the led xTaskCreate(taskBlickLed, (const char *)"task", configMINIMAL_STACK_SIZE*2, &numLedRGBred, tskIDLE_PRIORITY+1, 0); numLedRGBgreen=1; //LED GREEN //Create task to blick the led xTaskCreate(taskBlickLed, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, &numLedRGBgreen, tskIDLE_PRIORITY+1, 0); numLedRGBblue=2; //LED BLUE //Create task to blick the led xTaskCreate(taskBlickLed, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, &numLedRGBblue, tskIDLE_PRIORITY+1, 0); //Start the Scheduler vTaskStartScheduler(); while (1) { } }
int main(void) { _delay_ms(200); // Power and Hardware initial stabilization initHardware(); while(1) { _delay_ms(250); _delay_ms(250); //USART_EnviarLn("- "); _delay_ms(250); _delay_ms(250); uint32_t resADC = ADC_RealizarConversion(0); int8_t resp[3]; resp[2] = resADC/100; resp[1] = resADC/10-resp[2]*10; resp[0] = resADC-resp[2]*100-resp[1]*10; USART_Enviar(' '); USART_Enviar(resp[2]+0x30); USART_Enviar(resp[1]+0x30); USART_Enviar(resp[0]+0x30); USART_Enviar(0x0D); //TODO:: Please write your application code } }
/* * NAME * * main * * DESCRIPTION * * prints out a standard banner on serial port * * "University of Washington - UART Test Application" * * PARAMETERS * * none... * * EXAMPLE * * from crt.s * * B main * * NOTES * * This routine never terminates... * */ int main(void) { uint32_t p; /* initialize */ initHardware(); printString("\033[2J"); /* Clear entire screen */ printString("Olimex LPC-2378-STK... alive!!!\n"); //sprintf(string, "sprintf works!\n"); //printString(string); while (1) { /* Turn MCIPWR SD LED On */ VOLATILE32(FIO0SET) |= 1<<21; printString("University of Washington - UART Test Application \n"); for (p = 0; p < 0x100000; p++ ); // wait // IMPORTANT: String formatting drags in tons of other library code // sprintf(string, "\n.%u", p); // printString(string); /* Turn MCIPWR SD LED Off */ VOLATILE32(FIO0CLR) |= 1<<21; for (p = 0; p < 0x100000; p++ ); // wait } /* never terminates, but put this here to make compiler happy ... */ return(0); }
void RFM70::begin() { initHardware(); rfm70_SPI.begin(); rfm70_SPI.setDataMode(SPI_MODE0); rfm70_SPI.setBitOrder(MSBFIRST); // Set the SPI frequency to be one sixteenth of the frequency of the system clock rfm70_SPI.setClockDivider(RFM77_DEFAULT_SPI_CLOCK_DIV); digitalWrite(_cs, LOW); delay(100); delayMs(RFM70_BEGIN_INIT_WAIT_MS); initRegisters(); confAddrWidth(3); //max power configRfPower(3); //gain configLnaGain(1); //default mode is rx mode setMode(MODE_PRX); }
void main (void) { /* Add your code here: create tasks, semaphores, ... */ initHardware(0); analogInputs = semBCreate (SEM_Q_PRIORITY, SEM_FULL); writeDisplay = semBCreate (SEM_Q_PRIORITY, SEM_FULL); int readInputsID; readInputsID = taskSpawn ("readInputs", 150, 0,0x1000,(FUNCPTR) readInputs,0,0,0,0,0,0,0,0,0,0); int showInputsID; showInputsID = taskSpawn ("showInputs", 160, 0,0x1000,(FUNCPTR) showInputs,0,0,0,0,0,0,0,0,0,0); int readKeyboardID; readKeyboardID = taskSpawn ("readKeyboard", 170, 0,0x1000,(FUNCPTR) readKeyboard,0,0,0,0,0,0,0,0,0,0); int timerID; timerID = taskSpawn ("timer", 140, 0,0x1000,(FUNCPTR) timer,0,0,0,0,0,0,0,0,0,0); int tcpServerID; tcpServerID = taskSpawn ("tcpServer", 200, 0,0x1000,(FUNCPTR) tcpServer,0,0,0,0,0,0,0,0,0,0); printf("Hello World"); /* Suspend own task */ taskSuspend (0); } /* main */
int main(void) { /*==================[Inicializacion]==========================*/ uint8_t wbuf[2] = {0,0}; uint8_t rbuf[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //Se lo crea con 6 posiciones porque los registros que se procesan de los sensores son : /* ACCEL_XOUT_H ACCEL_XOUT_L ACCEL_YOUT_H ACCEL_YOUT_L ACCEL_ZOUT_H ACCEL_ZOUT_L TEMP_OUT_H TEMP_OUT_L GYRO_XOUT_H GYRO_XOUT_L GYRO_YOUT_H GYRO_YOUT_L GYRO_ZOUT_H GYRO_ZOUT_L */ uint16_t samples[7] = {0,0,0,0,0,0,0}; //cada posicion es de 16 bits, necesario para guardar //la parte low y high de las muestras de accel I2C_XFER_T xfer; initHardware(); /*==================[Configuracion del I2C_XFER_T]==========================*/ // Metodo de Escritura //Define el registro que se va a leer en la primera posicion de wbuf //wbuf[0] = MPU6050_RA_ACCEL_XOUT_H; //Parte high de la lectura en x del acelerometro //Como la lectura se realiza de forma secuencial, en la posicion 0 //del rbuf ira este dato y en la posicion 1 ira la correspondiente a //la posicion siguiente, osea ACCEL_XOUT_L (0x3C) MPU6050_wakeup(&xfer); //Lectura de PWR_MGMMT_1 2 (para verificar si se lo saco del sleep y de standby a los ejes) wbuf[0] = MPU6050_RA_PWR_MGMT_1; I2C_XFER_config(&xfer, rbuf, 2, MPU6050_I2C_SLAVE_ADDRESS, 0, wbuf, 1); //Configuracion de la 1era direccion desde la que se leeran los valores de los registros de los sensores wbuf[0]=MPU6050_RA_ACCEL_XOUT_H; wbuf[1]=0; while(1) { I2C_XFER_config(&xfer, rbuf, 14, MPU6050_I2C_SLAVE_ADDRESS, 0, wbuf, 1); Fill_Samples(&samples, &rbuf); } return 0; }
int main(void) { initHardware(); while (1) { Board_LED_Toggle(LED); pausems(DELAY_MS); } }
int main(void) { initHardware(); xTaskCreate(task, (const char *)"task", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); vTaskStartScheduler(); while (1) { } }
void main(void) { initHardware(); initSoftware(); ei(); while (1) { DEBUG_LED_PIN = (fSwitchState == SWITCH_PIN_ON) && fTimersMode; } }
int main(void) { initHardware(); sei(); kbdInit(); scanInit(); layersInit(); macrosInit(); expLoad(); _delay_ms(5); scanEnable(); /* try loading vref from eeprom; if set to 0xffff, run calibration */ vrefLoad(); if (vrefGet() == 0xffff) kbdCalibrate(); for (;;) { /* try to keep updates synchronous; we don't want to update * bitmap if we haven't sent the last report yet. */ if (( usingNKROReport() && !updateNKROReport) || (!usingNKROReport() && !updateKeyboardReport)) { bool needsUpdate = false; needsUpdate |= kbdUpdateSCBmp(); needsUpdate |= macrosProcessScan(); needsUpdate |= expProcessScan(needsUpdate); if (needsUpdate) { updateKeyboardReport = true; updateNKROReport = true; updateSystemReport = true; updateConsumerReport = true; } layersProcessScan(); } if (USB_DeviceState == DEVICE_STATE_Unattached || USB_DeviceState == DEVICE_STATE_Suspended) if (USB_Device_RemoteWakeupEnabled && kbdWantsWakeup()) USB_Device_SendRemoteWakeup(); HID_Device_USBTask(&keyboardHIDIface); HID_Device_USBTask(&genericHIDIface); HID_Device_USBTask(&nkroHIDIface); HID_Device_USBTask(&extrakeyHIDIface); USB_USBTask(); } }
int main(int argc, char **argv) { unsigned long freq; if (argc != 2) { printf("Usage: %s [frequency]\n", argv[0]); return 1; } // init PWM module for GPIO pin 18 with 50 Hz frequency freq = strtoul(argv[1], NULL, 0); initHardware(freq); }
int main(void) { // Init device initDevice(); initHardware(); // Start interrupts ei(); for(;;) continue; }
void main (void) { unsigned char tempOut; /* Connect interrupt service routine to vector and all stuff */ intConnect (INUM_TO_IVEC(aioIntNum), my_ISR, aioIntNum); sysIntEnablePIC (aioIRQNum); /* Enable interrupts on the aio: * All interrupts and interrupt from counter 1 too */ tempOut = 0x24; sysOutByte (aioBase + intEnAddress, tempOut); /* Start counter 1 as timer with 50 ms period * It has a clock input of 1 MHz = 1 µs * Therefore the load value is 0xC350 = 50000 */ tempOut = 0x74; sysOutByte (aioBase + cntCntrlReg, tempOut); tempOut = 0x50; sysOutByte (aioBase + cnt1Address, tempOut); tempOut = 0xC3; sysOutByte (aioBase + cnt1Address, tempOut); /* Add your code here: create tasks, semaphores, ... */ //printf("Hello World!"); /*The second task shall do the following: * - It starts counter a as an auto-reload timer with a period of 50 ms. * - The interrupt generated by this counter activates the task. * This shall be done with a semaphore. * - The task reads the analog inputs of both the potentiometer and the temperature. * - If the values have changed compared to the previous ones, these shall be written into global * variables (AIn). * - A hysteresis of e.g. 10 – 20 bit is necessary due to the noise of the analog inputs. * * */ initHardware(0); int readTask; readTask = taskSpawn("tRead", 101, 0, 0x1000, (FUNCPTR) tRead,0,0,0,0,0,0,0,0,0,0); timIntSem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY); /* The third task shall do the following: * - It writes the values of the global variables (AIn) onto the display. * - This shall happen approx. each 100 ms */ int writeTask; writeTask = taskSpawn("tWrite",102,0,0x1000, (FUNCPTR) tWrite,0,0,0,0,0,0,0,0,0,0); /* Suspend own task */ taskSuspend (0); //suspended sich selber } /* main */
int main(void) { facilitatePowersaving(); // Pull-ups and PR Registers initHardware(); // Switches, LEDs, Sleep, Interrupt sei(); // Enable global interrupts /* === Initialization of TWI Module === */ // Enable internal pull-up on PD0, PD1 for correct TWI operation PORTCFG.MPCMASK = 0x03; TWIPORT.PIN0CTRL = (TWIPORT.PIN0CTRL & ~PORT_OPC_gm) | PORT_OPC_PULLUP_gc; /* Initialize TWI master. */ TWI_MasterInit(&twiMaster, &TWI, TWI_MASTER_INTLVL_LO_gc, TWI_BAUDSETTING); /* Initialize TWI slave. */ TWI_SlaveInitializeDriver(&twiSlave, &TWI, TWI_SlaveProcessData); TWI_SlaveInitializeModule(&twiSlave, OWN_ADDRESS, TWI_SLAVE_INTLVL_LO_gc); /* === End Initialization === */ while (1) { // Try to sleep while we are waiting for button press while (READ_SWITCHES == 0x00){ //See board.h for READ_SWITCHES define. sleep(); } _delay_ms(5); // Debounce switch sendBuffer[0] = READ_SWITCHES; TWI_MasterWrite(&twiMaster, // Module OTHER_ADDRESS, // Which slave &sendBuffer[0], // What to send 1); // Send how much /* Wait until transaction is complete. Required TWI interrupts will be executed while waiting */ while (twiMaster.status != TWIM_STATUS_READY); // Wait for user to release button. while (READ_SWITCHES != 0x00); //See board.h for READ_SWITCHES define. } }
GraphicsDevice::GraphicsDevice( HWND p_hWnd, int p_width, int p_height, bool p_windowMode ) { m_width=p_width; m_height=p_height; m_windowMode = p_windowMode; m_wireframeMode=false; m_interopCanvasHandle=new Texture*; // 1. init hardware initSwapChain(p_hWnd); initHardware(); // 2. init factories m_viewFactory = new ViewFactory(m_device); m_shaderFactory = new ShaderFactory(m_device,m_deviceContext,m_featureLevel); m_bufferFactory = new BufferFactory(m_device,m_deviceContext); m_textureFactory = new TextureFactory(m_device); // 3. init views initBackBuffer(); initGBufferAndDepthStencil(); // 4. init shaders string exePathPrefix = GetExecutablePathDirectory(); m_composeShader = m_shaderFactory->createComposeShader(exePathPrefix+"../Shaders/ComposeShader.hlsl"); m_wireframeShader = m_shaderFactory->createMeshShader(exePathPrefix+"../Shaders/WireframeShader.hlsl"); m_meshBaseShader = m_shaderFactory->createMeshShader(exePathPrefix + "../Shaders/MeshShader.hlsl"); // 5. build states buildBlendStates(); m_currentBlendStateType = BlendState::DEFAULT; m_blendMask = 0xffffffff; for (int i=0;i<4;i++) m_blendFactors[i]=1; buildRasterizerStates(); m_currentRasterizerStateType = RasterizerState::DEFAULT; // 6. Create draw-quad and other built in primitives m_fullscreenQuad = m_bufferFactory->createFullScreenQuadBuffer(); m_aabbLineMesh = m_bufferFactory->createLineBox(0.5f); m_fallbackBox = m_bufferFactory->createBoxMesh(0.5f); m_meshFallbackBoxList.push_back(m_fallbackBox); fitViewport(); }
int main(void) { int duty = 100; initHardware(); while(1) { pausems(1000); duty += 100; if(duty == 1000) duty = 100; Chip_TIMER_SetMatch(LPC_TIMER1, 1, duty); Chip_TIMER_Reset(LPC_TIMER1); Chip_TIMER_ClearMatch(LPC_TIMER1, 1); Chip_TIMER_ClearMatch(LPC_TIMER1, 0); } }
static void init_unicorn_hat(void) { int i; struct sigaction sa; numLEDs = 64; initHardware(); clearLEDBuffer(); setBrightness(DEFAULT_BRIGHTNESS); for (i = 0; i < 64; i++) { memset(&sa, 0, sizeof(sa)); sa.sa_handler = unicornd_exit; sigaction(i, &sa, NULL); } }
int main(void) { initHardware(); dbgPrint("TEST"); // Create a semaphore //vSemaphoreCreateBinary(xSemaphore); //xSemaphoreTake(xSemaphore,portMAX_DELAY); //create the queue xQueue1 = xQueueCreate( QUEUE1_SIZE, sizeof(uint8_t) ); xTaskCreate(task, (const char *)"task", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); vTaskStartScheduler(); while (1) { } }
int main (int argc, char *argv[]) { // Init sound tones_init(WAVE_SQUARE); midi_init(); midi_play(&mario); // Init hardware initHardware(); // Main loop while (1) { // Get data from midi player abdac_output = midi_tick(); // Wait for next interrupt (Assume abdac) asm("sleep 1"); } return 0; }
void RFM70::begin() { initHardware(); initSPI(); delayMs(RFM70_BEGIN_INIT_WAIT_MS); initRegisters(); #if 0 confAddrWidth(3); //max power configRfPower(3); //gain configLnaGain(1); //default mode is rx mode setMode(MODE_PRX); #endif }
int main(void) { //Start the HW initHardware(); ciaaWriteOutput(3,0); // Create a semaphore vSemaphoreCreateBinary(xSemaphore); xSemaphoreTake(xSemaphore,0); //Create task to read the button xTaskCreate(taskReadButton, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); //Create task to blick the led xTaskCreate(taskBlickLed, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0); //Start the Scheduler vTaskStartScheduler(); while (1) { } }
int main(int argc, char **argv) { // init PWM module for GPIO pin 18 with 50 Hz frequency initHardware(); // servo test, position in percent: 0 % = 1 ms, 100 % = 2 ms while (1) { setServo(0); sleep(1); setServo(25); sleep(1); setServo(50); sleep(1); setServo(75); sleep(1); setServo(100); sleep(1); } return 0; }
int main(void) { _delay_ms(40); initHardware(); uint8_t EntraCarro[2] = {0x00, 0x00}; uint8_t SaleCarro[2] = {0xff, 0xff}; while(1){ _delay_ms(40); if(PIND&0x01){ I2C_EscribirBytes(0x00, 0x01, 0x00, 2, EntraCarro); while(PIND&0x01){} }else if(PIND&0x02){ I2C_EscribirBytes(0x00, 0x01, 0x00, 2, SaleCarro); while(PIND&0x02){} } } }
float rotSpeed = 0; float penSpeed = 0; // these are local variables for Function SteppermotorMove-Command, but for performance-reasons it will be initialized here static void Init(void) { /* initialize struct fields */ deviceData.handle = AS1_Init (&deviceData); deviceData.isSent = FALSE; deviceData.rxChar = '\0'; deviceData.rxPutFct = RxBuf_Put; /* set up to receive RX into input buffer */ // RxBuf_Init(); /* initialize RX buffer */ /* Set up ReceiveBlock() with a single byte buffer. We will be called in OnBlockReceived() event. */ while (AS1_ReceiveBlock (deviceData.handle, (LDD_TData *) &deviceData.rxChar, sizeof(deviceData.rxChar)) != ERR_OK) { } /* initial kick off for receiving data */ AccelStepper_Init (&rotMotor, STEP1_PIN, DIR1_PIN); AccelStepper_Init (&penMotor, STEP2_PIN, DIR2_PIN);
int main(void) { uint8_t wbuf[3] = {0,0,0xAA}; uint8_t rbuf[3] = {0,0,0}; uint32_t i; I2C_XFER_T xfer; initHardware(); /* Transferencia de escritura (escribo addr y datos, ojo, tamaño de página 32 bytes) */ xfer.rxBuff = 0; xfer.rxSz = 0; xfer.slaveAddr = 0x50; xfer.status = 0; xfer.txBuff = wbuf; xfer.txSz = 3; Chip_I2C_MasterTransfer(I2C1, &xfer); //delay por software calculado con el teorema de los cinco dedos oscilantes for(i=0; i<0xFFFF; i++); /* Transferencia de lectura (escribo addr, leo datos) */ xfer.rxBuff = rbuf; xfer.rxSz = 1; xfer.slaveAddr = 0x50; xfer.status = 0; xfer.txBuff = wbuf; xfer.txSz = 2; Chip_I2C_MasterTransfer(I2C1, &xfer); //delay por software calculado con el teorema de los cinco dedos oscilantes for(i=0; i<0xFFFF; i++); while(1); }
int main(void) { int i=0, offset; #if FILTRO_PASA_BANDA fir_q31_init(&filtro, history, bandpass_taps, BANDPASS_TAP_NUM); offset=500; #elif FILTRO_PASA_BAJOS fir_q31_init(&filtro, history, lowpass_taps, LOWPASS_TAP_NUM); offset=-100; #endif initHardware(); *DWT_CTRL |= 1; while(1) { if(adcFlag) { adcFlag=0; *DWT_CYCCNT=0; /* para medir tiempos de ejecucion */ #if(USAR_FUNCIONES_ASSEMBLER) y[i] = asm_fir_q31_get(&filtro)+offset; y[i] = __USAT(y[i],10); #else y[i] = fir_q31_get(&filtro)+offset; if(y[i]>0x3FF) y[i] = 0x3FF; else if(y[i]<0) y[i] = 0; #endif dacWrite(y[i]); i++; if(i==500) i=0; } } }
int main( void ) { // TODO: default implementation is bloated //clock_prescale_set( clock_div_1 ); // Allow user to see registers before any disruption bootLoaderInit(); initHardware(); // gives time for jumper pull-ups to stabilize while ( bootLoaderCondition() ) { // Run USB until we have some action to take and that transaction is complete uchar prevTxLen; do { prevTxLen = usbTxLen; wait_usb_interrupt(); } while ( !(prevCommand != cmd_info && usbTxLen == USBPID_NAK && prevTxLen != USBPID_NAK) ); // Stops once we have a command and we've just transmitted the final reply // back to host // Now we can ignore USB until our host program makes another request if ( prevCommand == cmd_erase ) erase_flash(); else if ( prevCommand == cmd_write ) write_flash(); else break; } leaveBootloader(); }
int main(void) { initHardware(); int flashy = 0; BootloaderState state = BLS_UNDEFINED; char currentCommand = 0; while (1) { if (!jshIsUSBSERIALConnected()) { jshPinOutput(LED2_PININDEX, 0); // reset, led off } else { int f = (flashy>>9) & 0x7F; if (f&0x40) f=128-f; jshPinOutput(LED3_PININDEX, ((flashy++)&0xFF)<f); // flash led int d = getc(); if (d>=0) { // if we have data if (state==BLS_EXPECT_DATA) { } else if (state==BLS_INITED) { currentCommand = d; state = BLS_COMMAND_FIRST_BYTE; } else if (state==BLS_COMMAND_FIRST_BYTE) { if (currentCommand == d^0xFF) { unsigned int addr,i; char chksum, buffer[256]; unsigned int nBytesMinusOne, nPages; // confirmed switch (currentCommand) { case CMD_GET: // get bootloader info putc(ACK); putc(5); // 6 bytes // now report what we support putc(BOOTLOADER_MAJOR_VERSION<<4 | BOOTLOADER_MINOR_VERSION); // Bootloader version // list supported commands putc(CMD_GET); putc(CMD_GET_ID); putc(CMD_READ); putc(CMD_WRITE); putc(CMD_EXTERASE); // erase putc(ACK); // last byte break; case CMD_GET_ID: // get chip ID putc(ACK); putc(1); // 2 bytes // now report what we support putc(0x04); // 0x30 F1 XL density // 0x14 F1 high density putc(0x30); // TODO: really? putc(ACK); // last byte break; case CMD_READ: // read memory putc(ACK); addr = getc_blocking() << 24; addr |= getc_blocking() << 16; addr |= getc_blocking() << 8; addr |= getc_blocking(); chksum = getc_blocking(); // TODO: check checksum putc(ACK); setLEDs(2); // green = wait for data nBytesMinusOne = getc_blocking(); chksum = getc_blocking(); // TODO: check checksum putc(ACK); for (i=0;i<=nBytesMinusOne;i++) putc(((unsigned char*)addr)[i]); setLEDs(0); // off break; case CMD_WRITE: // write memory putc(ACK); addr = getc_blocking() << 24; addr |= getc_blocking() << 16; addr |= getc_blocking() << 8; addr |= getc_blocking(); chksum = getc_blocking(); // TODO: check checksum and address&3==0 putc(ACK); setLEDs(2); // green = wait for data nBytesMinusOne = getc_blocking(); for (i=0;i<=nBytesMinusOne;i++) buffer[i] = getc_blocking(); chksum = getc_blocking(); setLEDs(1); // red = write // TODO: check checksum and (nBytesMinusOne+1)&3==0 FLASH_UnlockBank1(); for (i=0;i<=nBytesMinusOne;i+=4) { unsigned int realaddr = addr+i; if (realaddr >= (FLASH_START+BOOTLOADER_SIZE)) // protect bootloader FLASH_ProgramWord(realaddr, *(unsigned int*)&buffer[i]); } FLASH_LockBank1(); setLEDs(0); // off putc(ACK); // TODO - could speed up writes by ACKing beforehand if we have space break; case CMD_EXTERASE: // erase memory putc(ACK); nPages = getc_blocking() << 8; nPages |= getc_blocking(); chksum = getc_blocking(); // TODO: check checksum if (nPages == 0xFFFF) { // all pages (except us!) setLEDs(1); // red = write FLASH_UnlockBank1(); for (i=BOOTLOADER_SIZE;i<FLASH_TOTAL;i+=FLASH_PAGE_SIZE) FLASH_ErasePage((uint32_t)(FLASH_START + i)); FLASH_LockBank1(); setLEDs(0); // off putc(ACK); } else { putc(NACK); // not implemented } break; default: // unknown command putc(NACK); break; } } else { // not correct putc(NACK); } state = BLS_INITED; } else { switch (d) { case 0x7F: // initialisation byte putc(state == BLS_UNDEFINED ? ACK : NACK); state = BLS_INITED; break; } } } } } }