System Calls cleanup, multiple Processes and context switch
[cortex-from-scratch] / systick.c
index 589e286..f459512 100644 (file)
--- a/systick.c
+++ b/systick.c
@@ -37,8 +37,37 @@ struct interrupt_frame {
 void * systick_handler(/* struct interrupt_frame * frame */) {
 
        printf("Ticking...\n");
+
+}
+
+
+__attribute__ ((naked))
+               void * pendsv_handler_c(void) {
+//
+//     asm volatile ("push {r0-r11, lr}");
+//     asm volatile ("mrs %0, psp" : "=r" (oldpsp));
+//     asm volatile ("push {lr}");
+//
+//     //asm volatile ("push {lr}");
+//     
+//     //printf("FROM MSP %x", oldpsp);
+//     //PSP_array[curr_task] = oldpsp;
+//     //curr_task = next_task;
+//     //newpsp = PSP_array[next_task];        
+//
+//     asm volatile ("msr psp, %0" : : "r" (newpsp)); 
+//
+//     asm volatile("pop {lr}");
+//     //asm volatile ("pop {r0-r12}");
+//     asm volatile("bx lr"); // return
 }
 
+uint32_t set_psp(uint32_t) __attribute__( ( naked ) );
+uint32_t set_psp(uint32_t stackie) {
+  
+       asm volatile ("msr psp, r0" "\n\t"
+                 "bx lr");
+}
 
 void systick_init() {
 
@@ -50,7 +79,7 @@ void systick_init() {
        /* Get calibration and set this to 1 sec
         * !Most boards have a 1 ms or 10 ms 
         * calibration value */
-       int calib = (*STK_CALIB << 0) * 500;
+       int calib = (*STK_CALIB << 0) * 200;
 
        /* The counter reload registers counts down to zero
         * and then it is restores the value */
@@ -61,5 +90,4 @@ void systick_init() {
        rsetbit(STK_CTRL, 0);
        rsetbit(STK_CTRL, 1);
 
-
 }