You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(75) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(70) |
Feb
(20) |
Mar
(52) |
Apr
(149) |
May
(387) |
Jun
(466) |
Jul
(133) |
Aug
(87) |
Sep
(122) |
Oct
(140) |
Nov
(185) |
Dec
(105) |
2010 |
Jan
(85) |
Feb
(45) |
Mar
(75) |
Apr
(17) |
May
(41) |
Jun
(52) |
Jul
(33) |
Aug
(29) |
Sep
(36) |
Oct
(15) |
Nov
(26) |
Dec
(34) |
2011 |
Jan
(26) |
Feb
(25) |
Mar
(26) |
Apr
(29) |
May
(20) |
Jun
(27) |
Jul
(15) |
Aug
(32) |
Sep
(13) |
Oct
(64) |
Nov
(60) |
Dec
(10) |
2012 |
Jan
(64) |
Feb
(63) |
Mar
(39) |
Apr
(43) |
May
(54) |
Jun
(11) |
Jul
(30) |
Aug
(45) |
Sep
(11) |
Oct
(70) |
Nov
(24) |
Dec
(23) |
2013 |
Jan
(17) |
Feb
(8) |
Mar
(35) |
Apr
(40) |
May
(20) |
Jun
(24) |
Jul
(36) |
Aug
(25) |
Sep
(42) |
Oct
(40) |
Nov
(9) |
Dec
(21) |
2014 |
Jan
(29) |
Feb
(24) |
Mar
(60) |
Apr
(22) |
May
(22) |
Jun
(46) |
Jul
(11) |
Aug
(23) |
Sep
(26) |
Oct
(10) |
Nov
(14) |
Dec
(2) |
2015 |
Jan
(28) |
Feb
(47) |
Mar
(33) |
Apr
(58) |
May
(5) |
Jun
(1) |
Jul
|
Aug
(8) |
Sep
(12) |
Oct
(25) |
Nov
(58) |
Dec
(21) |
2016 |
Jan
(12) |
Feb
(40) |
Mar
(2) |
Apr
(1) |
May
(67) |
Jun
(2) |
Jul
(5) |
Aug
(36) |
Sep
|
Oct
(24) |
Nov
(17) |
Dec
(50) |
2017 |
Jan
(14) |
Feb
(16) |
Mar
(2) |
Apr
(35) |
May
(14) |
Jun
(16) |
Jul
(3) |
Aug
(3) |
Sep
|
Oct
(19) |
Nov
|
Dec
(16) |
2018 |
Jan
(55) |
Feb
(11) |
Mar
(34) |
Apr
(14) |
May
(4) |
Jun
(20) |
Jul
(39) |
Aug
(16) |
Sep
(17) |
Oct
(16) |
Nov
(20) |
Dec
(30) |
2019 |
Jan
(29) |
Feb
(24) |
Mar
(37) |
Apr
(26) |
May
(19) |
Jun
(21) |
Jul
(2) |
Aug
(3) |
Sep
(9) |
Oct
(12) |
Nov
(12) |
Dec
(12) |
2020 |
Jan
(47) |
Feb
(36) |
Mar
(54) |
Apr
(44) |
May
(37) |
Jun
(19) |
Jul
(32) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(32) |
Dec
(11) |
2021 |
Jan
(14) |
Feb
(5) |
Mar
(40) |
Apr
(32) |
May
(42) |
Jun
(31) |
Jul
(29) |
Aug
(47) |
Sep
(38) |
Oct
(17) |
Nov
(74) |
Dec
(33) |
2022 |
Jan
(11) |
Feb
(15) |
Mar
(40) |
Apr
(21) |
May
(39) |
Jun
(44) |
Jul
(19) |
Aug
(46) |
Sep
(79) |
Oct
(35) |
Nov
(21) |
Dec
(15) |
2023 |
Jan
(56) |
Feb
(13) |
Mar
(43) |
Apr
(28) |
May
(60) |
Jun
(15) |
Jul
(29) |
Aug
(28) |
Sep
(32) |
Oct
(21) |
Nov
(42) |
Dec
(39) |
2024 |
Jan
(35) |
Feb
(17) |
Mar
(28) |
Apr
(7) |
May
(14) |
Jun
(35) |
Jul
(30) |
Aug
(35) |
Sep
(30) |
Oct
(28) |
Nov
(38) |
Dec
(18) |
2025 |
Jan
(21) |
Feb
(28) |
Mar
(36) |
Apr
(35) |
May
(34) |
Jun
(58) |
Jul
(9) |
Aug
(20) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <zw...@ma...> - 2009-06-29 02:01:06
|
Author: zwelch Date: 2009-06-29 02:00:50 +0200 (Mon, 29 Jun 2009) New Revision: 2413 Added: trunk/src/jtag/interfaces.c trunk/src/jtag/interfaces.h Modified: trunk/src/jtag/Makefile.am trunk/src/jtag/tcl.c Log: Move JTAG interface list to new files. - Adds new source files to encapsulate static/dynamic module handling. - Further work should implement the jtag_interface_modules_load routine, to populate the jtag_interfaces list from shared libraries in a path. Modified: trunk/src/jtag/Makefile.am =================================================================== --- trunk/src/jtag/Makefile.am 2009-06-28 18:46:51 UTC (rev 2412) +++ trunk/src/jtag/Makefile.am 2009-06-29 00:00:50 UTC (rev 2413) @@ -75,12 +75,14 @@ libjtag_la_SOURCES = \ core.c \ + interface.c \ + interfaces.c \ tcl.c \ - interface.c \ $(DRIVERFILES) noinst_HEADERS = \ interface.h \ + interfaces.h \ commands.h \ minidriver.h \ bitbang.h \ Added: trunk/src/jtag/interfaces.c =================================================================== --- trunk/src/jtag/interfaces.c 2009-06-28 18:46:51 UTC (rev 2412) +++ trunk/src/jtag/interfaces.c 2009-06-29 00:00:50 UTC (rev 2413) @@ -0,0 +1,155 @@ +/*************************************************************************** + * Copyright (C) 2005 by Dominic Rath * + * Dom...@gm... * + * * + * Copyright (C) 2007,2008 Øyvind Harboe * + * oyv...@zy... * + * * + * Copyright (C) 2009 SoftPLC Corporation * + * http://softplc.com * + * di...@so... * + * * + * Copyright (C) 2009 Zachary T Welch * + * zw...@su... * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "interfaces.h" + +/** + * @file This file includes declarations for all built-in jtag interfaces, + * which are then listed in the jtag_interfaces array. + * + * Dynamic loading can be implemented be searching for shared libraries + * that contain a jtag_interface structure that can added to this list. + */ + +#if BUILD_ZY1000 == 1 +extern jtag_interface_t zy1000_interface; +#elif defined(BUILD_MINIDRIVER_DUMMY) +extern jtag_interface_t minidummy_interface; +#else // standard drivers +#if BUILD_PARPORT == 1 +extern jtag_interface_t parport_interface; +#endif +#if BUILD_DUMMY == 1 +extern jtag_interface_t dummy_interface; +#endif +#if BUILD_FT2232_FTD2XX == 1 +extern jtag_interface_t ft2232_interface; +#endif +#if BUILD_FT2232_LIBFTDI == 1 +extern jtag_interface_t ft2232_interface; +#endif +#if BUILD_AMTJTAGACCEL == 1 +extern jtag_interface_t amt_jtagaccel_interface; +#endif +#if BUILD_EP93XX == 1 +extern jtag_interface_t ep93xx_interface; +#endif +#if BUILD_AT91RM9200 == 1 +extern jtag_interface_t at91rm9200_interface; +#endif +#if BUILD_GW16012 == 1 +extern jtag_interface_t gw16012_interface; +#endif +#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1 +extern jtag_interface_t presto_interface; +#endif +#if BUILD_USBPROG == 1 +extern jtag_interface_t usbprog_interface; +#endif +#if BUILD_JLINK == 1 +extern jtag_interface_t jlink_interface; +#endif +#if BUILD_VSLLINK == 1 +extern jtag_interface_t vsllink_interface; +#endif +#if BUILD_RLINK == 1 +extern jtag_interface_t rlink_interface; +#endif +#if BUILD_ARMJTAGEW == 1 +extern jtag_interface_t armjtagew_interface; +#endif +#endif // standard drivers + +/** + * The list of built-in JTAG interfaces, containing entries for those + * drivers that were enabled by the @c configure script. + * + * The list should be defined to contain either one minidriver interface + * or some number of standard driver interfaces, never both. + */ +jtag_interface_t *jtag_interfaces[] = { +#if BUILD_ZY1000 == 1 + &zy1000_interface, +#elif defined(BUILD_MINIDRIVER_DUMMY) + &minidummy_interface, +#else // standard drivers +#if BUILD_PARPORT == 1 + &parport_interface, +#endif +#if BUILD_DUMMY == 1 + &dummy_interface, +#endif +#if BUILD_FT2232_FTD2XX == 1 + &ft2232_interface, +#endif +#if BUILD_FT2232_LIBFTDI == 1 + &ft2232_interface, +#endif +#if BUILD_AMTJTAGACCEL == 1 + &amt_jtagaccel_interface, +#endif +#if BUILD_EP93XX == 1 + &ep93xx_interface, +#endif +#if BUILD_AT91RM9200 == 1 + &at91rm9200_interface, +#endif +#if BUILD_GW16012 == 1 + &gw16012_interface, +#endif +#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1 + &presto_interface, +#endif +#if BUILD_USBPROG == 1 + &usbprog_interface, +#endif +#if BUILD_JLINK == 1 + &jlink_interface, +#endif +#if BUILD_VSLLINK == 1 + &vsllink_interface, +#endif +#if BUILD_RLINK == 1 + &rlink_interface, +#endif +#if BUILD_ARMJTAGEW == 1 + &armjtagew_interface, +#endif +#endif // standard drivers + NULL, + }; + +void jtag_interface_modules_load(const char *path) +{ + // @todo: implement dynamic module loading for JTAG interface drivers +} Property changes on: trunk/src/jtag/interfaces.c ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/src/jtag/interfaces.h =================================================================== --- trunk/src/jtag/interfaces.h 2009-06-28 18:46:51 UTC (rev 2412) +++ trunk/src/jtag/interfaces.h 2009-06-29 00:00:50 UTC (rev 2413) @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Dominic Rath * + * Dom...@gm... * + * * + * Copyright (C) 2007,2008 Øyvind Harboe * + * oyv...@zy... * + * * + * Copyright (C) 2009 SoftPLC Corporation * + * http://softplc.com * + * di...@so... * + * * + * Copyright (C) 2009 Zachary T Welch * + * zw...@su... * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef OPENOCD_JTAG_INTERFACES_H +#define OPENOCD_JTAG_INTERFACES_H + +/** + * @file Exports the list of JTAG interface drivers, along with routines + * for loading and unloading them dynamically from shared libraries. + */ + +#include "interface.h" + +/// Dynamically load all JTAG interface modules from specified directory. +void jtag_interface_modules_load(const char *path); + +extern jtag_interface_t *jtag_interfaces[]; + +#endif // OPENOCD_JTAG_INTERFACES_H Property changes on: trunk/src/jtag/interfaces.h ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/src/jtag/tcl.c =================================================================== --- trunk/src/jtag/tcl.c 2009-06-28 18:46:51 UTC (rev 2412) +++ trunk/src/jtag/tcl.c 2009-06-29 00:00:50 UTC (rev 2413) @@ -34,6 +34,7 @@ #include "jtag.h" #include "minidriver.h" #include "interface.h" +#include "interfaces.h" #ifdef HAVE_STRINGS_H #include <strings.h> @@ -46,130 +47,6 @@ { .name = NULL, .value = -1 } }; -/* jtag interfaces (parport, FTDI-USB, TI-USB, ...) - */ - -#if BUILD_ZY1000 == 1 - extern jtag_interface_t zy1000_interface; -#elif defined(BUILD_MINIDRIVER_DUMMY) - extern jtag_interface_t minidummy_interface; -#else // standard drivers -#if BUILD_PARPORT == 1 - extern jtag_interface_t parport_interface; -#endif - -#if BUILD_DUMMY == 1 - extern jtag_interface_t dummy_interface; -#endif - -#if BUILD_FT2232_FTD2XX == 1 - extern jtag_interface_t ft2232_interface; -#endif - -#if BUILD_FT2232_LIBFTDI == 1 - extern jtag_interface_t ft2232_interface; -#endif - -#if BUILD_AMTJTAGACCEL == 1 - extern jtag_interface_t amt_jtagaccel_interface; -#endif - -#if BUILD_EP93XX == 1 - extern jtag_interface_t ep93xx_interface; -#endif - -#if BUILD_AT91RM9200 == 1 - extern jtag_interface_t at91rm9200_interface; -#endif - -#if BUILD_GW16012 == 1 - extern jtag_interface_t gw16012_interface; -#endif - -#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1 - extern jtag_interface_t presto_interface; -#endif - -#if BUILD_USBPROG == 1 - extern jtag_interface_t usbprog_interface; -#endif - -#if BUILD_JLINK == 1 - extern jtag_interface_t jlink_interface; -#endif - -#if BUILD_VSLLINK == 1 - extern jtag_interface_t vsllink_interface; -#endif - -#if BUILD_RLINK == 1 - extern jtag_interface_t rlink_interface; -#endif - -#if BUILD_ARMJTAGEW == 1 - extern jtag_interface_t armjtagew_interface; -#endif -#endif // standard drivers - -/** - * The list of built-in JTAG interfaces, containing entries for those - * drivers that were enabled by the @c configure script. - * - * The list should be defined to contain either one minidriver interface - * or some number of standard driver interfaces, never both. - */ -jtag_interface_t *jtag_interfaces[] = { -#if BUILD_ZY1000 == 1 - &zy1000_interface, -#elif defined(BUILD_MINIDRIVER_DUMMY) - &minidummy_interface, -#else // standard drivers -#if BUILD_PARPORT == 1 - &parport_interface, -#endif -#if BUILD_DUMMY == 1 - &dummy_interface, -#endif -#if BUILD_FT2232_FTD2XX == 1 - &ft2232_interface, -#endif -#if BUILD_FT2232_LIBFTDI == 1 - &ft2232_interface, -#endif -#if BUILD_AMTJTAGACCEL == 1 - &amt_jtagaccel_interface, -#endif -#if BUILD_EP93XX == 1 - &ep93xx_interface, -#endif -#if BUILD_AT91RM9200 == 1 - &at91rm9200_interface, -#endif -#if BUILD_GW16012 == 1 - &gw16012_interface, -#endif -#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1 - &presto_interface, -#endif -#if BUILD_USBPROG == 1 - &usbprog_interface, -#endif -#if BUILD_JLINK == 1 - &jlink_interface, -#endif -#if BUILD_VSLLINK == 1 - &vsllink_interface, -#endif -#if BUILD_RLINK == 1 - &rlink_interface, -#endif -#if BUILD_ARMJTAGEW == 1 - &armjtagew_interface, -#endif -#endif // standard drivers - NULL, -}; - extern jtag_interface_t *jtag_interface; /* jtag commands */ |
From: <oh...@ma...> - 2009-06-28 20:46:53
|
Author: oharboe Date: 2009-06-28 20:46:51 +0200 (Sun, 28 Jun 2009) New Revision: 2412 Modified: trunk/doc/openocd.texi Log: David Brownell <da...@pa...> various missing commands Modified: trunk/doc/openocd.texi =================================================================== --- trunk/doc/openocd.texi 2009-06-28 03:09:15 UTC (rev 2411) +++ trunk/doc/openocd.texi 2009-06-28 18:46:51 UTC (rev 2412) @@ -987,7 +987,9 @@ Likewise, the @command{arm9tdmi vector_catch} command (or its @command{xscale vector_catch} sibling) can be a timesaver during some debug sessions, but don't make everyone use that either. -Keep those kinds of debugging aids in your user config file. +Keep those kinds of debugging aids in your user config file, +along with messaging and tracing setup. +(@xref{Software Debug Messages and Tracing}.) TCP/IP port configuration is another example of something which is environment-specific, and should only appear in @@ -1360,6 +1362,7 @@ set _CPUTAPID 0x3f0f0f0f @} @end example +@c but 0x3f0f0f0f is for an str73x part ... @emph{Remember:} Board config files may include multiple target config files, or the same target file multiple times @@ -1473,7 +1476,7 @@ examination of the instruction and data bus activity. Trace activity is controlled through an ``Embedded Trace Module'' (ETM) on one of the core's scan chains. The ETM emits voluminous data -through a ``trace port''. (@xref{ARM Tracing}.) +through a ``trace port''. (@xref{ARM Hardware Tracing}.) If you are using an external trace port, configure it in your board config file. If you are using an on-chip ``Embedded Trace Buffer'' (ETB), @@ -3359,6 +3362,7 @@ flash bank cfi 0x00000000 0x01000000 2 2 $_TARGETNAME flash bank cfi 0x01000000 0x01000000 2 2 $_TARGETNAME @end example +@c "cfi part_id" disabled @end deffn @subsection Internal Flash (Microcontrollers) @@ -3521,7 +3525,12 @@ flash bank lpc2000 0x0 0x7d000 0 0 $_TARGETNAME \ lpc2000_v2 14765 calc_checksum @end example + +@deffn {Command} {lpc2000 part_id} bank +Displays the four byte part identifier associated with +the specified flash @var{bank}. @end deffn +@end deffn @deffn {Flash Driver} lpc288x The LPC2888 microcontroller from NXP needs slightly different flash @@ -3625,7 +3634,12 @@ @example flash bank str7x 0x40000000 0x00040000 0 0 $_TARGETNAME STR71x @end example + +@deffn Command {str7x disable_jtag} bank +Activate the Debug/Readout protection mechanism +for the specified flash bank. @end deffn +@end deffn @deffn {Flash Driver} str9x Most members of the STR9 microcontroller family from ST Microelectronics @@ -4250,6 +4264,10 @@ @section Daemon Commands +@deffn {Command} exit +Exits the current telnet session. +@end deffn + @deffn Command sleep msec [@option{busy}] Wait for at least @var{msec} milliseconds before resuming. If @option{busy} is passed, busy-wait instead of sleeping. @@ -4406,16 +4424,62 @@ These commands are available when OpenOCD is built with @option{--enable-ioutil}. -They are mainly useful on embedded targets; -PC type hosts have complementary tools. +They are mainly useful on embedded targets, +notably the ZY1000. +Hosts with operating systems have complementary tools. @emph{Note:} there are several more such commands. +@deffn Command append_file filename [string]* +Appends the @var{string} parameters to +the text file @file{filename}. +Each string except the last one is followed by one space. +The last string is followed by a newline. +@end deffn + +@deffn Command cat filename +Reads and displays the text file @file{filename}. +@end deffn + +@deffn Command cp src_filename dest_filename +Copies contents from the file @file{src_filename} +into @file{dest_filename}. +@end deffn + +@deffn Command ip +@emph{No description provided.} +@end deffn + +@deffn Command ls +@emph{No description provided.} +@end deffn + +@deffn Command mac +@emph{No description provided.} +@end deffn + @deffn Command meminfo Display available RAM memory on OpenOCD host. Used in OpenOCD regression testing scripts. @end deffn +@deffn Command peek +@emph{No description provided.} +@end deffn + +@deffn Command poke +@emph{No description provided.} +@end deffn + +@deffn Command rm filename +@c "rm" has both normal and Jim-level versions?? +Unlinks the file @file{filename}. +@end deffn + +@deffn Command trunc filename +Removes all data in the file @file{filename}. +@end deffn + @anchor{Memory access} @section Memory access commands @cindex memory access @@ -4487,6 +4551,14 @@ (@option{bin}, @option{ihex}, or @option{elf}) @end deffn +@deffn Command {test_image} filename [address [@option{bin}|@option{ihex}|@option{elf}]] +Displays image section sizes and addresses +as if @var{filename} were loaded into target memory +starting at @var{address} (defaults to zero). +The file format may optionally be specified +(@option{bin}, @option{ihex}, or @option{elf}) +@end deffn + @deffn Command {verify_image} filename address [@option{bin}|@option{ihex}|@option{elf}] Verify @var{filename} against target memory starting at @var{address}. The file format may optionally be specified @@ -4535,14 +4607,23 @@ @end deffn @section Misc Commands + @cindex profiling - @deffn Command {profile} seconds filename Profiling samples the CPU's program counter as quickly as possible, which is useful for non-intrusive stochastic profiling. Saves up to 10000 sampines in @file{filename} using ``gmon.out'' format. @end deffn +@deffn Command {version} +Displays a string identifying the version of this OpenOCD server. +@end deffn + +@deffn Command {virt2phys} virtual_address +Requests the current target to map the specified @var{virtual_address} +to its corresponding physical address, and displays the result. +@end deffn + @node Architecture and Core Commands @chapter Architecture and Core Commands @cindex Architecture Specific Commands @@ -4553,8 +4634,9 @@ Some of those operations don't fit well in that framework, so they are exposed here as architecture or implementation (core) specific commands. -@anchor{ARM Tracing} -@section ARM Tracing +@anchor{ARM Hardware Tracing} +@section ARM Hardware Tracing +@cindex tracing @cindex ETM @cindex ETB @@ -5147,30 +5229,88 @@ Control masking (disabling) interrupts during target step/resume. @end deffn -@section Target DCC Requests +@anchor{Software Debug Messages and Tracing} +@section Software Debug Messages and Tracing @cindex Linux-ARM DCC support +@cindex tracing @cindex libdcc @cindex DCC -OpenOCD can handle certain target requests; currently debugmsgs +OpenOCD can process certain requests from target software. Currently @command{target_request debugmsgs} -are only supported for arm7_9 and cortex_m3. +is supported only for @option{arm7_9} and @option{cortex_m3} cores. +These messages are received as part of target polling, so +you need to have @command{poll on} active to receive them. +They are intrusive in that they will affect program execution +times. If that is a problem, @pxref{ARM Hardware Tracing}. -See libdcc in the contrib dir for more details. +See @file{libdcc} in the contrib dir for more details. +In addition to sending strings, characters, and +arrays of various size integers from the target, +@file{libdcc} also exports a software trace point mechanism. +The target being debugged may +issue trace messages which include a 24-bit @dfn{trace point} number. +Trace point support includes two distinct mechanisms, +each supported by a command: + +@itemize +@item @emph{History} ... A circular buffer of trace points +can be set up, and then displayed at any time. +This tracks where code has been, which can be invaluable in +finding out how some fault was triggered. + +The buffer may overflow, since it collects records continuously. +It may be useful to use some of the 24 bits to represent a +particular event, and other bits to hold data. + +@item @emph{Counting} ... An array of counters can be set up, +and then displayed at any time. +This can help establish code coverage and identify hot spots. + +The array of counters is directly indexed by the trace point +number, so trace points with higher numbers are not counted. +@end itemize + Linux-ARM kernels have a ``Kernel low-level debugging via EmbeddedICE DCC channel'' option (CONFIG_DEBUG_ICEDCC, depends on CONFIG_DEBUG_LL) which uses this mechanism to deliver messages before a serial console can be activated. +This is not the same format used by @file{libdcc}. +Other software, such as the U-Boot boot loader, sometimes +does the same thing. @deffn Command {target_request debugmsgs} [@option{enable}|@option{disable}|@option{charmsg}] Displays current handling of target DCC message requests. These messages may be sent to the debugger while the target is running. The optional @option{enable} and @option{charmsg} parameters both enable the messages, while @option{disable} disables them. + With @option{charmsg} the DCC words each contain one character, as used by Linux with CONFIG_DEBUG_ICEDCC; otherwise the libdcc format is used. @end deffn +@deffn Command {trace history} (@option{clear}|count) +With no parameter, displays all the trace points that have triggered +in the order they triggered. +With the parameter @option{clear}, erases all current trace history records. +With a @var{count} parameter, allocates space for that many +history records. +@end deffn + +@deffn Command {trace point} (@option{clear}|identifier) +With no parameter, displays all trace point identifiers and how many times +they have been triggered. +With the parameter @option{clear}, erases all current trace point counters. +With a numeric @var{identifier} parameter, creates a new a trace point counter +and associates it with that identifier. + +@emph{Important:} The identifier and the trace point number +are not related except by this command. +These trace point numbers always start at zero (from server startup, +or after @command{trace point clear}) and count up from there. +@end deffn + + @node JTAG Commands @chapter JTAG Commands @cindex JTAG Commands @@ -5622,10 +5762,10 @@ @item @b{arm7_9 fast_writes} @cindex arm7_9 fast_writes @*Use @command{arm7_9 fast_memory_access} instead. +@xref{arm7_9 fast_memory_access}. @item @b{endstate} @cindex endstate @*An buggy old command that would not really work since background polling would wipe out the global endstate -@xref{arm7_9 fast_memory_access}. @item @b{arm7_9 force_hw_bkpts} @*Use @command{gdb_breakpoint_override} instead. Note that GDB will use hardware breakpoints for flash if the GDB memory map has been set up(default when flash is declared in |
From: <du...@ma...> - 2009-06-28 05:09:19
|
Author: duane Date: 2009-06-28 05:09:15 +0200 (Sun, 28 Jun 2009) New Revision: 2411 Modified: trunk/src/target/target.c Log: Remove extra newline from debug log message Modified: trunk/src/target/target.c =================================================================== --- trunk/src/target/target.c 2009-06-28 02:54:19 UTC (rev 2410) +++ trunk/src/target/target.c 2009-06-28 03:09:15 UTC (rev 2411) @@ -3391,7 +3391,7 @@ while (teap) { if (teap->event == e) { done = 1; - LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s\n", + LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s", target->target_number, target->cmd_name, target_get_name(target), |
From: <du...@ma...> - 2009-06-28 04:54:23
|
Author: duane Date: 2009-06-28 04:54:19 +0200 (Sun, 28 Jun 2009) New Revision: 2410 Modified: trunk/src/server/gdb_server.c Log: A bit more log detail about connections comming and going Modified: trunk/src/server/gdb_server.c =================================================================== --- trunk/src/server/gdb_server.c 2009-06-28 02:40:08 UTC (rev 2409) +++ trunk/src/server/gdb_server.c 2009-06-28 02:54:19 UTC (rev 2410) @@ -803,6 +803,10 @@ target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_ATTACH); gdb_actual_connections++; + LOG_DEBUG("New GDB Connection: %d, Target %s, state: %s", + gdb_actual_connections, + gdb_service->target->cmd_name, + target_state_name(gdb_service->target)); return ERROR_OK; } @@ -813,6 +817,10 @@ gdb_connection_t *gdb_connection = connection->priv; gdb_actual_connections--; + LOG_DEBUG("GDB Close, Target: %s, state: %s, gdb_actual_connections=%d", + gdb_service->target->cmd_name, + target_state_name(gdb_service->target), + gdb_actual_connections); /* see if an image built with vFlash commands is left */ if (gdb_connection->vflash_image) |
From: <du...@ma...> - 2009-06-28 04:40:17
|
Author: duane Date: 2009-06-28 04:40:08 +0200 (Sun, 28 Jun 2009) New Revision: 2409 Modified: trunk/src/target/arm11.c trunk/src/target/arm7_9_common.c trunk/src/target/cortex_m3.c trunk/src/target/mips_m4k.c trunk/src/target/target.c trunk/src/target/target.h trunk/src/target/xscale.c Log: Refactor code, create target_state_name() Modified: trunk/src/target/arm11.c =================================================================== --- trunk/src/target/arm11.c 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/arm11.c 2009-06-28 02:40:08 UTC (rev 2409) @@ -732,7 +732,7 @@ arm11_common_t * arm11 = target->arch_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (target->state == TARGET_UNKNOWN) { @@ -789,7 +789,7 @@ arm11_common_t * arm11 = target->arch_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (target->state != TARGET_HALTED) @@ -889,7 +889,7 @@ FNC_INFO; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (target->state != TARGET_HALTED) { @@ -1035,7 +1035,7 @@ #if 0 LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); /* deassert reset lines */ Modified: trunk/src/target/arm7_9_common.c =================================================================== --- trunk/src/target/arm7_9_common.c 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/arm7_9_common.c 2009-06-28 02:40:08 UTC (rev 2409) @@ -992,7 +992,7 @@ armv4_5_common_t *armv4_5 = target->arch_info; arm7_9_common_t *arm7_9 = armv4_5->arch_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name); + target_state_name(target)); enum reset_types jtag_reset_config = jtag_get_reset_config(); if (!(jtag_reset_config & RESET_HAS_SRST)) @@ -1062,7 +1062,7 @@ { int retval = ERROR_OK; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name); + target_state_name(target)); /* deassert reset lines */ jtag_add_reset(0, 0); @@ -1275,7 +1275,7 @@ reg_t *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL]; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name); + target_state_name(target)); if (target->state == TARGET_HALTED) { Modified: trunk/src/target/cortex_m3.c =================================================================== --- trunk/src/target/cortex_m3.c 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/cortex_m3.c 2009-06-28 02:40:08 UTC (rev 2409) @@ -444,7 +444,7 @@ LOG_DEBUG("entered debug state in core mode: %s at PC 0x%" PRIx32 ", target->state: %s", armv7m_mode_strings[armv7m->core_mode], *(uint32_t*)(armv7m->core_cache->reg_list[15].value), - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (armv7m->post_debug_entry) armv7m->post_debug_entry(target); @@ -520,7 +520,7 @@ #if 0 /* Read Debug Fault Status Register, added to figure out the lockup when running flashtest.script */ mem_ap_read_atomic_u32(swjdp, NVIC_DFSR, &cortex_m3->nvic_dfsr); - LOG_DEBUG("dcb_dhcsr 0x%x, nvic_dfsr 0x%x, target->state: %s", cortex_m3->dcb_dhcsr, cortex_m3->nvic_dfsr, Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + LOG_DEBUG("dcb_dhcsr 0x%x, nvic_dfsr 0x%x, target->state: %s", cortex_m3->dcb_dhcsr, cortex_m3->nvic_dfsr, target_state_name(target)); #endif return ERROR_OK; @@ -529,7 +529,7 @@ int cortex_m3_halt(target_t *target) { LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (target->state == TARGET_HALTED) { @@ -753,7 +753,7 @@ int assert_srst = 1; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); enum reset_types jtag_reset_config = jtag_get_reset_config(); if (!(jtag_reset_config & RESET_HAS_SRST)) @@ -864,7 +864,7 @@ int cortex_m3_deassert_reset(target_t *target) { LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); /* deassert reset lines */ jtag_add_reset(0, 0); Modified: trunk/src/target/mips_m4k.c =================================================================== --- trunk/src/target/mips_m4k.c 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/mips_m4k.c 2009-06-28 02:40:08 UTC (rev 2409) @@ -148,7 +148,7 @@ LOG_DEBUG("entered debug state at PC 0x%" PRIx32 ", target->state: %s", *(uint32_t*)(mips32->core_cache->reg_list[MIPS32_PC].value), - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); return ERROR_OK; } @@ -220,7 +220,7 @@ mips_ejtag_t *ejtag_info = &mips32->ejtag_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (target->state == TARGET_HALTED) { @@ -265,7 +265,7 @@ mips_ejtag_t *ejtag_info = &mips32->ejtag_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); enum reset_types jtag_reset_config = jtag_get_reset_config(); if (!(jtag_reset_config & RESET_HAS_SRST)) @@ -324,7 +324,7 @@ int mips_m4k_deassert_reset(target_t *target) { LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); /* deassert reset lines */ jtag_add_reset(0, 0); Modified: trunk/src/target/target.c =================================================================== --- trunk/src/target/target.c 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/target.c 2009-06-28 02:40:08 UTC (rev 2409) @@ -237,6 +237,18 @@ { .name = NULL , .value = -1 }, }; +const char * +target_state_name( target_t *t ) +{ + const char *cp; + cp = Jim_Nvp_value2name_simple(nvp_target_state, t->state)->name; + if( !cp ){ + LOG_ERROR("Invalid target state: %d", (int)(t->state)); + cp = "(*BUG*unknown*BUG*)"; + } + return cp; +} + static int max_target_number(void) { target_t *t; @@ -1085,8 +1097,7 @@ return ERROR_OK; } - LOG_USER("target state: %s", - Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name); + LOG_USER("target state: %s", target_state_name( target )); if (target->state != TARGET_HALTED) return ERROR_OK; @@ -1544,8 +1555,7 @@ char marker = ' '; if (target->tap->enabled) - state = Jim_Nvp_value2name_simple(nvp_target_state, - target->state)->name; + state = target_state_name( target ); else state = "tap-disabled"; @@ -4079,7 +4089,8 @@ return JIM_ERR; } Jim_SetResultString(goi.interp, - Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name,-1); + target_state_name( target ), + -1); return JIM_OK; case TS_CMD_INVOKE_EVENT: if (goi.argc != 1) { Modified: trunk/src/target/target.h =================================================================== --- trunk/src/target/target.h 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/target.h 2009-06-28 02:40:08 UTC (rev 2409) @@ -42,8 +42,12 @@ * TARGET_RESET = 3: the target is being held in reset (only a temporary state, * not sure how this is used with all the recent changes) * TARGET_DEBUG_RUNNING = 4: the target is running, but it is executing code on - * behalf of the debugger (e.g. algorithm for flashing) */ + * behalf of the debugger (e.g. algorithm for flashing) + * + * also see: target_state_name(); + */ + enum target_state { TARGET_UNKNOWN = 0, @@ -131,6 +135,7 @@ struct working_area_s *working_areas;/* list of allocated working areas */ enum target_debug_reason debug_reason;/* reason why the target entered debug state */ enum target_endianess endianness; /* target endianess */ + // also see: target_state_name() enum target_state state; /* the current backend-state (running, halted, ...) */ struct reg_cache_s *reg_cache; /* the first register cache of the target (core regs) */ struct breakpoint_s *breakpoints; /* list of breakpoints */ @@ -357,6 +362,9 @@ extern int target_blank_check_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t* blank); extern int target_wait_state(target_t *target, enum target_state state, int ms); +/** Return the *name* of this targets current state */ +const char *target_state_name( target_t *target ); + /* DANGER!!!!! * * if "area" passed in to target_alloc_working_area() points to a memory Modified: trunk/src/target/xscale.c =================================================================== --- trunk/src/target/xscale.c 2009-06-27 17:25:07 UTC (rev 2408) +++ trunk/src/target/xscale.c 2009-06-28 02:40:08 UTC (rev 2409) @@ -1202,7 +1202,7 @@ xscale_common_t *xscale = armv4_5->arch_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); if (target->state == TARGET_HALTED) { @@ -1568,7 +1568,7 @@ xscale_common_t *xscale = armv4_5->arch_info; LOG_DEBUG("target->state: %s", - Jim_Nvp_value2name_simple(nvp_target_state, target->state)->name); + target_state_name(target)); /* select DCSR instruction (set endstate to R-T-I to ensure we don't * end up in T-L-R, which would reset JTAG |
From: <du...@ma...> - 2009-06-27 19:25:24
|
Author: duane Date: 2009-06-27 19:25:07 +0200 (Sat, 27 Jun 2009) New Revision: 2408 Modified: trunk/src/target/arm7_9_common.c trunk/src/target/breakpoints.c trunk/src/target/breakpoints.h trunk/src/target/cortex_m3.c trunk/src/target/mips_m4k.c Log: Add Breakpoint/Watchpoint unique ID to help debug hardware debug register leakage Modified: trunk/src/target/arm7_9_common.c =================================================================== --- trunk/src/target/arm7_9_common.c 2009-06-27 16:51:41 UTC (rev 2407) +++ trunk/src/target/arm7_9_common.c 2009-06-27 17:25:07 UTC (rev 2408) @@ -58,6 +58,7 @@ */ static int arm7_9_clear_watchpoints(arm7_9_common_t *arm7_9) { + LOG_DEBUG("-"); embeddedice_write_reg(&arm7_9->eice_cache->reg_list[EICE_W0_CONTROL_VALUE], 0x0); embeddedice_write_reg(&arm7_9->eice_cache->reg_list[EICE_W1_CONTROL_VALUE], 0x0); arm7_9->sw_breakpoints_added = 0; @@ -93,6 +94,10 @@ { LOG_ERROR("BUG: no hardware comparator available"); } + LOG_DEBUG("BPID: %d (0x%08" PRIx32 ") using hw wp: %d", + breakpoint->unique_id, + breakpoint->address, + breakpoint->set ); } /** @@ -152,6 +157,8 @@ LOG_ERROR("BUG: both watchpoints used, but wp_available >= 1"); return ERROR_FAIL; } + LOG_DEBUG("SW BP using hw wp: %d", + arm7_9->sw_breakpoints_added ); return jtag_execute_queue(); } @@ -220,6 +227,10 @@ arm7_9_common_t *arm7_9 = armv4_5->arch_info; int retval = ERROR_OK; + LOG_DEBUG("BPID: %d, Address: 0x%08" PRIx32, + breakpoint->unique_id, + breakpoint->address ); + if (target->state != TARGET_HALTED) { LOG_WARNING("target not halted"); @@ -343,6 +354,10 @@ armv4_5_common_t *armv4_5 = target->arch_info; arm7_9_common_t *arm7_9 = armv4_5->arch_info; + LOG_DEBUG("BPID: %d, Address: 0x%08" PRIx32, + breakpoint->unique_id, + breakpoint->address ); + if (!breakpoint->set) { LOG_WARNING("breakpoint not set"); @@ -351,6 +366,9 @@ if (breakpoint->type == BKPT_HARD) { + LOG_DEBUG("BPID: %d Releasing hw wp: %d", + breakpoint->unique_id, + breakpoint->set ); if (breakpoint->set == 1) { embeddedice_set_reg(&arm7_9->eice_cache->reg_list[EICE_W0_CONTROL_VALUE], 0x0); @@ -1807,7 +1825,7 @@ { if ((breakpoint = breakpoint_find(target, buf_get_u32(armv4_5->core_cache->reg_list[15].value, 0, 32)))) { - LOG_DEBUG("unset breakpoint at 0x%8.8" PRIx32 "", breakpoint->address); + LOG_DEBUG("unset breakpoint at 0x%8.8" PRIx32 " (id: %d)", breakpoint->address, breakpoint->unique_id ); if ((retval = arm7_9_unset_breakpoint(target, breakpoint)) != ERROR_OK) { return retval; Modified: trunk/src/target/breakpoints.c =================================================================== --- trunk/src/target/breakpoints.c 2009-06-27 16:51:41 UTC (rev 2407) +++ trunk/src/target/breakpoints.c 2009-06-27 17:25:07 UTC (rev 2408) @@ -39,16 +39,25 @@ "access" }; +// monotonic counter/id-number for breakpoints and watch points +static int bpwp_unique_id; + int breakpoint_add(target_t *target, uint32_t address, uint32_t length, enum breakpoint_type type) { breakpoint_t *breakpoint = target->breakpoints; breakpoint_t **breakpoint_p = &target->breakpoints; int retval; + int n; + n = 0; while (breakpoint) { - if (breakpoint->address == address) + n++; + if (breakpoint->address == address){ + LOG_DEBUG("Duplicate Breakpoint address: 0x%08" PRIx32 " (BP %d)", + address, breakpoint->unique_id ); return ERROR_OK; + } breakpoint_p = &breakpoint->next; breakpoint = breakpoint->next; } @@ -60,20 +69,25 @@ (*breakpoint_p)->set = 0; (*breakpoint_p)->orig_instr = malloc(length); (*breakpoint_p)->next = NULL; + (*breakpoint_p)->unique_id = bpwp_unique_id++; if ((retval = target_add_breakpoint(target, *breakpoint_p)) != ERROR_OK) { switch (retval) { case ERROR_TARGET_RESOURCE_NOT_AVAILABLE: - LOG_INFO("can't add %s breakpoint, resource not available", breakpoint_type_strings[(*breakpoint_p)->type]); + LOG_INFO("can't add %s breakpoint, resource not available (BPID=%d)", + breakpoint_type_strings[(*breakpoint_p)->type], + (*breakpoint_p)->unique_id ); + free((*breakpoint_p)->orig_instr); free(*breakpoint_p); *breakpoint_p = NULL; return retval; break; case ERROR_TARGET_NOT_HALTED: - LOG_INFO("can't add breakpoint while target is running"); + LOG_INFO("can't add breakpoint while target is running (BPID: %d)", + (*breakpoint_p)->unique_id ); free((*breakpoint_p)->orig_instr); free(*breakpoint_p); *breakpoint_p = NULL; @@ -84,9 +98,10 @@ } } - LOG_DEBUG("added %s breakpoint at 0x%8.8" PRIx32 " of length 0x%8.8x", - breakpoint_type_strings[(*breakpoint_p)->type], - (*breakpoint_p)->address, (*breakpoint_p)->length); + LOG_DEBUG("added %s breakpoint at 0x%8.8" PRIx32 " of length 0x%8.8x, (BPID: %d)", + breakpoint_type_strings[(*breakpoint_p)->type], + (*breakpoint_p)->address, (*breakpoint_p)->length, + (*breakpoint_p)->unique_id ); return ERROR_OK; } @@ -110,6 +125,7 @@ target_remove_breakpoint(target, breakpoint); + LOG_DEBUG("BPID: %d", breakpoint->unique_id ); (*breakpoint_p) = breakpoint->next; free(breakpoint->orig_instr); free(breakpoint); @@ -141,6 +157,7 @@ void breakpoint_clear_target(target_t *target) { breakpoint_t *breakpoint; + LOG_DEBUG("Delete all breakpoints for target: %s", target_get_name( target )); while ((breakpoint = target->breakpoints) != NULL) { breakpoint_free(target, breakpoint); @@ -183,19 +200,23 @@ (*watchpoint_p)->rw = rw; (*watchpoint_p)->set = 0; (*watchpoint_p)->next = NULL; + (*watchpoint_p)->unique_id = bpwp_unique_id++; if ((retval = target_add_watchpoint(target, *watchpoint_p)) != ERROR_OK) { switch (retval) { case ERROR_TARGET_RESOURCE_NOT_AVAILABLE: - LOG_INFO("can't add %s watchpoint, resource not available", watchpoint_rw_strings[(*watchpoint_p)->rw]); + LOG_INFO("can't add %s watchpoint, resource not available (WPID: %d)", + watchpoint_rw_strings[(*watchpoint_p)->rw], + (*watchpoint_p)->unique_id ); free (*watchpoint_p); *watchpoint_p = NULL; return retval; break; case ERROR_TARGET_NOT_HALTED: - LOG_INFO("can't add watchpoint while target is running"); + LOG_INFO("can't add watchpoint while target is running (WPID: %d)", + (*watchpoint_p)->unique_id ); free (*watchpoint_p); *watchpoint_p = NULL; return retval; @@ -207,9 +228,11 @@ } } - LOG_DEBUG("added %s watchpoint at 0x%8.8" PRIx32 " of length 0x%8.8x", - watchpoint_rw_strings[(*watchpoint_p)->rw], - (*watchpoint_p)->address, (*watchpoint_p)->length); + LOG_DEBUG("added %s watchpoint at 0x%8.8" PRIx32 " of length 0x%8.8x (WPID: %d)", + watchpoint_rw_strings[(*watchpoint_p)->rw], + (*watchpoint_p)->address, + (*watchpoint_p)->length, + (*watchpoint_p)->unique_id ); return ERROR_OK; } @@ -230,6 +253,7 @@ if (watchpoint == NULL) return; target_remove_watchpoint(target, watchpoint); + LOG_DEBUG("WPID: %d", watchpoint->unique_id ); (*watchpoint_p) = watchpoint->next; free(watchpoint); } @@ -260,6 +284,7 @@ void watchpoint_clear_target(target_t *target) { watchpoint_t *watchpoint; + LOG_DEBUG("Delete all watchpoints for target: %s", target_get_name( target )); while ((watchpoint = target->watchpoints) != NULL) { watchpoint_free(target, watchpoint); Modified: trunk/src/target/breakpoints.h =================================================================== --- trunk/src/target/breakpoints.h 2009-06-27 16:51:41 UTC (rev 2407) +++ trunk/src/target/breakpoints.h 2009-06-27 17:25:07 UTC (rev 2408) @@ -43,6 +43,7 @@ int set; uint8_t *orig_instr; struct breakpoint_s *next; + int unique_id; } breakpoint_t; typedef struct watchpoint_s @@ -54,6 +55,7 @@ enum watchpoint_rw rw; int set; struct watchpoint_s *next; + int unique_id; } watchpoint_t; extern void breakpoint_clear_target(struct target_s *target); Modified: trunk/src/target/cortex_m3.c =================================================================== --- trunk/src/target/cortex_m3.c 2009-06-27 16:51:41 UTC (rev 2407) +++ trunk/src/target/cortex_m3.c 2009-06-27 17:25:07 UTC (rev 2408) @@ -664,7 +664,9 @@ /* Single step past breakpoint at current address */ if ((breakpoint = breakpoint_find(target, resume_pc))) { - LOG_DEBUG("unset breakpoint at 0x%8.8" PRIx32 "", breakpoint->address); + LOG_DEBUG("unset breakpoint at 0x%8.8" PRIx32 " (ID: %d)", + breakpoint->address, + breakpoint->unique_id ); cortex_m3_unset_breakpoint(target, breakpoint); cortex_m3_single_step_core(target); cortex_m3_set_breakpoint(target, breakpoint); @@ -897,7 +899,7 @@ if (breakpoint->set) { - LOG_WARNING("breakpoint already set"); + LOG_WARNING("breakpoint (BPID: %d) already set", breakpoint->unique_id); return ERROR_OK; } @@ -943,6 +945,13 @@ breakpoint->set = 0x11; /* Any nice value but 0 */ } + LOG_DEBUG("BPID: %d, Type: %d, Address: 0x%08" PRIx32 " Length: %d (set=%d)", + breakpoint->unique_id, + (int)(breakpoint->type), + breakpoint->address, + breakpoint->length, + breakpoint->set); + return ERROR_OK; } @@ -960,6 +969,13 @@ return ERROR_OK; } + LOG_DEBUG("BPID: %d, Type: %d, Address: 0x%08" PRIx32 " Length: %d (set=%d)", + breakpoint->unique_id, + (int)(breakpoint->type), + breakpoint->address, + breakpoint->length, + breakpoint->set); + if (breakpoint->type == BKPT_HARD) { int fp_num = breakpoint->set - 1; @@ -1085,7 +1101,7 @@ if (watchpoint->set) { - LOG_WARNING("watchpoint already set"); + LOG_WARNING("watchpoint (%d) already set", watchpoint->unique_id ); return ERROR_OK; } @@ -1118,10 +1134,13 @@ } else { - LOG_WARNING("Cannot watch data values"); /* Move this test to add_watchpoint */ + /* Move this test to add_watchpoint */ + LOG_WARNING("Cannot watch data values (id: %d)", + watchpoint->unique_id ); return ERROR_OK; } - + LOG_DEBUG("Watchpoint (ID: %d) address: 0x%08" PRIx32 " set=%d ", + watchpoint->unique_id, watchpoint->address, watchpoint->set ); return ERROR_OK; } @@ -1136,10 +1155,13 @@ if (!watchpoint->set) { - LOG_WARNING("watchpoint not set"); + LOG_WARNING("watchpoint (wpid: %d) not set", watchpoint->unique_id ); return ERROR_OK; } + LOG_DEBUG("Watchpoint (ID: %d) address: 0x%08" PRIx32 " set=%d ", + watchpoint->unique_id, watchpoint->address,watchpoint->set ); + dwt_num = watchpoint->set - 1; if ((dwt_num < 0) || (dwt_num >= cortex_m3->dwt_num_comp)) @@ -1179,6 +1201,7 @@ } cortex_m3->dwt_comp_available--; + LOG_DEBUG("dwt_comp_available: %d", cortex_m3->dwt_comp_available); return ERROR_OK; } @@ -1201,6 +1224,7 @@ } cortex_m3->dwt_comp_available++; + LOG_DEBUG("dwt_comp_available: %d", cortex_m3->dwt_comp_available); return ERROR_OK; } Modified: trunk/src/target/mips_m4k.c =================================================================== --- trunk/src/target/mips_m4k.c 2009-06-27 16:51:41 UTC (rev 2407) +++ trunk/src/target/mips_m4k.c 2009-06-27 17:25:07 UTC (rev 2408) @@ -513,7 +513,8 @@ bp_num++; if (bp_num >= mips32->num_inst_bpoints) { - LOG_DEBUG("ERROR Can not find free FP Comparator"); + LOG_DEBUG("ERROR Can not find free FP Comparator(bpid: %d)", + breakpoint->unique_id ); LOG_WARNING("ERROR Can not find free FP Comparator"); exit(-1); } @@ -523,10 +524,13 @@ target_write_u32(target, comparator_list[bp_num].reg_address, comparator_list[bp_num].bp_value); target_write_u32(target, comparator_list[bp_num].reg_address + 0x08, 0x00000000); target_write_u32(target, comparator_list[bp_num].reg_address + 0x18, 1); - LOG_DEBUG("bp_num %i bp_value 0x%" PRIx32 "", bp_num, comparator_list[bp_num].bp_value); + LOG_DEBUG("bpid: %d, bp_num %i bp_value 0x%" PRIx32 "", + breakpoint->unique_id, + bp_num, comparator_list[bp_num].bp_value); } else if (breakpoint->type == BKPT_SOFT) { + LOG_DEBUG("bpid: %d", breakpoint->unique_id ); if (breakpoint->length == 4) { uint32_t verify = 0xffffffff; @@ -598,16 +602,22 @@ int bp_num = breakpoint->set - 1; if ((bp_num < 0) || (bp_num >= mips32->num_inst_bpoints)) { - LOG_DEBUG("Invalid FP Comparator number in breakpoint"); + LOG_DEBUG("Invalid FP Comparator number in breakpoint (bpid: %d)", + breakpoint->unique_id); return ERROR_OK; } + LOG_DEBUG("bpid: %d - releasing hw: %d", + breakpoint->unique_id, + bp_num ); comparator_list[bp_num].used = 0; comparator_list[bp_num].bp_value = 0; target_write_u32(target, comparator_list[bp_num].reg_address + 0x18, 0); + } else { /* restore original instruction (kept in target endianness) */ + LOG_DEBUG("bpid: %d", breakpoint->unique_id); if (breakpoint->length == 4) { uint32_t current_instr; |
From: <du...@ma...> - 2009-06-27 18:51:47
|
Author: duane Date: 2009-06-27 18:51:41 +0200 (Sat, 27 Jun 2009) New Revision: 2407 Modified: trunk/src/flash/at91sam3.c Log: Change from alloca() to malloc() Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-27 16:44:35 UTC (rev 2406) +++ trunk/src/flash/at91sam3.c 2009-06-27 16:51:41 UTC (rev 2407) @@ -2121,19 +2121,25 @@ struct sam3_bank_private *pPrivate; uint8_t *pagebuffer; + // incase we bail further below, set this to null + pagebuffer = NULL; + // ignore dumb requests if (count == 0) { - return ERROR_OK; + r = ERROR_OK; + goto done; } if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); - return ERROR_TARGET_NOT_HALTED; + r = ERROR_TARGET_NOT_HALTED; + goto done; } pPrivate = get_sam3_bank_private(bank); if (!(pPrivate->probed)) { - return ERROR_FLASH_BANK_NOT_PROBED; + r = ERROR_FLASH_BANK_NOT_PROBED; + goto done; } @@ -2143,10 +2149,16 @@ (unsigned int)(offset), (unsigned int)(count), (unsigned int)(pPrivate->size_bytes)); - return ERROR_FAIL; + r = ERROR_FAIL; + goto done; } - pagebuffer = alloca(pPrivate->page_size); + pagebuffer = malloc(pPrivate->page_size); + if( !pagebuffer ){ + LOG_ERROR("No memory for %d Byte page buffer", (int)(pPrivate->page_size)); + r = ERROR_FAIL; + goto done; + } // what page do we start & end in? page_cur = offset / pPrivate->page_size; @@ -2167,7 +2179,7 @@ LOG_DEBUG("Special case, all in one page"); r = sam3_page_read(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { - return r; + goto done; } page_offset = (offset & (pPrivate->page_size-1)); @@ -2177,9 +2189,10 @@ r = sam3_page_write(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { - return r; + goto done; } - return ERROR_OK; + r = ERROR_OK; + goto done; } // non-aligned start @@ -2189,7 +2202,7 @@ // read the partial r = sam3_page_read(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { - return r; + goto done; } // over-write with new data @@ -2200,7 +2213,7 @@ r = sam3_page_write(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { - return r; + goto done; } count -= n; @@ -2219,7 +2232,7 @@ (count >= pPrivate->page_size)) { r = sam3_page_write(pPrivate, page_cur, buffer); if (r != ERROR_OK) { - return r; + goto done; } count -= pPrivate->page_size; buffer += pPrivate->page_size; @@ -2232,19 +2245,24 @@ // we have a partial page r = sam3_page_read(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { - return r; + goto done; } // data goes at start memcpy(pagebuffer, buffer, count); r = sam3_page_write(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { - return r; + goto done; } buffer += count; count -= count; } LOG_DEBUG("Done!"); - return ERROR_OK; + r = ERROR_OK; + done: + if( pagebuffer ){ + free(pagebuffer); + } + return r; } static int |
From: <du...@ma...> - 2009-06-27 18:44:38
|
Author: duane Date: 2009-06-27 18:44:35 +0200 (Sat, 27 Jun 2009) New Revision: 2406 Modified: trunk/src/helper/membuf.c Log: Switch to strotk() grr.... Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-26 12:57:56 UTC (rev 2405) +++ trunk/src/helper/membuf.c 2009-06-27 16:44:35 UTC (rev 2406) @@ -58,11 +58,13 @@ if (pBuf) { pBuf->_strtoklast = NULL; *pLast = pBuf; - return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast)); + // this should be "strtok_r()" but windows lacks */ + return strtok(((char *)(pBuf->buf)), sep); } else { // recover our pBuf pBuf = *((struct membuf **)(pLast)); - return strtok_r(NULL, sep, &(pBuf->_strtoklast)); + // this should be "strtok_r()" but windows lacks */ + return strtok( NULL, sep); } } |
From: oharboe at B. <oh...@ma...> - 2009-06-26 14:57:59
|
Author: oharboe Date: 2009-06-26 14:57:56 +0200 (Fri, 26 Jun 2009) New Revision: 2405 Modified: trunk/src/jtag/zy1000/zy1000.c zy1000/trunk/build/menu/zy1000menu.xml zy1000/trunk/build/tcl/openocd.cfg zy1000/trunk/build/tcl/upgrade.tcl Log: zy1000 rev C work Modified: trunk/src/jtag/zy1000/zy1000.c =================================================================== --- trunk/src/jtag/zy1000/zy1000.c 2009-06-26 07:30:21 UTC (rev 2404) +++ trunk/src/jtag/zy1000/zy1000.c 2009-06-26 12:57:56 UTC (rev 2405) @@ -283,6 +283,14 @@ { version_str = ZYLIN_DATE; } + else if (strcmp("pcb", str) == 0) + { +#ifdef CYGPKG_HAL_NIOS2 + version_str="c"; +#else + version_str="b"; +#endif + } else { return JIM_ERR; @@ -295,6 +303,37 @@ } +#ifdef CYGPKG_HAL_NIOS2 +static int jim_zy1000_writefirmware(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + if (argc != 2) + return JIM_ERR; + + int length; + int stat; + const char *str = Jim_GetString(argv[1], &length); + + /* BUG!!!! skip header! */ + void *firmware_address=0x4000000; + int firmware_length=0x100000; + + if (length>firmware_length) + return JIM_ERR; + + void *err_addr; + + if ((stat = flash_erase((void *)firmware_address, firmware_length, (void **)&err_addr)) != 0) + { + return JIM_ERR; + } + + if ((stat = flash_program(firmware_address, str, length, (void **)&err_addr)) != 0) + return JIM_ERR; + + return JIM_OK; +} +#endif + static int zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp, int argc, @@ -324,6 +363,11 @@ Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL); +#ifdef CYGPKG_HAL_NIOS2 + Jim_CreateCommand(interp, "updatezy1000firmware", jim_zy1000_writefirmware, NULL, NULL); +#endif + + return ERROR_OK; } Modified: zy1000/trunk/build/menu/zy1000menu.xml =================================================================== --- zy1000/trunk/build/menu/zy1000menu.xml 2009-06-26 07:30:21 UTC (rev 2404) +++ zy1000/trunk/build/menu/zy1000menu.xml 2009-06-26 12:57:56 UTC (rev 2405) @@ -41,6 +41,7 @@ Version<br> OpenOCD ver.<br> Build date<br> + PCB<br> Current IP<br> GDB Port </td> @@ -65,6 +66,7 @@ <tcl>append buffer [zy1000_version zy1000]</tcl><br> <tcl>append buffer [zy1000_version openocd]</tcl><br> <tcl>append buffer [zy1000_version date]</tcl><br> + <tcl>append buffer [zy1000_version pcb]</tcl><br> <tcl>append buffer [ip]</tcl><br> <tcl>append buffer [ocd_gdb_port]</tcl> </td> @@ -1252,13 +1254,8 @@ append buffer {<form enctype="multipart/form-data" action="upgrade.tcl" method="post">} if {[string compare $form_action "Upload"]==0} { - if [string match ZylinPhiFirmware* $form_filecontent]==1 { - set form_filename /config/firmware.phi - puts "Writing firmware to $form_filename" - set fp [aio.open $form_filename w]; - $fp puts -nonewline $form_filecontent - $fp close - puts "Done writing firmware to $form_filename" + if {[check_firmware $form_filecontent]} { + write_firmware $form_filecontent append buffer "<br><div style='font-size:14px;'>Upgraded Zylin JTAG, rebooting (wait ca. 30 seconds)...</div><br>" reboot } else { Modified: zy1000/trunk/build/tcl/openocd.cfg =================================================================== --- zy1000/trunk/build/tcl/openocd.cfg 2009-06-26 07:30:21 UTC (rev 2404) +++ zy1000/trunk/build/tcl/openocd.cfg 2009-06-26 12:57:56 UTC (rev 2405) @@ -134,6 +134,38 @@ global startup_status set startup_status 0 +if {[string compare [zy1000_version pcb] b]==0} { + + proc check_firmware {fw} { + return [expr [string match ZylinPhiFirmware* $fw]==1] + } + + proc write_firmware {fw} { + set form_filename /config/firmware.phi + + puts "Writing firmware to $form_filename" + + set fp [aio.open $form_filename w]; + $fp puts -nonewline $fw + $fp close + + puts "Done writing firmware to $form_filename" + } +} else { + proc check_firmware {fw} { + return [expr [string match CZylinPhiFirmware* $fw]==1] + } + + # pcb revision C, nios firmware + proc write_firmware {fw} { + # write to flash directly + puts "Writing firmware to flash" + updatezy1000firmware $fw + puts "Done writing firmware to flash" + } +} + + # Here we do *not* catch the error since we want the file & line number to appear # in the log script /config/settings/openocd.cfg @@ -143,3 +175,5 @@ # init is run from C code so we can propagate any exception in this # script easily. + + Modified: zy1000/trunk/build/tcl/upgrade.tcl =================================================================== --- zy1000/trunk/build/tcl/upgrade.tcl 2009-06-26 07:30:21 UTC (rev 2404) +++ zy1000/trunk/build/tcl/upgrade.tcl 2009-06-26 12:57:56 UTC (rev 2405) @@ -191,13 +191,8 @@ append buffer {<form enctype="multipart/form-data" action="upgrade.tcl" method="post">} if {[string compare $form_action "Upload"]==0} { - if [string match ZylinPhiFirmware* $form_filecontent]==1 { - set form_filename /config/firmware.phi - puts "Writing firmware to $form_filename" - set fp [aio.open $form_filename w]; - $fp puts -nonewline $form_filecontent - $fp close - puts "Done writing firmware to $form_filename" + if {[check_firmware $form_filecontent]} { + write_firmware $form_filecontent append buffer "<br><div style='font-size:14px;'>Upgraded Zylin JTAG, rebooting (wait ca. 30 seconds)...</div><br>" reboot } else { |
From: oharboe at B. <oh...@ma...> - 2009-06-26 09:30:26
|
Author: oharboe Date: 2009-06-26 09:30:21 +0200 (Fri, 26 Jun 2009) New Revision: 2404 Modified: trunk/doc/openocd.texi Log: David Brownell <da...@pa...> Add a short chapter on boundary scan support, which currently just documents the SVF and XSVF commands. Modified: trunk/doc/openocd.texi =================================================================== --- trunk/doc/openocd.texi 2009-06-25 15:11:57 UTC (rev 2403) +++ trunk/doc/openocd.texi 2009-06-26 07:30:21 UTC (rev 2404) @@ -78,6 +78,7 @@ * General Commands:: General Commands * Architecture and Core Commands:: Architecture and Core Commands * JTAG Commands:: JTAG Commands +* Boundary Scan Commands:: Boundary Scan Commands * TFTP:: TFTP * GDB and OpenOCD:: Using GDB and OpenOCD * Tcl Scripting API:: Tcl Scripting API @@ -850,7 +851,7 @@ A simple way to organize them all involves keeping a single directory for your work with a given board. When you start OpenOCD from that directory, -it searches there first for configuration files +it searches there first for configuration files, scripts, and for code you upload to the target board. It is also the natural place to write files, such as log files and data you download from the board. @@ -5353,6 +5354,53 @@ Consult the documentation for the TAP(s) you are working with. @end itemize +@node Boundary Scan Commands +@chapter Boundary Scan Commands + +One of the original purposes of JTAG was to support +boundary scan based hardware testing. +Although its primary focus is to support On-Chip Debugging, +OpenOCD also includes some boundary scan commands. + +@section SVF: Serial Vector Format +@cindex Serial Vector Format +@cindex SVF + +The Serial Vector Format, better known as @dfn{SVF}, is a +way to represent JTAG test patterns in text files. +OpenOCD supports running such test files. + +@deffn Command {svf} filename [@option{quiet}] +This issues a JTAG reset (Test-Logic-Reset) and then +runs the SVF script from @file{filename}. +Unless the @option{quiet} option is specified, +each command is logged before it is executed. +@end deffn + +@section XSVF: Xilinx Serial Vector Format +@cindex Xilinx Serial Vector Format +@cindex XSVF + +The Xilinx Serial Vector Format, better known as @dfn{XSVF}, is a +binary representation of SVF which is optimized for use with +Xilinx devices. +OpenOCD supports running such test files. + +@quotation Important +Not all XSVF commands are supported. +@end quotation + +@deffn Command {xsvf} (tapname|@option{plain}) filename [@option{virt2}] [@option{quiet}] +This issues a JTAG reset (Test-Logic-Reset) and then +runs the XSVF script from @file{filename}. +When a @var{tapname} is specified, the commands are directed at +that TAP. +When @option{virt2} is specified, the @sc{xruntest} command counts +are interpreted as TCK cycles instead of microseconds. +Unless the @option{quiet} option is specified, +messages are logged for comments and some retries. +@end deffn + @node TFTP @chapter TFTP @cindex TFTP |
From: ntfreak at B. <nt...@ma...> - 2009-06-25 17:12:01
|
Author: ntfreak Date: 2009-06-25 17:11:57 +0200 (Thu, 25 Jun 2009) New Revision: 2403 Modified: trunk/src/server/gdb_server.c Log: - fix issue when using gdb_port cmd - bug introduced in r2240 Modified: trunk/src/server/gdb_server.c =================================================================== --- trunk/src/server/gdb_server.c 2009-06-25 12:18:07 UTC (rev 2402) +++ trunk/src/server/gdb_server.c 2009-06-25 15:11:57 UTC (rev 2403) @@ -2242,9 +2242,7 @@ return ERROR_OK; } - /* only if the port wasn't overwritten by cmdline */ - if (gdb_port == 0) - gdb_port = strtoul(args[0], NULL, 0); + gdb_port = strtoul(args[0], NULL, 0); return ERROR_OK; } |
From: oharboe at B. <oh...@ma...> - 2009-06-25 14:18:08
|
Author: oharboe Date: 2009-06-25 14:18:07 +0200 (Thu, 25 Jun 2009) New Revision: 2402 Modified: trunk/src/target/mips_ejtag.h trunk/src/target/mips_m4k.c Log: Oleksandr Tymoshenko <go...@bl...> simple watchpoint support for MIPS32/EJTAG (no value comparation yet). Modified: trunk/src/target/mips_ejtag.h =================================================================== --- trunk/src/target/mips_ejtag.h 2009-06-25 00:12:40 UTC (rev 2401) +++ trunk/src/target/mips_ejtag.h 2009-06-25 12:18:07 UTC (rev 2402) @@ -96,6 +96,11 @@ #define EJTAG_IBA1 0xFF301100 #define EJTAG_DBS 0xFF302000 #define EJTAG_DBA1 0xFF302100 +#define EJTAG_DBCn_NOSB (1 << 13) +#define EJTAG_DBCn_NOLB (1 << 12) +#define EJTAG_DBCn_BLM_MASK 0xff +#define EJTAG_DBCn_BLM_SHIFT 4 +#define EJTAG_DBCn_BE (1 << 0) typedef struct mips_ejtag_s { Modified: trunk/src/target/mips_m4k.c =================================================================== --- trunk/src/target/mips_m4k.c 2009-06-25 00:12:40 UTC (rev 2401) +++ trunk/src/target/mips_m4k.c 2009-06-25 12:18:07 UTC (rev 2402) @@ -693,25 +693,132 @@ int mips_m4k_set_watchpoint(struct target_s *target, watchpoint_t *watchpoint) { - /* TODO */ + mips32_common_t *mips32 = target->arch_info; + mips32_comparator_t * comparator_list = mips32->data_break_list; + int wp_num = 0; + /* + * watchpoint enabled, ignore all byte lanes in value register + * and exclude both load and store accesses from watchpoint + * condition evaluation + */ + int enable = EJTAG_DBCn_NOSB | EJTAG_DBCn_NOLB | EJTAG_DBCn_BE | + (0xff << EJTAG_DBCn_BLM_SHIFT); + + if (watchpoint->set) + { + LOG_WARNING("watchpoint already set"); + return ERROR_OK; + } + + while(comparator_list[wp_num].used && (wp_num < mips32->num_data_bpoints)) + wp_num++; + if (wp_num >= mips32->num_data_bpoints) + { + LOG_DEBUG("ERROR Can not find free FP Comparator"); + LOG_WARNING("ERROR Can not find free FP Comparator"); + exit(-1); + } + + if (watchpoint->length != 4) + { + LOG_ERROR("Only watchpoints of length 4 are supported"); + return ERROR_TARGET_UNALIGNED_ACCESS; + } + + if (watchpoint->address % 4) + { + LOG_ERROR("Watchpoints address should be word aligned"); + return ERROR_TARGET_UNALIGNED_ACCESS; + } + + switch (watchpoint->rw) + { + case WPT_READ: + enable &= ~EJTAG_DBCn_NOLB; + break; + case WPT_WRITE: + enable &= ~EJTAG_DBCn_NOSB; + break; + case WPT_ACCESS: + enable &= ~(EJTAG_DBCn_NOLB | EJTAG_DBCn_NOSB); + break; + default: + LOG_ERROR("BUG: watchpoint->rw neither read, write nor access"); + } + + watchpoint->set = wp_num + 1; + comparator_list[wp_num].used = 1; + comparator_list[wp_num].bp_value = watchpoint->address; + target_write_u32(target, comparator_list[wp_num].reg_address, comparator_list[wp_num].bp_value); + target_write_u32(target, comparator_list[wp_num].reg_address + 0x08, 0x00000000); + target_write_u32(target, comparator_list[wp_num].reg_address + 0x10, 0x00000000); + target_write_u32(target, comparator_list[wp_num].reg_address + 0x18, enable); + target_write_u32(target, comparator_list[wp_num].reg_address + 0x20, 0); + LOG_DEBUG("wp_num %i bp_value 0x%" PRIx32 "", wp_num, comparator_list[wp_num].bp_value); + return ERROR_OK; } int mips_m4k_unset_watchpoint(struct target_s *target, watchpoint_t *watchpoint) { - /* TODO */ + /* get pointers to arch-specific information */ + mips32_common_t *mips32 = target->arch_info; + mips32_comparator_t * comparator_list = mips32->data_break_list; + + if (!watchpoint->set) + { + LOG_WARNING("watchpoint not set"); + return ERROR_OK; + } + + int wp_num = watchpoint->set - 1; + if ((wp_num < 0) || (wp_num >= mips32->num_data_bpoints)) + { + LOG_DEBUG("Invalid FP Comparator number in watchpoint"); + return ERROR_OK; + } + comparator_list[wp_num].used = 0; + comparator_list[wp_num].bp_value = 0; + target_write_u32(target, comparator_list[wp_num].reg_address + 0x18, 0); + watchpoint->set = 0; + return ERROR_OK; } int mips_m4k_add_watchpoint(struct target_s *target, watchpoint_t *watchpoint) { - /* TODO */ + mips32_common_t *mips32 = target->arch_info; + + if (mips32->num_data_bpoints_avail < 1) + { + LOG_INFO("no hardware watchpoints available"); + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + } + + mips32->num_data_bpoints_avail--; + + mips_m4k_set_watchpoint(target, watchpoint); return ERROR_OK; } int mips_m4k_remove_watchpoint(struct target_s *target, watchpoint_t *watchpoint) { - /* TODO */ + /* get pointers to arch-specific information */ + mips32_common_t *mips32 = target->arch_info; + + if (target->state != TARGET_HALTED) + { + LOG_WARNING("target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + if (watchpoint->set) + { + mips_m4k_unset_watchpoint(target, watchpoint); + } + + mips32->num_data_bpoints_avail++; + return ERROR_OK; } |
From: <du...@ma...> - 2009-06-25 02:12:43
|
Author: duane Date: 2009-06-25 02:12:40 +0200 (Thu, 25 Jun 2009) New Revision: 2401 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c Log: Fixes from Oleksandr Tymoshenko "go...@bl..." Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 16:56:11 UTC (rev 2400) +++ trunk/src/flash/at91sam3.c 2009-06-25 00:12:40 UTC (rev 2401) @@ -2385,6 +2385,7 @@ if (0 == strcmp("show", argv[0])) { if (who == -1) { showall: + r = ERROR_OK; for (x = 0 ; x < pChip->details.n_gpnvms ; x++) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); if (r != ERROR_OK) { Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 16:56:11 UTC (rev 2400) +++ trunk/src/helper/membuf.c 2009-06-25 00:12:40 UTC (rev 2401) @@ -20,7 +20,7 @@ #include <stdio.h> #include <stdarg.h> -#include <malloc.h> +#include <stdlib.h> #include <string.h> #include "membuf.h" |
From: <oh...@ma...> - 2009-06-24 18:56:15
|
Author: oharboe Date: 2009-06-24 18:56:11 +0200 (Wed, 24 Jun 2009) New Revision: 2400 Modified: trunk/doc/openocd.texi Log: David Brownell <da...@pa...> Fix formatting bug in at91sam7 doc added with the at91sam3 support; and some formatting issues with sam7 and stm32 keyword params. Tweak at91sam3 docs. Remove ninth nibble from flash bank addresses, clarify "at91sam3 show" variants and that the flash bank layout is not needed as a parameter (unlike with sam7); formatting fixes. Modified: trunk/doc/openocd.texi =================================================================== --- trunk/doc/openocd.texi 2009-06-24 09:38:28 UTC (rev 2399) +++ trunk/doc/openocd.texi 2009-06-24 16:56:11 UTC (rev 2400) @@ -3376,57 +3376,66 @@ @deffn {Flash Driver} at91sam3 @cindex at91sam3 -All members of the AT91SAM3 (cortex-M3) microcontroller family from -atmel include internal flash and use the Cortex-M3 core. The driver +All members of the AT91SAM3 microcontroller family from +Atmel include internal flash and use ARM's Cortex-M3 core. The driver currently (6/22/09) recognizes the AT91SAM3U[1/2/4][C/E] chips. Note that the driver was orginaly developed and tested using the AT91SAM3U4E, using a SAM3U-EK eval board. Support for other chips in -the family where cribbed from the data sheet [Note to future +the family was cribbed from the data sheet. @emph{Note to future readers/updaters: Please remove this worrysome comment after other -chips are confirmed]. +chips are confirmed.} The AT91SAM3U4[E/C] (256K) chips have 2 flash banks, the other chips -(3U[1/2][E/C]) have 1 flash bank, in all cases the flash banks are at -the following fixed locations. +(3U[1/2][E/C]) have 1 flash bank. In all cases the flash banks are at +the following fixed locations: @example # Flash bank 0 - all chips -flash bank at91sam3 0x000080000 0 1 1 $_TARGETNAME +flash bank at91sam3 0x00080000 0 1 1 $_TARGETNAME # Flash bank 1 - only 256K chips -flash bank at91sam3 0x000100000 0 1 1 $_TARGETNAME +flash bank at91sam3 0x00100000 0 1 1 $_TARGETNAME @end example -Internally, the AT91SAM3 flash memory is organized as follows: +Internally, the AT91SAM3 flash memory is organized as follows. +Unlike the AT91SAM7 chips, these are not used as parameters +to the @command{flash bank} command: @itemize -@item @var{N-Banks:} 256K chips have 2 banks, others have 1 bank. -@item @var{Bank Size:} 128K/64K Per flash bank -@item @var{Sectors:} 16 or 8 per bank -@item @var{SectorSize:} 8K Per Sector -@item @var{PageSize:} 256 bytes per page. Note that OpenOCD operates on 'sector' sizes, not page sizes. +@item @emph{N-Banks:} 256K chips have 2 banks, others have 1 bank. +@item @emph{Bank Size:} 128K/64K Per flash bank +@item @emph{Sectors:} 16 or 8 per bank +@item @emph{SectorSize:} 8K Per Sector +@item @emph{PageSize:} 256 bytes per page. Note that OpenOCD operates on 'sector' sizes, not page sizes. @end itemize -The AT91SAM3 driver adds an additional command: +The AT91SAM3 driver adds some additional commands: -@deffn Command {at91sam3 gpnvm set|clear|show all|NUMBER} -This command allows you to set, clear, or show the state of the GPNVM bits. +@deffn Command {at91sam3 gpnvm} +@deffnx Command {at91sam3 gpnvm clear} number +@deffnx Command {at91sam3 gpnvm set} number +@deffnx Command {at91sam3 gpnvm show} [@option{all}|number] +With no parameters, @command{show} or @command{show all}, +shows the status of all GPNVM bits. +With @command{show} @var{number}, displays that bit. + +With @command{set} @var{number} or @command{clear} @var{number}, +modifies that GPNVM bit. @end deffn @deffn Command {at91sam3 info} This command attempts to display information about the AT91SAM3 -chip. @b{First} it read the @var{CHIPID_CIDR} [address 0x400e0740, see +chip. @emph{First} it read the @code{CHIPID_CIDR} [address 0x400e0740, see Section 28.2.1, page 505 of the AT91SAM3U 29/may/2009 datasheet, -document id: doc6430A] and decodes the values. @b{Second} it reads the +document id: doc6430A] and decodes the values. @emph{Second} it reads the various clock configuration registers and attempts to display how it believes the chip is configured. By default, the SLOWCLK is assumed to -be 32768 Hz, see the command @b{at91sam3 slowclk}. +be 32768 Hz, see the command @command{at91sam3 slowclk}. @end deffn -@deffn Command {at91sam3 slowclk [VALUE]} +@deffn Command {at91sam3 slowclk} [value] This command shows/sets the slow clock frequency used in the -@b{at91sam3 info} command calculations above. +@command{at91sam3 info} command calculations above. @end deffn - @end deffn @deffn {Flash Driver} at91sam7 @@ -3434,9 +3443,7 @@ internal flash and use ARM7TDMI cores. The driver automatically recognizes a number of these chips using the chip identification register, and autoconfigures itself. -@end deffn - @example flash bank at91sam7 0 0 0 0 $_TARGETNAME @end example @@ -3466,7 +3473,7 @@ plane (of up to 256KB), and it will be used automatically when you issue @command{flash erase_sector} or @command{flash erase_address} commands. -@deffn Command {at91sam7 gpnvm} bitnum (set|clear) +@deffn Command {at91sam7 gpnvm} bitnum (@option{set}|@option{clear}) Set or clear a ``General Purpose Non-Volatle Memory'' (GPNVM) bit for the processor. Each processor has a number of such bits, used for controlling features such as brownout detection (so they @@ -3476,6 +3483,7 @@ the appropriate at91sam7 target. @end quotation @end deffn +@end deffn @deffn {Flash Driver} avr The AVR 8-bit microcontrollers from Atmel integrate flash memory. @@ -3601,7 +3609,7 @@ The @var{num} parameter is a value shown by @command{flash banks}. @end deffn -@deffn Command {stm32x options_write} num (SWWDG|HWWDG) (RSTSTNDBY|NORSTSTNDBY) (RSTSTOP|NORSTSTOP) +@deffn Command {stm32x options_write} num (@option{SWWDG}|@option{HWWDG}) (@option{RSTSTNDBY}|@option{NORSTSTNDBY}) (@option{RSTSTOP}|@option{NORSTSTOP}) Writes the stm32 option byte with the specified values. The @var{num} parameter is a value shown by @command{flash banks}. @end deffn |
From: <zw...@ma...> - 2009-06-24 11:38:31
|
Author: zwelch Date: 2009-06-24 11:38:28 +0200 (Wed, 24 Jun 2009) New Revision: 2399 Modified: trunk/src/flash/at91sam3.c Log: Minor fixes to new at91sam3 files for x86-32/64 compilation problems. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:38:21 UTC (rev 2398) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:38:28 UTC (rev 2399) @@ -286,7 +286,9 @@ // else // Bank1 is the boot rom // endif - .bank[0] = { +// .bank[0] = { + { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -298,9 +300,10 @@ .nsectors = 16, .sector_size = 8192, .page_size = 256, - }, + }, - .bank[1] = { +// .bank[1] = { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -312,6 +315,7 @@ .nsectors = 16, .sector_size = 8192, .page_size = 256, + }, }, }, @@ -331,7 +335,9 @@ // boot is via FLASH // Selection is via gpnvm[2] // endif - .bank[0] = { +// .bank[0] = { + { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -343,12 +349,13 @@ .nsectors = 16, .sector_size = 8192, .page_size = 256, - }, - - .bank[1] = { + }, +// .bank[1] = { + { .present = 0, .probed = 0, .bank_number = 1, + }, }, }, { @@ -369,7 +376,9 @@ // endif // - .bank[0] = { +// .bank[0] = { + { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -381,12 +390,14 @@ .nsectors = 8, .sector_size = 8192, .page_size = 256, - }, + }, - .bank[1] = { +// .bank[1] = { + { .present = 0, .probed = 0, .bank_number = 1, + }, }, }, @@ -413,7 +424,9 @@ // else // Bank1 is the boot rom // endif - .bank[0] = { + { + { +// .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -425,9 +438,9 @@ .nsectors = 16, .sector_size = 8192, .page_size = 256, - }, - - .bank[1] = { + }, +// .bank[1] = { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -439,6 +452,7 @@ .nsectors = 16, .sector_size = 8192, .page_size = 256, + }, }, }, @@ -458,7 +472,9 @@ // boot is via FLASH // Selection is via gpnvm[2] // endif - .bank[0] = { + { +// .bank[0] = { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -470,12 +486,13 @@ .nsectors = 16, .sector_size = 8192, .page_size = 256, - }, - - .bank[1] = { + }, +// .bank[1] = { + { .present = 0, .probed = 0, .bank_number = 1, + }, }, }, { @@ -496,7 +513,9 @@ // endif // - .bank[0] = { + { +// .bank[0] = { + { .probed = 0, .pChip = NULL, .pBank = NULL, @@ -508,12 +527,14 @@ .nsectors = 8, .sector_size = 8192, .page_size = 256, - }, - - .bank[1] = { + }, +// .bank[1] = { + { .present = 0, .probed = 0, .bank_number = 1, + + }, }, }, @@ -1313,6 +1334,9 @@ cp = "upll (*ERROR* UPLL is disabled)"; } break; + default: + assert(0); + break; } sam3_sprintf(pChip, "%s (%3.03f Mhz)\n", @@ -1351,6 +1375,9 @@ pdiv = 6; cp = "clock/6"; break; + default: + assert(0); + break; } sam3_sprintf(pChip, "(%s)\n", cp); fin = fin / pdiv; |
From: <zw...@ma...> - 2009-06-24 11:38:25
|
Author: zwelch Date: 2009-06-24 11:38:21 +0200 (Wed, 24 Jun 2009) New Revision: 2398 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c trunk/src/helper/membuf.h Log: Remove whitespace at end of lines, step 2. - Replace '\s*$' with ''. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:38:15 UTC (rev 2397) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:38:21 UTC (rev 2398) @@ -23,7 +23,7 @@ /* BEGIN ATMEL COPYRIGHT */ /* ---------------------------------------------------------------------------- - * ATMEL Microcontroller Software Support + * ATMEL Microcontroller Software Support * ---------------------------------------------------------------------------- * Copyright (c) 2009, Atmel Corporation * @@ -130,7 +130,7 @@ uint32_t CHIPID_EXID; #define SAM3_SUPC_CR (0x400E1210) - uint32_t SUPC_CR; + uint32_t SUPC_CR; #define SAM3_PMC_BASE (0x400E0400) #define SAM3_PMC_SCSR (SAM3_PMC_BASE + 0x0008) @@ -168,13 +168,13 @@ int probed; // DANGER: THERE ARE DRAGONS HERE.. // NOTE: If you add more 'ghost' pointers - // be aware that you must *manually* update + // be aware that you must *manually* update // these pointers in the function sam3_GetDetails() // See the comment "Here there be dragons" // so we can find the chip we belong to struct sam3_chip *pChip; - // so we can find the orginal bank pointer + // so we can find the orginal bank pointer flash_bank_t *pBank; unsigned bank_number; uint32_t controller_address; @@ -268,14 +268,14 @@ .name = "at91sam3u4e", .total_flash_size = 256 * 1024, .total_sram_size = 52 * 1024, - .n_gpnvms = 3, + .n_gpnvms = 3, .n_banks = 2, // System boots at address 0x0 // gpnvm[1] = selects boot code // if gpnvm[1] == 0 // boot is via "SAMBA" (rom) - // else + // else // boot is via FLASH // Selection is via gpnvm[2] // endif @@ -286,12 +286,12 @@ // else // Bank1 is the boot rom // endif - .bank[0] = { + .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, .bank_number = 0, - .base_address = FLASH_BANK0_BASE, + .base_address = FLASH_BANK0_BASE, .controller_address = 0x400e0800, .present = 1, .size_bytes = 128 * 1024, @@ -320,23 +320,23 @@ .name = "at91sam3u2e", .total_flash_size = 128 * 1024, .total_sram_size = 36 * 1024, - .n_gpnvms = 2, + .n_gpnvms = 2, .n_banks = 1, // System boots at address 0x0 // gpnvm[1] = selects boot code // if gpnvm[1] == 0 // boot is via "SAMBA" (rom) - // else + // else // boot is via FLASH // Selection is via gpnvm[2] // endif - .bank[0] = { + .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, .bank_number = 0, - .base_address = FLASH_BANK0_BASE, + .base_address = FLASH_BANK0_BASE, .controller_address = 0x400e0800, .present = 1, .size_bytes = 128 * 1024, @@ -356,25 +356,25 @@ .name = "at91sam3u1e", .total_flash_size = 64 * 1024, .total_sram_size = 20 * 1024, - .n_gpnvms = 2, + .n_gpnvms = 2, .n_banks = 1, // System boots at address 0x0 // gpnvm[1] = selects boot code // if gpnvm[1] == 0 // boot is via "SAMBA" (rom) - // else + // else // boot is via FLASH // Selection is via gpnvm[2] // endif // - - .bank[0] = { + + .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, .bank_number = 0, - .base_address = FLASH_BANK0_BASE, + .base_address = FLASH_BANK0_BASE, .controller_address = 0x400e0800, .present = 1, .size_bytes = 64 * 1024, @@ -389,20 +389,20 @@ .bank_number = 1, }, }, - + { .chipid_cidr = 0x28000960, .name = "at91sam3u4c", .total_flash_size = 256 * 1024, .total_sram_size = 52 * 1024, - .n_gpnvms = 3, + .n_gpnvms = 3, .n_banks = 2, // System boots at address 0x0 // gpnvm[1] = selects boot code // if gpnvm[1] == 0 // boot is via "SAMBA" (rom) - // else + // else // boot is via FLASH // Selection is via gpnvm[2] // endif @@ -413,12 +413,12 @@ // else // Bank1 is the boot rom // endif - .bank[0] = { + .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, .bank_number = 0, - .base_address = FLASH_BANK0_BASE, + .base_address = FLASH_BANK0_BASE, .controller_address = 0x400e0800, .present = 1, .size_bytes = 128 * 1024, @@ -447,23 +447,23 @@ .name = "at91sam3u2c", .total_flash_size = 128 * 1024, .total_sram_size = 36 * 1024, - .n_gpnvms = 2, + .n_gpnvms = 2, .n_banks = 1, // System boots at address 0x0 // gpnvm[1] = selects boot code // if gpnvm[1] == 0 // boot is via "SAMBA" (rom) - // else + // else // boot is via FLASH // Selection is via gpnvm[2] // endif - .bank[0] = { + .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, .bank_number = 0, - .base_address = FLASH_BANK0_BASE, + .base_address = FLASH_BANK0_BASE, .controller_address = 0x400e0800, .present = 1, .size_bytes = 128 * 1024, @@ -483,25 +483,25 @@ .name = "at91sam3u1c", .total_flash_size = 64 * 1024, .total_sram_size = 20 * 1024, - .n_gpnvms = 2, + .n_gpnvms = 2, .n_banks = 1, // System boots at address 0x0 // gpnvm[1] = selects boot code // if gpnvm[1] == 0 // boot is via "SAMBA" (rom) - // else + // else // boot is via FLASH // Selection is via gpnvm[2] // endif // - - .bank[0] = { + + .bank[0] = { .probed = 0, .pChip = NULL, .pBank = NULL, .bank_number = 0, - .base_address = FLASH_BANK0_BASE, + .base_address = FLASH_BANK0_BASE, .controller_address = 0x400e0800, .present = 1, .size_bytes = 64 * 1024, @@ -518,7 +518,7 @@ }, // terminate - { + { .chipid_cidr = 0, .name = NULL, } @@ -539,17 +539,17 @@ * @param pPrivate - info about the bank * @param v - result goes here */ -static int +static int EFC_GetStatus(struct sam3_bank_private *pPrivate, uint32_t *v) { int r; r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FSR, v); - LOG_DEBUG("Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)", + LOG_DEBUG("Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)", (unsigned int)(*v), ((unsigned int)((*v >> 2) & 1)), ((unsigned int)((*v >> 1) & 1)), ((unsigned int)((*v >> 0) & 1))); - + return r; } @@ -557,7 +557,7 @@ * @param pPrivate - info about the bank * @param v - result goes here */ -static int +static int EFC_GetResult(struct sam3_bank_private *pPrivate, uint32_t *v) { int r; @@ -586,7 +586,7 @@ case AT91C_EFC_FCMD_WP: case AT91C_EFC_FCMD_WPL: - case AT91C_EFC_FCMD_EWP: + case AT91C_EFC_FCMD_EWP: case AT91C_EFC_FCMD_EWPL: // case AT91C_EFC_FCMD_EPL: // case AT91C_EFC_FCMD_EPA: @@ -597,15 +597,15 @@ LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n)); } break; - + case AT91C_EFC_FCMD_SFB: case AT91C_EFC_FCMD_CFB: if (argument >= pPrivate->pChip->details.n_gpnvms) { - LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs", + LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs", pPrivate->pChip->details.n_gpnvms); } break; - + case AT91C_EFC_FCMD_GETD: case AT91C_EFC_FCMD_EA: case AT91C_EFC_FCMD_GLB: @@ -640,11 +640,11 @@ return ERROR_FAIL; } else { retry++; - LOG_ERROR("Flash controller(%d) is not ready, attempting reset", + LOG_ERROR("Flash controller(%d) is not ready, attempting reset", pPrivate->bank_number); // we do that by issuing the *STOP* command EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0); - // above is recursive, and further recursion is blocked by + // above is recursive, and further recursion is blocked by // if (command == AT91C_EFC_FCMD_SPUI) above goto do_retry; } @@ -653,7 +653,7 @@ v = (0x5A << 24) | (argument << 8) | command; LOG_DEBUG("Command: 0x%08x", ((unsigned int)(v))); - r = target_write_u32(pPrivate->pBank->target, + r = target_write_u32(pPrivate->pBank->target, pPrivate->controller_address + offset_EFC_FCR, v); if (r != ERROR_OK) { @@ -669,10 +669,10 @@ * @param argument - Optional command argument. * @param status - put command status bits here */ -static int -EFC_PerformCommand(struct sam3_bank_private *pPrivate, - unsigned command, - unsigned argument, +static int +EFC_PerformCommand(struct sam3_bank_private *pPrivate, + unsigned command, + unsigned argument, uint32_t *status) { @@ -680,7 +680,7 @@ uint32_t v; long long ms_now, ms_end; - // default + // default if (status) { *status = 0; } @@ -721,7 +721,7 @@ /** Read the unique ID. - * + * * \param pPrivate - info about the bank * * The unique ID is stored in the 'pPrivate' structure. @@ -746,7 +746,7 @@ } for (x = 0 ; x < 4 ; x++) { - r = target_read_u32(pPrivate->pChip->target, + r = target_read_u32(pPrivate->pChip->target, pPrivate->pBank->base + (x * 4), &v); if (r < 0) { @@ -757,13 +757,13 @@ r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0, NULL); LOG_DEBUG("End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x", - r, + r, (unsigned int)(pPrivate->pChip->cfg.unique_id[0]), (unsigned int)(pPrivate->pChip->cfg.unique_id[1]), (unsigned int)(pPrivate->pChip->cfg.unique_id[2]), (unsigned int)(pPrivate->pChip->cfg.unique_id[3])); return r; - + } /** Erases the entire flash. @@ -785,7 +785,7 @@ * */ //------------------------------------------------------------------------------ -static int +static int FLASHD_GetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm, unsigned *puthere) { uint32_t v; @@ -814,7 +814,7 @@ if (puthere) { // Check if GPNVM is set - // get the bit and make it a 0/1 + // get the bit and make it a 0/1 *puthere = (v >> gpnvm) & 1; } @@ -829,7 +829,7 @@ * * Returns 0 if successful; otherwise returns an error code. */ -static int +static int FLASHD_ClrGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm) { int r; @@ -863,7 +863,7 @@ * @param gpnvm GPNVM index. * */ -static int +static int FLASHD_SetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm) { int r; @@ -901,7 +901,7 @@ * \param end End address of range. */ -static int +static int FLASHD_GetLockBits(struct sam3_bank_private *pPrivate, uint32_t *v) { int r; @@ -915,7 +915,7 @@ } -/**Unlocks all the regions in the given address range. +/**Unlocks all the regions in the given address range. * * \param start_sector - first sector to unlock * \param end_sector - last (inclusive) to unlock @@ -955,7 +955,7 @@ */ -static int +static int FLASHD_Lock(struct sam3_bank_private *pPrivate, unsigned start_sector, unsigned end_sector) @@ -966,7 +966,7 @@ int r; pages_per_sector = pPrivate->sector_size / pPrivate->page_size; - + /* Lock all pages */ while (start_sector <= end_sector) { pg = start_sector * pages_per_sector; @@ -999,8 +999,8 @@ } // print the fieldname, the field value, in dec & hex, and return field value -static uint32_t -sam3_reg_fieldname(struct sam3_chip *pChip, +static uint32_t +sam3_reg_fieldname(struct sam3_chip *pChip, const char *regname, uint32_t value, unsigned shift, @@ -1020,9 +1020,9 @@ hwidth = 8; dwidth = 12; } - + // show the basics - sam3_sprintf(pChip, "\t%*s: %*d [0x%0*x] ", + sam3_sprintf(pChip, "\t%*s: %*d [0x%0*x] ", REG_NAME_WIDTH, regname, dwidth, v, hwidth, v); @@ -1034,7 +1034,7 @@ static const char * const eproc_names[] = { _unknown, // 0 "arm946es", // 1 - "arm7tdmi", // 2 + "arm7tdmi", // 2 "cortex-m3", // 3 "arm920t", // 4 "arm926ejs", // 5 @@ -1075,13 +1075,13 @@ "48K Bytes", // 0 "1K Bytes", // 1 "2K Bytes", // 2 - "6K Bytes", // 3 + "6K Bytes", // 3 "112K Bytes", // 4 "4K Bytes", // 5 "80K Bytes", // 6 "160K Bytes", // 7 - "8K Bytes", // 8 - "16K Bytes", // 9 + "8K Bytes", // 8 + "16K Bytes", // 9 "32K Bytes", // 10 "64K Bytes", // 11 "128K Bytes", // 12 @@ -1133,8 +1133,8 @@ "sram emulating flash", // 4 _unknown, // 5 _unknown, // 6 - _unknown, // 7 - + _unknown, // 7 + }; static const char *_yes_or_no(uint32_t v) @@ -1150,7 +1150,7 @@ "4 MHz", "8 MHz", "12 MHz", "reserved" }; -static void +static void sam3_explain_ckgr_mor(struct sam3_chip *pChip) { uint32_t v; @@ -1159,7 +1159,7 @@ v = sam3_reg_fieldname(pChip, "MOSCXTEN", pChip->cfg.CKGR_MOR, 0, 1); sam3_sprintf(pChip, "(main xtal enabled: %s)\n", _yes_or_no(v)); - v = sam3_reg_fieldname(pChip, "MOSCXTBY", pChip->cfg.CKGR_MOR, 1, 1); + v = sam3_reg_fieldname(pChip, "MOSCXTBY", pChip->cfg.CKGR_MOR, 1, 1); sam3_sprintf(pChip, "(main osc bypass: %s)\n", _yes_or_no(v)); rcen = sam3_reg_fieldname(pChip, "MOSCRCEN", pChip->cfg.CKGR_MOR, 2, 1); @@ -1192,15 +1192,15 @@ v = sam3_reg_fieldname(pChip, "MOSCSEL", pChip->cfg.CKGR_MOR, 24, 1); sam3_sprintf(pChip, "(mainosc source: %s)\n", v ? "external xtal" : "internal RC"); - + v = sam3_reg_fieldname(pChip,"CFDEN", pChip->cfg.CKGR_MOR, 25, 1); sam3_sprintf(pChip, "(clock failure enabled: %s)\n", _yes_or_no(v)); } - -static void + +static void sam3_explain_chipid_cidr(struct sam3_chip *pChip) { int x; @@ -1212,7 +1212,7 @@ v = sam3_reg_fieldname(pChip, "EPROC", pChip->cfg.CHIPID_CIDR, 5, 3); sam3_sprintf(pChip, "%s\n", eproc_names[v]); - + v = sam3_reg_fieldname(pChip, "NVPSIZE", pChip->cfg.CHIPID_CIDR, 8, 4); sam3_sprintf(pChip, "%s\n", nvpsize[v]); @@ -1230,7 +1230,7 @@ break; } } - + sam3_sprintf(pChip, "%s\n", cp); v = sam3_reg_fieldname(pChip, "NVPTYP", pChip->cfg.CHIPID_CIDR, 28, 3); @@ -1240,17 +1240,17 @@ sam3_sprintf(pChip, "(exists: %s)\n", _yes_or_no(v)); } -static void +static void sam3_explain_ckgr_mcfr(struct sam3_chip *pChip) { uint32_t v; - + v = sam3_reg_fieldname(pChip, "MAINFRDY", pChip->cfg.CKGR_MCFR, 16, 1); sam3_sprintf(pChip, "(main ready: %s)\n", _yes_or_no(v)); v = sam3_reg_fieldname(pChip, "MAINF", pChip->cfg.CKGR_MCFR, 0, 16); - + v = (v * pChip->cfg.slow_freq) / 16; pChip->cfg.mainosc_freq = v; @@ -1281,8 +1281,8 @@ _tomhz(pChip->cfg.plla_freq)); } } - - + + static void sam3_explain_mckr(struct sam3_chip *pChip) { @@ -1316,7 +1316,7 @@ } sam3_sprintf(pChip, "%s (%3.03f Mhz)\n", - cp, + cp, _tomhz(fin)); pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3); switch (pres & 0x07) { @@ -1354,7 +1354,7 @@ } sam3_sprintf(pChip, "(%s)\n", cp); fin = fin / pdiv; - // sam3 has a *SINGLE* clock - + // sam3 has a *SINGLE* clock - // other at91 series parts have divisors for these. pChip->cfg.cpu_freq = fin; pChip->cfg.mclk_freq = fin; @@ -1362,7 +1362,7 @@ sam3_sprintf(pChip, "\t\tResult CPU Freq: %3.03f\n", _tomhz(fin)); } - + #if 0 static struct sam3_chip * target2sam3(target_t *pTarget) @@ -1388,7 +1388,7 @@ static uint32_t * sam3_get_reg_ptr(struct sam3_cfg *pCfg, const struct sam3_reg_list *pList) { - // this function exists to help + // this function exists to help // keep funky offsetof() errors // and casting from causing bugs @@ -1397,8 +1397,8 @@ return ((uint32_t *)(((char *)(pCfg)) + pList->struct_offset)); } - - + + #define SAM3_ENTRY(NAME, FUNC) { .address = SAM3_ ## NAME, .struct_offset = offsetof(struct sam3_cfg, NAME), #NAME, FUNC } static const struct sam3_reg_list sam3_all_regs[] = { SAM3_ENTRY(CKGR_MOR , sam3_explain_ckgr_mor), @@ -1448,7 +1448,7 @@ // calculate where this one go.. // it is "possibly" this register. - + pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset)); // well? Is it this register @@ -1484,9 +1484,9 @@ } return r; } - - + + static int sam3_ReadAllRegs(struct sam3_chip *pChip) { @@ -1495,14 +1495,14 @@ pReg = &(sam3_all_regs[0]); while (pReg->name) { - r = sam3_ReadThisReg(pChip, + r = sam3_ReadThisReg(pChip, sam3_get_reg_ptr(&(pChip->cfg), pReg)); if (r != ERROR_OK) { LOG_ERROR("Cannot read SAM3 registere: %s @ 0x%08x, Error: %d\n", pReg->name, ((unsigned)(pReg->address)), r); return r; } - + pReg++; } @@ -1524,7 +1524,7 @@ // display all regs LOG_DEBUG("Start: %s", pReg->name); regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg); - sam3_sprintf(pChip, "%*s: [0x%08x] -> 0x%08x\n", + sam3_sprintf(pChip, "%*s: [0x%08x] -> 0x%08x\n", REG_NAME_WIDTH, pReg->name, pReg->address, @@ -1539,7 +1539,7 @@ sam3_sprintf(pChip," mainosc: %3.03f MHz\n", _tomhz(pChip->cfg.mainosc_freq)); sam3_sprintf(pChip," plla: %3.03f MHz\n", _tomhz(pChip->cfg.plla_freq)); sam3_sprintf(pChip," cpu-freq: %3.03f MHz\n", _tomhz(pChip->cfg.cpu_freq)); - sam3_sprintf(pChip,"mclk-freq: %3.03f MHz\n", _tomhz(pChip->cfg.mclk_freq)); + sam3_sprintf(pChip,"mclk-freq: %3.03f MHz\n", _tomhz(pChip->cfg.mclk_freq)); sam3_sprintf(pChip, " UniqueId: 0x%08x 0x%08x 0x%08x 0x%08x\n", @@ -1548,12 +1548,12 @@ pChip->cfg.unique_id[2], pChip->cfg.unique_id[3]); - + return ERROR_OK; } - -static int + +static int sam3_erase_check(struct flash_bank_s *bank) { int x; @@ -1577,7 +1577,7 @@ return ERROR_OK; } -static int +static int sam3_protect_check(struct flash_bank_s *bank) { int r; @@ -1599,7 +1599,7 @@ if (!(pPrivate->probed)) { return ERROR_FLASH_BANK_NOT_PROBED; } - + r = FLASHD_GetLockBits(pPrivate , &v); if (r != ERROR_OK) { LOG_DEBUG("Failed: %d",r); @@ -1613,17 +1613,17 @@ return ERROR_OK; } -static int -sam3_flash_bank_command(struct command_context_s *cmd_ctx, - char *cmd, - char **args, - int argc, +static int +sam3_flash_bank_command(struct command_context_s *cmd_ctx, + char *cmd, + char **args, + int argc, struct flash_bank_s *bank) { struct sam3_chip *pChip; pChip = all_sam3_chips; - + // is this an existing chip? while (pChip) { if (pChip->target == bank->target) { @@ -1653,7 +1653,7 @@ return ERROR_FAIL; } } - + switch (bank->base) { default: LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x or 0x%08x)", @@ -1701,11 +1701,11 @@ } } if (pDetails->name == NULL) { - LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)", + LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)", (unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR)); // Help the victim, print details about the chip membuf_reset(pPrivate->pChip->mbuf); - membuf_sprintf(pPrivate->pChip->mbuf, + membuf_sprintf(pPrivate->pChip->mbuf, "SAM3 CHIPID_CIDR: 0x%08x decodes as follows\n", pPrivate->pChip->cfg.CHIPID_CIDR); sam3_explain_chipid_cidr(pPrivate->pChip); @@ -1735,8 +1735,8 @@ } // Overwrite the "details" structure. - memcpy(&(pPrivate->pChip->details), - pDetails, + memcpy(&(pPrivate->pChip->details), + pDetails, sizeof(pPrivate->pChip->details)); // now fix the ghosted pointers @@ -1745,15 +1745,15 @@ pChip->details.bank[x].pBank = saved_banks[x]; } - // update the *BANK*SIZE* + // update the *BANK*SIZE* LOG_DEBUG("End"); return ERROR_OK; -} - +} -static int + +static int _sam3_probe(struct flash_bank_s *bank, int noise) { unsigned x; @@ -1779,7 +1779,7 @@ return r; } - + LOG_DEBUG("Here"); r = sam3_GetInfo(pPrivate->pChip); if (r != ERROR_OK) { @@ -1791,7 +1791,7 @@ r = sam3_GetDetails(pPrivate); if (r != ERROR_OK) { return r; - } + } } // update the flash bank size @@ -1809,7 +1809,7 @@ return ERROR_FAIL; } bank->num_sectors = pPrivate->nsectors; - + for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++) { bank->sectors[x].size = pPrivate->sector_size; bank->sectors[x].offset = x * (pPrivate->sector_size); @@ -1829,7 +1829,7 @@ LOG_DEBUG("Bank = %d, nbanks = %d", pPrivate->bank_number , pPrivate->pChip->details.n_banks); if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks) { - // read unique id, + // read unique id, // it appears to be associated with the *last* flash bank. FLASHD_ReadUniqueID(pPrivate); } @@ -1837,13 +1837,13 @@ return r; } -static int +static int sam3_probe(struct flash_bank_s *bank) { return _sam3_probe(bank, 1); } -static int +static int sam3_auto_probe(struct flash_bank_s *bank) { return _sam3_probe(bank, 0); @@ -1851,7 +1851,7 @@ -static int +static int sam3_erase(struct flash_bank_s *bank, int first, int last) { struct sam3_bank_private *pPrivate; @@ -1883,7 +1883,7 @@ return ERROR_OK; } -static int +static int sam3_protect(struct flash_bank_s *bank, int set, int first, int last) { struct sam3_bank_private *pPrivate; @@ -1908,7 +1908,7 @@ LOG_DEBUG("End: r=%d",r); return r; - + } @@ -1932,7 +1932,7 @@ adr = pagenum * pPrivate->page_size; adr += adr + pPrivate->base_address; - r = target_read_memory(pPrivate->pChip->target, + r = target_read_memory(pPrivate->pChip->target, adr, 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, @@ -1951,11 +1951,11 @@ // the DAP cannot... so - we download this 28byte thing // Run the algorithm - (below) // to program the device -// +// // ======================================== // #include <stdint.h> -// -// struct foo { +// +// struct foo { // uint32_t *dst; // const uint32_t *src; // int n; @@ -1963,7 +1963,7 @@ // uint32_t cmd; // }; // -// +// // uint32_t sam3_function(struct foo *p) // { // volatile uint32_t *v; @@ -1971,18 +1971,18 @@ // const uint32_t *s; // int n; // uint32_t r; -// +// // d = p->dst; // s = p->src; // n = p->n; -// +// // do { // *d++ = *s++; // } while (--n) // ; -// +// // v = p->base; -// +// // v[ 1 ] = p->cmd; // do { // r = v[8/4]; @@ -1994,7 +1994,7 @@ -static const uint8_t +static const uint8_t sam3_page_write_opcodes[] = { // 24 0000 0446 mov r4, r0 0x04,0x46, @@ -2046,7 +2046,7 @@ adr += (adr + pPrivate->base_address); LOG_DEBUG("Wr Page %u @ phys address: 0x%08x", pagenum, (unsigned int)(adr)); - r = target_write_memory(pPrivate->pChip->target, + r = target_write_memory(pPrivate->pChip->target, adr, 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, @@ -2075,15 +2075,15 @@ } return ERROR_OK; } - - - - -static int -sam3_write(struct flash_bank_s *bank, - uint8_t *buffer, - uint32_t offset, + + + + +static int +sam3_write(struct flash_bank_s *bank, + uint8_t *buffer, + uint32_t offset, uint32_t count) { int n; @@ -2113,28 +2113,28 @@ if ((offset + count) > pPrivate->size_bytes) { LOG_ERROR("Flash write error - past end of bank"); LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x", - (unsigned int)(offset), + (unsigned int)(offset), (unsigned int)(count), (unsigned int)(pPrivate->size_bytes)); return ERROR_FAIL; } pagebuffer = alloca(pPrivate->page_size); - + // what page do we start & end in? page_cur = offset / pPrivate->page_size; page_end = (offset + count - 1) / pPrivate->page_size; - + LOG_DEBUG("Offset: 0x%08x, Count: 0x%08x", (unsigned int)(offset), (unsigned int)(count)); LOG_DEBUG("Page start: %d, Page End: %d", (int)(page_cur), (int)(page_end)); - + // Special case: all one page // // Otherwise: // (1) non-aligned start // (2) body pages // (3) non-aligned end. - + // Handle special case - all one page. if (page_cur == page_end) { LOG_DEBUG("Special case, all in one page"); @@ -2142,12 +2142,12 @@ if (r != ERROR_OK) { return r; } - + page_offset = (offset & (pPrivate->page_size-1)); memcpy(pagebuffer + page_offset, buffer, count); - + r = sam3_page_write(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { return r; @@ -2170,7 +2170,7 @@ memcpy(pagebuffer + page_offset, buffer, n); - + r = sam3_page_write(pPrivate, page_cur, pagebuffer); if (r != ERROR_OK) { return r; @@ -2183,12 +2183,12 @@ } // intermediate large pages - // also - the final *terminal* + // also - the final *terminal* // if that terminal page is a full page - LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count = 0x%08x", + LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count = 0x%08x", (int)page_cur, (int)page_end, (unsigned int)(count)); - while ((page_cur < page_end) && + while ((page_cur < page_end) && (count >= pPrivate->page_size)) { r = sam3_page_write(pPrivate, page_cur, buffer); if (r != ERROR_OK) { @@ -2235,13 +2235,13 @@ } r = 0; - + // bank0 must exist before we can do anything if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: - command_print(cmd_ctx, - "Please define bank %d via command: flash bank %s ... ", + command_print(cmd_ctx, + "Please define bank %d via command: flash bank %s ... ", x, at91sam3_flash.name); return ERROR_FAIL; @@ -2256,16 +2256,16 @@ } // above garentees the "chip details" structure is valid // and thus, bank private areas are valid - // and we have a SAM3 chip, what a concept! - + // and we have a SAM3 chip, what a concept! + // auto-probe other banks, 0 done above for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++) { // skip banks not present if (!(pChip->details.bank[x].present)) { continue; } - + if (pChip->details.bank[x].pBank == NULL) { goto need_define; } @@ -2273,21 +2273,21 @@ if (pChip->details.bank[x].probed) { continue; } - + r = sam3_auto_probe(pChip->details.bank[x].pBank); if (r != ERROR_OK) { return r; } } - + r = sam3_GetInfo(pChip); if (r != ERROR_OK) { LOG_DEBUG("Sam3Info, Failed %d\n",r); return r; } - + // print results cp = membuf_strtok(pChip->mbuf, "\n", &vp); while (cp) { @@ -2381,7 +2381,7 @@ command_print(cmd_ctx, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } - + if (0 == strcmp("set", argv[0])) { r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who); } else if ((0 == strcmp("clr", argv[0])) || @@ -2394,7 +2394,7 @@ return r; } -static int +static int sam3_handle_slowclk_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc) { uint32_t v; @@ -2422,14 +2422,14 @@ } pChip->cfg.slow_freq = v; break; - + default: // error command_print(cmd_ctx,"Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print(cmd_ctx, "Slowclk freq: %d.%03dkhz", + command_print(cmd_ctx, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq/ 1000), (int)(pChip->cfg.slow_freq% 1000)); return ERROR_OK; @@ -2448,9 +2448,9 @@ pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); register_command(cmd_ctx, pCmd, - "gpnvm", - sam3_handle_gpnvm_command, - COMMAND_EXEC, + "gpnvm", + sam3_handle_gpnvm_command, + COMMAND_EXEC, "at91sam3 gpnvm [action [<BIT>], by default 'show', otherwise set | clear BIT"); register_command(cmd_ctx, pCmd, "info", @@ -2471,7 +2471,7 @@ { .name = "at91sam3", .register_commands = sam3_register_commands, - + .flash_bank_command = sam3_flash_bank_command, .erase = sam3_erase, .protect = sam3_protect, Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:38:15 UTC (rev 2397) +++ trunk/src/helper/membuf.c 2009-06-24 09:38:21 UTC (rev 2398) @@ -29,7 +29,7 @@ // buflen is alway "+1" bigger then // what is shown here, the +1 is for // the NULL string terminator -#define DEFAULT_BUFSIZE 100 +#define DEFAULT_BUFSIZE 100 size_t maxlen; // allocated size size_t curlen; // where we are inserting at char *_strtoklast; @@ -40,7 +40,7 @@ #define space_avail(pBuf) (pBuf->maxlen - pBuf->curlen) #define dataend(pBuf) (((char *)(pBuf->buf)) + pBuf->curlen) -size_t +size_t membuf_len(struct membuf *pBuf) { return pBuf->curlen; @@ -65,9 +65,9 @@ return strtok_r(NULL, sep, &(pBuf->_strtoklast)); } } - + struct membuf * membuf_new(void) { @@ -161,7 +161,7 @@ // do work r = vsnprintf(dataend(pBuf), sa, - fmt, + fmt, ap); if ((r > 0) && (((size_t)(r)) < sa)) { // Success! Modified: trunk/src/helper/membuf.h =================================================================== --- trunk/src/helper/membuf.h 2009-06-24 09:38:15 UTC (rev 2397) +++ trunk/src/helper/membuf.h 2009-06-24 09:38:21 UTC (rev 2398) @@ -12,15 +12,15 @@ * This is a simple 'string buffer' that auto-grows. * * More correctly put, this is a "memory buffer" - * it may contain binary data - * + * it may contain binary data + * * Note: Internally the buffer always has a 'null terminator' */ /* contents of this structure are 'opaque' */ struct membuf; - + /** Create a new membuf * By default the memory buffer has "some non-zero-size" * (couple hundred bytes, exact amount is opaque) @@ -34,7 +34,7 @@ /** grow/shrink a membuf by specified amount. - * @param pBuf - the buffer + * @param pBuf - the buffer * @param amount - the amount to grow or shrink by. * * Symantics of 'realloc()' return NULL on failure @@ -43,7 +43,7 @@ /** how long is this buffer (memlen(), strlen()) * @param pBuf - the buffer - * + * * @returns: length of current buffer. */ size_t membuf_len(struct membuf *pBuf); @@ -76,10 +76,10 @@ */ int membuf_vsprintf(struct membuf *pBuf , const char *fmt, va_list ap); -/** Tokenize lines using strtok() +/** Tokenize lines using strtok() * @param pBuf - buffer to tokenize * @param delim - delimiter parameter for strtok_r() - * + * * Identical to "strtok()" - pass "pBuff = NULL" on second call * * NOTE: This call is <b > destructive</b> to the buffer. |
From: <zw...@ma...> - 2009-06-24 11:38:22
|
Author: zwelch Date: 2009-06-24 11:38:15 +0200 (Wed, 24 Jun 2009) New Revision: 2397 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c Log: - Replace '){' with ') {'. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:38:08 UTC (rev 2396) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:38:15 UTC (rev 2397) @@ -237,21 +237,21 @@ static struct sam3_chip *p; t = get_current_target(cmd_ctx); - if (!t){ + if (!t) { command_print(cmd_ctx, "No current target?"); return NULL; } p = all_sam3_chips; - if (!p){ + if (!p) { // this should not happen // the command is not registered until the chip is created? command_print(cmd_ctx, "No SAM3 chips exist?"); return NULL; } - while (p){ - if (p->target == t){ + while (p) { + if (p->target == t) { return p; } p = p->next; @@ -563,7 +563,7 @@ int r; uint32_t rv; r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv); - if (v){ + if (v) { *v = rv; } LOG_DEBUG("Result: 0x%08x", ((unsigned int)(rv))); @@ -593,14 +593,14 @@ case AT91C_EFC_FCMD_SLB: case AT91C_EFC_FCMD_CLB: n = (pPrivate->size_bytes / pPrivate->page_size); - if (argument >= n){ + if (argument >= n) { LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n)); } break; case AT91C_EFC_FCMD_SFB: case AT91C_EFC_FCMD_CFB: - if (argument >= pPrivate->pChip->details.n_gpnvms){ + if (argument >= pPrivate->pChip->details.n_gpnvms) { LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs", pPrivate->pChip->details.n_gpnvms); } @@ -612,7 +612,7 @@ case AT91C_EFC_FCMD_GFB: case AT91C_EFC_FCMD_STUI: case AT91C_EFC_FCMD_SPUI: - if (argument != 0){ + if (argument != 0) { LOG_ERROR("Argument is meaningless for cmd: %d", command); } break; @@ -621,7 +621,7 @@ break; } - if (command == AT91C_EFC_FCMD_SPUI){ + if (command == AT91C_EFC_FCMD_SPUI) { // this is a very special situation. // Situation (1) - error/retry - see below // And we are being called recursively @@ -629,11 +629,11 @@ } else { // it should be "ready" EFC_GetStatus(pPrivate, &v); - if (v & 1){ + if (v & 1) { // then it is ready // we go on } else { - if (retry){ + if (retry) { // we have done this before // the controller is not responding. LOG_ERROR("flash controller(%d) is not ready! Error", pPrivate->bank_number); @@ -656,7 +656,7 @@ r = target_write_u32(pPrivate->pBank->target, pPrivate->controller_address + offset_EFC_FCR, v); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_DEBUG("Error Write failed"); } return r; @@ -681,12 +681,12 @@ long long ms_now, ms_end; // default - if (status){ + if (status) { *status = 0; } r = EFC_StartCommand(pPrivate, command, argument); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } @@ -695,11 +695,11 @@ do { r = EFC_GetStatus(pPrivate, &v); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } ms_now = timeval_ms(); - if (ms_now > ms_end){ + if (ms_now > ms_end) { // error LOG_ERROR("Command timeout"); return ERROR_FAIL; @@ -709,7 +709,7 @@ ; // error bits.. - if (status){ + if (status) { *status = (v & 0x6); } return ERROR_OK; @@ -741,15 +741,15 @@ LOG_DEBUG("Begin"); r = EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_STUI, 0); - if (r < 0){ + if (r < 0) { return r; } - for (x = 0 ; x < 4 ; x++){ + for (x = 0 ; x < 4 ; x++) { r = target_read_u32(pPrivate->pChip->target, pPrivate->pBank->base + (x * 4), &v); - if (r < 0){ + if (r < 0) { return r; } pPrivate->pChip->cfg.unique_id[x] = v; @@ -792,12 +792,12 @@ int r; LOG_DEBUG("Here"); - if (pPrivate->bank_number != 0){ + if (pPrivate->bank_number != 0) { LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if (gpnvm >= pPrivate->pChip->details.n_gpnvms){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms) { LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", gpnvm,pPrivate->pChip->details.n_gpnvms); return ERROR_FAIL; @@ -805,14 +805,14 @@ // Get GPNVMs status r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_ERROR("Failed"); return r; } r = EFC_GetResult(pPrivate, &v); - if (puthere){ + if (puthere) { // Check if GPNVM is set // get the bit and make it a 0/1 *puthere = (v >> gpnvm) & 1; @@ -836,19 +836,19 @@ unsigned v; LOG_DEBUG("Here"); - if (pPrivate->bank_number != 0){ + if (pPrivate->bank_number != 0) { LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if (gpnvm >= pPrivate->pChip->details.n_gpnvms){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms) { LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", gpnvm,pPrivate->pChip->details.n_gpnvms); return ERROR_FAIL; } r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_DEBUG("Failed: %d",r); return r; } @@ -869,22 +869,22 @@ int r; unsigned v; - if (pPrivate->bank_number != 0){ + if (pPrivate->bank_number != 0) { LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if (gpnvm >= pPrivate->pChip->details.n_gpnvms){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms) { LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", gpnvm,pPrivate->pChip->details.n_gpnvms); return ERROR_FAIL; } r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } - if (v){ + if (v) { // already set r = ERROR_OK; } else { @@ -907,7 +907,7 @@ int r; LOG_DEBUG("Here"); r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL); - if (r == ERROR_OK){ + if (r == ERROR_OK) { r = EFC_GetResult(pPrivate, v); } LOG_DEBUG("End: %d",r); @@ -934,7 +934,7 @@ pages_per_sector = pPrivate->sector_size / pPrivate->page_size; /* Unlock all pages */ - while (start_sector <= end_sector){ + while (start_sector <= end_sector) { pg = start_sector * pages_per_sector; r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_CLB, pg, &status); @@ -968,7 +968,7 @@ pages_per_sector = pPrivate->sector_size / pPrivate->page_size; /* Lock all pages */ - while (start_sector <= end_sector){ + while (start_sector <= end_sector) { pg = start_sector * pages_per_sector; r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SLB, pg, &status); @@ -990,7 +990,7 @@ { va_list ap; va_start(ap,fmt); - if (pChip->mbuf == NULL){ + if (pChip->mbuf == NULL) { return; } @@ -1013,7 +1013,7 @@ // extract the field v = value >> shift; v = v & ((1 << width)-1); - if (width <= 16){ + if (width <= 16) { hwidth = 4; dwidth = 5; } else { @@ -1139,7 +1139,7 @@ static const char *_yes_or_no(uint32_t v) { - if (v){ + if (v) { return "YES"; } else { return "NO"; @@ -1170,8 +1170,8 @@ _rc_freq[v]); pChip->cfg.rc_freq = 0; - if (rcen){ - switch (v){ + if (rcen) { + switch (v) { default: pChip->cfg.rc_freq = 0; case 0: @@ -1224,8 +1224,8 @@ v = sam3_reg_fieldname(pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8); cp = _unknown; - for (x = 0 ; archnames[x].name ; x++){ - if (v == archnames[x].value){ + for (x = 0 ; archnames[x].name ; x++) { + if (v == archnames[x].value) { cp = archnames[x].name; break; } @@ -1271,11 +1271,11 @@ mula = sam3_reg_fieldname(pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11); sam3_sprintf(pChip,"\n"); pChip->cfg.plla_freq = 0; - if (mula == 0){ + if (mula == 0) { sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula = 0)\n"); - } else if (diva == 0){ + } else if (diva == 0) { sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n"); - } else if (diva == 1){ + } else if (diva == 1) { pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula + 1)); sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n", _tomhz(pChip->cfg.plla_freq)); @@ -1291,7 +1291,7 @@ const char *cp; css = sam3_reg_fieldname(pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2); - switch (css & 3){ + switch (css & 3) { case 0: fin = pChip->cfg.slow_freq; cp = "slowclk"; @@ -1305,7 +1305,7 @@ cp = "plla"; break; case 3: - if (pChip->cfg.CKGR_UCKR & (1 << 16)){ + if (pChip->cfg.CKGR_UCKR & (1 << 16)) { fin = 480 * 1000 * 1000; cp = "upll"; } else { @@ -1319,7 +1319,7 @@ cp, _tomhz(fin)); pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3); - switch (pres & 0x07){ + switch (pres & 0x07) { case 0: pdiv = 1; cp = "selected clock"; @@ -1369,13 +1369,13 @@ { struct sam3_chip *pChip; - if (pTarget == NULL){ + if (pTarget == NULL) { return NULL; } pChip = all_sam3_chips; - while (pChip){ - if (pChip->target == pTarget){ + while (pChip) { + if (pChip->target == pTarget) { break; // return below } else { pChip = pChip->next; @@ -1443,7 +1443,7 @@ const struct sam3_reg_list *pReg; pReg = &(sam3_all_regs[0]); - while (pReg->name){ + while (pReg->name) { uint32_t *pPossible; // calculate where this one go.. @@ -1452,7 +1452,7 @@ pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset)); // well? Is it this register - if (pPossible == goes_here){ + if (pPossible == goes_here) { // Jump for joy! return pReg; } @@ -1473,12 +1473,12 @@ int r; pReg = sam3_GetReg(pChip, goes_here); - if (!pReg){ + if (!pReg) { return ERROR_FAIL; } r = target_read_u32(pChip->target, pReg->address, goes_here); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_ERROR("Cannot read SAM3 register: %s @ 0x%08x, Err: %d\n", pReg->name, (unsigned)(pReg->address), r); } @@ -1494,10 +1494,10 @@ const struct sam3_reg_list *pReg; pReg = &(sam3_all_regs[0]); - while (pReg->name){ + while (pReg->name) { r = sam3_ReadThisReg(pChip, sam3_get_reg_ptr(&(pChip->cfg), pReg)); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_ERROR("Cannot read SAM3 registere: %s @ 0x%08x, Error: %d\n", pReg->name, ((unsigned)(pReg->address)), r); return r; @@ -1520,7 +1520,7 @@ pReg = &(sam3_all_regs[0]); - while (pReg->name){ + while (pReg->name) { // display all regs LOG_DEBUG("Start: %s", pReg->name); regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg); @@ -1529,7 +1529,7 @@ pReg->name, pReg->address, regval); - if (pReg->explain_func){ + if (pReg->explain_func) { (*(pReg->explain_func))(pChip); } LOG_DEBUG("End: %s", pReg->name); @@ -1563,13 +1563,13 @@ LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } - if (0 == bank->num_sectors){ + if (0 == bank->num_sectors) { LOG_ERROR("Target: not supported/not probed\n"); return ERROR_FAIL; } LOG_INFO("sam3 - supports auto-erase, erase_check ignored"); - for (x = 0 ; x < bank->num_sectors ; x++){ + for (x = 0 ; x < bank->num_sectors ; x++) { bank->sectors[x].is_erased = 1; } @@ -1592,21 +1592,21 @@ } pPrivate = get_sam3_bank_private(bank); - if (!pPrivate){ + if (!pPrivate) { LOG_ERROR("no private for this bank?"); return ERROR_FAIL; } - if (!(pPrivate->probed)){ + if (!(pPrivate->probed)) { return ERROR_FLASH_BANK_NOT_PROBED; } r = FLASHD_GetLockBits(pPrivate , &v); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_DEBUG("Failed: %d",r); return r; } - for (x = 0 ; x < pPrivate->nsectors ; x++){ + for (x = 0 ; x < pPrivate->nsectors ; x++) { bank->sectors[x].is_protected = (!!(v & (1 << x))); } LOG_DEBUG("Done"); @@ -1625,17 +1625,17 @@ pChip = all_sam3_chips; // is this an existing chip? - while (pChip){ - if (pChip->target == bank->target){ + while (pChip) { + if (pChip->target == bank->target) { break; } pChip = pChip->next; } - if (!pChip){ + if (!pChip) { // this is a *NEW* chip pChip = calloc(1, sizeof(struct sam3_chip)); - if (!pChip){ + if (!pChip) { LOG_ERROR("NO RAM!"); return ERROR_FAIL; } @@ -1648,13 +1648,13 @@ pChip->cfg.slow_freq = 32768; pChip->probed = 0; pChip->mbuf = membuf_new(); - if (!(pChip->mbuf)){ + if (!(pChip->mbuf)) { LOG_ERROR("no memory"); return ERROR_FAIL; } } - switch (bank->base){ + switch (bank->base) { default: LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x or 0x%08x)", ((unsigned int)(bank->base)), @@ -1693,14 +1693,14 @@ LOG_DEBUG("Begin"); pDetails = all_sam3_details; - while (pDetails->name){ - if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR){ + while (pDetails->name) { + if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR) { break; } else { pDetails++; } } - if (pDetails->name == NULL){ + if (pDetails->name == NULL) { LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)", (unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR)); // Help the victim, print details about the chip @@ -1710,7 +1710,7 @@ pPrivate->pChip->cfg.CHIPID_CIDR); sam3_explain_chipid_cidr(pPrivate->pChip); cp = membuf_strtok(pPrivate->pChip->mbuf, "\n", &vp); - while (cp){ + while (cp) { LOG_INFO("%s", cp); cp = membuf_strtok(NULL, "\n", &vp); } @@ -1730,7 +1730,7 @@ // // save the "bank" pointers - for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++) { saved_banks[ x ] = pChip->details.bank[x].pBank; } @@ -1740,7 +1740,7 @@ sizeof(pPrivate->pChip->details)); // now fix the ghosted pointers - for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++) { pChip->details.bank[x].pChip = pChip; pChip->details.bank[x].pBank = saved_banks[x]; } @@ -1769,48 +1769,48 @@ } pPrivate = get_sam3_bank_private(bank); - if (!pPrivate){ + if (!pPrivate) { LOG_ERROR("Invalid/unknown bank number\n"); return ERROR_FAIL; } r = sam3_ReadAllRegs(pPrivate->pChip); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } LOG_DEBUG("Here"); r = sam3_GetInfo(pPrivate->pChip); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } - if (!(pPrivate->pChip->probed)){ + if (!(pPrivate->pChip->probed)) { pPrivate->pChip->probed = 1; LOG_DEBUG("Here"); r = sam3_GetDetails(pPrivate); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } } // update the flash bank size - for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){ - if (bank->base == pPrivate->pChip->details.bank[0].base_address){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++) { + if (bank->base == pPrivate->pChip->details.bank[0].base_address) { bank->size = pPrivate->pChip->details.bank[0].size_bytes; break; } } - if (bank->sectors == NULL){ + if (bank->sectors == NULL) { bank->sectors = calloc(pPrivate->nsectors, (sizeof((bank->sectors)[0]))); - if (bank->sectors == NULL){ + if (bank->sectors == NULL) { LOG_ERROR("No memory!"); return ERROR_FAIL; } bank->num_sectors = pPrivate->nsectors; - for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++){ + for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++) { bank->sectors[x].size = pPrivate->sector_size; bank->sectors[x].offset = x * (pPrivate->sector_size); // mark as unknown @@ -1822,13 +1822,13 @@ pPrivate->probed = 1; r = sam3_protect_check(bank); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } LOG_DEBUG("Bank = %d, nbanks = %d", pPrivate->bank_number , pPrivate->pChip->details.n_banks); - if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks){ + if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks) { // read unique id, // it appears to be associated with the *last* flash bank. FLASHD_ReadUniqueID(pPrivate); @@ -1864,17 +1864,17 @@ } r = sam3_auto_probe(bank); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_DEBUG("Here,r=%d",r); return r; } pPrivate = get_sam3_bank_private(bank); - if (!(pPrivate->probed)){ + if (!(pPrivate->probed)) { return ERROR_FLASH_BANK_NOT_PROBED; } - if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors)))){ + if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors)))) { // whole chip LOG_DEBUG("Here"); return FLASHD_EraseEntireBank(pPrivate); @@ -1896,11 +1896,11 @@ } pPrivate = get_sam3_bank_private(bank); - if (!(pPrivate->probed)){ + if (!(pPrivate->probed)) { return ERROR_FLASH_BANK_NOT_PROBED; } - if (set){ + if (set) { r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last)); } else { r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last)); @@ -1937,7 +1937,7 @@ 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, buf); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_ERROR("SAM3: Flash program failed to read page phys address: 0x%08x", (unsigned int)(adr)); } return r; @@ -2051,7 +2051,7 @@ 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, buf); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_ERROR("SAM3: Failed to write (buffer) page at phys address 0x%08x", (unsigned int)(adr)); return r; } @@ -2062,14 +2062,14 @@ pagenum, &status); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_ERROR("SAM3: Error performing Erase & Write page @ phys address 0x%08x", (unsigned int)(adr)); } - if (status & (1 << 2)){ + if (status & (1 << 2)) { LOG_ERROR("SAM3: Page @ Phys address 0x%08x is locked", (unsigned int)(adr)); return ERROR_FAIL; } - if (status & (1 << 1)){ + if (status & (1 << 1)) { LOG_ERROR("SAM3: Flash Command error @phys address 0x%08x", (unsigned int)(adr)); return ERROR_FAIL; } @@ -2095,7 +2095,7 @@ uint8_t *pagebuffer; // ignore dumb requests - if (count == 0){ + if (count == 0) { return ERROR_OK; } @@ -2105,12 +2105,12 @@ } pPrivate = get_sam3_bank_private(bank); - if (!(pPrivate->probed)){ + if (!(pPrivate->probed)) { return ERROR_FLASH_BANK_NOT_PROBED; } - if ((offset + count) > pPrivate->size_bytes){ + if ((offset + count) > pPrivate->size_bytes) { LOG_ERROR("Flash write error - past end of bank"); LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x", (unsigned int)(offset), @@ -2136,10 +2136,10 @@ // (3) non-aligned end. // Handle special case - all one page. - if (page_cur == page_end){ + if (page_cur == page_end) { LOG_DEBUG("Special case, all in one page"); r = sam3_page_read(pPrivate, page_cur, pagebuffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } @@ -2149,7 +2149,7 @@ count); r = sam3_page_write(pPrivate, page_cur, pagebuffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } return ERROR_OK; @@ -2157,11 +2157,11 @@ // non-aligned start page_offset = offset & (pPrivate->page_size - 1); - if (page_offset){ + if (page_offset) { LOG_DEBUG("Not-Aligned start"); // read the partial r = sam3_page_read(pPrivate, page_cur, pagebuffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } @@ -2172,7 +2172,7 @@ n); r = sam3_page_write(pPrivate, page_cur, pagebuffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } @@ -2189,9 +2189,9 @@ (int)page_cur, (int)page_end, (unsigned int)(count)); while ((page_cur < page_end) && - (count >= pPrivate->page_size)){ + (count >= pPrivate->page_size)) { r = sam3_page_write(pPrivate, page_cur, buffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } count -= pPrivate->page_size; @@ -2200,17 +2200,17 @@ } // terminal partial page? - if (count){ + if (count) { LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count)); // we have a partial page r = sam3_page_read(pPrivate, page_cur, pagebuffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } // data goes at start memcpy(pagebuffer, buffer, count); r = sam3_page_write(pPrivate, page_cur, pagebuffer); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } buffer += count; @@ -2230,14 +2230,14 @@ int r; pChip = get_current_sam3(cmd_ctx); - if (!pChip){ + if (!pChip) { return ERROR_OK; } r = 0; // bank0 must exist before we can do anything - if (pChip->details.bank[0].pBank == NULL){ + if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: command_print(cmd_ctx, @@ -2248,9 +2248,9 @@ } // if bank 0 is not probed, then probe it - if (!(pChip->details.bank[0].probed)){ + if (!(pChip->details.bank[0].probed)) { r = sam3_auto_probe(pChip->details.bank[0].pBank); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return ERROR_FAIL; } } @@ -2260,29 +2260,29 @@ // auto-probe other banks, 0 done above - for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++){ + for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++) { // skip banks not present - if (!(pChip->details.bank[x].present)){ + if (!(pChip->details.bank[x].present)) { continue; } - if (pChip->details.bank[x].pBank == NULL){ + if (pChip->details.bank[x].pBank == NULL) { goto need_define; } - if (pChip->details.bank[x].probed){ + if (pChip->details.bank[x].probed) { continue; } r = sam3_auto_probe(pChip->details.bank[x].pBank); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } } r = sam3_GetInfo(pChip); - if (r != ERROR_OK){ + if (r != ERROR_OK) { LOG_DEBUG("Sam3Info, Failed %d\n",r); return r; } @@ -2290,7 +2290,7 @@ // print results cp = membuf_strtok(pChip->mbuf, "\n", &vp); - while (cp){ + while (cp) { command_print(cmd_ctx,"%s", cp); cp = membuf_strtok(NULL, "\n", &vp); } @@ -2306,30 +2306,30 @@ struct sam3_chip *pChip; pChip = get_current_sam3(cmd_ctx); - if (!pChip){ + if (!pChip) { return ERROR_OK; } - if (pChip->target->state != TARGET_HALTED){ + if (pChip->target->state != TARGET_HALTED) { LOG_ERROR("sam3 - target not halted"); return ERROR_TARGET_NOT_HALTED; } - if (pChip->details.bank[0].pBank == NULL){ + if (pChip->details.bank[0].pBank == NULL) { command_print(cmd_ctx, "Bank0 must be defined first via: flash bank %s ...", at91sam3_flash.name); return ERROR_FAIL; } - if (!pChip->details.bank[0].probed){ + if (!pChip->details.bank[0].probed) { r = sam3_auto_probe(pChip->details.bank[0].pBank); - if (r != ERROR_OK){ + if (r != ERROR_OK) { return r; } } - switch (argc){ + switch (argc) { default: command_print(cmd_ctx,"Too many parameters\n"); return ERROR_COMMAND_SYNTAX_ERROR; @@ -2342,11 +2342,11 @@ who = -1; break; case 2: - if ((0 == strcmp(argv[0], "show")) && (0 == strcmp(argv[1], "all"))){ + if ((0 == strcmp(argv[0], "show")) && (0 == strcmp(argv[1], "all"))) { who = -1; } else { r = parse_u32(argv[1], &v32); - if (r != ERROR_OK){ + if (r != ERROR_OK) { command_print(cmd_ctx, "Not a number: %s", argv[1]); return r; } @@ -2355,19 +2355,19 @@ break; } - if (0 == strcmp("show", argv[0])){ - if (who == -1){ + if (0 == strcmp("show", argv[0])) { + if (who == -1) { showall: - for (x = 0 ; x < pChip->details.n_gpnvms ; x++){ + for (x = 0 ; x < pChip->details.n_gpnvms ; x++) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); - if (r != ERROR_OK){ + if (r != ERROR_OK) { break; } command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v); } return r; } - if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)){ + if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v); return r; @@ -2377,15 +2377,15 @@ } } - if (who == -1){ + if (who == -1) { command_print(cmd_ctx, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } - if (0 == strcmp("set", argv[0])){ + if (0 == strcmp("set", argv[0])) { r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who); } else if ((0 == strcmp("clr", argv[0])) || - (0 == strcmp("clear", argv[0]))){ // quietly accept both + (0 == strcmp("clear", argv[0]))) { // quietly accept both r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); } else { command_print(cmd_ctx, "Unkown command: %s", argv[0]); @@ -2403,19 +2403,19 @@ struct sam3_chip *pChip; pChip = get_current_sam3(cmd_ctx); - if (!pChip){ + if (!pChip) { return ERROR_OK; } - switch (argc){ + switch (argc) { case 0: // show break; case 1: // set r = parse_u32(argv[0], &v); - if (v > 200000){ + if (v > 200000) { // absurd slow clock of 200Khz? command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; @@ -2443,7 +2443,7 @@ command_t *pCmd; // only register once - if (!sam3_registered){ + if (!sam3_registered) { sam3_registered++; pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:38:08 UTC (rev 2396) +++ trunk/src/helper/membuf.c 2009-06-24 09:38:15 UTC (rev 2397) @@ -55,7 +55,7 @@ const char * membuf_strtok(struct membuf *pBuf, const char *sep, void **pLast) { - if (pBuf){ + if (pBuf) { pBuf->_strtoklast = NULL; *pLast = pBuf; return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast)); @@ -75,10 +75,10 @@ struct membuf *pBuf; pBuf = calloc(1, sizeof(*pBuf)); - if (pBuf){ + if (pBuf) { // we *ALWAYS* allocate +1 for null terminator. pBuf->buf = calloc(DEFAULT_BUFSIZE + 1, sizeof(char)); - if (pBuf->buf == NULL){ + if (pBuf->buf == NULL) { free(pBuf); pBuf = NULL; } else { @@ -99,13 +99,13 @@ newsize = ((int)(pBuf->maxlen)) + n; // do not go negative, or too small - if (newsize < DEFAULT_BUFSIZE){ + if (newsize < DEFAULT_BUFSIZE) { newsize = DEFAULT_BUFSIZE; } // always alloc +1 for the null terminator vp = realloc(pBuf->buf, newsize + 1); - if (vp){ + if (vp) { pBuf->buf = vp; pBuf->maxlen = newsize; return pBuf; @@ -123,8 +123,8 @@ void membuf_delete(struct membuf *pBuf) { - if (pBuf){ - if (pBuf->buf){ + if (pBuf) { + if (pBuf->buf) { // wack data so it cannot be reused memset(pBuf->buf,0,pBuf->maxlen); free(pBuf->buf); @@ -163,7 +163,7 @@ sa, fmt, ap); - if ((r > 0) && (((size_t)(r)) < sa)){ + if ((r > 0) && (((size_t)(r)) < sa)) { // Success! pBuf->curlen += ((size_t)(r)); // remember: We always alloc'ed +1 @@ -174,7 +174,7 @@ } // failure - if (r < 0){ + if (r < 0) { // Option(A) format error // Option(B) glibc2.0 bug // assume (B). @@ -182,13 +182,13 @@ } // don't do this again - if (grew){ + if (grew) { r = -1; break; } grew = 1; pBuf = membuf_grow(pBuf, r); - if (pBuf == NULL){ + if (pBuf == NULL) { // grow failed r = -1; break; @@ -213,13 +213,13 @@ sa = space_avail(pBuf); // will it fit? - if (sa < len){ + if (sa < len) { // if not, how much do we need? r = ((int)(sa - len)); // do the grow. pBuf = membuf_grow(pBuf, r); // failed? - if (pBuf == NULL){ + if (pBuf == NULL) { return pBuf; } } |
From: <zw...@ma...> - 2009-06-24 11:38:12
|
Author: zwelch Date: 2009-06-24 11:38:08 +0200 (Wed, 24 Jun 2009) New Revision: 2396 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c trunk/src/helper/membuf.h Log: Remove whitespace that occurs before ')'. - Replace '[ \t]*[)]' with ')'. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:38:01 UTC (rev 2395) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:38:08 UTC (rev 2396) @@ -100,7 +100,7 @@ static float -_tomhz(uint32_t freq_hz ) +_tomhz(uint32_t freq_hz) { float f; @@ -224,34 +224,34 @@ struct sam3_reg_list { uint32_t address; size_t struct_offset; const char *name; - void (*explain_func)(struct sam3_chip *pInfo ); + void (*explain_func)(struct sam3_chip *pInfo); }; static struct sam3_chip *all_sam3_chips; static struct sam3_chip * -get_current_sam3(struct command_context_s *cmd_ctx ) +get_current_sam3(struct command_context_s *cmd_ctx) { target_t *t; static struct sam3_chip *p; - t = get_current_target(cmd_ctx ); - if (!t ){ + t = get_current_target(cmd_ctx); + if (!t){ command_print(cmd_ctx, "No current target?"); return NULL; } p = all_sam3_chips; - if (!p ){ + if (!p){ // this should not happen // the command is not registered until the chip is created? command_print(cmd_ctx, "No SAM3 chips exist?"); return NULL; } - while (p ){ - if (p->target == t ){ + while (p){ + if (p->target == t){ return p; } p = p->next; @@ -540,10 +540,10 @@ * @param v - result goes here */ static int -EFC_GetStatus(struct sam3_bank_private *pPrivate, uint32_t *v ) +EFC_GetStatus(struct sam3_bank_private *pPrivate, uint32_t *v) { int r; - r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FSR, v ); + r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FSR, v); LOG_DEBUG("Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)", (unsigned int)(*v), ((unsigned int)((*v >> 2) & 1)), @@ -558,12 +558,12 @@ * @param v - result goes here */ static int -EFC_GetResult(struct sam3_bank_private *pPrivate, uint32_t *v ) +EFC_GetResult(struct sam3_bank_private *pPrivate, uint32_t *v) { int r; uint32_t rv; - r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv ); - if (v ){ + r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv); + if (v){ *v = rv; } LOG_DEBUG("Result: 0x%08x", ((unsigned int)(rv))); @@ -572,7 +572,7 @@ static int EFC_StartCommand(struct sam3_bank_private *pPrivate, - unsigned command, unsigned argument ) + unsigned command, unsigned argument) { uint32_t n,v; int r; @@ -593,16 +593,16 @@ case AT91C_EFC_FCMD_SLB: case AT91C_EFC_FCMD_CLB: n = (pPrivate->size_bytes / pPrivate->page_size); - if (argument >= n ){ + if (argument >= n){ LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n)); } break; case AT91C_EFC_FCMD_SFB: case AT91C_EFC_FCMD_CFB: - if (argument >= pPrivate->pChip->details.n_gpnvms ){ + if (argument >= pPrivate->pChip->details.n_gpnvms){ LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs", - pPrivate->pChip->details.n_gpnvms ); + pPrivate->pChip->details.n_gpnvms); } break; @@ -612,8 +612,8 @@ case AT91C_EFC_FCMD_GFB: case AT91C_EFC_FCMD_STUI: case AT91C_EFC_FCMD_SPUI: - if (argument != 0 ){ - LOG_ERROR("Argument is meaningless for cmd: %d", command ); + if (argument != 0){ + LOG_ERROR("Argument is meaningless for cmd: %d", command); } break; default: @@ -621,42 +621,42 @@ break; } - if (command == AT91C_EFC_FCMD_SPUI ){ + if (command == AT91C_EFC_FCMD_SPUI){ // this is a very special situation. // Situation (1) - error/retry - see below // And we are being called recursively // Situation (2) - normal, finished reading unique id } else { // it should be "ready" - EFC_GetStatus(pPrivate, &v ); - if (v & 1 ){ + EFC_GetStatus(pPrivate, &v); + if (v & 1){ // then it is ready // we go on } else { - if (retry ){ + if (retry){ // we have done this before // the controller is not responding. - LOG_ERROR("flash controller(%d) is not ready! Error", pPrivate->bank_number ); + LOG_ERROR("flash controller(%d) is not ready! Error", pPrivate->bank_number); return ERROR_FAIL; } else { retry++; LOG_ERROR("Flash controller(%d) is not ready, attempting reset", - pPrivate->bank_number ); + pPrivate->bank_number); // we do that by issuing the *STOP* command - EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0 ); + EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0); // above is recursive, and further recursion is blocked by - // if (command == AT91C_EFC_FCMD_SPUI ) above + // if (command == AT91C_EFC_FCMD_SPUI) above goto do_retry; } } } v = (0x5A << 24) | (argument << 8) | command; - LOG_DEBUG("Command: 0x%08x", ((unsigned int)(v)) ); + LOG_DEBUG("Command: 0x%08x", ((unsigned int)(v))); r = target_write_u32(pPrivate->pBank->target, pPrivate->controller_address + offset_EFC_FCR, v); - if (r != ERROR_OK ){ + if (r != ERROR_OK){ LOG_DEBUG("Error Write failed"); } return r; @@ -681,12 +681,12 @@ long long ms_now, ms_end; // default - if (status ){ + if (status){ *status = 0; } - r = EFC_StartCommand(pPrivate, command, argument ); - if (r != ERROR_OK ){ + r = EFC_StartCommand(pPrivate, command, argument); + if (r != ERROR_OK){ return r; } @@ -694,22 +694,22 @@ do { - r = EFC_GetStatus(pPrivate, &v ); - if (r != ERROR_OK ){ + r = EFC_GetStatus(pPrivate, &v); + if (r != ERROR_OK){ return r; } ms_now = timeval_ms(); - if (ms_now > ms_end ){ + if (ms_now > ms_end){ // error LOG_ERROR("Command timeout"); return ERROR_FAIL; } } - while ((v & 1) == 0 ) + while ((v & 1) == 0) ; // error bits.. - if (status ){ + if (status){ *status = (v & 0x6); } return ERROR_OK; @@ -728,7 +728,7 @@ */ static int -FLASHD_ReadUniqueID (struct sam3_bank_private *pPrivate ) +FLASHD_ReadUniqueID (struct sam3_bank_private *pPrivate) { int r; uint32_t v; @@ -741,21 +741,21 @@ LOG_DEBUG("Begin"); r = EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_STUI, 0); - if (r < 0 ){ + if (r < 0){ return r; } - for (x = 0 ; x < 4 ; x++ ){ + for (x = 0 ; x < 4 ; x++){ r = target_read_u32(pPrivate->pChip->target, pPrivate->pBank->base + (x * 4), - &v ); - if (r < 0 ){ + &v); + if (r < 0){ return r; } pPrivate->pChip->cfg.unique_id[x] = v; } - r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0, NULL ); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0, NULL); LOG_DEBUG("End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x", r, (unsigned int)(pPrivate->pChip->cfg.unique_id[0]), @@ -770,10 +770,10 @@ * @param pPrivate - the info about the bank. */ static int -FLASHD_EraseEntireBank(struct sam3_bank_private *pPrivate ) +FLASHD_EraseEntireBank(struct sam3_bank_private *pPrivate) { LOG_DEBUG("Here"); - return EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_EA, 0, NULL ); + return EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_EA, 0, NULL); } @@ -792,27 +792,27 @@ int r; LOG_DEBUG("Here"); - if (pPrivate->bank_number != 0 ){ + if (pPrivate->bank_number != 0){ LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if (gpnvm >= pPrivate->pChip->details.n_gpnvms ){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms){ LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", - gpnvm,pPrivate->pChip->details.n_gpnvms ); + gpnvm,pPrivate->pChip->details.n_gpnvms); return ERROR_FAIL; } // Get GPNVMs status - r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL ); - if (r != ERROR_OK ){ + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL); + if (r != ERROR_OK){ LOG_ERROR("Failed"); return r; } - r = EFC_GetResult(pPrivate, &v ); + r = EFC_GetResult(pPrivate, &v); - if (puthere ){ + if (puthere){ // Check if GPNVM is set // get the bit and make it a 0/1 *puthere = (v >> gpnvm) & 1; @@ -836,19 +836,19 @@ unsigned v; LOG_DEBUG("Here"); - if (pPrivate->bank_number != 0 ){ + if (pPrivate->bank_number != 0){ LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if (gpnvm >= pPrivate->pChip->details.n_gpnvms ){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms){ LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", - gpnvm,pPrivate->pChip->details.n_gpnvms ); + gpnvm,pPrivate->pChip->details.n_gpnvms); return ERROR_FAIL; } - r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v ); - if (r != ERROR_OK ){ + r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v); + if (r != ERROR_OK){ LOG_DEBUG("Failed: %d",r); return r; } @@ -869,27 +869,27 @@ int r; unsigned v; - if (pPrivate->bank_number != 0 ){ + if (pPrivate->bank_number != 0){ LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if (gpnvm >= pPrivate->pChip->details.n_gpnvms ){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms){ LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", - gpnvm,pPrivate->pChip->details.n_gpnvms ); + gpnvm,pPrivate->pChip->details.n_gpnvms); return ERROR_FAIL; } - r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v ); - if (r != ERROR_OK ){ + r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v); + if (r != ERROR_OK){ return r; } - if (v ){ + if (v){ // already set r = ERROR_OK; } else { // set it - r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SFB, gpnvm, NULL ); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SFB, gpnvm, NULL); } return r; } @@ -902,13 +902,13 @@ */ static int -FLASHD_GetLockBits(struct sam3_bank_private *pPrivate, uint32_t *v ) +FLASHD_GetLockBits(struct sam3_bank_private *pPrivate, uint32_t *v) { int r; LOG_DEBUG("Here"); r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL); - if (r == ERROR_OK ){ - r = EFC_GetResult(pPrivate, v ); + if (r == ERROR_OK){ + r = EFC_GetResult(pPrivate, v); } LOG_DEBUG("End: %d",r); return r; @@ -924,7 +924,7 @@ static int FLASHD_Unlock(struct sam3_bank_private *pPrivate, unsigned start_sector, - unsigned end_sector ) + unsigned end_sector) { int r; uint32_t status; @@ -937,7 +937,7 @@ while (start_sector <= end_sector){ pg = start_sector * pages_per_sector; - r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_CLB, pg, &status ); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_CLB, pg, &status); if (r != ERROR_OK) { return r; } @@ -958,7 +958,7 @@ static int FLASHD_Lock(struct sam3_bank_private *pPrivate, unsigned start_sector, - unsigned end_sector ) + unsigned end_sector) { uint32_t status; uint32_t pg; @@ -971,7 +971,7 @@ while (start_sector <= end_sector){ pg = start_sector * pages_per_sector; - r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SLB, pg, &status ); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SLB, pg, &status); if (r != ERROR_OK) { return r; } @@ -986,15 +986,15 @@ /* begin helpful debug code */ static void -sam3_sprintf(struct sam3_chip *pChip , const char *fmt, ... ) +sam3_sprintf(struct sam3_chip *pChip , const char *fmt, ...) { va_list ap; va_start(ap,fmt); - if (pChip->mbuf == NULL ){ + if (pChip->mbuf == NULL){ return; } - membuf_vsprintf(pChip->mbuf, fmt, ap ); + membuf_vsprintf(pChip->mbuf, fmt, ap); va_end(ap); } @@ -1013,7 +1013,7 @@ // extract the field v = value >> shift; v = v & ((1 << width)-1); - if (width <= 16 ){ + if (width <= 16){ hwidth = 4; dwidth = 5; } else { @@ -1025,7 +1025,7 @@ sam3_sprintf(pChip, "\t%*s: %*d [0x%0*x] ", REG_NAME_WIDTH, regname, dwidth, v, - hwidth, v ); + hwidth, v); return v; } @@ -1137,9 +1137,9 @@ }; -static const char *_yes_or_no(uint32_t v ) +static const char *_yes_or_no(uint32_t v) { - if (v ){ + if (v){ return "YES"; } else { return "NO"; @@ -1151,27 +1151,27 @@ }; static void -sam3_explain_ckgr_mor(struct sam3_chip *pChip ) +sam3_explain_ckgr_mor(struct sam3_chip *pChip) { uint32_t v; uint32_t rcen; - v = sam3_reg_fieldname(pChip, "MOSCXTEN", pChip->cfg.CKGR_MOR, 0, 1 ); + v = sam3_reg_fieldname(pChip, "MOSCXTEN", pChip->cfg.CKGR_MOR, 0, 1); sam3_sprintf(pChip, "(main xtal enabled: %s)\n", - _yes_or_no(v) ); - v = sam3_reg_fieldname(pChip, "MOSCXTBY", pChip->cfg.CKGR_MOR, 1, 1 ); + _yes_or_no(v)); + v = sam3_reg_fieldname(pChip, "MOSCXTBY", pChip->cfg.CKGR_MOR, 1, 1); sam3_sprintf(pChip, "(main osc bypass: %s)\n", - _yes_or_no(v) ); - rcen = sam3_reg_fieldname(pChip, "MOSCRCEN", pChip->cfg.CKGR_MOR, 2, 1 ); + _yes_or_no(v)); + rcen = sam3_reg_fieldname(pChip, "MOSCRCEN", pChip->cfg.CKGR_MOR, 2, 1); sam3_sprintf(pChip, "(onchip RC-OSC enabled: %s)\n", - _yes_or_no(rcen) ); - v = sam3_reg_fieldname(pChip, "MOSCRCF", pChip->cfg.CKGR_MOR, 4, 3 ); + _yes_or_no(rcen)); + v = sam3_reg_fieldname(pChip, "MOSCRCF", pChip->cfg.CKGR_MOR, 4, 3); sam3_sprintf(pChip, "(onchip RC-OSC freq: %s)\n", - _rc_freq[v] ); + _rc_freq[v]); pChip->cfg.rc_freq = 0; - if (rcen ){ - switch (v ){ + if (rcen){ + switch (v){ default: pChip->cfg.rc_freq = 0; case 0: @@ -1186,14 +1186,14 @@ } } - v = sam3_reg_fieldname(pChip,"MOSCXTST", pChip->cfg.CKGR_MOR, 8, 8 ); + v = sam3_reg_fieldname(pChip,"MOSCXTST", pChip->cfg.CKGR_MOR, 8, 8); sam3_sprintf(pChip, "(startup clks, time= %f uSecs)\n", ((float)(v * 1000000)) / ((float)(pChip->cfg.slow_freq))); - v = sam3_reg_fieldname(pChip, "MOSCSEL", pChip->cfg.CKGR_MOR, 24, 1 ); + v = sam3_reg_fieldname(pChip, "MOSCSEL", pChip->cfg.CKGR_MOR, 24, 1); sam3_sprintf(pChip, "(mainosc source: %s)\n", v ? "external xtal" : "internal RC"); - v = sam3_reg_fieldname(pChip,"CFDEN", pChip->cfg.CKGR_MOR, 25, 1 ); + v = sam3_reg_fieldname(pChip,"CFDEN", pChip->cfg.CKGR_MOR, 25, 1); sam3_sprintf(pChip, "(clock failure enabled: %s)\n", _yes_or_no(v)); } @@ -1201,97 +1201,97 @@ static void -sam3_explain_chipid_cidr(struct sam3_chip *pChip ) +sam3_explain_chipid_cidr(struct sam3_chip *pChip) { int x; uint32_t v; const char *cp; - sam3_reg_fieldname(pChip, "Version", pChip->cfg.CHIPID_CIDR, 0, 5 ); + sam3_reg_fieldname(pChip, "Version", pChip->cfg.CHIPID_CIDR, 0, 5); sam3_sprintf(pChip,"\n"); - v = sam3_reg_fieldname(pChip, "EPROC", pChip->cfg.CHIPID_CIDR, 5, 3 ); + v = sam3_reg_fieldname(pChip, "EPROC", pChip->cfg.CHIPID_CIDR, 5, 3); sam3_sprintf(pChip, "%s\n", eproc_names[v]); - v = sam3_reg_fieldname(pChip, "NVPSIZE", pChip->cfg.CHIPID_CIDR, 8, 4 ); + v = sam3_reg_fieldname(pChip, "NVPSIZE", pChip->cfg.CHIPID_CIDR, 8, 4); sam3_sprintf(pChip, "%s\n", nvpsize[v]); - v = sam3_reg_fieldname(pChip, "NVPSIZE2", pChip->cfg.CHIPID_CIDR, 12, 4 ); + v = sam3_reg_fieldname(pChip, "NVPSIZE2", pChip->cfg.CHIPID_CIDR, 12, 4); sam3_sprintf(pChip, "%s\n", nvpsize2[v]); - v = sam3_reg_fieldname(pChip, "SRAMSIZE", pChip->cfg.CHIPID_CIDR, 16,4 ); - sam3_sprintf(pChip, "%s\n", sramsize[ v ] ); + v = sam3_reg_fieldname(pChip, "SRAMSIZE", pChip->cfg.CHIPID_CIDR, 16,4); + sam3_sprintf(pChip, "%s\n", sramsize[ v ]); - v = sam3_reg_fieldname(pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8 ); + v = sam3_reg_fieldname(pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8); cp = _unknown; - for (x = 0 ; archnames[x].name ; x++ ){ - if (v == archnames[x].value ){ + for (x = 0 ; archnames[x].name ; x++){ + if (v == archnames[x].value){ cp = archnames[x].name; break; } } - sam3_sprintf(pChip, "%s\n", cp ); + sam3_sprintf(pChip, "%s\n", cp); - v = sam3_reg_fieldname(pChip, "NVPTYP", pChip->cfg.CHIPID_CIDR, 28, 3 ); - sam3_sprintf(pChip, "%s\n", nvptype[ v ] ); + v = sam3_reg_fieldname(pChip, "NVPTYP", pChip->cfg.CHIPID_CIDR, 28, 3); + sam3_sprintf(pChip, "%s\n", nvptype[ v ]); - v = sam3_reg_fieldname(pChip, "EXTID", pChip->cfg.CHIPID_CIDR, 31, 1 ); + v = sam3_reg_fieldname(pChip, "EXTID", pChip->cfg.CHIPID_CIDR, 31, 1); sam3_sprintf(pChip, "(exists: %s)\n", _yes_or_no(v)); } static void -sam3_explain_ckgr_mcfr(struct sam3_chip *pChip ) +sam3_explain_ckgr_mcfr(struct sam3_chip *pChip) { uint32_t v; - v = sam3_reg_fieldname(pChip, "MAINFRDY", pChip->cfg.CKGR_MCFR, 16, 1 ); - sam3_sprintf(pChip, "(main ready: %s)\n", _yes_or_no(v )); + v = sam3_reg_fieldname(pChip, "MAINFRDY", pChip->cfg.CKGR_MCFR, 16, 1); + sam3_sprintf(pChip, "(main ready: %s)\n", _yes_or_no(v)); - v = sam3_reg_fieldname(pChip, "MAINF", pChip->cfg.CKGR_MCFR, 0, 16 ); + v = sam3_reg_fieldname(pChip, "MAINF", pChip->cfg.CKGR_MCFR, 0, 16); v = (v * pChip->cfg.slow_freq) / 16; pChip->cfg.mainosc_freq = v; sam3_sprintf(pChip, "(%3.03f Mhz (%d.%03dkhz slowclk)\n", - _tomhz(v ), + _tomhz(v), pChip->cfg.slow_freq / 1000, pChip->cfg.slow_freq % 1000); } static void -sam3_explain_ckgr_plla(struct sam3_chip *pChip ) +sam3_explain_ckgr_plla(struct sam3_chip *pChip) { uint32_t mula,diva; - diva = sam3_reg_fieldname(pChip, "DIVA", pChip->cfg.CKGR_PLLAR, 0, 8 ); + diva = sam3_reg_fieldname(pChip, "DIVA", pChip->cfg.CKGR_PLLAR, 0, 8); sam3_sprintf(pChip,"\n"); - mula = sam3_reg_fieldname(pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11 ); + mula = sam3_reg_fieldname(pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11); sam3_sprintf(pChip,"\n"); pChip->cfg.plla_freq = 0; - if (mula == 0 ){ + if (mula == 0){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula = 0)\n"); - } else if (diva == 0 ){ + } else if (diva == 0){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n"); - } else if (diva == 1 ){ + } else if (diva == 1){ pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula + 1)); sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n", - _tomhz(pChip->cfg.plla_freq )); + _tomhz(pChip->cfg.plla_freq)); } } static void -sam3_explain_mckr(struct sam3_chip *pChip ) +sam3_explain_mckr(struct sam3_chip *pChip) { uint32_t css, pres,fin; int pdiv; const char *cp; - css = sam3_reg_fieldname(pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2 ); - switch (css & 3 ){ + css = sam3_reg_fieldname(pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2); + switch (css & 3){ case 0: fin = pChip->cfg.slow_freq; cp = "slowclk"; @@ -1305,7 +1305,7 @@ cp = "plla"; break; case 3: - if (pChip->cfg.CKGR_UCKR & (1 << 16) ){ + if (pChip->cfg.CKGR_UCKR & (1 << 16)){ fin = 480 * 1000 * 1000; cp = "upll"; } else { @@ -1317,9 +1317,9 @@ sam3_sprintf(pChip, "%s (%3.03f Mhz)\n", cp, - _tomhz(fin ) ); - pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3 ); - switch (pres & 0x07 ){ + _tomhz(fin)); + pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3); + switch (pres & 0x07){ case 0: pdiv = 1; cp = "selected clock"; @@ -1352,7 +1352,7 @@ cp = "clock/6"; break; } - sam3_sprintf(pChip, "(%s)\n", cp ); + sam3_sprintf(pChip, "(%s)\n", cp); fin = fin / pdiv; // sam3 has a *SINGLE* clock - // other at91 series parts have divisors for these. @@ -1360,22 +1360,22 @@ pChip->cfg.mclk_freq = fin; pChip->cfg.fclk_freq = fin; sam3_sprintf(pChip, "\t\tResult CPU Freq: %3.03f\n", - _tomhz(fin ) ); + _tomhz(fin)); } #if 0 static struct sam3_chip * -target2sam3(target_t *pTarget ) +target2sam3(target_t *pTarget) { struct sam3_chip *pChip; - if (pTarget == NULL ){ + if (pTarget == NULL){ return NULL; } pChip = all_sam3_chips; while (pChip){ - if (pChip->target == pTarget ){ + if (pChip->target == pTarget){ break; // return below } else { pChip = pChip->next; @@ -1386,7 +1386,7 @@ #endif static uint32_t * -sam3_get_reg_ptr(struct sam3_cfg *pCfg, const struct sam3_reg_list *pList ) +sam3_get_reg_ptr(struct sam3_cfg *pCfg, const struct sam3_reg_list *pList) { // this function exists to help // keep funky offsetof() errors @@ -1395,29 +1395,29 @@ // By using prototypes - we can detect what would // be casting errors. - return ((uint32_t *)(((char *)(pCfg)) + pList->struct_offset )); + return ((uint32_t *)(((char *)(pCfg)) + pList->struct_offset)); } -#define SAM3_ENTRY(NAME, FUNC ) { .address = SAM3_ ## NAME, .struct_offset = offsetof(struct sam3_cfg, NAME ), #NAME, FUNC } +#define SAM3_ENTRY(NAME, FUNC) { .address = SAM3_ ## NAME, .struct_offset = offsetof(struct sam3_cfg, NAME), #NAME, FUNC } static const struct sam3_reg_list sam3_all_regs[] = { - SAM3_ENTRY(CKGR_MOR , sam3_explain_ckgr_mor ), - SAM3_ENTRY(CKGR_MCFR , sam3_explain_ckgr_mcfr ), - SAM3_ENTRY(CKGR_PLLAR , sam3_explain_ckgr_plla ), - SAM3_ENTRY(CKGR_UCKR , NULL ), - SAM3_ENTRY(PMC_FSMR , NULL ), - SAM3_ENTRY(PMC_FSPR , NULL ), - SAM3_ENTRY(PMC_IMR , NULL ), - SAM3_ENTRY(PMC_MCKR , sam3_explain_mckr ), - SAM3_ENTRY(PMC_PCK0 , NULL ), - SAM3_ENTRY(PMC_PCK1 , NULL ), - SAM3_ENTRY(PMC_PCK2 , NULL ), - SAM3_ENTRY(PMC_PCSR , NULL ), - SAM3_ENTRY(PMC_SCSR , NULL ), - SAM3_ENTRY(PMC_SR , NULL ), - SAM3_ENTRY(CHIPID_CIDR , sam3_explain_chipid_cidr ), - SAM3_ENTRY(CHIPID_EXID , NULL ), - SAM3_ENTRY(SUPC_CR, NULL ), + SAM3_ENTRY(CKGR_MOR , sam3_explain_ckgr_mor), + SAM3_ENTRY(CKGR_MCFR , sam3_explain_ckgr_mcfr), + SAM3_ENTRY(CKGR_PLLAR , sam3_explain_ckgr_plla), + SAM3_ENTRY(CKGR_UCKR , NULL), + SAM3_ENTRY(PMC_FSMR , NULL), + SAM3_ENTRY(PMC_FSPR , NULL), + SAM3_ENTRY(PMC_IMR , NULL), + SAM3_ENTRY(PMC_MCKR , sam3_explain_mckr), + SAM3_ENTRY(PMC_PCK0 , NULL), + SAM3_ENTRY(PMC_PCK1 , NULL), + SAM3_ENTRY(PMC_PCK2 , NULL), + SAM3_ENTRY(PMC_PCSR , NULL), + SAM3_ENTRY(PMC_SCSR , NULL), + SAM3_ENTRY(PMC_SR , NULL), + SAM3_ENTRY(CHIPID_CIDR , sam3_explain_chipid_cidr), + SAM3_ENTRY(CHIPID_EXID , NULL), + SAM3_ENTRY(SUPC_CR, NULL), // TERMINATE THE LIST { .name = NULL } @@ -1428,7 +1428,7 @@ static struct sam3_bank_private * -get_sam3_bank_private(flash_bank_t *bank ) +get_sam3_bank_private(flash_bank_t *bank) { return (struct sam3_bank_private *)(bank->driver_priv); } @@ -1438,7 +1438,7 @@ * Determine the register name, address from the all registers table. */ static const struct sam3_reg_list * -sam3_GetReg(struct sam3_chip *pChip, uint32_t *goes_here ) +sam3_GetReg(struct sam3_chip *pChip, uint32_t *goes_here) { const struct sam3_reg_list *pReg; @@ -1449,10 +1449,10 @@ // calculate where this one go.. // it is "possibly" this register. - pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset )); + pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset)); // well? Is it this register - if (pPossible == goes_here ){ + if (pPossible == goes_here){ // Jump for joy! return pReg; } @@ -1467,20 +1467,20 @@ static int -sam3_ReadThisReg(struct sam3_chip *pChip, uint32_t *goes_here ) +sam3_ReadThisReg(struct sam3_chip *pChip, uint32_t *goes_here) { const struct sam3_reg_list *pReg; int r; - pReg = sam3_GetReg(pChip, goes_here ); - if (!pReg ){ + pReg = sam3_GetReg(pChip, goes_here); + if (!pReg){ return ERROR_FAIL; } - r = target_read_u32(pChip->target, pReg->address, goes_here ); - if (r != ERROR_OK ){ + r = target_read_u32(pChip->target, pReg->address, goes_here); + if (r != ERROR_OK){ LOG_ERROR("Cannot read SAM3 register: %s @ 0x%08x, Err: %d\n", - pReg->name, (unsigned)(pReg->address), r ); + pReg->name, (unsigned)(pReg->address), r); } return r; } @@ -1488,18 +1488,18 @@ static int -sam3_ReadAllRegs(struct sam3_chip *pChip ) +sam3_ReadAllRegs(struct sam3_chip *pChip) { int r; const struct sam3_reg_list *pReg; pReg = &(sam3_all_regs[0]); - while (pReg->name ){ + while (pReg->name){ r = sam3_ReadThisReg(pChip, - sam3_get_reg_ptr(&(pChip->cfg), pReg ) ); - if (r != ERROR_OK ){ + sam3_get_reg_ptr(&(pChip->cfg), pReg)); + if (r != ERROR_OK){ LOG_ERROR("Cannot read SAM3 registere: %s @ 0x%08x, Error: %d\n", - pReg->name, ((unsigned)(pReg->address)), r ); + pReg->name, ((unsigned)(pReg->address)), r); return r; } @@ -1511,35 +1511,35 @@ static int -sam3_GetInfo(struct sam3_chip *pChip ) +sam3_GetInfo(struct sam3_chip *pChip) { const struct sam3_reg_list *pReg; uint32_t regval; - membuf_reset(pChip->mbuf ); + membuf_reset(pChip->mbuf); pReg = &(sam3_all_regs[0]); while (pReg->name){ // display all regs - LOG_DEBUG("Start: %s", pReg->name ); - regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg ); + LOG_DEBUG("Start: %s", pReg->name); + regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg); sam3_sprintf(pChip, "%*s: [0x%08x] -> 0x%08x\n", REG_NAME_WIDTH, pReg->name, pReg->address, - regval ); - if (pReg->explain_func ){ - (*(pReg->explain_func))(pChip ); + regval); + if (pReg->explain_func){ + (*(pReg->explain_func))(pChip); } - LOG_DEBUG("End: %s", pReg->name ); + LOG_DEBUG("End: %s", pReg->name); pReg++; } - sam3_sprintf(pChip," rc-osc: %3.03f MHz\n", _tomhz(pChip->cfg.rc_freq )); - sam3_sprintf(pChip," mainosc: %3.03f MHz\n", _tomhz(pChip->cfg.mainosc_freq )); - sam3_sprintf(pChip," plla: %3.03f MHz\n", _tomhz(pChip->cfg.plla_freq )); - sam3_sprintf(pChip," cpu-freq: %3.03f MHz\n", _tomhz(pChip->cfg.cpu_freq )); - sam3_sprintf(pChip,"mclk-freq: %3.03f MHz\n", _tomhz(pChip->cfg.mclk_freq )); + sam3_sprintf(pChip," rc-osc: %3.03f MHz\n", _tomhz(pChip->cfg.rc_freq)); + sam3_sprintf(pChip," mainosc: %3.03f MHz\n", _tomhz(pChip->cfg.mainosc_freq)); + sam3_sprintf(pChip," plla: %3.03f MHz\n", _tomhz(pChip->cfg.plla_freq)); + sam3_sprintf(pChip," cpu-freq: %3.03f MHz\n", _tomhz(pChip->cfg.cpu_freq)); + sam3_sprintf(pChip,"mclk-freq: %3.03f MHz\n", _tomhz(pChip->cfg.mclk_freq)); sam3_sprintf(pChip, " UniqueId: 0x%08x 0x%08x 0x%08x 0x%08x\n", @@ -1563,13 +1563,13 @@ LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } - if (0 == bank->num_sectors ){ + if (0 == bank->num_sectors){ LOG_ERROR("Target: not supported/not probed\n"); return ERROR_FAIL; } LOG_INFO("sam3 - supports auto-erase, erase_check ignored"); - for (x = 0 ; x < bank->num_sectors ; x++ ){ + for (x = 0 ; x < bank->num_sectors ; x++){ bank->sectors[x].is_erased = 1; } @@ -1592,21 +1592,21 @@ } pPrivate = get_sam3_bank_private(bank); - if (!pPrivate ){ + if (!pPrivate){ LOG_ERROR("no private for this bank?"); return ERROR_FAIL; } - if (!(pPrivate->probed) ){ + if (!(pPrivate->probed)){ return ERROR_FLASH_BANK_NOT_PROBED; } - r = FLASHD_GetLockBits(pPrivate , &v ); - if (r != ERROR_OK ){ + r = FLASHD_GetLockBits(pPrivate , &v); + if (r != ERROR_OK){ LOG_DEBUG("Failed: %d",r); return r; } - for (x = 0 ; x < pPrivate->nsectors ; x++ ){ + for (x = 0 ; x < pPrivate->nsectors ; x++){ bank->sectors[x].is_protected = (!!(v & (1 << x))); } LOG_DEBUG("Done"); @@ -1626,16 +1626,16 @@ // is this an existing chip? while (pChip){ - if (pChip->target == bank->target ){ + if (pChip->target == bank->target){ break; } pChip = pChip->next; } - if (!pChip ){ + if (!pChip){ // this is a *NEW* chip - pChip = calloc(1, sizeof(struct sam3_chip) ); - if (!pChip ){ + pChip = calloc(1, sizeof(struct sam3_chip)); + if (!pChip){ LOG_ERROR("NO RAM!"); return ERROR_FAIL; } @@ -1648,13 +1648,13 @@ pChip->cfg.slow_freq = 32768; pChip->probed = 0; pChip->mbuf = membuf_new(); - if (!(pChip->mbuf) ){ + if (!(pChip->mbuf)){ LOG_ERROR("no memory"); return ERROR_FAIL; } } - switch (bank->base ){ + switch (bank->base){ default: LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x or 0x%08x)", ((unsigned int)(bank->base)), @@ -1681,7 +1681,7 @@ } static int -sam3_GetDetails(struct sam3_bank_private *pPrivate ) +sam3_GetDetails(struct sam3_bank_private *pPrivate) { const struct sam3_chip_details *pDetails; struct sam3_chip *pChip; @@ -1693,26 +1693,26 @@ LOG_DEBUG("Begin"); pDetails = all_sam3_details; - while (pDetails->name ){ - if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR ){ + while (pDetails->name){ + if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR){ break; } else { pDetails++; } } - if (pDetails->name == NULL ){ + if (pDetails->name == NULL){ LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)", - (unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR) ); + (unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR)); // Help the victim, print details about the chip - membuf_reset(pPrivate->pChip->mbuf ); + membuf_reset(pPrivate->pChip->mbuf); membuf_sprintf(pPrivate->pChip->mbuf, "SAM3 CHIPID_CIDR: 0x%08x decodes as follows\n", - pPrivate->pChip->cfg.CHIPID_CIDR ); - sam3_explain_chipid_cidr(pPrivate->pChip ); - cp = membuf_strtok(pPrivate->pChip->mbuf, "\n", &vp ); + pPrivate->pChip->cfg.CHIPID_CIDR); + sam3_explain_chipid_cidr(pPrivate->pChip); + cp = membuf_strtok(pPrivate->pChip->mbuf, "\n", &vp); while (cp){ - LOG_INFO("%s", cp ); - cp = membuf_strtok(NULL, "\n", &vp ); + LOG_INFO("%s", cp); + cp = membuf_strtok(NULL, "\n", &vp); } return ERROR_FAIL; } @@ -1730,7 +1730,7 @@ // // save the "bank" pointers - for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){ saved_banks[ x ] = pChip->details.bank[x].pBank; } @@ -1740,7 +1740,7 @@ sizeof(pPrivate->pChip->details)); // now fix the ghosted pointers - for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){ pChip->details.bank[x].pChip = pChip; pChip->details.bank[x].pBank = saved_banks[x]; } @@ -1761,56 +1761,56 @@ struct sam3_bank_private *pPrivate; - LOG_DEBUG("Begin: Bank: %d, Noise: %d", bank->bank_number, noise ); + LOG_DEBUG("Begin: Bank: %d, Noise: %d", bank->bank_number, noise); if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } - pPrivate = get_sam3_bank_private(bank ); - if (!pPrivate ){ + pPrivate = get_sam3_bank_private(bank); + if (!pPrivate){ LOG_ERROR("Invalid/unknown bank number\n"); return ERROR_FAIL; } r = sam3_ReadAllRegs(pPrivate->pChip); - if (r != ERROR_OK ){ + if (r != ERROR_OK){ return r; } LOG_DEBUG("Here"); - r = sam3_GetInfo(pPrivate->pChip ); - if (r != ERROR_OK ){ + r = sam3_GetInfo(pPrivate->pChip); + if (r != ERROR_OK){ return r; } - if (!(pPrivate->pChip->probed) ){ + if (!(pPrivate->pChip->probed)){ pPrivate->pChip->probed = 1; LOG_DEBUG("Here"); - r = sam3_GetDetails(pPrivate ); - if (r != ERROR_OK ){ + r = sam3_GetDetails(pPrivate); + if (r != ERROR_OK){ return r; } } // update the flash bank size - for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ - if (bank->base == pPrivate->pChip->details.bank[0].base_address ){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){ + if (bank->base == pPrivate->pChip->details.bank[0].base_address){ bank->size = pPrivate->pChip->details.bank[0].size_bytes; break; } } - if (bank->sectors == NULL ){ - bank->sectors = calloc(pPrivate->nsectors, (sizeof((bank->sectors)[0] ))); - if (bank->sectors == NULL ){ + if (bank->sectors == NULL){ + bank->sectors = calloc(pPrivate->nsectors, (sizeof((bank->sectors)[0]))); + if (bank->sectors == NULL){ LOG_ERROR("No memory!"); return ERROR_FAIL; } bank->num_sectors = pPrivate->nsectors; - for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++ ){ + for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++){ bank->sectors[x].size = pPrivate->sector_size; bank->sectors[x].offset = x * (pPrivate->sector_size); // mark as unknown @@ -1821,14 +1821,14 @@ pPrivate->probed = 1; - r = sam3_protect_check(bank ); - if (r != ERROR_OK ){ + r = sam3_protect_check(bank); + if (r != ERROR_OK){ return r; } LOG_DEBUG("Bank = %d, nbanks = %d", pPrivate->bank_number , pPrivate->pChip->details.n_banks); - if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks ){ + if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks){ // read unique id, // it appears to be associated with the *last* flash bank. FLASHD_ReadUniqueID(pPrivate); @@ -1840,13 +1840,13 @@ static int sam3_probe(struct flash_bank_s *bank) { - return _sam3_probe(bank, 1 ); + return _sam3_probe(bank, 1); } static int sam3_auto_probe(struct flash_bank_s *bank) { - return _sam3_probe(bank, 0 ); + return _sam3_probe(bank, 0); } @@ -1863,21 +1863,21 @@ return ERROR_TARGET_NOT_HALTED; } - r = sam3_auto_probe(bank ); - if (r != ERROR_OK ){ + r = sam3_auto_probe(bank); + if (r != ERROR_OK){ LOG_DEBUG("Here,r=%d",r); return r; } - pPrivate = get_sam3_bank_private(bank ); - if (!(pPrivate->probed) ){ + pPrivate = get_sam3_bank_private(bank); + if (!(pPrivate->probed)){ return ERROR_FLASH_BANK_NOT_PROBED; } - if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors))) ){ + if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors)))){ // whole chip LOG_DEBUG("Here"); - return FLASHD_EraseEntireBank(pPrivate ); + return FLASHD_EraseEntireBank(pPrivate); } LOG_INFO("sam3 auto-erases while programing (request ignored)"); return ERROR_OK; @@ -1895,12 +1895,12 @@ return ERROR_TARGET_NOT_HALTED; } - pPrivate = get_sam3_bank_private(bank ); - if (!(pPrivate->probed) ){ + pPrivate = get_sam3_bank_private(bank); + if (!(pPrivate->probed)){ return ERROR_FLASH_BANK_NOT_PROBED; } - if (set ){ + if (set){ r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last)); } else { r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last)); @@ -1913,7 +1913,7 @@ static int -sam3_info(flash_bank_t *bank, char *buf, int buf_size ) +sam3_info(flash_bank_t *bank, char *buf, int buf_size) { if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); @@ -1924,7 +1924,7 @@ } static int -sam3_page_read(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf ) +sam3_page_read(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf) { uint32_t adr; int r; @@ -1936,9 +1936,9 @@ adr, 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, - buf ); - if (r != ERROR_OK ){ - LOG_ERROR("SAM3: Flash program failed to read page phys address: 0x%08x", (unsigned int)(adr) ); + buf); + if (r != ERROR_OK){ + LOG_ERROR("SAM3: Flash program failed to read page phys address: 0x%08x", (unsigned int)(adr)); } return r; } @@ -1964,7 +1964,7 @@ // }; // // -// uint32_t sam3_function(struct foo *p ) +// uint32_t sam3_function(struct foo *p) // { // volatile uint32_t *v; // uint32_t *d; @@ -1978,7 +1978,7 @@ // // do { // *d++ = *s++; -// } while (--n ) +// } while (--n) // ; // // v = p->base; @@ -1986,7 +1986,7 @@ // v[ 1 ] = p->cmd; // do { // r = v[8/4]; -// } while (!(r&1) ) +// } while (!(r&1)) // ; // return r; // } @@ -2036,7 +2036,7 @@ static int -sam3_page_write(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf ) +sam3_page_write(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf) { uint32_t adr; uint32_t status; @@ -2045,14 +2045,14 @@ adr = pagenum * pPrivate->page_size; adr += (adr + pPrivate->base_address); - LOG_DEBUG("Wr Page %u @ phys address: 0x%08x", pagenum, (unsigned int)(adr) ); + LOG_DEBUG("Wr Page %u @ phys address: 0x%08x", pagenum, (unsigned int)(adr)); r = target_write_memory(pPrivate->pChip->target, adr, 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, - buf ); - if (r != ERROR_OK ){ - LOG_ERROR("SAM3: Failed to write (buffer) page at phys address 0x%08x", (unsigned int)(adr) ); + buf); + if (r != ERROR_OK){ + LOG_ERROR("SAM3: Failed to write (buffer) page at phys address 0x%08x", (unsigned int)(adr)); return r; } @@ -2060,17 +2060,17 @@ // send Erase & Write Page AT91C_EFC_FCMD_EWP, pagenum, - &status ); + &status); - if (r != ERROR_OK ){ - LOG_ERROR("SAM3: Error performing Erase & Write page @ phys address 0x%08x", (unsigned int)(adr) ); + if (r != ERROR_OK){ + LOG_ERROR("SAM3: Error performing Erase & Write page @ phys address 0x%08x", (unsigned int)(adr)); } - if (status & (1 << 2) ){ - LOG_ERROR("SAM3: Page @ Phys address 0x%08x is locked", (unsigned int)(adr) ); + if (status & (1 << 2)){ + LOG_ERROR("SAM3: Page @ Phys address 0x%08x is locked", (unsigned int)(adr)); return ERROR_FAIL; } - if (status & (1 << 1) ){ - LOG_ERROR("SAM3: Flash Command error @phys address 0x%08x", (unsigned int)(adr) ); + if (status & (1 << 1)){ + LOG_ERROR("SAM3: Flash Command error @phys address 0x%08x", (unsigned int)(adr)); return ERROR_FAIL; } return ERROR_OK; @@ -2095,7 +2095,7 @@ uint8_t *pagebuffer; // ignore dumb requests - if (count == 0 ){ + if (count == 0){ return ERROR_OK; } @@ -2105,28 +2105,28 @@ } pPrivate = get_sam3_bank_private(bank); - if (!(pPrivate->probed) ){ + if (!(pPrivate->probed)){ return ERROR_FLASH_BANK_NOT_PROBED; } - if ((offset + count) > pPrivate->size_bytes ){ + if ((offset + count) > pPrivate->size_bytes){ LOG_ERROR("Flash write error - past end of bank"); LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x", (unsigned int)(offset), (unsigned int)(count), - (unsigned int)(pPrivate->size_bytes) ); + (unsigned int)(pPrivate->size_bytes)); return ERROR_FAIL; } - pagebuffer = alloca(pPrivate->page_size ); + pagebuffer = alloca(pPrivate->page_size); // what page do we start & end in? page_cur = offset / pPrivate->page_size; page_end = (offset + count - 1) / pPrivate->page_size; LOG_DEBUG("Offset: 0x%08x, Count: 0x%08x", (unsigned int)(offset), (unsigned int)(count)); - LOG_DEBUG("Page start: %d, Page End: %d", (int)(page_cur), (int)(page_end) ); + LOG_DEBUG("Page start: %d, Page End: %d", (int)(page_cur), (int)(page_end)); // Special case: all one page // @@ -2136,20 +2136,20 @@ // (3) non-aligned end. // Handle special case - all one page. - if (page_cur == page_end ){ + if (page_cur == page_end){ LOG_DEBUG("Special case, all in one page"); - r = sam3_page_read(pPrivate, page_cur, pagebuffer ); - if (r != ERROR_OK ){ + r = sam3_page_read(pPrivate, page_cur, pagebuffer); + if (r != ERROR_OK){ return r; } page_offset = (offset & (pPrivate->page_size-1)); memcpy(pagebuffer + page_offset, buffer, - count ); + count); - r = sam3_page_write(pPrivate, page_cur, pagebuffer ); - if (r != ERROR_OK ){ + r = sam3_page_write(pPrivate, page_cur, pagebuffer); + if (r != ERROR_OK){ return r; } return ERROR_OK; @@ -2157,22 +2157,22 @@ // non-aligned start page_offset = offset & (pPrivate->page_size - 1); - if (page_offset ){ + if (page_offset){ LOG_DEBUG("Not-Aligned start"); // read the partial - r = sam3_page_read(pPrivate, page_cur, pagebuffer ); - if (r != ERROR_OK ){ + r = sam3_page_read(pPrivate, page_cur, pagebuffer); + if (r != ERROR_OK){ return r; } // over-write with new data - n = (pPrivate->page_size - page_offset ); + n = (pPrivate->page_size - page_offset); memcpy(pagebuffer + page_offset, buffer, - n ); + n); - r = sam3_page_write(pPrivate, page_cur, pagebuffer ); - if (r != ERROR_OK ){ + r = sam3_page_write(pPrivate, page_cur, pagebuffer); + if (r != ERROR_OK){ return r; } @@ -2186,12 +2186,12 @@ // also - the final *terminal* // if that terminal page is a full page LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count = 0x%08x", - (int)page_cur, (int)page_end, (unsigned int)(count) ); + (int)page_cur, (int)page_end, (unsigned int)(count)); while ((page_cur < page_end) && - (count >= pPrivate->page_size) ){ - r = sam3_page_write(pPrivate, page_cur, buffer ); - if (r != ERROR_OK ){ + (count >= pPrivate->page_size)){ + r = sam3_page_write(pPrivate, page_cur, buffer); + if (r != ERROR_OK){ return r; } count -= pPrivate->page_size; @@ -2200,17 +2200,17 @@ } // terminal partial page? - if (count ){ + if (count){ LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count)); // we have a partial page - r = sam3_page_read(pPrivate, page_cur, pagebuffer ); - if (r != ERROR_OK ){ + r = sam3_page_read(pPrivate, page_cur, pagebuffer); + if (r != ERROR_OK){ return r; } // data goes at start - memcpy(pagebuffer, buffer, count ); - r = sam3_page_write(pPrivate, page_cur, pagebuffer ); - if (r != ERROR_OK ){ + memcpy(pagebuffer, buffer, count); + r = sam3_page_write(pPrivate, page_cur, pagebuffer); + if (r != ERROR_OK){ return r; } buffer += count; @@ -2221,7 +2221,7 @@ } static int -sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc ) +sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc) { struct sam3_chip *pChip; void *vp; @@ -2230,27 +2230,27 @@ int r; pChip = get_current_sam3(cmd_ctx); - if (!pChip ){ + if (!pChip){ return ERROR_OK; } r = 0; // bank0 must exist before we can do anything - if (pChip->details.bank[0].pBank == NULL ){ + if (pChip->details.bank[0].pBank == NULL){ x = 0; need_define: command_print(cmd_ctx, "Please define bank %d via command: flash bank %s ... ", x, - at91sam3_flash.name ); + at91sam3_flash.name); return ERROR_FAIL; } // if bank 0 is not probed, then probe it - if (!(pChip->details.bank[0].probed) ){ - r = sam3_auto_probe(pChip->details.bank[0].pBank ); - if (r != ERROR_OK ){ + if (!(pChip->details.bank[0].probed)){ + r = sam3_auto_probe(pChip->details.bank[0].pBank); + if (r != ERROR_OK){ return ERROR_FAIL; } } @@ -2260,39 +2260,39 @@ // auto-probe other banks, 0 done above - for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++){ // skip banks not present - if (!(pChip->details.bank[x].present) ){ + if (!(pChip->details.bank[x].present)){ continue; } - if (pChip->details.bank[x].pBank == NULL ){ + if (pChip->details.bank[x].pBank == NULL){ goto need_define; } - if (pChip->details.bank[x].probed ){ + if (pChip->details.bank[x].probed){ continue; } - r = sam3_auto_probe(pChip->details.bank[x].pBank ); - if (r != ERROR_OK ){ + r = sam3_auto_probe(pChip->details.bank[x].pBank); + if (r != ERROR_OK){ return r; } } - r = sam3_GetInfo(pChip ); - if (r != ERROR_OK ){ + r = sam3_GetInfo(pChip); + if (r != ERROR_OK){ LOG_DEBUG("Sam3Info, Failed %d\n",r); return r; } // print results - cp = membuf_strtok(pChip->mbuf, "\n", &vp ); + cp = membuf_strtok(pChip->mbuf, "\n", &vp); while (cp){ - command_print(cmd_ctx,"%s", cp ); - cp = membuf_strtok(NULL, "\n", &vp ); + command_print(cmd_ctx,"%s", cp); + cp = membuf_strtok(NULL, "\n", &vp); } return ERROR_OK; } @@ -2306,30 +2306,30 @@ struct sam3_chip *pChip; pChip = get_current_sam3(cmd_ctx); - if (!pChip ){ + if (!pChip){ return ERROR_OK; } - if (pChip->target->state != TARGET_HALTED ){ + if (pChip->target->state != TARGET_HALTED){ LOG_ERROR("sam3 - target not halted"); return ERROR_TARGET_NOT_HALTED; } - if (pChip->details.bank[0].pBank == NULL ){ + if (pChip->details.bank[0].pBank == NULL){ command_print(cmd_ctx, "Bank0 must be defined first via: flash bank %s ...", - at91sam3_flash.name ); + at91sam3_flash.name); return ERROR_FAIL; } - if (!pChip->details.bank[0].probed ){ - r = sam3_auto_probe(pChip->details.bank[0].pBank ); - if (r != ERROR_OK ){ + if (!pChip->details.bank[0].probed){ + r = sam3_auto_probe(pChip->details.bank[0].pBank); + if (r != ERROR_OK){ return r; } } - switch (argc ){ + switch (argc){ default: command_print(cmd_ctx,"Too many parameters\n"); return ERROR_COMMAND_SYNTAX_ERROR; @@ -2342,12 +2342,12 @@ who = -1; break; case 2: - if ((0 == strcmp(argv[0], "show" )) && (0 == strcmp(argv[1], "all" )) ){ + if ((0 == strcmp(argv[0], "show")) && (0 == strcmp(argv[1], "all"))){ who = -1; } else { - r = parse_u32(argv[1], &v32 ); - if (r != ERROR_OK ){ - command_print(cmd_ctx, "Not a number: %s", argv[1] ); + r = parse_u32(argv[1], &v32); + if (r != ERROR_OK){ + command_print(cmd_ctx, "Not a number: %s", argv[1]); return r; } who = v32; @@ -2355,40 +2355,40 @@ break; } - if (0 == strcmp("show", argv[0] ) ){ - if (who == -1 ){ + if (0 == strcmp("show", argv[0])){ + if (who == -1){ showall: - for (x = 0 ; x < pChip->details.n_gpnvms ; x++ ){ - r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v ); - if (r != ERROR_OK ){ + for (x = 0 ; x < pChip->details.n_gpnvms ; x++){ + r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); + if (r != ERROR_OK){ break; } - command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v ); + command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v); } return r; } - if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms) ){ - r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v ); - command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v ); + if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)){ + r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); + command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v); return r; } else { - command_print(cmd_ctx, "sam3-gpnvm invalid GPNVM: %u", who ); + command_print(cmd_ctx, "sam3-gpnvm invalid GPNVM: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } - if (who == -1 ){ + if (who == -1){ command_print(cmd_ctx, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } - if (0 == strcmp("set", argv[0] ) ){ - r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who ); - } else if ((0 == strcmp("clr", argv[0] )) || - (0 == strcmp("clear", argv[0])) ){ // quietly accept both - r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who ); + if (0 == strcmp("set", argv[0])){ + r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who); + } else if ((0 == strcmp("clr", argv[0])) || + (0 == strcmp("clear", argv[0]))){ // quietly accept both + r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); } else { - command_print(cmd_ctx, "Unkown command: %s", argv[0] ); + command_print(cmd_ctx, "Unkown command: %s", argv[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; @@ -2403,19 +2403,19 @@ struct sam3_chip *pChip; pChip = get_current_sam3(cmd_ctx); - if (!pChip ){ + if (!pChip){ return ERROR_OK; } - switch (argc ){ + switch (argc){ case 0: // show break; case 1: // set - r = parse_u32(argv[0], &v ); - if (v > 200000 ){ + r = parse_u32(argv[0], &v); + if (v > 200000){ // absurd slow clock of 200Khz? command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; @@ -2443,10 +2443,10 @@ command_t *pCmd; // only register once - if (!sam3_registered ){ + if (!sam3_registered){ sam3_registered++; - pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL ); + pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); register_command(cmd_ctx, pCmd, "gpnvm", sam3_handle_gpnvm_command, Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:38:01 UTC (rev 2395) +++ trunk/src/helper/membuf.c 2009-06-24 09:38:08 UTC (rev 2396) @@ -37,32 +37,32 @@ }; -#define space_avail(pBuf ) (pBuf->maxlen - pBuf->curlen) -#define dataend(pBuf ) (((char *)(pBuf->buf)) + pBuf->curlen ) +#define space_avail(pBuf) (pBuf->maxlen - pBuf->curlen) +#define dataend(pBuf) (((char *)(pBuf->buf)) + pBuf->curlen) size_t -membuf_len(struct membuf *pBuf ) +membuf_len(struct membuf *pBuf) { return pBuf->curlen; } const void * -membuf_datapointer(struct membuf *pBuf ) +membuf_datapointer(struct membuf *pBuf) { return ((void *)(pBuf->buf)); } const char * -membuf_strtok(struct membuf *pBuf, const char *sep, void **pLast ) +membuf_strtok(struct membuf *pBuf, const char *sep, void **pLast) { - if (pBuf ){ + if (pBuf){ pBuf->_strtoklast = NULL; *pLast = pBuf; - return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast) ); + return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast)); } else { // recover our pBuf pBuf = *((struct membuf **)(pLast)); - return strtok_r(NULL, sep, &(pBuf->_strtoklast) ); + return strtok_r(NULL, sep, &(pBuf->_strtoklast)); } } @@ -74,11 +74,11 @@ // by default - parameters are zero. struct membuf *pBuf; - pBuf = calloc(1, sizeof(*pBuf) ); - if (pBuf ){ + pBuf = calloc(1, sizeof(*pBuf)); + if (pBuf){ // we *ALWAYS* allocate +1 for null terminator. pBuf->buf = calloc(DEFAULT_BUFSIZE + 1, sizeof(char)); - if (pBuf->buf == NULL ){ + if (pBuf->buf == NULL){ free(pBuf); pBuf = NULL; } else { @@ -90,7 +90,7 @@ struct membuf * -membuf_grow(struct membuf *pBuf, int n ) +membuf_grow(struct membuf *pBuf, int n) { void *vp; signed int newsize; @@ -99,13 +99,13 @@ newsize = ((int)(pBuf->maxlen)) + n; // do not go negative, or too small - if (newsize < DEFAULT_BUFSIZE ){ + if (newsize < DEFAULT_BUFSIZE){ newsize = DEFAULT_BUFSIZE; } // always alloc +1 for the null terminator - vp = realloc(pBuf->buf, newsize + 1 ); - if (vp ){ + vp = realloc(pBuf->buf, newsize + 1); + if (vp){ pBuf->buf = vp; pBuf->maxlen = newsize; return pBuf; @@ -115,15 +115,15 @@ } -void membuf_reset(struct membuf *pBuf ) +void membuf_reset(struct membuf *pBuf) { pBuf->curlen = 0; } -void membuf_delete(struct membuf *pBuf ) +void membuf_delete(struct membuf *pBuf) { - if (pBuf ){ + if (pBuf){ if (pBuf->buf){ // wack data so it cannot be reused memset(pBuf->buf,0,pBuf->maxlen); @@ -136,18 +136,18 @@ } int -membuf_sprintf(struct membuf *pBuf , const char *fmt, ... ) +membuf_sprintf(struct membuf *pBuf , const char *fmt, ...) { int r; va_list ap; - va_start(ap, fmt ); - r = membuf_vsprintf(pBuf, fmt, ap ); + va_start(ap, fmt); + r = membuf_vsprintf(pBuf, fmt, ap); va_end(ap); return r; } int -membuf_vsprintf(struct membuf *pBuf, const char *fmt, va_list ap ) +membuf_vsprintf(struct membuf *pBuf, const char *fmt, va_list ap) { int r; size_t sa; @@ -159,11 +159,11 @@ sa = space_avail(pBuf); // do work - r = vsnprintf(dataend(pBuf ), + r = vsnprintf(dataend(pBuf), sa, fmt, - ap ); - if ((r > 0) && (((size_t)(r)) < sa) ){ + ap); + if ((r > 0) && (((size_t)(r)) < sa)){ // Success! pBuf->curlen += ((size_t)(r)); // remember: We always alloc'ed +1 @@ -174,7 +174,7 @@ } // failure - if (r < 0 ){ + if (r < 0){ // Option(A) format error // Option(B) glibc2.0 bug // assume (B). @@ -182,12 +182,12 @@ } // don't do this again - if (grew ){ + if (grew){ r = -1; break; } grew = 1; - pBuf = membuf_grow(pBuf, r ); + pBuf = membuf_grow(pBuf, r); if (pBuf == NULL){ // grow failed r = -1; @@ -198,26 +198,26 @@ } struct membuf * -membuf_strcat(struct membuf *pBuf, const char *pStr ) +membuf_strcat(struct membuf *pBuf, const char *pStr) { - return membuf_append(pBuf, pStr, strlen(pStr ) ); + return membuf_append(pBuf, pStr, strlen(pStr)); } struct membuf * -membuf_append(struct membuf *pBuf, const void *pData, size_t len ) +membuf_append(struct membuf *pBuf, const void *pData, size_t len) { size_t sa; int r; // how much room is there? - sa = space_avail(pBuf ); + sa = space_avail(pBuf); // will it fit? - if (sa < len ){ + if (sa < len){ // if not, how much do we need? r = ((int)(sa - len)); // do the grow. - pBuf = membuf_grow(pBuf, r ); + pBuf = membuf_grow(pBuf, r); // failed? if (pBuf == NULL){ return pBuf; @@ -226,7 +226,7 @@ // append memcpy(dataend(pBuf), pData, - len ); + len); pBuf->curlen += len; return pBuf; } Modified: trunk/src/helper/membuf.h =================================================================== --- trunk/src/helper/membuf.h 2009-06-24 09:38:01 UTC (rev 2395) +++ trunk/src/helper/membuf.h 2009-06-24 09:38:08 UTC (rev 2396) @@ -30,7 +30,7 @@ /** delete (destroy) the mem buffer * @param pBuf - buffer to release */ -void membuf_delete(struct membuf *pBuf ); +void membuf_delete(struct membuf *pBuf); /** grow/shrink a membuf by specified amount. @@ -39,14 +39,14 @@ * * Symantics of 'realloc()' return NULL on failure */ -struct membuf *membuf_grow(struct membuf *pBuf, int amount ); +struct membuf *membuf_grow(struct membuf *pBuf, int amount); /** how long is this buffer (memlen(), strlen()) * @param pBuf - the buffer * * @returns: length of current buffer. */ -size_t membuf_len(struct membuf *pBuf ); +size_t membuf_len(struct membuf *pBuf); /** reset an membuf to zero length. @@ -54,7 +54,7 @@ * * Note this does not 'release' the memory buffer */ -void membuf_reset(struct membuf *pBuf ); +void membuf_reset(struct membuf *pBuf); /** sprintf() to the string buffer @@ -64,7 +64,7 @@ * Returns 0 on success * Returns non-zero on failure */ -int membuf_sprintf(struct membuf *pBuf , const char *fmt, ... ); +int membuf_sprintf(struct membuf *pBuf , const char *fmt, ...); /** vsprintf() to the string buffer * @param pBuf - buffer to capture sprintf() data into @@ -84,14 +84,14 @@ * * NOTE: This call is <b > destructive</b> to the buffer. */ -const char *membuf_strtok(struct membuf *pBuf, const char *delim, void **pSave ); +const char *membuf_strtok(struct membuf *pBuf, const char *delim, void **pSave); /** Return pointer to the memory in the buffer * @param pBuf - buffer * * NOTE: Thou shall not modify this pointer, it is <b > CONST</b> */ -const void *membuf_datapointer(struct membuf *pBuf ); +const void *membuf_datapointer(struct membuf *pBuf); /** Append data to the buffer @@ -102,7 +102,7 @@ * Modified symantics of "memcpy()". On memory allocation failure * returns NULL. On success, returns pointer to orginal membuf. */ -struct membuf *membuf_append(struct membuf *pBuf, const void *pData, size_t len ); +struct membuf *membuf_append(struct membuf *pBuf, const void *pData, size_t len); /** Append string to the buffer @@ -112,7 +112,7 @@ * Modified symantics of "strcat()". On memory allocation failure * returns NULL. On success, returns pointer to orginal membuf. */ -struct membuf *membuf_strcat(struct membuf *pBuf, const char *s ); +struct membuf *membuf_strcat(struct membuf *pBuf, const char *s); #endif |
From: <zw...@ma...> - 2009-06-24 11:38:05
|
Author: zwelch Date: 2009-06-24 11:38:01 +0200 (Wed, 24 Jun 2009) New Revision: 2395 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c trunk/src/helper/membuf.h Log: Remove whitespace that occurs after '('. - Replace '([ \t]*' with '('. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:37:56 UTC (rev 2394) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:38:01 UTC (rev 2395) @@ -100,7 +100,7 @@ static float -_tomhz( uint32_t freq_hz ) +_tomhz(uint32_t freq_hz ) { float f; @@ -224,7 +224,7 @@ struct sam3_reg_list { uint32_t address; size_t struct_offset; const char *name; - void (*explain_func)( struct sam3_chip *pInfo ); + void (*explain_func)(struct sam3_chip *pInfo ); }; @@ -236,27 +236,27 @@ target_t *t; static struct sam3_chip *p; - t = get_current_target( cmd_ctx ); - if ( !t ){ - command_print( cmd_ctx, "No current target?"); + t = get_current_target(cmd_ctx ); + if (!t ){ + command_print(cmd_ctx, "No current target?"); return NULL; } p = all_sam3_chips; - if ( !p ){ + if (!p ){ // this should not happen // the command is not registered until the chip is created? - command_print( cmd_ctx, "No SAM3 chips exist?"); + command_print(cmd_ctx, "No SAM3 chips exist?"); return NULL; } - while ( p ){ - if ( p->target == t ){ + while (p ){ + if (p->target == t ){ return p; } p = p->next; } - command_print( cmd_ctx, "Cannot find SAM3 chip?"); + command_print(cmd_ctx, "Cannot find SAM3 chip?"); return NULL; } @@ -540,10 +540,10 @@ * @param v - result goes here */ static int -EFC_GetStatus( struct sam3_bank_private *pPrivate, uint32_t *v ) +EFC_GetStatus(struct sam3_bank_private *pPrivate, uint32_t *v ) { int r; - r = target_read_u32( pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FSR, v ); + r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FSR, v ); LOG_DEBUG("Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)", (unsigned int)(*v), ((unsigned int)((*v >> 2) & 1)), @@ -558,12 +558,12 @@ * @param v - result goes here */ static int -EFC_GetResult( struct sam3_bank_private *pPrivate, uint32_t *v ) +EFC_GetResult(struct sam3_bank_private *pPrivate, uint32_t *v ) { int r; uint32_t rv; - r = target_read_u32( pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv ); - if ( v ){ + r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv ); + if (v ){ *v = rv; } LOG_DEBUG("Result: 0x%08x", ((unsigned int)(rv))); @@ -593,14 +593,14 @@ case AT91C_EFC_FCMD_SLB: case AT91C_EFC_FCMD_CLB: n = (pPrivate->size_bytes / pPrivate->page_size); - if ( argument >= n ){ + if (argument >= n ){ LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n)); } break; case AT91C_EFC_FCMD_SFB: case AT91C_EFC_FCMD_CFB: - if ( argument >= pPrivate->pChip->details.n_gpnvms ){ + if (argument >= pPrivate->pChip->details.n_gpnvms ){ LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs", pPrivate->pChip->details.n_gpnvms ); } @@ -612,7 +612,7 @@ case AT91C_EFC_FCMD_GFB: case AT91C_EFC_FCMD_STUI: case AT91C_EFC_FCMD_SPUI: - if ( argument != 0 ){ + if (argument != 0 ){ LOG_ERROR("Argument is meaningless for cmd: %d", command ); } break; @@ -621,19 +621,19 @@ break; } - if ( command == AT91C_EFC_FCMD_SPUI ){ + if (command == AT91C_EFC_FCMD_SPUI ){ // this is a very special situation. // Situation (1) - error/retry - see below // And we are being called recursively // Situation (2) - normal, finished reading unique id } else { // it should be "ready" - EFC_GetStatus( pPrivate, &v ); - if ( v & 1 ){ + EFC_GetStatus(pPrivate, &v ); + if (v & 1 ){ // then it is ready // we go on } else { - if ( retry ){ + if (retry ){ // we have done this before // the controller is not responding. LOG_ERROR("flash controller(%d) is not ready! Error", pPrivate->bank_number ); @@ -643,9 +643,9 @@ LOG_ERROR("Flash controller(%d) is not ready, attempting reset", pPrivate->bank_number ); // we do that by issuing the *STOP* command - EFC_StartCommand( pPrivate, AT91C_EFC_FCMD_SPUI, 0 ); + EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0 ); // above is recursive, and further recursion is blocked by - // if ( command == AT91C_EFC_FCMD_SPUI ) above + // if (command == AT91C_EFC_FCMD_SPUI ) above goto do_retry; } } @@ -653,10 +653,10 @@ v = (0x5A << 24) | (argument << 8) | command; LOG_DEBUG("Command: 0x%08x", ((unsigned int)(v)) ); - r = target_write_u32( pPrivate->pBank->target, + r = target_write_u32(pPrivate->pBank->target, pPrivate->controller_address + offset_EFC_FCR, v); - if ( r != ERROR_OK ){ + if (r != ERROR_OK ){ LOG_DEBUG("Error Write failed"); } return r; @@ -670,7 +670,7 @@ * @param status - put command status bits here */ static int -EFC_PerformCommand( struct sam3_bank_private *pPrivate, +EFC_PerformCommand(struct sam3_bank_private *pPrivate, unsigned command, unsigned argument, uint32_t *status) @@ -681,12 +681,12 @@ long long ms_now, ms_end; // default - if ( status ){ + if (status ){ *status = 0; } - r = EFC_StartCommand( pPrivate, command, argument ); - if ( r != ERROR_OK ){ + r = EFC_StartCommand(pPrivate, command, argument ); + if (r != ERROR_OK ){ return r; } @@ -694,22 +694,22 @@ do { - r = EFC_GetStatus( pPrivate, &v ); - if ( r != ERROR_OK ){ + r = EFC_GetStatus(pPrivate, &v ); + if (r != ERROR_OK ){ return r; } ms_now = timeval_ms(); - if ( ms_now > ms_end ){ + if (ms_now > ms_end ){ // error LOG_ERROR("Command timeout"); return ERROR_FAIL; } } - while ( (v & 1) == 0 ) + while ((v & 1) == 0 ) ; // error bits.. - if ( status ){ + if (status ){ *status = (v & 0x6); } return ERROR_OK; @@ -728,7 +728,7 @@ */ static int -FLASHD_ReadUniqueID ( struct sam3_bank_private *pPrivate ) +FLASHD_ReadUniqueID (struct sam3_bank_private *pPrivate ) { int r; uint32_t v; @@ -740,22 +740,22 @@ pPrivate->pChip->cfg.unique_id[3] = 0; LOG_DEBUG("Begin"); - r = EFC_StartCommand( pPrivate, AT91C_EFC_FCMD_STUI, 0); - if ( r < 0 ){ + r = EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_STUI, 0); + if (r < 0 ){ return r; } - for ( x = 0 ; x < 4 ; x++ ){ - r = target_read_u32( pPrivate->pChip->target, + for (x = 0 ; x < 4 ; x++ ){ + r = target_read_u32(pPrivate->pChip->target, pPrivate->pBank->base + (x * 4), &v ); - if ( r < 0 ){ + if (r < 0 ){ return r; } pPrivate->pChip->cfg.unique_id[x] = v; } - r = EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_SPUI, 0, NULL ); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SPUI, 0, NULL ); LOG_DEBUG("End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x", r, (unsigned int)(pPrivate->pChip->cfg.unique_id[0]), @@ -770,10 +770,10 @@ * @param pPrivate - the info about the bank. */ static int -FLASHD_EraseEntireBank( struct sam3_bank_private *pPrivate ) +FLASHD_EraseEntireBank(struct sam3_bank_private *pPrivate ) { LOG_DEBUG("Here"); - return EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_EA, 0, NULL ); + return EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_EA, 0, NULL ); } @@ -786,33 +786,33 @@ */ //------------------------------------------------------------------------------ static int -FLASHD_GetGPNVM( struct sam3_bank_private *pPrivate, unsigned gpnvm, unsigned *puthere) +FLASHD_GetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm, unsigned *puthere) { uint32_t v; int r; LOG_DEBUG("Here"); - if ( pPrivate->bank_number != 0 ){ + if (pPrivate->bank_number != 0 ){ LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if ( gpnvm >= pPrivate->pChip->details.n_gpnvms ){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms ){ LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", gpnvm,pPrivate->pChip->details.n_gpnvms ); return ERROR_FAIL; } // Get GPNVMs status - r = EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL ); - if ( r != ERROR_OK ){ + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL ); + if (r != ERROR_OK ){ LOG_ERROR("Failed"); return r; } r = EFC_GetResult(pPrivate, &v ); - if ( puthere ){ + if (puthere ){ // Check if GPNVM is set // get the bit and make it a 0/1 *puthere = (v >> gpnvm) & 1; @@ -830,29 +830,29 @@ * Returns 0 if successful; otherwise returns an error code. */ static int -FLASHD_ClrGPNVM( struct sam3_bank_private *pPrivate, unsigned gpnvm) +FLASHD_ClrGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm) { int r; unsigned v; LOG_DEBUG("Here"); - if ( pPrivate->bank_number != 0 ){ + if (pPrivate->bank_number != 0 ){ LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if ( gpnvm >= pPrivate->pChip->details.n_gpnvms ){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms ){ LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", gpnvm,pPrivate->pChip->details.n_gpnvms ); return ERROR_FAIL; } - r = FLASHD_GetGPNVM( pPrivate, gpnvm, &v ); - if ( r != ERROR_OK ){ + r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v ); + if (r != ERROR_OK ){ LOG_DEBUG("Failed: %d",r); return r; } - r = EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_CFB, gpnvm, NULL); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_CFB, gpnvm, NULL); LOG_DEBUG("End: %d",r); return r; } @@ -864,32 +864,32 @@ * */ static int -FLASHD_SetGPNVM( struct sam3_bank_private *pPrivate, unsigned gpnvm) +FLASHD_SetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm) { int r; unsigned v; - if ( pPrivate->bank_number != 0 ){ + if (pPrivate->bank_number != 0 ){ LOG_ERROR("GPNVM only works with Bank0"); return ERROR_FAIL; } - if ( gpnvm >= pPrivate->pChip->details.n_gpnvms ){ + if (gpnvm >= pPrivate->pChip->details.n_gpnvms ){ LOG_ERROR("Invalid GPNVM %d, max: %d, ignored", gpnvm,pPrivate->pChip->details.n_gpnvms ); return ERROR_FAIL; } - r = FLASHD_GetGPNVM( pPrivate, gpnvm, &v ); - if ( r != ERROR_OK ){ + r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v ); + if (r != ERROR_OK ){ return r; } - if ( v ){ + if (v ){ // already set r = ERROR_OK; } else { // set it - r = EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_SFB, gpnvm, NULL ); + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SFB, gpnvm, NULL ); } return r; } @@ -906,8 +906,8 @@ { int r; LOG_DEBUG("Here"); - r = EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL); - if ( r == ERROR_OK ){ + r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL); + if (r == ERROR_OK ){ r = EFC_GetResult(pPrivate, v ); } LOG_DEBUG("End: %d",r); @@ -922,7 +922,7 @@ */ static int -FLASHD_Unlock( struct sam3_bank_private *pPrivate, +FLASHD_Unlock(struct sam3_bank_private *pPrivate, unsigned start_sector, unsigned end_sector ) { @@ -956,7 +956,7 @@ static int -FLASHD_Lock( struct sam3_bank_private *pPrivate, +FLASHD_Lock(struct sam3_bank_private *pPrivate, unsigned start_sector, unsigned end_sector ) { @@ -986,21 +986,21 @@ /* begin helpful debug code */ static void -sam3_sprintf( struct sam3_chip *pChip , const char *fmt, ... ) +sam3_sprintf(struct sam3_chip *pChip , const char *fmt, ... ) { va_list ap; va_start(ap,fmt); - if ( pChip->mbuf == NULL ){ + if (pChip->mbuf == NULL ){ return; } - membuf_vsprintf( pChip->mbuf, fmt, ap ); + membuf_vsprintf(pChip->mbuf, fmt, ap ); va_end(ap); } // print the fieldname, the field value, in dec & hex, and return field value static uint32_t -sam3_reg_fieldname( struct sam3_chip *pChip, +sam3_reg_fieldname(struct sam3_chip *pChip, const char *regname, uint32_t value, unsigned shift, @@ -1013,7 +1013,7 @@ // extract the field v = value >> shift; v = v & ((1 << width)-1); - if ( width <= 16 ){ + if (width <= 16 ){ hwidth = 4; dwidth = 5; } else { @@ -1022,7 +1022,7 @@ } // show the basics - sam3_sprintf( pChip, "\t%*s: %*d [0x%0*x] ", + sam3_sprintf(pChip, "\t%*s: %*d [0x%0*x] ", REG_NAME_WIDTH, regname, dwidth, v, hwidth, v ); @@ -1137,9 +1137,9 @@ }; -static const char *_yes_or_no( uint32_t v ) +static const char *_yes_or_no(uint32_t v ) { - if ( v ){ + if (v ){ return "YES"; } else { return "NO"; @@ -1151,27 +1151,27 @@ }; static void -sam3_explain_ckgr_mor( struct sam3_chip *pChip ) +sam3_explain_ckgr_mor(struct sam3_chip *pChip ) { uint32_t v; uint32_t rcen; v = sam3_reg_fieldname(pChip, "MOSCXTEN", pChip->cfg.CKGR_MOR, 0, 1 ); - sam3_sprintf( pChip, "(main xtal enabled: %s)\n", + sam3_sprintf(pChip, "(main xtal enabled: %s)\n", _yes_or_no(v) ); v = sam3_reg_fieldname(pChip, "MOSCXTBY", pChip->cfg.CKGR_MOR, 1, 1 ); - sam3_sprintf( pChip, "(main osc bypass: %s)\n", + sam3_sprintf(pChip, "(main osc bypass: %s)\n", _yes_or_no(v) ); rcen = sam3_reg_fieldname(pChip, "MOSCRCEN", pChip->cfg.CKGR_MOR, 2, 1 ); - sam3_sprintf( pChip, "(onchip RC-OSC enabled: %s)\n", + sam3_sprintf(pChip, "(onchip RC-OSC enabled: %s)\n", _yes_or_no(rcen) ); v = sam3_reg_fieldname(pChip, "MOSCRCF", pChip->cfg.CKGR_MOR, 4, 3 ); - sam3_sprintf( pChip, "(onchip RC-OSC freq: %s)\n", + sam3_sprintf(pChip, "(onchip RC-OSC freq: %s)\n", _rc_freq[v] ); pChip->cfg.rc_freq = 0; - if ( rcen ){ - switch ( v ){ + if (rcen ){ + switch (v ){ default: pChip->cfg.rc_freq = 0; case 0: @@ -1187,10 +1187,10 @@ } v = sam3_reg_fieldname(pChip,"MOSCXTST", pChip->cfg.CKGR_MOR, 8, 8 ); - sam3_sprintf( pChip, "(startup clks, time= %f uSecs)\n", + sam3_sprintf(pChip, "(startup clks, time= %f uSecs)\n", ((float)(v * 1000000)) / ((float)(pChip->cfg.slow_freq))); v = sam3_reg_fieldname(pChip, "MOSCSEL", pChip->cfg.CKGR_MOR, 24, 1 ); - sam3_sprintf( pChip, "(mainosc source: %s)\n", + sam3_sprintf(pChip, "(mainosc source: %s)\n", v ? "external xtal" : "internal RC"); v = sam3_reg_fieldname(pChip,"CFDEN", pChip->cfg.CKGR_MOR, 25, 1 ); @@ -1201,97 +1201,97 @@ static void -sam3_explain_chipid_cidr( struct sam3_chip *pChip ) +sam3_explain_chipid_cidr(struct sam3_chip *pChip ) { int x; uint32_t v; const char *cp; - sam3_reg_fieldname( pChip, "Version", pChip->cfg.CHIPID_CIDR, 0, 5 ); + sam3_reg_fieldname(pChip, "Version", pChip->cfg.CHIPID_CIDR, 0, 5 ); sam3_sprintf(pChip,"\n"); - v = sam3_reg_fieldname( pChip, "EPROC", pChip->cfg.CHIPID_CIDR, 5, 3 ); - sam3_sprintf( pChip, "%s\n", eproc_names[v]); + v = sam3_reg_fieldname(pChip, "EPROC", pChip->cfg.CHIPID_CIDR, 5, 3 ); + sam3_sprintf(pChip, "%s\n", eproc_names[v]); - v = sam3_reg_fieldname( pChip, "NVPSIZE", pChip->cfg.CHIPID_CIDR, 8, 4 ); - sam3_sprintf( pChip, "%s\n", nvpsize[v]); + v = sam3_reg_fieldname(pChip, "NVPSIZE", pChip->cfg.CHIPID_CIDR, 8, 4 ); + sam3_sprintf(pChip, "%s\n", nvpsize[v]); - v = sam3_reg_fieldname( pChip, "NVPSIZE2", pChip->cfg.CHIPID_CIDR, 12, 4 ); - sam3_sprintf( pChip, "%s\n", nvpsize2[v]); + v = sam3_reg_fieldname(pChip, "NVPSIZE2", pChip->cfg.CHIPID_CIDR, 12, 4 ); + sam3_sprintf(pChip, "%s\n", nvpsize2[v]); - v = sam3_reg_fieldname( pChip, "SRAMSIZE", pChip->cfg.CHIPID_CIDR, 16,4 ); - sam3_sprintf( pChip, "%s\n", sramsize[ v ] ); + v = sam3_reg_fieldname(pChip, "SRAMSIZE", pChip->cfg.CHIPID_CIDR, 16,4 ); + sam3_sprintf(pChip, "%s\n", sramsize[ v ] ); - v = sam3_reg_fieldname( pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8 ); + v = sam3_reg_fieldname(pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8 ); cp = _unknown; - for ( x = 0 ; archnames[x].name ; x++ ){ - if ( v == archnames[x].value ){ + for (x = 0 ; archnames[x].name ; x++ ){ + if (v == archnames[x].value ){ cp = archnames[x].name; break; } } - sam3_sprintf( pChip, "%s\n", cp ); + sam3_sprintf(pChip, "%s\n", cp ); - v = sam3_reg_fieldname( pChip, "NVPTYP", pChip->cfg.CHIPID_CIDR, 28, 3 ); - sam3_sprintf( pChip, "%s\n", nvptype[ v ] ); + v = sam3_reg_fieldname(pChip, "NVPTYP", pChip->cfg.CHIPID_CIDR, 28, 3 ); + sam3_sprintf(pChip, "%s\n", nvptype[ v ] ); - v = sam3_reg_fieldname( pChip, "EXTID", pChip->cfg.CHIPID_CIDR, 31, 1 ); + v = sam3_reg_fieldname(pChip, "EXTID", pChip->cfg.CHIPID_CIDR, 31, 1 ); sam3_sprintf(pChip, "(exists: %s)\n", _yes_or_no(v)); } static void -sam3_explain_ckgr_mcfr( struct sam3_chip *pChip ) +sam3_explain_ckgr_mcfr(struct sam3_chip *pChip ) { uint32_t v; - v = sam3_reg_fieldname( pChip, "MAINFRDY", pChip->cfg.CKGR_MCFR, 16, 1 ); - sam3_sprintf( pChip, "(main ready: %s)\n", _yes_or_no( v )); + v = sam3_reg_fieldname(pChip, "MAINFRDY", pChip->cfg.CKGR_MCFR, 16, 1 ); + sam3_sprintf(pChip, "(main ready: %s)\n", _yes_or_no(v )); - v = sam3_reg_fieldname( pChip, "MAINF", pChip->cfg.CKGR_MCFR, 0, 16 ); + v = sam3_reg_fieldname(pChip, "MAINF", pChip->cfg.CKGR_MCFR, 0, 16 ); v = (v * pChip->cfg.slow_freq) / 16; pChip->cfg.mainosc_freq = v; sam3_sprintf(pChip, "(%3.03f Mhz (%d.%03dkhz slowclk)\n", - _tomhz( v ), + _tomhz(v ), pChip->cfg.slow_freq / 1000, pChip->cfg.slow_freq % 1000); } static void -sam3_explain_ckgr_plla( struct sam3_chip *pChip ) +sam3_explain_ckgr_plla(struct sam3_chip *pChip ) { uint32_t mula,diva; - diva = sam3_reg_fieldname( pChip, "DIVA", pChip->cfg.CKGR_PLLAR, 0, 8 ); + diva = sam3_reg_fieldname(pChip, "DIVA", pChip->cfg.CKGR_PLLAR, 0, 8 ); sam3_sprintf(pChip,"\n"); - mula = sam3_reg_fieldname( pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11 ); + mula = sam3_reg_fieldname(pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11 ); sam3_sprintf(pChip,"\n"); pChip->cfg.plla_freq = 0; - if ( mula == 0 ){ + if (mula == 0 ){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula = 0)\n"); - } else if ( diva == 0 ){ + } else if (diva == 0 ){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n"); - } else if ( diva == 1 ){ + } else if (diva == 1 ){ pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula + 1)); sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n", - _tomhz( pChip->cfg.plla_freq )); + _tomhz(pChip->cfg.plla_freq )); } } static void -sam3_explain_mckr( struct sam3_chip *pChip ) +sam3_explain_mckr(struct sam3_chip *pChip ) { uint32_t css, pres,fin; int pdiv; const char *cp; - css = sam3_reg_fieldname( pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2 ); - switch ( css & 3 ){ + css = sam3_reg_fieldname(pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2 ); + switch (css & 3 ){ case 0: fin = pChip->cfg.slow_freq; cp = "slowclk"; @@ -1305,7 +1305,7 @@ cp = "plla"; break; case 3: - if ( pChip->cfg.CKGR_UCKR & (1 << 16) ){ + if (pChip->cfg.CKGR_UCKR & (1 << 16) ){ fin = 480 * 1000 * 1000; cp = "upll"; } else { @@ -1315,11 +1315,11 @@ break; } - sam3_sprintf( pChip, "%s (%3.03f Mhz)\n", + sam3_sprintf(pChip, "%s (%3.03f Mhz)\n", cp, - _tomhz( fin ) ); + _tomhz(fin ) ); pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3 ); - switch ( pres & 0x07 ){ + switch (pres & 0x07 ){ case 0: pdiv = 1; cp = "selected clock"; @@ -1352,20 +1352,20 @@ cp = "clock/6"; break; } - sam3_sprintf( pChip, "(%s)\n", cp ); + sam3_sprintf(pChip, "(%s)\n", cp ); fin = fin / pdiv; // sam3 has a *SINGLE* clock - // other at91 series parts have divisors for these. pChip->cfg.cpu_freq = fin; pChip->cfg.mclk_freq = fin; pChip->cfg.fclk_freq = fin; - sam3_sprintf( pChip, "\t\tResult CPU Freq: %3.03f\n", - _tomhz( fin ) ); + sam3_sprintf(pChip, "\t\tResult CPU Freq: %3.03f\n", + _tomhz(fin ) ); } #if 0 static struct sam3_chip * -target2sam3( target_t *pTarget ) +target2sam3(target_t *pTarget ) { struct sam3_chip *pChip; @@ -1386,7 +1386,7 @@ #endif static uint32_t * -sam3_get_reg_ptr( struct sam3_cfg *pCfg, const struct sam3_reg_list *pList ) +sam3_get_reg_ptr(struct sam3_cfg *pCfg, const struct sam3_reg_list *pList ) { // this function exists to help // keep funky offsetof() errors @@ -1395,29 +1395,29 @@ // By using prototypes - we can detect what would // be casting errors. - return ((uint32_t *)( ((char *)(pCfg)) + pList->struct_offset )); + return ((uint32_t *)(((char *)(pCfg)) + pList->struct_offset )); } -#define SAM3_ENTRY( NAME, FUNC ) { .address = SAM3_ ## NAME, .struct_offset = offsetof( struct sam3_cfg, NAME ), #NAME, FUNC } +#define SAM3_ENTRY(NAME, FUNC ) { .address = SAM3_ ## NAME, .struct_offset = offsetof(struct sam3_cfg, NAME ), #NAME, FUNC } static const struct sam3_reg_list sam3_all_regs[] = { - SAM3_ENTRY( CKGR_MOR , sam3_explain_ckgr_mor ), - SAM3_ENTRY( CKGR_MCFR , sam3_explain_ckgr_mcfr ), - SAM3_ENTRY( CKGR_PLLAR , sam3_explain_ckgr_plla ), - SAM3_ENTRY( CKGR_UCKR , NULL ), - SAM3_ENTRY( PMC_FSMR , NULL ), - SAM3_ENTRY( PMC_FSPR , NULL ), - SAM3_ENTRY( PMC_IMR , NULL ), - SAM3_ENTRY( PMC_MCKR , sam3_explain_mckr ), - SAM3_ENTRY( PMC_PCK0 , NULL ), - SAM3_ENTRY( PMC_PCK1 , NULL ), - SAM3_ENTRY( PMC_PCK2 , NULL ), - SAM3_ENTRY( PMC_PCSR , NULL ), - SAM3_ENTRY( PMC_SCSR , NULL ), - SAM3_ENTRY( PMC_SR , NULL ), - SAM3_ENTRY( CHIPID_CIDR , sam3_explain_chipid_cidr ), - SAM3_ENTRY( CHIPID_EXID , NULL ), - SAM3_ENTRY( SUPC_CR, NULL ), + SAM3_ENTRY(CKGR_MOR , sam3_explain_ckgr_mor ), + SAM3_ENTRY(CKGR_MCFR , sam3_explain_ckgr_mcfr ), + SAM3_ENTRY(CKGR_PLLAR , sam3_explain_ckgr_plla ), + SAM3_ENTRY(CKGR_UCKR , NULL ), + SAM3_ENTRY(PMC_FSMR , NULL ), + SAM3_ENTRY(PMC_FSPR , NULL ), + SAM3_ENTRY(PMC_IMR , NULL ), + SAM3_ENTRY(PMC_MCKR , sam3_explain_mckr ), + SAM3_ENTRY(PMC_PCK0 , NULL ), + SAM3_ENTRY(PMC_PCK1 , NULL ), + SAM3_ENTRY(PMC_PCK2 , NULL ), + SAM3_ENTRY(PMC_PCSR , NULL ), + SAM3_ENTRY(PMC_SCSR , NULL ), + SAM3_ENTRY(PMC_SR , NULL ), + SAM3_ENTRY(CHIPID_CIDR , sam3_explain_chipid_cidr ), + SAM3_ENTRY(CHIPID_EXID , NULL ), + SAM3_ENTRY(SUPC_CR, NULL ), // TERMINATE THE LIST { .name = NULL } @@ -1428,7 +1428,7 @@ static struct sam3_bank_private * -get_sam3_bank_private( flash_bank_t *bank ) +get_sam3_bank_private(flash_bank_t *bank ) { return (struct sam3_bank_private *)(bank->driver_priv); } @@ -1438,7 +1438,7 @@ * Determine the register name, address from the all registers table. */ static const struct sam3_reg_list * -sam3_GetReg( struct sam3_chip *pChip, uint32_t *goes_here ) +sam3_GetReg(struct sam3_chip *pChip, uint32_t *goes_here ) { const struct sam3_reg_list *pReg; @@ -1449,10 +1449,10 @@ // calculate where this one go.. // it is "possibly" this register. - pPossible = ((uint32_t *)( ((char *)(&(pChip->cfg))) + pReg->struct_offset )); + pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset )); // well? Is it this register - if ( pPossible == goes_here ){ + if (pPossible == goes_here ){ // Jump for joy! return pReg; } @@ -1467,18 +1467,18 @@ static int -sam3_ReadThisReg( struct sam3_chip *pChip, uint32_t *goes_here ) +sam3_ReadThisReg(struct sam3_chip *pChip, uint32_t *goes_here ) { const struct sam3_reg_list *pReg; int r; - pReg = sam3_GetReg( pChip, goes_here ); - if ( !pReg ){ + pReg = sam3_GetReg(pChip, goes_here ); + if (!pReg ){ return ERROR_FAIL; } - r = target_read_u32( pChip->target, pReg->address, goes_here ); - if ( r != ERROR_OK ){ + r = target_read_u32(pChip->target, pReg->address, goes_here ); + if (r != ERROR_OK ){ LOG_ERROR("Cannot read SAM3 register: %s @ 0x%08x, Err: %d\n", pReg->name, (unsigned)(pReg->address), r ); } @@ -1488,16 +1488,16 @@ static int -sam3_ReadAllRegs( struct sam3_chip *pChip ) +sam3_ReadAllRegs(struct sam3_chip *pChip ) { int r; const struct sam3_reg_list *pReg; pReg = &(sam3_all_regs[0]); - while ( pReg->name ){ - r = sam3_ReadThisReg( pChip, - sam3_get_reg_ptr( &(pChip->cfg), pReg ) ); - if ( r != ERROR_OK ){ + while (pReg->name ){ + r = sam3_ReadThisReg(pChip, + sam3_get_reg_ptr(&(pChip->cfg), pReg ) ); + if (r != ERROR_OK ){ LOG_ERROR("Cannot read SAM3 registere: %s @ 0x%08x, Error: %d\n", pReg->name, ((unsigned)(pReg->address)), r ); return r; @@ -1511,38 +1511,38 @@ static int -sam3_GetInfo( struct sam3_chip *pChip ) +sam3_GetInfo(struct sam3_chip *pChip ) { const struct sam3_reg_list *pReg; uint32_t regval; - membuf_reset( pChip->mbuf ); + membuf_reset(pChip->mbuf ); pReg = &(sam3_all_regs[0]); while (pReg->name){ // display all regs LOG_DEBUG("Start: %s", pReg->name ); - regval = *sam3_get_reg_ptr( &(pChip->cfg), pReg ); + regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg ); sam3_sprintf(pChip, "%*s: [0x%08x] -> 0x%08x\n", REG_NAME_WIDTH, pReg->name, pReg->address, regval ); - if ( pReg->explain_func ){ - (*(pReg->explain_func))( pChip ); + if (pReg->explain_func ){ + (*(pReg->explain_func))(pChip ); } LOG_DEBUG("End: %s", pReg->name ); pReg++; } - sam3_sprintf(pChip," rc-osc: %3.03f MHz\n", _tomhz( pChip->cfg.rc_freq )); - sam3_sprintf(pChip," mainosc: %3.03f MHz\n", _tomhz( pChip->cfg.mainosc_freq )); - sam3_sprintf(pChip," plla: %3.03f MHz\n", _tomhz( pChip->cfg.plla_freq )); - sam3_sprintf(pChip," cpu-freq: %3.03f MHz\n", _tomhz( pChip->cfg.cpu_freq )); - sam3_sprintf(pChip,"mclk-freq: %3.03f MHz\n", _tomhz( pChip->cfg.mclk_freq )); + sam3_sprintf(pChip," rc-osc: %3.03f MHz\n", _tomhz(pChip->cfg.rc_freq )); + sam3_sprintf(pChip," mainosc: %3.03f MHz\n", _tomhz(pChip->cfg.mainosc_freq )); + sam3_sprintf(pChip," plla: %3.03f MHz\n", _tomhz(pChip->cfg.plla_freq )); + sam3_sprintf(pChip," cpu-freq: %3.03f MHz\n", _tomhz(pChip->cfg.cpu_freq )); + sam3_sprintf(pChip,"mclk-freq: %3.03f MHz\n", _tomhz(pChip->cfg.mclk_freq )); - sam3_sprintf( pChip, " UniqueId: 0x%08x 0x%08x 0x%08x 0x%08x\n", + sam3_sprintf(pChip, " UniqueId: 0x%08x 0x%08x 0x%08x 0x%08x\n", pChip->cfg.unique_id[0], pChip->cfg.unique_id[1], pChip->cfg.unique_id[2], @@ -1563,13 +1563,13 @@ LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } - if ( 0 == bank->num_sectors ){ + if (0 == bank->num_sectors ){ LOG_ERROR("Target: not supported/not probed\n"); return ERROR_FAIL; } LOG_INFO("sam3 - supports auto-erase, erase_check ignored"); - for ( x = 0 ; x < bank->num_sectors ; x++ ){ + for (x = 0 ; x < bank->num_sectors ; x++ ){ bank->sectors[x].is_erased = 1; } @@ -1592,21 +1592,21 @@ } pPrivate = get_sam3_bank_private(bank); - if ( !pPrivate ){ + if (!pPrivate ){ LOG_ERROR("no private for this bank?"); return ERROR_FAIL; } - if ( !(pPrivate->probed) ){ + if (!(pPrivate->probed) ){ return ERROR_FLASH_BANK_NOT_PROBED; } - r = FLASHD_GetLockBits( pPrivate , &v ); - if ( r != ERROR_OK ){ + r = FLASHD_GetLockBits(pPrivate , &v ); + if (r != ERROR_OK ){ LOG_DEBUG("Failed: %d",r); return r; } - for ( x = 0 ; x < pPrivate->nsectors ; x++ ){ + for (x = 0 ; x < pPrivate->nsectors ; x++ ){ bank->sectors[x].is_protected = (!!(v & (1 << x))); } LOG_DEBUG("Done"); @@ -1626,16 +1626,16 @@ // is this an existing chip? while (pChip){ - if ( pChip->target == bank->target ){ + if (pChip->target == bank->target ){ break; } pChip = pChip->next; } - if ( !pChip ){ + if (!pChip ){ // this is a *NEW* chip - pChip = calloc( 1, sizeof(struct sam3_chip) ); - if ( !pChip ){ + pChip = calloc(1, sizeof(struct sam3_chip) ); + if (!pChip ){ LOG_ERROR("NO RAM!"); return ERROR_FAIL; } @@ -1648,13 +1648,13 @@ pChip->cfg.slow_freq = 32768; pChip->probed = 0; pChip->mbuf = membuf_new(); - if ( !(pChip->mbuf) ){ + if (!(pChip->mbuf) ){ LOG_ERROR("no memory"); return ERROR_FAIL; } } - switch ( bank->base ){ + switch (bank->base ){ default: LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x or 0x%08x)", ((unsigned int)(bank->base)), @@ -1681,7 +1681,7 @@ } static int -sam3_GetDetails( struct sam3_bank_private *pPrivate ) +sam3_GetDetails(struct sam3_bank_private *pPrivate ) { const struct sam3_chip_details *pDetails; struct sam3_chip *pChip; @@ -1693,26 +1693,26 @@ LOG_DEBUG("Begin"); pDetails = all_sam3_details; - while ( pDetails->name ){ - if ( pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR ){ + while (pDetails->name ){ + if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR ){ break; } else { pDetails++; } } - if ( pDetails->name == NULL ){ + if (pDetails->name == NULL ){ LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)", (unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR) ); // Help the victim, print details about the chip - membuf_reset( pPrivate->pChip->mbuf ); - membuf_sprintf( pPrivate->pChip->mbuf, + membuf_reset(pPrivate->pChip->mbuf ); + membuf_sprintf(pPrivate->pChip->mbuf, "SAM3 CHIPID_CIDR: 0x%08x decodes as follows\n", pPrivate->pChip->cfg.CHIPID_CIDR ); - sam3_explain_chipid_cidr( pPrivate->pChip ); - cp = membuf_strtok( pPrivate->pChip->mbuf, "\n", &vp ); + sam3_explain_chipid_cidr(pPrivate->pChip ); + cp = membuf_strtok(pPrivate->pChip->mbuf, "\n", &vp ); while (cp){ LOG_INFO("%s", cp ); - cp = membuf_strtok( NULL, "\n", &vp ); + cp = membuf_strtok(NULL, "\n", &vp ); } return ERROR_FAIL; } @@ -1730,17 +1730,17 @@ // // save the "bank" pointers - for ( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ saved_banks[ x ] = pChip->details.bank[x].pBank; } // Overwrite the "details" structure. - memcpy( &(pPrivate->pChip->details), + memcpy(&(pPrivate->pChip->details), pDetails, sizeof(pPrivate->pChip->details)); // now fix the ghosted pointers - for ( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ pChip->details.bank[x].pChip = pChip; pChip->details.bank[x].pBank = saved_banks[x]; } @@ -1768,49 +1768,49 @@ return ERROR_TARGET_NOT_HALTED; } - pPrivate = get_sam3_bank_private( bank ); - if ( !pPrivate ){ + pPrivate = get_sam3_bank_private(bank ); + if (!pPrivate ){ LOG_ERROR("Invalid/unknown bank number\n"); return ERROR_FAIL; } r = sam3_ReadAllRegs(pPrivate->pChip); - if ( r != ERROR_OK ){ + if (r != ERROR_OK ){ return r; } LOG_DEBUG("Here"); - r = sam3_GetInfo( pPrivate->pChip ); - if ( r != ERROR_OK ){ + r = sam3_GetInfo(pPrivate->pChip ); + if (r != ERROR_OK ){ return r; } - if ( !(pPrivate->pChip->probed) ){ + if (!(pPrivate->pChip->probed) ){ pPrivate->pChip->probed = 1; LOG_DEBUG("Here"); - r = sam3_GetDetails( pPrivate ); - if ( r != ERROR_OK ){ + r = sam3_GetDetails(pPrivate ); + if (r != ERROR_OK ){ return r; } } // update the flash bank size - for ( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ - if ( bank->base == pPrivate->pChip->details.bank[0].base_address ){ + for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + if (bank->base == pPrivate->pChip->details.bank[0].base_address ){ bank->size = pPrivate->pChip->details.bank[0].size_bytes; break; } } - if ( bank->sectors == NULL ){ - bank->sectors = calloc(pPrivate->nsectors, (sizeof( (bank->sectors)[0] ))); - if ( bank->sectors == NULL ){ + if (bank->sectors == NULL ){ + bank->sectors = calloc(pPrivate->nsectors, (sizeof((bank->sectors)[0] ))); + if (bank->sectors == NULL ){ LOG_ERROR("No memory!"); return ERROR_FAIL; } bank->num_sectors = pPrivate->nsectors; - for ( x = 0 ; ((int)(x)) < bank->num_sectors ; x++ ){ + for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++ ){ bank->sectors[x].size = pPrivate->sector_size; bank->sectors[x].offset = x * (pPrivate->sector_size); // mark as unknown @@ -1821,14 +1821,14 @@ pPrivate->probed = 1; - r = sam3_protect_check( bank ); - if ( r != ERROR_OK ){ + r = sam3_protect_check(bank ); + if (r != ERROR_OK ){ return r; } LOG_DEBUG("Bank = %d, nbanks = %d", pPrivate->bank_number , pPrivate->pChip->details.n_banks); - if ( (pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks ){ + if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks ){ // read unique id, // it appears to be associated with the *last* flash bank. FLASHD_ReadUniqueID(pPrivate); @@ -1840,13 +1840,13 @@ static int sam3_probe(struct flash_bank_s *bank) { - return _sam3_probe( bank, 1 ); + return _sam3_probe(bank, 1 ); } static int sam3_auto_probe(struct flash_bank_s *bank) { - return _sam3_probe( bank, 0 ); + return _sam3_probe(bank, 0 ); } @@ -1863,21 +1863,21 @@ return ERROR_TARGET_NOT_HALTED; } - r = sam3_auto_probe( bank ); - if ( r != ERROR_OK ){ + r = sam3_auto_probe(bank ); + if (r != ERROR_OK ){ LOG_DEBUG("Here,r=%d",r); return r; } - pPrivate = get_sam3_bank_private( bank ); - if ( !(pPrivate->probed) ){ + pPrivate = get_sam3_bank_private(bank ); + if (!(pPrivate->probed) ){ return ERROR_FLASH_BANK_NOT_PROBED; } - if ( (first == 0) && ((last + 1)== ((int)(pPrivate->nsectors))) ){ + if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors))) ){ // whole chip LOG_DEBUG("Here"); - return FLASHD_EraseEntireBank( pPrivate ); + return FLASHD_EraseEntireBank(pPrivate ); } LOG_INFO("sam3 auto-erases while programing (request ignored)"); return ERROR_OK; @@ -1895,15 +1895,15 @@ return ERROR_TARGET_NOT_HALTED; } - pPrivate = get_sam3_bank_private( bank ); - if ( !(pPrivate->probed) ){ + pPrivate = get_sam3_bank_private(bank ); + if (!(pPrivate->probed) ){ return ERROR_FLASH_BANK_NOT_PROBED; } - if ( set ){ - r = FLASHD_Lock( pPrivate, (unsigned)(first), (unsigned)(last)); + if (set ){ + r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last)); } else { - r = FLASHD_Unlock( pPrivate, (unsigned)(first), (unsigned)(last)); + r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last)); } LOG_DEBUG("End: r=%d",r); @@ -1913,7 +1913,7 @@ static int -sam3_info( flash_bank_t *bank, char *buf, int buf_size ) +sam3_info(flash_bank_t *bank, char *buf, int buf_size ) { if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); @@ -1924,7 +1924,7 @@ } static int -sam3_page_read( struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf ) +sam3_page_read(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf ) { uint32_t adr; int r; @@ -1932,12 +1932,12 @@ adr = pagenum * pPrivate->page_size; adr += adr + pPrivate->base_address; - r = target_read_memory( pPrivate->pChip->target, + r = target_read_memory(pPrivate->pChip->target, adr, 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, buf ); - if ( r != ERROR_OK ){ + if (r != ERROR_OK ){ LOG_ERROR("SAM3: Flash program failed to read page phys address: 0x%08x", (unsigned int)(adr) ); } return r; @@ -1964,7 +1964,7 @@ // }; // // -// uint32_t sam3_function( struct foo *p ) +// uint32_t sam3_function(struct foo *p ) // { // volatile uint32_t *v; // uint32_t *d; @@ -1978,7 +1978,7 @@ // // do { // *d++ = *s++; -// } while ( --n ) +// } while (--n ) // ; // // v = p->base; @@ -1986,7 +1986,7 @@ // v[ 1 ] = p->cmd; // do { // r = v[8/4]; -// } while ( !(r&1) ) +// } while (!(r&1) ) // ; // return r; // } @@ -2036,7 +2036,7 @@ static int -sam3_page_write( struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf ) +sam3_page_write(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *buf ) { uint32_t adr; uint32_t status; @@ -2046,30 +2046,30 @@ adr += (adr + pPrivate->base_address); LOG_DEBUG("Wr Page %u @ phys address: 0x%08x", pagenum, (unsigned int)(adr) ); - r = target_write_memory( pPrivate->pChip->target, + r = target_write_memory(pPrivate->pChip->target, adr, 4, /* THIS*MUST*BE* in 32bit values */ pPrivate->page_size / 4, buf ); - if ( r != ERROR_OK ){ + if (r != ERROR_OK ){ LOG_ERROR("SAM3: Failed to write (buffer) page at phys address 0x%08x", (unsigned int)(adr) ); return r; } - r = EFC_PerformCommand( pPrivate, + r = EFC_PerformCommand(pPrivate, // send Erase & Write Page AT91C_EFC_FCMD_EWP, pagenum, &status ); - if ( r != ERROR_OK ){ + if (r != ERROR_OK ){ LOG_ERROR("SAM3: Error performing Erase & Write page @ phys address 0x%08x", (unsigned int)(adr) ); } - if ( status & (1 << 2) ){ + if (status & (1 << 2) ){ LOG_ERROR("SAM3: Page @ Phys address 0x%08x is locked", (unsigned int)(adr) ); return ERROR_FAIL; } - if ( status & (1 << 1) ){ + if (status & (1 << 1) ){ LOG_ERROR("SAM3: Flash Command error @phys address 0x%08x", (unsigned int)(adr) ); return ERROR_FAIL; } @@ -2095,7 +2095,7 @@ uint8_t *pagebuffer; // ignore dumb requests - if ( count == 0 ){ + if (count == 0 ){ return ERROR_OK; } @@ -2105,12 +2105,12 @@ } pPrivate = get_sam3_bank_private(bank); - if ( !(pPrivate->probed) ){ + if (!(pPrivate->probed) ){ return ERROR_FLASH_BANK_NOT_PROBED; } - if ( (offset + count) > pPrivate->size_bytes ){ + if ((offset + count) > pPrivate->size_bytes ){ LOG_ERROR("Flash write error - past end of bank"); LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x", (unsigned int)(offset), @@ -2119,7 +2119,7 @@ return ERROR_FAIL; } - pagebuffer = alloca( pPrivate->page_size ); + pagebuffer = alloca(pPrivate->page_size ); // what page do we start & end in? page_cur = offset / pPrivate->page_size; @@ -2136,20 +2136,20 @@ // (3) non-aligned end. // Handle special case - all one page. - if ( page_cur == page_end ){ + if (page_cur == page_end ){ LOG_DEBUG("Special case, all in one page"); - r = sam3_page_read( pPrivate, page_cur, pagebuffer ); - if ( r != ERROR_OK ){ + r = sam3_page_read(pPrivate, page_cur, pagebuffer ); + if (r != ERROR_OK ){ return r; } page_offset = (offset & (pPrivate->page_size-1)); - memcpy( pagebuffer + page_offset, + memcpy(pagebuffer + page_offset, buffer, count ); - r = sam3_page_write( pPrivate, page_cur, pagebuffer ); - if ( r != ERROR_OK ){ + r = sam3_page_write(pPrivate, page_cur, pagebuffer ); + if (r != ERROR_OK ){ return r; } return ERROR_OK; @@ -2157,22 +2157,22 @@ // non-aligned start page_offset = offset & (pPrivate->page_size - 1); - if ( page_offset ){ + if (page_offset ){ LOG_DEBUG("Not-Aligned start"); // read the partial - r = sam3_page_read( pPrivate, page_cur, pagebuffer ); - if ( r != ERROR_OK ){ + r = sam3_page_read(pPrivate, page_cur, pagebuffer ); + if (r != ERROR_OK ){ return r; } // over-write with new data n = (pPrivate->page_size - page_offset ); - memcpy( pagebuffer + page_offset, + memcpy(pagebuffer + page_offset, buffer, n ); - r = sam3_page_write( pPrivate, page_cur, pagebuffer ); - if ( r != ERROR_OK ){ + r = sam3_page_write(pPrivate, page_cur, pagebuffer ); + if (r != ERROR_OK ){ return r; } @@ -2188,10 +2188,10 @@ LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count = 0x%08x", (int)page_cur, (int)page_end, (unsigned int)(count) ); - while ( (page_cur < page_end) && + while ((page_cur < page_end) && (count >= pPrivate->page_size) ){ - r = sam3_page_write( pPrivate, page_cur, buffer ); - if ( r != ERROR_OK ){ + r = sam3_page_write(pPrivate, page_cur, buffer ); + if (r != ERROR_OK ){ return r; } count -= pPrivate->page_size; @@ -2200,17 +2200,17 @@ } // terminal partial page? - if ( count ){ + if (count ){ LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count)); // we have a partial page - r = sam3_page_read( pPrivate, page_cur, pagebuffer ); - if ( r != ERROR_OK ){ + r = sam3_page_read(pPrivate, page_cur, pagebuffer ); + if (r != ERROR_OK ){ return r; } // data goes at start - memcpy( pagebuffer, buffer, count ); - r = sam3_page_write( pPrivate, page_cur, pagebuffer ); - if ( r != ERROR_OK ){ + memcpy(pagebuffer, buffer, count ); + r = sam3_page_write(pPrivate, page_cur, pagebuffer ); + if (r != ERROR_OK ){ return r; } buffer += count; @@ -2221,7 +2221,7 @@ } static int -sam3_handle_info_command( struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc ) +sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc ) { struct sam3_chip *pChip; void *vp; @@ -2230,17 +2230,17 @@ int r; pChip = get_current_sam3(cmd_ctx); - if ( !pChip ){ + if (!pChip ){ return ERROR_OK; } r = 0; // bank0 must exist before we can do anything - if ( pChip->details.bank[0].pBank == NULL ){ + if (pChip->details.bank[0].pBank == NULL ){ x = 0; need_define: - command_print( cmd_ctx, + command_print(cmd_ctx, "Please define bank %d via command: flash bank %s ... ", x, at91sam3_flash.name ); @@ -2248,9 +2248,9 @@ } // if bank 0 is not probed, then probe it - if ( !(pChip->details.bank[0].probed) ){ - r = sam3_auto_probe( pChip->details.bank[0].pBank ); - if ( r != ERROR_OK ){ + if (!(pChip->details.bank[0].probed) ){ + r = sam3_auto_probe(pChip->details.bank[0].pBank ); + if (r != ERROR_OK ){ return ERROR_FAIL; } } @@ -2260,45 +2260,45 @@ // auto-probe other banks, 0 done above - for ( x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ // skip banks not present - if ( !(pChip->details.bank[x].present) ){ + if (!(pChip->details.bank[x].present) ){ continue; } - if ( pChip->details.bank[x].pBank == NULL ){ + if (pChip->details.bank[x].pBank == NULL ){ goto need_define; } - if ( pChip->details.bank[x].probed ){ + if (pChip->details.bank[x].probed ){ continue; } - r = sam3_auto_probe( pChip->details.bank[x].pBank ); - if ( r != ERROR_OK ){ + r = sam3_auto_probe(pChip->details.bank[x].pBank ); + if (r != ERROR_OK ){ return r; } } - r = sam3_GetInfo( pChip ); - if ( r != ERROR_OK ){ + r = sam3_GetInfo(pChip ); + if (r != ERROR_OK ){ LOG_DEBUG("Sam3Info, Failed %d\n",r); return r; } // print results - cp = membuf_strtok( pChip->mbuf, "\n", &vp ); + cp = membuf_strtok(pChip->mbuf, "\n", &vp ); while (cp){ command_print(cmd_ctx,"%s", cp ); - cp = membuf_strtok( NULL, "\n", &vp ); + cp = membuf_strtok(NULL, "\n", &vp ); } return ERROR_OK; } static int -sam3_handle_gpnvm_command( struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc) +sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc) { unsigned x,v; uint32_t v32; @@ -2306,30 +2306,30 @@ struct sam3_chip *pChip; pChip = get_current_sam3(cmd_ctx); - if ( !pChip ){ + if (!pChip ){ return ERROR_OK; } - if ( pChip->target->state != TARGET_HALTED ){ + if (pChip->target->state != TARGET_HALTED ){ LOG_ERROR("sam3 - target not halted"); return ERROR_TARGET_NOT_HALTED; } - if ( pChip->details.bank[0].pBank == NULL ){ - command_print( cmd_ctx, "Bank0 must be defined first via: flash bank %s ...", + if (pChip->details.bank[0].pBank == NULL ){ + command_print(cmd_ctx, "Bank0 must be defined first via: flash bank %s ...", at91sam3_flash.name ); return ERROR_FAIL; } - if ( !pChip->details.bank[0].probed ){ - r = sam3_auto_probe( pChip->details.bank[0].pBank ); - if ( r != ERROR_OK ){ + if (!pChip->details.bank[0].probed ){ + r = sam3_auto_probe(pChip->details.bank[0].pBank ); + if (r != ERROR_OK ){ return r; } } - switch ( argc ){ + switch (argc ){ default: command_print(cmd_ctx,"Too many parameters\n"); return ERROR_COMMAND_SYNTAX_ERROR; @@ -2342,12 +2342,12 @@ who = -1; break; case 2: - if ( (0 == strcmp( argv[0], "show" )) && (0 == strcmp( argv[1], "all" )) ){ + if ((0 == strcmp(argv[0], "show" )) && (0 == strcmp(argv[1], "all" )) ){ who = -1; } else { - r = parse_u32( argv[1], &v32 ); - if ( r != ERROR_OK ){ - command_print( cmd_ctx, "Not a number: %s", argv[1] ); + r = parse_u32(argv[1], &v32 ); + if (r != ERROR_OK ){ + command_print(cmd_ctx, "Not a number: %s", argv[1] ); return r; } who = v32; @@ -2355,20 +2355,20 @@ break; } - if ( 0 == strcmp( "show", argv[0] ) ){ - if ( who == -1 ){ + if (0 == strcmp("show", argv[0] ) ){ + if (who == -1 ){ showall: - for ( x = 0 ; x < pChip->details.n_gpnvms ; x++ ){ - r = FLASHD_GetGPNVM( &(pChip->details.bank[0]), x, &v ); - if ( r != ERROR_OK ){ + for (x = 0 ; x < pChip->details.n_gpnvms ; x++ ){ + r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v ); + if (r != ERROR_OK ){ break; } command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v ); } return r; } - if ( (who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms) ){ - r = FLASHD_GetGPNVM( &(pChip->details.bank[0]), who, &v ); + if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms) ){ + r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v ); command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v ); return r; } else { @@ -2377,25 +2377,25 @@ } } - if ( who == -1 ){ - command_print( cmd_ctx, "Missing GPNVM number"); + if (who == -1 ){ + command_print(cmd_ctx, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } - if ( 0 == strcmp( "set", argv[0] ) ){ - r = FLASHD_SetGPNVM( &(pChip->details.bank[0]), who ); - } else if ( (0 == strcmp( "clr", argv[0] )) || - (0 == strcmp( "clear", argv[0])) ){ // quietly accept both - r = FLASHD_ClrGPNVM( &(pChip->details.bank[0]), who ); + if (0 == strcmp("set", argv[0] ) ){ + r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who ); + } else if ((0 == strcmp("clr", argv[0] )) || + (0 == strcmp("clear", argv[0])) ){ // quietly accept both + r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who ); } else { - command_print( cmd_ctx, "Unkown command: %s", argv[0] ); + command_print(cmd_ctx, "Unkown command: %s", argv[0] ); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; } static int -sam3_handle_slowclk_command( struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc) +sam3_handle_slowclk_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc) { uint32_t v; int r; @@ -2403,19 +2403,19 @@ struct sam3_chip *pChip; pChip = get_current_sam3(cmd_ctx); - if ( !pChip ){ + if (!pChip ){ return ERROR_OK; } - switch ( argc ){ + switch (argc ){ case 0: // show break; case 1: // set - r = parse_u32( argv[0], &v ); - if ( v > 200000 ){ + r = parse_u32(argv[0], &v ); + if (v > 200000 ){ // absurd slow clock of 200Khz? command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; @@ -2425,11 +2425,11 @@ default: // error - command_print( cmd_ctx,"Too many parameters"); + command_print(cmd_ctx,"Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print( cmd_ctx, "Slowclk freq: %d.%03dkhz", + command_print(cmd_ctx, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq/ 1000), (int)(pChip->cfg.slow_freq% 1000)); return ERROR_OK; @@ -2438,26 +2438,26 @@ static int sam3_registered; static int -sam3_register_commands( struct command_context_s *cmd_ctx) +sam3_register_commands(struct command_context_s *cmd_ctx) { command_t *pCmd; // only register once - if ( !sam3_registered ){ + if (!sam3_registered ){ sam3_registered++; - pCmd = register_command( cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL ); - register_command( cmd_ctx, pCmd, + pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL ); + register_command(cmd_ctx, pCmd, "gpnvm", sam3_handle_gpnvm_command, COMMAND_EXEC, "at91sam3 gpnvm [action [<BIT>], by default 'show', otherwise set | clear BIT"); - register_command( cmd_ctx, pCmd, + register_command(cmd_ctx, pCmd, "info", sam3_handle_info_command, COMMAND_EXEC, "at91sam3 info - print information about the current sam3 chip"); - register_command( cmd_ctx, pCmd, + register_command(cmd_ctx, pCmd, "slowclk", sam3_handle_slowclk_command, COMMAND_EXEC, Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:37:56 UTC (rev 2394) +++ trunk/src/helper/membuf.c 2009-06-24 09:38:01 UTC (rev 2395) @@ -37,32 +37,32 @@ }; -#define space_avail( pBuf ) (pBuf->maxlen - pBuf->curlen) -#define dataend( pBuf ) ( ((char *)(pBuf->buf)) + pBuf->curlen ) +#define space_avail(pBuf ) (pBuf->maxlen - pBuf->curlen) +#define dataend(pBuf ) (((char *)(pBuf->buf)) + pBuf->curlen ) size_t -membuf_len( struct membuf *pBuf ) +membuf_len(struct membuf *pBuf ) { return pBuf->curlen; } const void * -membuf_datapointer( struct membuf *pBuf ) +membuf_datapointer(struct membuf *pBuf ) { return ((void *)(pBuf->buf)); } const char * -membuf_strtok( struct membuf *pBuf, const char *sep, void **pLast ) +membuf_strtok(struct membuf *pBuf, const char *sep, void **pLast ) { - if ( pBuf ){ + if (pBuf ){ pBuf->_strtoklast = NULL; *pLast = pBuf; - return strtok_r( ((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast) ); + return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast) ); } else { // recover our pBuf pBuf = *((struct membuf **)(pLast)); - return strtok_r( NULL, sep, &(pBuf->_strtoklast) ); + return strtok_r(NULL, sep, &(pBuf->_strtoklast) ); } } @@ -74,11 +74,11 @@ // by default - parameters are zero. struct membuf *pBuf; - pBuf = calloc( 1, sizeof(*pBuf) ); - if ( pBuf ){ + pBuf = calloc(1, sizeof(*pBuf) ); + if (pBuf ){ // we *ALWAYS* allocate +1 for null terminator. - pBuf->buf = calloc( DEFAULT_BUFSIZE + 1, sizeof(char)); - if ( pBuf->buf == NULL ){ + pBuf->buf = calloc(DEFAULT_BUFSIZE + 1, sizeof(char)); + if (pBuf->buf == NULL ){ free(pBuf); pBuf = NULL; } else { @@ -90,7 +90,7 @@ struct membuf * -membuf_grow( struct membuf *pBuf, int n ) +membuf_grow(struct membuf *pBuf, int n ) { void *vp; signed int newsize; @@ -99,13 +99,13 @@ newsize = ((int)(pBuf->maxlen)) + n; // do not go negative, or too small - if ( newsize < DEFAULT_BUFSIZE ){ + if (newsize < DEFAULT_BUFSIZE ){ newsize = DEFAULT_BUFSIZE; } // always alloc +1 for the null terminator - vp = realloc( pBuf->buf, newsize + 1 ); - if ( vp ){ + vp = realloc(pBuf->buf, newsize + 1 ); + if (vp ){ pBuf->buf = vp; pBuf->maxlen = newsize; return pBuf; @@ -115,16 +115,16 @@ } -void membuf_reset( struct membuf *pBuf ) +void membuf_reset(struct membuf *pBuf ) { pBuf->curlen = 0; } -void membuf_delete( struct membuf *pBuf ) +void membuf_delete(struct membuf *pBuf ) { - if ( pBuf ){ - if ( pBuf->buf){ + if (pBuf ){ + if (pBuf->buf){ // wack data so it cannot be reused memset(pBuf->buf,0,pBuf->maxlen); free(pBuf->buf); @@ -136,18 +136,18 @@ } int -membuf_sprintf( struct membuf *pBuf , const char *fmt, ... ) +membuf_sprintf(struct membuf *pBuf , const char *fmt, ... ) { int r; va_list ap; - va_start( ap, fmt ); - r = membuf_vsprintf( pBuf, fmt, ap ); + va_start(ap, fmt ); + r = membuf_vsprintf(pBuf, fmt, ap ); va_end(ap); return r; } int -membuf_vsprintf( struct membuf *pBuf, const char *fmt, va_list ap ) +membuf_vsprintf(struct membuf *pBuf, const char *fmt, va_list ap ) { int r; size_t sa; @@ -159,11 +159,11 @@ sa = space_avail(pBuf); // do work - r = vsnprintf( dataend( pBuf ), + r = vsnprintf(dataend(pBuf ), sa, fmt, ap ); - if ( (r > 0) && (((size_t)(r)) < sa) ){ + if ((r > 0) && (((size_t)(r)) < sa) ){ // Success! pBuf->curlen += ((size_t)(r)); // remember: We always alloc'ed +1 @@ -174,7 +174,7 @@ } // failure - if ( r < 0 ){ + if (r < 0 ){ // Option(A) format error // Option(B) glibc2.0 bug // assume (B). @@ -182,12 +182,12 @@ } // don't do this again - if ( grew ){ + if (grew ){ r = -1; break; } grew = 1; - pBuf = membuf_grow( pBuf, r ); + pBuf = membuf_grow(pBuf, r ); if (pBuf == NULL){ // grow failed r = -1; @@ -198,33 +198,33 @@ } struct membuf * -membuf_strcat( struct membuf *pBuf, const char *pStr ) +membuf_strcat(struct membuf *pBuf, const char *pStr ) { - return membuf_append( pBuf, pStr, strlen( pStr ) ); + return membuf_append(pBuf, pStr, strlen(pStr ) ); } struct membuf * -membuf_append( struct membuf *pBuf, const void *pData, size_t len ) +membuf_append(struct membuf *pBuf, const void *pData, size_t len ) { size_t sa; int r; // how much room is there? - sa = space_avail( pBuf ); + sa = space_avail(pBuf ); // will it fit? - if ( sa < len ){ + if (sa < len ){ // if not, how much do we need? r = ((int)(sa - len)); // do the grow. - pBuf = membuf_grow( pBuf, r ); + pBuf = membuf_grow(pBuf, r ); // failed? if (pBuf == NULL){ return pBuf; } } // append - memcpy( dataend(pBuf), + memcpy(dataend(pBuf), pData, len ); pBuf->curlen += len; Modified: trunk/src/helper/membuf.h =================================================================== --- trunk/src/helper/membuf.h 2009-06-24 09:37:56 UTC (rev 2394) +++ trunk/src/helper/membuf.h 2009-06-24 09:38:01 UTC (rev 2395) @@ -30,7 +30,7 @@ /** delete (destroy) the mem buffer * @param pBuf - buffer to release */ -void membuf_delete( struct membuf *pBuf ); +void membuf_delete(struct membuf *pBuf ); /** grow/shrink a membuf by specified amount. @@ -39,14 +39,14 @@ * * Symantics of 'realloc()' return NULL on failure */ -struct membuf *membuf_grow( struct membuf *pBuf, int amount ); +struct membuf *membuf_grow(struct membuf *pBuf, int amount ); /** how long is this buffer (memlen(), strlen()) * @param pBuf - the buffer * * @returns: length of current buffer. */ -size_t membuf_len( struct membuf *pBuf ); +size_t membuf_len(struct membuf *pBuf ); /** reset an membuf to zero length. @@ -54,7 +54,7 @@ * * Note this does not 'release' the memory buffer */ -void membuf_reset( struct membuf *pBuf ); +void membuf_reset(struct membuf *pBuf ); /** sprintf() to the string buffer @@ -64,7 +64,7 @@ * Returns 0 on success * Returns non-zero on failure */ -int membuf_sprintf( struct membuf *pBuf , const char *fmt, ... ); +int membuf_sprintf(struct membuf *pBuf , const char *fmt, ... ); /** vsprintf() to the string buffer * @param pBuf - buffer to capture sprintf() data into @@ -74,7 +74,7 @@ * Returns 0 on success * Returns non-zero on failure */ -int membuf_vsprintf( struct membuf *pBuf , const char *fmt, va_list ap); +int membuf_vsprintf(struct membuf *pBuf , const char *fmt, va_list ap); /** Tokenize lines using strtok() * @param pBuf - buffer to tokenize @@ -84,14 +84,14 @@ * * NOTE: This call is <b > destructive</b> to the buffer. */ -const char *membuf_strtok( struct membuf *pBuf, const char *delim, void **pSave ); +const char *membuf_strtok(struct membuf *pBuf, const char *delim, void **pSave ); /** Return pointer to the memory in the buffer * @param pBuf - buffer * * NOTE: Thou shall not modify this pointer, it is <b > CONST</b> */ -const void *membuf_datapointer( struct membuf *pBuf ); +const void *membuf_datapointer(struct membuf *pBuf ); /** Append data to the buffer @@ -102,7 +102,7 @@ * Modified symantics of "memcpy()". On memory allocation failure * returns NULL. On success, returns pointer to orginal membuf. */ -struct membuf *membuf_append( struct membuf *pBuf, const void *pData, size_t len ); +struct membuf *membuf_append(struct membuf *pBuf, const void *pData, size_t len ); /** Append string to the buffer @@ -112,7 +112,7 @@ * Modified symantics of "strcat()". On memory allocation failure * returns NULL. On success, returns pointer to orginal membuf. */ -struct membuf *membuf_strcat( struct membuf *pBuf, const char *s ); +struct membuf *membuf_strcat(struct membuf *pBuf, const char *s ); #endif |
From: <zw...@ma...> - 2009-06-24 11:37:59
|
Author: zwelch Date: 2009-06-24 11:37:56 +0200 (Wed, 24 Jun 2009) New Revision: 2394 Modified: trunk/src/helper/membuf.h Log: - Fixes '[<>]' whitespace - Replace '\(\w\)\([<>]\)\(\w\)' with '\1 \2 \3'. Modified: trunk/src/helper/membuf.h =================================================================== --- trunk/src/helper/membuf.h 2009-06-24 09:37:50 UTC (rev 2393) +++ trunk/src/helper/membuf.h 2009-06-24 09:37:56 UTC (rev 2394) @@ -82,14 +82,14 @@ * * Identical to "strtok()" - pass "pBuff = NULL" on second call * - * NOTE: This call is <b>destructive</b> to the buffer. + * NOTE: This call is <b > destructive</b> to the buffer. */ const char *membuf_strtok( struct membuf *pBuf, const char *delim, void **pSave ); /** Return pointer to the memory in the buffer * @param pBuf - buffer * - * NOTE: Thou shall not modify this pointer, it is <b>CONST</b> + * NOTE: Thou shall not modify this pointer, it is <b > CONST</b> */ const void *membuf_datapointer( struct membuf *pBuf ); |
From: <zw...@ma...> - 2009-06-24 11:37:54
|
Author: zwelch Date: 2009-06-24 11:37:50 +0200 (Wed, 24 Jun 2009) New Revision: 2393 Modified: trunk/src/flash/at91sam3.c Log: - Fixes '[|]' whitespace - Replace '\(\w\)\([|]\)\(\w\)' with '\1 \2 \3'. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:37:44 UTC (rev 2392) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:37:50 UTC (rev 2393) @@ -2451,7 +2451,7 @@ "gpnvm", sam3_handle_gpnvm_command, COMMAND_EXEC, - "at91sam3 gpnvm [action [<BIT>], by default 'show', otherwise set|clear BIT"); + "at91sam3 gpnvm [action [<BIT>], by default 'show', otherwise set | clear BIT"); register_command( cmd_ctx, pCmd, "info", sam3_handle_info_command, |
From: <zw...@ma...> - 2009-06-24 11:37:48
|
Author: zwelch Date: 2009-06-24 11:37:44 +0200 (Wed, 24 Jun 2009) New Revision: 2392 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c Log: - Fixes '+' whitespace - Replace '\(\w\)\(+\)\(\w\)' with '\1 \2 \3'. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:37:37 UTC (rev 2391) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:37:44 UTC (rev 2392) @@ -1276,7 +1276,7 @@ } else if ( diva == 0 ){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n"); } else if ( diva == 1 ){ - pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula+1)); + pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula + 1)); sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n", _tomhz( pChip->cfg.plla_freq )); } @@ -1828,7 +1828,7 @@ LOG_DEBUG("Bank = %d, nbanks = %d", pPrivate->bank_number , pPrivate->pChip->details.n_banks); - if ( (pPrivate->bank_number+1) == pPrivate->pChip->details.n_banks ){ + if ( (pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks ){ // read unique id, // it appears to be associated with the *last* flash bank. FLASHD_ReadUniqueID(pPrivate); @@ -1874,7 +1874,7 @@ return ERROR_FLASH_BANK_NOT_PROBED; } - if ( (first == 0) && ((last+1)== ((int)(pPrivate->nsectors))) ){ + if ( (first == 0) && ((last + 1)== ((int)(pPrivate->nsectors))) ){ // whole chip LOG_DEBUG("Here"); return FLASHD_EraseEntireBank( pPrivate ); Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:37:37 UTC (rev 2391) +++ trunk/src/helper/membuf.c 2009-06-24 09:37:44 UTC (rev 2392) @@ -77,7 +77,7 @@ pBuf = calloc( 1, sizeof(*pBuf) ); if ( pBuf ){ // we *ALWAYS* allocate +1 for null terminator. - pBuf->buf = calloc( DEFAULT_BUFSIZE+1, sizeof(char)); + pBuf->buf = calloc( DEFAULT_BUFSIZE + 1, sizeof(char)); if ( pBuf->buf == NULL ){ free(pBuf); pBuf = NULL; @@ -104,7 +104,7 @@ } // always alloc +1 for the null terminator - vp = realloc( pBuf->buf, newsize+1 ); + vp = realloc( pBuf->buf, newsize + 1 ); if ( vp ){ pBuf->buf = vp; pBuf->maxlen = newsize; |
From: <zw...@ma...> - 2009-06-24 11:37:45
|
Author: zwelch Date: 2009-06-24 11:37:37 +0200 (Wed, 24 Jun 2009) New Revision: 2391 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.h Log: - Fixes '=' whitespace - Replace '\(\w\)\(=\)\(\w\)' with '\1 \2 \3'. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:37:31 UTC (rev 2390) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:37:37 UTC (rev 2391) @@ -756,7 +756,7 @@ } r = EFC_PerformCommand( pPrivate, AT91C_EFC_FCMD_SPUI, 0, NULL ); - LOG_DEBUG("End: R=%d, id=0x%08x, 0x%08x, 0x%08x, 0x%08x", + LOG_DEBUG("End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x", r, (unsigned int)(pPrivate->pChip->cfg.unique_id[0]), (unsigned int)(pPrivate->pChip->cfg.unique_id[1]), @@ -1272,9 +1272,9 @@ sam3_sprintf(pChip,"\n"); pChip->cfg.plla_freq = 0; if ( mula == 0 ){ - sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula=0)\n"); + sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula = 0)\n"); } else if ( diva == 0 ){ - sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva=0)\n"); + sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n"); } else if ( diva == 1 ){ pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula+1)); sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n", @@ -1945,7 +1945,7 @@ // The code below is basically this: // compiled with -// arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 -O9 -S ./foobar.c -o foobar.s +// arm-none-eabi-gcc -mthumb -mcpu = cortex-m3 -O9 -S ./foobar.c -o foobar.s // // Only the *CPU* can write to the flash buffer. // the DAP cannot... so - we download this 28byte thing @@ -2185,7 +2185,7 @@ // intermediate large pages // also - the final *terminal* // if that terminal page is a full page - LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count=0x%08x", + LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count = 0x%08x", (int)page_cur, (int)page_end, (unsigned int)(count) ); while ( (page_cur < page_end) && @@ -2201,7 +2201,7 @@ // terminal partial page? if ( count ){ - LOG_DEBUG("Terminal partial page, count=0x%08x", (unsigned int)(count)); + LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count)); // we have a partial page r = sam3_page_read( pPrivate, page_cur, pagebuffer ); if ( r != ERROR_OK ){ Modified: trunk/src/helper/membuf.h =================================================================== --- trunk/src/helper/membuf.h 2009-06-24 09:37:31 UTC (rev 2390) +++ trunk/src/helper/membuf.h 2009-06-24 09:37:37 UTC (rev 2391) @@ -80,7 +80,7 @@ * @param pBuf - buffer to tokenize * @param delim - delimiter parameter for strtok_r() * - * Identical to "strtok()" - pass "pBuff=NULL" on second call + * Identical to "strtok()" - pass "pBuff = NULL" on second call * * NOTE: This call is <b>destructive</b> to the buffer. */ |
From: <zw...@ma...> - 2009-06-24 11:37:34
|
Author: zwelch Date: 2009-06-24 11:37:31 +0200 (Wed, 24 Jun 2009) New Revision: 2390 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c Log: - Fixes '==' whitespace - Replace '\(\w\)\(==\)\(\w\)' with '\1 \2 \3'. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:37:23 UTC (rev 2389) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:37:31 UTC (rev 2390) @@ -1271,7 +1271,7 @@ mula = sam3_reg_fieldname( pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11 ); sam3_sprintf(pChip,"\n"); pChip->cfg.plla_freq = 0; - if ( mula==0 ){ + if ( mula == 0 ){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula=0)\n"); } else if ( diva == 0 ){ sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva=0)\n"); Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:37:23 UTC (rev 2389) +++ trunk/src/helper/membuf.c 2009-06-24 09:37:31 UTC (rev 2390) @@ -219,7 +219,7 @@ // do the grow. pBuf = membuf_grow( pBuf, r ); // failed? - if (pBuf==NULL){ + if (pBuf == NULL){ return pBuf; } } |
From: <zw...@ma...> - 2009-06-24 11:37:28
|
Author: zwelch Date: 2009-06-24 11:37:23 +0200 (Wed, 24 Jun 2009) New Revision: 2389 Modified: trunk/src/flash/at91sam3.c trunk/src/helper/membuf.c Log: - Replace 'for(' with 'for ('. Modified: trunk/src/flash/at91sam3.c =================================================================== --- trunk/src/flash/at91sam3.c 2009-06-24 09:37:18 UTC (rev 2388) +++ trunk/src/flash/at91sam3.c 2009-06-24 09:37:23 UTC (rev 2389) @@ -745,7 +745,7 @@ return r; } - for( x = 0 ; x < 4 ; x++ ){ + for ( x = 0 ; x < 4 ; x++ ){ r = target_read_u32( pPrivate->pChip->target, pPrivate->pBank->base + (x * 4), &v ); @@ -1224,7 +1224,7 @@ v = sam3_reg_fieldname( pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8 ); cp = _unknown; - for( x = 0 ; archnames[x].name ; x++ ){ + for ( x = 0 ; archnames[x].name ; x++ ){ if ( v == archnames[x].value ){ cp = archnames[x].name; break; @@ -1569,7 +1569,7 @@ } LOG_INFO("sam3 - supports auto-erase, erase_check ignored"); - for( x = 0 ; x < bank->num_sectors ; x++ ){ + for ( x = 0 ; x < bank->num_sectors ; x++ ){ bank->sectors[x].is_erased = 1; } @@ -1606,7 +1606,7 @@ return r; } - for( x = 0 ; x < pPrivate->nsectors ; x++ ){ + for ( x = 0 ; x < pPrivate->nsectors ; x++ ){ bank->sectors[x].is_protected = (!!(v & (1 << x))); } LOG_DEBUG("Done"); @@ -1730,7 +1730,7 @@ // // save the "bank" pointers - for( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for ( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ saved_banks[ x ] = pChip->details.bank[x].pBank; } @@ -1740,7 +1740,7 @@ sizeof(pPrivate->pChip->details)); // now fix the ghosted pointers - for( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for ( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ pChip->details.bank[x].pChip = pChip; pChip->details.bank[x].pBank = saved_banks[x]; } @@ -1795,7 +1795,7 @@ } // update the flash bank size - for( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for ( x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ if ( bank->base == pPrivate->pChip->details.bank[0].base_address ){ bank->size = pPrivate->pChip->details.bank[0].size_bytes; break; @@ -1810,7 +1810,7 @@ } bank->num_sectors = pPrivate->nsectors; - for( x = 0 ; ((int)(x)) < bank->num_sectors ; x++ ){ + for ( x = 0 ; ((int)(x)) < bank->num_sectors ; x++ ){ bank->sectors[x].size = pPrivate->sector_size; bank->sectors[x].offset = x * (pPrivate->sector_size); // mark as unknown @@ -2260,7 +2260,7 @@ // auto-probe other banks, 0 done above - for( x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ + for ( x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++ ){ // skip banks not present if ( !(pChip->details.bank[x].present) ){ continue; @@ -2358,7 +2358,7 @@ if ( 0 == strcmp( "show", argv[0] ) ){ if ( who == -1 ){ showall: - for( x = 0 ; x < pChip->details.n_gpnvms ; x++ ){ + for ( x = 0 ; x < pChip->details.n_gpnvms ; x++ ){ r = FLASHD_GetGPNVM( &(pChip->details.bank[0]), x, &v ); if ( r != ERROR_OK ){ break; Modified: trunk/src/helper/membuf.c =================================================================== --- trunk/src/helper/membuf.c 2009-06-24 09:37:18 UTC (rev 2388) +++ trunk/src/helper/membuf.c 2009-06-24 09:37:23 UTC (rev 2389) @@ -155,7 +155,7 @@ grew = 0; - for(;;) { + for (;;) { sa = space_avail(pBuf); // do work |