Date:2011-02-11 01:15:05 (8 years 11 months ago)
Author:Werner Almesberger
Commit:e73ca5fcd5514be78554c563580501798523bd47
Message:tools/lib: cache chip ID in the descriptor

- atrf.c (struct atrf_dsc): added field "chip_id" to cache chip ID
- atrf.c (identify, atrf_identify): moved identification logic to new
function
- atrf.c (atrf_open, atrf_identify): cache chip ID when opening the
device and return ID from cache
Files: tools/lib/atrf.c (4 diffs)

Change Details

tools/lib/atrf.c
2727struct atrf_dsc {
2828    struct atrf_driver *driver;
2929    void *handle;
30    enum atrf_chip_id chip_id;
3031};
3132
3233
...... 
5354}
5455
5556
57static enum atrf_chip_id identify(struct atrf_dsc *dsc)
58{
59    uint8_t part, version;
60
61    part = atrf_reg_read(dsc, REG_PART_NUM);
62    version = atrf_reg_read(dsc, REG_VERSION_NUM);
63    switch (part) {
64    case 2: /* AT86RF230 */
65        switch (version) {
66        case 1: /* rev A */
67        case 2: /* rev B */
68            return artf_at86rf230;
69        default:
70            return atrf_unknown_chip;
71        }
72        break;
73    case 3: /* AT86RF231 */
74        switch (version) {
75        case 2: /* rev A */
76            return artf_at86rf231;
77        default:
78            return atrf_unknown_chip;
79        }
80        break;
81    default:
82        return atrf_unknown_chip;
83    }
84    return atrf_unknown_chip;
85}
86
87
5688struct atrf_dsc *atrf_open(void)
5789{
5890    struct atrf_dsc *dsc;
...... 
76108    }
77109    dsc->driver = driver;
78110    dsc->handle = handle;
111    dsc->chip_id = identify(dsc);
79112    return dsc;
80113}
81114
...... 
103136
104137enum atrf_chip_id atrf_identify(struct atrf_dsc *dsc)
105138{
106    uint8_t part, version;
107
108    part = atrf_reg_read(dsc, REG_PART_NUM);
109    version = atrf_reg_read(dsc, REG_VERSION_NUM);
110    switch (part) {
111    case 2: /* AT86RF230 */
112        switch (version) {
113        case 1: /* rev A */
114        case 2: /* rev B */
115            return artf_at86rf230;
116        default:
117            return atrf_unknown_chip;
118        }
119        break;
120    case 3: /* AT86RF231 */
121        switch (version) {
122        case 2: /* rev A */
123            return artf_at86rf231;
124        default:
125            return atrf_unknown_chip;
126        }
127        break;
128    default:
129        return atrf_unknown_chip;
130    }
131    return atrf_unknown_chip;
139    return dsc->chip_id;
132140}
133141
134142

Archive Download the corresponding diff file



interactive