Пример #1
0
/************************************************************************************************ 
* RomToRam_Kinetis
* 将部分ROM中的数据转移至RAM中
************************************************************************************************/
static void RomToRam_Kinetis(void)
{
  K_int32u_t n = (K_int32u_t)__section_end(".data_init") - (K_int32u_t)__section_begin(".data_init");
  K_int8u_t *ptr1 = __section_begin(".data"), *ptr2 = __section_begin(".data_init");
  
  K_int8u_t* code_relocate_ram = __section_begin("CodeRelocateRam");
  K_int8u_t* code_relocate = __section_begin("CodeRelocate");
  K_int8u_t* code_relocate_end = __section_end("CodeRelocate");
  
  if(n != 0)
  {
    do
    {
      *ptr1++ = *ptr2++;  
    } while(--n);  
  } 
  
  /* Copy functions from ROM to RAM */
  n = (K_int32u_t)code_relocate_end - (K_int32u_t)code_relocate;
  if(n != 0)
  {
    while (n--)
    {
      *code_relocate_ram++ = *code_relocate++;
    }
  }
}
Пример #2
0
void VECTableInit(void)
{
 
    /* Declare a counter we'll use in all of the copy loops */
    ULONG n;
 
 
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */  
    extern ULONG __VECTOR_TABLE[];
    extern ULONG __VECTOR_RAM[];

    /* Copy the vector table to RAM */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < 0x410; n++)
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
    }
    /* Point the VTOR to the new copy of the vector table */
    //write_vtor((uint32)__VECTOR_RAM);  
    
    SCB_VTOR = (ULONG)__VECTOR_RAM;
    
    /* Get the addresses for the .data section (initialized data section) */
    U8* data_ram = __section_begin(".data");
    U8* data_rom = __section_begin(".data_init");
    U8* data_rom_end = __section_end(".data_init");
    
    /* Copy initialized data from ROM to RAM */
    n = data_rom_end - data_rom;
    while (n--)
      *data_ram++ = *data_rom++;
 
 
    /* Get the addresses for the .bss section (zero-initialized data) */
    U8* bss_start = __section_begin(".bss");
    U8* bss_end = __section_end(".bss");
    
    /* Clear the zero-initialized data section */
    n = bss_end - bss_start;
    while(n--)
      *bss_start++ = 0;    
    
    /* Get addresses for any code sections that need to be copied from ROM to RAM.
     * The IAR tools have a predefined keyword that can be used to mark individual
     * functions for execution from RAM. Add "__ramfunc" before the return type in
     * the function prototype for any routines you need to execute from RAM instead 
     * of ROM. ex: __ramfunc void foo(void);
     */
    U8* code_relocate_ram = __section_begin("CodeRelocateRam");
    U8* code_relocate = __section_begin("CodeRelocate");
    U8* code_relocate_end = __section_end("CodeRelocate");
    
    /* Copy functions from ROM to RAM */
    n = code_relocate_end - code_relocate;
    while (n--)
      *code_relocate_ram++ = *code_relocate++;
    
}
Пример #3
0
void __iar_data_init_app(void)
{
    __bss_sram_start__ = (uint8_t *)__section_begin(".bss.sram");
    __bss_sram_end__   = (uint8_t *)__section_end(".bss.sram");
    __bss_dtcm_start__ = (uint8_t *)__section_begin(".bss.dtcm");
    __bss_dtcm_end__   = (uint8_t *)__section_end(".bss.dtcm");
    __bss_dram_start__ = (uint8_t *)__section_begin(".bss.dram");
    __bss_dram_end__   = (uint8_t *)__section_end(".bss.dram");
}
Пример #4
0
/*
 * @ingroup finsh
 *
 * This function will initialize finsh shell
 */
void finsh_system_init(void)
{
	rt_err_t result;

#ifdef FINSH_USING_SYMTAB
#ifdef __CC_ARM                 /* ARM C Compiler */
    extern const int FSymTab$$Base;
    extern const int FSymTab$$Limit;
    extern const int VSymTab$$Base;
    extern const int VSymTab$$Limit;
	finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
	finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit);
#elif defined (__ICCARM__)      /* for IAR Compiler */
    finsh_system_function_init(__section_begin("FSymTab"),
                               __section_end("FSymTab"));
    finsh_system_var_init(__section_begin("VSymTab"),
                          __section_end("VSymTab"));
#elif defined (__GNUC__)        /* GNU GCC Compiler */
	extern const int __fsymtab_start;
	extern const int __fsymtab_end;
	extern const int __vsymtab_start;
	extern const int __vsymtab_end;
	finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
	finsh_system_var_init(&__vsymtab_start, &__vsymtab_end);
#endif
#endif

	/* create or set shell structure */
#ifdef RT_USING_HEAP
	shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell));
#else
	shell = &_shell;
