- line speed and duplex mode is passed with the link change notification

This commit is contained in:
Wiesner András 2024-05-01 18:59:20 +02:00
parent 2e11cc00e9
commit bb7a8e1f16
2 changed files with 23 additions and 12 deletions

View File

@ -25,8 +25,10 @@ static int ethintf_llrxnotify(EthIODef *io) {
return 0; return 0;
} }
static int ethinf_lllinkchg(EthIODef *io, int ls) { static int ethinf_lllinkchg(EthIODef *io, int ls, uint16_t speed, bool duplex) {
ethinf_push_notification((EthInterface *)io->tag, ETH_IIE_LINK_CHG_NOTIFY, (uint16_t)ls); // TAG: speed [11:2] | duplex [1] | ls [0]
uint16_t tag = ((speed & 0x3FF) << 2) | ((duplex & 0b1) << 1) | (ls & 0b1);
ethinf_push_notification((EthInterface *)io->tag, ETH_IIE_LINK_CHG_NOTIFY, tag);
return 0; return 0;
} }
@ -105,7 +107,10 @@ static ThreadReturnType task_ethintf(ThreadParamType param) {
} break; } break;
case ETH_IIE_LINK_CHG_NOTIFY: { case ETH_IIE_LINK_CHG_NOTIFY: {
bool ls = event_data; bool ls = event_data & 0b1;
bool duplex = (event_data >> 1) & 0b1;
uint16_t speed = (event_data >> 2);
bool prev_ls = ethinf_get_link_state(intf); // get previous link state bool prev_ls = ethinf_get_link_state(intf); // get previous link state
ethinf_set_link_state(intf, ls); // set new link state ethinf_set_link_state(intf, ls); // set new link state
@ -117,7 +122,13 @@ static ThreadReturnType task_ethintf(ThreadParamType param) {
} }
} }
MSG("ETH LINK: %s%s\n", (ls ? (ANSI_COLOR_BGREEN "UP") : (ANSI_COLOR_BRED "DOWN")), ANSI_COLOR_RESET); // print generic message
MSG("ETH LINK: %s%s", (ls ? (ANSI_COLOR_BGREEN "UP ") : (ANSI_COLOR_BRED "DOWN\n")), ANSI_COLOR_RESET);
// print link properties
if (ls) {
MSG("(%u Mbps, %s duplex)\n", speed, duplex ? "FULL" : "HALF");
}
} break; } break;
case ETH_IIE_TRANSMIT_NOTIFY: { case ETH_IIE_TRANSMIT_NOTIFY: {
intf->ioDef->llTxTrigger(intf->ioDef, intf->txQ); intf->ioDef->llTxTrigger(intf->ioDef, intf->txQ);

View File

@ -19,14 +19,14 @@
* Ethernet interface low level definition. * Ethernet interface low level definition.
*/ */
typedef struct EthIODef_ { typedef struct EthIODef_ {
int (*llTxTrigger)(struct EthIODef_ *io, MsgQueue *mq); ///< Function pointer to low-level transmit function trigger int (*llTxTrigger)(struct EthIODef_ *io, MsgQueue *mq); ///< Function pointer to low-level transmit function trigger
int (*llTxDone)(struct EthIODef_ *io, const RawPckt *rawPckt); ///< Transmission done (interrupt) callback int (*llTxDone)(struct EthIODef_ *io, const RawPckt *rawPckt); ///< Transmission done (interrupt) callback
int (*llLinkChg)(struct EthIODef_ *io, int linkState); ///< Link change interrupt int (*llLinkChg)(struct EthIODef_ *io, int linkState, uint16_t speed, bool duplex); ///< Link change interrupt
int (*llRxStore)(struct EthIODef_ *io, const RawPckt *rawPckt); ///< Receive done callback int (*llRxStore)(struct EthIODef_ *io, const RawPckt *rawPckt); ///< Receive done callback
int (*llError)(struct EthIODef_ *io, int error); ///< Low-level error interrupt int (*llError)(struct EthIODef_ *io, int error); ///< Low-level error interrupt
int (*llRxRead)(struct EthIODef_ *io); ///< Read received packets int (*llRxRead)(struct EthIODef_ *io); ///< Read received packets
int (*llRxNotify)(struct EthIODef_ *io); ///< Notify of received packets int (*llRxNotify)(struct EthIODef_ *io); ///< Notify of received packets
void *tag; ///< Some arbitrary tagging void *tag; ///< Some arbitrary tagging
} EthIODef; } EthIODef;