- Ethernet Emulation Model (EEM) basics added

This commit is contained in:
Wiesner András 2024-04-27 22:11:59 +02:00
parent c9d8a42872
commit 53226e79cb
3 changed files with 68 additions and 0 deletions

View File

@ -4,6 +4,9 @@ target_sources(
class/cdc.c
class/cdc.h
class/eem.c
class/eem.h
CMakeLists.txt
desc/usb_desc.c

39
class/eem.c Normal file
View File

@ -0,0 +1,39 @@
#include "eem.h"
#include <memory.h>
#include "../usb.h"
static USB_EemState eems = {0};
void usb_eem_init(uint8_t data_ep) {
// clear the state
memset(&eems, 0, sizeof(USB_EemState));
// store data endpoint number
eems.data_ep = data_ep;
// EEM is operational
eems.initialized = true;
}
int usb_eem_process_and_return(USB_CallbackEvent *cbevt) {
switch (cbevt->type) {
case USB_CBEVT_UNKNOWN_REQ:
break;
case USB_CBEVT_OUT:
break;
case USB_CBEVT_IN:
if (cbevt->ep == eems.data_ep) { // verify endpoint number
usbcore_write(eems.data_ep, NULL, 0); // send ZLP
}
break;
default:
break;
}
return 0;
}

26
class/eem.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef CLASS_EEM
#define CLASS_EEM
#include <stdint.h>
#include "../usb_callback_event.h"
typedef struct {
uint8_t data_ep; // bulk data in and out endpoint pair
bool initialized; // EEM is initialized
} USB_EemState;
/**
* Initialize USB EEM module.
* @param data_ep data endpoint number
*/
void usb_eem_init(uint8_t data_ep);
/**
* Callback function for data reception and transmission.
* @param cbevt pointer to callback event structure
* @return function returns how to proceed with packet processing
*/
int usb_eem_process_and_return(USB_CallbackEvent * cbevt);
#endif /* CLASS_EEM */