#endif
	if (shell == RT_NULL)
	{
		rt_kprintf("no memory for shell\n");
		return;
	}
	
	memset(shell, 0, sizeof(struct finsh_shell));

	rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
	result = rt_thread_init(&finsh_thread,
		"tshell",
		finsh_thread_entry, RT_NULL,
		&finsh_thread_stack[0], sizeof(finsh_thread_stack),
		FINSH_THREAD_PRIORITY, 10);

	if (result == RT_EOK)
		rt_thread_startup(&finsh_thread);
}
Пример #5
0
void help(uint8_t argc, char** argv)
{
    struct COMMAND_ENTRY* entry_seek;
    struct COMMAND_ENTRY* entry_tail;

    entry_seek = __section_begin("COMMAND_ENTRY");
    entry_tail = __section_end("COMMAND_ENTRY");

    if(argc == 0)
    {// show all
        for(; entry_seek < entry_tail; ++entry_seek)
        {
            showHelp(entry_seek);
        }
    }
    else
    {
        for(; entry_seek < entry_tail; ++entry_seek)
        {
            if( strcmp(argv[0], entry_seek->name) == 0 )
            {
                showHelp(entry_seek);
                break;
            }
        }
    }
}
Пример #6
0
Файл: nvm.c Проект: miaofng/ulp
int nvm_save(void)
{
	char *src, *dest, *bak;
	int magic = NVM_MAGIC;
	int sz_ram, pages;

	src = __section_begin(".nvm.ram");
	sz_ram = (int)__section_end(".nvm.ram") - (int)__section_begin(".nvm.ram");
	if(sz_ram == 0)
		return 0;
	sz_ram = align(sz_ram, 4);
	pages = align(sz_ram + 8, FLASH_PAGE_SZ) / FLASH_PAGE_SZ;
	dest = (char *)FLASH_ADDR(FLASH_PAGE_NR - pages); //rom 1
	bak = (char *)FLASH_ADDR(FLASH_PAGE_NR - pages - pages); // rom 2

	//ram -> rom 1
	flash_Write(dest + 4, &sz_ram, 4);
	flash_Write(dest + 8, src, sz_ram);
	flash_Write(dest + 0, &magic, 4);

	//ram -> rom 2
	flash_Erase(bak, pages);
	flash_Write(bak + 4, &sz_ram, 4);
	flash_Write(bak + 8, src, sz_ram);
	flash_Write(bak + 0, &magic, 4);

	//erase rom 1
	flash_Erase(dest, pages);
	return 0;
}
Пример #7
0
/* Start the secondary core. */
void BOARD_StartSecondaryCore(void)
{
/* Calculate size of the secondary core image - not required on MCUXpresso. MCUXpresso copies the image to RAM during
 * startup
 * automatically */
#if (defined(__CC_ARM) || defined(__ICCARM__))
#if defined(__CC_ARM)
    uint32_t core1_image_size = (uint32_t)&Image$$CORE1_REGION$$Length;
#elif defined(__ICCARM__)
#pragma section = "__sec_core"
    uint32_t core1_image_size = (uint32_t)__section_end("__sec_core") - (uint32_t)&core1_image_start;
#endif

    /* Copy core1 application from FLASH to RAM. Primary core code is executed from FLASH, Secondary from RAM
     * for maximal effectivity.*/
    memcpy(CORE1_BOOT_ADDRESS, (void *)CORE1_IMAGE_START, core1_image_size);
#endif
    /* Boot source for Core 1 from RAM */
    SYSCON->CPBOOT = SYSCON_CPBOOT_BOOTADDR(*(uint32_t *)((uint8_t *)CORE1_BOOT_ADDRESS + 0x4));
    SYSCON->CPSTACK = SYSCON_CPSTACK_STACKADDR(*(uint32_t *)CORE1_BOOT_ADDRESS);

    uint32_t temp = SYSCON->CPUCTRL;
    temp |= 0xc0c48000U;
    SYSCON->CPUCTRL = temp | SYSCON_CPUCTRL_CM0RSTEN_MASK | SYSCON_CPUCTRL_CM0CLKEN_MASK;
    SYSCON->CPUCTRL = (temp | SYSCON_CPUCTRL_CM0CLKEN_MASK) & (~SYSCON_CPUCTRL_CM0RSTEN_MASK);
}
Пример #8
0
void *
malloc (unsigned nbytes)
{
    /* Get addresses for the HEAP start and end */
    #if defined(CW)  
      //extern char __HEAP_START[];
      //extern char __HEAP_END[];
	  extern char __heap_addr[];
	  extern char __heap_size;
	  char *__HEAP_START = __heap_addr;
	  char *__HEAP_END = __heap_addr + __heap_size;
    #elif defined(IAR)
      char* __HEAP_START = __section_begin("HEAP");
      char* __HEAP_END = __section_end("HEAP");
    #elif defined(KEIL)
	  extern uint32_t HEAP$$Base;
	  extern uint32_t HEAP$$Limit;
	  uint32_t __HEAP_START = (uint32_t)&HEAP$$Base;
	  uint32_t __HEAP_END = (uint32_t)&HEAP$$Limit;
    #endif
   
    ALLOC_HDR *p, *prevp;
    unsigned nunits;

    nunits = ((nbytes+sizeof(ALLOC_HDR)-1) / sizeof(ALLOC_HDR)) + 1;

    if ((prevp = freep) == NULL)
    {
        p = (ALLOC_HDR *)__HEAP_START;
        p->s.size = ( ((uint32)__HEAP_END - (uint32)__HEAP_START)
            / sizeof(ALLOC_HDR) );
        p->s.ptr = &base;
        base.s.ptr = p;
        base.s.size = 0;
        prevp = freep = &base;
    }

    for (p = prevp->s.ptr; ; prevp = p, p = p->s.ptr)
    {
        if (p->s.size >= nunits)
        {
            if (p->s.size == nunits)
            {
                prevp->s.ptr = p->s.ptr;
            }
            else
            {
                p->s.size -= nunits;
                p += p->s.size;
                p->s.size = nunits;
            }
            freep = prevp;
            return (void *)(p + 1);
        }

        if (p == freep)
            return NULL;
    }
}
Пример #9
0
Файл: nvm.c Проект: miaofng/ulp
int nvm_init(void)
{
	char *src, *dst, *bak;
	int sz_ram, magic, sz_nvm, pages;

	dst = __section_begin(".nvm.ram");
	sz_ram = (int)__section_end(".nvm.ram") - (int)__section_begin(".nvm.ram");
	if(sz_ram == 0) { //no nvm var is used
		nvm_flag_null = 0;
		return 0;
	}

	sz_ram = align(sz_ram, 4);
	pages = align(sz_ram + 8, FLASH_PAGE_SZ) / FLASH_PAGE_SZ;
	src = (char *)FLASH_ADDR(FLASH_PAGE_NR - pages); //rom 1
	bak = (char *)FLASH_ADDR(FLASH_PAGE_NR - pages - pages); // rom 2

	//rom 1 -> ram, always read & erase rom 1 in case of "rom1 not null!!!"
	flash_Read(&magic, src, 4);
	flash_Read(&sz_nvm, src + 4, 4);

	if(magic == NVM_MAGIC && sz_nvm == sz_ram) {
		flash_Read(dst, src + 8, sz_ram);

		//rom1 data is ok, rom1 -> rom 2
		flash_Erase(bak, pages);
		flash_Write(bak + 4, &sz_nvm, 4);
		flash_Write(bak + 8, dst, sz_ram);
		flash_Write(bak + 0, &magic, 4);
		flash_Erase(src, pages); //erase rom 1
		nvm_flag_null = 0;
		return 0;
	}

	//to avoid one more time erase op on an empty flash page
	if(sz_nvm != -1) {
		flash_Erase(src, pages); //erase rom 1
	}

	//rom 2 -> ram
	src = bak;
	flash_Read(&magic, src, 4);
	flash_Read(&sz_nvm, src + 4, 4);
	if(magic == NVM_MAGIC && sz_nvm == sz_ram) {
		flash_Read(dst, src + 8, sz_ram);
		nvm_flag_null = 0;
		return 0;
	}

	//fail ...
	nvm_flag_null = 1;
	return -1;
}
Пример #10
0
void __iar_data_init3(void)
{
  char const * p = __section_begin("Region$$Table");
  uint32_t const * pe = __section_end("Region$$Table");
  uint32_t const * pi = (uint32_t const *)(p);
  while (pi != pe)
  {
    init_fun_t * fun = (init_fun_t *)((char *)pi + *(int32_t *)pi);
    pi++;
    pi = fun(pi);
  }
}
Пример #11
0
/************************************************************************************************ 
* FillBss_0_Kinetis
* 将"BSS"数据区初始化为0
************************************************************************************************/
static void FillBss_0_Kinetis(void)
{ 
  K_int8u_t *bss_start = __section_begin(".bss");
  K_int8u_t *bss_end   = __section_end(".bss");
  K_int32u_t n = (K_int32u_t)bss_end - (K_int32u_t)bss_start;;
  
  if(n != 0)
  {
    while(n--)
    {
      *bss_start++ = 0;
    }
  }
}
Пример #12
0
void * malloc (unsigned nbytes)
{
    /* Get addresses for the HEAP start and end */
    #if defined(__IAR_SYSTEMS_ICC__)
      char* __HEAP_START = __section_begin("HEAP");
      char* __HEAP_END = __section_end("HEAP");
    #else
      #warning 非IAR编译器需确定HEAP起始结束地址
      extern char __HEAP_START;
      extern char __HEAP_END[];
    #endif
   
    ALLOC_HDR *p, *prevp;
    unsigned nunits;

    nunits = ((nbytes+sizeof(ALLOC_HDR)-1) / sizeof(ALLOC_HDR)) + 1;

    if ((prevp = freep) == NULL)
    {
        p = (ALLOC_HDR *)__HEAP_START;
        p->s.size = ( ((uint32)__HEAP_END - (uint32)__HEAP_START)
            / sizeof(ALLOC_HDR) );
        p->s.ptr = &base;
        base.s.ptr = p;
        base.s.size = 0;
        prevp = freep = &base;
    }

    for (p = prevp->s.ptr; ; prevp = p, p = p->s.ptr)
    {
        if (p->s.size >= nunits)
        {
            if (p->s.size == nunits)
            {
                prevp->s.ptr = p->s.ptr;
            }
            else
            {
                p->s.size -= nunits;
                p += p->s.size;
                p->s.size = nunits;
            }
            freep = prevp;
            return (void *)(p + 1);
        }

        if (p == freep)
            return NULL;
    }
}
Пример #13
0
void shell_init(void)
{
#ifdef __CC_ARM                 /* ARM C Compiler */
    extern const int FSymTab$$Base;
    extern const int FSymTab$$Limit;
    _system_function_section_init(&FSymTab$$Base, &FSymTab$$Limit);
    
#elif defined (__ICCARM__)      /* for IAR Compiler */
    #pragma section="FSymTab"
    _system_function_section_init(__section_begin("FSymTab"),
                               __section_end("FSymTab"));

#endif
    
}
Пример #14
0
static  void  AppMemCreate(void)
{
    OS_ERR  error = OS_ERR_NONE;

    void        *p_addr;
    void        *p_addr_end;
    OS_MEM_QTY  n_blks;
    OS_MEM_SIZE blk_size;

    p_addr = __section_begin("OS_4K_MEM_POOL");
    p_addr_end = __section_end("OS_4K_MEM_POOL");
    n_blks = ((OS_MEM_SIZE)p_addr_end - (OS_MEM_SIZE)p_addr)/(4*1024);
    blk_size = (4*1024);


    OSMemCreate(&AppMem4KB,
                "4KB memory for app",
                p_addr,
                n_blks,
                blk_size,
                &error );


    p_addr = __section_begin("OS_2M_MEM_POOL");
    p_addr_end = __section_end("OS_2M_MEM_POOL");
    n_blks = ((OS_MEM_SIZE)p_addr_end - (OS_MEM_SIZE)p_addr) / (2*1024*1024);
    blk_size = (2*1024*1024);

    OSMemCreate(&AppMem2MB,
                "2MB memory for app",
                p_addr,
                n_blks,
                blk_size,
                &error );

}
Пример #15
0
__stackless void HardFault_Handler(void)
{
    __ASM volatile(
    "   ldr   r0, 100f                         \n"
    "   cmp   r0, lr                           \n"
    "   bne   1f                               \n"
    /* Reading PSP into R0 */
    "   mrs   r0, PSP                          \n"
    "   b     3f                               \n"
    "1:                                        \n"
    /* Reading MSP into R0 */
    "   mrs   r0, MSP                          \n"
    /* -----------------------------------------------------------------
     * If we have selected MSP check if we may use stack safetly.
     * If not - reset the stack to the initial value. */
    "   ldr   r1, 101f                         \n"
    "   ldr   r2, 102f                         \n"

    /* MSP is in the range of the stack area */
    "   cmp   r0, r1                           \n"
    "   bhi   2f                               \n"
    "   cmp   r0, r2                           \n"
    "   bhi   3f                               \n"
    /* ----------------------------------------------------------------- */
    "2:                                        \n"
    "   mov   SP, r1                           \n"
    "   movs  r0, #0                           \n"

    "3:                                        \n"
    "   ldr r3, 103f                           \n"
    "   bx r3                                  \n"

    "DATA                                      \n"
    "100:                                      \n"
    "   DC32 0xFFFFFFFD                        \n"
    "101:                                      \n"
    "   DC32 %c0                               \n"
    "102:                                      \n"
    "   DC32 %c1                               \n"
    "103:                                      \n"
    "   DC32 %c2                               \n"
    : /* Outputs */
    : /* Inputs */
    "i"(__section_end("CSTACK")),
    "i"(__section_begin("CSTACK")),
    "i"(&HardFault_c_handler)
    );
}
Пример #16
0
__stackless void HardFault_Handler(void)
{
    __ASM volatile(
    "   ldr.n r3, 103f                          \n"
    "   tst   lr, #4                            \n"

    /* PSP is quite simple and does not require additional handler */
    "   itt   ne                                \n"
    "   mrsne r0, psp                           \n"
    /* Jump to the handler, do not store LR - returning from handler just exits exception */
    "   bxne  r3                                \n"

    /* Processing MSP requires stack checking */
    "   mrs r0, msp                             \n"

    "   ldr.n r1, 101f                          \n"
    "   ldr.n r2, 102f                          \n"

    /* MSP is in the range of the stack area */
    "   cmp   r0, r1                            \n"
    "   bhi.n 1f                                \n"
    "   cmp   r0, r2                            \n"
    "   bhi.n 2f                                \n"

    "1:                                         \n"
    "   mov   sp, r1                            \n"
    "   mov   r0, #0                            \n"

    "2:                                         \n"
    "   bx r3                                   \n"
    /* Data alignment if required */
    "   nop                                     \n"

    "DATA                                       \n"
    "101:                                       \n"
    "   DC32 %c0                                \n"
    "102:                                       \n"
    "   DC32 %c1                                \n"
    "103:                                       \n"
    "   DC32 %c2                                \n"
    : /* Outputs */
    : /* Inputs */
    "i"(__section_end("CSTACK")),
    "i"(__section_begin("CSTACK")),
    "i"(&HardFault_c_handler)
    );
}
Пример #17
0
Файл: nvm.c Проект: miaofng/ulp
/*clear nvm strorage to default state*/
int nvm_clear(void)
{
	char *src, *dest, *bak;
	int sz_ram, pages;

	src = __section_begin(".nvm.ram");
	sz_ram = (int)__section_end(".nvm.ram") - (int)__section_begin(".nvm.ram");
	if(sz_ram == 0)
		return 0;
	sz_ram = align(sz_ram, 4);
	pages = align(sz_ram + 8, FLASH_PAGE_SZ) / FLASH_PAGE_SZ;
	dest = (char *)FLASH_ADDR(FLASH_PAGE_NR - pages); //rom 1
	bak = (char *)FLASH_ADDR(FLASH_PAGE_NR - pages - pages); // rom 2

	//erase rom 2
	flash_Erase(bak, pages);

	//erase rom 1
	flash_Erase(dest, pages);
	return 0;
}
Пример #18
0
/*FUNCTION**********************************************************************
 *
 * Function Name : init_data_bss
 * Description   : Make necessary initializations for RAM.
 * - Copy initialized data from ROM to RAM.
 * - Clear the zero-initialized data section.
 * - Copy the vector table from ROM to RAM. This could be an option.  
 *
 * Tool Chians:
 *   __GNUC__   : GCC
 *   __CC_ARM   : KEIL
 *   __ICCARM__ : IAR
 *
 *END**************************************************************************/
