搜索
bottom↓
回复: 6

请教: #pragma segment="FLASHCODE" 和 #pragma vector = PORT1_VECT

[复制链接]

出0入0汤圆

发表于 2011-9-28 20:33:44 | 显示全部楼层 |阅读模式
//******************************************************************************
//  MSP430x54x Demo - Block Write and Memory Erase @ 0x10000 Executed from RAM
//
//  Description: This program first copies write_block_int function to RAM.
//  Copying to RAM requires a custom made .xcl command linker file. This file is
//  attached as part of the project called custom_lnk_msp430f5438.xcl. This
//  program then erases Flash address 0x10000 - 0x1FFFF which is executed from
//  RAM. Then, it writes to Bank 1 from 0x10000 to 0x1003F. This write shows the
//  advantage of block writing in which 2 consecutive word can be written.
//
//  Important Notes:
//
//  1. Copy a new linker file (custom_lnk_msp430f5438.xcl) before modifying it.
//     See the zip file for the modified linker file. 1 line was added and 2
//     line was changed. Goto Project Options --> Linker --> Config. Overide the
//     linker command file and insert the new .xcl file.
//
//     -QRAMCODE=FLASHCODE                   // Needed to tell compiler that user
//                                              will copy flash code to ram code
//     -Z(DATA)RAMCODE,DATA16_I,DATA16_Z,DATA16_N,DATA16_HEAP+_DATA16_HEAP_SIZE=1C00-5BFF
//                                           // Add RAMCODE into Flash segment
//     -P(CODE)FLASHCODE,CODE=5C00-FF7F,10000-45BFF
//                                           // Add FLASHCODE into Flash segment
//
//  2. Define the allocated memory area that will be copied from FLASH to RAM.
//     In this case, user has to manually define the start address of FLASH and
//     RAM. These memory addresses has to be the same as defined in the linker
//     file origin address of FLASH_MEM and RAM_MEM. The FLASH_MEM_LENGTH can be
//     changed to however much the final compiled code size is.
//
//     WRITE_LENGTH      EQU   64
//     FLASH_MEM_BEGIN   EQU   0x5C00       ; Flash code starting address
//     FLASH_MEM_LENGTH  EQU   0x0200       ; Function segment size to be copied
//     RAM_MEM_BEGIN     EQU   0x1C00       ; RAM code starting address
//     WRITE_ADDR        EQU   0x10000      ; Flash write address
//
//  RESET the device to re-execute code. This is implemented to prevent
//  stressing of Flash unintentionally.
//  ACLK = REFO = 32kHz, MCLK = SMCLK = default DCO 1048576Hz
//
//                MSP430x54x
//            -----------------
//        /|\|              XIN|-
//         | |                 |
//         --|RST          XOUT|-
//           |                 |
//
//   W. Goh
//   Texas Instruments Inc.
//   April 2009
//   Built with IAR Embedded Workbench Version: 4.11B
//******************************************************************************

#include "msp430x54x.h"
#include "string.h"

#pragma segment="FLASHCODE"                 // Define flash segment code
#pragma segment="RAMCODE"                   /////??????????????????????????问题在这里?  这两句的意思是什么?

// Function prototypes
void copy_flash_to_RAM(void);
void write_block_int(void);

unsigned long value;

void main(void)
{

  WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT

  copy_flash_to_RAM();                      // Copy flash to RAM function

  value = 0x12340000;                       // initialize Value

  write_block_int();                        // This portion of code is executed
                                            // in RAM
  while(1);                                 // Loop forever, SET BREAKPOINT HERE
}

//------------------------------------------------------------------------------
// Copy flash function to RAM.
//------------------------------------------------------------------------------
void copy_flash_to_RAM(void)
{
  unsigned char *flash_start_ptr;           // Initialize pointers
  unsigned char *flash_end_ptr;
  unsigned char *RAM_start_ptr;

  //Initialize flash and ram start and end address
  flash_start_ptr = (unsigned char *)__segment_begin("FLASHCODE");
  flash_end_ptr = (unsigned char *)__segment_end("FLASHCODE");
  RAM_start_ptr = (unsigned char *)__segment_begin("RAMCODE");

  //calculate function size
  unsigned long function_size = (unsigned long)(flash_end_ptr) - (unsigned long)(flash_start_ptr);

  // Copy flash function to RAM
  memcpy(RAM_start_ptr,flash_start_ptr,function_size);
}

#pragma location="RAMCODE"
//------------------------------------------------------------------------------
// This portion of the code is first stored in Flash and copied to RAM then
// finally executes from RAM.
//-------------------------------------------------------------------------------
void write_block_int(void)
{
  unsigned int i;
  unsigned long * Flash_ptr;
  Flash_ptr = (unsigned long *)0x10000;     // Initialize write address
  __disable_interrupt();                    // 5xx Workaround: Disable global
                                            // interrupt while erasing. Re-Enable
                                            // GIE if needed
  // Erase Flash
  while(BUSY & FCTL3);                      // Check if Flash being used
  FCTL3 = FWKEY;                            // Clear Lock bit
  FCTL1 = FWKEY+ERASE;                      // Set Erase bit
  *Flash_ptr = 0;                           // Dummy write to erase Flash seg
  while(BUSY & FCTL3);                      // Check if Erase is done

  // Write Flash
  FCTL1 = FWKEY+BLKWRT+WRT;                 // Enable block write

  for(i = 0; i < 64; i++)
  {
    *Flash_ptr++ = value++;                 // Write long int to Flash

    while(!(WAIT & FCTL3));                 // Test wait until ready for next byte
  }

  FCTL1 = FWKEY;                            // Clear WRT, BLKWRT
  while(BUSY & FCTL3);                      // Check for write completion
  FCTL3 = FWKEY+LOCK;                       // Set LOCK
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2011-10-2 00:11:52 | 显示全部楼层
IAR帮助文档里有,你找找看。

出0入0汤圆

 楼主| 发表于 2011-10-11 13:40:48 | 显示全部楼层
回复【1楼】ljmdzyx
-----------------------------------------------------------------------

文档 确实 是有。
不过 看的实在是累人。
兄弟 要是懂的话, 就交流指导一下吧。。

出0入0汤圆

 楼主| 发表于 2011-10-14 15:45:16 | 显示全部楼层

(原文件名:11111.png)

在文档 里面有该语句的解释, 不过貌视 我还是看不太懂!!!
哪位知道的能分享 一些经验吗?
还有 那个 例子是什么意思呢?

出0入0汤圆

发表于 2011-10-15 01:38:49 | 显示全部楼层
唉,msp低功耗的方式太多了,很多都很难搞明白的

出0入0汤圆

发表于 2011-10-16 09:28:32 | 显示全部楼层
#pragma vector=数值 表示一个中断向量
紧接着就是中断函数,为了区分,中断函数前面加__interrupt关键字

出0入0汤圆

发表于 2011-10-16 10:32:47 | 显示全部楼层
JJ,在函数前加#pragma segment="RAMCODE"  就是存储在ram里
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-28 13:31

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表