<commit_before>#include "mod_uIP.h"
#if UIP_CORE_APP_DHCP
#include "dhcpc.h"
#endif

clocker  uIP_Clocker;

timer   uIP_periodic_timer;
timer   uIP_arp_timer;
uIP_App *uIP_app_list;
u8_t    *uip_buf;
    
static void uIP_dev_send(mETH_t *eth);
static void uIP_dev_read(mETH_t *eth);
static MadBool uIP_preinit(mETH_t *eth);
static MadBool uIP_handler(mETH_t *eth, MadUint event, MadTim_t dt);

/*****************************************************
 *
 *  uIP-Misc
 *
 *****************************************************/
void uip_log(char *msg)
{  // Required by uip to print log.
    MAD_LOG("%s\n", msg);
}

void tcpip_output(void)
{   // Required by uip-split.c using for multiple network interface.
    // We have NOT used it yet.
    // Some say it equal to uip_fw_output();
}

/*****************************************************
 *
 *  uIP Core Function
 *
 *****************************************************/
void uIP_Init(void)
{
    mEth_Init(uIP_preinit, uIP_handler);
}

void uIP_AppRegister(uIP_App *app) 
{
    MadCpsr_t cpsr;
    madEnterCritical(cpsr);
    app->next = uIP_app_list;
    uIP_app_list = app;
    madExitCritical(cpsr);
}

void uIP_AppUnregister(uIP_App *app)
{
    MadCpsr_t cpsr;
    madEnterCritical(cpsr);
    uIP_App *pre_app = 0;
    uIP_App *cur_app = uIP_app_list;
    while(cur_app) {
        if(app == cur_app) {
            if(pre_app) pre_app->next = cur_app->next;
            else        uIP_app_list  = cur_app->next;
            break;
        }
        pre_app = cur_app;
        cur_app = cur_app->next;
    }
    madExitCritical(cpsr);
}

void uIP_SetTcpConn(struct uip_conn *conn, uIP_Callback app_call)
{
    conn->appstate.app_call = app_call;
}

void uIP_SetUdpConn(struct uip_udp_conn *conn, uIP_Callback app_call)
{
    conn->appstate.app_call = app_call;
}

/*****************************************************
 *
 *  uIP Core Apps Callback
 *
 *****************************************************/
#if UIP_CORE_APP_DHCP
void dhcpc_configured(const struct dhcpc_state *s)
{
    uip_sethostaddr(s->ipaddr);
    uip_setdraddr(s->default_router);
    uip_setnetmask(s->netmask);
}
#endif

/*****************************************************
 *
 *  uIP Core Callback
 *
 *****************************************************/
#define APPLIST_LOOP(x) \
do {                                    \
    uIP_App *app_list = uIP_app_list;   \
    while(app_list) {                   \
        if(app_list->link_changed)      \
            app_list->link_changed(x);  \
        app_list = app_list->next;      \
    }                                   \
} while(0)

#define APPCONN_CALL(x) \
do {                                        \
    if(x && x->appstate.app_call)           \
        x->appstate.app_call((MadVptr)0);   \
} while(0)

void uIP_linked_on(void)   { APPLIST_LOOP((MadVptr)uIP_LINKED_ON); }
void uIP_linked_off(void)  { APPLIST_LOOP((MadVptr)uIP_LINKED_OFF); }
void uIP_tcp_appcall(void) { APPCONN_CALL(uip_conn); }
void uIP_udp_appcall(void) { APPCONN_CALL(uip_udp_conn); }

/*****************************************************
 *
 *  uIP-Core
 *
 *****************************************************/
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])

void uIP_dev_send(mETH_t *eth)
{
    if(eth->isLinked)
        ETH_HandleTxPkt(uip_buf, uip_len);
}

