⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash_monitor.s43

📁 msp430应用程序头文件
💻 S43
📖 第 1 页 / 共 2 页
字号:
;// THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
;// REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
;// INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
;// FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
;// COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
;// TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
;// POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
;// INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
;// YOUR USE OF THE PROGRAM.
;//
;// IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
;// CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
;// THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
;// OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
;// OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
;// EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
;// REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
;// OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
;// USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
;// AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
;// YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
;// (U.S.$500).
;//
;// Unless otherwise stated, the Program written and copyrighted
;// by Texas Instruments is distributed as "freeware".  You may,
;// only under TI's copyright in the Program, use and modify the
;// Program without any charge or restriction.  You may
;// distribute to third parties, provided that you transfer a
;// copy of this license to the third party and the third party
;// agrees to these terms by its first use of the Program. You
;// must reproduce the copyright notice and any other legend of
;// ownership on each copy or partial copy, of the Program.
;//
;// You acknowledge and agree that the Program contains
;// copyrighted material, trade secrets and other TI proprietary
;// information and is protected by copyright laws,
;// international copyright treaties, and trade secret laws, as
;// well as other intellectual property laws.  To protect TI's
;// rights in the Program, you agree not to decompile, reverse
;// engineer, disassemble or otherwise translate any object code
;// versions of the Program to a human-readable form.  You agree
;// that in no event will you alter, remove or destroy any
;// copyright notice included in the Program.  TI reserves all
;// rights not specifically granted under this license. Except
;// as specifically provided herein, nothing in this agreement
;// shall be construed as conferring by implication, estoppel,
;// or otherwise, upon you, any license or other right under any
;// TI patents, copyrights or trade secrets.
;//
;// You may not use the Program in non-TI devices.
;//
;-------------------------------------------------------------------------------
;******************************************************************************
;   MSP430 Flash Monitor
;
;   Description:
;   This monitor provides the capability of updating the MSP430 flash
;   via USART
;
;   Communications parameters are:  9600bps
;                                   8 bits/char, 1 stop bit, no parity
;                                   no flow control
;
;   The can be built to run at reset, or to run an application first.
;   When configured to run at reset, it waits for a character on the USART.
;   If it doesn't receive a character on the USART within ~2 seconds of reset,
;   it will transfer code to a user program assumed to have a reset vector at
;   0xFBFE (Top of flash segment 2)
;
;   Valid commands are: C - calculate a checksum on user flash
;                       D - dump user flash to USART
;                       E - Erase user flash (requires password)
;                       G - Run user application
;                       I - Erase information flash
;                       U - Update user flash - the monitor will expect an ASCII
;                           file in MSP430.txt format
;
;
;   For 'F1xx devices MCLK = SMCLK = DCOCLK  ~ 750 KHz
;   For 'F4xx devices MCLK = SMCLK = DCOCLK = 1.048576 MHz
;
;
;
;                MSP430F169
;             -----------------
;         /|\|              XIN|-
;          | |                 |
;          --|RST          XOUT|-
;            |                 |
;            |             P3.6|------------>
;            |                 |  9600 - 8N1
;            |             P3.7|<------------
;
;   Jim Patterson
;   Texas Instruments, Inc
;   November 2006
;   Built with IAR Embedded Workbench Version: 3.41A
;
;   USART and target device selected in TargetDefs.h
;   test target Softbaugh DIr169 board
;******************************************************************************
#include  "TargetDefs.h"
#include  "flash_monitor.h"
;------------------------------------------------------------------------------
        PUBLIC  WarmStart

        RSEG CSTACK

OutString DS8 80          ;reserve 80 chars for output string
Address   DS16  1         ;dump start address
Count     DS16  1         ;dump word count
Pace      DS8   1         ;flag for pacing dump
FlashPtr  DS16  1         ;flash address update pointer
FlashBuf  DS8   32        ;RAM buffer for flash data
ByteCount DS16  1

#ifndef DIRECT_INTERRUPTS

    ASEG
    ORG 0xFC00  ;place at the bottom of Segment 1