void init_data_bss(void)
{
    uint32_t n; 
    
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
#if defined(__CC_ARM)
    extern uint32_t Image$$VECTOR_ROM$$Base[];
    extern uint32_t Image$$VECTOR_RAM$$Base[];
    #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base  
    #define __VECTOR_RAM Image$$VECTOR_RAM$$Base  
#elif defined(__ICCARM__)
    extern uint32_t __VECTOR_TABLE[VECTOR_TABLE_SIZE];  
    extern uint32_t __VECTOR_RAM[VECTOR_TABLE_SIZE];  
#elif defined(__GNUC__)
    extern uint32_t __VECTOR_TABLE[];
    extern uint32_t __VECTOR_RAM[];
#endif
    
    /* Copy the vector table from ROM to RAM */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < VECTOR_TABLE_SIZE; n++)
        {
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
        }
    }

    /* Point the VTOR to the new copy of the vector table */
    SCB->VTOR = (uint32_t)__VECTOR_RAM;

#if !defined(__CC_ARM)
    
    /* Declare pointers for various data sections. These pointers
     * are initialized using values pulled in from the linker file */
    uint8_t * data_ram, * data_rom, * data_rom_end;
    uint8_t * bss_start, * bss_end;

    /* Get the addresses for the .data section (initialized data section) */
