Guys, I'm having trouble with floats in my RTOS tht I have ported to SAMA5D44. I think the error is caused by the function that creates the context for the floating registers. I have listed it below removing a lot of the code that I feel you do not need to see.
struct task_ctrl_obj * api_program(void(*task)(void), char const * name, void * variable_pass, unsigned int mpu_mem, unsigned char priority, unsigned char ceiling ){ unsigned int program = (unsigned int)task & ~1u; /* Mask off lower bit in case task is thumb mode */ /* Mask off lower bit in case task is thumb mode */ /* * Setup general purpose registers */ * cpu_core_stack-- = (unsigned int) program; /* PC */ * cpu_core_stack-- = (unsigned int) internal_task_destructor; /* LR: Supervisor mode */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R12 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R11 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R10 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R9 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R8 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R7 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R6 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R5 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R4 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R3 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R2 */ * cpu_core_stack-- = (unsigned int) 0x00000000; /* R1 */ * cpu_core_stack-- = (unsigned int) variable_pass; /* R0 ARGUMENT PASS */ #define OS_CPU_ARM_BIT_CPSR_MODE_SUPERVISOR 0x13u #define OS_CPU_ARM_BIT_CPSR_T (1u << 5u) // Setup Status registers if (((unsigned int)task & 0x01u) == 0x01u) { /* See if task runs in Thumb or ARM mode */ *cpu_core_stack-- = (OS_CPU_ARM_BIT_CPSR_MODE_SUPERVISOR /* Set supervisor mode. */ | OS_CPU_ARM_BIT_CPSR_T); /* Set Thumb mode. */ } else { *cpu_core_stack-- = (0x00000100 | OS_CPU_ARM_BIT_CPSR_MODE_SUPERVISOR); } { /* * Setup Floating Point registers **/ *cpu_core_stack-- = 0x00000000; /* Initialise Floating point status & control register */ for (int i = 0; i < 32; i++) * cpu_core_stack-- = 0x00000000; /* Initialise general-purpose Floating point registers */ * cpu_core_stack = 0x40000000; /* Initialise Floating-Point Exception Register (Enable)*/ } // Insert Newly created task on to the Kernel internal_kernel_insert_task(tcb); // insert task ctrl block unto Kernel Schedular tcb->stack_ptr = (unsigned char *)cpu_core_stack; // Store Stack pointer unto the task ctrl block return(tcb); // Return Handle to the newly Created Task }
The part of interest is:
#define OS_CPU_ARM_BIT_CPSR_MODE_SUPERVISOR 0x13u #define OS_CPU_ARM_BIT_CPSR_T (1u << 5u) // Setup Status registers if (((unsigned int)task & 0x01u) == 0x01u) { /* See if task runs in Thumb or ARM mode */ *cpu_core_stack-- = (OS_CPU_ARM_BIT_CPSR_MODE_SUPERVISOR /* Set supervisor mode. */ | OS_CPU_ARM_BIT_CPSR_T); /* Set Thumb mode. */ } else { *cpu_core_stack-- = (0x00000100 | OS_CPU_ARM_BIT_CPSR_MODE_SUPERVISOR); } { /* * Setup Floating Point registers **/ *cpu_core_stack-- = 0x00000000; /* Initialise Floating point status & control register */ for (int i = 0; i < 32; i++) * cpu_core_stack-- = 0x00000000; /* Initialise general-purpose Floating point registers */ * cpu_core_stack = 0x40000000; /* Initialise Floating-Point Exception Register (Enable)*/ }
Any advise is very much welcome.