Int_Priority_0: mov.w  &0xFBE0, PC
Int_Priority_1: mov.w  &0xFBE2, PC
Int_Priority_2: mov.w  &0xFBE4, PC
Int_Priority_3: mov.w  &0xFBE6, PC
Int_Priority_4: mov.w  &0xFBE8, PC
Int_Priority_5: mov.w  &0xFBEA, PC
Int_Priority_6: mov.w  &0xFBEC, PC
Int_Priority_7: mov.w  &0xFBEE, PC
Int_Priority_8: mov.w  &0xFBF0, PC
Int_Priority_9: mov.w  &0xFBF2, PC
Int_Priority_A: mov.w  &0xFBF4, PC
Int_Priority_B: mov.w  &0xFBF6, PC
Int_Priority_C: mov.w  &0xFBF8, PC
Int_Priority_D: mov.w  &0xFBFA, PC
Int_Priority_E: mov.w  &0xFBFC, PC
User_Reset:     mov.w  &0xFBFE, PC

#endif

#ifdef  DIRECT_INTERRUPTS
            ASEG
            ORG     MONITOR_START            ; Progam Start
#endif
;------------------------------------------------------------------------------
WarmStart: DW      MonStart

Reset:
#ifndef     DELAY_START  ; controls the monitor or application runs first

            cmp.w   #-1, &0xFBFE            ; Is the user reset programmed?
            jz      MonStart                ; Start monitor if it isn't
            mov.w   &0xFBFE, PC             ; If it is, start application
#endif
MonStart:   bic.b   #GIE, SR
            mov.w   #SFE(CSTACK),SP         ; Initialize stackpointer
            mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT

#ifdef  DELAY_START   ; don't start timer if user application runs first
SetupTA     mov.w   #TASSEL_1+MC_2+TAIE,&TACTL
            mov.w   #0, &TAR                ;Clear TimerA
; TimerA will overflow in 2 seconds.
; If it overflows before a character is received from the USART,
; control will be transferred to the user application (Vector at 0xFBFE).
; If the vector is unprogrammed (0xFFFF) the monitor will restart.
#endif

#ifdef  F1xx
            mov.b   #DCO1, DCOCTL             ; DCOCTL = 0x40
            bis.b   #(UTX+URX), &UART_PORTSEL ; Select UART function
SetupUART   bis.b   #UTXE_+URXE_,&UART_ME     ; Enable USART TXD/RXD
            bis.b   #CHAR,&U_CTL              ; 8-bit char
            bis.b   #SSEL0,&U_TCTL            ; UCLK = TACLK
            mov.b   #3,&U_BR0                 ; 32768/9600 = 3.41
            mov.b   #000h,&U_BR1              ;
            mov.b   #04Ah,&U_MCTL             ; Modulation
            bic.b   #SWRST,&U_CTL             ; Enable USART state machine
;
; Set flash timing generator for ~350kHz
;
Timing      mov.w   #FWKEY+FSSEL0+FN0,&FCTL2  ; *Timing generator = MCLK/2

#endif
#ifdef  F4xx
            bis.b   #(UTX+URX), &UART_PORTSEL
SetupUART   bis.b   #UTXE_+URXE_,&UART_ME   ; Enable USART TXD/RXD
            bis.b   #CHAR,&U_CTL            ; 8-bit characters
            mov.b   #SSEL1,&U_TCTL          ; UCLK = SMCLK
            mov.b   #06Dh,&U_BR0            ; 1.048576 MHz/9600
            mov.b   #000h,&U_BR1            ;
            mov.b   #003h,&U_MCTL           ; modulation
            bic.b   #SWRST,&U_CTL           ; Initialize USART state machine
            bis.b   #UART_RX_IFG,&IE1       ; Enable USART RX interrupt
;
; Set flash timing generator for ~333kHz
;
Timing      mov.w   #FWKEY+FSSEL0+FN1,&FCTL2  ; *Timing generator = MCLK/3

#endif

            mov.w   #GetWord, R7          ;R7 points to GetWord function
            mov.w   #SendString, R8       ;R8 points to string output function
            mov.w   #SendChar, R9         ;R9 points to char output function

Ready:      mov.w   #Prompt, R12
            call    R8                    ;#SendString

GetCmd:     call    #GetChar
;
;   Tests go here
;
            mov.w   #CmdTable, R6             ;Load address of command table