#if defined(__ICCARM__)
    data_ram = __section_begin(".data");
    data_rom = __section_begin(".data_init");
    data_rom_end = __section_end(".data_init");
    n = data_rom_end - data_rom;
#elif defined(__GNUC__)
    extern uint32_t __DATA_ROM[];
    extern uint32_t __DATA_RAM[];
    extern char __DATA_END[];
    data_ram = (uint8_t *)__DATA_RAM;
    data_rom = (uint8_t *)__DATA_ROM;
    data_rom_end  = (uint8_t *)__DATA_END;
    n = data_rom_end - data_rom;
#endif

    /* Copy initialized data from ROM to RAM */
    while (n--)
    {
        *data_ram++ = *data_rom++;
    }   
    
    /* Get the addresses for the .bss section (zero-initialized data) */
#if defined(__ICCARM__)
    bss_start = __section_begin(".bss");
    bss_end = __section_end(".bss");
#elif defined(__GNUC__)
    extern char __START_BSS[];
    extern char __END_BSS[];
    bss_start = (uint8_t *)__START_BSS;
    bss_end = (uint8_t *)__END_BSS;
#endif
		
    /* Clear the zero-initialized data section */
    n = bss_end - bss_start;
    while(n--)
    {
        *bss_start++ = 0;
    }
