@@ -837,19 +837,21 @@ struct timeval {
837
837
#define MG_ENABLE_TCPIP_DRIVER_INIT 1 // enabled built-in driver for
838
838
#endif // Mongoose built-in network stack
839
839
840
- #ifndef MG_TCPIP_IP // e.g. MG_IPV4(192, 168, 0, 223)
841
- #define MG_TCPIP_IP MG_IPV4 (0 , 0 , 0 , 0 ) // or leave as 0 for DHCP
840
+ #ifndef MG_TCPIP_IP // e.g. MG_IPV4(192, 168, 0, 223)
841
+ #define MG_TCPIP_IP MG_IPV4 (0 , 0 , 0 , 0 ) // Default is 0.0.0.0 ( DHCP)
842
842
#endif
843
843
844
844
#ifndef MG_TCPIP_MASK
845
- #define MG_TCPIP_MASK MG_IPV4 (255 , 255 , 255 , 0 )
845
+ #define MG_TCPIP_MASK MG_IPV4 (0 , 0 , 0 , 0 ) // Default is 0.0.0.0 (DHCP )
846
846
#endif
847
847
848
848
#ifndef MG_TCPIP_GW
849
- #define MG_TCPIP_GW MG_IPV4 (0 , 0 , 0 , 1 )
849
+ #define MG_TCPIP_GW MG_IPV4 (0 , 0 , 0 , 0 ) // Default is 0.0.0.0 (DHCP )
850
850
#endif
851
851
852
- #define MG_MAC_ADDRESS_RANDOM { 0 , 0 , 0 , 0 , 0 , 0 }
852
+ #ifndef MG_SET_MAC_ADDRESS
853
+ #define MG_SET_MAC_ADDRESS (mac )
854
+ #endif
853
855
854
856
#ifndef MG_ENABLE_TCPIP_PRINT_DEBUG_STATS
855
857
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
@@ -2882,15 +2884,6 @@ struct mg_profitem {
2882
2884
#include " Driver_ETH_MAC.h" // keep this include
2883
2885
#include " Driver_ETH_PHY.h" // keep this include
2884
2886
2885
- #ifndef MG_MAC_ADDRESS
2886
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
2887
- #endif
2888
-
2889
- #define MG_TCPIP_DRIVER_DATA int driver_data;
2890
-
2891
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_cmsis
2892
- #define MG_TCPIP_DRIVER_NAME " cmsis"
2893
-
2894
2887
#endif
2895
2888
2896
2889
@@ -2913,10 +2906,6 @@ struct mg_tcpip_driver_imxrt_data {
2913
2906
uint8_t phy_addr; // PHY address
2914
2907
};
2915
2908
2916
- #ifndef MG_MAC_ADDRESS
2917
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
2918
- #endif
2919
-
2920
2909
#ifndef MG_TCPIP_PHY_ADDR
2921
2910
#define MG_TCPIP_PHY_ADDR 2
2922
2911
#endif
@@ -2925,15 +2914,6 @@ struct mg_tcpip_driver_imxrt_data {
2925
2914
#define MG_DRIVER_MDC_CR 24
2926
2915
#endif
2927
2916
2928
- #define MG_TCPIP_DRIVER_DATA \
2929
- static struct mg_tcpip_driver_imxrt_data driver_data = { \
2930
- .mdc_cr = MG_DRIVER_MDC_CR, \
2931
- .phy_addr = MG_TCPIP_PHY_ADDR, \
2932
- };
2933
-
2934
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_imxrt
2935
- #define MG_TCPIP_DRIVER_NAME " imxrt"
2936
-
2937
2917
#endif
2938
2918
2939
2919
@@ -2968,35 +2948,6 @@ struct mg_tcpip_driver_ra_data {
2968
2948
uint8_t phy_addr; // PHY address
2969
2949
};
2970
2950
2971
- #undef MG_ENABLE_TCPIP_DRIVER_INIT
2972
- #define MG_ENABLE_TCPIP_DRIVER_INIT 0 // TODO(): needs SystemCoreClock
2973
- #if 0
2974
- #ifndef MG_MAC_ADDRESS
2975
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
2976
- #endif
2977
-
2978
- #ifndef MG_TCPIP_PHY_ADDR
2979
- #define MG_TCPIP_PHY_ADDR 1
2980
- #endif
2981
-
2982
- #ifndef MG_DRIVER_RA_CLOCK
2983
- #define MG_DRIVER_RA_CLOCK
2984
- #endif
2985
-
2986
- #ifndef MG_DRIVER_RA_IRQNO
2987
- #define MG_DRIVER_RA_IRQNO 0
2988
- #endif
2989
-
2990
- #define MG_TCPIP_DRIVER_DATA \
2991
- static struct mg_tcpip_driver_ra_data driver_data = { \
2992
- .clock = MG_DRIVER_RA_CLOCK, \
2993
- .irqno = MG_DRIVER_RA_CLOCK, \
2994
- .phy_addr = MG_TCPIP_PHY_ADDR, \
2995
- };
2996
-
2997
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_ra
2998
- #define MG_TCPIP_DRIVER_NAME "ra"
2999
- #endif
3000
2951
#endif
3001
2952
3002
2953
@@ -3006,22 +2957,10 @@ struct mg_tcpip_driver_same54_data {
3006
2957
int mdc_cr;
3007
2958
};
3008
2959
3009
- #ifndef MG_MAC_ADDRESS
3010
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
3011
- #endif
3012
-
3013
2960
#ifndef MG_DRIVER_MDC_CR
3014
2961
#define MG_DRIVER_MDC_CR 5
3015
2962
#endif
3016
2963
3017
- #define MG_TCPIP_DRIVER_DATA \
3018
- static struct mg_tcpip_driver_same54_data driver_data = { \
3019
- .mdc_cr = MG_DRIVER_MDC_CR, \
3020
- };
3021
-
3022
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_same54
3023
- #define MG_TCPIP_DRIVER_NAME " same54"
3024
-
3025
2964
#endif
3026
2965
3027
2966
@@ -3045,10 +2984,6 @@ struct mg_tcpip_driver_stm32f_data {
3045
2984
uint8_t phy_addr; // PHY address
3046
2985
};
3047
2986
3048
- #ifndef MG_MAC_ADDRESS
3049
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
3050
- #endif
3051
-
3052
2987
#ifndef MG_TCPIP_PHY_ADDR
3053
2988
#define MG_TCPIP_PHY_ADDR 0
3054
2989
#endif
@@ -3057,14 +2992,21 @@ struct mg_tcpip_driver_stm32f_data {
3057
2992
#define MG_DRIVER_MDC_CR 4
3058
2993
#endif
3059
2994
3060
- #define MG_TCPIP_DRIVER_DATA \
3061
- static struct mg_tcpip_driver_stm32f_data driver_data = { \
3062
- .mdc_cr = MG_DRIVER_MDC_CR, \
3063
- .phy_addr = MG_TCPIP_PHY_ADDR, \
3064
- };
3065
-
3066
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_stm32f
3067
- #define MG_TCPIP_DRIVER_NAME " stm32f"
2995
+ #define MG_TCPIP_DRIVER_INIT (mgr ) \
2996
+ do { \
2997
+ static struct mg_tcpip_driver_stm32f_data driver_data_; \
2998
+ static struct mg_tcpip_if mif_; \
2999
+ driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \
3000
+ driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \
3001
+ mif_.ip = MG_TCPIP_IP; \
3002
+ mif_.mask = MG_TCPIP_MASK; \
3003
+ mif_.gw = MG_TCPIP_GW; \
3004
+ mif_.driver = &mg_tcpip_driver_stm32f; \
3005
+ mif_.driver_data = &driver_data_; \
3006
+ MG_SET_MAC_ADDRESS (mif_.mac ); \
3007
+ mg_tcpip_init (mgr, &mif_); \
3008
+ MG_INFO ((" Driver: stm32f, MAC: %M" , mg_print_mac, mif_.mac )); \
3009
+ } while (0 )
3068
3010
3069
3011
#endif
3070
3012
@@ -3081,19 +3023,15 @@ struct mg_tcpip_driver_stm32h_data {
3081
3023
// 100-150 MHz HCLK/62 1
3082
3024
// 20-35 MHz HCLK/16 2
3083
3025
// 35-60 MHz HCLK/26 3
3084
- // 150-250 MHz HCLK/102 4 <-- value for Nucleo-H* on max speed
3085
- // driven by HSI 250-300 MHz HCLK/124 5 <-- value for Nucleo-H* on
3086
- // max speed driven by CSI 110, 111 Reserved
3026
+ // 150-250 MHz HCLK/102 4 <-- value for max speed HSI
3027
+ // 250-300 MHz HCLK/124 5 <-- value for Nucleo-H* on CSI
3028
+ // 110, 111 Reserved
3087
3029
int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
3088
3030
3089
3031
uint8_t phy_addr; // PHY address
3090
3032
uint8_t phy_conf; // PHY config
3091
3033
};
3092
3034
3093
- #ifndef MG_MAC_ADDRESS
3094
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
3095
- #endif
3096
-
3097
3035
#ifndef MG_TCPIP_PHY_ADDR
3098
3036
#define MG_TCPIP_PHY_ADDR 0
3099
3037
#endif
@@ -3102,14 +3040,21 @@ struct mg_tcpip_driver_stm32h_data {
3102
3040
#define MG_DRIVER_MDC_CR 4
3103
3041
#endif
3104
3042
3105
- #define MG_TCPIP_DRIVER_DATA \
3106
- static struct mg_tcpip_driver_stm32h_data driver_data = { \
3107
- .mdc_cr = MG_DRIVER_MDC_CR, \
3108
- .phy_addr = MG_TCPIP_PHY_ADDR, \
3109
- };
3110
-
3111
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_stm32h
3112
- #define MG_TCPIP_DRIVER_NAME " stm32h"
3043
+ #define MG_TCPIP_DRIVER_INIT (mgr ) \
3044
+ do { \
3045
+ static struct mg_tcpip_driver_stm32h_data driver_data_; \
3046
+ static struct mg_tcpip_if mif_; \
3047
+ driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \
3048
+ driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \
3049
+ mif_.ip = MG_TCPIP_IP; \
3050
+ mif_.mask = MG_TCPIP_MASK; \
3051
+ mif_.gw = MG_TCPIP_GW; \
3052
+ mif_.driver = &mg_tcpip_driver_stm32h; \
3053
+ mif_.driver_data = &driver_data_; \
3054
+ MG_SET_MAC_ADDRESS (mif_.mac ); \
3055
+ mg_tcpip_init (mgr, &mif_); \
3056
+ MG_INFO ((" Driver: stm32h, MAC: %M" , mg_print_mac, mif_.mac )); \
3057
+ } while (0 )
3113
3058
3114
3059
#endif
3115
3060
@@ -3129,31 +3074,10 @@ struct mg_tcpip_driver_tm4c_data {
3129
3074
int mdc_cr; // Valid values: -1, 0, 1, 2, 3
3130
3075
};
3131
3076
3132
- #ifndef MG_MAC_ADDRESS
3133
- #define MG_MAC_ADDRESS MG_MAC_ADDRESS_RANDOM
3134
- #endif
3135
-
3136
3077
#ifndef MG_DRIVER_MDC_CR
3137
3078
#define MG_DRIVER_MDC_CR 1
3138
3079
#endif
3139
3080
3140
- #define MG_TCPIP_DRIVER_DATA \
3141
- static struct mg_tcpip_driver_tm4c_data driver_data = { \
3142
- .mdc_cr = MG_DRIVER_MDC_CR, \
3143
- };
3144
-
3145
- #define MG_TCPIP_DRIVER_CODE &mg_tcpip_driver_tm4c
3146
- #define MG_TCPIP_DRIVER_NAME " tm4c"
3147
-
3148
-
3149
- #endif
3150
-
3151
-
3152
- #if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_W5500) && MG_ENABLE_DRIVER_W5500
3153
-
3154
- #undef MG_ENABLE_TCPIP_DRIVER_INIT
3155
- #define MG_ENABLE_TCPIP_DRIVER_INIT 0
3156
-
3157
3081
#endif
3158
3082
3159
3083
#ifdef __cplusplus
0 commit comments