kosmos/source/firmware/arch/stm32f4xx/stm32f4xx_stack._c

39 lines
706 B
Plaintext
Raw Normal View History

2016-07-28 19:02:54 +00:00
/*
* stm32f4xx_stack.c
*
* Created on: Oct 1, 2015
* Author: tkl
*/
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "stm32f4xx_stack.h"
#include "queue.h"
#include "thread.h"
#include "kernel.h"
stack_t *stack_init(
void (*task_func)(void *),
void *arg,
stack_t *stack_start,
unsigned int stack_size)
{
stack_t *stk;
stk = (stack_t *)(stack_start + stack_size);
stk--;
*stk = 0x01000000; // xPSR
stk--;
*stk = (stack_t) task_func; // PC
stk--;
*stk = (stack_t) thread_exit; // LR
stk -= 5; // R12, R3, R2 and R1.
*stk = (stack_t) arg; // R0
stk--;
*stk = 0xfffffffd;
stk -= 8; // R11, R10, R9, R8, R7, R6, R5 and R4.
return stk;
}