CheckChar:  mov.b   @R6, R5                   ;Load table entry to R5
            tst.b   R5                        ;At end of table?
            jz      Ready                     ;if yes, wait for next command
            cmp.b   @R6+, R12                 ;is character a valid command
            jz      ProcessCmd                ;if yes, process it
            jmp     CheckChar                 ;if no, check against next entry

ProcessCmd: sub     #CmdTable+1,R6            ;generate offset into jump table
            rla.w   R6
            call    CmdFunctions(R6)          ;call the command function
            jmp     Ready                     ;wait for another command

SendString: mov.w   R12, R14                ;Copy pointer to R14
SendNext:   mov.b   @R14+, R12              ;load next character
            tst.b   R12                     ;Null character?
            jz      StringDone              ;Return at end of string
            call    R9                      ;#SendChar
            jmp     SendNext
StringDone: ret

SendChar:   bit.b   #UART_TX_IFG, &UART_IFG ;is TX ready?
            jz      SendChar                ;Wait until it is
            mov.b   R12, &U_TXBUF           ;Send character
            ret                             ;return

ToString:                           ;R14 points to the result
            mov.b   #4, R11         ;This is the nibble counter
NextChar:   mov.b   #4, R15         ;R15 is the bit counter
Rotate:     rlc.w   R12             ;Move the MS bit in R12
            rlc.w   R13             ;into the LS bit in R14
            dec.w   R15             ;count the bits
            jnz     Rotate          ;4 iterations moves a nibble
            and.b   #0xF, R13       ;mask all but 4 LSBs
            cmp.b   #10, R13        ;Check magnitude
            jge     Add37
            add.b   #0x30, R13      ;add 0x30 to 0-9
            jmp     SaveHex
Add37:      add.b   #0x37, R13      ;add 0x37 to A-F
SaveHex:    mov.b   R13, 0(R14)     ;Store in OutString
            inc.w   R14             ;point to the next char in string
            dec.w   R11             ;Decrement the nibble count
            jnz   NextChar
            mov.b R11, 0(R14)       ;Terminate string with null char
            ret

; Receive 8-bit ASCII characters from USART and convert it to a binary value
; Binary word is returned in R12
; R15 tells how many nibbles to get, usually 2 or 4

GetWord:    mov.b #4, R15
            clr.w R14             ; Build word in R14
            mov.b   #1, R13       ; flag set for ASCII char, cleared for word

NextNibble: call  #GetChar        ; Get a character from USART in R12
            cmp.b #'0', R12       ; Check lower limit
            jl    WordDone        ; Just return char if < '0'
            cmp.b #'G', R12       ; Check upper limit 'G'
            jge   WordDone        ; Return if > 'F'
            cmp.b #':', R12       ; '0' <= (R12) <= 'F', check if < 3Ah
            jl    IsNumeric       ; convert if '0' <= (R12) <= '9'
            cmp.b #'A', R12       ; Check for 'A'
            jl    WordDone        ; Return if ':' >= (R12) <= 'A'
            sub.b #0x37, R12      ; if 'A'<=(R12)<='F', subract 0x37
            jmp   IsHex           ; Conversion to hex is done

IsNumeric:  sub.b  #'0', R12      ;if '0'<=(R12)<='9' subtract '0'

IsHex:      mov.b #0, R13         ;at least 1 hex character received
            rla.w R14             ;R14 <<= R14
            rla.w R14
            rla.w R14
            rla.w R14
            xor.w R12, R14        ; OR in new 4 bits
            dec.w R15             ; Received 4 nibbles?
            jz    WordDone        ; If yes, we have a word
            jmp   NextNibble      ; Wait for another character

WordDone:   tst.b R13             ; 1 or more hex chars received?
            jnz   ReturnChar      ; return if none
            mov.w R14, R12        ; Return word in R12

ReturnChar: ret                   ; Return with word in R12



; Get a char from USART, return it in R12
GetChar:    bit.b #UART_RX_IFG, &UART_IFG   ; wait for RX character
            jnz   ReadChar                  ; Read RXBUF if flag is set

#ifdef  DELAY_START               ; Checks for timer A overflow
                                  ; not assembled if DELAY_START not defined

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -