SingingCat 0
application
networkif.h
1#ifndef NETWORKIF_H
2#define NETWORKIF_H 1
3
4#include "main-header.h"
5#include "stdint.h"
6
7// various bits defining the status
8// was it probed?
9#define STATUS_PROBED 0
10// did probe succeed?
11#define STATUS_PROBE_SUCCESS 1
12// was it successfully initialised
13#define STATUS_INITIALISED 2
14// is it ready to transmit? (the device sets and clears this)
15#define STATUS_READY_TO_TRANSMIT 3
16
17// a registered network device
18typedef struct network_context {
19 struct networkif * nif;
20 uint8_t status;
21 uint8_t source;
22 MCULIB_HANDLE mculib_handle;
24
25// an instance of a network device
26typedef struct networkif {
27 int (*probe)(struct network_context *nc); // return 0 if device exists
28 int (*init)(struct network_context *nc); // return 0 if device was initialised
29 int (*loop)(struct network_context *nc); // return 0
30 int (*transmit)(struct network_context *nc, const uint8_t *buf, uint16_t size); // return 0 if data was transmitted
31 int (*stop)(struct network_context *nc);
32 void (*info)(struct network_context *nc); // print info
33 int (*busy)(struct network_context *nc); // returns != 0 if device is currently busy sending stuff
35
36
37
38void init_nic_registry();
39void register_nic(struct networkif *nif, int SOURCE);
40void init_all_nics();
41void print_all_nics();
42void process_nic_event_loop();
43int stop_nic_by_type(int source);
44int start_nic_by_type(int source);
45int isready_by_type(int source); // is this device ready to transmit (generally. it might still be busy)
46int isonline_by_type(int source); // is this device ready to transmit or expected to be able to transmit shortly?
47void nic_set_transmit_status(struct network_context *nctx, int status);
48int nic_is_busy(int source); // calls nic->busy()
49struct network_context *nic_by_type(int source);
50struct network_context *nic_by_index(int index);
51
52#endif