mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2025-04-21 12:27:27 +03:00
tools: give the driver control over CLKM (for ATmega32U2 boards)
- include/atrf.h (atrf_set_clkm), lib/atrf.c (atrf_set_clkm): set or disable CLKM - lib/driver.h (atrf_set_clkm_generic), lib/atrf.c (atrf_set_clkm_generic): generic function to set CLKM without restrictions - lib/driver.h (struct atrf_driver): added driver operation "set_clkm" to set CLKM - lib/atusb.c (atusb_set_clkm, atusb_driver): restrict CLKM on ATmega32U2 boards - atrf-txrx/atrf-txrx.c (init_txrx): use atrf_set_clkm to set CLKM - atrf-txrx/atrf-txrx.c (init_txrx, main): pass CLKM frequency in MHz instead of code point
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* lib/atusb.c - ATUSB access functions library (USB version)
|
||||
*
|
||||
* Written 2010 by Werner Almesberger
|
||||
* Copyright 2010 Werner Almesberger
|
||||
* Written 2010-2011 by Werner Almesberger
|
||||
* Copyright 2010-2011 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -227,6 +227,48 @@ static int atusb_interrupt(void *dsc)
|
||||
}
|
||||
|
||||
|
||||
/* ----- CLKM handling ----------------------------------------------------- */
|
||||
|
||||
|
||||
/*
|
||||
* ATmega32U2-based boards don't allow disabling CLKM, so we keep it at 8 MHz.
|
||||
* We could accommodate a choice between 8 MHz and 16 MHz, but that's for
|
||||
* later.
|
||||
*/
|
||||
|
||||
static int atusb_set_clkm(void *dsc, int mhz)
|
||||
{
|
||||
usb_dev_handle *dev = dsc;
|
||||
uint8_t ids[3];
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return 0;
|
||||
res = usb_control_msg(dev, FROM_DEV, ATUSB_ID, 0, 0,
|
||||
(void *) ids, 3, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATUSB_ID: %s\n", usb_strerror());
|
||||
error = 1;
|
||||
return 0;
|
||||
}
|
||||
switch (ids[2]) {
|
||||
case HW_TYPE_100813:
|
||||
case HW_TYPE_101216:
|
||||
break;
|
||||
case HW_TYPE_110131:
|
||||
if (mhz == 0 || mhz == 8)
|
||||
return 1;
|
||||
fprintf(stderr, "this board only supports CLKM = 8 MHz\n");
|
||||
return 0;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"atusb_set_clkm: unknown hardware type 0x%02x\n", ids[2]);
|
||||
return 0;
|
||||
}
|
||||
return atrf_set_clkm_generic(atusb_reg_write, dsc, mhz);
|
||||
}
|
||||
|
||||
|
||||
/* ----- driver interface -------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -239,6 +281,7 @@ struct atrf_driver atusb_driver = {
|
||||
.reset = atusb_reset,
|
||||
.reset_rf = atusb_reset_rf,
|
||||
.test_mode = atusb_test_mode,
|
||||
.set_clkm = atusb_set_clkm,
|
||||
.reg_write = atusb_reg_write,
|
||||
.reg_read = atusb_reg_read,
|
||||
.buf_write = atusb_buf_write,
|
||||
|
||||
Reference in New Issue
Block a user