void uIP_dev_read(mETH_t *eth)
{
    uip_len = ETH_HandleRxPkt(uip_buf);
#if ETH_SOFT_FLOW_CONTROL
    do {
        MadCpsr_t cpsr;
        madEnterCritical(cpsr);<commit_msg>MadOS v2.30RC1<commit_after>#include "mod_uIP.h"
#if UIP_CORE_APP_DHCP
#include "dhcpc.h"
#endif

clocker  uIP_Clocker;

timer   uIP_periodic_timer;
timer   uIP_arp_timer;
uIP_App *uIP_app_list;
u8_t    *uip_buf;
    
static void uIP_dev_send(mETH_t *eth);
static void uIP_dev_read(mETH_t *eth);
static MadBool uIP_preinit(mETH_t *eth);
static MadBool uIP_handler(mETH_t *eth, MadUint event, MadTim_t dt);

/*****************************************************
 *
 *  uIP-Misc
 *
 *****************************************************/
void uip_log(char *msg)
{  // Required by uip to print log.
    MAD_LOG("%s\n", msg);
}

void tcpip_output(void)
{   // Required by uip-split.c using for multiple network interface.
    // We have NOT used it yet.
    // Some say it equal to uip_fw_output();
}

/*****************************************************
 *
 *  uIP Core Function
 *
 *****************************************************/
void uIP_Init(void)
{
    mEth_Init(uIP_preinit, uIP_handler);
}

void uIP_AppRegister(uIP_App *app) 
{
    MadCpsr_t cpsr;
    madEnterCritical(cpsr);
    app->next = uIP_app_list;
    uIP_app_list = app;
    madExitCritical(cpsr);
}

void uIP_AppUnregister(uIP_App *app)
{
    MadCpsr_t cpsr;
    madEnterCritical(cpsr);
    uIP_App *pre_app = 0;
    uIP_App *cur_app = uIP_app_list;
    while(cur_app) {
        if(app == cur_app) {
            if(pre_app) pre_app->next = cur_app->next;
            else        uIP_app_list  = cur_app->next;
            break;
        }
        pre_app = cur_app;
        cur_app = cur_app->next;
    }
    madExitCritical(cpsr);
}

void uIP_SetTcpConn(struct uip_conn *conn, uIP_Callback app_call)
{
    conn->appstate.app_call = app_call;
}

void uIP_SetUdpConn(struct uip_udp_conn *conn, uIP_Callback app_call)
{
    conn->appstate.app_call = app_call;
}

/*****************************************************
 *
 *  uIP Core Apps Callback
 *
 *****************************************************/
#if UIP_CORE_APP_DHCP
void dhcpc_configured(const struct dhcpc_state *s)
{
    uip_sethostaddr(s->ipaddr);
    uip_setdraddr(s->default_router);
    uip_setnetmask(s->netmask);
}
#endif

/*****************************************************
 *
 *  uIP Core Callback
 *
 *****************************************************/
#define APPLIST_LOOP(x) \
do {                                    \
    uIP_App *app_list = uIP_app_list;   \
    while(app_list) {                   \
        if(app_list->link_changed)      \
            app_list->link_changed(x);  \
        app_list = app_list->next;      \
    }                                   \
} while(0)

#define APPCONN_CALL(x) \
do {                                        \
    if(x && x->appstate.app_call)           \
        x->appstate.app_call((MadVptr)x);   \
} while(0)

void uIP_linked_on(void)   { APPLIST_LOOP((MadVptr)uIP_LINKED_ON); }
void uIP_linked_off(void)  { APPLIST_LOOP((MadVptr)uIP_LINKED_OFF); }
void uIP_tcp_appcall(void) { APPCONN_CALL(uip_conn); }
void uIP_udp_appcall(void) { APPCONN_CALL(uip_udp_conn); }

/*****************************************************
 *
 *  uIP-Core
 *
 *****************************************************/
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])

void uIP_dev_send(mETH_t *eth)
{
    if(eth->isLinked)
        ETH_HandleTxPkt(uip_buf, uip_len);
}

void uIP_dev_read(mETH_t *eth)
{
    uip_len = ETH_HandleRxPkt(uip_buf);
#if ETH_SOFT_FLOW_CONTROL
    do {
        MadCpsr_t cpsr;
        madEnterCritical(cpsr);
{'fraction_non_alphanumeric': 0.24918079498504062, 'fraction_numerical': 0.0021370565607636417, 'mean_word_length': 3.2883323152107513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5517795', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2575, 'n_words': 408}