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

📄 flash_access_example.asm

📁 csr芯片内置dsp编程demo,可以学习它的dsp编程
💻 ASM
字号:
// *****************************************************************************
// Copyright (C) Cambridge Silicon Radio plc 2003-2006        http://www.csr.com
// Part of BlueLab 3.5.2-release
//
// $Revision$  $Date$
// *****************************************************************************

// *****************************************************************************
// DESCRIPTION
//    An example of accessing flash data (and code for BC5-MM) from the Kalimba DSP
//
// NOTES
//    If using BC3-MM a kalimba_r03 chip (date code of 450 or higher) must be
// used if Kalimba is to access flash memory.  If the data code is less than 450
// then the KalimbaLoad() call from the VM will fail.
//
//    For BC5-MM chips we run part of the code from flash PM as an example.  See
// the ".CODESEGMENT PM_FLASH;" below.
//
// What the code does:
//    1) Reads an ascii text string from flash and sends it as a message to the
//       VM.  The VM then displays this message using a PRINT statement.
//    2) Next it reads 23Kwords of data from flash and checks that what it's
//       read is what it expected.  The data is words of 0-31 repeated many
//       times (see below).
//    3) Finally it reads another string from flash and sends it as a message to
//       the VM.  The VM then displays this message using a PRINT statement.
//
// *****************************************************************************

// includes
.include "core_library.h"

.define $FLASH_TEST_MESSAGE_TO_VM       0x1000

.MODULE $M.main;
   .CODESEGMENT PM;
   .DATASEGMENT DM;

   .VAR  $message_buffer[64];

   // -- Define a new flash group to use called 'FLASHDATA' --
   //          Name            Start   End     Width   Tag         Relocatable?
   .DEFGROUP   FlashDataGroup  0x0000  0xFFFF  16      flash.data  RELOCATABLE;

   //          Name            CIRCULAR?       Link Order          Group list
   .DEFSEGMENT FLASHDATA                       1                   FlashDataGroup;

   // This address gets filled in by firmware upon a KalimbaLoad call from the VM
   .VAR/DM1 $flash.data.address;


   .VAR/FLASHDATA $hello_text[] = 72, 101, 108, 108, 111,  46,  32,  84, 104,
                                 105, 115,  32, 109, 101, 115, 115,  97, 103,
                                 101,  32, 104,  97, 115,  32,  99, 111, 109,
                                 101,  32, 102, 114, 111, 109,  32, 102, 108,
                                  97, 115, 104,  33, 0;

   .DEFINE LOTA_DATA_512  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, \
                          0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31

   .VAR/FLASHDATA $lota_flash_data[23552] = LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512, LOTA_DATA_512, LOTA_DATA_512,
                                            LOTA_DATA_512;

   .VAR/FLASHDATA $completed_text[] =   50,  51,  75, 119, 111, 114, 100, 115,
                                        32, 111, 102,  32, 102, 108,  97, 115,
                                       104,  32, 100,  97, 116,  97,  32, 104,
                                        97, 118, 101,  32,  98, 101, 101, 110,
                                        32, 115, 117,  99,  99, 101, 115, 115,
                                       102, 117, 108, 108, 121,  32, 114, 101,
                                        97, 100,  46;

   $main:
   // initialise the stack library
   call $stack.initialise;
   // initialise the interrupt library
   call $interrupt.initialise;
   // initialise the message library
   call $message.initialise;
   // initialise the cbuffer library
   call $cbuffer.initialise;
   .ifdef DEBUG_ON
      // initialise the profiler library
      call $profiler.initialise;
   .endif

   // tell vm we're ready and wait for the go message
   call $message.send_ready_wait_for_go;

   // if we're using BC5-MM then we'll test running code from flash
   .ifdef BC5MM
      call $flash.init_pm;
   .endif

   // now test the flash access
   // running the code from flash (if BC5MM)
   jump $test_the_flash_access;

.ENDMODULE;




.MODULE $M.test_the_flash_access;
   .ifdef BC5MM
      .CODESEGMENT PM_FLASH;
   .else
      .CODESEGMENT PM;
   .endif
   .DATASEGMENT DM;

   $test_the_flash_access:

   // -- Send 'hello' message to VM using text string from flash --
   // copy variable from flash pages to dm
   r0 = &$hello_text;
   r1 = LENGTH($hello_text);
   I0 = &$message_buffer;
   r2 = M[$flash.data.address];
   call $flash.copy_to_dm;
   // send message
   r2 = $message.LONG_MESSAGE_MODE_ID;
   r3 = $FLASH_TEST_MESSAGE_TO_VM;
   r4 = LENGTH($hello_text);
   r5 = &$message_buffer;
   call $message.send;



   // -- Example of reading a large block of data from flash (lota_flash_data1) --
   r4 = &$lota_flash_data;
   r5 = LENGTH($lota_flash_data);
   r6 = 0;
   // Only 4k of flash is mapped in at any one point. So we need to make sure we
   // dont read past a page boundary, if we need to then we must map in the next
   // page.
   lota_flash_data_page_loop:
      // map in the flash page, and get a pointer to the data
      r0 = r4;
      r1 = r5;
      r2 = M[$flash.data.address];
      call $flash.map_page_into_dm;
      // set I0 = pointer to flash data (in the dm2 window)
      // set r10 = amount to read (from this flash page)
      I0 = r0;
      r10 = r1;

      // set remaining amount to read next time
      r5 = r5 - r1;
      // and starting address to read from next time
      r4 = r4 + r1;

      // read all flash data needed from this flash page
      do lota_flash_data_inner_loop;
         // read word from flash
         r0 = M[I0,1];
         // check word is what we expect it to be
         Null = r0 - r6;
         if NZ call $error;
         // increment check word for next time
         r6 = r6 + 1;
         Null = r6 - 32;
         if Z r6 = 0;
      lota_flash_data_inner_loop:

      // if we haven't read all the data then loop around again mapping in another page
      Null = r5;
   if NZ jump lota_flash_data_page_loop;


   // wait for message queue to empty
   wait_till_queue_empty:
      call $timer.1ms_delay;
      call $message.send_queue_fullness;
      Null = r0;
   if NZ jump wait_till_queue_empty;


   // -- Send 'completed' message to VM using text string from flash --
   // copy variable from flash pages to dm
   r0 = &$completed_text;
   r1 = LENGTH($completed_text);
   I0 = &$message_buffer;
   r2 = M[$flash.data.address];
   call $flash.copy_to_dm;
   // send message
   r2 = $message.LONG_MESSAGE_MODE_ID;
   r3 = $FLASH_TEST_MESSAGE_TO_VM;
   r4 = LENGTH($completed_text);
   r5 = &$message_buffer;
   call $message.send;


   // now sit doing nothing!
   main_loop:
      call $timer.1ms_delay;
   jump main_loop;

.ENDMODULE;

⌨️ 快捷键说明

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