#endif /* __CC_ARM */
}
Пример #19
0
void
common_startup(void)
{
    /* Declare a counter we'll use in all of the copy loops */
    uint32 n;
    
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */  
    extern uint32 __vector_table[];

    /* Copy the vector table to RAM */
    if ((uint32 *)FNET_CFG_CPU_VECTOR_TABLE != __vector_table)
    {
        uint32 *vector_ram = (uint32 *)FNET_CFG_CPU_VECTOR_TABLE;
			
        for (n = 0; n < 0x410; n++)
        {
            *vector_ram++= __vector_table[n];					
        }				
    }
	
    /* Point the VTOR to the new copy of the vector table */
    write_vtor((uint32)FNET_CFG_CPU_VECTOR_TABLE);

#if FNET_CFG_COMP_CW
    {
    	RomInfo *ptr_tmp = __S_romp;
    	StaticInitializer s, *p;
    	
    	/* Zero bss section*/
    	fnet_memset(__START_BSS, 0, (__END_BSS - __START_BSS));
        
        /* Copying sections from ROM to RAM.*/
        if((uint32)ptr_tmp)
		{
			int	index;
	
			/*
			 *	Go through the entire table, copying sections from ROM to RAM.
			 */
			for (index = 0;
				 __S_romp[index].Source != 0 ||
				 __S_romp[index].Target != 0 ||
				 __S_romp[index].Size != 0;
				 ++index)
			{
				copy_rom_section( __S_romp[index].Target,
									__S_romp[index].Source,
									__S_romp[index].Size );
			} 	
		}
     	
        /*	See if the static initializer table exists	*/
        if (__sinit__)
        {
        	/*	call all static initializers in the table	*/
        	for (p = __sinit__; p && (s = *p) != 0; p++)
        		s();
        }
    }    
#endif /* FNET_CFG_COMP_CW */
    
#if FNET_CFG_COMP_IAR
    {
		/* Get the addresses for the .data section (initialized data section) */
		uint8* data_ram = __section_begin(".data");
		uint8* data_rom = __section_begin(".data_init");
		uint8* data_rom_end = __section_end(".data_init");
		
		/* Copy initialized data from ROM to RAM */
		n = data_rom_end - data_rom;
		while (n--)
		  *data_ram++ = *data_rom++;
	 
	 
		/* Get the addresses for the .bss section (zero-initialized data) */
		uint8* bss_start = __section_begin(".bss");
		uint8* bss_end = __section_end(".bss");
		
		/* Clear the zero-initialized data section */
		n = bss_end - bss_start;
		while(n--)
		  *bss_start++ = 0;    
		
		/* Get addresses for any code sections that need to be copied from ROM to RAM.
		 * The IAR tools have a predefined keyword that can be used to mark individual
		 * functions for execution from RAM. Add "__ramfunc" before the return type in
		 * the function prototype for any routines you need to execute from RAM instead 
		 * of ROM. ex: __ramfunc void foo(void);
		 */
		uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
		uint8* code_relocate = __section_begin("CodeRelocate");
		uint8* code_relocate_end = __section_end("CodeRelocate");
		
		/* Copy functions from ROM to RAM */
		n = code_relocate_end - code_relocate;
		while (n--)
		  *code_relocate_ram++ = *code_relocate++;
    }
#endif /*FNET_CFG_COMP_IAR*/    
}
Пример #20
0
void
common_startup(void)
{

#if (defined(CW))
    extern char __START_BSS[];
    extern char __END_BSS[];
    extern uint32 __DATA_ROM[];
    extern uint32 __DATA_RAM[];
    extern char __DATA_END[];
#endif

    /* Declare a counter we'll use in all of the copy loops */
    uint32 n;

    /* Declare pointers for various data sections. These pointers
     * are initialized using values pulled in from the linker file
     */
    uint8 * data_ram, * data_rom, * data_rom_end;
    uint8 * bss_start, * bss_end;


    /* Get the addresses for the .data section (initialized data section) */
#if (defined(CW))
    data_ram = (uint8 *)__DATA_RAM;
    data_rom = (uint8 *)__DATA_ROM;
    data_rom_end  = (uint8 *)__DATA_END; /* This is actually a RAM address in CodeWarrior */
    n = data_rom_end - data_ram;
#elif (defined(IAR))
    data_ram = __section_begin(".data");
    data_rom = __section_begin(".data_init");
    data_rom_end = __section_end(".data_init");
    n = data_rom_end - data_rom;
#endif

    /* Copy initialized data from ROM to RAM */
    while (n--)
        *data_ram++ = *data_rom++;


    /* Get the addresses for the .bss section (zero-initialized data) */
#if (defined(CW))
    bss_start = (uint8 *)__START_BSS;
    bss_end = (uint8 *)__END_BSS;
#elif (defined(IAR))
    bss_start = __section_begin(".bss");
    bss_end = __section_end(".bss");
#endif




    /* Clear the zero-initialized data section */
    n = bss_end - bss_start;
    while(n--)
        *bss_start++ = 0;

    /* Get addresses for any code sections that need to be copied from ROM to RAM.
     * The IAR tools have a predefined keyword that can be used to mark individual
     * functions for execution from RAM. Add "__ramfunc" before the return type in
     * the function prototype for any routines you need to execute from RAM instead
     * of ROM. ex: __ramfunc void foo(void);
     */
#if (defined(IAR))
    uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
    uint8* code_relocate = __section_begin("CodeRelocate");
    uint8* code_relocate_end = __section_end("CodeRelocate");

    /* Copy functions from ROM to RAM */
    n = code_relocate_end - code_relocate;
    while (n--)
        *code_relocate_ram++ = *code_relocate++;
#endif
}
Пример #21
0
void CLI_Exec(void)
{
    uint8_t index;
    uint8_t argc;
    char*   argv[ARGV_MAX_SIZE];

    // Òì³£ÅжÏ
    if(Command_Ready == false)
    {
        goto __EXIT;
    }

    if(Buffer_Index == 1)
    {
        goto __EXIT;
    }

    // ²ÎÊý½âÎö
    argv[0] = strtok(Buffer, " ");

    for(index = 1; index < ARGV_MAX_SIZE; index ++)
    {
        argv[index] = strtok(NULL, " ");
        if(argv[index] == NULL)
            break;
    }

    argc = index;


    // ÃüÁî·Ö·¢
    struct COMMAND_ENTRY* entry_seek;
    struct COMMAND_ENTRY* entry_tail;

    entry_seek = __section_begin("COMMAND_ENTRY");
    entry_tail = __section_end("COMMAND_ENTRY");

    for(; entry_seek < entry_tail; ++entry_seek)
    {
        if( strcmp(argv[0], entry_seek->name) )
            continue;

        if( (argc < entry_seek->min_argc) ||
            (argc > entry_seek->max_argc) )
        {// arg error
            showHelp(entry_seek);
            goto __EXIT;
        }

        if(entry_seek->command != 0)
        {
            entry_seek->command(argc-1, &argv[1]);
        }
    }

    showPrompt();

  __EXIT:
    Command_Ready = false;
    Buffer_Index = 0;

}
void
common_startup(void)
{

#if (defined(CW))	
    extern char __START_BSS[];
    extern char __END_BSS[];
    extern uint32 __DATA_ROM[];
    extern uint32 __DATA_RAM[];
    extern char __DATA_END[];
#endif

    /* 声明一个计数器在拷贝循环中使用 */
    uint32 n;

    /* 为不同的数据段定义指针。
     * 这些变量将由链接文件中获取的值初始化
     */
    uint8 * data_ram, * data_rom, * data_rom_end;
    uint8 * bss_start, * bss_end;


    /* 引进链接文件中的VECTOR_TABLE和VECTOR_RAM的地址 */
    extern uint32 __VECTOR_TABLE[];
    extern uint32 __VECTOR_RAM[];

    /* 将中断向量表复制到RAM中 */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < 0x410; n++)
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
    }
    /* 将新的中断向量表指针赋给VTOR寄存器 */
    write_vtor((uint32)__VECTOR_RAM);

    /* 获得.data段的地址(已初始化的数据段) */
	#if (defined(CW))
        data_ram = (uint8 *)__DATA_RAM;
	    data_rom = (uint8 *)__DATA_ROM;
	    data_rom_end  = (uint8 *)__DATA_END; /* 该段在CodeWarrior编译器中为RAM地址 */
	    n = data_rom_end - data_ram;
    #elif (defined(IAR))
		data_ram = __section_begin(".data");
		data_rom = __section_begin(".data_init");
		data_rom_end = __section_end(".data_init");
		n = data_rom_end - data_rom;
	#endif		
		
	/* 从ROM复制已初始化的数据到RAM */
	while (n--)
		*data_ram++ = *data_rom++;
	
	
    /* 获得.bss段的地址 (初始化为0的数据) */
	#if (defined(CW))
		bss_start = (uint8 *)__START_BSS;
		bss_end = (uint8 *)__END_BSS;
	#elif (defined(IAR))
		bss_start = __section_begin(".bss");
		bss_end = __section_end(".bss");
	#endif
		
		
	

    /* 清零初始化为0的数据段 */
    n = bss_end - bss_start;
    while(n--)
      *bss_start++ = 0;

	/* 取得所有应该从ROM复制到RAM的代码段的地址。
         * IAR有一个预定义的关键字可以标记独立的函数为从RAM执行。
         * 在函数的返回类型前添加"__ramfunc"关键字可以将函数标记为从RAM中执行。
         * 例如:__ramfunc void foo(void);
	 */
	#if (defined(IAR))
		uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
		uint8* code_relocate = __section_begin("CodeRelocate");
		uint8* code_relocate_end = __section_end("CodeRelocate");

		/* 将函数从ROM复制到RAM */
		n = code_relocate_end - code_relocate;
		while (n--)
			*code_relocate_ram++ = *code_relocate++;
	#endif
}
Пример #23
0
/*
** Main function. The application starts here.
*/
int main(void)
{
    unsigned char rxByte;
    unsigned int value = (unsigned int)E_FAIL;

    #ifdef __TMS470__
    /* Relocate the required section to internal RAM */
    memcpy((void *)(&relocstart), (const void *)(&iram_start),
           (unsigned int)(&iram_size));
    #elif defined(__IAR_SYSTEMS_ICC__)
    #pragma section = "CodeRelocOverlay"
    #pragma section = "DataRelocOverlay"
    #pragma section = "DataOverlayBlk"
    #pragma section = "CodeOverlayBlk"
    char* srcAddr = (__section_begin("CodeRelocOverlay"));
    char* endAddr = (__section_end("DataRelocOverlay"));

    memcpy((void *)(__section_begin("CodeRelocOverlay")),
           (const void *)(__section_begin("CodeOverlayBlk")),
           endAddr - srcAddr);

    #else
    memcpy((void *)&(relocstart), (const void *)&(iram_start),
           (unsigned int)(((&(relocend)) -
            (&(relocstart))) * (sizeof(unsigned int))));
    #endif

    MMUConfigAndEnable();    

    /* Enable Instruction Cache */
    CacheEnable(CACHE_ALL);

    PeripheralsSetUp();

    /* Initialize the ARM Interrupt Controller */
    IntAINTCInit();

    /* Register the ISRs */  
    Timer2IntRegister();
    Timer4IntRegister();
    EnetIntRegister();
    RtcIntRegister();
    CM3IntRegister();
    HSMMCSDIntRegister();
    IntRegister(127, dummyIsr);

    IntMasterIRQEnable();

    pageIndex = 0;
    prevAction = 0;

    /* Enable system interrupts */
    IntSystemEnable(SYS_INT_RTCINT);
    IntPrioritySet(SYS_INT_RTCINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWTXINT0);
    IntPrioritySet(SYS_INT_3PGSWTXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWRXINT0);
    IntPrioritySet(SYS_INT_3PGSWRXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT2);
    IntPrioritySet(SYS_INT_TINT2, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT4);
    IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ);	
    IntSystemEnable(SYS_INT_MMCSD0INT);
    IntPrioritySet(SYS_INT_MMCSD0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_EDMACOMPINT);
    IntPrioritySet(SYS_INT_EDMACOMPINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntPrioritySet(SYS_INT_M3_TXEV, 0, AINTC_HOSTINT_ROUTE_IRQ );
    IntSystemEnable(SYS_INT_M3_TXEV);
    IntSystemEnable(127);
    IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ);

    IntSystemEnable(SYS_INT_UART0INT);
    IntPrioritySet(SYS_INT_UART0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_UART0INT, uartIsr);

     /*	GPIO interrupts	*/
    IntSystemEnable(SYS_INT_GPIOINT0A);
    IntPrioritySet(SYS_INT_GPIOINT0A, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_GPIOINT0A, gpioIsr);
    IntSystemEnable(SYS_INT_GPIOINT0B);
    IntPrioritySet(SYS_INT_GPIOINT0B, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_GPIOINT0B, gpioIsr);

    BoardInfoInit();
    deviceVersion = DeviceVersionGet();

    CM3EventsClear();
    CM3LoadAndRun();
    waitForM3Txevent();

    /* Initialize console for communication with the Host Machine */
    ConsoleUtilsInit();

    /*
    ** Select the console type based on compile time check
    ** Note: This example is not fully complaint to semihosting. It is
    **       recommended to use Uart console interface only.
    */
    ConsoleUtilsSetType(CONSOLE_UART);

    /* Print Board and SoC information on console */
    ConsoleUtilsPrintf("\n\r Board Name          : %s", BoardNameGet());
    ConsoleUtilsPrintf("\n\r Board Version       : %s", BoardVersionGet());
    ConsoleUtilsPrintf("\n\r SoC Version         : %d", deviceVersion);

    /* On CM3 init firmware version is loaded onto the IPC Message Reg */
    ConsoleUtilsPrintf("\n CM3 Firmware Version: %d", readCM3FWVersion());

    I2CIntRegister(I2C_0);
    IntPrioritySet(SYS_INT_I2C0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_I2C0INT);
    I2CInit(I2C_0);

    IntSystemEnable(SYS_INT_TINT1_1MS);
    IntPrioritySet(SYS_INT_TINT1_1MS, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_TINT1_1MS,clearTimerInt);

    configVddOpVoltage();
    RtcInit();
    HSMMCSDContolInit();
    DelayTimerSetup();

    initializeTimer1();
    ConsoleUtilsPrintf("\r\n After intializing timer");
    Timer2Config();
    Timer4Config();
    LedIfConfig();
    MailBoxInit();

    Timer2IntEnable();
    Timer4IntEnable();
    RtcSecIntEnable();
    	
    Timer4Start(); 
    while(FALSE == tmr4Flag);
    tmr4Flag = FALSE;
    Timer4Stop();

    ConsoleUtilsPrintf("\n\r Configuring for maximum OPP");
    mpuOpp = ConfigMaximumOPP();

    mpuFreq = FrequencyGet(mpuOpp);
    mpuVdd1 = VddVoltageGet(mpuOpp);
    PrintConfigDVFS();

    /*  Create menu page */
    pageIndex = MENU_IDX_MAIN;

    ActionEnetInit();

    /*
    ** Loop for ever. Necessary actions shall be taken
    ** after detecting the click.
    */
    while(1)
    {
        /*
        ** Check for any any activity on Uart Console and process it.
        */
        if (true == UARTCharsAvail(SOC_UART_0_REGS))
        {

            /* Receiving bytes from the host machine through serial console. */
            rxByte = UARTGetc();

            /*
            ** Checking if the entered character is a carriage return.
            ** Pressing the 'Enter' key on the keyboard executes a
            ** carriage return on the serial console.
            */
            if('\r' == rxByte)
            {
                ConsoleUtilsPrintf("\n");
                UartAction(value);
                value = (unsigned int)E_FAIL;
                rxByte = 0;
            }

            /*
            ** Checking if the character entered is one among the decimal
            ** number set 0,1,2,3,....9
            */
            if(('0' <= rxByte) && (rxByte <= '9'))
            {
                ConsoleUtilsPrintf("%c", rxByte);

                if((unsigned int)E_FAIL == value)
                {
                    value = 0;
                }

                value = value*10 + (rxByte - 0x30);
            }

        }

         /*
         ** Check if click is detected
         */
         if(clickIdx != 0)
         {
             /*
             ** Take the Action for click
             */
             ClickAction();

             clickIdx = 0;
         }
       
         /*
         ** Check if the Timer Expired
         */ 
         if(TRUE == tmrFlag)
         {
             /* Toggle the LED state */
             LedToggle();
             tmrFlag = FALSE;
         }
 
         /*
         ** Check if RTC Time is set
         */
         if(TRUE == rtcSetFlag)
         {
             if(TRUE == rtcSecUpdate)
             { 
                 rtcSecUpdate = FALSE;
                 RtcTimeCalDisplay();
                 ConsoleUtilsPrintf(" --- Selected:  ");
             }
         } 
   
         if(TRUE == tmr4Flag)
         {
            tmr4Flag = FALSE;
             /* Make sure that interrupts are disabled and no lwIP functions
                are executed while calling an lwIP exported API */
             IntMasterIRQDisable();
             etharp_tmr();
             IntMasterIRQEnable();
         }
    }
}
Пример #24
0
/*
 * @ingroup finsh
 *
 * This function will initialize finsh shell
 */
