Contiki 3.x
ethconfig.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include "cfs/cfs.h"
6 
7 static struct {
8  char *screen;
9  uint16_t address;
10  char *driver;
11 } drivers[] = {
12 #ifdef __APPLE2__
13  {"Uthernet", 0xC080, "cs8900a.eth" },
14  {"Uthernet II", 0xC084, "w5100.eth" },
15  {"LANceGS", 0xC080, "lan91c96.eth"}
16 #endif
17 #ifdef __ATARI__
18  {"Dragon Cart", 0xD500, "cs8900a.eth" }
19 #endif
20 #ifdef __CBM__
21  {"RR-Net", 0xDE08, "cs8900a.eth" },
22  {"TFE", 0xDE00, "cs8900a.eth" },
23  {"ETH64", 0xDE00, "lan91c96.eth"}
24 #endif
25 };
26 
27 uint8_t ipcfg[16];
28 
29 /*-----------------------------------------------------------------------------------*/
30 uint8_t
31 choose(uint8_t max)
32 {
33  char val;
34 
35  do {
36  printf("\n?");
37  val = getchar();
38  } while(val < '0' || val > max + '0');
39 
40  putchar('\n');
41  if(val == '0') {
42  exit(0);
43  }
44 
45  return val - '0';
46 }
47 /*-----------------------------------------------------------------------------------*/
48 void
49 main(void)
50 {
51  int f;
52  uint8_t d;
53 
54  f = cfs_open("contiki.cfg", CFS_READ);
55  if(f == -1) {
56  printf("Loading Config - Error\n");
57  return;
58  }
59  cfs_read(f, ipcfg, sizeof(ipcfg));
60  cfs_close(f);
61 
62  for(d = 0; d < sizeof(drivers) / sizeof(drivers[0]); ++d) {
63  printf("%d: %s\n", d + 1, drivers[d].screen);
64  }
65  d = choose(d) - 1;
66 
67 #ifdef __APPLE2__
68  printf("\nSlot (1-7)\n");
69  drivers[d].address += choose(7) * 0x10;
70 #endif
71 
72  f = cfs_open("contiki.cfg", CFS_WRITE);
73  if(f == -1) {
74  printf("\nSaving Config - Error\n");
75  return;
76  }
77  cfs_write(f, ipcfg, sizeof(ipcfg));
78  cfs_write(f, &drivers[d].address, sizeof(drivers[d].address));
79  cfs_write(f, drivers[d].driver, strlen(drivers[d].driver));
80  cfs_close(f);
81 
82  printf("\nSaving Config - Done\n");
83 }
84 /*-----------------------------------------------------------------------------------*/
int cfs_open(const char *name, int flags)
Open a file.
Definition: cfs-coffee.c:996
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
Definition: cfs.h:104
#define CFS_READ
Specify that cfs_open() should open a file for reading.
Definition: cfs.h:90
int main(void)
This is main...
Definition: ethconfig.c:49
void cfs_close(int fd)
Close an open file.
Definition: cfs-coffee.c:1032
CFS header file.