Exemple #1
0
FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
  uintptr_t topaddr;

  /* Align the frame_size */

  frame_size = STACK_ALIGN_UP(frame_size);

  /* Is there already a stack allocated? Is it big enough? */

  if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
    {
      return NULL;
    }

  /* Save the adjusted stack values in the struct tcb_s */

  topaddr              = (uintptr_t)tcb->adj_stack_ptr - frame_size;
  tcb->adj_stack_ptr   = (FAR void *)topaddr;
  tcb->adj_stack_size -= frame_size;

  /* Reset the initial state */

  up_initial_state(tcb);

  /* And return a pointer to the allocated memory */

  return (FAR void *)(topaddr + sizeof(uint32_t));
}
Exemple #2
0
FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
  uintptr_t topaddr;

  /* Align the frame_size */

  frame_size = STACK_ALIGN_UP(frame_size);

  /* Is there already a stack allocated? Is it big enough? */

  if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
    {
      return NULL;
    }

  /* Save the adjusted stack values in the struct tcb_s */

  topaddr               = (uintptr_t)tcb->adj_stack_ptr - frame_size;
  tcb->adj_stack_ptr    = (FAR void *)topaddr;
  tcb->adj_stack_size  -= frame_size;

  /* Reset the initial stack pointer */

  tcb->xcp.regs[REG_SPH] = (uint16_t)tcb->adj_stack_ptr >> 8;
  tcb->xcp.regs[REG_SPL] = (uint16_t)tcb->adj_stack_ptr & 0xff;

  /* And return the pointer to the allocated region */

  return (FAR void *)(topaddr + sizeof(uint16_t));
}
Exemple #3
0
VAR_t p_pos_initTask(POSTASK_t task, UINT_t stacksize, POSTASKFUNC_t funcptr, void *funcarg)
{

  unsigned int z;

  stacksize = STACK_ALIGN_UP(stacksize);
  task->stack = NOS_MEM_ALLOC(stacksize);
  if (task->stack == NULL)
    return -1;

  task->stackSize = stacksize;

#if POSCFG_ARGCHECK > 1
  nosMemSet(task->stack, PORT_STACK_MAGIC, stacksize);
#endif

  z = (unsigned int) task->stack + stacksize;
  constructStackFrame(task, (void*) z, funcptr, funcarg);
  return 0;
}
Exemple #4
0
void Reset_Handler(void)
{
  unsigned int *src, *dst;

  /*
   *  Copy data section from flash to RAM
   */
  src = __data_load_start;
  dst = __data_start;
  while (dst < _edata)
    *dst++ = *src++;

  /*
   *  Clear the bss section
   */
  dst = __bss_start;
  while (dst < __bss_end)
    *dst++ = 0;

  /*
   * Start heap after .bss segment, align it upwards.
   * Reserve IRQ stack at top of memory, heap end before it.
   */
  portIrqStack = (void*) STACK_ALIGN_UP((unsigned int) __stack - PORTCFG_IRQ_STACK_SIZE + 1);

#if POSCFG_ENABLE_NANO != 0
#if NOSCFG_FEATURE_MEMALLOC == 1 && NOSCFG_MEM_MANAGER_TYPE == 1
  __heap_end   = (void*) (portIrqStack - PORT_STACK_ALIGNMENT);
  __heap_start = (void*) STACK_ALIGN_UP((unsigned int) _end);
#endif
#endif

#if POSCFG_ARGCHECK > 1

  /*
   * Fill unused portion of IRQ stack with PORT_STACK_MAGIC.
   */
  register uint32_t sp asm("sp");
  register uint32_t si      = sp - 10; // Just to be sure not to overwrite anything
  register unsigned char* s = (unsigned char*) si;

  while (s >= portIrqStack)
  *(s--) = PORT_STACK_MAGIC;

  *s = 0;// Separator between lowest stack location and heap

#if POSCFG_ENABLE_NANO != 0
#if NOSCFG_FEATURE_MEMALLOC == 1 && NOSCFG_MEM_MANAGER_TYPE == 1

  s = (unsigned char*) __heap_start;
  while (s <= (unsigned char*) __heap_end)
  *(s++) = 'H';

#endif
#endif
#endif

  main();
  while (1)
    ;
}