int finsh_system_init(void)
{
	rt_err_t result;

#ifdef FINSH_USING_SYMTAB
#ifdef __CC_ARM                 /* ARM C Compiler */
    extern const int FSymTab$$Base;
    extern const int FSymTab$$Limit;
    extern const int VSymTab$$Base;
    extern const int VSymTab$$Limit;
	finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
	finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit);
#elif defined (__ICCARM__)      /* for IAR Compiler */
    finsh_system_function_init(__section_begin("FSymTab"),
                               __section_end("FSymTab"));
    finsh_system_var_init(__section_begin("VSymTab"),
                          __section_end("VSymTab"));
#elif defined (__GNUC__) || defined(__TI_COMPILER_VERSION__)
    /* GNU GCC Compiler and TI CCS */
	extern const int __fsymtab_start;
	extern const int __fsymtab_end;
	extern const int __vsymtab_start;
	extern const int __vsymtab_end;
	finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
	finsh_system_var_init(&__vsymtab_start, &__vsymtab_end);
#elif defined(__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
    finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
    finsh_system_var_init(&__vsymtab_start, &__vsymtab_end);
#elif defined(_MSC_VER)
	unsigned int *ptr_begin, *ptr_end;

	ptr_begin = (unsigned int*)&__fsym_begin; ptr_begin += (sizeof(struct finsh_syscall)/sizeof(unsigned int));
	while (*ptr_begin == 0) ptr_begin ++;

	ptr_end = (unsigned int*) &__fsym_end; ptr_end --;
	while (*ptr_end == 0) ptr_end --;

	finsh_system_function_init(ptr_begin, ptr_end);
