void Test_sdcard(void) { if (Sdio_verification!=FALSE) { #ifdef ENABLE_WRITE_MODE /* Write a single sector of data (512 bytes) */ if (!sdcardinfo.sdck_wp()) { prep_data(0, 1); /* Warning: This may corrupt SD card data! */ if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) { errorc = -3; goto error_exit1; } /* Wait for write to finish (at the card) */ wait_for_program_finish(); } #endif memset(lbuff, 0, sizeof(lbuff)); /* Read a single sector of data (512 bytes) */ if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) { errorc = -4; goto error_exit1; } #ifdef ENABLE_WRITE_MODE /* Verify data and halt if an error occurs */ if (!sdcardinfo.sdck_wp()) { if (verify_data(1, 0, 1) == 0) { errorc = -5; goto error_exit1; } lpc_printf("SD card Verified!"); Sdio_verification = TRUE; goto exit1; } #endif exit1: return; } error_exit1: lpc_printf("\n\rSD Card read/write operation not succeeded."); Sdio_verification = FALSE; }
void commonInit(void) { platformInit(); timerInit(); GPIOInit(); USB_UserInit(); debug_frmwrk_init_clk(CLKFREQ); lpc_printf("M4 start\n"); }
void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize) { platformInit(); // button, SPI_SSEL LPC_GPIO_PORT->MASK[5] = 0; LPC_GPIO_PORT->PIN[5] = 0x20; // negate SPI_SS LPC_GPIO_PORT->DIR[5] = 0x20; // SPI_SS - output // deal with P4_1, GPIO2[1] LPC_GPIO_PORT->MASK[2] = 0; LPC_GPIO_PORT->DIR[2] = 0; // set timer so we count clock cycles LPC_TIMER1->IR = 0; LPC_TIMER1->TCR = 1; LPC_TIMER1->PR = 0; // microsecond timer LPC_TIMER2->IR = 0; LPC_TIMER2->TCR = 1; LPC_TIMER2->PR = CLKFREQ_US-1; debug_frmwrk_init_clk(CLKFREQ); USB_UserInit(); lpc_printf("M4 start\n"); IPC_haltSlave(); ADCInit(); SCTInit(); CameraInit(); // start slave IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize); IPC_startSlave(); // initialize chirp objects g_chirpUsb = new ChirpUsb(); g_chirpM0 = new ChirpM0(); // initialize devices/modules pwr_init(); spi_init(); cam_init(); rcs_init(); led_init(); //cc_init(); }
int main(void) { // pixyInit(SRAM3_LOC, &LR0[0], sizeof(LR0)); #if 0 pixyInit(); cc_init(g_chirpUsb); ser_init(); exec_init(g_chirpUsb); #endif #if 1 /* test loop */ pixyInit(); exec_init(g_chirpUsb); #if 0 int i = 0; cam_setMode(1); while(1) { //uint8_t reg = cam_getRegister(0x0a); g_chirpUsb->service(); cprintf("hello world %d\n", i++); } #endif #if 0 while(1) { uint8_t *frame = (uint8_t *)SRAM1_LOC; int res; res = cam_getFrame(frame, SRAM1_SIZE, CAM_GRAB_M1R2, 0, 0, CAM_RES2_WIDTH, CAM_RES2_HEIGHT); i++; if (i%50==0) { lpc_printf("%d\n", i); } } #endif #endif #if 1 exec_addProg(&g_progBlobs); ptLoadParams(); exec_addProg(&g_progPt); exec_addProg(&g_progVideo, true); exec_loop(); #endif #if 0 //prm_format(); ColorModel model, *model2; uint32_t len; model.m_hue[0].m_slope = 1.0; model.m_hue[0].m_yi = 2.0; model.m_hue[1].m_slope = 3.0; model.m_hue[1].m_yi = 4.0; model.m_sat[0].m_slope = 5.0; model.m_sat[0].m_yi = 6.0; model.m_sat[1].m_slope = 7.0; model.m_sat[1].m_yi = 8.0; prm_add("signature1", "Color signature 1", INTS8(sizeof(ColorModel), &model), END); prm_set("signature1", INTS8(sizeof(ColorModel), &model), END); model.m_hue[0].m_slope = 9.0; model.m_hue[0].m_yi = 10.0; model.m_hue[1].m_slope = 11.0; model.m_hue[1].m_yi = 12.0; model.m_sat[0].m_slope = 13.0; model.m_sat[0].m_yi = 14.0; model.m_sat[1].m_slope = 15.0; model.m_sat[1].m_yi = 16.0; prm_add("signature2", "Color signature 2", INTS8(sizeof(ColorModel), &model), END); prm_set("signature2", INTS8(sizeof(ColorModel), &model), END); prm_get("signature1", &len, &model2, END); model.m_hue[0].m_slope = 17.0; model.m_hue[0].m_yi = 18.0; model.m_hue[1].m_slope = 19.0; model.m_hue[1].m_yi = 20.0; model.m_sat[0].m_slope = 21.0; model.m_sat[0].m_yi = 22.0; model.m_sat[1].m_slope = 23.0; model.m_sat[1].m_yi = 24.0; prm_get("signature1", &len, &model2, END); prm_set("signature1", INTS8(sizeof(ColorModel), &model), END); prm_get("signature1", &len, &model2, END); prm_get("signature2", &len, &model2, END); #endif #if 0 #define DELAY 1000000 rcs_setFreq(100); rcs_setLimits(0, -200, 200); rcs_setLimits(1, -200, 200); while(1) { rcs_setPos(0, 0); delayus(DELAY); rcs_setPos(0, 500); delayus(DELAY); rcs_setPos(0, 1000); delayus(DELAY); rcs_setPos(1, 0); delayus(DELAY); rcs_setPos(1, 500); delayus(DELAY); rcs_setPos(1, 1000); delayus(DELAY); } #endif #if 0 while(1) { g_chirpUsb->service(); handleButton(); } #endif }
/*********************************************************************//** * @brief Main SDIO program body * @param[in] None * @return int **********************************************************************/ void Sdio_init(void) { uint32_t dms, sdio_clk; int32_t loops, blk; uint8_t buf[50]; errorc = 1; /* Configure the IO's for the LEDs */ /* Setup muxing for SD interface */ /*Xplorer*/ scu_pinmux(0x1 ,11 , SDFASTINOUTPIN, FUNC7); /* P1.11 SDIO D2 */ scu_pinmux(0x1 ,10 , SDFASTINOUTPIN, FUNC7); /* P1.10 SDIO D1 */ scu_pinmux(0x1 ,9 , SDFASTINOUTPIN, FUNC7); /* P1.9 SDIO D0 */ scu_pinmux(0x1 ,6, SDFASTINOUTPIN, FUNC7); /* P1.6 SDIO command */ scu_pinmux(0x1 ,12 , SDFASTINOUTPIN, FUNC7); /* P1.12 SDIO D3 */ LPC_SCU->SFSCLK_2 = 0x04; /* CLK2 Enable*/ CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_SDIO); /* Generate interrupt @ 100 Hz */ /* The SDIO driver needs to know the SDIO clock rate */ sdio_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_SDIO); /* This init sdio with sdio_clk */ sdif_init(sdio_clk, sdmmc_irq); /* Wait for a card to be inserted (note CD is not on the SDMMC power rail and can be polled without enabling SD slot power */ /* Allow some time for the power supply to settle and the card to fully seat in the slot */ dms = u32Milliseconds + 250; while (dms > u32Milliseconds); /* Enumerate the card once detected. Note this function may block for a little while. */ if (!sdmmc_acquire(sdmmc_setup_wakeup, sdmmc_irq_driven_wait, sdmmc_waitms, &sdcardinfo)) { errorc = -1; goto error_exit; } lpc_printf("SD card detected and initialized..!\r\n"); /* Setup card specific callbacks - use driver functions, but these can be changed to custom functions or unique functions per slot. These aren't used in the drivers, so setup of these is optional, but they are setup here to be complete. */ sdcardinfo.sdck_det = sdif_card_ndetect; sdcardinfo.sdck_wp = sdif_card_wp_on; sdcardinfo.sd_setpow = sdif_power_onoff; sdcardinfo.sd_setrst = sdif_reset; memset(lbuff, 0, sizeof(lbuff)); if (sdmmc_read_blocks((void *) lbuff, 0, 0) == 0) { errorc = -2; goto error_exit; } #ifdef ENABLE_WRITE_MODE lpc_printf("Writing data to sector 1 of SD card and verifying:\r\n"); /* Write a single sector of data (512 bytes) */ if (!sdcardinfo.sdck_wp()) { prep_data(0, 1); /* Warning: This may corrupt SD card data! */ if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) { errorc = -3; goto error_exit; } /* Wait for write to finish (at the card) */ wait_for_program_finish(); } #endif memset(lbuff, 0, sizeof(lbuff)); /* Read a single sector of data (512 bytes) */ if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) { errorc = -4; goto error_exit; } #ifdef ENABLE_WRITE_MODE /* Verify data and halt if an error occurs */ if (!sdcardinfo.sdck_wp()) { if (verify_data(1, 0, 1) == 0) { errorc = -5; goto error_exit; } lpc_printf("Verified!\r\n"); } #endif #ifdef USE_MULTPLE_TRANSFER #ifdef ENABLE_WRITE_MODE lpc_printf("Writing data in Multitransfer mode and verifying:\r\n"); /* Write data using multiple sector write */ if (!sdcardinfo.sdck_wp()) { prep_data(0x10, 3); /* Warning: This may corrupt SD card data! */ if (sdmmc_write_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) { errorc = -6; goto error_exit; } wait_for_program_finish(); } #endif memset(lbuff, 0, sizeof(lbuff)); /* Read data using multiple sector read */ if (sdmmc_read_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) { errorc = -7; goto error_exit; } #ifdef ENABLE_WRITE_MODE /* Verify data and halt if an error occurs */ if (!sdcardinfo.sdck_wp()) { if (verify_data(MULT_XFER_MAX_SECTORS, 0x10, 3) == 0) { errorc = -8; goto error_exit; } lpc_printf("Verified!\r\n"); } #endif lpc_printf("measure continuous read speed...\r\n"); tstartr = u32Milliseconds; loops = 1000; blk = 64; while (loops-- > 0) { if (sdmmc_read_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) { errorc = -8; goto error_exit; } blk += MULT_XFER_MAX_SECTORS; } tstopr = u32Milliseconds; memset(buf, 0, sizeof(buf)); lpc_printf("read speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*1000/(tstopr-tstartr)); #ifdef ENABLE_WRITE_MODE lpc_printf("measure continuous write speed...\r\n"); if (!sdcardinfo.sdck_wp()) { tstartw = u32Milliseconds; loops = 200; blk = 64; while (loops-- > 0) { if (sdmmc_write_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) { errorc = -9; goto error_exit; } blk += MULT_XFER_MAX_SECTORS; wait_for_program_finish(); } tstopw = u32Milliseconds; } memset(buf, 0, sizeof(buf)); lpc_printf("write speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*200/(tstopw-tstartw)); #endif #endif goto exit; error_exit: lpc_printf("SD Card read/write operation not succeeded.\r\n"); Sdio_verification = FALSE; exit: return; }