Subversion Repositories freemyipod

Rev

Rev 784 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 784 Rev 898
Line 1... Line 1...
1
//
1
//
2
//
2
//
3
//    Copyright 2011 user890104
3
//    Copyright 2013 user890104
4
//
4
//
5
//
5
//
6
//    This file is part of emCORE.
6
//    This file is part of emCORE.
7
//
7
//
8
//    emCORE is free software: you can redistribute it and/or
8
//    emCORE is free software: you can redistribute it and/or
Line 18... Line 18...
18
//    You should have received a copy of the GNU General Public License along
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
20
//
21
//
21
//
22
 
22
 
23
 
-
 
24
#include "global.h"
23
#include "global.h"
25
 
24
 
26
#include "usb.h"
25
#include "usb.h"
27
#include "cache.h"
26
#include "cache.h"
28
#include "emcore.h"
27
#include "emcore.h"
29
#include "fuse.h"
28
#include "fuse.h"
30
#include "util.h"
29
#include "util.h"
31
#include "emcorefs.h"
-
 
32
 
30
 
-
 
31
int main() {
-
 
32
    int32_t res, res2;
-
 
33
    uint8_t reattach = 0;
-
 
34
 
-
 
35
    /* emcore_get_version */
-
 
36
    struct emcore_dev_info dev_info;
33
 
37
 
34
struct fuse_operations emcorefs_oper =
-
 
35
{
-
 
36
    .getattr    = emcorefs_getattr,
-
 
37
    
-
 
38
    .opendir    = emcorefs_opendir,
38
    /* emcore_get_malloc_pool_bounds */
39
    .readdir    = emcorefs_readdir,
-
 
40
    .releasedir = emcorefs_releasedir,
39
    struct emcore_malloc_pool_bounds bounds;
41
 
40
 
42
    .open       = emcorefs_open,
-
 
43
    .read       = emcorefs_read,
-
 
44
    .write      = emcorefs_write,
-
 
45
    .release    = emcorefs_release,
41
    /* emcore_readmem */
46
 
42
    /*
47
    .mkdir      = emcorefs_mkdir,
-
 
48
    .rmdir      = emcorefs_rmdir,
43
    void *buf;
49
 
-
 
50
    .create     = emcorefs_create,
44
    uint16_t buf_size;
51
    .mknod      = emcorefs_mknod,
-
 
52
    .unlink     = emcorefs_unlink,
45
    uint32_t read_addr;
53
    .rename     = emcorefs_rename,
46
    */
54
    .truncate   = emcorefs_truncate,
-
 
55
    
47
    
56
    .ftruncate  = emcorefs_ftruncate,
48
    /* emcore_readi2c */
57
};
49
    /* uint8_t i2cdata; */
58
 
50
 
-
 
51
    /* emcore_dir_open */
59
int main(int argc, char* argv[])
52
    //uint32_t dir_handle;
60
{
53
 
61
    int res, res2;
54
    /* emcore_dir_close_all */
62
    uint8_t reattach = 0;
55
    //uint32_t count;
63
 
56
 
64
    res = usb_init();
57
    res = usb_init();
65
 
58
 
66
    if (LIBUSB_SUCCESS == res)
59
    if (res == LIBUSB_SUCCESS) {
67
    {
-
 
68
        res = usb_find(EMCORE_USB_VID, EMCORE_USB_PID, &reattach);
60
        res = usb_find(EMCORE_USB_VID, EMCORE_USB_PID, &reattach);
69
    }
61
    }
70
 
62
 
71
    if (LIBUSB_SUCCESS == res)
63
    if (res == LIBUSB_SUCCESS) {
72
    {
-
 
73
        res = emcorefs_init();
64
        res = emcorefs_init();
74
    }
65
    }
75
 
66
 
76
    if (EMCORE_SUCCESS == res)
-
 
77
    {
67
    do {
78
#ifdef TEST_ONLY
-
 
79
        /* gcc complains about unused vars */
-
 
80
        (void)(argc);
-
 
81
        (void)(argv);
-
 
82
 
-
 
83
        res = emcore_test();
68
        res = emcore_get_version(&dev_info);
84
#else
-
 
85
        cache_init();
-
 
86
 
69
 
-
 
70
        if (res != EMCORE_SUCCESS) {
-
 
71
            break;
-
 
72
        }
-
 
73
 
-
 
74
        printf("Connected to %c%c%c%c running %s v%d.%d.%d r%d\n",
-
 
75
            dev_info.hw_type & 0xFF, (dev_info.hw_type >> 8) & 0xFF, (dev_info.hw_type >> 16) & 0xFF, dev_info.hw_type >> 24,
-
 
76
            (dev_info.sw_type == 2 ? "emCORE" : "UNKNOWN"),
-
 
77
            dev_info.major, dev_info.minor, dev_info.patch, dev_info.svn_revision
-
 
78
        );
-
 
79
        
-
 
80
        res = emcore_get_malloc_pool_bounds(&bounds);
-
 
81
 
-
 
82
        if (res != EMCORE_SUCCESS) {
-
 
83
            break;
-
 
84
        }
-
 
85
 
-
 
86
        printf("Malloc pool bounds: 0x%08x - 0x%08x\n", bounds.lower, bounds.upper);
-
 
87
/*
-
 
88
        read_addr = 0x09000000;
-
 
89
        buf_size = 0x1000;
-
 
90
        buf = malloc(buf_size);
-
 
91
        
-
 
92
        printf("Reading 0x%08x bytes from 0x%08x\n", buf_size, read_addr);
-
 
93
 
87
        res = fuse_main(argc, argv, &emcorefs_oper, NULL);
94
        res = emcore_read(buf, read_addr, buf_size);
-
 
95
 
-
 
96
        if (res != EMCORE_SUCCESS) {
-
 
97
            free(buf);
-
 
98
            break;
-
 
99
        }
-
 
100
 
-
 
101
#ifdef DEBUG
-
 
102
        //dump_packet(buf, buf_size);
88
 
103
 
89
        cache_destroy();
-
 
90
#endif
104
#endif
-
 
105
 
-
 
106
        printf("Writing 0x%08x bytes to 0x%08x\n", buf_size, read_addr);
-
 
107
 
-
 
108
        res = emcore_write(buf, read_addr, buf_size);
-
 
109
 
-
 
110
        if (res != EMCORE_SUCCESS) {
-
 
111
            free(buf);
-
 
112
            break;
-
 
113
        }
-
 
114
 
-
 
115
        free(buf);
-
 
116
*/
-
 
117
        /*
-
 
118
        printf("Reading 1 byte from I2C\n");
-
 
119
 
-
 
120
        res = emcore_readi2c(&i2cdata, 0, 0xe6, 0x29, 1);
-
 
121
 
-
 
122
        if (res != EMCORE_SUCCESS) {
-
 
123
            break;
-
 
124
        }
-
 
125
 
-
 
126
#ifdef DEBUG
-
 
127
        dump_packet(&i2cdata, 1);
-
 
128
 
-
 
129
#endif
-
 
130
        */
-
 
131
        /* nano2g - turns on/off the backlight */
-
 
132
        /*
-
 
133
        i2cdata = 1;
-
 
134
 
-
 
135
        printf("Writing 1 byte to I2C\n");
-
 
136
 
-
 
137
        res = emcore_writei2c(&i2cdata, 0, 0xe6, 0x29, 1);
-
 
138
 
-
 
139
        if (res != EMCORE_SUCCESS) {
-
 
140
            break;
-
 
141
        }
-
 
142
 
-
 
143
        sleep(1);
-
 
144
 
-
 
145
        i2cdata = 0;
-
 
146
 
-
 
147
        printf("Writing 1 byte to I2C\n");
-
 
148
 
-
 
149
        res = emcore_writei2c(&i2cdata, 0, 0xe6, 0x29, 1);
-
 
150
 
-
 
151
        if (res != EMCORE_SUCCESS) {
-
 
152
            break;
-
 
153
        }
-
 
154
        */
-
 
155
        /*
-
 
156
        // short filenames without malloc()
-
 
157
        res = emcore_file_open(&dir_handle, "/README", 0);
-
 
158
 
-
 
159
        if (res != EMCORE_SUCCESS) {
-
 
160
            break;
-
 
161
        }
-
 
162
 
-
 
163
        printf("Opened file handle: 0x%08x\n", dir_handle);
-
 
164
 
-
 
165
        res = emcore_file_close(dir_handle);
-
 
166
 
-
 
167
        if (res != EMCORE_SUCCESS) {
-
 
168
            break;
-
 
169
        }
-
 
170
 
-
 
171
        printf("Closed file handle: 0x%08x\n", dir_handle);
-
 
172
 
-
 
173
        // long filenames with malloc()
-
 
174
        res = emcore_file_open(&dir_handle, "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png", 0);
-
 
175
 
-
 
176
        if (res != EMCORE_SUCCESS) {
-
 
177
            break;
-
 
178
        }
-
 
179
 
-
 
180
        printf("Opened file handle: 0x%08x\n", dir_handle);
-
 
181
 
-
 
182
        res = emcore_file_close(dir_handle);
-
 
183
 
-
 
184
        if (res != EMCORE_SUCCESS) {
-
 
185
            break;
-
 
186
        }
-
 
187
 
-
 
188
        printf("Closed file handle: 0x%08x\n", dir_handle);
-
 
189
        */
-
 
190
        /*
-
 
191
        res = emcore_dir_open(&dir_handle, "/");
-
 
192
 
-
 
193
        if (res != EMCORE_SUCCESS) {
-
 
194
            break;
-
 
195
        }
-
 
196
 
-
 
197
        printf("Opened dir handle: 0x%08x\n", dir_handle);
-
 
198
 
-
 
199
        res = emcore_ls(dir_handle);
-
 
200
 
-
 
201
        if (res != EMCORE_SUCCESS) {
-
 
202
            break;
-
 
203
        }
-
 
204
 
-
 
205
        printf("Listed dir handle: 0x%08x\n", dir_handle);
-
 
206
 
-
 
207
        res = emcore_dir_close(dir_handle);
-
 
208
 
-
 
209
        if (res != EMCORE_SUCCESS) {
-
 
210
            break;
-
 
211
        }
-
 
212
 
-
 
213
        printf("Closed dir handle 0x%08x\n", dir_handle);
-
 
214
 
-
 
215
        res = emcore_dir_close_all(&count);
-
 
216
 
-
 
217
        if (res != EMCORE_SUCCESS) {
-
 
218
            break;
-
 
219
        }
-
 
220
 
-
 
221
        printf("Closed %d dir handles\n", count);
-
 
222
        */
-
 
223
        
-
 
224
        /* powers off the device - graceful
-
 
225
        res = emcore_poweroff(1);
-
 
226
 
-
 
227
        if (res != EMCORE_SUCCESS) {
-
 
228
            break;
-
 
229
        }
-
 
230
 
-
 
231
        printf("Device powered off successfully!\n");
-
 
232
        */
91
    }
233
    }
-
 
234
    while (0);
92
 
235
 
93
    if (EMCORE_SUCCESS != res)
236
    if (res != EMCORE_SUCCESS) {
94
    {
-
 
95
        print_error(res);
237
        print_error(res);
96
    }
238
    }
97
 
239
 
98
    res2 = usb_destroy(reattach);
240
    res2 = usb_destroy(reattach);
99
 
241
 
100
    if (LIBUSB_SUCCESS != res2)
242
    if (res2 != LIBUSB_SUCCESS) {
101
    {
-
 
102
        print_error(res2);
243
        print_error(res2);
103
    }
244
    }
104
 
245
 
105
    if (res < 0)
246
    if (res < 0) {
106
    {
-
 
107
        res = -res;
247
        res = -res;
108
    }
248
    }
109
 
249
 
110
    return res;
250
    return res;
111
}
251
}