#endif
#endif

	/* create or set shell structure */
#ifdef RT_USING_HEAP
	shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell));
#else
	shell = &_shell;
#endif
	if (shell == RT_NULL)
	{
		rt_kprintf("no memory for shell\n");
		return -1;
	}
	
	memset(shell, 0, sizeof(struct finsh_shell));

	rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
	result = rt_thread_init(&finsh_thread,
		"tshell",
		finsh_thread_entry, RT_NULL,
		&finsh_thread_stack[0], sizeof(finsh_thread_stack),
		FINSH_THREAD_PRIORITY, 10);

	if (result == RT_EOK)
		rt_thread_startup(&finsh_thread);
	return 0;
}
Пример #25
0
//------------------------------------------------------------------------------
///  Run all init handlers from level 1 to level 7
///  \return 0 succeed, other value failure
//-----------------------------------------------------------------------------
unsigned int RunAllInit()
{
  T_INIT *pInitSecStart, *pInitSecEnd, *pInitTmp;

#if defined(__ICCARM__)
  
  pInitSecStart = __section_begin(".gs_initsection");
  pInitSecEnd   = __section_end(".gs_initsection");
  
#elif defined(__CC_ARM)
  
  pInitSecStart   = (T_INIT *)&Image$$GS_Init_Region$$Base;
  pInitSecEnd     = (T_INIT *)&Image$$GS_Init_Region$$Limit;
 
#elif defined(__GNUC__)
  
  pInitSecStart   = (T_INIT *)&__gs_init_section_start;
  pInitSecEnd     = (T_INIT *)&__gs_init_section_end;
   
#else
  
#error "Unsupported tool chain!"
  
#endif
  
  //count init handler number
  int iInitNum = pInitSecEnd - pInitSecStart;
  
  unsigned int i, iLvlTmp, iLvlMin = 0, iLvlMax = 0xffffffff;
  
  iLvlTmp = 0;
  
  while(iLvlMin <= iLvlMax && iInitNum > 0) {
    
    pInitTmp = pInitSecStart;
    for(i = 0; i < iInitNum && pInitTmp <= pInitSecEnd; ++i, ++pInitTmp) {
      
      if(iLvlMin == 0)
        iLvlMin = pInitTmp->initlvl;
      
      if(iLvlMax == 0xffffffff)
        iLvlMax = pInitTmp->initlvl;
      
      if(pInitTmp->initlvl > iLvlMax)
        iLvlMax = pInitTmp->initlvl;
      
      if((pInitTmp->initlvl > iLvlTmp && pInitTmp->initlvl < iLvlMin) ||
         (pInitTmp->initlvl > iLvlTmp && iLvlMin == iLvlTmp))
        iLvlMin = pInitTmp->initlvl;
      
      //run initHanddler
      if(pInitTmp->initlvl == iLvlTmp)
        pInitTmp->pfInitFunc();
    }
    
    if(iLvlTmp == iLvlMax)
      break;
    
    iLvlTmp = iLvlMin;    
  }
    
  return 0;
}
Пример #26
0
/*FUNCTION**********************************************************************
 *
 * Function Name : init_data_bss
 * Description   : Make necessary initializations for RAM.
 * - Copy initialized data from ROM to RAM.
 * - Clear the zero-initialized data section.
 * - Copy the vector table from ROM to RAM. This could be an option.
 *
 * Tool Chians:
 *   __GNUC__   : GCC
 *   __CC_ARM   : KEIL
 *   __ICCARM__ : IAR
 *
 *END**************************************************************************/
