diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-06-20 19:29:20 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-06-20 19:29:20 +0000 |
commit | 524b08c3fcf36eff5114363d4ed889432de1baff (patch) | |
tree | f89b678cd14ff74894b93a97d64c57e17abed82d /nuttx | |
parent | 8812170a7c584b80d8097cdcf6548857be98c30e (diff) | |
download | px4-firmware-524b08c3fcf36eff5114363d4ed889432de1baff.tar.gz px4-firmware-524b08c3fcf36eff5114363d4ed889432de1baff.tar.bz2 px4-firmware-524b08c3fcf36eff5114363d4ed889432de1baff.zip |
Updates to support the Mirtoo internal clocking
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4855 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx')
45 files changed, 143 insertions, 1920 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index e2a291621..9a30500f6 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2914,4 +2914,6 @@ PIC32MX1 and PIC32MX2 families. * configs/mirtoo: Add a board configuration to support the DTX1-4000L "Mirtoo" module from http://www.dimitech.com/ + * tools/pic32mx: All of the duplicate directories containing the same + same PIC32 tools were move to this single location. diff --git a/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c b/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c index a0e616f04..0b01ecd69 100644 --- a/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c +++ b/nuttx/arch/arm/src/stm32/stm32f10xxx_rtc.c @@ -602,7 +602,7 @@ int up_rtc_settime(FAR const struct timespec *tp) ************************************************************************************/ #ifdef CONFIG_RTC_ALARM -int up_rtc_setalarm(FAR const struct timespec *tp, alarmcb_t callback); +int up_rtc_setalarm(FAR const struct timespec *tp, alarmcb_t callback) { struct rtc_regvals_s regvals; irqstate_t flags; diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-config.h b/nuttx/arch/mips/src/pic32mx/pic32mx-config.h index f2ccd89b0..419cd5250 100644 --- a/nuttx/arch/mips/src/pic32mx/pic32mx-config.h +++ b/nuttx/arch/mips/src/pic32mx/pic32mx-config.h @@ -775,6 +775,25 @@ # error "Unknown board POSC mode" #endif +#undef CONFIG_PIC32MX_FNOSC +#if defined(BOARD_FNOSC_FRC) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_FRC +#elif defined(BOARD_FNOSC_FRCPLL) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_FRCPLL +#elif defined(BOARD_FNOSC_POSC) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_POSC +#elif defined(BOARD_FNOSC_POSCPLL) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_POSCPLL +#elif defined(BOARD_FNOSC_SOSC) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_SOSC +#elif defined(BOARD_FNOSC_LPRC) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_LPRC +#elif defined(BOARD_FNOSC_FRCDIV) +# define CONFIG_PIC32MX_FNOSC DEVCFG1_FNOSC_FRCDIV +#else +# error "Unknown board FNOSC selection" +#endif + #undef CONFIG_PIC32MX_FCKSM #if defined(BOARD_POSC_SWITCH) # if defined(BOARD_POSC_FSCM) diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-head.S b/nuttx/arch/mips/src/pic32mx/pic32mx-head.S index 2a6ef39a8..3e9cfeb46 100644 --- a/nuttx/arch/mips/src/pic32mx/pic32mx-head.S +++ b/nuttx/arch/mips/src/pic32mx/pic32mx-head.S @@ -617,7 +617,7 @@ devconfig2: DEVCFG2_UNUSED devconfig1: - .long DEVCFG1_FNOSC_POSCPLL | CONFIG_PIC32MX_FSOSCEN | \ + .long CONFIG_PIC32MX_FNOSC | CONFIG_PIC32MX_FSOSCEN | \ CONFIG_PIC32MX_IESO | CONFIG_PIC32MX_POSCMOD | \ CONFIG_PIC32MX_PBDIV | CONFIG_PIC32MX_FCKSM | \ CONFIG_PIC32MX_WDENABLE | DEVCFG1_UNUSED diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-lowinit.c b/nuttx/arch/mips/src/pic32mx/pic32mx-lowinit.c index 9cf77fb50..d6bc6a812 100644 --- a/nuttx/arch/mips/src/pic32mx/pic32mx-lowinit.c +++ b/nuttx/arch/mips/src/pic32mx/pic32mx-lowinit.c @@ -63,7 +63,7 @@ /* Make sure that the selected clock parameters are sane */ -#define CALC_SYSCLOCK (((BOARD_POSC_FREQ / BOARD_PLL_IDIV) * BOARD_PLL_MULT) / BOARD_PLL_ODIV) +#define CALC_SYSCLOCK (((BOARD_PLL_INPUT / BOARD_PLL_IDIV) * BOARD_PLL_MULT) / BOARD_PLL_ODIV) #if CALC_SYSCLOCK != BOARD_CPU_CLOCK # error "Bad BOARD_CPU_CLOCK calculcation in board.h" #endif diff --git a/nuttx/configs/mirtoo/README.txt b/nuttx/configs/mirtoo/README.txt index 055a71c2e..7867a6640 100644 --- a/nuttx/configs/mirtoo/README.txt +++ b/nuttx/configs/mirtoo/README.txt @@ -388,14 +388,14 @@ Loading NuttX with ICD3 file to contain physical addresses. But the nuttx.hex file generated from the top-level make will have address in the KSEG0 and KSEG1 regions. - tools/mkpichex: - --------------- + tools/pic32mx/mkpichex: + ---------------------- - There is a simple tool in the configs/mirtoo/tools directory - that can be used to solve both issues with the nuttx.hex file. But, - first, you must build the the tools: + There is a simple tool in the NuttX tools/pic32mx directory that can be + used to solve both issues with the nuttx.hex file. But, first, you must + build the tool: - cd configs/mirtoo/tools + cd tools/pic32mx make Now you will have an excecutable file call mkpichex (or mkpichex.exe on @@ -406,7 +406,7 @@ Loading NuttX with ICD3 To use this file, you need to do the following things: . ./setenv.sh # Source setenv.sh. Among other this, this script - # will add configs/mirtoo/tools to your + # will add the NuttX tools/pic32mx directory to your # PATH variable make # Build nuttx and nuttx.hex mkpichex $PWD # Convert addresses in nuttx.hex. $PWD is the path diff --git a/nuttx/configs/mirtoo/include/board.h b/nuttx/configs/mirtoo/include/board.h index 98aa904a3..ffea646d1 100644 --- a/nuttx/configs/mirtoo/include/board.h +++ b/nuttx/configs/mirtoo/include/board.h @@ -52,16 +52,22 @@ /* Configuration ************************************************************/ /* Clocking *****************************************************************/ -/* Crystal frequencies */ +/* The Mirtoo does not use an external crystal but relies instead on the + * internal +/- 0.9% FRC clock. That clock has a nomninal frequency of 8MHz. + */ + +#define BOARD_FRC_FREQ 8000000 /* FRC nomimal frequency(8MHz) */ + +/* Oscillator modes */ -#define BOARD_POSC_FREQ 8000000 /* Primary OSC XTAL frequency (8MHz) */ -#define BOARD_SOSC_FREQ 32768 /* Secondary OSC XTAL frequency (32.768KHz) */ -#define BOARD_POSC_HSMODE 1 /* High-speed crystal (HS) mode */ +#define BOARD_FNOSC_FRCPLL 1 /* Use FRC w/PLL module */ +#define BOARD_POSC_DISABLED 1 /* Disable primary oscillator */ /* PLL configuration and resulting CPU clock. * CPU_CLOCK = ((POSC_FREQ / IDIV) * MULT) / ODIV */ +#define BOARD_PLL_INPUT BOARD_FRC_FREQ #define BOARD_PLL_IDIV 2 /* PLL input divider */ #define BOARD_PLL_MULT 20 /* PLL multiplier */ #define BOARD_PLL_ODIV 1 /* PLL output divider */ diff --git a/nuttx/configs/mirtoo/ostest/ld.script b/nuttx/configs/mirtoo/ostest/ld.script index 35019a9e3..7463754d7 100644 --- a/nuttx/configs/mirtoo/ostest/ld.script +++ b/nuttx/configs/mirtoo/ostest/ld.script @@ -46,18 +46,19 @@ MEMORY * 0x1fc00000-0x1fc00c00. The initial reset vector is in KSEG1, but * all other accesses are in KSEG0. * - * REGION PHYSICAL KSEG SIZE - * DESCRIPTION START ADDR (BYTES) - * ------------- ---------- ------ ---------------------- + * REGION PHYSICAL KSEG SIZE + * DESCRIPTION START ADDR (BYTES) + * --------------- ---------- ------ ---------------------- * Exceptions:* - * Reset 0x1fc00000 KSEG1 512 512 (0.500Kb) - * TLB Refill 0x1fc00200 KSEG1 256 768 (0.750Kb) - * Cache Error 0x1fc00300 KSEG1 128 896 (0.875Kb) - * Others 0x1fc00380 KSEG1 128 1024 (1.000Kb) - * Interrupt 0x1fc00400 KSEG1 128 1152 (1.125Kb) - * JTAG 0x1fc00480 KSEG1 16 1168 (1.141Kb) - * Exceptions 0x1fc00490 KSEG0 3072-1168-16 3056 (2.984Kb) - * DEVCFG3-0 0x1fc00bf0 KSEG1 16 3072 (3Kb) + * Reset 0x1fc00000 KSEG1 384 384 (0.375Kb) + * Gen exception 0x1fc00000 KSEG1 128 512 (0.500Kb) + * TLB Refill 0x1fc00200 KSEG1 256 768 (0.750Kb) + * Cache Error 0x1fc00300 KSEG1 128 896 (0.875Kb) + * Others 0x1fc00380 KSEG1 128 1024 (1.000Kb) + * Interrupt 0x1fc00400 KSEG1 128 1152 (1.125Kb) + * JTAG 0x1fc00480 KSEG1 16 1168 (1.141Kb) + * Exceptions 0x1fc00490 KSEG0 3072-1168-16 3056 (2.984Kb) + * DEVCFG3-0 0x1fc00bf0 KSEG1 16 3072 (3Kb) * * Exceptions assume: * @@ -69,7 +70,8 @@ MEMORY kseg1_reset (rx) : ORIGIN = 0xbfc00000, LENGTH = 384 kseg1_genexcpt (rx) : ORIGIN = 0xbfc00180, LENGTH = 128 - kseg1_ebexcpt (rx) : ORIGIN = 0xbfc00200, LENGTH = 128 + kseg1_ebexcpt (rx) : ORIGIN = 0xbfc00200, LENGTH = 256 + kseg1_cacherr (rx) : ORIGIN = 0xbfc00300, LENGTH = 128 kseg1_bevexcpt (rx) : ORIGIN = 0xbfc00380, LENGTH = 128 kseg1_intexcpt (rx) : ORIGIN = 0xbfc00400, LENGTH = 128 kseg1_dbgexcpt (rx) : ORIGIN = 0xbfc00480, LENGTH = 16 @@ -80,11 +82,11 @@ MEMORY * 0x00000000. Since the PIC32MX has no data cache, this memory is * always accessed through KSEG1. * - * When used with MPLAB, we need to set aside 512 bytes of memory - * for use by MPLAB. + * NOTE: When used with MPLAB, we need to set aside 512 bytes of memory + * at the beginning of this region for use by MPLAB. */ - kseg1_datamem (w!x) : ORIGIN = 0xa0000200, LENGTH = 32K - 512 + kseg1_datamem (w!x) : ORIGIN = 0xa0000200, LENGTH = 32K } OUTPUT_FORMAT("elf32-tradlittlemips") @@ -154,8 +156,6 @@ SECTIONS *(.int_handler) } > kseg0_bootmem - .dbg_code = ORIGIN(kseg1_dbgcode); - .devcfg : { KEEP (*(.devcfg)) diff --git a/nuttx/configs/mirtoo/ostest/setenv.sh b/nuttx/configs/mirtoo/ostest/setenv.sh index 420af8932..5d336813b 100755 --- a/nuttx/configs/mirtoo/ostest/setenv.sh +++ b/nuttx/configs/mirtoo/ostest/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/mirtoo/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pcblogic-pic32mx/README.txt b/nuttx/configs/pcblogic-pic32mx/README.txt index 7c109d60b..481be703c 100644 --- a/nuttx/configs/pcblogic-pic32mx/README.txt +++ b/nuttx/configs/pcblogic-pic32mx/README.txt @@ -235,14 +235,14 @@ Loading NuttX with PICkit2 file to contain physical addresses. But the nuttx.hex file generated from the top-level make will have address in the KSEG0 and KSEG1 regions. - tools/mkpichex: - --------------- + tools/pic32mx/mkpichex: + ---------------------- - There is a simple tool in the configs/pcblogic-pic32mx/tools directory - that can be used to solve both issues with the nuttx.hex file. But, - first, you must build the the tools: + There is a simple tool in the NuttX tools/pic32mx directory that can be + used to solve both issues with the nuttx.hex file. But, first, you must + build the tool: - cd configs/pcblogic-pic32mx/tools + cd tools/pic32mx make Now you will have an excecutable file call mkpichex (or mkpichex.exe on @@ -253,7 +253,7 @@ Loading NuttX with PICkit2 To use this file, you need to do the following things: . ./setenv.sh # Source setenv.sh. Among other this, this script - # will add configs/pcblogic-pic32mx/tools to your + # will add the NuttX tools/pic32mx directory to your # PATH variable make # Build nuttx and nuttx.hex mkpichex $PWD # Convert addresses in nuttx.hex. $PWD is the path diff --git a/nuttx/configs/pcblogic-pic32mx/include/board.h b/nuttx/configs/pcblogic-pic32mx/include/board.h index a47f989b7..6c0bef477 100644 --- a/nuttx/configs/pcblogic-pic32mx/include/board.h +++ b/nuttx/configs/pcblogic-pic32mx/include/board.h @@ -53,12 +53,17 @@ #define BOARD_POSC_FREQ 8000000 /* Primary OSC XTAL frequency (8MHz) */ #define BOARD_SOSC_FREQ 32768 /* Secondary OSC XTAL frequency (32.768KHz) */ + +/* Oscillator modes */ + +#define BOARD_FNOSC_POSCPLL 1 /* Use primary oscillator w/PLL */ #define BOARD_POSC_HSMODE 1 /* High-speed crystal (HS) mode */ /* PLL configuration and resulting CPU clock. * CPU_CLOCK = ((POSC_FREQ / IDIV) * MULT) / ODIV */ +#define BOARD_PLL_INPUT BOARD_POSC_FREQ #define BOARD_PLL_IDIV 2 /* PLL input divider */ #define BOARD_PLL_MULT 20 /* PLL multiplier */ #define BOARD_PLL_ODIV 1 /* PLL output divider */ diff --git a/nuttx/configs/pcblogic-pic32mx/nsh/setenv.sh b/nuttx/configs/pcblogic-pic32mx/nsh/setenv.sh index c38bb4c8f..5f8bc609b 100755 --- a/nuttx/configs/pcblogic-pic32mx/nsh/setenv.sh +++ b/nuttx/configs/pcblogic-pic32mx/nsh/setenv.sh @@ -1,8 +1,8 @@ #!/bin/bash # configs/pcblogic-pic32mx/nsh/setenv.sh # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/pcblogic-pic32mx/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pcblogic-pic32mx/ostest/setenv.sh b/nuttx/configs/pcblogic-pic32mx/ostest/setenv.sh index 254434914..1624cf8de 100755 --- a/nuttx/configs/pcblogic-pic32mx/ostest/setenv.sh +++ b/nuttx/configs/pcblogic-pic32mx/ostest/setenv.sh @@ -1,8 +1,8 @@ #!/bin/bash # configs/pcblogic-pic32mx/ostest/setenv.sh # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/pcblogic-pic32mx/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pcblogic-pic32mx/tools/Makefile b/nuttx/configs/pcblogic-pic32mx/tools/Makefile deleted file mode 100644 index 018fcaa8c..000000000 --- a/nuttx/configs/pcblogic-pic32mx/tools/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################ -# configs/pcblogic-pic32mx/tools/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -all: mkpichex -default: mkpichex -.PHONY: clean - -# Add CFLAGS=-g on the make command line to build debug versions - -CFLAGS = -O2 -Wall -I. - -# mkpichex - Convert virtual addresses in nuttx.hex to physical addresses - -mkconfig: mkpichex.c mkpichex.c - @gcc $(CFLAGS) -o mkpichex mkpichex.c - -clean: - @rm -f *.o *.a *~ .*.swp - @rm -f mkpichex mkpichex.exe diff --git a/nuttx/configs/pcblogic-pic32mx/tools/mkpichex.c b/nuttx/configs/pcblogic-pic32mx/tools/mkpichex.c deleted file mode 100644 index 3cd8c8187..000000000 --- a/nuttx/configs/pcblogic-pic32mx/tools/mkpichex.c +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** - * configs/pcblogic-pic32mx/tools/mkpichex.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_LINE 1024 - -/* Line offsets */ - -#define START_OFFSET 0 -#define LEN_OFFSET 1 -#define ADDR_OFFSET (LEN_OFFSET + 2) -#define TYPE_OFFSET (ADDR_OFFSET + 4) -#define PAYLOAD_OFFSET (TYPE_OFFSET + 2) -#define CHKSUM_OFFSET(n) (PAYLOAD_OFFSET+2*(n)) - -/* Record types: - * - * 00, data record, contains data and 16-bit address. The format described - * above. - * 01, End Of File record, a file termination record. No data. Has to be - * the last line of the file, only one per file permitted. Usually - * ':00000001FF'. Originally the End Of File record could contain a - * start address for the program being loaded, e.g. :00AB2F0125 - * would make a jump to address AB2F. This was convenient when programs - * were loaded from punched paper tape. - * 02, Extended Segment Address Record, segment-base address. Used when 16 - * bits are not enough, identical to 80x86 real mode addressing. The - * address specified by the 02 record is multiplied by 16 (shifted 4 - * bits left) and added to the subsequent 00 record addresses. This - * allows addressing of up to a megabyte of address space. The address - * field of this record has to be 0000, the byte count is 02 (the segment - * is 16-bit). The least significant hex digit of the segment address is - * always 0. - * 03, Start Segment Address Record. For 80x86 processors, it specifies the - * initial content of the CS:IP registers. The address field is 0000, the - * byte count is 04, the first two bytes are the CS value, the latter two - * are the IP value. - * 04, Extended Linear Address Record, allowing for fully 32 bit addressing. - * The address field is 0000, the byte count is 02. The two data bytes - * represent the upper 16 bits of the 32 bit address, when combined with - * the address of the 00 type record. - * 05, Start Linear Address Record. The address field is 0000, the byte - * count is 04. The 4 data bytes represent the 32-bit value loaded into - * the EIP register of the 80386 and higher CPU. - */ - -#define TYPE_DATA 0 -#define TYPE_EOF 1 -#define TYPE_EXTSEG 2 -#define TYPE_STARTSEG 3 -#define TYPE_EXTLIN 4 -#define TYPE_STARTLIN 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct hex_s -{ - unsigned char len; /* Length of the data payload */ - unsigned char type; /* Record type */ - unsigned short addr; /* Lower 16-bit address */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char line[MAX_LINE+1]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline char *getfilepath(const char *path, const char *name, const char *extension) -{ - snprintf(line, MAX_LINE, "%s/%s.%s", path, name, extension); - line[MAX_LINE] = '\0'; - return strdup(line); -} - -static void show_usage(const char *progname) -{ - fprintf(stderr, "USAGE: %s <abs path to nuttx.hex>\n", progname); - exit(1); -} - -static unsigned char get4(char hex) -{ - if (hex >= '0' && hex <= '9') - { - return hex - '0'; - } - else if (hex >= 'a' && hex <= 'f') - { - return hex - 'a' + 10; - } - else if (hex >= 'A' && hex <= 'F') - { - return hex - 'A' + 10; - } - - fprintf(stderr, "Bad hex character code: %s\n", line); - exit(2); -} - -static unsigned char get8(const char *ptr) -{ - return get4(ptr[0]) << 4 | get4(ptr[1]); -} - -static unsigned short get16(const char *ptr) -{ - return (unsigned short)get8(&ptr[0]) << 8 | (unsigned short)get8(&ptr[2]); -} - -static int parse_line(struct hex_s *hexline) -{ - /* :LLAAAATT... */ - - if (line[START_OFFSET] != ':') - { - fprintf(stderr, "Bad start code: %s\n", line); - return 1; - } - - hexline->len = get8(&line[LEN_OFFSET]); - hexline->addr = get16(&line[ADDR_OFFSET]); - hexline->type = get8(&line[TYPE_OFFSET]); - return 0; -} - -#if 0 -static unsigned char checksum(chksum_ndx) -{ - int chksum = 0; - int ndx; - - for (ndx = 1; ndx < chksum_ndx; ndx += 2) - { - chksum += (int)get8(&line[ndx]); - } - return (unsigned char)((-chksum) & 0xff); -} -#endif - -static void adjust_extlin(struct hex_s *hexline) -{ - unsigned short segment; - int chksum; - - /* Make sure that the payload is exactly 2 bytes */ - - if (hexline->len != 2) - { - fprintf(stderr, "Bad length on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* And the address field is supposed to be zero */ - - if (hexline->addr != 0) - { - fprintf(stderr, "Bad address on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* Decode the 2 byte payload */ - - segment = get16(&line[PAYLOAD_OFFSET]); - - /* Convert the address to a 29-bit physical address */ - - segment &= 0x1fff; - - /* Recalculate the checksum and make sure that there is a null terminator - * Since len=2, addr=0, type=4, the is a trivial calculation. - */ - - chksum = (-(segment + (segment >> 8) + 6)) & 0xff; - - /* Then create the new output record */ - - snprintf(line, MAX_LINE-PAYLOAD_OFFSET, ":02000004%04X%02X\n", segment, chksum); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv, char **envp) -{ - struct hex_s hexline; - char *srcfile; - char *destfile; - FILE *src; - FILE *dest; - - if (argc != 2) - { - fprintf(stderr, "Unexpected number of arguments\n"); - show_usage(argv[0]); - } - - srcfile = getfilepath(argv[1], "nuttx", "hex"); - if (!srcfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - destfile = getfilepath(argv[1], "nuttx", "tmp"); - if (!destfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - src = fopen(srcfile, "r"); - if (!src) - { - fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); - exit(3); - } - - dest = fopen(destfile, "w"); - if (!dest) - { - fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); - exit(3); - } - - /* Read each line from the source file */ - - while (fgets(line, MAX_LINE, src) != NULL) - { - if (parse_line(&hexline)) - { - fprintf(stderr, "Failed to parse line\n"); - exit(1); - } - - /* Adjust 'Extended Segment Address Records'. */ - - if (hexline.type == TYPE_EXTLIN) - { - adjust_extlin(&hexline); - } - fputs(line, dest); - } - - fclose(src); - fclose(dest); - - /* Remove the original nuttx.hex file */ - - if (remove(srcfile) != 0) - { - fprintf(stderr, "Failed to remove the old '%s'\n", srcfile); - - } - - /* Rename the new nuttx.tmp file to nuttx.hex */ - - if (rename(destfile, srcfile) != 0) - { - fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile); - } - - return 0; -} diff --git a/nuttx/configs/pic32-starterkit/README.txt b/nuttx/configs/pic32-starterkit/README.txt index a6faed486..d7e999077 100644 --- a/nuttx/configs/pic32-starterkit/README.txt +++ b/nuttx/configs/pic32-starterkit/README.txt @@ -486,14 +486,14 @@ Creating Compatible NuttX HEX files file to contain physical addresses. But the nuttx.hex file generated from the top-level make will have address in the KSEG0 and KSEG1 regions. - tools/mkpichex: - --------------- + tools/pic32mx/mkpichex: + ---------------------- - There is a simple tool in the configs/pic32-starterkit/tools directory - that can be used to solve both issues with the nuttx.hex file. But, - first, you must build the the tools: + There is a simple tool in the NuttX tools/pic32mx directory that can be + used to solve both issues with the nuttx.hex file. But, first, you must + build the tool: - cd configs/pic32-starterkit/tools + cd tools/pic32mx make Now you will have an excecutable file call mkpichex (or mkpichex.exe on @@ -504,7 +504,7 @@ Creating Compatible NuttX HEX files To use this file, you need to do the following things: . ./setenv.sh # Source setenv.sh. Among other this, this script - # will add configs/pic32-starterkit/tools to your + # will add the NuttX tools/pic32mx directory to your # PATH variable make # Build nuttx and nuttx.hex mkpichex $PWD # Convert addresses in nuttx.hex. $PWD is the path diff --git a/nuttx/configs/pic32-starterkit/include/board.h b/nuttx/configs/pic32-starterkit/include/board.h index 5b2880c77..ebe15e89b 100644 --- a/nuttx/configs/pic32-starterkit/include/board.h +++ b/nuttx/configs/pic32-starterkit/include/board.h @@ -57,12 +57,17 @@ #define BOARD_POSC_FREQ 8000000 /* Primary OSC XTAL frequency (8MHz) */ #define BOARD_SOSC_FREQ 32768 /* Secondary OSC XTAL frequency (32.768KHz) */ + +/* Oscillator modes */ + +#define BOARD_FNOSC_POSCPLL 1 /* Use primary oscillator w/PLL */ #define BOARD_POSC_HSMODE 1 /* High-speed crystal (HS) mode */ /* PLL configuration and resulting CPU clock. * CPU_CLOCK = ((POSC_FREQ / IDIV) * MULT) / ODIV */ +#define BOARD_PLL_INPUT BOARD_POSC_FREQ #define BOARD_PLL_IDIV 2 /* PLL input divider */ #define BOARD_PLL_MULT 20 /* PLL multiplier */ #define BOARD_PLL_ODIV 1 /* PLL output divider */ diff --git a/nuttx/configs/pic32-starterkit/nsh/setenv.sh b/nuttx/configs/pic32-starterkit/nsh/setenv.sh index 0a826b6ae..540ade226 100755 --- a/nuttx/configs/pic32-starterkit/nsh/setenv.sh +++ b/nuttx/configs/pic32-starterkit/nsh/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the tools subdirectory -export PIC32TOOL_DIR="${WD}/configs/pic32-starterkit/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pic32-starterkit/nsh2/setenv.sh b/nuttx/configs/pic32-starterkit/nsh2/setenv.sh index 724a0a67e..47effba5b 100755 --- a/nuttx/configs/pic32-starterkit/nsh2/setenv.sh +++ b/nuttx/configs/pic32-starterkit/nsh2/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the tools subdirectory -export PIC32TOOL_DIR="${WD}/configs/pic32-starterkit/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pic32-starterkit/ostest/setenv.sh b/nuttx/configs/pic32-starterkit/ostest/setenv.sh index 9a852dde5..4e4777ce6 100755 --- a/nuttx/configs/pic32-starterkit/ostest/setenv.sh +++ b/nuttx/configs/pic32-starterkit/ostest/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/pic32-starterkit/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pic32-starterkit/tools/Makefile b/nuttx/configs/pic32-starterkit/tools/Makefile deleted file mode 100644 index 71ec90476..000000000 --- a/nuttx/configs/pic32-starterkit/tools/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################ -# configs/pic32-starterkit/tools/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -all: mkpichex -default: mkpichex -.PHONY: clean - -# Add CFLAGS=-g on the make command line to build debug versions - -CFLAGS = -O2 -Wall -I. - -# mkpichex - Convert virtual addresses in nuttx.hex to physical addresses - -mkconfig: mkpichex.c mkpichex.c - @gcc $(CFLAGS) -o mkpichex mkpichex.c - -clean: - @rm -f *.o *.a *~ .*.swp - @rm -f mkpichex mkpichex.exe diff --git a/nuttx/configs/pic32-starterkit/tools/mkpichex.c b/nuttx/configs/pic32-starterkit/tools/mkpichex.c deleted file mode 100644 index ba7d082f9..000000000 --- a/nuttx/configs/pic32-starterkit/tools/mkpichex.c +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** - * configs/pic32-starterkit/tools/mkpichex.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_LINE 1024 - -/* Line offsets */ - -#define START_OFFSET 0 -#define LEN_OFFSET 1 -#define ADDR_OFFSET (LEN_OFFSET + 2) -#define TYPE_OFFSET (ADDR_OFFSET + 4) -#define PAYLOAD_OFFSET (TYPE_OFFSET + 2) -#define CHKSUM_OFFSET(n) (PAYLOAD_OFFSET+2*(n)) - -/* Record types: - * - * 00, data record, contains data and 16-bit address. The format described - * above. - * 01, End Of File record, a file termination record. No data. Has to be - * the last line of the file, only one per file permitted. Usually - * ':00000001FF'. Originally the End Of File record could contain a - * start address for the program being loaded, e.g. :00AB2F0125 - * would make a jump to address AB2F. This was convenient when programs - * were loaded from punched paper tape. - * 02, Extended Segment Address Record, segment-base address. Used when 16 - * bits are not enough, identical to 80x86 real mode addressing. The - * address specified by the 02 record is multiplied by 16 (shifted 4 - * bits left) and added to the subsequent 00 record addresses. This - * allows addressing of up to a megabyte of address space. The address - * field of this record has to be 0000, the byte count is 02 (the segment - * is 16-bit). The least significant hex digit of the segment address is - * always 0. - * 03, Start Segment Address Record. For 80x86 processors, it specifies the - * initial content of the CS:IP registers. The address field is 0000, the - * byte count is 04, the first two bytes are the CS value, the latter two - * are the IP value. - * 04, Extended Linear Address Record, allowing for fully 32 bit addressing. - * The address field is 0000, the byte count is 02. The two data bytes - * represent the upper 16 bits of the 32 bit address, when combined with - * the address of the 00 type record. - * 05, Start Linear Address Record. The address field is 0000, the byte - * count is 04. The 4 data bytes represent the 32-bit value loaded into - * the EIP register of the 80386 and higher CPU. - */ - -#define TYPE_DATA 0 -#define TYPE_EOF 1 -#define TYPE_EXTSEG 2 -#define TYPE_STARTSEG 3 -#define TYPE_EXTLIN 4 -#define TYPE_STARTLIN 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct hex_s -{ - unsigned char len; /* Length of the data payload */ - unsigned char type; /* Record type */ - unsigned short addr; /* Lower 16-bit address */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char line[MAX_LINE+1]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline char *getfilepath(const char *path, const char *name, const char *extension) -{ - snprintf(line, MAX_LINE, "%s/%s.%s", path, name, extension); - line[MAX_LINE] = '\0'; - return strdup(line); -} - -static void show_usage(const char *progname) -{ - fprintf(stderr, "USAGE: %s <abs path to nuttx.hex>\n", progname); - exit(1); -} - -static unsigned char get4(char hex) -{ - if (hex >= '0' && hex <= '9') - { - return hex - '0'; - } - else if (hex >= 'a' && hex <= 'f') - { - return hex - 'a' + 10; - } - else if (hex >= 'A' && hex <= 'F') - { - return hex - 'A' + 10; - } - - fprintf(stderr, "Bad hex character code: %s\n", line); - exit(2); -} - -static unsigned char get8(const char *ptr) -{ - return get4(ptr[0]) << 4 | get4(ptr[1]); -} - -static unsigned short get16(const char *ptr) -{ - return (unsigned short)get8(&ptr[0]) << 8 | (unsigned short)get8(&ptr[2]); -} - -static int parse_line(struct hex_s *hexline) -{ - /* :LLAAAATT... */ - - if (line[START_OFFSET] != ':') - { - fprintf(stderr, "Bad start code: %s\n", line); - return 1; - } - - hexline->len = get8(&line[LEN_OFFSET]); - hexline->addr = get16(&line[ADDR_OFFSET]); - hexline->type = get8(&line[TYPE_OFFSET]); - return 0; -} - -#if 0 -static unsigned char checksum(chksum_ndx) -{ - int chksum = 0; - int ndx; - - for (ndx = 1; ndx < chksum_ndx; ndx += 2) - { - chksum += (int)get8(&line[ndx]); - } - return (unsigned char)((-chksum) & 0xff); -} -#endif - -static void adjust_extlin(struct hex_s *hexline) -{ - unsigned short segment; - int chksum; - - /* Make sure that the payload is exactly 2 bytes */ - - if (hexline->len != 2) - { - fprintf(stderr, "Bad length on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* And the address field is supposed to be zero */ - - if (hexline->addr != 0) - { - fprintf(stderr, "Bad address on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* Decode the 2 byte payload */ - - segment = get16(&line[PAYLOAD_OFFSET]); - - /* Convert the address to a 29-bit physical address */ - - segment &= 0x1fff; - - /* Recalculate the checksum and make sure that there is a null terminator - * Since len=2, addr=0, type=4, the is a trivial calculation. - */ - - chksum = (-(segment + (segment >> 8) + 6)) & 0xff; - - /* Then create the new output record */ - - snprintf(line, MAX_LINE-PAYLOAD_OFFSET, ":02000004%04X%02X\n", segment, chksum); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv, char **envp) -{ - struct hex_s hexline; - char *srcfile; - char *destfile; - FILE *src; - FILE *dest; - - if (argc != 2) - { - fprintf(stderr, "Unexpected number of arguments\n"); - show_usage(argv[0]); - } - - srcfile = getfilepath(argv[1], "nuttx", "hex"); - if (!srcfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - destfile = getfilepath(argv[1], "nuttx", "tmp"); - if (!destfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - src = fopen(srcfile, "r"); - if (!src) - { - fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); - exit(3); - } - - dest = fopen(destfile, "w"); - if (!dest) - { - fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); - exit(3); - } - - /* Read each line from the source file */ - - while (fgets(line, MAX_LINE, src) != NULL) - { - if (parse_line(&hexline)) - { - fprintf(stderr, "Failed to parse line\n"); - exit(1); - } - - /* Adjust 'Extended Segment Address Records'. */ - - if (hexline.type == TYPE_EXTLIN) - { - adjust_extlin(&hexline); - } - fputs(line, dest); - } - - fclose(src); - fclose(dest); - - /* Remove the original nuttx.hex file */ - - if (remove(srcfile) != 0) - { - fprintf(stderr, "Failed to remove the old '%s'\n", srcfile); - - } - - /* Rename the new nuttx.tmp file to nuttx.hex */ - - if (rename(destfile, srcfile) != 0) - { - fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile); - } - - return 0; -} diff --git a/nuttx/configs/pic32mx7mmb/README.txt b/nuttx/configs/pic32mx7mmb/README.txt index 949a5c31d..e4cbd3952 100644 --- a/nuttx/configs/pic32mx7mmb/README.txt +++ b/nuttx/configs/pic32mx7mmb/README.txt @@ -221,14 +221,14 @@ Creating Compatible NuttX HEX files file to contain physical addresses. But the nuttx.hex file generated from the top-level make will have address in the KSEG0 and KSEG1 regions. - tools/mkpichex: - --------------- + tools/pic32mx/mkpichex: + ---------------------- - There is a simple tool in the configs/pic32mx7mmb/tools directory - that can be used to solve both issues with the nuttx.hex file. But, - first, you must build the the tools: + There is a simple tool in the NuttX tools/pic32mx directory that can be + used to solve both issues with the nuttx.hex file. But, first, you must + build the tool: - cd configs/pic32mx7mmb/tools + cd tools/pic32mx make Now you will have an excecutable file call mkpichex (or mkpichex.exe on @@ -239,7 +239,7 @@ Creating Compatible NuttX HEX files To use this file, you need to do the following things: . ./setenv.sh # Source setenv.sh. Among other this, this script - # will add configs/pic32mx7mmb/tools to your + # will add the NuttX tools/pic32mx directory to your # PATH variable make # Build nuttx and nuttx.hex mkpichex $PWD # Convert addresses in nuttx.hex. $PWD is the path diff --git a/nuttx/configs/pic32mx7mmb/include/board.h b/nuttx/configs/pic32mx7mmb/include/board.h index c4bf715e4..41f105b50 100644 --- a/nuttx/configs/pic32mx7mmb/include/board.h +++ b/nuttx/configs/pic32mx7mmb/include/board.h @@ -58,8 +58,9 @@ #define BOARD_POSC_FREQ 8000000 /* Primary OSC XTAL frequency (8MHz) */ #define BOARD_SOSC_FREQ 32768 /* Secondary OSC XTAL frequency (32.768KHz) */ -/* Clock modes */ +/* Oscillator modes */ +#define BOARD_FNOSC_POSCPLL 1 /* Use primary oscillator w/PLL */ #define BOARD_POSC_XTMODE 1 /* Resonator, crystal or resonator (XT) mode */ #undef BOARD_POSC_SWITCH /* Use FRC until POSC stabilizes, then switch */ #undef BOARD_POSC_FSCM /* Switch to FRC if POSC fails */ @@ -70,6 +71,7 @@ * CPU_CLOCK = ((POSC_FREQ / IDIV) * MULT) / ODIV */ +#define BOARD_PLL_INPUT BOARD_POSC_FREQ #define BOARD_PLL_IDIV 2 /* PLL input divider */ #define BOARD_PLL_MULT 20 /* PLL multiplier */ #define BOARD_PLL_ODIV 1 /* PLL output divider */ diff --git a/nuttx/configs/pic32mx7mmb/nsh/setenv.sh b/nuttx/configs/pic32mx7mmb/nsh/setenv.sh index 97c96a2f7..aefb891cf 100755 --- a/nuttx/configs/pic32mx7mmb/nsh/setenv.sh +++ b/nuttx/configs/pic32mx7mmb/nsh/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the tools subdirectory -export PIC32TOOL_DIR="${WD}/configs/pic32mx7mmb/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH variable export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pic32mx7mmb/ostest/setenv.sh b/nuttx/configs/pic32mx7mmb/ostest/setenv.sh index 3ddaaa44b..a960d4b7c 100755 --- a/nuttx/configs/pic32mx7mmb/ostest/setenv.sh +++ b/nuttx/configs/pic32mx7mmb/ostest/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the tools subdirectory -export PIC32TOOL_DIR="${WD}/configs/pic32mx7mmb/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH variable export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/pic32mx7mmb/tools/Makefile b/nuttx/configs/pic32mx7mmb/tools/Makefile deleted file mode 100644 index e29f6184d..000000000 --- a/nuttx/configs/pic32mx7mmb/tools/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################ -# configs/pic32mx7mmb/tools/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -all: mkpichex -default: mkpichex -.PHONY: clean - -# Add CFLAGS=-g on the make command line to build debug versions - -CFLAGS = -O2 -Wall -I. - -# mkpichex - Convert virtual addresses in nuttx.hex to physical addresses - -mkconfig: mkpichex.c mkpichex.c - @gcc $(CFLAGS) -o mkpichex mkpichex.c - -clean: - @rm -f *.o *.a *~ .*.swp - @rm -f mkpichex mkpichex.exe diff --git a/nuttx/configs/pic32mx7mmb/tools/mkpichex.c b/nuttx/configs/pic32mx7mmb/tools/mkpichex.c deleted file mode 100644 index a9d79801e..000000000 --- a/nuttx/configs/pic32mx7mmb/tools/mkpichex.c +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** - * configs/pic32mx7mmb/tools/mkpichex.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_LINE 1024 - -/* Line offsets */ - -#define START_OFFSET 0 -#define LEN_OFFSET 1 -#define ADDR_OFFSET (LEN_OFFSET + 2) -#define TYPE_OFFSET (ADDR_OFFSET + 4) -#define PAYLOAD_OFFSET (TYPE_OFFSET + 2) -#define CHKSUM_OFFSET(n) (PAYLOAD_OFFSET+2*(n)) - -/* Record types: - * - * 00, data record, contains data and 16-bit address. The format described - * above. - * 01, End Of File record, a file termination record. No data. Has to be - * the last line of the file, only one per file permitted. Usually - * ':00000001FF'. Originally the End Of File record could contain a - * start address for the program being loaded, e.g. :00AB2F0125 - * would make a jump to address AB2F. This was convenient when programs - * were loaded from punched paper tape. - * 02, Extended Segment Address Record, segment-base address. Used when 16 - * bits are not enough, identical to 80x86 real mode addressing. The - * address specified by the 02 record is multiplied by 16 (shifted 4 - * bits left) and added to the subsequent 00 record addresses. This - * allows addressing of up to a megabyte of address space. The address - * field of this record has to be 0000, the byte count is 02 (the segment - * is 16-bit). The least significant hex digit of the segment address is - * always 0. - * 03, Start Segment Address Record. For 80x86 processors, it specifies the - * initial content of the CS:IP registers. The address field is 0000, the - * byte count is 04, the first two bytes are the CS value, the latter two - * are the IP value. - * 04, Extended Linear Address Record, allowing for fully 32 bit addressing. - * The address field is 0000, the byte count is 02. The two data bytes - * represent the upper 16 bits of the 32 bit address, when combined with - * the address of the 00 type record. - * 05, Start Linear Address Record. The address field is 0000, the byte - * count is 04. The 4 data bytes represent the 32-bit value loaded into - * the EIP register of the 80386 and higher CPU. - */ - -#define TYPE_DATA 0 -#define TYPE_EOF 1 -#define TYPE_EXTSEG 2 -#define TYPE_STARTSEG 3 -#define TYPE_EXTLIN 4 -#define TYPE_STARTLIN 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct hex_s -{ - unsigned char len; /* Length of the data payload */ - unsigned char type; /* Record type */ - unsigned short addr; /* Lower 16-bit address */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char line[MAX_LINE+1]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline char *getfilepath(const char *path, const char *name, const char *extension) -{ - snprintf(line, MAX_LINE, "%s/%s.%s", path, name, extension); - line[MAX_LINE] = '\0'; - return strdup(line); -} - -static void show_usage(const char *progname) -{ - fprintf(stderr, "USAGE: %s <abs path to nuttx.hex>\n", progname); - exit(1); -} - -static unsigned char get4(char hex) -{ - if (hex >= '0' && hex <= '9') - { - return hex - '0'; - } - else if (hex >= 'a' && hex <= 'f') - { - return hex - 'a' + 10; - } - else if (hex >= 'A' && hex <= 'F') - { - return hex - 'A' + 10; - } - - fprintf(stderr, "Bad hex character code: %s\n", line); - exit(2); -} - -static unsigned char get8(const char *ptr) -{ - return get4(ptr[0]) << 4 | get4(ptr[1]); -} - -static unsigned short get16(const char *ptr) -{ - return (unsigned short)get8(&ptr[0]) << 8 | (unsigned short)get8(&ptr[2]); -} - -static int parse_line(struct hex_s *hexline) -{ - /* :LLAAAATT... */ - - if (line[START_OFFSET] != ':') - { - fprintf(stderr, "Bad start code: %s\n", line); - return 1; - } - - hexline->len = get8(&line[LEN_OFFSET]); - hexline->addr = get16(&line[ADDR_OFFSET]); - hexline->type = get8(&line[TYPE_OFFSET]); - return 0; -} - -#if 0 -static unsigned char checksum(chksum_ndx) -{ - int chksum = 0; - int ndx; - - for (ndx = 1; ndx < chksum_ndx; ndx += 2) - { - chksum += (int)get8(&line[ndx]); - } - return (unsigned char)((-chksum) & 0xff); -} -#endif - -static void adjust_extlin(struct hex_s *hexline) -{ - unsigned short segment; - int chksum; - - /* Make sure that the payload is exactly 2 bytes */ - - if (hexline->len != 2) - { - fprintf(stderr, "Bad length on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* And the address field is supposed to be zero */ - - if (hexline->addr != 0) - { - fprintf(stderr, "Bad address on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* Decode the 2 byte payload */ - - segment = get16(&line[PAYLOAD_OFFSET]); - - /* Convert the address to a 29-bit physical address */ - - segment &= 0x1fff; - - /* Recalculate the checksum and make sure that there is a null terminator - * Since len=2, addr=0, type=4, the is a trivial calculation. - */ - - chksum = (-(segment + (segment >> 8) + 6)) & 0xff; - - /* Then create the new output record */ - - snprintf(line, MAX_LINE-PAYLOAD_OFFSET, ":02000004%04X%02X\n", segment, chksum); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv, char **envp) -{ - struct hex_s hexline; - char *srcfile; - char *destfile; - FILE *src; - FILE *dest; - - if (argc != 2) - { - fprintf(stderr, "Unexpected number of arguments\n"); - show_usage(argv[0]); - } - - srcfile = getfilepath(argv[1], "nuttx", "hex"); - if (!srcfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - destfile = getfilepath(argv[1], "nuttx", "tmp"); - if (!destfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - src = fopen(srcfile, "r"); - if (!src) - { - fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); - exit(3); - } - - dest = fopen(destfile, "w"); - if (!dest) - { - fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); - exit(3); - } - - /* Read each line from the source file */ - - while (fgets(line, MAX_LINE, src) != NULL) - { - if (parse_line(&hexline)) - { - fprintf(stderr, "Failed to parse line\n"); - exit(1); - } - - /* Adjust 'Extended Segment Address Records'. */ - - if (hexline.type == TYPE_EXTLIN) - { - adjust_extlin(&hexline); - } - fputs(line, dest); - } - - fclose(src); - fclose(dest); - - /* Remove the original nuttx.hex file */ - - if (remove(srcfile) != 0) - { - fprintf(stderr, "Failed to remove the old '%s'\n", srcfile); - - } - - /* Rename the new nuttx.tmp file to nuttx.hex */ - - if (rename(destfile, srcfile) != 0) - { - fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile); - } - - return 0; -} diff --git a/nuttx/configs/sure-pic32mx/README.txt b/nuttx/configs/sure-pic32mx/README.txt index 79ac31392..72c578bf2 100644 --- a/nuttx/configs/sure-pic32mx/README.txt +++ b/nuttx/configs/sure-pic32mx/README.txt @@ -301,14 +301,14 @@ Loading NuttX with PICkit2 file to contain physical addresses. But the nuttx.hex file generated from the top-level make will have address in the KSEG0 and KSEG1 regions. - tools/mkpichex: - --------------- + tools/pic32mx/mkpichex: + ---------------------- - There is a simple tool in the configs/sure-pic32mx/tools directory - that can be used to solve both issues with the nuttx.hex file. But, - first, you must build the the tools: + There is a simple tool in the NuttX tools/pic32mx directory that can be + used to solve both issues with the nuttx.hex file. But, first, you must + build the tool: - cd configs/sure-pic32mx/tools + cd tools/pic32mx make Now you will have an excecutable file call mkpichex (or mkpichex.exe on @@ -319,7 +319,7 @@ Loading NuttX with PICkit2 To use this file, you need to do the following things: . ./setenv.sh # Source setenv.sh. Among other this, this script - # will add configs/sure-pic32mx/tools to your + # will add the NuttX tools/pic32mx directory to your # PATH variable make # Build nuttx and nuttx.hex mkpichex $PWD # Convert addresses in nuttx.hex. $PWD is the path diff --git a/nuttx/configs/sure-pic32mx/include/board.h b/nuttx/configs/sure-pic32mx/include/board.h index 7521c694e..3b4d7f798 100644 --- a/nuttx/configs/sure-pic32mx/include/board.h +++ b/nuttx/configs/sure-pic32mx/include/board.h @@ -53,12 +53,17 @@ #define BOARD_POSC_FREQ 20000000 /* Primary OSC XTAL frequency (20MHz) */ #define BOARD_SOSC_FREQ 32768 /* Secondary OSC XTAL frequency (32.768KHz) */ + +/* Oscillator modes */ + +#define BOARD_FNOSC_POSCPLL 1 /* Use primary oscillator w/PLL */ #define BOARD_POSC_HSMODE 1 /* High-speed crystal (HS) mode */ /* PLL configuration and resulting CPU clock. * CPU_CLOCK = ((POSC_FREQ / IDIV) * MULT) / ODIV */ +#define BOARD_PLL_INPUT BOARD_POSC_FREQ #define BOARD_PLL_IDIV 5 /* PLL input divider */ #define BOARD_PLL_MULT 15 /* PLL multiplier */ #define BOARD_PLL_ODIV 1 /* PLL output divider */ diff --git a/nuttx/configs/sure-pic32mx/nsh/setenv.sh b/nuttx/configs/sure-pic32mx/nsh/setenv.sh index f0fc42838..8c4df233b 100755 --- a/nuttx/configs/sure-pic32mx/nsh/setenv.sh +++ b/nuttx/configs/sure-pic32mx/nsh/setenv.sh @@ -1,7 +1,7 @@ #!/bin/bash # configs/sure-pic32mx/nsh/setenv.sh # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/sure-pic32mx/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/sure-pic32mx/ostest/setenv.sh b/nuttx/configs/sure-pic32mx/ostest/setenv.sh index 841aa7d82..b26ea960e 100755 --- a/nuttx/configs/sure-pic32mx/ostest/setenv.sh +++ b/nuttx/configs/sure-pic32mx/ostest/setenv.sh @@ -1,8 +1,8 @@ #!/bin/bash # configs/sure-pic32mx/ostest/setenv.sh # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/sure-pic32mx/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/sure-pic32mx/tools/Makefile b/nuttx/configs/sure-pic32mx/tools/Makefile deleted file mode 100644 index b9474a4fc..000000000 --- a/nuttx/configs/sure-pic32mx/tools/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################ -# configs/sure-pic32mx/tools/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -all: mkpichex -default: mkpichex -.PHONY: clean - -# Add CFLAGS=-g on the make command line to build debug versions - -CFLAGS = -O2 -Wall -I. - -# mkpichex - Convert virtual addresses in nuttx.hex to physical addresses - -mkconfig: mkpichex.c mkpichex.c - @gcc $(CFLAGS) -o mkpichex mkpichex.c - -clean: - @rm -f *.o *.a *~ .*.swp - @rm -f mkpichex mkpichex.exe diff --git a/nuttx/configs/sure-pic32mx/tools/mkpichex.c b/nuttx/configs/sure-pic32mx/tools/mkpichex.c deleted file mode 100644 index 70de368bd..000000000 --- a/nuttx/configs/sure-pic32mx/tools/mkpichex.c +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** - * configs/sure-pic32mx/tools/mkpichex.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_LINE 1024 - -/* Line offsets */ - -#define START_OFFSET 0 -#define LEN_OFFSET 1 -#define ADDR_OFFSET (LEN_OFFSET + 2) -#define TYPE_OFFSET (ADDR_OFFSET + 4) -#define PAYLOAD_OFFSET (TYPE_OFFSET + 2) -#define CHKSUM_OFFSET(n) (PAYLOAD_OFFSET+2*(n)) - -/* Record types: - * - * 00, data record, contains data and 16-bit address. The format described - * above. - * 01, End Of File record, a file termination record. No data. Has to be - * the last line of the file, only one per file permitted. Usually - * ':00000001FF'. Originally the End Of File record could contain a - * start address for the program being loaded, e.g. :00AB2F0125 - * would make a jump to address AB2F. This was convenient when programs - * were loaded from punched paper tape. - * 02, Extended Segment Address Record, segment-base address. Used when 16 - * bits are not enough, identical to 80x86 real mode addressing. The - * address specified by the 02 record is multiplied by 16 (shifted 4 - * bits left) and added to the subsequent 00 record addresses. This - * allows addressing of up to a megabyte of address space. The address - * field of this record has to be 0000, the byte count is 02 (the segment - * is 16-bit). The least significant hex digit of the segment address is - * always 0. - * 03, Start Segment Address Record. For 80x86 processors, it specifies the - * initial content of the CS:IP registers. The address field is 0000, the - * byte count is 04, the first two bytes are the CS value, the latter two - * are the IP value. - * 04, Extended Linear Address Record, allowing for fully 32 bit addressing. - * The address field is 0000, the byte count is 02. The two data bytes - * represent the upper 16 bits of the 32 bit address, when combined with - * the address of the 00 type record. - * 05, Start Linear Address Record. The address field is 0000, the byte - * count is 04. The 4 data bytes represent the 32-bit value loaded into - * the EIP register of the 80386 and higher CPU. - */ - -#define TYPE_DATA 0 -#define TYPE_EOF 1 -#define TYPE_EXTSEG 2 -#define TYPE_STARTSEG 3 -#define TYPE_EXTLIN 4 -#define TYPE_STARTLIN 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct hex_s -{ - unsigned char len; /* Length of the data payload */ - unsigned char type; /* Record type */ - unsigned short addr; /* Lower 16-bit address */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char line[MAX_LINE+1]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline char *getfilepath(const char *path, const char *name, const char *extension) -{ - snprintf(line, MAX_LINE, "%s/%s.%s", path, name, extension); - line[MAX_LINE] = '\0'; - return strdup(line); -} - -static void show_usage(const char *progname) -{ - fprintf(stderr, "USAGE: %s <abs path to nuttx.hex>\n", progname); - exit(1); -} - -static unsigned char get4(char hex) -{ - if (hex >= '0' && hex <= '9') - { - return hex - '0'; - } - else if (hex >= 'a' && hex <= 'f') - { - return hex - 'a' + 10; - } - else if (hex >= 'A' && hex <= 'F') - { - return hex - 'A' + 10; - } - - fprintf(stderr, "Bad hex character code: %s\n", line); - exit(2); -} - -static unsigned char get8(const char *ptr) -{ - return get4(ptr[0]) << 4 | get4(ptr[1]); -} - -static unsigned short get16(const char *ptr) -{ - return (unsigned short)get8(&ptr[0]) << 8 | (unsigned short)get8(&ptr[2]); -} - -static int parse_line(struct hex_s *hexline) -{ - /* :LLAAAATT... */ - - if (line[START_OFFSET] != ':') - { - fprintf(stderr, "Bad start code: %s\n", line); - return 1; - } - - hexline->len = get8(&line[LEN_OFFSET]); - hexline->addr = get16(&line[ADDR_OFFSET]); - hexline->type = get8(&line[TYPE_OFFSET]); - return 0; -} - -#if 0 -static unsigned char checksum(chksum_ndx) -{ - int chksum = 0; - int ndx; - - for (ndx = 1; ndx < chksum_ndx; ndx += 2) - { - chksum += (int)get8(&line[ndx]); - } - return (unsigned char)((-chksum) & 0xff); -} -#endif - -static void adjust_extlin(struct hex_s *hexline) -{ - unsigned short segment; - int chksum; - - /* Make sure that the payload is exactly 2 bytes */ - - if (hexline->len != 2) - { - fprintf(stderr, "Bad length on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* And the address field is supposed to be zero */ - - if (hexline->addr != 0) - { - fprintf(stderr, "Bad address on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* Decode the 2 byte payload */ - - segment = get16(&line[PAYLOAD_OFFSET]); - - /* Convert the address to a 29-bit physical address */ - - segment &= 0x1fff; - - /* Recalculate the checksum and make sure that there is a null terminator - * Since len=2, addr=0, type=4, the is a trivial calculation. - */ - - chksum = (-(segment + (segment >> 8) + 6)) & 0xff; - - /* Then create the new output record */ - - snprintf(line, MAX_LINE-PAYLOAD_OFFSET, ":02000004%04X%02X\n", segment, chksum); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv, char **envp) -{ - struct hex_s hexline; - char *srcfile; - char *destfile; - FILE *src; - FILE *dest; - - if (argc != 2) - { - fprintf(stderr, "Unexpected number of arguments\n"); - show_usage(argv[0]); - } - - srcfile = getfilepath(argv[1], "nuttx", "hex"); - if (!srcfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - destfile = getfilepath(argv[1], "nuttx", "tmp"); - if (!destfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - src = fopen(srcfile, "r"); - if (!src) - { - fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); - exit(3); - } - - dest = fopen(destfile, "w"); - if (!dest) - { - fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); - exit(3); - } - - /* Read each line from the source file */ - - while (fgets(line, MAX_LINE, src) != NULL) - { - if (parse_line(&hexline)) - { - fprintf(stderr, "Failed to parse line\n"); - exit(1); - } - - /* Adjust 'Extended Segment Address Records'. */ - - if (hexline.type == TYPE_EXTLIN) - { - adjust_extlin(&hexline); - } - fputs(line, dest); - } - - fclose(src); - fclose(dest); - - /* Remove the original nuttx.hex file */ - - if (remove(srcfile) != 0) - { - fprintf(stderr, "Failed to remove the old '%s'\n", srcfile); - - } - - /* Rename the new nuttx.tmp file to nuttx.hex */ - - if (rename(destfile, srcfile) != 0) - { - fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile); - } - - return 0; -} diff --git a/nuttx/configs/sure-pic32mx/usbnsh/setenv.sh b/nuttx/configs/sure-pic32mx/usbnsh/setenv.sh index 23df1f856..263dfc596 100755 --- a/nuttx/configs/sure-pic32mx/usbnsh/setenv.sh +++ b/nuttx/configs/sure-pic32mx/usbnsh/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/sure-pic32mx/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/ubw32/README.txt b/nuttx/configs/ubw32/README.txt index 1d3362a51..c60f8eccd 100644 --- a/nuttx/configs/ubw32/README.txt +++ b/nuttx/configs/ubw32/README.txt @@ -245,14 +245,14 @@ Loading NuttX with PICkit2 file to contain physical addresses. But the nuttx.hex file generated from the top-level make will have address in the KSEG0 and KSEG1 regions. - tools/mkpichex: - --------------- + tools/pic32mx/mkpichex: + ---------------------- - There is a simple tool in the configs/ubw32/tools directory - that can be used to solve both issues with the nuttx.hex file. But, - first, you must build the the tools: + There is a simple tool in the NuttX tools/pic32mx directory that can be + used to solve both issues with the nuttx.hex file. But, first, you must + build the tool: - cd configs/ubw32/tools + cd tools/pic32mx make Now you will have an excecutable file call mkpichex (or mkpichex.exe on @@ -263,7 +263,7 @@ Loading NuttX with PICkit2 To use this file, you need to do the following things: . ./setenv.sh # Source setenv.sh. Among other this, this script - # will add configs/ubw32/tools to your + # will add the NuttX tools/pic32mx directory to your # PATH variable make # Build nuttx and nuttx.hex mkpichex $PWD # Convert addresses in nuttx.hex. $PWD is the path diff --git a/nuttx/configs/ubw32/include/board.h b/nuttx/configs/ubw32/include/board.h index da8ecc50c..63869cc5f 100644 --- a/nuttx/configs/ubw32/include/board.h +++ b/nuttx/configs/ubw32/include/board.h @@ -54,12 +54,17 @@ #define BOARD_POSC_FREQ 8000000 /* Primary OSC XTAL frequency (8MHz) */ #define BOARD_SOSC_FREQ 32768 /* Secondary OSC XTAL frequency (32.768KHz) * (Not present on my board) */ + +/* Oscillator modes */ + +#define BOARD_FNOSC_POSCPLL 1 /* Use primary oscillator w/PLL */ #define BOARD_POSC_HSMODE 1 /* High-speed crystal (HS) mode */ /* PLL configuration and resulting CPU clock. * CPU_CLOCK = ((POSC_FREQ / IDIV) * MULT) / ODIV */ +#define BOARD_PLL_INPUT BOARD_POSC_FREQ #define BOARD_PLL_IDIV 2 /* PLL input divider */ #define BOARD_PLL_MULT 20 /* PLL multiplier */ #define BOARD_PLL_ODIV 1 /* PLL output divider */ diff --git a/nuttx/configs/ubw32/nsh/setenv.sh b/nuttx/configs/ubw32/nsh/setenv.sh index 853574b6e..26946b1bb 100755 --- a/nuttx/configs/ubw32/nsh/setenv.sh +++ b/nuttx/configs/ubw32/nsh/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/ubw32/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/ubw32/ostest/setenv.sh b/nuttx/configs/ubw32/ostest/setenv.sh index b1ba2e9b0..6123ce6ba 100755 --- a/nuttx/configs/ubw32/ostest/setenv.sh +++ b/nuttx/configs/ubw32/ostest/setenv.sh @@ -53,7 +53,7 @@ fi export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin" # This is the path to the toosl subdirectory -export PIC32TOOL_DIR="${WD}/configs/ubw32/tools" +export PIC32TOOL_DIR="${WD}/tools/pic32mx" # Add the path to the toolchain to the PATH varialble export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}" diff --git a/nuttx/configs/ubw32/tools/Makefile b/nuttx/configs/ubw32/tools/Makefile deleted file mode 100644 index 8282ae530..000000000 --- a/nuttx/configs/ubw32/tools/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################ -# configs/ubw32/tools/Makefile -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -all: mkpichex -default: mkpichex -.PHONY: clean - -# Add CFLAGS=-g on the make command line to build debug versions - -CFLAGS = -O2 -Wall -I. - -# mkpichex - Convert virtual addresses in nuttx.hex to physical addresses - -mkconfig: mkpichex.c mkpichex.c - @gcc $(CFLAGS) -o mkpichex mkpichex.c - -clean: - @rm -f *.o *.a *~ .*.swp - @rm -f mkpichex mkpichex.exe diff --git a/nuttx/configs/ubw32/tools/mkpichex.c b/nuttx/configs/ubw32/tools/mkpichex.c deleted file mode 100644 index 9f2f0127b..000000000 --- a/nuttx/configs/ubw32/tools/mkpichex.c +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** - * configs/ubw32/tools/mkpichex.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_LINE 1024 - -/* Line offsets */ - -#define START_OFFSET 0 -#define LEN_OFFSET 1 -#define ADDR_OFFSET (LEN_OFFSET + 2) -#define TYPE_OFFSET (ADDR_OFFSET + 4) -#define PAYLOAD_OFFSET (TYPE_OFFSET + 2) -#define CHKSUM_OFFSET(n) (PAYLOAD_OFFSET+2*(n)) - -/* Record types: - * - * 00, data record, contains data and 16-bit address. The format described - * above. - * 01, End Of File record, a file termination record. No data. Has to be - * the last line of the file, only one per file permitted. Usually - * ':00000001FF'. Originally the End Of File record could contain a - * start address for the program being loaded, e.g. :00AB2F0125 - * would make a jump to address AB2F. This was convenient when programs - * were loaded from punched paper tape. - * 02, Extended Segment Address Record, segment-base address. Used when 16 - * bits are not enough, identical to 80x86 real mode addressing. The - * address specified by the 02 record is multiplied by 16 (shifted 4 - * bits left) and added to the subsequent 00 record addresses. This - * allows addressing of up to a megabyte of address space. The address - * field of this record has to be 0000, the byte count is 02 (the segment - * is 16-bit). The least significant hex digit of the segment address is - * always 0. - * 03, Start Segment Address Record. For 80x86 processors, it specifies the - * initial content of the CS:IP registers. The address field is 0000, the - * byte count is 04, the first two bytes are the CS value, the latter two - * are the IP value. - * 04, Extended Linear Address Record, allowing for fully 32 bit addressing. - * The address field is 0000, the byte count is 02. The two data bytes - * represent the upper 16 bits of the 32 bit address, when combined with - * the address of the 00 type record. - * 05, Start Linear Address Record. The address field is 0000, the byte - * count is 04. The 4 data bytes represent the 32-bit value loaded into - * the EIP register of the 80386 and higher CPU. - */ - -#define TYPE_DATA 0 -#define TYPE_EOF 1 -#define TYPE_EXTSEG 2 -#define TYPE_STARTSEG 3 -#define TYPE_EXTLIN 4 -#define TYPE_STARTLIN 5 - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct hex_s -{ - unsigned char len; /* Length of the data payload */ - unsigned char type; /* Record type */ - unsigned short addr; /* Lower 16-bit address */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char line[MAX_LINE+1]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline char *getfilepath(const char *path, const char *name, const char *extension) -{ - snprintf(line, MAX_LINE, "%s/%s.%s", path, name, extension); - line[MAX_LINE] = '\0'; - return strdup(line); -} - -static void show_usage(const char *progname) -{ - fprintf(stderr, "USAGE: %s <abs path to nuttx.hex>\n", progname); - exit(1); -} - -static unsigned char get4(char hex) -{ - if (hex >= '0' && hex <= '9') - { - return hex - '0'; - } - else if (hex >= 'a' && hex <= 'f') - { - return hex - 'a' + 10; - } - else if (hex >= 'A' && hex <= 'F') - { - return hex - 'A' + 10; - } - - fprintf(stderr, "Bad hex character code: %s\n", line); - exit(2); -} - -static unsigned char get8(const char *ptr) -{ - return get4(ptr[0]) << 4 | get4(ptr[1]); -} - -static unsigned short get16(const char *ptr) -{ - return (unsigned short)get8(&ptr[0]) << 8 | (unsigned short)get8(&ptr[2]); -} - -static int parse_line(struct hex_s *hexline) -{ - /* :LLAAAATT... */ - - if (line[START_OFFSET] != ':') - { - fprintf(stderr, "Bad start code: %s\n", line); - return 1; - } - - hexline->len = get8(&line[LEN_OFFSET]); - hexline->addr = get16(&line[ADDR_OFFSET]); - hexline->type = get8(&line[TYPE_OFFSET]); - return 0; -} - -#if 0 -static unsigned char checksum(chksum_ndx) -{ - int chksum = 0; - int ndx; - - for (ndx = 1; ndx < chksum_ndx; ndx += 2) - { - chksum += (int)get8(&line[ndx]); - } - return (unsigned char)((-chksum) & 0xff); -} -#endif - -static void adjust_extlin(struct hex_s *hexline) -{ - unsigned short segment; - int chksum; - - /* Make sure that the payload is exactly 2 bytes */ - - if (hexline->len != 2) - { - fprintf(stderr, "Bad length on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* And the address field is supposed to be zero */ - - if (hexline->addr != 0) - { - fprintf(stderr, "Bad address on extended segment address record\n"); - fprintf(stderr, " %s", line); - } - - /* Decode the 2 byte payload */ - - segment = get16(&line[PAYLOAD_OFFSET]); - - /* Convert the address to a 29-bit physical address */ - - segment &= 0x1fff; - - /* Recalculate the checksum and make sure that there is a null terminator - * Since len=2, addr=0, type=4, the is a trivial calculation. - */ - - chksum = (-(segment + (segment >> 8) + 6)) & 0xff; - - /* Then create the new output record */ - - snprintf(line, MAX_LINE-PAYLOAD_OFFSET, ":02000004%04X%02X\n", segment, chksum); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int main(int argc, char **argv, char **envp) -{ - struct hex_s hexline; - char *srcfile; - char *destfile; - FILE *src; - FILE *dest; - - if (argc != 2) - { - fprintf(stderr, "Unexpected number of arguments\n"); - show_usage(argv[0]); - } - - srcfile = getfilepath(argv[1], "nuttx", "hex"); - if (!srcfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - destfile = getfilepath(argv[1], "nuttx", "tmp"); - if (!destfile) - { - fprintf(stderr, "getfilepath failed\n"); - exit(2); - } - - src = fopen(srcfile, "r"); - if (!src) - { - fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); - exit(3); - } - - dest = fopen(destfile, "w"); - if (!dest) - { - fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); - exit(3); - } - - /* Read each line from the source file */ - - while (fgets(line, MAX_LINE, src) != NULL) - { - if (parse_line(&hexline)) - { - fprintf(stderr, "Failed to parse line\n"); - exit(1); - } - - /* Adjust 'Extended Segment Address Records'. */ - - if (hexline.type == TYPE_EXTLIN) - { - adjust_extlin(&hexline); - } - fputs(line, dest); - } - - fclose(src); - fclose(dest); - - /* Remove the original nuttx.hex file */ - - if (remove(srcfile) != 0) - { - fprintf(stderr, "Failed to remove the old '%s'\n", srcfile); - - } - - /* Rename the new nuttx.tmp file to nuttx.hex */ - - if (rename(destfile, srcfile) != 0) - { - fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile); - } - - return 0; -} diff --git a/nuttx/include/nuttx/rtc.h b/nuttx/include/nuttx/rtc.h index 5082b4d2d..b9bd020c9 100644 --- a/nuttx/include/nuttx/rtc.h +++ b/nuttx/include/nuttx/rtc.h @@ -107,7 +107,7 @@ ****************************************************************************/ /* The form of an alarm callback */ -typedef FAR void (*alarmcb_t)(void); +typedef CODE void (*alarmcb_t)(void); /**************************************************************************** * Public Variables diff --git a/nuttx/tools/README.txt b/nuttx/tools/README.txt index b4368aff9..39128fa1b 100755 --- a/nuttx/tools/README.txt +++ b/nuttx/tools/README.txt @@ -79,6 +79,10 @@ mksyscall.c accept this CVS file as input and generate all of the required proxy or stub files as output. See syscall/README.txt for additonal information. +pic32mx + + This directory contains build tools used only for PIC32MX platforms + bdf-convert.c This C file is used to build the bdf-converter program. The bdf-converter diff --git a/nuttx/configs/mirtoo/tools/Makefile b/nuttx/tools/pic32mx/Makefile index cd4bf50cb..040cf58cc 100644 --- a/nuttx/configs/mirtoo/tools/Makefile +++ b/nuttx/tools/pic32mx/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# configs/mirtoo/tools/Makefile +# tools/pic32mx//Makefile # # Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <gnutt@nuttx.org> diff --git a/nuttx/configs/mirtoo/tools/mkpichex.c b/nuttx/tools/pic32mx/mkpichex.c index 379e6a72e..14fefdb8c 100644 --- a/nuttx/configs/mirtoo/tools/mkpichex.c +++ b/nuttx/tools/pic32mx/mkpichex.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/mirtoo/tools/mkpichex.c + * tools/pic32mx//mkpichex.c * * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> |