sys_log: replace old debug macros at USB DFU sample

USB DFU sample application is now using new system log macros and
updated the .conf file.

JIRA: ZEP-311

Change-Id: Ifa5ede70c06a5fe18dde865fa7e97f469364ddb8
Signed-off-by: Genaro Saucedo Tejada <genaro.saucedo.tejada@intel.com>
This commit is contained in:
Genaro Saucedo Tejada 2016-07-29 16:13:27 -05:00 committed by Andrew Boie
commit 573b7420d4
2 changed files with 42 additions and 42 deletions

View file

@ -4,6 +4,9 @@ CONFIG_ARC_INIT=n
CONFIG_USB=y CONFIG_USB=y
CONFIG_USB_DW=y CONFIG_USB_DW=y
CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_STACK=y
#Un comment to enable logging
#CONFIG_SYS_LOG=y
CONFIG_SYS_LOG_USB_DFU_LEVEL=0
CONFIG_SYS_LOG_USB_DW_LEVEL=0 CONFIG_SYS_LOG_USB_DW_LEVEL=0
CONFIG_SYS_LOG_USB_LEVEL=0 CONFIG_SYS_LOG_USB_LEVEL=0
CONFIG_FLASH=y CONFIG_FLASH=y

View file

@ -45,16 +45,8 @@
#include "usb_dfu.h" #include "usb_dfu.h"
#ifndef CONFIG_USB_DFU_DEBUG #define SYS_LOG_LEVEL CONFIG_SYS_LOG_USB_DFU_LEVEL
#define DBG(...) { ; } #include <misc/sys_log.h>
#else
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define DBG printf
#else
#define DBG printk
#endif /* CONFIG_STDOUT_CONSOLE */
#endif /* CONFIG_USB_DFU_DEBUG */
/* Alternate settings are used to access additional memory segments. /* Alternate settings are used to access additional memory segments.
* This example uses the alternate settings as an offset into flash. * This example uses the alternate settings as an offset into flash.
@ -346,7 +338,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
switch (pSetup->bRequest) { switch (pSetup->bRequest) {
case DFU_GETSTATUS: case DFU_GETSTATUS:
DBG("DFU_GETSTATUS: status %d, state %d\n", SYS_LOG_DBG("DFU_GETSTATUS: status %d, state %d",
dfu_data.status, dfu_data.state); dfu_data.status, dfu_data.state);
if (dfu_data.state == dfuMANIFEST_SYNC) if (dfu_data.state == dfuMANIFEST_SYNC)
@ -362,13 +354,13 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
break; break;
case DFU_GETSTATE: case DFU_GETSTATE:
DBG("DFU_GETSTATE\n"); SYS_LOG_DBG("DFU_GETSTATE");
(*data)[0] = dfu_data.state; (*data)[0] = dfu_data.state;
*data_len = 1; *data_len = 1;
break; break;
case DFU_ABORT: case DFU_ABORT:
DBG("DFU_ABORT\n"); SYS_LOG_DBG("DFU_ABORT");
if (dfu_check_app_state()) if (dfu_check_app_state())
return -EINVAL; return -EINVAL;
@ -379,7 +371,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
break; break;
case DFU_CLRSTATUS: case DFU_CLRSTATUS:
DBG("DFU_CLRSTATUS\n"); SYS_LOG_DBG("DFU_CLRSTATUS");
if (dfu_check_app_state()) if (dfu_check_app_state())
return -EINVAL; return -EINVAL;
@ -389,7 +381,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
break; break;
case DFU_DNLOAD: case DFU_DNLOAD:
DBG("DFU_DNLOAD block %d, len %d, state %d\n", SYS_LOG_DBG("DFU_DNLOAD block %d, len %d, state %d",
pSetup->wValue, pSetup->wLength, dfu_data.state); pSetup->wValue, pSetup->wLength, dfu_data.state);
if (dfu_check_app_state()) if (dfu_check_app_state())
@ -398,7 +390,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
switch (dfu_data.state) { switch (dfu_data.state) {
case dfuIDLE: case dfuIDLE:
dfu_reset_counters(); dfu_reset_counters();
DBG("DFU_DNLOAD start\n"); SYS_LOG_DBG("DFU_DNLOAD start");
case dfuDNLOAD_IDLE: case dfuDNLOAD_IDLE:
if (pSetup->wLength != 0) { if (pSetup->wLength != 0) {
/* Download has started */ /* Download has started */
@ -410,12 +402,13 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
DFU_FLASH_ADDR + DFU_FLASH_ADDR +
dfu_data.bytes_rcvd, dfu_data.bytes_rcvd,
dfu_data.flash_page_size); dfu_data.flash_page_size);
DBG("Flash erase\n"); SYS_LOG_DBG("Flash erase");
if (ret) { if (ret) {
dfu_data.state = dfuERROR; dfu_data.state = dfuERROR;
dfu_data.status = errERASE; dfu_data.status = errERASE;
DBG("DFU flash erase error, " SYS_LOG_ERR("DFU flash erase "
"ret %d\n", ret); "error, ret %d",
ret);
} }
} }
@ -428,8 +421,8 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
if (ret) { if (ret) {
dfu_data.state = dfuERROR; dfu_data.state = dfuERROR;
dfu_data.status = errWRITE; dfu_data.status = errWRITE;
DBG("DFU flash write error, ret %d\n", SYS_LOG_ERR("DFU flash write error, "
ret); "ret %d", ret);
} else } else
dfu_data.bytes_rcvd += pSetup->wLength; dfu_data.bytes_rcvd += pSetup->wLength;
} else { } else {
@ -439,7 +432,8 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
} }
break; break;
default: default:
DBG("DFU_DNLOAD wrong state %d\n", dfu_data.state); SYS_LOG_ERR("DFU_DNLOAD wrong state %d",
dfu_data.state);
dfu_data.state = dfuERROR; dfu_data.state = dfuERROR;
dfu_data.status = errUNKNOWN; dfu_data.status = errUNKNOWN;
dfu_reset_counters(); dfu_reset_counters();
@ -447,7 +441,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
} }
break; break;
case DFU_UPLOAD: case DFU_UPLOAD:
DBG("DFU_UPLOAD block %d, len %d, state %d\n", SYS_LOG_DBG("DFU_UPLOAD block %d, len %d, state %d",
pSetup->wValue, pSetup->wLength, dfu_data.state); pSetup->wValue, pSetup->wLength, dfu_data.state);
if (dfu_check_app_state()) if (dfu_check_app_state())
@ -456,12 +450,12 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
switch (dfu_data.state) { switch (dfu_data.state) {
case dfuIDLE: case dfuIDLE:
dfu_reset_counters(); dfu_reset_counters();
DBG("DFU_UPLOAD start\n"); SYS_LOG_DBG("DFU_UPLOAD start");
case dfuUPLOAD_IDLE: case dfuUPLOAD_IDLE:
if (!pSetup->wLength || if (!pSetup->wLength ||
dfu_data.block_nr != pSetup->wValue) { dfu_data.block_nr != pSetup->wValue) {
DBG("DFU_UPLOAD block %d, expected %d, " SYS_LOG_ERR("DFU_UPLOAD block %d, expected "
"len %d\n", pSetup->wValue, "%d, len %d", pSetup->wValue,
dfu_data.block_nr, pSetup->wLength); dfu_data.block_nr, pSetup->wLength);
dfu_data.state = dfuERROR; dfu_data.state = dfuERROR;
dfu_data.status = errUNKNOWN; dfu_data.status = errUNKNOWN;
@ -504,7 +498,8 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
break; break;
default: default:
DBG("DFU_UPLOAD wrong state %d\n", dfu_data.state); SYS_LOG_ERR("DFU_UPLOAD wrong state %d",
dfu_data.state);
dfu_data.state = dfuERROR; dfu_data.state = dfuERROR;
dfu_data.status = errUNKNOWN; dfu_data.status = errUNKNOWN;
dfu_reset_counters(); dfu_reset_counters();
@ -512,7 +507,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
} }
break; break;
case DFU_DETACH: case DFU_DETACH:
DBG("DFU_DETACH timeout %d, state %d\n", SYS_LOG_DBG("DFU_DETACH timeout %d, state %d",
pSetup->wValue, dfu_data.state); pSetup->wValue, dfu_data.state);
if (dfu_data.state != appIDLE) { if (dfu_data.state != appIDLE) {
@ -533,7 +528,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
usb_set_config(&dfu_config); usb_set_config(&dfu_config);
break; break;
default: default:
DBG("DFU UNKNOWN STATE: %d\n", pSetup->bRequest); SYS_LOG_ERR("DFU UNKNOWN STATE: %d", pSetup->bRequest);
return -EINVAL; return -EINVAL;
} }
@ -552,32 +547,33 @@ static void dfu_status_cb(enum usb_dc_status_code status)
/* Check the USB status and do needed action if required */ /* Check the USB status and do needed action if required */
switch (status) { switch (status) {
case USB_DC_ERROR: case USB_DC_ERROR:
DBG("USB device error\n"); SYS_LOG_ERR("USB device error");
break; break;
case USB_DC_RESET: case USB_DC_RESET:
DBG("USB device reset detected, state %d\n", dfu_data.state); SYS_LOG_DBG("USB device reset detected, state %d",
dfu_data.state);
if (dfu_data.state == appDETACH) { if (dfu_data.state == appDETACH) {
dfu_data.state = dfuIDLE; dfu_data.state = dfuIDLE;
} }
break; break;
case USB_DC_CONNECTED: case USB_DC_CONNECTED:
DBG("USB device connected\n"); SYS_LOG_DBG("USB device connected");
break; break;
case USB_DC_CONFIGURED: case USB_DC_CONFIGURED:
DBG("USB device configured\n"); SYS_LOG_DBG("USB device configured");
break; break;
case USB_DC_DISCONNECTED: case USB_DC_DISCONNECTED:
DBG("USB device disconnected\n"); SYS_LOG_DBG("USB device disconnected");
break; break;
case USB_DC_SUSPEND: case USB_DC_SUSPEND:
DBG("USB device supended\n"); SYS_LOG_DBG("USB device supended");
break; break;
case USB_DC_RESUME: case USB_DC_RESUME:
DBG("USB device resumed\n"); SYS_LOG_DBG("USB device resumed");
break; break;
case USB_DC_UNKNOWN: case USB_DC_UNKNOWN:
default: default:
DBG("USB unknown state\n"); SYS_LOG_WRN("USB unknown state");
break; break;
} }
} }
@ -600,11 +596,12 @@ static int dfu_custom_handle_req(struct usb_setup_packet *pSetup,
if (REQTYPE_GET_RECIP(pSetup->bmRequestType) == if (REQTYPE_GET_RECIP(pSetup->bmRequestType) ==
REQTYPE_RECIP_INTERFACE) { REQTYPE_RECIP_INTERFACE) {
if (pSetup->bRequest == REQ_SET_INTERFACE) { if (pSetup->bRequest == REQ_SET_INTERFACE) {
DBG("DFU alternate setting %d\n", pSetup->wValue); SYS_LOG_DBG("DFU alternate setting %d",
pSetup->wValue);
if (pSetup->wValue >= DFU_MODE_ALTERNATE_SETTINGS) { if (pSetup->wValue >= DFU_MODE_ALTERNATE_SETTINGS) {
DBG("Invalid DFU alternate setting (%d)\n", SYS_LOG_DBG("Invalid DFU alternate setting "
pSetup->wValue); "(%d)", pSetup->wValue);
} else { } else {
dfu_data.alt_setting = pSetup->wValue; dfu_data.alt_setting = pSetup->wValue;
} }
@ -655,14 +652,14 @@ int dfu_start(struct device *flash_dev, uint32_t flash_base_addr,
/* Initialize the USB driver with the right configuration */ /* Initialize the USB driver with the right configuration */
ret = usb_set_config(&dfu_config); ret = usb_set_config(&dfu_config);
if (ret < 0) { if (ret < 0) {
DBG("Failed to config USB\n"); SYS_LOG_ERR("Failed to config USB");
return ret; return ret;
} }
/* Enable USB driver */ /* Enable USB driver */
ret = usb_enable(&dfu_config); ret = usb_enable(&dfu_config);
if (ret < 0) { if (ret < 0) {
DBG("Failed to enable USB\n"); SYS_LOG_ERR("Failed to enable USB");
return ret; return ret;
} }