void init_data_bss(void)
{
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
#if defined(__CC_ARM)
    extern uint32_t Image$$VECTOR_ROM$$Base[];
    extern uint32_t Image$$VECTOR_RAM$$Base[];
    extern uint32_t Image$$RW_m_data$$Base[];

    #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
    #define __VECTOR_RAM Image$$VECTOR_RAM$$Base
    #define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base))
#elif defined(__ICCARM__)
    extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
    extern uint32_t __VECTOR_TABLE[];
    extern uint32_t __VECTOR_RAM[];
#elif defined(__GNUC__)
    extern uint32_t __VECTOR_TABLE[];
#endif

#if (defined(__ICCARM__))
    SCB->VTOR = (uint32_t)__section_begin(".intvec");
#else
    SCB->VTOR = (uint32_t)__VECTOR_TABLE;
#endif

#if !defined(__CC_ARM)

    /* Declare pointers for various data sections. These pointers
     * are initialized using values pulled in from the linker file */
    uint8_t * data_ram, * data_rom, * data_rom_end;
    uint8_t * bss_start, * bss_end;
    uint32_t n;

    // Get the addresses for the .data section (initialized data section)
#if defined(__GNUC__)
    extern uint32_t __DATA_ROM[];
    extern uint32_t __DATA_RAM[];
    extern char __DATA_END[];
    data_ram = (uint8_t *)__DATA_RAM;
    data_rom = (uint8_t *)__DATA_ROM;
    data_rom_end  = (uint8_t *)__DATA_END; // This is actually a RAM address in CodeWarrior
    n = data_rom_end - data_rom;
#elif (defined(__ICCARM__))
    data_ram = __section_begin(".data");
    data_rom = __section_begin(".data_init");
    data_rom_end = __section_end(".data_init");
    n = data_rom_end - data_rom;
#endif

    if (data_ram != data_rom)
    {
        // Copy initialized data from ROM to RAM
        while (n)
        {
            *data_ram++ = *data_rom++;
            n--;
        }
    }

    // Get the addresses for the .bss section (zero-initialized data)
#if defined(__GNUC__)
    extern char __START_BSS[];
    extern char __END_BSS[];
    bss_start = (uint8_t *)__START_BSS;
    bss_end = (uint8_t *)__END_BSS;
#elif (defined(__ICCARM__))
    bss_start = __section_begin(".bss");
    bss_end = __section_end(".bss");
#endif


    // Clear the zero-initialized data section
    n = bss_end - bss_start;
    while(n)
    {
        *bss_start++ = 0;
        n--;
    }

    /* Get addresses for any code sections that need to be copied from ROM to RAM.
     * The IAR tools have a predefined keyword that can be used to mark individual
     * functions for execution from RAM. Add "__ramfunc" before the return type in
     * the function prototype for any routines you need to execute from RAM instead
     * of ROM. ex: __ramfunc void foo(void);
     */
#if (defined(__ICCARM__))
    uint8_t* code_relocate_ram = __section_begin("CodeRelocateRam");
    uint8_t* code_relocate = __section_begin("CodeRelocate");
    uint8_t* code_relocate_end = __section_end("CodeRelocate");

    // Copy functions from ROM to RAM
    n = code_relocate_end - code_relocate;
    while (n)
    {
        *code_relocate_ram++ = *code_relocate++;
        n--;
    }
#endif
#endif /* !__CC_ARM && !__ICCARM__*/
}
Пример #27
0
/* Make sure that this function is at 0x20000000, don't initialize any
   local variable while declaring in this function */
void GsnStartup_Main( void )
{
    unsigned int* bssEnd = __section_end("BSS_SECTION");
    unsigned int* bssStart = __section_begin("BSS_SECTION");
    unsigned int* dataEnd = __section_end("DATA_SECTION");
    unsigned int* dataStart = __section_begin("DATA_SECTION");
    unsigned int* dataInitStart = __section_begin("DATA_INIT_SECTION");
    unsigned int* romPatchFptEnd = __section_end("ROM_PATCH_FPT_SECTION");
    unsigned int* romPatchFptStart = __section_begin("ROM_PATCH_FPT_SECTION");
    unsigned int* appCodeEnd = __section_end("APP_CODE_SECTION");
    unsigned int* appCodeStart = (unsigned int*)APP_CODE_START;
    unsigned int length, src, dst,  heap1Start, heap2Start;

    int heap1Length, heap2Length;


	/* 2. Copy from flash to initialize the "initialised data" in data	segment.
    The Data init secion can be used as heap once the below copy is done. For
    now we are not doing this  */
	length = (unsigned int)( dataEnd )- (unsigned int)(dataStart);
	src = (unsigned int)dataInitStart; /* Location in Flash */
	dst = (unsigned int)dataStart; /* RAM location to copy, i.e. the DATA section */
    APP_STARTUP_COPY_PROG(src, length, dst);
	
	/*
     * Copy patch function pointers from the flash to the SRAM.
       The ROM PATCH secion can be used as heap once the below copy is done. For
       now we are not doing this. ROM PATCH and DATA INIT section seems to be
       contiguous. So both the section can be clubed to one and can be made as
       one single  heap  */
    length = (unsigned int)( romPatchFptEnd )- (unsigned int)(romPatchFptStart);
    src = (unsigned int)romPatchFptStart;/* Location in Flash for ROM PATCH FPT */
    dst = GSN_ROM_PATCH_FPT_LOCATION;/* RAM location to copy */
    APP_STARTUP_COPY_PROG(src, length,  dst );


	/* Won't be copying the APP code. Calculate the heap at the end*/
	heap1Start = (((unsigned int)&GsnSramFreeMem) & ~0x3) + 0x8;
	heap1Length = (unsigned int)(appCodeStart)  - heap1Start;
	if( heap1Length < 0 )
	{
		/* ERROR APP CODE Section is more than what it can fit in the SRAM. */
		while(1);
	}
	heap2Start = (((unsigned int)appCodeEnd) & ~0x3) + 0x8;
	heap2Length = SRAM_END_ADDR - heap2Start;

	
	/*
	* Initialize BSS segment.
	*/
    /* 1. memset uninitailize data.*/
    src = (unsigned int)bssStart;
    length = (unsigned int)( bssEnd )- (unsigned int)( bssStart );
    memset((void*) src, 0, length );


    /* Initialize the free memory section to use tx byte pool for dynamic memory
       allocation */
	/*Note : bytePool[0] is already created in rom_main.c */
    tx_byte_pool_create(&bytePool[0].bPool, NULL, (void*)heap1Start,
                               (UINT32)heap1Length );

    tx_byte_pool_create(&bytePool[1].bPool, NULL, (void*)heap2Start,
                               (UINT32)heap2Length );
   


	pGsnBytePoolHead =  ( heap2Length > heap1Length ) ?
					&bytePool[1] : &bytePool[0];
	pGsnBytePoolHead->pNext = ( heap2Length > heap1Length ) ?
					&bytePool[0] : &bytePool[1];
	pGsnBytePoolHead->pNext->pNext = NULL;


    /* Assign 3 SRAM blocks to wlan*/
    *((volatile UINT32 *)(0x40080008)) = (UINT32)0x1c;
	//*((volatile UINT32 *)(0x40080008)) = (UINT32)0x78;

	/* Call APP MAIN */
    App_Main();
    //while(1);
    App_IdleHandlerLoop();
}