Ejemplo n.º 1
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
static void rt_thread_entry_sd_test( void* parameter )
{
	FRESULT res;
	char tempbuf[64];
	rt_sem_take( &sem_dataflash, RT_TICK_PER_SECOND * FLASH_SEM_DELAY );
	SPI_Configuration();
	res = SD_Init();
	if(0 == res)
		{
		rt_kprintf("\r\n SD CARD INIT OK!");
		memset(tempbuf,0,sizeof(tempbuf));
		SD_GetCID(tempbuf);
		rt_kprintf("\r\n CID=");
		printf_hex_data(tempbuf, 16);
		SD_GetCSD(tempbuf);
		rt_kprintf("\r\n SID=");
		printf_hex_data(tempbuf, 16);
		
		rt_kprintf("\r\n SD 容量=%d",SD_GetCapacity());			
		}
	else
		{
		rt_kprintf("\r\n SD CARD INIT ERR = %d",res);
		}
	if(0 == f_mount(MMC, &fs))
		{
		rt_kprintf("\r\n f_mount SD OK!");
		}
	rt_sem_release(&sem_dataflash);
	while( 1 )
	{
		
		rt_thread_delay( RT_TICK_PER_SECOND / 20 );
	}
}
Ejemplo n.º 2
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03}; 
    uint8_t src_addr[4] = {192, 168,  77,  9};
    uint8_t gw_addr[4]  = {192, 168,  77,  1};
    uint8_t sub_addr[4] = {255, 255, 255,  0};		
    //uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
    uint8_t tmp[8], ret, cid[16];
    int i;
    GPIO_InitTypeDef GPIO_InitDef;  


    /* External Clock */
    CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Clock */
     *(volatile uint32_t *)(0x41001014) = 0x000C0200; // 48MHz
    //*(volatile uint32_t *)(0x41001014) = 0x00050200; // 20MHz, Default
    //*(volatile uint32_t *)(0x41001014) = 0x00040200; // 16MHz
   
    
    /* Set Systme init */
    SystemInit();

    /* UART2 Init */
    S_UART_Init(115200);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    printf(" GetSystemClock : %d (Hz) \r\n", GetSystemClock());  
    setTIC100US((GetSystemClock()/10000));
    printf(" val: %X, getTIC100US: %X, (%X) \r\n", GetSystemClock(), getTIC100US(), *(uint32_t *)WZTOE_TIC100US);        


#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif	
    printf("PHY is linked. \r\n"); 
#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
    delay(1000);
#endif
    
    GPIO_InitDef.GPIO_Pin = (GPIO_Pin_1 | GPIO_Pin_2);
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_Init(GPIOA, &GPIO_InitDef);
    PAD_AFConfig(PAD_PA, (GPIO_Pin_1 | GPIO_Pin_2), PAD_AF1);  

    for(i=0; i<4; i++)
    {
        // LED ON
        GPIO_ResetBits(GPIOA, (GPIO_Pin_1 | GPIO_Pin_2)) ;
        delay(200);	
        // LED OFF
        GPIO_SetBits(GPIOA, (GPIO_Pin_1 | GPIO_Pin_2)) ;        
        delay(200);		
    }

    printf("[DEBUG] SD Card	Test\r\n");
    bsp_sd_gpio_init();
    ret = SD_Init();

    switch(SD_Type)
    {
        case SD_TYPE_MMC: printf("[DEBUG] init ret : %d , SD Card Type : MMC\r\n", ret); 	break;
        case SD_TYPE_V1: printf("[DEBUG] init ret : %d , SD Card Type : SD\r\n", ret); 	break;
        case SD_TYPE_V2: printf("[DEBUG] init ret : %d , SD Card Type : SD2\r\n", ret); 	break;
        case SD_TYPE_V2HC: printf("[DEBUG] init ret : %d , SD Card Type : SDHC\r\n", ret); 	break;
        default: printf("[DEBUG] init ret : %d , SD Card Type : %d\r\n", ret, SD_Type); 	break;
    }

    memset(&cid[0], 0x00, 16);
    ret = SD_GetCID(cid);
    if( (cid[0]==0x00) && (cid[1]==0x00) && (cid[2]==0x00) && (cid[3]==0x00) &&
          (cid[4]==0x00) && (cid[5]==0x00) && (cid[6]==0x00) && (cid[7]==0x00) &&
            (cid[8]==0x00) && (cid[9]==0x00) && (cid[10]==0x00) && (cid[11]==0x00) &&
            (cid[12]==0x00) && (cid[13]==0x00) && (cid[14]==0x00) && (cid[15]==0x00)
    )
    {
        // Turn on LED 1
        printf("SD Test Fail!!\r\n");
        GPIO_ResetBits(GPIOA, GPIO_Pin_1);
    }
    else
    {
        // Turn on LED 1 & LED 2
        printf("SD Test O.K!!!r\n");
        GPIO_ResetBits(GPIOA, (GPIO_Pin_1|GPIO_Pin_2) );
    }
    //printf("[DEBUG] state : %d\r\n", state);
    printf("[DEBUG] CID / MID : 0x%.2X\r\n", cid[0]);
    printf("[DEBUG] CID / OID : %c%c\r\n", cid[1], cid[2]);
    printf("[DEBUG] CID / PNM : %c%c%c%c%c\r\n", cid[3], cid[4], cid[5], cid[6], cid[7]);
    
    
    /* Network Configuration */
    setSHAR(mac_addr);
    getSHAR(tmp);
    printf(" MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); 
    
    setSIPR(src_addr);
    getSIPR(tmp);
    printf("IP ADDRESS : %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    
    setGAR(gw_addr);
    getGAR(tmp);
    printf("GW ADDRESS : %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 

    setSUBR(sub_addr);
    getSUBR(tmp);
    printf("SN MASK: %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 

    while(1)
    {
        loopback_tcps(0, test_buf, 5000);
    }

}