Ignore:
Timestamp:
Feb 4, 2025, 11:33:27 AM (3 months ago)
Author:
Zed
Message:

Fixing project to enable DMA for SPI2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/SES/Core/Src/main_task.cpp

    r77 r78  
    1010#include "utils.h"
    1111
     12#include "wizchip_conf.h"
    1213#include "dhcp.h"
    1314
     15static constexpr unsigned ETH_MAX_BUF_SIZE = 2048U;
     16static constexpr unsigned SOCKET_DHCP = 1;
    1417
    1518static const char* const TAG = "MAIN";
     
    2225
    2326static FATFS fs;// __attribute__((section(".DTCM_RAM")));     // Filesystem object
    24 static uint8_t dhcp_buffer[256];
     27static uint8_t dhcp_buffer[ETH_MAX_BUF_SIZE];
     28
     29wiz_NetInfo gWIZNETINFO = {
     30                .mac = {0x00, 0x08, 0xdc, 0x6f, 0x00, 0x8a},
     31                .ip = {192, 168, 11, 109},
     32                .sn = {255, 255, 255, 0},
     33                .gw = {192, 168, 11, 1},
     34                .dns = {8, 8, 8, 8},
     35                .dhcp = NETINFO_DHCP
     36};
     37
    2538
    2639FRESULT scan_files (TCHAR* path);
    2740FRESULT list_dir (const char* path);
    2841
     42static void ip_assigned(void);
     43static void ip_updated(void);
     44static void ip_conflict(void);
     45static void wizchip_initialize(void);
     46static void wizchip_reset(void);
     47static void wizchip_check(void);
     48static void wizchip_dhcp_init(void);
     49
    2950//------------------------------------------------------------------------------
    3051
     
    3354        (void)argument;
    3455
     56        wizchip_initialize();
     57
     58        if (gWIZNETINFO.dhcp == NETINFO_DHCP) // DHCP
     59        {
     60                wizchip_dhcp_init();
     61
     62                while (DHCP_run() != DHCP_IP_LEASED)
     63              wiz_delay_ms(1000);
     64        }
     65        else // static
     66        {
     67                ctlnetwork(CN_SET_NETINFO, &gWIZNETINFO);
     68                printf("\r\n----------STATIC Net Information--------------\r\n");
     69                //print_network_information();
     70        }
     71
     72        //DHCP_init(0, dhcp_buffer);
     73        //reg_dhcp_cbfunc(ip_assigned, ip_updated, ip_conflict);
     74
     75        //MX_LWIP_Init();
     76
     77    FRESULT  r = f_mount(&fs, (const TCHAR*)"", 1);            // Mount the default drive
     78        if (r != FR_OK) printf("Cannot mount SD-card!\n");
     79        else
     80        {
     81                printf("SD-card was mounted.\n");
     82
     83                static TCHAR buff[256];
     84                strcpy (buff, "/");
     85                list_dir(buff);
     86        }
     87
     88        while(1)
     89        {
     90                vTaskDelay(pdMS_TO_TICKS(delay_ms));
     91
     92                //DHCP_run();
     93                //printThreadStackInfo(TAG);
     94        }
     95}
     96
     97//------------------------------------------------------------------------------
     98
     99void wizchip_reset(void)
     100{
    35101        HAL_GPIO_WritePin(ETH_SPI_PWR_GPIO_Port, ETH_SPI_PWR_Pin, GPIO_PIN_RESET);
    36102        vTaskDelay(pdMS_TO_TICKS(100U));
    37103        HAL_GPIO_WritePin(ETH_SPI_RST_GPIO_Port, ETH_SPI_RST_Pin, GPIO_PIN_SET);
    38104        vTaskDelay(pdMS_TO_TICKS(65U));   // Min 60.3ms
    39 
    40         DHCP_init(0, dhcp_buffer);
    41 
    42         //MX_LWIP_Init();
    43 
    44     FRESULT  r = f_mount(&fs, (const TCHAR*)"", 1);            // Mount the default drive
    45         if (r != FR_OK) printf("Cannot mount SD-card!\n");
    46         else
    47         {
    48                 printf("SD-card was mounted.\n");
    49 
    50                 static TCHAR buff[256];
    51                 strcpy (buff, "/");
    52                 list_dir(buff);
    53         }
     105}
     106
     107//------------------------------------------------------------------------------
     108
     109void wizchip_initialize(void)
     110{
     111        uint8_t W5100S_AdrSet[2][4]= {{2,2,2,2},{2,2,2,2}};
     112    uint8_t tmp1, tmp2;
     113        intr_kind temp= IK_DEST_UNREACH;
     114
     115        wizchip_reset();
     116
     117        if (ctlwizchip(CW_INIT_WIZCHIP, (void*)W5100S_AdrSet) == -1)
     118                printf(">>>>W5100s memory initialization failed\r\n");
     119
     120        if(ctlwizchip(CW_SET_INTRMASK,&temp) == -1)
     121                printf("W5100S interrupt\r\n");
     122
     123        wizchip_check();
    54124
    55125        while(1)
    56126        {
    57                 vTaskDelay(pdMS_TO_TICKS(delay_ms));
    58 
    59                 //printThreadStackInfo(TAG);
    60         }
     127                ctlwizchip(CW_GET_PHYLINK, &tmp1 );
     128                ctlwizchip(CW_GET_PHYLINK, &tmp2 );
     129                if (tmp1 == PHY_LINK_ON && tmp2 == PHY_LINK_ON) break;
     130        }
     131}
     132
     133//------------------------------------------------------------------------------
     134
     135static void ip_assigned(void)
     136{
     137        printf("IP-address was assigned.\n");
     138
     139        uint8_t ip[4];
     140        getIPfromDHCP(ip);
     141        printf("IP-address: %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
     142
     143        uint8_t nm[4];
     144        getSNfromDHCP(nm);
     145        printf("Subnet mask: %u.%u.%u.%u\n", nm[0], nm[1], nm[2], nm[3]);
     146
     147        uint8_t gw[4];
     148        getGWfromDHCP(gw);
     149        printf("Gateway address: %u.%u.%u.%u\n", gw[0], gw[1], gw[2], gw[3]);
     150
     151        uint8_t dns[4];
     152        getDNSfromDHCP(dns);
     153        printf("DNS address: %u.%u.%u.%u\n", dns[0], dns[1], dns[2], dns[3]);
     154
     155        printf("Lease time: %u\n", getDHCPLeasetime());
     156}
     157
     158//------------------------------------------------------------------------------
     159
     160static void ip_updated(void)
     161{
     162        printf("IP-address was updated.\n");
     163}
     164
     165//------------------------------------------------------------------------------
     166
     167static void ip_conflict(void)
     168{
     169        printf("IP-address conflict!.\n");
     170}
     171
     172//------------------------------------------------------------------------------
     173
     174void wizchip_check(void)
     175{
     176        // Read version register
     177    if (getVER() != 0x51) // W5100S
     178    {
     179        printf(" ACCESS ERR : VERSIONR != 0x51, read value = 0x%02x\n", getVER());
     180        while (1);
     181    }
     182}
     183
     184//------------------------------------------------------------------------------
     185
     186void wizchip_dhcp_init(void)
     187{
     188    DHCP_init(SOCKET_DHCP, dhcp_buffer);
     189    reg_dhcp_cbfunc(ip_assigned, ip_updated, ip_conflict);
    61190}
    62191
Note: See TracChangeset for help on using the changeset viewer.