1 
  2 #include <msp430.h>
  3 #include <stdio.h>
  4 #include <string.h>
  5 #include <stdlib.h>
  6 
  7 #include "contiki.h"
  8 #include "contiki-net.h"
  9 #include "sys/mt.h"
 10 
 11 #include "config.h"
 12 #include "ta_mod.h"
 13 
 14 #include <sancus_support/elf.h>
 15 #include <sancus_support/global_symtab.h>
 16 #include <sancus_support/sm_control.h>
 17 
 18 
 19 DECLARE_SM(TACore, 0x1234);
 20 
 21 
 22 #ifdef __DEBUG
 23 #ifdef __SANCUS_MSP430
 24   #include "util/memcpy.c"
 25 #endif
 26 #endif
 27 
 28 
 29 int SM_DATA(TA_SM_NAME) TAInitialised = 0;
 30 
 31 #if (TA_SCHEDULER_PROTECTION == 1)
 32   #include "ta_mod_scheduler.c"
 33 #endif
 34 
 35 
 36 /*---------------------------------------------------------------------------*/
 37 /* TAInit()                                                                  */
 38 
 39 static int SM_FUNC(TA_SM_NAME) TAInit (void)
 40 {
 41 
 42   if (! TAInitialised) {
 43     TAInvarInit ();
 44     TAProcInit ();
 45 
 46     TAInitialised = 1;
 47   }
 48 
 49   return (TA_SUCCESS);
 50 }
 51 
 52 
 53 /*---------------------------------------------------------------------------*/
 54 /* Interface Function: TAMainFunc() -- main() of the TA module.              */
 55 
 56 int SM_ENTRY(TA_SM_NAME) TAMainFunc (process_event_t ev)
 57 {
 58   __TIMING_INIT();
 59 
 60 #ifdef __TIMING
 61   volatile int tmp;
 62   if (!TAInitialised) {
 63     tmp = NoTAEntryPoint();
 64     __TIMING_PRINT("+++ unprot call from prot code: ");
 65     __TIMING_REINIT();
 66     tmp = TAEntryPoint();
 67     __TIMING_PRINT("+++ sm_entry call from prot code: ");
 68     __TIMING_REINIT();
 69   }
 70 #endif
 71 
 72   if (!TAInitialised) {
 73     TAInit ();
 74   }
 75 
 76   // This needs to be done after processes are initialised.
 77   if (ev == PROCESS_EVENT_TIMER && TAInitialised == 1) {
 78 #if (PROTECT_IVTBL == 1)
 79     // protect Interrupt Vector Table
 80     // 0000ffe0 <__ivtbl_16>: 32 bytes
 81     TARegisterInvar((void *) 0xffe0,32);
 82 #endif
 83 
 84 #if (TA_PROCESS_INSPECTOR == 1)
 85     TAScanProcessesInit();
 86 #endif
 87 
 88     TAInitialised = 2;
 89   }
 90 
 91   __TIMING_PRINT("+++ TAMainFunc(): initialisation ");
 92   __TIMING_REINIT();
 93 
 94 #if (TA_PROCESS_INSPECTOR == 1)
 95   TACheckProcesses();
 96   __TIMING_PRINT("+++ TACheckProcesses(): ");
 97   __TIMING_REINIT();
 98 #endif
 99   TACheckInvars ();
100   __TIMING_PRINT("+++ TACheckInvars(): ");
101 
102   return (TA_SUCCESS);
103 }
104 
105 /*---------------------------------------------------------------------------*/
106