// ============================================================================= // boot_IspiSendData // ----------------------------------------------------------------------------- /// Send one data. /// This functions sends one data frame. /// The number returned is the number of data frames actually sent. /// /// @param csId The CS to use to send the data. This cs must be activated before /// sending data. /// @param data Frame of data to send. /// @param read \c TRUE if the response of the device to this sent data is /// expected to be read later and thus will be put in the read Fifo. /// @return 1 if the data was sent, 0 otherwise. // ============================================================================= PUBLIC UINT32 boot_IspiSendData(BOOT_ISPI_CS_T csId, UINT32 data, BOOL read) { UINT32 freeRoom; // Clear data upper bit to only keep the data frame. UINT32 reg = data & ~(SPI_CS_MASK | SPI_READ_ENA_MASK); // Add CS and read mode bit reg |= SPI_CS(csId) | (read?SPI_READ_ENA:0); // Enter critical section. UINT32 status = hwp_sysIrq->SC; // Check FIFO availability. freeRoom = GET_BITFIELD(hwp_spi3->status, SPI_TX_SPACE); if (freeRoom > 0) { // Write data. hwp_spi3->rxtx_buffer = reg; // Exit critical section. hwp_sysIrq->SC = status; return 1; } else { // Exit critical section. hwp_sysIrq->SC = status; return 0; } }
int spi_init() { int j; int i; int r; SDHCtype=1; j=5; while(--j) { SPI_CS(0); // Disable CS spi_spin(); puts("SD init...\n"); // puts("SPI Init()\n"); DBG("Activating CS\n"); SPI_CS(1); i=50; while(--i) { if(cmd_reset()==1) // Enable SPI mode { i=1; j=1; } DBG("Sent reset command\n"); if(i==2) { puts("SD card reset failed!\n"); return(0); } } } DBG("Card responded to reset\n"); SDHCtype=is_sdhc(); if(SDHCtype) DBG("SDHC card detected\n"); else // Not SDHC? Set blocksize to 512. { DBG("Sending cmd16\n"); cmd_CMD16(1); } SPI(0xFF); SPI_CS(0); SPI(0xFF); DBG("Init done\n"); return(1); }
int sd_write_sector(unsigned long lba,unsigned char *buf) // FIXME - Stub { int i,t,timeout; SPI(0xff); SPI_CS(1|(1<<HW_SPI_FAST)); SPI(0xff); t=cmd_writesector(lba); if(t!=0) { puts("Write failed\n"); // printf("Read command failed at %d (%d)\n",lba,r); return(1); } SPI(0xFF); // one byte gap SPI(0xFE); // send Data Token // send sector bytes for (i = 0; i < 128; i++) { int t=*(int *)buf; SPI((t>>24)&255); SPI((t>>16)&255); SPI((t>>8)&255); SPI(t&255); buf+=4; } SPI(0xFF); // send CRC lo byte SPI(0xFF); // send CRC hi byte SPI(0xFF); // Pump the response byte timeout = 100000; do { SPI(0xFF); i=SPI_READ(); } while((i==0) && --timeout); SPI(0xff); SPI_CS(0); return(0); }
int CreateMediaRender(char * buf) { void *msg; tls_os_status_t status; u8 uuid[17] = {0}; u8 *mac = wpa_supplicant_get_mac(); sprintf((char *)uuid, "%02x%02x%02x%02x%02x%02x-dmr", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); tls_dmr_init((char *)uuid, (char *)uuid); tls_gpio_cfg(SPI_CLK, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_FLOATING); tls_gpio_cfg(SPI_DATO, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_FLOATING); tls_gpio_cfg(SPI_CCS, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLHIGH); tls_gpio_cfg(DAT_REQ, TLS_GPIO_DIR_INPUT, TLS_GPIO_ATTR_FLOATING); tls_gpio_cfg(LED, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLHIGH); tls_gpio_cfg(RST, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLHIGH); // tls_gpio_cfg(RUN_MODE, TLS_GPIO_DIR_INPUT, TLS_GPIO_ATTR_FLOATING); SPI_CS(1); LED_ON(0); msg = tls_mem_alloc(64 * sizeof(void *)); if (!msg) return -1; status = tls_os_queue_create(&sd_down_mbox, msg, 64, 0); if (status != TLS_OS_SUCCESS) { tls_mem_free(msg); return -1; } tls_os_task_create(NULL, NULL, sd_down_thread, NULL, (void *)sd_down_task_stk, UPNP_SD_STK_SIZE * sizeof(u32), DEMO_DMR_TASK_PRIO,//DEMO_DMR_TASK_PRIO, 0); tls_dmr_set_play_callback(httpdownloadmusic); tls_dmr_set_stop_callback(httpstopdownloadmusic); tls_dmr_set_seek_callback(httpstopdownloadmusic); tls_dmr_set_pause_callback(httpstopdownloadmusic); tls_dmr_set_play_progress_callback(get_grogress); tls_dmr_set_mute_callback(mute_callback); tls_dmr_set_volume_callback(volume_callback); tls_dmr_set_volumedb_callback(volumedb_callback); tls_dmr_set_loudness_callback(loudness_callback); return 0; }
int spi_init() { int i; int r; SDHCtype=1; SPI_CS(0); // Disable CS spi_spin(); puts("SPI Init()\n"); DBG("Activating CS\n"); SPI_CS(1); i=8; while(--i) { if(cmd_reset()==1) // Enable SPI mode i=1; DBG("Sent reset command\n"); if(i==2) { DBG("SD card initialization error!\n"); return(0); } } DBG("Card responded to reset\n"); SDHCtype=is_sdhc(); if(SDHCtype) DBG("SDHC card detected\n"); else // If not SDHC, Set blocksize to 512 bytes { DBG("Sending cmd16 (blocksize)\n"); cmd_CMD16(1); } SPI(0xFF); SPI_CS(0); SPI(0xFF); DBG("Init done\n"); return(1); }
int spi_init() { int i; int r; SDHCtype=1; // HW_PER(PER_TIMER_DIV7)=150; // About 350KHz SPI_CS(0); // Disable CS spi_spin(); // puts("Activating CS\n"); SPI_CS(1); i=8; while(--i) { if(cmd_reset()==1) // Enable SPI mode i=1; puts("Sent reset command\n"); if(i==2) { puts("SD card initialization error!\n"); return(0); } } puts("Card responded to reset\n"); SDHCtype=is_sdhc(); if(SDHCtype) puts("SDHC card detected\n"); puts("Sending cmd16\n"); cmd_CMD16(1); SPI(0xFF); SPI_CS(0); SPI(0xFF); puts("Init done\n"); // HW_PER(PER_TIMER_DIV7)=HW_PER(PER_CAP_SPISPEED); return(1); }
static void spi_end(void) { SPI_CS(true); spi_delay(); }
static void spi_begin(void) { SPI_CS(false); spi_delay(); }
int sd_read_sector(unsigned long lba,unsigned char *buf) { int result=0; int i; int r; // printf("sd_read_sector %d, %d\n",lba,buf); SPI_CS(1|(1<<VAMPIRE_SPI_FAST)); SPI(0xff); r=cmd_read(lba); if(r!=0) { printf("Read command failed at %d (%d)\n",lba,r); return(result); } i=1500000; while(--i) { int v; SPI(0xff); // SPI_WAIT(); v=SPI_READ(); if(v==0xfe) { // puts("Reading sector data\n"); // spi_readsector((long *)buf); int j; // SPI(0xff); short *out=(short *)buf; for(j=0;j<256;++j) { unsigned int t=0; SPI(0xff); t=SPI_READ()<<8; SPI(0xff); t|=SPI_READ(); *out++=t; } #if 0 for(j=0;j<256;++j) { int t,v; t=SPI_PUMP(); *(short *)buf=t; // printf("%d: %d\n",buf,t); buf+=2; } #endif i=1; // break out of the loop result=1; } } SPI(0xff); // SPI_WAIT(); SPI_CS(0); // puts("Sector read\n"); return(result); }
/********************************************** Lcd初始化函数 Initial condition (DB0-15,RS,CSB,WRD,RDB,RESETB="L") ***********************************************/ void Lcd_Initialize(void) { int i; SPI_CS(1); WriteComm(0x0001); Delay(100); SPI_CS(0); WriteComm(0x0011); Delay(20); WriteComm(0x00D0); WriteData(0x0007); WriteData(0x0041); WriteData(0x001C); WriteComm(0x00D1); WriteData(0x0000); WriteData(0x0036); //30 vcm WriteData(0x001B); //15 vdv WriteComm(0x00D2); WriteData(0x0001); // AP0[2:0] WriteData(0x0011); // DC10[2:0],DC00[2:0] WriteComm(0x00C0); //****** ******* WriteData(0x0010); // REV & SM & GS WriteData(0x003B); // NL[5:0] WriteData(0x0000); // SCN[6:0] WriteData(0x0012); //02 NDL , PTS[2:0] WriteData(0x0001); //11 PTG , ISC[3:0] WriteComm(0x00C5); WriteData(0x0003); WriteComm(0x00C8); WriteData(0x0000); WriteData(0x0057); WriteData(0x0033); WriteData(0x0000); WriteData(0x0000); WriteData(0x0000); WriteData(0x0044); WriteData(0x0002); WriteData(0x0077); WriteData(0x0000); WriteData(0x0000); WriteData(0x0000); WriteComm(0x00F8); WriteData(0x0001); WriteComm(0x00FE); WriteData(0x0000); WriteData(0x0002); WriteComm(0x0036); // Set_address_mode WriteData(0x000A); // Bit3: RGB/BGR Delay(20); WriteComm(0x003a); // Set_address_mode WriteData(0x0055); //05---16BIT,06---18BIT Delay(20); WriteComm(0x0029); Delay(10); WriteComm(0x36); //Set_address_mode WriteData(0x68); //横屏,从左下角开始,从左到右,从下到上 Lcd_Light_ON; // while(1) { WriteComm(0x36);//竖屏 WriteData(0x48);// // while(!(SPI1->SR&0x0002)); for(i=0;i<320*480;i++) { LCD_RS(1); SPI_I2S_SendData(SPI1, COLOR_BLUE>>8); LCD_RS(1); SPI_I2S_SendData(SPI1, COLOR_BLUE); } for(i=0;i<320*480;i++) { LCD_RS(1); SPI_I2S_SendData(SPI1, COLOR_YELLOW>>8); LCD_RS(1); SPI_I2S_SendData(SPI1, COLOR_YELLOW); } WriteComm(0x36); WriteData(0x28);// } }