]> rtime.felk.cvut.cz Git - arc.git/commitdiff
merge with osek-ctest
authormahi <devnull@localhost>
Thu, 22 Jul 2010 12:19:40 +0000 (14:19 +0200)
committermahi <devnull@localhost>
Thu, 22 Jul 2010 12:19:40 +0000 (14:19 +0200)
40 files changed:
1  2 
arch/arm/arm_cm3/drivers/Mcu.c
arch/arm/arm_cm3/kernel/irq_types.h
arch/arm/arm_cm3/kernel/stack.h
arch/arm/arm_cm3/kernel/sys_tick.c
arch/hc1x/hcs12d/kernel/sys_tick.c
arch/ppc/mpc55xx/drivers/sys_tick.c
boards/board_common.mk
boards/hcs12_elmicro_card12/build_config.mk
common/printf.c
examples/blinker_node/makefile
examples/pwm_node/makefile
examples/pwm_node2/makefile
examples/simple/config/mpc5516it/Os_Cfg.c
examples/simple/config/mpc5516it/Os_Cfg.h
examples/switch_node/makefile
include/Dio.h
include/Os.h
include/arm/stm32f10x.h
include/os_config_funcs.h
scripts/rules.mk
system/EcuM/EcuM.c
system/kernel/alarm.c
system/kernel/event.c
system/kernel/include/arch.h
system/kernel/include/sched_table_i.h
system/kernel/include/sys.h
system/kernel/init.c
system/kernel/isr.c
system/kernel/makefile
system/kernel/sched_table.c
system/kernel/task.c
system/kernel/testsystem/config/Os_Cfg.c
system/kernel/testsystem/config/Os_Cfg.h
system/kernel/testsystem/os_test.h
system/kernel/testsystem/test_03_alarm.c
system/kernel/testsystem/test_framework.c
system/kernel/testsystem/test_framework.h
system/kernel/testsystem/test_sup_01.c
system/kernel/testsystem/test_sup_02.c
system/kernel/testsystem/test_sup_05.c

index ef5e1eebee36d4fc41f6ed267ac8e3b2a6de233d,59492bdfe799a9de2ee5c063970e90b383138d77..9154fddcad32859059213a888d94255c5a2b0451
@@@ -152,14 -151,12 +151,12 @@@ static core_info_t *Mcu_IdentifyCore(ui
    }\r
  \r
    return NULL;\r
 -}
 -
 -/**
 - * Identify the core, just to check that we have support for it.
 - *
 - * @return
 +}\r
 +\r
\r
\r
 +/**\r
 + * Identify the core, just to check that we have support for it.\r
 + *\r
 + * @return\r
   */\r
  static uint32 Mcu_CheckCpu( void ) {\r
  \r
  \r
    return 0;\r
  }\r
 -
 -static uint32_t GetPllValueFromMult(uint8_t pll)
 -{
 -      return (((uint32_t)pll - 2) << 18);
 -}
 -static uint32_t GetPll2ValueFromMult(uint8_t pll)
 -{
 -      return (((uint32_t)pll - 2) << 8);
 -}
 -
 -/**
 -  * Set bus clocks. SysClk,AHBClk,APB1Clk,APB2Clk
 -  */
 -static void SetClocks(Mcu_ClockSettingConfigType *clockSettingsPtr)
 -{
 -  volatile uint32 StartUpCounter = 0, HSEStatus = 0;
 -
 -  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
 -  /* Enable HSE */
 -  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 -
 -  /* Wait till HSE is ready and if Time out is reached exit */
 -  do
 -  {
 -    HSEStatus = RCC->CR & RCC_CR_HSERDY;
 -    StartUpCounter++;
 -  } while((HSEStatus == 0) && (StartUpCounter != HSEStartUp_TimeOut));
 -
 -  if ((RCC->CR & RCC_CR_HSERDY) != RESET)
 -  {
 -    HSEStatus = (uint32_t)0x01;
 -  }
 -  else
 -  {
 -    HSEStatus = (uint32_t)0x00;
 -  }
 -
 -  if (HSEStatus == (uint32_t)0x01)
 -  {
 -    /* Enable Prefetch Buffer */
 -    FLASH->ACR |= FLASH_ACR_PRFTBE;
 -
 -    /* Flash 2 wait state */
 -    FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
 -    FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;
 -
 -
 -    /* HCLK = SYSCLK */
 -    RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
 -
 -    /* PCLK2 = HCLK */
 -    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
 -
 -    /* PCLK1 = HCLK */
 -    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
 -
 -#ifdef STM32F10X_CL
 -    /* Configure PLLs ------------------------------------------------------*/
 -    /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
 -    /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
 -
 -    RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
 -                              RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
 -    RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | GetPll2ValueFromMult(clockSettingsPtr->Pll2) |
 -                             RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
 -
 -    /* Enable PLL2 */
 -    RCC->CR |= RCC_CR_PLL2ON;
 -    /* Wait till PLL2 is ready */
 -    while((RCC->CR & RCC_CR_PLL2RDY) == 0)
 -    {
 -    }
 -
 -    /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */
 -    RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
 -    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
 -                              GetPllValueFromMult(clockSettingsPtr->Pll1));
 -#else
 -    /*  PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
 -    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
 -                                        RCC_CFGR_PLLMULL));
 -    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | GetPllValueFromMult(clockSettingsPtr->Pll1));
 -#endif /* STM32F10X_CL */
 -
 -    /* Enable PLL */
 -    RCC->CR |= RCC_CR_PLLON;
 -
 -    /* Wait till PLL is ready */
 -    while((RCC->CR & RCC_CR_PLLRDY) == 0)
 -    {
 -    }
 -
 -    /* Select PLL as system clock source */
 -    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
 -    RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
 -
 -    /* Wait till PLL is used as system clock source */
 -    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
 -    {
 -    }
 -  }
 -  else
 -  { /* HSE fails to start-up, the application will have wrong clock */
 -        NVIC_SystemReset();
 -  }
 -}
 -
 -/**
 -  * Initialize Peripherals clocks
 -  */
 -static void InitPerClocks()
 -{
 -      RCC->AHBENR |= McuPerClockConfigData.AHBClocksEnable;
 -      RCC->APB1ENR |= McuPerClockConfigData.APB1ClocksEnable;
 -      RCC->APB2ENR |= McuPerClockConfigData.APB2ClocksEnable;
 -}
 -
 -/**
 -  * Initialize Flash, PLL and clocks.
 -  */
 -static void InitMcuClocks(Mcu_ClockSettingConfigType *clockSettingsPtr)
 -{
 -  /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
 -  /* Set HSION bit */
 -  RCC->CR |= (uint32_t)0x00000001;
 -
 -  /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
 -#ifndef STM32F10X_CL
 -  RCC->CFGR &= (uint32_t)0xF8FF0000;
 -#else
 -  RCC->CFGR &= (uint32_t)0xF0FF0000;
 -#endif /* STM32F10X_CL */
 -
 -  /* Reset HSEON, CSSON and PLLON bits */
 -  RCC->CR &= (uint32_t)0xFEF6FFFF;
 -
 -  /* Reset HSEBYP bit */
 -  RCC->CR &= (uint32_t)0xFFFBFFFF;
 -
 -  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
 -  RCC->CFGR &= (uint32_t)0xFF80FFFF;
 -
 -#ifndef STM32F10X_CL
 -  /* Disable all interrupts and clear pending bits  */
 -  RCC->CIR = 0x009F0000;
 -#else
 -  /* Reset PLL2ON and PLL3ON bits */
 -  RCC->CR &= (uint32_t)0xEBFFFFFF;
 -
 -  /* Disable all interrupts and clear pending bits  */
 -  RCC->CIR = 0x00FF0000;
 -
 -  /* Reset CFGR2 register */
 -  RCC->CFGR2 = 0x00000000;
 -#endif /* STM32F10X_CL */
 -
 -  /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
 -  /* Configure the Flash Latency cycles and enable prefetch buffer */
 -  SetClocks(clockSettingsPtr);
 +\r
++static uint32_t GetPllValueFromMult(uint8_t pll)\r
++{\r
++      return (((uint32_t)pll - 2) << 18);\r
++}\r
++static uint32_t GetPll2ValueFromMult(uint8_t pll)\r
++{\r
++      return (((uint32_t)pll - 2) << 8);\r
++}\r
++\r
++/**\r
++  * Set bus clocks. SysClk,AHBClk,APB1Clk,APB2Clk\r
++  */\r
++static void SetClocks(Mcu_ClockSettingConfigType *clockSettingsPtr)\r
++{\r
++  volatile uint32 StartUpCounter = 0, HSEStatus = 0;\r
++\r
++  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/\r
++  /* Enable HSE */\r
++  RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
++\r
++  /* Wait till HSE is ready and if Time out is reached exit */\r
++  do\r
++  {\r
++    HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
++    StartUpCounter++;\r
++  } while((HSEStatus == 0) && (StartUpCounter != HSEStartUp_TimeOut));\r
++\r
++  if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
++  {\r
++    HSEStatus = (uint32_t)0x01;\r
++  }\r
++  else\r
++  {\r
++    HSEStatus = (uint32_t)0x00;\r
++  }\r
++\r
++  if (HSEStatus == (uint32_t)0x01)\r
++  {\r
++    /* Enable Prefetch Buffer */\r
++    FLASH->ACR |= FLASH_ACR_PRFTBE;\r
++\r
++    /* Flash 2 wait state */\r
++    FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
++    FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;\r
++\r
++\r
++    /* HCLK = SYSCLK */\r
++    RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
++\r
++    /* PCLK2 = HCLK */\r
++    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
++\r
++    /* PCLK1 = HCLK */\r
++    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;\r
++\r
++#ifdef STM32F10X_CL\r
++    /* Configure PLLs ------------------------------------------------------*/\r
++    /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */\r
++    /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */\r
++\r
++    RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |\r
++                              RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);\r
++    RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | GetPll2ValueFromMult(clockSettingsPtr->Pll2) |\r
++                             RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);\r
++\r
++    /* Enable PLL2 */\r
++    RCC->CR |= RCC_CR_PLL2ON;\r
++    /* Wait till PLL2 is ready */\r
++    while((RCC->CR & RCC_CR_PLL2RDY) == 0)\r
++    {\r
++    }\r
++\r
++    /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */\r
++    RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);\r
++    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |\r
++                              GetPllValueFromMult(clockSettingsPtr->Pll1));\r
++#else\r
++    /*  PLL configuration: PLLCLK = HSE * 9 = 72 MHz */\r
++    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |\r
++                                        RCC_CFGR_PLLMULL));\r
++    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | GetPllValueFromMult(clockSettingsPtr->Pll1));\r
++#endif /* STM32F10X_CL */\r
++\r
++    /* Enable PLL */\r
++    RCC->CR |= RCC_CR_PLLON;\r
++\r
++    /* Wait till PLL is ready */\r
++    while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
++    {\r
++    }\r
++\r
++    /* Select PLL as system clock source */\r
++    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
++    RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;\r
++\r
++    /* Wait till PLL is used as system clock source */\r
++    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)\r
++    {\r
++    }\r
++  }\r
++  else\r
++  { /* HSE fails to start-up, the application will have wrong clock */\r
++        NVIC_SystemReset();\r
++  }\r
++}\r
++\r
++/**\r
++  * Initialize Peripherals clocks\r
++  */\r
++static void InitPerClocks()\r
++{\r
++      RCC->AHBENR |= McuPerClockConfigData.AHBClocksEnable;\r
++      RCC->APB1ENR |= McuPerClockConfigData.APB1ClocksEnable;\r
++      RCC->APB2ENR |= McuPerClockConfigData.APB2ClocksEnable;\r
++}\r
++\r
++/**\r
++  * Initialize Flash, PLL and clocks.\r
++  */\r
++static void InitMcuClocks(Mcu_ClockSettingConfigType *clockSettingsPtr)\r
++{\r
++  /* Reset the RCC clock configuration to the default reset state(for debug purpose) */\r
++  /* Set HSION bit */\r
++  RCC->CR |= (uint32_t)0x00000001;\r
++\r
++  /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */\r
++#ifndef STM32F10X_CL\r
++  RCC->CFGR &= (uint32_t)0xF8FF0000;\r
++#else\r
++  RCC->CFGR &= (uint32_t)0xF0FF0000;\r
++#endif /* STM32F10X_CL */\r
++\r
++  /* Reset HSEON, CSSON and PLLON bits */\r
++  RCC->CR &= (uint32_t)0xFEF6FFFF;\r
++\r
++  /* Reset HSEBYP bit */\r
++  RCC->CR &= (uint32_t)0xFFFBFFFF;\r
++\r
++  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */\r
++  RCC->CFGR &= (uint32_t)0xFF80FFFF;\r
++\r
++#ifndef STM32F10X_CL\r
++  /* Disable all interrupts and clear pending bits  */\r
++  RCC->CIR = 0x009F0000;\r
++#else\r
++  /* Reset PLL2ON and PLL3ON bits */\r
++  RCC->CR &= (uint32_t)0xEBFFFFFF;\r
++\r
++  /* Disable all interrupts and clear pending bits  */\r
++  RCC->CIR = 0x00FF0000;\r
++\r
++  /* Reset CFGR2 register */\r
++  RCC->CFGR2 = 0x00000000;\r
++#endif /* STM32F10X_CL */\r
++\r
++  /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */\r
++  /* Configure the Flash Latency cycles and enable prefetch buffer */\r
++  SetClocks(clockSettingsPtr);\r
+ }\r
  \r
  //-------------------------------------------------------------------\r
  \r
@@@ -186,15 -342,12 +342,12 @@@ void Mcu_Init(const Mcu_ConfigType *con
  {\r
    VALIDATE( ( NULL != configPtr ), MCU_INIT_SERVICE_ID, MCU_E_PARAM_CONFIG );\r
  \r
-   if( !SIMULATOR() ) {\r
-         Mcu_CheckCpu();\r
-   }\r
 -#if !defined(USE_SIMULATOR)
++#if !defined(USE_SIMULATOR)\r
+   Mcu_CheckCpu();\r
+ #endif\r
  \r
    memset(&Mcu_Global.stats,0,sizeof(Mcu_Global.stats));\r
 -
 +\r
\r
-   SystemInit();\r
\r
    Irq_Enable();\r
  \r
    Mcu_Global.config = configPtr;\r
@@@ -230,7 -383,10 +383,10 @@@ Std_ReturnType Mcu_InitClock(const Mcu_
  \r
    Mcu_Global.clockSetting = ClockSetting;\r
    clockSettingsPtr = &Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting];\r
 -
 -  InitMcuClocks(clockSettingsPtr);
 -
 -  InitPerClocks(clockSettingsPtr);
 +\r
++  InitMcuClocks(clockSettingsPtr);\r
++\r
++  InitPerClocks(clockSettingsPtr);\r
  \r
    return E_OK;\r
  }\r
@@@ -248,23 -404,22 +404,22 @@@ void Mcu_DistributePllClock(void
  \r
  //-------------------------------------------------------------------\r
  \r
 -
 -Mcu_PllStatusType Mcu_GetPllStatus(void) {
 -      VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_GETPLLSTATUS_SERVICE_ID, MCU_E_UNINIT, MCU_PLL_STATUS_UNDEFINED );
 -      Mcu_PllStatusType rv;
 -
 -#if !defined(USE_SIMULATOR)
 -      if (RCC->CR & RCC_CR_PLLRDY) {
 -              rv = MCU_PLL_LOCKED;
 -      } else {
 -              rv = MCU_PLL_UNLOCKED;
 -      }
 -#else
 -      /* We are running on instruction set simulator. PLL is then always in sync... */
 -      rv = MCU_PLL_LOCKED;
 -#endif
 -      return rv;
 +\r
 +Mcu_PllStatusType Mcu_GetPllStatus(void) {\r
 +      VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_GETPLLSTATUS_SERVICE_ID, MCU_E_UNINIT, MCU_PLL_STATUS_UNDEFINED );\r
 +      Mcu_PllStatusType rv;\r
 +\r
-       if (!SIMULATOR()) {\r
-               if (RCC->CR & RCC_CR_PLLRDY) {\r
-                       rv = MCU_PLL_LOCKED;\r
-               } else {\r
-                       rv = MCU_PLL_UNLOCKED;\r
-               }\r
-       } else {\r
-               /* We are running on instruction set simulator. PLL is then always in sync... */\r
++#if !defined(USE_SIMULATOR)\r
++      if (RCC->CR & RCC_CR_PLLRDY) {\r
 +              rv = MCU_PLL_LOCKED;\r
++      } else {\r
++              rv = MCU_PLL_UNLOCKED;\r
 +      }\r
\r
++#else\r
++      /* We are running on instruction set simulator. PLL is then always in sync... */\r
++      rv = MCU_PLL_LOCKED;\r
++#endif\r
 +      return rv;\r
  }\r
  \r
  //-------------------------------------------------------------------\r
@@@ -350,52 -505,62 +505,62 @@@ void Mcu_SetMode(const Mcu_ModeType Mcu
   * different register settings in HW.\r
   */\r
  uint32_t McuE_GetSystemClock(void)\r
 -{
 +{\r
-   /*\r
-    * System clock calculation\r
-    *\r
-    */\r
+   uint32_t f_sys;\r
 -
 -  uint32  extal = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].McuClockReferencePointFrequency;
 -  uint32 pll1 = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].Pll1;
 -
 -#ifdef STM32F10X_CL
 -  uint32 pll2 = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].Pll2;
 -  /* PLL2 configuration: PLL2CLK = (HSE / 5) * PLL2 */
 -  /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 */
 -  /* PLL configuration: PLLCLK = PREDIV1 * PLL1 */
 -  f_sys = (extal / 5 * pll2) / 5 * pll1;
 -#else
 -  /* PLL configuration: PLLCLK = HSE * PLL1 */
 -  f_sys = extal * pll1;
 -#endif
 +\r
-   // TODO: This of course wrong....\r
-   uint32_t f_sys = 72000000UL;\r
- #if 0\r
 +  uint32  extal = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].McuClockReferencePointFrequency;\r
\r
-   f_sys =  CALC_SYSTEM_CLOCK(extal,emfd,eprediv,erfd);\r
++  uint32 pll1 = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].Pll1;\r
++\r
++#ifdef STM32F10X_CL\r
++  uint32 pll2 = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].Pll2;\r
++  /* PLL2 configuration: PLL2CLK = (HSE / 5) * PLL2 */\r
++  /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 */\r
++  /* PLL configuration: PLLCLK = PREDIV1 * PLL1 */\r
++  f_sys = (extal / 5 * pll2) / 5 * pll1;\r
++#else\r
++  /* PLL configuration: PLLCLK = HSE * PLL1 */\r
++  f_sys = extal * pll1;\r
 +#endif\r
  \r
- //  f_sys = extal * (emfd+16) / ( (eprediv+1) * ( erfd+1 ));\r
    return f_sys;\r
  }\r
  \r
  imask_t McuE_EnterCriticalSection()\r
 -{
 -      uint32_t val;
 +{\r
- #if 0\r
-   uint32_t msr = get_msr();\r
-   Irq_Disable();\r
-   return msr;\r
- #endif\r
-   return 0;\r
++      uint32_t val;\r
+       Irq_Save(val);\r
+       return val;\r
  }\r
  \r
  void McuE_ExitCriticalSection(uint32_t old_state)\r
  {\r
- #if 0\r
-   set_msr(old_state);\r
- #endif\r
 -      Irq_Restore(old_state);
++      Irq_Restore(old_state);\r
  }\r
  \r
  /**\r
   * Get the peripheral clock in Hz for a specific device\r
   */\r
\r
- #if 0\r
  uint32_t McuE_GetPeripheralClock(McuE_PeriperalClock_t type)\r
  {\r
 -
 -      switch(type)
 -      {
 -      case PERIPHERAL_CLOCK_AHB:
 -              res = McuE_GetSystemClock();
 -              break;
 -      case PERIPHERAL_CLOCK_APB1:
 -              res = McuE_GetSystemClock() / 2;
 -              break;
 -      case PERIPHERAL_CLOCK_APB2:
 -              res = McuE_GetSystemClock();
 -              break;
 -      default:
 -              break;
 -      }
 -
+       uint32_t res = 0;\r
-       return 0;\r
++\r
++      switch(type)\r
++      {\r
++      case PERIPHERAL_CLOCK_AHB:\r
++              res = McuE_GetSystemClock();\r
++              break;\r
++      case PERIPHERAL_CLOCK_APB1:\r
++              res = McuE_GetSystemClock() / 2;\r
++              break;\r
++      case PERIPHERAL_CLOCK_APB2:\r
++              res = McuE_GetSystemClock();\r
++              break;\r
++      default:\r
++              break;\r
++      }\r
 +\r
+       return res;\r
  }\r
- #endif\r
  \r
  \r
  /**\r
index 8feeebacf2a4eaf7ac3475f3806f884aa26c7534,1290cad4e2f0f988ae8dc64d996156598d635067..2d5461ee1c915e4a519216e9e9e448e0f834a404
  \r
  #include "stm32f10x.h"\r
  \r
 -typedef IRQn_Type IrqType;
 -
 -/* Offset from start of exceptions to interrupts
 - * Exceptions have negative offsets while interrupts have positive
 - */
 +typedef IRQn_Type IrqType;\r
 +\r
 +/* Offset from start of exceptions to interrupts\r
 + * Exceptions have negative offsets while interrupts have positive\r
 + */\r
  #define IRQ_INTERRUPT_OFFSET  16\r
 -
 -/* Total number of interrupts and exceptions
 - */
 -
 -#if   defined(STM32F10X_LD) || defined(STM32F10X_MD)
 -#define NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS (USBWakeUp_IRQn+IRQ_INTERRUPT_OFFSET)
 -#elif defined(STM32F10X_HD)
 -#define NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS (DMA2_Channel4_5_IRQn+IRQ_INTERRUPT_OFFSET)
 -#elif defined(STM32F10X_CL)
 -#define NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS (OTG_FS_IRQn+IRQ_INTERRUPT_OFFSET)
 -#else
 -#error No device selected
 -#endif
 -
 -
 -typedef enum {
 -        PERIPHERAL_CLOCK_AHB,
 -        PERIPHERAL_CLOCK_APB1,
 -        PERIPHERAL_CLOCK_APB2,
 -} McuE_PeriperalClock_t;
 -
 +\r
 +/* Total number of interrupts and exceptions\r
 + */\r
 +\r
 +#if   defined(STM32F10X_LD) || defined(STM32F10X_MD)\r
 +#define NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS (USBWakeUp_IRQn+IRQ_INTERRUPT_OFFSET)\r
 +#elif defined(STM32F10X_HD)\r
 +#define NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS (DMA2_Channel4_5_IRQn+IRQ_INTERRUPT_OFFSET)\r
 +#elif defined(STM32F10X_CL)\r
 +#define NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS (OTG_FS_IRQn+IRQ_INTERRUPT_OFFSET)\r
 +#else\r
 +#error No device selected\r
 +#endif\r
 +\r
++\r
++typedef enum {\r
++        PERIPHERAL_CLOCK_AHB,\r
++        PERIPHERAL_CLOCK_APB1,\r
++        PERIPHERAL_CLOCK_APB2,\r
++} McuE_PeriperalClock_t;\r
++\r
\r
  typedef enum {\r
        CPU_0=0,\r
  } Cpu_t;\r
index e81ea880d3b91921c565960377119ea2940700e0,4da131786784778a8a9181e9bb0bf9ab0860c923..eaa8cee7c9ebf3a75c40ad3d62cce5c712b1f62d
   *     r13 - SP\r
   *     r14 - LR\r
   *     r15 - PC\r
 - *
 - *   See "Procedure Call Standard for the ARM® Architecture" for more information.
 - *
 - *   Other:
 - *   PSR
 - *   PRIMASK[0]      0 - No effect,
 - *                   1 - Prevents the activation of all exceptions with
 - *                       configurable priority.
 - *   FAULTMASK
 - *   BASEPRI[7:4]    0x0 - No effect
 - *                   !=0 -  When BASEPRI is set to a nonzero value, it prevents
 - *                          the activation of all exceptions with same or lower
 - *                          priority level as the BASEPRI value.
 - *   CONTOROL
 - *
 + *\r
++ *   See "Procedure Call Standard for the ARM® Architecture" for more information.\r
++ *\r
 + *   Other:\r
 + *   PSR\r
 + *   PRIMASK[0]      0 - No effect,\r
 + *                   1 - Prevents the activation of all exceptions with\r
 + *                       configurable priority.\r
 + *   FAULTMASK\r
 + *   BASEPRI[7:4]    0x0 - No effect\r
 + *                   !=0 -  When BASEPRI is set to a nonzero value, it prevents\r
 + *                          the activation of all exceptions with same or lower\r
 + *                          priority level as the BASEPRI value.\r
 + *   CONTOROL\r
 + *\r
   *\r
   * EXCEPTION FRAME\r
   *\r
index 14cf957d8a8992af4a7c7789eacbc3d1ceca1185,794c05dea45d24096dfa23255408c1a564be2c6e..e0393667e1592449c9196510515e9b414cc47ab1
@@@ -63,10 -63,10 +63,10 @@@ void Os_SysTickStart(uint32_t period_ti
  }\r
  \r
  /**\r
 - * @return
 + * @return\r
   */\r
  \r
- uint32_t Os_SysTickGetTimeElapsed( void )\r
+ uint32_t Os_SysTickGetValue( void )\r
  {\r
        return (SysTick->VAL);\r
  }\r
index 835f4e4ba1a8ff8fa2287f1b2a5e4950fed0dce0,043289874478dadfc636aa11e15bd5054b5a9925..1a269f86becba449bfbd6fb4c77cb089f2a1cb92
@@@ -64,15 -64,15 +64,15 @@@ void Os_SysTickStart(uint32_t period_ti
  /**\r
   * ???\r
   * TODO: This function just subtract the max value?! ok??\r
 - *
 - * @return
 + *\r
 + * @return\r
   */\r
 -
 +\r
  /** @req OS383 */\r
- uint32_t Os_SysTickGetTimeElapsed( void )\r
+ uint32_t Os_SysTickGetValue( void )\r
 -{
 +{\r
  #if 0\r
        uint32_t timer = get_spr(SPR_DECAR) - get_spr(SPR_DEC);\r
 -      return (timer);
 +      return (timer);\r
  #endif\r
  }\r
index d0f9b04c30266f2d2065eee79a4b73699b6246e1,611e049ee9da07da71ccaccc83a37fd08d8ae16d..7216421efcf8a6c2de90901e58e04d41db7319dc
@@@ -60,12 -60,12 +60,12 @@@ void Os_SysTickStart(uint32_t period_ti
  /**\r
   * ???\r
   * TODO: This function just subtract the max value?! ok??\r
 - *
 - * @return
 + *\r
 + * @return\r
   */\r
 -
 +\r
  /** @req OS383 */\r
uint32_t Os_SysTickGetTimeElapsed( void )\r
TickType Os_SysTickGetValue( void )\r
  {\r
        uint32_t timer = get_spr(SPR_DECAR) - get_spr(SPR_DEC);\r
        return (timer);\r
Simple merge
index cc81e669ef2ab6a341b0801c2eb916da18bf8d67,a35543c3b9b7ea41f684a020482ae9b146a567b8..ed4d9bca73b6a55d5429ac779a6ccef9c0d94d55
@@@ -1,15 -1,23 +1,20 @@@
\r
- # ARCH defines\r
- ARCH=hcs12d\r
- ARCH_FAM=hc1x\r
- ARCH_MCU=MC912DG128A\r
\r
- # CFG (y/n) macros (These become CFG_XXX=y and def-y += CFG_XXX ) \r
- CFG=HC1X HCS12D MC912DG128A BRD_HCS12_ELMICRO_CARD12 SIMULATOR\r
\r
- # What buildable modules does this board have, \r
- # default or private (These become MOD_XXX=y )\r
- MOD_AVAIL+=KERNEL MCU GPT DIO PORT COM CAN CANIF PWM ADC DEM DCM PDUR COMM NM CANNM CANSM CANTP\r
\r
- # Needed by us (These become USE_XXX=y and def-y += USE_XXX )\r
- MOD_USE=KERNEL MCU\r
+ # ARCH defines
+ ARCH=hcs12d
+ ARCH_FAM=hc1x
+ ARCH_MCU=MC912DG128A
+ # CFG (y/n) macros (These become CFG_XXX=y and def-y += CFG_XXX ) 
+ CFG=HC1X HCS12D MC912DG128A BRD_HCS12_ELMICRO_CARD12 SIMULATOR
+ # What buildable modules does this board have, 
+ # default or private (These become MOD_XXX=y )
+ MOD_AVAIL+=MCU GPT     
+ # System + Communication + Diagnostic
+ MOD_AVAIL+=CANIF CANTP COM DCM DEM DET ECUM IOHWAB KERNEL PDUR WDGM
+ # Additional
+ MOD_AVAIL+=COMMON NEWLIB RAMLOG 
+ # Needed by us (These become USE_XXX=y and def-y += USE_XXX )
+ MOD_USE=KERNEL MCU
 -
 -# Extra defines
 -def-y += HEAPSIZE=400
diff --cc common/printf.c
index c754d0d3589f45031e7d19cd3b5733aacbe72d6b,2cd3ee28f2726d4ff52e5c5819a5818110ea52d6..e14b2ff8b382827a1ab74a7abf57b5143c6c886f
- /*\r
-  * Copyright ArcCore AB\r
-  *\r
-  * A simple implementation of all formatted xxprintf functionallity.\r
-  *\r
-  * DESIGN CRITERIA:\r
-  *  - Reentrant\r
-  *  - Use little stack\r
-  *\r
-  *  What you normally would do is to print to a buffer of some kind and then\r
-  *  call write(). However little stack indicates that we can't place buffers\r
-  *  on the stack and reentrant tells us that we can't have a static buffer.\r
-  *  That leaves us with printing characters as it is ready. From a speed\r
-  *  point of view that is less than optimal, but that the way it's got to be.\r
-  *  (Could make a 16 long char buffer??)\r
-  *\r
-  *  This is just intended to be used as a replacement for newlibs implementation.\r
-  *  Newlib porting interface have the following API:\r
-  *    int write(  int fd, char *buf, int nbytes)\r
-  *\r
-  *\r
-  *  Note that puts(), putc() are still the newlib variants....\r
-  *\r
-  *    printf()       -> vfprintf(stdout,) -> vsnprintf(buf,)\r
-  *                                           write()\r
-  *    vprintf()      -> vfprintf(stdout,) -> vsnprintf(buf,)\r
-  *                                           write()\r
-  *    sprintf(buf,)  ->                      vsnprintf(buf,)\r
-  *    snprintf(buf,) ->                      vsnprintf(buf,)\r
-  *\r
-  * IMPLEMENTATION NOTE:\r
-  *  If printing more than the limit, e.g. using vsnprintf() then\r
-  *  the emit function will only stop printing, but not interrupted\r
-  *  (The code will get more complicated that way)\r
-  */\r
\r
- #include <unistd.h>\r
- #include <stdio.h>\r
- #include <stdarg.h>\r
- #include <assert.h>\r
- #include <string.h>\r
\r
- //#define HOST_TEST   1\r
\r
- #ifdef HOST_TEST\r
- #define _STDOUT       stdout\r
- #define _STDIN        stdin\r
- #define _STDERR       stderr\r
- #else\r
- #define _STDOUT       (FILE *)STDOUT_FILENO\r
- #define _STDINT       STDIN_FILENO\r
- #define _STDERR       (FILE *)STDERR_FILENO\r
- #endif\r
\r
\r
- int arc_putchar(int fd, int c);\r
- int print(FILE *file, char **buffer, size_t n, const char *format, va_list ap);\r
\r
- int printf(const char *format, ...) {\r
-       va_list ap;\r
-       int rv;\r
\r
-       va_start(ap, format);\r
-       rv = vfprintf(_STDOUT, format, ap);\r
-       va_end(ap);\r
-       return rv;\r
- }\r
\r
- int fprintf(FILE *file, const char *format, ...) {\r
-       va_list ap;\r
-       int rv;\r
\r
-       va_start(ap, format);\r
-       rv = vfprintf(file, format, ap);\r
-       va_end(ap);\r
-       return rv;\r
- }\r
\r
- int sprintf(char *buffer, const char *format, ...) {\r
-       va_list ap;\r
-       int rv;\r
\r
-       va_start(ap, format);\r
-       rv = vsnprintf(buffer, ~(size_t)0, format, ap);\r
-       va_end(ap);\r
\r
-       return rv;\r
- }\r
\r
- int snprintf(char *buffer, size_t n, const char *format, ...) {\r
-       va_list ap;\r
-       int rv;\r
\r
-       va_start(ap, format);\r
-       rv = vsnprintf(buffer, n, format, ap);\r
-       va_end(ap);\r
-       return rv;\r
- }\r
\r
- int vprintf(const char *format, va_list ap) {\r
-       return vfprintf(_STDOUT, format, ap);\r
- }\r
\r
- int vsprintf(char *buffer, const char *format, va_list ap) {\r
-       return vsnprintf(buffer, ~(size_t)0, format, ap);\r
- }\r
\r
- int vfprintf(FILE *file, const char *format, va_list ap) {\r
-       int rv;\r
-       /* Just print to _STDOUT */\r
-       rv = print(file,NULL,~(size_t)0, format,ap);\r
-       return rv;\r
- }\r
\r
- int vfiprintf(FILE *file, const char *format, va_list ap) {\r
-       return vfprintf(file,format,ap);\r
- }\r
\r
- int vsnprintf(char *buffer, size_t n, const char *format, va_list ap) {\r
-       int rv;\r
\r
-       rv = print(NULL, &buffer, n, format,ap);\r
-       return rv;\r
- }\r
\r
\r
- /**\r
-  *\r
-  * @param file  The file to print to\r
-  * @param buf   The buffer to print to\r
-  * @param c           The char to print\r
-  * @return\r
-  */\r
- static inline int emitChar( FILE *file, char **buf, char c, int *left ) {\r
-       if( (*left) == 1 ) {\r
-               return 1;\r
-       }\r
-       --(*left);\r
-       if( buf == NULL ) {\r
- #if HOST_TEST\r
-               putc(c, _STDOUT);\r
-               fflush(_STDOUT);\r
- #else\r
-               arc_putchar((int)file, c);\r
- #endif\r
-       } else {\r
-               **buf = c;\r
-               (*buf)++;\r
-       }\r
-       return 1;\r
- }\r
\r
\r
- #if defined(HOST_TEST)\r
- /**\r
-  * Convert a number to a string\r
-  *\r
-  * @param val         The value to convert\r
-  * @param str         Pointer to a space where to put the string\r
-  * @param base                The base\r
-  * @param negative    If negative or not.\r
-  */\r
- void xtoa( unsigned long val, char* str, int base, int negative) {\r
-       int i;\r
-       char *oStr = str;\r
-       char c;\r
\r
-       if (negative) {\r
-               val = -val;\r
-       }\r
\r
-       if( base < 10 && base > 16 ) {\r
-               *str = '0';\r
-               return;\r
-       }\r
-     i = 0;\r
\r
-     do {\r
-       str[i++] = "0123456789abcdef"[ val % base ];\r
-       } while ((val /= base) > 0);\r
\r
\r
-     if (negative) {\r
-         str[i++] = '-';\r
-     }\r
\r
-     str[i] = '\0';\r
-     str = &str[i]-1;\r
-     while(str > oStr) {\r
-       c = *str;\r
-       *str-- = *oStr;\r
-       *oStr++=c;\r
-     }\r
- }\r
- #else\r
- extern void xtoa( unsigned long val, char* str, int base, int negative);\r
- #endif\r
\r
\r
- #define FL_NONE                                       (0<<0)\r
- #define FL_ZERO                                       (1<<1)\r
- #define FL_HASH                                       (1<<2)\r
- #define FL_SPACE                              (1<<3)\r
- #define FL_ALIGN_LEFT                 (1<<4)\r
- #define FL_TYPE_SIGNED_INT            (1<<5)\r
- #define FL_TYPE_UNSIGNED_INT  (1<<6)\r
\r
\r
- static void emitString( FILE *file, char **buffer, char *string, int width, int flags, int *left) {\r
-       char pad;\r
-       char *str = string;\r
-       int i;\r
-       int strLen;\r
-       /* padding: FL_ZERO or normal ' '\r
-        * align: FL_ALIGN_LEFT (left) or normal (right)\r
-        */\r
-       pad = (flags & FL_ZERO) ? '0' : ' ';\r
\r
\r
-       if( flags & FL_ALIGN_LEFT ) {\r
-               for(i=0;str[i]; i++) {\r
-                       emitChar(file,buffer,str[i],left);\r
-               }\r
\r
-               /* Pad the rest */\r
-               for(;i<width;i++) {\r
-                       emitChar(file,buffer,pad,left);\r
-               }\r
-       } else {\r
\r
-               strLen = strlen(string);\r
\r
-               /* Pad first  */\r
-               if( width > strLen ) {\r
-                       for(i=0;i<(width-strLen);i++) {\r
-                               emitChar(file,buffer,pad,left);\r
-                       }\r
-               }\r
\r
-               for(i=0;i<strLen; i++) {\r
-                       emitChar(file,buffer,string[i],left);\r
-               }\r
-       }\r
- }\r
\r
- void emitInt( FILE *file, char **buffer, int val, int base, int width, int flags, int *left )\r
- {\r
-       char lBuf[12];  // longest is base 10, 2^32\r
-       char *str = lBuf;\r
\r
-       if( flags & FL_TYPE_SIGNED_INT ) {\r
-               xtoa(val,str,base ,(val < 0));\r
-       } else {\r
-               xtoa((unsigned)val,str,base ,0);\r
-       }\r
\r
-       emitString(file,buffer,str,width,flags,left);\r
- }\r
\r
- #define PRINT_CHAR(_c)  *buffer++= (_c);\r
\r
\r
- /**\r
-  * Write formatted output to an array with a maximum number of characters.\r
-  *\r
-  * This is the mother of the formatted print family. The main goal here\r
-  * is to be very small and memory efficient.\r
-  *\r
-  * Support:\r
-  *   Parameter: None\r
-  *   Flags    : '-' and '0'\r
-  *   Width    : Normal padding is supported, '*' is not.\r
-  *   Precision: None\r
-  *   Length   : None\r
-  *   C99      : None\r
-  *   Type     : d,u,x,s,and c\r
-  *\r
-  * @param file    The file descriptor\r
-  * @param buffer  A pointer to the place to store the output\r
-  *                If NULL the output is instead\r
-  * @param n       The maximum number of characters to write\r
-  * @param format  The format string\r
-  * @param ap      The va list\r
-  * @return\r
-  */\r
- int print(FILE *file, char **buffer, size_t n, const char *format, va_list ap)\r
- {\r
-       char ch;\r
-       int flags;\r
-       char *str;\r
-       int width;\r
-       int left = n;\r
\r
-       while ( (ch = *format++) ) {\r
\r
-               if (ch == '%') {\r
-                       ch = *format++;\r
\r
-                       if( ch == '%') {\r
-                               emitChar(file,buffer,ch,&left);\r
-                               continue;\r
-                       }\r
\r
-                       /* Find flags */\r
-                       switch (ch) {\r
-                       case '0':\r
-                               flags = FL_ZERO;\r
-                               break;\r
-                       case ' ':\r
-                               flags = FL_SPACE;\r
-                               break;\r
-                       case '-':\r
-                               flags = FL_ALIGN_LEFT;\r
-                               break;\r
-                       default:\r
-                               /* Not supported or no flag */\r
-                               flags = FL_NONE;\r
-                               format--;\r
-                               break;\r
-                       }\r
\r
-                       ch = *format++;\r
\r
-                       /* Width */\r
-                       if( (ch >= '0')  && (ch <= '9') ) {\r
-                               width = ch -'0';\r
-                               ch = *format++;\r
-                       } else {\r
-                               width = 0;\r
-                       }\r
\r
-                       /* Find type */\r
-                       switch (ch) {\r
-                       case 'c':\r
-                               emitChar(file,buffer,(char )va_arg( ap, int ),&left);\r
-                               break;\r
-                       case 'd':\r
-                               flags |= FL_TYPE_SIGNED_INT;\r
-                               emitInt(file,buffer,va_arg( ap, int ),10,width,flags,&left);\r
-                               break;\r
-                       case 'u':\r
-                               flags |= FL_TYPE_UNSIGNED_INT;\r
-                               emitInt(file,buffer,va_arg( ap, int ),10,width,flags,&left);\r
-                               break;\r
-                       case 'x':\r
-                               flags |= FL_TYPE_UNSIGNED_INT;\r
-                               emitInt(file,buffer,va_arg( ap, int ),16,width,flags,&left);\r
-                               break;\r
-                       case 's':\r
-                               str = (char *)va_arg( ap, int );\r
\r
-                               if( str == NULL ) {\r
-                                       str = "(null)";\r
-                               }\r
\r
-                               emitString(file,buffer,str,width,flags,&left);\r
-                               break;\r
-                       default:\r
-                               assert(0); // oops\r
-                               break;\r
-                       }\r
\r
-               } else {\r
-                       flags = FL_NONE;\r
-                       emitChar(file,buffer,ch,&left);\r
-               }\r
-       }\r
- //    va_end(ap);             // Removed, TODO: Check the va_start/va_end handling (used in calling functions also).\r
-       if(buffer!=0) {\r
-               left = 0;\r
-               emitChar(file,buffer,'\0',&left);\r
-       }\r
-       return 0; // Wrong.. but for now.\r
- }\r
\r
- #if defined(HOST_TEST)\r
- int main(void) {\r
-       char *ptr = NULL;\r
-       char buff[30];\r
\r
-       printf("char: %c %c = a B\n", 'a', 66);\r
\r
-       printf("string: %s = (null)\n", (char *)ptr);\r
\r
-       printf("string: %s = foobar \n", "foobar");\r
\r
-       printf("string: %2s = foobar \n", "foobar");\r
-       printf("string: \"%8s\" = \"  foobar\" \n", "foobar");\r
-       /* Left justify */\r
-       printf("string: \"%-8s\" = \"foobar  \" \n", "foobar");\r
\r
-       printf("decimal:  23 = %d \n", 23);\r
-       printf("hex:     c23 = %x \n", 0xc23);\r
-       printf("hex:    0c23 = %04x \n", 0xc23);\r
-       printf("decimal with blanks:     23 = %6d  \n", 23);\r
-       printf("decimal with zero:   000023 = %06d \n", 23);\r
\r
-       /* negative and large numbers */\r
-       printf("decimal:  -23 = %d \n", -23);\r
-       printf("decimal:  4294967273 = %u \n", -23);\r
-       printf("decimal:  c0000000   = %x \n", 0xc0000000);\r
\r
-       printf("decimal:  00c000   = %06x \n", 0xc000);\r
\r
-       fprintf(_STDOUT, "string: %s = foobar \n", "foobar");\r
-       sprintf(buff, "string: %s = foobar \n", "foobar");\r
-       printf("%s",buff);\r
\r
-       snprintf(buff,10, "%s\n", "12345678901234567");\r
-       printf("\"123456789\" = \"%s\"\n",buff);\r
\r
-       snprintf(buff,12, "%s\n", "abcdefghijklmn");\r
-       printf("\"abcdefghijkl\" = \"%s\"\n",buff);\r
\r
-       return 0;\r
- }\r
- #endif\r
\r
\r
+ /*
+  * Copyright ArcCore AB
+  *
+  * A simple implementation of all formatted xxprintf functionallity.
+  *
+  * DESIGN CRITERIA:
+  *  - Reentrant
+  *  - Use little stack
+  *
+  *  What you normally would do is to print to a buffer of some kind and then
+  *  call write(). However little stack indicates that we can't place buffers
+  *  on the stack and reentrant tells us that we can't have a static buffer.
+  *  That leaves us with printing characters as it is ready. From a speed
+  *  point of view that is less than optimal, but that the way it's got to be.
+  *  (Could make a 16 long char buffer??)
+  *
+  *  This is just intended to be used as a replacement for newlibs implementation.
+  *  Newlib porting interface have the following API:
+  *    int write(  int fd, char *buf, int nbytes)
+  *
+  *
+  *  Note that puts(), putc() are still the newlib variants....
+  *
+  *    printf()       -> vfprintf(stdout,) -> vsnprintf(buf,)
+  *                                           write()
+  *    vprintf()      -> vfprintf(stdout,) -> vsnprintf(buf,)
+  *                                           write()
+  *    sprintf(buf,)  ->                      vsnprintf(buf,)
+  *    snprintf(buf,) ->                      vsnprintf(buf,)
+  *
+  * IMPLEMENTATION NOTE:
+  *  If printing more than the limit, e.g. using vsnprintf() then
+  *  the emit function will only stop printing, but not interrupted
+  *  (The code will get more complicated that way)
+  */
+ #include <unistd.h>
+ #include <stdio.h>
+ #include <stdarg.h>
+ #include <assert.h>
+ #include <string.h>
+ //#define HOST_TEST   1
+ #ifdef HOST_TEST
+ #define _STDOUT       stdout
+ #define _STDIN        stdin
+ #define _STDERR       stderr
+ #else
+ #define _STDOUT       (FILE *)STDOUT_FILENO
+ #define _STDINT       STDIN_FILENO
+ #define _STDERR       (FILE *)STDERR_FILENO
+ #endif
 -
++int arc_putchar(int fd, int c);
+ int print(FILE *file, char **buffer, size_t n, const char *format, va_list ap);
+ int printf(const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vfprintf(_STDOUT, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int fprintf(FILE *file, const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vfprintf(file, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int sprintf(char *buffer, const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vsnprintf(buffer, ~(size_t)0, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int snprintf(char *buffer, size_t n, const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vsnprintf(buffer, n, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int vprintf(const char *format, va_list ap) {
+       return vfprintf(_STDOUT, format, ap);
+ }
+ int vsprintf(char *buffer, const char *format, va_list ap) {
+       return vsnprintf(buffer, ~(size_t)0, format, ap);
+ }
+ int vfprintf(FILE *file, const char *format, va_list ap) {
+       int rv;
+       /* Just print to _STDOUT */
+       rv = print(file,NULL,~(size_t)0, format,ap);
+       return rv;
+ }
+ int vsnprintf(char *buffer, size_t n, const char *format, va_list ap) {
+       int rv;
+       rv = print(NULL, &buffer, n, format,ap);
+       return rv;
+ }
+ /*
+  * The integer only counterpart
+  */
+ int iprintf(const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vfprintf(_STDOUT, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int fiprintf(FILE *file, const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vfprintf(file, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int siprintf(char *buffer, const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vsnprintf(buffer, ~(size_t)0, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int sniprintf(char *buffer, size_t n, const char *format, ...) {
+       va_list ap;
+       int rv;
+       va_start(ap, format);
+       rv = vsnprintf(buffer, n, format, ap);
+       va_end(ap);
+       return rv;
+ }
+ int viprintf(const char *format, va_list ap) {
+       return vfprintf(_STDOUT, format, ap);
+ }
+ int vsiprintf(char *buffer, const char *format, va_list ap) {
+       return vsnprintf(buffer, ~(size_t)0, format, ap);
+ }
+ int vfiprintf(FILE *file, const char *format, va_list ap) {
+       int rv;
+       /* Just print to _STDOUT */
+       rv = print(file,NULL,~(size_t)0, format,ap);
+       return rv;
+ }
+ int vsniprintf(char *buffer, size_t n, const char *format, va_list ap) {
+       int rv;
+       rv = print(NULL, &buffer, n, format,ap);
+       return rv;
+ }
+ /**
+  *
+  * @param file  The file to print to
+  * @param buf   The buffer to print to
+  * @param c           The char to print
+  * @return
+  */
+ static inline int emitChar( FILE *file, char **buf, char c, int *left ) {
+       if( (*left) == 1 ) {
+               return 1;
+       }
+       --(*left);
+       if( buf == NULL ) {
+ #if HOST_TEST
+               putc(c, _STDOUT);
+               fflush(_STDOUT);
+ #else
 -              arc_putchar(file,c);
++              arc_putchar((int)file, c);
+ #endif
+       } else {
+               **buf = c;
+               (*buf)++;
+       }
+       return 1;
+ }
+ #if defined(HOST_TEST)
+ /**
+  * Convert a number to a string
+  *
+  * @param val         The value to convert
+  * @param str         Pointer to a space where to put the string
+  * @param base                The base
+  * @param negative    If negative or not.
+  */
+ void xtoa( unsigned long val, char* str, int base, int negative) {
+       int i;
+       char *oStr = str;
+       char c;
+       if (negative) {
+               val = -val;
+       }
+       if( base < 10 && base > 16 ) {
+               *str = '0';
+               return;
+       }
+     i = 0;
+     do {
+       str[i++] = "0123456789abcdef"[ val % base ];
+       } while ((val /= base) > 0);
+     if (negative) {
+         str[i++] = '-';
+     }
+     str[i] = '\0';
+     str = &str[i]-1;
+     while(str > oStr) {
+       c = *str;
+       *str-- = *oStr;
+       *oStr++=c;
+     }
+ }
+ #else
+ extern void xtoa( unsigned long val, char* str, int base, int negative);
+ #endif
+ #define FL_NONE                                       (0<<0)
+ #define FL_ZERO                                       (1<<1)
+ #define FL_HASH                                       (1<<2)
+ #define FL_SPACE                              (1<<3)
+ #define FL_ALIGN_LEFT                 (1<<4)
+ #define FL_TYPE_SIGNED_INT            (1<<5)
+ #define FL_TYPE_UNSIGNED_INT  (1<<6)
+ static void emitString( FILE *file, char **buffer, char *string, int width, int flags, int *left) {
+       char pad;
+       char *str = string;
+       int i;
+       int strLen;
+       /* padding: FL_ZERO or normal ' '
+        * align: FL_ALIGN_LEFT (left) or normal (right)
+        */
+       pad = (flags & FL_ZERO) ? '0' : ' ';
+       if( flags & FL_ALIGN_LEFT ) {
+               for(i=0;str[i]; i++) {
+                       emitChar(file,buffer,str[i],left);
+               }
+               /* Pad the rest */
+               for(;i<width;i++) {
+                       emitChar(file,buffer,pad,left);
+               }
+       } else {
+               strLen = strlen(string);
+               /* Pad first  */
+               if( width > strLen ) {
+                       for(i=0;i<(width-strLen);i++) {
+                               emitChar(file,buffer,pad,left);
+                       }
+               }
+               for(i=0;i<strLen; i++) {
+                       emitChar(file,buffer,string[i],left);
+               }
+       }
+ }
 -void emitInt( FILE *file, char **buffer, int base, int width, int flags, va_list ap, int *left )
++void emitInt( FILE *file, char **buffer, int val, int base, int width, int flags, int *left )
+ {
+       char lBuf[12];  // longest is base 10, 2^32
+       char *str = lBuf;
 -      int val;
+       if( flags & FL_TYPE_SIGNED_INT ) {
 -              val = (int )va_arg( ap, int );
+               xtoa(val,str,base ,(val < 0));
+       } else {
 -              xtoa((unsigned)va_arg( ap, int ),str,base ,0);
++              xtoa((unsigned)val,str,base ,0);
+       }
+       emitString(file,buffer,str,width,flags,left);
+ }
 -
 -
+ #define PRINT_CHAR(_c)  *buffer++= (_c);
+ /**
+  * Write formatted output to an array with a maximum number of characters.
+  *
+  * This is the mother of the formatted print family. The main goal here
+  * is to be very small and memory efficient.
+  *
+  * Support:
+  *   Parameter: None
+  *   Flags    : '-' and '0'
+  *   Width    : Normal padding is supported, '*' is not.
+  *   Precision: None
+  *   Length   : None
+  *   C99      : None
+  *   Type     : d,u,x,s,and c
+  *
+  * @param file    The file descriptor
+  * @param buffer  A pointer to the place to store the output
+  *                If NULL the output is instead
+  * @param n       The maximum number of characters to write
+  * @param format  The format string
+  * @param ap      The va list
+  * @return
+  */
+ int print(FILE *file, char **buffer, size_t n, const char *format, va_list ap)
+ {
+       char ch;
+       int flags;
+       char *str;
+       int width;
+       int left = n;
+       while ( (ch = *format++) ) {
+               if (ch == '%') {
+                       ch = *format++;
+                       if( ch == '%') {
+                               emitChar(file,buffer,ch,&left);
+                               continue;
+                       }
+                       /* Find flags */
+                       switch (ch) {
+                       case '0':
+                               flags = FL_ZERO;
+                               break;
+                       case ' ':
+                               flags = FL_SPACE;
+                               break;
+                       case '-':
+                               flags = FL_ALIGN_LEFT;
+                               break;
+                       default:
+                               /* Not supported or no flag */
+                               flags = FL_NONE;
+                               format--;
+                               break;
+                       }
+                       ch = *format++;
+                       /* Width */
+                       if( (ch >= '0')  && (ch <= '9') ) {
+                               width = ch -'0';
+                               ch = *format++;
+                       } else {
+                               width = 0;
+                       }
+                       /* Find type */
+                       switch (ch) {
+                       case 'c':
+                               emitChar(file,buffer,(char )va_arg( ap, int ),&left);
+                               break;
+                       case 'd':
+                               flags |= FL_TYPE_SIGNED_INT;
 -                              emitInt(file,buffer,10,width,flags,ap,&left);
++                              emitInt(file,buffer,va_arg( ap, int ),10,width,flags,&left);
+                               break;
+                       case 'u':
+                               flags |= FL_TYPE_UNSIGNED_INT;
 -                              emitInt(file,buffer,10,width,flags,ap,&left);
++                              emitInt(file,buffer,va_arg( ap, int ),10,width,flags,&left);
+                               break;
+                       case 'x':
+                               flags |= FL_TYPE_UNSIGNED_INT;
 -                              emitInt(file,buffer,16,width,flags,ap,&left);
++                              emitInt(file,buffer,va_arg( ap, int ),16,width,flags,&left);
+                               break;
+                       case 's':
+                               str = (char *)va_arg( ap, int );
+                               if( str == NULL ) {
+                                       str = "(null)";
+                               }
+                               emitString(file,buffer,str,width,flags,&left);
+                               break;
+                       default:
+                               assert(0); // oops
+                               break;
+                       }
+               } else {
+                       flags = FL_NONE;
+                       emitChar(file,buffer,ch,&left);
+               }
+       }
 -      va_end(ap);
++//    va_end(ap);             // Removed, TODO: Check the va_start/va_end handling (used in calling functions also).
+       if(buffer!=0) {
+               left = 0;
+               emitChar(file,buffer,'\0',&left);
+       }
+       return 0; // Wrong.. but for now.
+ }
+ #if defined(HOST_TEST)
+ int main(void) {
+       char *ptr = NULL;
+       char buff[30];
+       printf("char: %c %c = a B\n", 'a', 66);
+       printf("string: %s = (null)\n", (char *)ptr);
+       printf("string: %s = foobar \n", "foobar");
+       printf("string: %2s = foobar \n", "foobar");
+       printf("string: \"%8s\" = \"  foobar\" \n", "foobar");
+       /* Left justify */
+       printf("string: \"%-8s\" = \"foobar  \" \n", "foobar");
+       printf("decimal:  23 = %d \n", 23);
+       printf("hex:     c23 = %x \n", 0xc23);
+       printf("hex:    0c23 = %04x \n", 0xc23);
+       printf("decimal with blanks:     23 = %6d  \n", 23);
+       printf("decimal with zero:   000023 = %06d \n", 23);
+       /* negative and large numbers */
+       printf("decimal:  -23 = %d \n", -23);
+       printf("decimal:  4294967273 = %u \n", -23);
+       printf("decimal:  c0000000   = %x \n", 0xc0000000);
+       printf("decimal:  00c000   = %06x \n", 0xc000);
+       fprintf(_STDOUT, "string: %s = foobar \n", "foobar");
+       sprintf(buff, "string: %s = foobar \n", "foobar");
+       printf("%s",buff);
+       snprintf(buff,10, "%s\n", "12345678901234567");
+       printf("\"123456789\" = \"%s\"\n",buff);
+       snprintf(buff,12, "%s\n", "abcdefghijklmn");
+       printf("\"abcdefghijkl\" = \"%s\"\n",buff);
+       return 0;
+ }
+ #endif
index ee696f67259d6ce9f168e48eb1e7e1cc171802ae,d6d4ec25bccc5822daaf0f7c19eac76f77d8255b..a64521f17844ca794f045dcdaf243e54f0b399ba
@@@ -1,42 -1,41 +1,42 @@@
\r
- # Our object files\r
- obj-y += blinker_main.o\r
- obj-y += Tasks.o\r
- obj-y += Hooks.o\r
- obj-y += Rte.o\r
\r
- # OS object files.\r
- obj-y += Os_Cfg.o\r
- # Board object files\r
- include $(ROOTDIR)/boards/board_common.mk\r
\r
- ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))\r
\r
- # The more precise configuration, the higher preceedance.\r
- VPATH := ../config/$(BOARDDIR) ../config $(VPATH)\r
- inc-y := ../config/$(BOARDDIR) ../config $(inc-y)\r
\r
- inc-y += $(ROOTDIR)/system/kernel/$(objdir)\r
- inc-y += $(ROOTDIR)/system/kernel/include\r
\r
- #TODO: Remove?, Build other way?\r
- VPATH += $(ROOTDIR)/$(SUBDIR)/Rte\r
- inc-y += $(ROOTDIR)/$(SUBDIR)/Rte\r
- VPATH += $(ROOTDIR)/components/blinker\r
- inc-y += $(ROOTDIR)/components/blinker\r
\r
\r
- # libs needed by us \r
- #libitem-y +=\r
\r
- #linkfile\r
- ldcmdfile-y = linkscript_gcc.ldp\r
- vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts\r
\r
- # What I want to build\r
- build-exe-y = blinker_node.elf\r
\r
\r
\r
\r
\r
+ # Our object files
+ obj-y += blinker_main.o
+ obj-y += Tasks.o
+ obj-y += Hooks.o
+ obj-y += Rte.o
+ # OS object files.
+ obj-y += Os_Cfg.o
+ # Board object files
+ include $(ROOTDIR)/boards/board_common.mk
+ ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))
+ # The more precise configuration, the higher preceedance.
+ VPATH := ../config/$(BOARDDIR) ../config $(VPATH)
+ inc-y := ../config/$(BOARDDIR) ../config $(inc-y)
+ inc-y += $(ROOTDIR)/system/kernel/$(objdir)
+ inc-y += $(ROOTDIR)/system/kernel/include
+ #TODO: Remove?, Build other way?
+ VPATH += $(ROOTDIR)/$(SUBDIR)/Rte
+ inc-y += $(ROOTDIR)/$(SUBDIR)/Rte
+ VPATH += $(ROOTDIR)/components/blinker
+ inc-y += $(ROOTDIR)/components/blinker
+ # libs needed by us 
+ #libitem-y +=
+ #linkfile
 -ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf
++ldcmdfile-y = linkscript_gcc.ldp
++vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts
+ # What I want to build
+ build-exe-y = blinker_node.elf
index 195b735a66267607ad898fbcf44d812098d9b254,60eb87432392e4db6e34cf2dee134000eac2ce18..2260be0ce3e8efe8c0ba688f25282786ee936811
@@@ -1,44 -1,43 +1,44 @@@
\r
- # Our object files\r
- obj-y += pwm_sine_main.o\r
- obj-y += Tasks.o\r
- obj-y += Hooks.o\r
- obj-y += Rte.o\r
\r
- # OS object files.\r
- obj-y += Os_Cfg.o\r
- # Board object files\r
- include $(ROOTDIR)/boards/board_common.mk\r
\r
- ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))\r
\r
- # The more precise configuration, the higher preceedance.\r
- VPATH := ../config/$(BOARDDIR) ../config $(VPATH)\r
- inc-y := ../config/$(BOARDDIR) ../config $(inc-y)\r
\r
\r
\r
- inc-y += $(ROOTDIR)/system/kernel/$(objdir)\r
- inc-y += $(ROOTDIR)/system/kernel/include\r
\r
- #TODO: Remove?, Build other way?\r
- VPATH += $(ROOTDIR)/$(SUBDIR)/Rte\r
- inc-y += $(ROOTDIR)/$(SUBDIR)/Rte\r
- VPATH += $(ROOTDIR)/components/pwm_sine\r
- inc-y += $(ROOTDIR)/components/pwm_sine\r
\r
\r
- # libs needed by us \r
- #libitem-y +=\r
\r
- #linkfile\r
- ldcmdfile-y = linkscript_gcc.ldp\r
- vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts\r
\r
- # What I want to build\r
- build-exe-y = pwm_node.elf\r
\r
\r
\r
\r
\r
+ # Our object files
+ obj-y += pwm_sine_main.o
+ obj-y += Tasks.o
+ obj-y += Hooks.o
+ obj-y += Rte.o
+ # OS object files.
+ obj-y += Os_Cfg.o
+ # Board object files
+ include $(ROOTDIR)/boards/board_common.mk
+ ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))
+ # The more precise configuration, the higher preceedance.
+ VPATH := ../config/$(BOARDDIR) ../config $(VPATH)
+ inc-y := ../config/$(BOARDDIR) ../config $(inc-y)
+ inc-y += $(ROOTDIR)/system/kernel/$(objdir)
+ inc-y += $(ROOTDIR)/system/kernel/include
+ #TODO: Remove?, Build other way?
+ VPATH += $(ROOTDIR)/$(SUBDIR)/Rte
+ inc-y += $(ROOTDIR)/$(SUBDIR)/Rte
+ VPATH += $(ROOTDIR)/components/pwm_sine
+ inc-y += $(ROOTDIR)/components/pwm_sine
+ # libs needed by us 
+ #libitem-y +=
+ #linkfile
 -ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf
++ldcmdfile-y = linkscript_gcc.ldp
++vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts
+ # What I want to build
+ build-exe-y = pwm_node.elf
index 9e330df0bf0ab262fa6bf92648edde323fde48cb,f073267c2bc6a933855fd137a3005ea3d40ac4e7..41297f8e9c0adfaa15b8b7ddb413c1a43200373b
@@@ -1,45 -1,44 +1,45 @@@
\r
- # Our object files\r
- obj-y += pwm_node2_helpers.o\r
- obj-y += fading_led.o\r
- obj-y += Rte.o\r
- obj-y += Tasks.o\r
- obj-y += Hooks.o\r
\r
- inc-y += $(ROOTDIR)/system/kernel/$(objdir)\r
- inc-y += $(ROOTDIR)/system/kernel/include\r
\r
- # OS object files.\r
- obj-y += Os_Cfg.o\r
- # Board object files\r
- include $(ROOTDIR)/boards/board_common.mk\r
\r
- ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))\r
\r
- # The more precise configuration, the higher preceedance.\r
- VPATH := ../config/$(BOARDDIR) ../config $(VPATH)\r
- inc-y := ../config/$(BOARDDIR) ../config $(inc-y)\r
\r
- inc-y += $(ROOTDIR)/system/kernel/$(objdir)\r
\r
- #TODO: Remove?, Build other way?\r
- VPATH += $(ROOTDIR)/$(SUBDIR)/Rte\r
- inc-y += $(ROOTDIR)/$(SUBDIR)/Rte\r
- VPATH += $(ROOTDIR)/components/fading_led\r
- inc-y += $(ROOTDIR)/components/fading_led\r
\r
\r
- # libs needed by us \r
- #libitem-y +=\r
\r
- #linkfile\r
- ldcmdfile-y = linkscript_gcc.ldp\r
- vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts\r
\r
- # What I want to build\r
- build-exe-y = pwm_node2.elf\r
\r
\r
\r
\r
\r
+ # Our object files
+ obj-y += pwm_node2_helpers.o
+ obj-y += fading_led.o
+ obj-y += Rte.o
+ obj-y += Tasks.o
+ obj-y += Hooks.o
+ inc-y += $(ROOTDIR)/system/kernel/$(objdir)
+ inc-y += $(ROOTDIR)/system/kernel/include
+ # OS object files.
+ obj-y += Os_Cfg.o
+ # Board object files
+ include $(ROOTDIR)/boards/board_common.mk
+ ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))
+ # The more precise configuration, the higher preceedance.
+ VPATH := ../config/$(BOARDDIR) ../config $(VPATH)
+ inc-y := ../config/$(BOARDDIR) ../config $(inc-y)
+ inc-y += $(ROOTDIR)/system/kernel/$(objdir)
+ #TODO: Remove?, Build other way?
+ VPATH += $(ROOTDIR)/$(SUBDIR)/Rte
+ inc-y += $(ROOTDIR)/$(SUBDIR)/Rte
+ VPATH += $(ROOTDIR)/components/fading_led
+ inc-y += $(ROOTDIR)/components/fading_led
+ # libs needed by us 
+ #libitem-y +=
+ #linkfile
 -ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf
++ldcmdfile-y = linkscript_gcc.ldp
++vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts
+ # What I want to build
+ build-exe-y = pwm_node2.elf
index 22442c4049be92c4bab161769fcf268029640b39,d040f365f62a4abeaa225d2a193a3b925c477170..7a28204241cd28ae41ff9efa712245ed1e349908
@@@ -1,17 -1,17 +1,17 @@@
 -/* 
 -* Configuration of module Os (Os_Cfg.c)
 -* 
 -* Created by: ArcCore AB
 -* Configured for (MCU): Undefined MCU
 -* 
 -* Module editor vendor:  ArcCore
 -* Module editor version: 2.0.7
 -* 
 -* Copyright ArcCore AB 2010
 -* Generated by Arctic Studio (http://arccore.com)
 -*           on Thu Jun 17 10:18:14 CEST 2010
 -*/
 -
 +/* \r
 +* Configuration of module Os (Os_Cfg.c)\r
 +* \r
 +* Created by: ArcCore AB\r
 +* Configured for (MCU): Undefined MCU\r
 +* \r
 +* Module editor vendor:  ArcCore\r
 +* Module editor version: 2.0.7\r
 +* \r
 +* Copyright ArcCore AB 2010\r
 +* Generated by Arctic Studio (http://arccore.com)\r
- *           on Mon May 03 11:26:09 CEST 2010\r
++*           on Thu Jun 17 10:18:14 CEST 2010\r
 +*/\r
 +\r
        \r
  \r
  #include <stdlib.h>\r
index 1f4617e99194252461a9649baa8bae35eeeeac19,f6b94b8db341dee2c5f178c4558934fe7e5828af..4ba786e6e73e6f12c52cebc6f2b6800124de26f8
@@@ -1,22 -1,22 +1,22 @@@
 -/* 
 -* Configuration of module Os (Os_Cfg.h)
 -* 
 -* Created by: ArcCore AB
 -* Configured for (MCU): Undefined MCU
 -* 
 -* Module editor vendor:  ArcCore
 -* Module editor version: 2.0.7
 -* 
 -* Copyright ArcCore AB 2010
 -* Generated by Arctic Studio (http://arccore.com)
 -*           on Thu Jun 17 10:18:14 CEST 2010
 -*/
 -
 -
 -#if (OS_SW_MAJOR_VERSION != 2) 
 -#error "Os: Configuration file version differs from BSW version."
 -#endif
 -
 +/* \r
 +* Configuration of module Os (Os_Cfg.h)\r
 +* \r
 +* Created by: ArcCore AB\r
 +* Configured for (MCU): Undefined MCU\r
 +* \r
 +* Module editor vendor:  ArcCore\r
 +* Module editor version: 2.0.7\r
 +* \r
 +* Copyright ArcCore AB 2010\r
 +* Generated by Arctic Studio (http://arccore.com)\r
- *           on Mon May 03 11:26:09 CEST 2010\r
++*           on Thu Jun 17 10:18:14 CEST 2010\r
 +*/\r
 +\r
 +\r
 +#if (OS_SW_MAJOR_VERSION != 2) \r
 +#error "Os: Configuration file version differs from BSW version."\r
 +#endif\r
 +\r
  \r
  #ifndef OS_CFG_H_\r
  #define OS_CFG_H_\r
index 8ef59e3702351431fc237db9840af66dbc6ca366,5a2032c8dd037f06b8713c8eb000db8d942ab491..d9bf0e99cd9dd69beb9186ebdac08e9727e4c228
@@@ -1,45 -1,44 +1,45 @@@
\r
- # Our object files\r
- obj-y += switch_node_helpers.o\r
- obj-y += switch.o\r
- obj-y += Rte.o\r
- obj-y += Tasks.o\r
- obj-y += Hooks.o\r
\r
- inc-y += $(ROOTDIR)/system/kernel/$(objdir)\r
- inc-y += $(ROOTDIR)/system/kernel/include\r
\r
- # OS object files.\r
- obj-y += Os_Cfg.o\r
- # Board object files\r
- include $(ROOTDIR)/boards/board_common.mk\r
\r
- ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))\r
\r
- # The more precise configuration, the higher preceedance.\r
- VPATH := ../config/$(BOARDDIR) ../config $(VPATH)\r
- inc-y := ../config/$(BOARDDIR) ../config $(inc-y)\r
\r
- inc-y += $(ROOTDIR)/system/kernel/$(objdir)\r
\r
- #TODO: Remove?, Build other way?\r
- VPATH += $(ROOTDIR)/$(SUBDIR)/Rte\r
- inc-y += $(ROOTDIR)/$(SUBDIR)/Rte\r
- VPATH += $(ROOTDIR)/components/switch\r
- inc-y += $(ROOTDIR)/components/switch\r
\r
\r
- # libs needed by us \r
- #libitem-y +=\r
\r
- #linkfile\r
- ldcmdfile-y = linkscript_gcc.ldp\r
- vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts\r
\r
- # What I want to build\r
- build-exe-y = switch_node.elf\r
\r
\r
\r
\r
\r
+ # Our object files
+ obj-y += switch_node_helpers.o
+ obj-y += switch.o
+ obj-y += Rte.o
+ obj-y += Tasks.o
+ obj-y += Hooks.o
+ inc-y += $(ROOTDIR)/system/kernel/$(objdir)
+ inc-y += $(ROOTDIR)/system/kernel/include
+ # OS object files.
+ obj-y += Os_Cfg.o
+ # Board object files
+ include $(ROOTDIR)/boards/board_common.mk
+ ABSDIR := $(subst $(TOPDIR)/,,$(CURDIR))
+ # The more precise configuration, the higher preceedance.
+ VPATH := ../config/$(BOARDDIR) ../config $(VPATH)
+ inc-y := ../config/$(BOARDDIR) ../config $(inc-y)
+ inc-y += $(ROOTDIR)/system/kernel/$(objdir)
+ #TODO: Remove?, Build other way?
+ VPATH += $(ROOTDIR)/$(SUBDIR)/Rte
+ inc-y += $(ROOTDIR)/$(SUBDIR)/Rte
+ VPATH += $(ROOTDIR)/components/switch
+ inc-y += $(ROOTDIR)/components/switch
+ # libs needed by us 
+ #libitem-y +=
+ #linkfile
 -ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf
++ldcmdfile-y = linkscript_gcc.ldp
++vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts
+ # What I want to build
+ build-exe-y = switch_node.elf
diff --cc include/Dio.h
index df771594b2bd5314a57bb75346cf134869c8ff4a,022643b7216a08192f67f3a997105c828f17498c..824b8a2ac8affc2e1f87841520217bcac6e141de
- /* -------------------------------- Arctic Core ------------------------------\r
-  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
-  *\r
-  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
-  *\r
-  * This source code is free software; you can redistribute it and/or modify it\r
-  * under the terms of the GNU General Public License version 2 as published by the\r
-  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
-  *\r
-  * This program is distributed in the hope that it will be useful, but\r
-  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
-  * for more details.\r
-  * -------------------------------- Arctic Core ------------------------------*/\r
\r
\r
\r
\r
\r
\r
\r
\r
- #ifndef DIO_H_\r
- #define DIO_H_\r
\r
- #include "Std_Types.h" /** @req DIO131 */\r
\r
- // API Service ID's\r
- #define DIO_READCHANNEL_ID                    0x00\r
- #define DIO_WRITECHANNEL_ID                   0x01\r
- #define DIO_READPORT_ID                               0x02\r
- #define DIO_WRITEPORT_ID                      0x03\r
- #define DIO_READCHANNELGROUP_ID               0x04\r
- #define DIO_WRITECHANNELGROUP_ID      0x05\r
- #define DIO_GETVERSIONINFO_ID         0x12\r
\r
- #define DIO_E_PARAM_INVALID_CHANNEL_ID                10\r
- #define DIO_E_PARAM_INVALID_PORT_ID           20\r
- #define DIO_E_PARAM_INVALID_GROUP_ID          31\r
\r
- #if defined(CFG_HC1X)\r
- typedef uint8 Dio_ChannelType;\r
- typedef uint8 Dio_PortType;\r
\r
- /** @req DIO021 */\r
- /** @req DIO022 */\r
- typedef struct\r
- {\r
-   Dio_PortType port;\r
-   uint8 offset;\r
-   uint8 mask;\r
- } Dio_ChannelGroupType;\r
\r
- /** @req DIO023 */\r
- typedef uint8 Dio_LevelType;\r
\r
- /** @req DIO024 */\r
- typedef uint8 Dio_PortLevelType;\r
\r
- #else // CFG_PPC, CFG_STM32_STAMP and others\r
- typedef uint32 Dio_ChannelType;\r
- typedef uint32 Dio_PortType;\r
- typedef struct\r
- {\r
-   Dio_PortType port;\r
-   uint8 offset;\r
-   uint32 mask;\r
- } Dio_ChannelGroupType;\r
\r
- typedef uint32 Dio_LevelType;\r
\r
- typedef uint16 Dio_PortLevelType;\r
- #endif\r
\r
\r
- #define DIO_MODULE_ID                 MODULE_ID_DIO\r
- #define DIO_VENDOR_ID                 1\r
\r
- #define DIO_SW_MAJOR_VERSION  1\r
- #define DIO_SW_MINOR_VERSION  0\r
- #define DIO_SW_PATCH_VERSION  0\r
\r
- #define DIO_AR_MAJOR_VERSION  2\r
- #define DIO_AR_MINOR_VERSION  2 \r
- #define DIO_AR_PATCH_VERSION  1 \r
\r
- #include "Dio_Cfg.h"\r
\r
- /** @req DIO124 */\r
- #if ( DIO_VERSION_INFO_API == STD_ON)\r
- /** @req DIO139 */\r
- #define Dio_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,DIO)\r
- #endif\r
\r
- /** @req DIO133 */\r
- /** @req DIO027 */\r
- Dio_LevelType Dio_ReadChannel(Dio_ChannelType channelId);\r
\r
- /** @req DIO134 */\r
- void Dio_WriteChannel(Dio_ChannelType channelId, Dio_LevelType level);\r
\r
- /** @req DIO135 */\r
- /** @req DIO031 */\r
- Dio_PortLevelType Dio_ReadPort(Dio_PortType portId);\r
\r
- /** @req DIO136 */\r
- void Dio_WritePort(Dio_PortType portId, Dio_PortLevelType level);\r
\r
- /** @req DIO137 */\r
- Dio_PortLevelType Dio_ReadChannelGroup( const Dio_ChannelGroupType *channelGroupIdPtr );\r
\r
- /** @req DIO138 */\r
- void Dio_WriteChannelGroup(const Dio_ChannelGroupType *channelGroupIdPtr, Dio_PortLevelType level);\r
\r
- #endif /*DIO_H_*/\r
+ /* -------------------------------- Arctic Core ------------------------------
+  * Arctic Core - the open source AUTOSAR platform http://arccore.com
+  *
+  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
+  *
+  * This source code is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU General Public License version 2 as published by the
+  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
+  *
+  * This program is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  * for more details.
+  * -------------------------------- Arctic Core ------------------------------*/
++
++
++
++
++
++
++
+ #ifndef DIO_H_
+ #define DIO_H_
+ #include "Std_Types.h" /** @req DIO131 */
+ // API Service ID's
+ #define DIO_READCHANNEL_ID                    0x00
+ #define DIO_WRITECHANNEL_ID                   0x01
+ #define DIO_READPORT_ID                               0x02
+ #define DIO_WRITEPORT_ID                      0x03
+ #define DIO_READCHANNELGROUP_ID               0x04
+ #define DIO_WRITECHANNELGROUP_ID      0x05
+ #define DIO_GETVERSIONINFO_ID         0x12
+ #define DIO_E_PARAM_INVALID_CHANNEL_ID                10
+ #define DIO_E_PARAM_INVALID_PORT_ID           20
+ #define DIO_E_PARAM_INVALID_GROUP_ID          31
++#if defined(CFG_HC1X)
++typedef uint8 Dio_ChannelType;
++typedef uint8 Dio_PortType;
++
++/** @req DIO021 */
++/** @req DIO022 */
++typedef struct
++{
++  Dio_PortType port;
++  uint8 offset;
++  uint8 mask;
++} Dio_ChannelGroupType;
++
++/** @req DIO023 */
++typedef uint8 Dio_LevelType;
++
++/** @req DIO024 */
++typedef uint8 Dio_PortLevelType;
++
++#else // CFG_PPC, CFG_STM32_STAMP and others
++typedef uint32 Dio_ChannelType;
++typedef uint32 Dio_PortType;
++typedef struct
++{
++  Dio_PortType port;
++  uint8 offset;
++  uint32 mask;
++} Dio_ChannelGroupType;
++
++typedef uint32 Dio_LevelType;
++
++typedef uint16 Dio_PortLevelType;
++#endif
++
++
++#define DIO_MODULE_ID                 MODULE_ID_DIO
++#define DIO_VENDOR_ID                 1
++
+ #define DIO_SW_MAJOR_VERSION  1
+ #define DIO_SW_MINOR_VERSION  0
+ #define DIO_SW_PATCH_VERSION  0
 -#define DIO_AR_MAJOR_VERSION     2
 -#define DIO_AR_MINOR_VERSION     2 
 -#define DIO_AR_PATCH_VERSION     1 
++#define DIO_AR_MAJOR_VERSION  2
++#define DIO_AR_MINOR_VERSION  2 
++#define DIO_AR_PATCH_VERSION  1 
+ #include "Dio_Cfg.h"
+ /** @req DIO124 */
+ #if ( DIO_VERSION_INFO_API == STD_ON)
+ /** @req DIO139 */
 -void Dio_GetVersionInfo( Std_VersionInfoType *versionInfo );
++#define Dio_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,DIO)
+ #endif
+ /** @req DIO133 */
+ /** @req DIO027 */
+ Dio_LevelType Dio_ReadChannel(Dio_ChannelType channelId);
++
+ /** @req DIO134 */
+ void Dio_WriteChannel(Dio_ChannelType channelId, Dio_LevelType level);
+ /** @req DIO135 */
+ /** @req DIO031 */
+ Dio_PortLevelType Dio_ReadPort(Dio_PortType portId);
++
+ /** @req DIO136 */
+ void Dio_WritePort(Dio_PortType portId, Dio_PortLevelType level);
+ /** @req DIO137 */
+ Dio_PortLevelType Dio_ReadChannelGroup( const Dio_ChannelGroupType *channelGroupIdPtr );
++
+ /** @req DIO138 */
+ void Dio_WriteChannelGroup(const Dio_ChannelGroupType *channelGroupIdPtr, Dio_PortLevelType level);
+ #endif /*DIO_H_*/
diff --cc include/Os.h
index 076b53372dd4ad7e7ad8962722d91e0e659dafe3,e1f482232c3d548a0a981d32841efdbf845eb339..55dd70b8eb1de5f32a6bc4dbcd10a75409d7c616
@@@ -282,7 -275,17 +276,17 @@@ typedef TickType *TickRefType
  StatusType IncrementCounter( CounterType );\r
  StatusType GetCounterValue( CounterType, TickRefType );\r
  StatusType GetElapsedCounterValue( CounterType, TickRefType val, TickRefType elapsed_val);\r
 -
 -
 -/*-------------------------------------------------------------------
 - * System timer
 - *-----------------------------------------------------------------*/
 -typedef const uint32 OsTickType;
 -void Os_SysTickInit( void );
 -void Os_SysTickStart(TickType period_ticks);
 -TickType Os_SysTickGetValue( void );
 -TickType Os_SysTickGetElapsedValue( TickType preValue );
 +\r
++\r
++/*-------------------------------------------------------------------\r
++ * System timer\r
++ *-----------------------------------------------------------------*/\r
++typedef const uint32 OsTickType;\r
++void Os_SysTickInit( void );\r
++void Os_SysTickStart(TickType period_ticks);\r
++TickType Os_SysTickGetValue( void );\r
++TickType Os_SysTickGetElapsedValue( TickType preValue );\r
\r
  /*-------------------------------------------------------------------\r
   * Schedule Tables\r
   *-----------------------------------------------------------------*/\r
Simple merge
index 2fc7b87f96c290109391b5541dde9da9b5786a75,3e7daa20ad93e37f5bf81b4ff6c68af1df40b071..65d91583fe02bd08de0e069203090425746dbec0
   */\r
  #include "kernel.h"\r
  #include "Os_Cfg.h"\r
 -
 -/** @req OS327 */
 -#if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)
 -#if (OS_STATUS_STANDARD == STD_ON )
 -#error req OS327 not fullfilled
 -#endif
 -#endif
 -
 -\r
 -// COUNTER, RESOURCE, TSAK, must be at least 1
 -
 -#define OS_VALIDATE(_a,_b)   if((_a)!=(_b) ) { \
 -                                                              assert(#_a  #_b); \
 -                                                        }
 -
 -
 -
 -
 -void Os_CfgValidate(void ) {
 -      OS_VALIDATE(OS_COUNTER_CNT,ARRAY_SIZE(counter_list));
 -#if (RESOURCE_CNT!=0)
 -      OS_VALIDATE(OS_RESOURCE_CNT,ARRAY_SIZE(resource_list));
 -#endif
 -      OS_VALIDATE(OS_TASK_CNT ,ARRAY_SIZE(rom_pcb_list));
 -#if (RESOURCE_CNT!=0)
 -      OS_VALIDATE(OS_ALARM_CNT,ARRAY_SIZE(alarm_list));
 -#endif
 -#if (OS_SCHTBL_CNT!=0)
 -      OS_VALIDATE(OS_SCHTBL_CNT, ARRAY_SIZE(sched_list));
 -#endif
 -}
 +\r
 +/** @req OS327 */\r
 +#if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)\r
 +#if (OS_STATUS_STANDARD == STD_ON )\r
 +#error req OS327 not fullfilled\r
 +#endif\r
 +#endif\r
 +\r
 +\r
 +// COUNTER, RESOURCE, TSAK, must be at least 1\r
 +\r
 +#define OS_VALIDATE(_a,_b)   if((_a)!=(_b) ) { \\r
 +                                                              assert(#_a  #_b); \\r
 +                                                        }\r
 +\r
 +\r
 +\r
 +\r
 +void Os_CfgValidate(void ) {\r
 +      OS_VALIDATE(OS_COUNTER_CNT,ARRAY_SIZE(counter_list));\r
 +#if (RESOURCE_CNT!=0)\r
 +      OS_VALIDATE(OS_RESOURCE_CNT,ARRAY_SIZE(resource_list));\r
 +#endif\r
 +      OS_VALIDATE(OS_TASK_CNT ,ARRAY_SIZE(rom_pcb_list));\r
 +#if (RESOURCE_CNT!=0)\r
 +      OS_VALIDATE(OS_ALARM_CNT,ARRAY_SIZE(alarm_list));\r
 +#endif\r
 +#if (OS_SCHTBL_CNT!=0)\r
 +      OS_VALIDATE(OS_SCHTBL_CNT, ARRAY_SIZE(sched_list));\r
 +#endif\r
 +}\r
  \r
os_error_t os_error;\r
OsErrorType os_error;\r
  \r
  //-------------------------------------------------------------------\r
  \r
index 75cab81c9f5c7fecf0fba085f3570ed4c61d794a,c501f35715f29ce2f070f397223f22c41a49ece0..89e84a5e1a16ebce1e1beb0ffd2a3388ef2dff61
@@@ -67,36 -67,16 +67,38 @@@ include $(ROOTDIR)/scripts/cc_$(COMPILE
  # Get object files\r
  include ../makefile\r
  \r
 +\r
 +##### For backwards compatability with older project makefiles\r
 +# Remove dependency on libkernel\r
 +deprecated-libs += $(ROOTDIR)/libs/libkernel_$(ARCH_MCU).a\r
 +deprecated-libs-included = $(filter $(deprecated-libs),$(libitem-y))\r
 +ifneq ($(deprecated-libs-included),)\r
 +$(info >>>> Ignoring deprecated lib dependencies: $(deprecated-libs-included)')\r
 +libitem-y := $(filter-out $(deprecated-libs),$(libitem-y))\r
 +endif\r
 +\r
 +# Automatic preprocessing of std linkscripts\r
 +old-ldcmdfile = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf\r
 +new-ldcmdfile = linkscript_gcc.ldp\r
 +old-ldcmdfile-used = $(filter $(old-ldcmdfile),$(ldcmdfile-y))\r
 +ifneq ($(old-ldcmdfile-used),)\r
 +$(info >>>> Changing linkscript to preprocessed version: $(old-ldcmdfile) -> $(new-ldcmdfile)')\r
 +ldcmdfile-y := $(subst $(old-ldcmdfile),$(new-ldcmdfile),$(ldcmdfile-y))\r
 +vpath %.ldf $(ROOTDIR)/$(ARCH_PATH-y)/scripts\r
 +endif\r
 +\r
 +#####\r
 +\r
  inc-y += $(ROOTDIR)/include\r
- #inc-$(CFG_PPC) += $(ROOTDIR)/include/ppc\r
- #inc-$(CFG_ARM) += $(ROOTDIR)/include/arm\r
  inc-y += $(ROOTDIR)/include/$(ARCH_FAM)\r
  \r
- .PHONY config:\r
  \r
- config:\r
+ .PHONY clean: \r
+ clean: FORCE\r
+       @-rm -f *.o *.d *.h *.elf *.a *.ldp\r
\r
+ .PHONY config: \r
+ config: FORCE\r
        @echo "board   modules:" $(MOD_AVAIL)\r
        @echo "example modules:" $(MOD_USE)\r
        @echo $(MOD) ${def-y}\r
@@@ -182,12 -165,11 +187,13 @@@ els
                                                                /^\.data/ { print "  data:"  $$3+0 " bytes"; rom+=$$3; ram+=$$3}; \\r
                                                                /^\.bss/ { print "  bss :"  $$3+0 " bytes"; ram+=$$3}; \\r
                                                                END { print "  ROM: ~" rom " bytes"; print "  RAM: ~" ram " bytes"}' $(subst .elf,.map,$@)\r
+ endif\r
  endif\r
 +      @echo\r
        @echo "  >>>>>>>  DONE  <<<<<<<<<"\r
 +      @echo\r
        \r
\r
+       \r
  $(size-exe-y): $(build-exe-y)\r
        $(Q)$(OBJDUMP) -h $<\r
        @echo TODO: Parse the file....\r
index eb624b74421d46aa31602ea1f2521cb285e98a98,eae5f0c8487262e56c13f89e4385738cbb91372f..d4da75a34d54dbc83419490f09d39f90c6211813
@@@ -1,25 -1,18 +1,18 @@@
 -/* -------------------------------- Arctic Core ------------------------------
 - * Arctic Core - the open source AUTOSAR platform http://arccore.com
 - *
 - * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
 - *
 - * This source code is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License version 2 as published by the
 - * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
 - *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 - * for more details.
 - * -------------------------------- Arctic Core ------------------------------*/
 -
 +/* -------------------------------- Arctic Core ------------------------------\r
 + * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
 + *\r
 + * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
 + *\r
 + * This source code is free software; you can redistribute it and/or modify it\r
 + * under the terms of the GNU General Public License version 2 as published by the\r
 + * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
 + *\r
 + * This program is distributed in the hope that it will be useful, but\r
 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
 + * for more details.\r
 + * -------------------------------- Arctic Core ------------------------------*/\r
 +\r
\r
\r
\r
\r
\r
\r
\r
  #include "EcuM.h"\r
  #include "Modules.h"\r
  #include "string.h"\r
Simple merge
index cfa0f783faeeb02067e2f343d4706e70121eb35e,a8a8ff8228135985fe840b3bf055fb4e4df5a462..4c7df9f8c810493d0acb4d782ab0c754a65dc93b
@@@ -99,18 -83,17 +99,17 @@@ StatusType WaitEvent( EventMaskType Mas
  \r
  StatusType SetEvent( TaskType TaskID, EventMaskType Mask ) {\r
        StatusType rv = E_OK;\r
 -      OsPcbType *dest_pcb;
 -      OsPcbType *currPcbPtr;
 +      OsPcbType *dest_pcb;\r
 +      OsPcbType *currPcbPtr;\r
        uint32_t flags;\r
 -
 -      if( TaskID  >= Os_CfgGetTaskCnt() ) {
 -              rv = E_OS_ID;
 -              goto err;
 -      }
  \r
-       dest_pcb = os_get_pcb(TaskID);\r
\r
\r
 -      dest_pcb = os_get_pcb(TaskID);
 +      if( TaskID  >= Os_CfgGetTaskCnt() ) {\r
 +              rv = E_OS_ID;\r
 +              goto err;\r
 +      }\r
 +\r
++      dest_pcb = os_get_pcb(TaskID);\r
\r
        if( (dest_pcb->state & ST_SUSPENDED ) ) {\r
                rv = E_OS_STATE;\r
                goto err;\r
                rv = E_OS_ACCESS;\r
                goto err;\r
        }\r
 -
 -      Irq_Save(flags);
 -
 -      /* Calling  SetEvent  causes  the  task  <TaskID>  to be  transferred
 -       * to  the  ready  state,  if  it  was  waiting  for  at  least one of the
 -       * events specified in <Mask>.
 -       *
 -       * OSEK/VDX 4.6.1,  rescheduling is performed in all of the following cases:
 -       * ..
 -       * Setting an event to a waiting task at task level (e.g. system service SetEvent,
 -       * see chapter 13.5.3.1, message notification mechanism, alarm expiration, if event setting
 -       * defined, see chapter 9.2)
 -       * ... */
 -
 -      dest_pcb->ev_set |= Mask;
 -
 -      if( (Mask & dest_pcb->ev_wait) ) {
 -              /* We have a an event match */
 -              if( dest_pcb->state & ST_WAITING) {
 -                      Os_TaskMakeReady(dest_pcb);
 -
 -                      currPcbPtr = Os_TaskGetCurrent();
 -                      /* Checking "4.6.2  Non preemptive scheduling" it does not dispatch if NON  */
 -                      if( (os_sys.int_nest_cnt == 0) &&
 -                              (currPcbPtr->scheduling == FULL) &&
 -                              (dest_pcb->prio > currPcbPtr->prio) )
 -                      {
 -                              Os_SetOp(OP_SET_EVENT);
 -                              Os_Dispatch(0);
 -                      }
 -
 -              }  else if(dest_pcb->state & ST_READY ) {
 -                      /* Hmm, we do nothing */
 -              }
 -      }
 +\r
 +      Irq_Save(flags);\r
 +\r
 +      /* Calling  SetEvent  causes  the  task  <TaskID>  to be  transferred\r
 +       * to  the  ready  state,  if  it  was  waiting  for  at  least one of the\r
 +       * events specified in <Mask>.\r
 +       *\r
 +       * OSEK/VDX 4.6.1,  rescheduling is performed in all of the following cases:\r
 +       * ..\r
 +       * Setting an event to a waiting task at task level (e.g. system service SetEvent,\r
 +       * see chapter 13.5.3.1, message notification mechanism, alarm expiration, if event setting\r
 +       * defined, see chapter 9.2)\r
 +       * ... */\r
 +\r
 +      dest_pcb->ev_set |= Mask;\r
 +\r
 +      if( (Mask & dest_pcb->ev_wait) ) {\r
 +              /* We have an event match */\r
 +              if( dest_pcb->state & ST_WAITING) {\r
 +                      Os_TaskMakeReady(dest_pcb);\r
 +\r
 +                      currPcbPtr = Os_TaskGetCurrent();\r
 +                      /* Checking "4.6.2  Non preemptive scheduling" it does not dispatch if NON  */\r
 +                      if( (os_sys.int_nest_cnt == 0) &&\r
 +                              (currPcbPtr->scheduling == FULL) &&\r
 +                              (dest_pcb->prio > currPcbPtr->prio) &&\r
 +                              (Os_SchedulerResourceIsFree()) )\r
 +                      {\r
++                              Os_SetOp(OP_SET_EVENT);\r
 +                              Os_Dispatch(0);\r
 +                      }\r
 +\r
 +              }  else if(dest_pcb->state & ST_READY ) {\r
 +                      /* Hmm, we do nothing */\r
 +              }\r
 +      }\r
  \r
        Irq_Restore(flags);\r
  \r
        OS_STD_END_2(OSServiceId_SetEvent,TaskID, Mask);\r
  }\r
 -
 -
 -/**
 - * This service returns the current state of all event bits of the task
 - * <TaskID>, not the events that the task is waiting for.
 - * The service may be called from interrupt service routines, task
 - * level and some hook routines (see Figure 12-1).
 - *  The current status of the event mask of task <TaskID> is copied
 - * to <Event>.
 - *
 - * @param TaskId Task whose event mask is to be returned.
 - * @param Mask   Reference to the memory of the return data.
 - * @return
 +\r
++\r
++/**\r
++ * This service returns the current state of all event bits of the task\r
++ * <TaskID>, not the events that the task is waiting for.\r
++ * The service may be called from interrupt service routines, task\r
++ * level and some hook routines (see Figure 12-1).\r
++ *  The current status of the event mask of task <TaskID> is copied\r
++ * to <Event>.\r
++ *\r
++ * @param TaskId Task whose event mask is to be returned.\r
++ * @param Mask   Reference to the memory of the return data.\r
++ * @return\r
+  */\r
  StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask) {\r
  \r
        OsPcbType *dest_pcb;\r
        OS_STD_END_2(OSServiceId_GetEvent,TaskId, Mask);\r
  }\r
  \r
 -
 -/**
 - * The events of the extended task calling ClearEvent are cleared
 - * according to the event mask <Mask>.
 - *
 - *
 - * @param Mask
 - * @return
 +\r
++/**\r
++ * The events of the extended task calling ClearEvent are cleared\r
++ * according to the event mask <Mask>.\r
++ *\r
++ *\r
++ * @param Mask\r
++ * @return\r
+  */\r
  StatusType ClearEvent( EventMaskType Mask) {\r
      StatusType rv = E_OK;\r
 -      OsPcbType *pcb;
 -
 -      if( os_sys.int_nest_cnt != 0 ) {
 -              rv =  E_OS_CALLEVEL;
 -              goto err;
 -      }
 +      OsPcbType *pcb;\r
 +\r
 +      if( os_sys.int_nest_cnt != 0 ) {\r
 +              rv =  E_OS_CALLEVEL;\r
 +              goto err;\r
 +      }\r
  \r
        pcb = get_curr_pcb();\r
 +\r
 +      if (pcb->proc_type != PROC_EXTENDED) {\r
 +              rv = E_OS_ACCESS;\r
 +              goto err;\r
 +      }\r
 +\r
        pcb->ev_set &= ~Mask;\r
  \r
        if (0) goto err;\r
index d8ed0bbd8fcf7c9c4dcf16efba12e6dfc63cd4fc,1faf97eef7d185407e525cb9e6d056f1751f5050..fc27f15e56d59f26723e5c9a02aa610b0ea910eb
@@@ -94,21 -94,21 +94,21 @@@ void Os_ArchInit( void )
   */\r
  void Os_ArchFirstCall( void );\r
  \r
 -
 -/**
 - * Reboot the OS. Can be used as soft reset but also to get a controlled
 - * reboot of the OS, but saving state.
 - *
 - * This should probably:
 - * - Setup the stack pointer to same as in crt0.
 - * - Jump to main?!
 - * - De-init for some devices?
 - *
 - * @param type OS_REBOOT_COLD - Reboot cold. Soft reset.
 - *             OS_REBOOT_WARM - Reboot warm. Does not run init on sections (crt0)
 - */
 -void Os_ArchReboot( int type );
 -
 +\r
 +/**\r
 + * Reboot the OS. Can be used as soft reset but also to get a controlled\r
 + * reboot of the OS, but saving state.\r
 + *\r
 + * This should probably:\r
 + * - Setup the stack pointer to same as in crt0.\r
 + * - Jump to main?!\r
 + * - De-init for some devices?\r
 + *\r
-  * @param type OS_REBOOT_COLD - Reboot cold. It quite close to reset.\r
++ * @param type OS_REBOOT_COLD - Reboot cold. Soft reset.\r
 + *             OS_REBOOT_WARM - Reboot warm. Does not run init on sections (crt0)\r
 + */\r
 +void Os_ArchReboot( int type );\r
 +\r
  \r
  /**\r
   * Get the small context size\r
index 61264f22156ddd0e04a3a190b11eac5b1a6e9123,69bdaf1b22c6d905b5419243fd4521c5baf8589f..3d5aa1be91e035990e8f3f58a465de817fd9b131
@@@ -206,22 -206,23 +206,23 @@@ typedef struct OsSchTbl 
  #define os_stbl_get_action_event(x) os_stbl_get_action(x)->event\r
  */\r
  \r
 -void Os_SchTblInit( void );
 +void Os_SchTblInit( void );\r
  void Os_SchTblAutostart( void );\r
 -void Os_SchTblCalcExpire( OsSchTblType *stbl );
 -void Os_SchTblCheck(OsCounterType *c_p);
 -void Os_SchTblAutostart( void );
 -
 -
 -static inline TickType Os_SchTblGetInitialOffset( OsSchTblType *sPtr ) {
 -      return SA_LIST_GET(&sPtr->expirePointList,0)->offset;
 -}
 -
 -static inline TickType Os_SchTblGetFinalOffset( OsSchTblType *sPtr ) {
 -      return (sPtr->duration -
 -                      SA_LIST_GET(&sPtr->expirePointList, SA_LIST_CNT(&sPtr->expirePointList)-1)->offset);
 -}
 -
 -void Os_SchTblCheck(OsCounterType *c_p);
 +void Os_SchTblCalcExpire( OsSchTblType *stbl );\r
 +void Os_SchTblCheck(OsCounterType *c_p);\r
 +void Os_SchTblAutostart( void );\r
 +\r
 +\r
 +static inline TickType Os_SchTblGetInitialOffset( OsSchTblType *sPtr ) {\r
 +      return SA_LIST_GET(&sPtr->expirePointList,0)->offset;\r
 +}\r
 +\r
 +static inline TickType Os_SchTblGetFinalOffset( OsSchTblType *sPtr ) {\r
 +      return (sPtr->duration -\r
 +                      SA_LIST_GET(&sPtr->expirePointList, SA_LIST_CNT(&sPtr->expirePointList)-1)->offset);\r
 +}\r
 +\r
++void Os_SchTblCheck(OsCounterType *c_p);\r
  \r
  \r
  #endif /*SCHED_TABLE_I_H_*/\r
index 752ec6c441d330686266c0df3714434c87767e06,5a257a249611b9c28deca95a556dad812e1902bd..001e615a75da3122df6ed50f80dc92865d24adab
  #define SYS_H_\r
  \r
  struct os_conf_global_hook_s;\r
 -
 -#define OP_SET_EVENT          1
 -#define OP_ACTIVATE_TASK      2
 -
 +\r
++#define OP_SET_EVENT          1\r
++#define OP_ACTIVATE_TASK      2\r
++\r
\r
  typedef struct sys_s {\r
  //    OsApplicationType *curr_application;\r
        /* Current running task*/\r
@@@ -25,7 -29,9 +29,9 @@@
        /* List of all tasks */\r
        OsPcbType *pcb_list;\r
        /* Interrupt nested count */\r
 -      uint32 int_nest_cnt;
 -      /* The current operation */
 +      uint32 int_nest_cnt;\r
++      /* The current operation */\r
+       uint8_t op;\r
        /* Ptr to the interrupt stack */\r
        void *int_stack;\r
        // The os tick\r
  } sys_t;\r
  \r
  extern sys_t os_sys;\r
 -
 -static inline void Os_SetOp( uint8_t op) {
 -      os_sys.op = op;
 -}
 -
 -static inline uint8_t Os_GetOp( void ) {
 -      return os_sys.op;
 -}
 +\r
++static inline void Os_SetOp( uint8_t op) {\r
++      os_sys.op = op;\r
++}\r
++\r
++static inline uint8_t Os_GetOp( void ) {\r
++      return os_sys.op;\r
++}\r
\r
  static inline OsPcbType *Os_TaskGetCurrent(  void ) {\r
        return os_sys.curr_pcb;\r
  }\r
index 67c5e6f58bf7ea010f3850435a27306fa68a0e23,247d060dff520b523aeafa6551796f80c7d90926..4acd4552b344fb370862669ba88ddc5da437ad93
- /* -------------------------------- Arctic Core ------------------------------\r
-  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
-  *\r
-  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
-  *\r
-  * This source code is free software; you can redistribute it and/or modify it\r
-  * under the terms of the GNU General Public License version 2 as published by the\r
-  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
-  *\r
-  * This program is distributed in the hope that it will be useful, but\r
-  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
-  * for more details.\r
-  * -------------------------------- Arctic Core ------------------------------*/\r
\r
\r
- #include <stdlib.h>\r
- #include <string.h>\r
- #include "Os.h"\r
- #include "internal.h"\r
- #include "arc.h"\r
- #include "debug.h"\r
- #include "arch.h"\r
\r
- extern void Os_CfgGetInterruptStackInfo( OsStackType *stack );\r
- extern uint32_t McuE_GetSystemClock( void );\r
- extern OsTickType OsTickFreq;\r
\r
- sys_t os_sys;\r
\r
- Os_IntCounterType Os_IntDisableAllCnt;\r
- Os_IntCounterType Os_IntSuspendAllCnt;\r
- Os_IntCounterType Os_IntSuspendOsCnt;\r
\r
\r
- /**\r
-  * Copy rom pcb data(r_pcb) to ram data\r
-  *\r
-  * @param     pcb             ram data\r
-  * @param     r_pcb   rom data\r
-  */\r
\r
- static void os_pcb_rom_copy( OsPcbType *pcb, const OsRomPcbType *r_pcb ) {\r
\r
- #if 0 //?????\r
-       // Check to that the memory is ok\r
-       {\r
-               int cnt = sizeof(OsPcbType);\r
-               for(int i=0;i<cnt;i++) {\r
-                       if( *((unsigned char *)pcb) != 0 ) {\r
-                               while(1);\r
-                       }\r
-               }\r
-       }\r
- #endif\r
\r
- //    memset(pcb,sizeof(OsPcbType),0);\r
-       pcb->pid = r_pcb->pid;\r
-       pcb->prio = r_pcb->prio;\r
- #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )\r
-       pcb->application = Os_CfgGetApplObj(r_pcb->application_id);\r
- #endif\r
-       pcb->entry = r_pcb->entry;\r
-       pcb->proc_type = r_pcb->proc_type;\r
-       pcb->autostart =  r_pcb->autostart;\r
-       pcb->stack= r_pcb->stack;\r
-       pcb->pcb_rom_p = r_pcb;\r
-       pcb->resource_int_p = r_pcb->resource_int_p;\r
-       pcb->scheduling = r_pcb->scheduling;\r
-       pcb->resourceAccess = r_pcb->resourceAccess;\r
-       pcb->activationLimit = r_pcb->activationLimit;\r
- //    pcb->app = &app_list[r_pcb->app];\r
- //    pcb->app_mask = app_mask[r_pcb->app];\r
-       strncpy(pcb->name,r_pcb->name,16);\r
- }\r
\r
- static _Bool init_os_called = 0;\r
\r
- /**\r
-  * Initialization of kernel structures and start of the first\r
-  * task.\r
-  */\r
\r
- void InitOS( void ) {\r
-       int i;\r
-       OsPcbType *tmp_pcb;\r
-       OsStackType int_stack;\r
\r
-       init_os_called = 1;\r
\r
-       DEBUG(DEBUG_LOW,"os_init");\r
\r
-       /* Clear sys */\r
-       memset(&os_sys,0,sizeof(sys_t));\r
\r
-       Os_ArchInit();\r
\r
-       // Assign pcb list and init ready queue\r
-       os_sys.pcb_list = pcb_list;\r
-       TAILQ_INIT(& os_sys.ready_head);\r
-       TAILQ_INIT(& os_sys.pcb_head);\r
\r
-       // Calc interrupt stack\r
-       Os_CfgGetInterruptStackInfo(&int_stack);\r
-       // TODO: 16 is arch dependent\r
-       os_sys.int_stack = int_stack.top + int_stack.size - 16;\r
\r
-       // Init counter.. with alarms and schedule tables\r
-       Os_CounterInit();\r
-       Os_SchTblInit();\r
\r
-       // Put all tasks in the pcb list\r
-       // Put the one that belong in the ready queue there\r
-       // TODO: we should really hash on priority here to get speed, but I don't care for the moment\r
-       // TODO: Isn't this just EXTENED tasks ???\r
-       for( i=0; i < Os_CfgGetTaskCnt(); i++) {\r
-               tmp_pcb = os_get_pcb(i);\r
\r
-               assert(tmp_pcb->prio<=OS_TASK_PRIORITY_MAX);\r
\r
-               os_pcb_rom_copy(tmp_pcb,os_get_rom_pcb(i));\r
-               if( !(tmp_pcb->proc_type & PROC_ISR) ) {\r
-                       Os_ContextInit(tmp_pcb);\r
-               }\r
\r
-               TAILQ_INIT(&tmp_pcb->resource_head);\r
\r
-               Os_AddTask(tmp_pcb);\r
\r
-               DEBUG(DEBUG_LOW,"pid:%d name:%s prio:%d\n",tmp_pcb->pid,tmp_pcb->name,tmp_pcb->prio);\r
-       }\r
\r
-       Os_ResourceInit();\r
\r
-       // Now all tasks should be created.\r
- }\r
\r
- static void os_start( void ) {\r
-       OsPcbType *tmp_pcb;\r
\r
-       // We will be setting up interrupts,\r
-       // but we don't want them to fire just yet\r
-       Irq_Disable();\r
\r
-       assert(init_os_called);\r
\r
-       /* TODO: fix ugly */\r
-       /* Call the startup hook */\r
-       extern struct OsHooks os_conf_global_hooks;\r
-       os_sys.hooks = &os_conf_global_hooks;\r
-       if( os_sys.hooks->StartupHook!=NULL ) {\r
-               os_sys.hooks->StartupHook();\r
-       }\r
\r
-       /* Alarm autostart */\r
-       for(int j=0; j < Os_CfgGetAlarmCnt(); j++ ) {\r
-               OsAlarmType *alarmPtr;\r
-               alarmPtr = Os_CfgGetAlarmObj(j);\r
-               if(alarmPtr->autostartPtr != NULL ) {\r
-                       const OsAlarmAutostartType *autoPtr = alarmPtr->autostartPtr;\r
\r
-                       if( os_sys.appMode & autoPtr->appModeRef) {\r
-                       if( autoPtr->autostartType == ALARM_AUTOSTART_ABSOLUTE ) {\r
-                               SetAbsAlarm(j,autoPtr->alarmTime, autoPtr->cycleTime);\r
-                       } else {\r
-                               SetRelAlarm(j,autoPtr->alarmTime, autoPtr->cycleTime);\r
-                       }\r
-               }\r
-       }\r
-       }\r
\r
-       Os_SchTblAutostart();\r
\r
-       // Set up the systick interrupt\r
-       {\r
-               uint32_t sys_freq = McuE_GetSystemClock();\r
-               Os_SysTickInit();\r
-               Os_SysTickStart(sys_freq/OsTickFreq);\r
-       }\r
\r
-       /* Find highest Autostart task */\r
-       {\r
-               OsPcbType *iterPcbPtr;\r
-               OsPriorityType topPrio = -1;\r
\r
-               TAILQ_FOREACH(iterPcbPtr,& os_sys.pcb_head,pcb_list) {\r
-                       if(     iterPcbPtr->autostart ) {\r
-                               if( iterPcbPtr->prio > topPrio ) {\r
-                                       tmp_pcb = iterPcbPtr;\r
-                                       topPrio = iterPcbPtr->prio;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
\r
-       // Swap in prio proc.\r
-       {\r
-               // FIXME: Do this in a more structured way.. setting os_sys.curr_pcb manually is not the way to go..\r
-               os_sys.curr_pcb = tmp_pcb;\r
\r
-               // register this auto-start activation\r
-               if (tmp_pcb->proc_type == PROC_BASIC) {\r
-                       assert(tmp_pcb->activations < tmp_pcb->activationLimit);\r
-                       tmp_pcb->activations++;\r
-               }\r
\r
-               // NOTE! We don't go for os_swap_context() here..\r
-               // first arg(NULL) is dummy only\r
-               Os_TaskSwapContextTo(NULL,tmp_pcb);\r
-               // We should not return here\r
-               assert(0);\r
-       }\r
- }\r
- #if 0\r
- static void os_start( void ) {\r
\r
- }\r
- #endif\r
\r
- #define TEST_DATA  12345\r
- int test_data = TEST_DATA;\r
- int test_bss = 0;\r
\r
\r
- void noooo( void ) {\r
-       while(1);\r
- }\r
\r
- extern void EcuM_Init();\r
- int main( void )\r
- {\r
-       EcuM_Init();\r
\r
- }\r
\r
- /**\r
-  * Starts the OS\r
-  *\r
-  * @param Mode - Application mode to start in\r
-  *\r
-  */\r
- void StartOS(AppModeType Mode) {\r
\r
-       /* Check link file */\r
-       if (TEST_DATA != test_data) {\r
-               noooo();\r
-       }\r
\r
-       if (test_bss != 0) {\r
-               noooo();\r
-       }\r
\r
-       os_sys.appMode = Mode;\r
\r
-       Os_CfgValidate();\r
\r
-       os_start();\r
\r
-       /** @req OS424 */\r
-       assert(0);\r
- }\r
\r
- /**\r
-  * OS shutdown\r
-  *\r
-  * @param Error - Reason for shutdown\r
-  */\r
\r
- /** @req OS071 */\r
- void ShutdownOS( StatusType Error ) {\r
\r
-       if( os_sys.hooks->ShutdownHook != NULL ) {\r
-               os_sys.hooks->ShutdownHook(Error);\r
-       }\r
\r
-       Irq_Disable();\r
-       /** @req OS425 */\r
-       while(1) {      }\r
\r
- }\r
\r
\r
\r
+ /* -------------------------------- Arctic Core ------------------------------
+  * Arctic Core - the open source AUTOSAR platform http://arccore.com
+  *
+  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
+  *
+  * This source code is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU General Public License version 2 as published by the
+  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
+  *
+  * This program is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  * for more details.
+  * -------------------------------- Arctic Core ------------------------------*/
+ #include <stdlib.h>
+ #include <string.h>
+ #include "Os.h"
+ #include "internal.h"
+ #include "arc.h"
+ #include "debug.h"
+ #include "arch.h"
+ extern void Os_CfgGetInterruptStackInfo( OsStackType *stack );
+ extern uint32_t McuE_GetSystemClock( void );
+ extern OsTickType OsTickFreq;
+ sys_t os_sys;
+ Os_IntCounterType Os_IntDisableAllCnt;
+ Os_IntCounterType Os_IntSuspendAllCnt;
+ Os_IntCounterType Os_IntSuspendOsCnt;
+ /**
+  * Copy rom pcb data(r_pcb) to ram data
+  *
+  * @param     pcb             ram data
+  * @param     r_pcb   rom data
+  */
+ static void os_pcb_rom_copy( OsPcbType *pcb, const OsRomPcbType *r_pcb ) {
+ #if 0 //?????
+       // Check to that the memory is ok
+       {
+               int cnt = sizeof(OsPcbType);
+               for(int i=0;i<cnt;i++) {
+                       if( *((unsigned char *)pcb) != 0 ) {
+                               while(1);
+                       }
+               }
+       }
+ #endif
+ //    memset(pcb,sizeof(OsPcbType),0);
+       pcb->pid = r_pcb->pid;
+       pcb->prio = r_pcb->prio;
+ #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )
+       pcb->application = Os_CfgGetApplObj(r_pcb->application_id);
+ #endif
+       pcb->entry = r_pcb->entry;
+       pcb->proc_type = r_pcb->proc_type;
+       pcb->autostart =  r_pcb->autostart;
+       pcb->stack= r_pcb->stack;
+       pcb->pcb_rom_p = r_pcb;
+       pcb->resource_int_p = r_pcb->resource_int_p;
+       pcb->scheduling = r_pcb->scheduling;
+       pcb->resourceAccess = r_pcb->resourceAccess;
+       pcb->activationLimit = r_pcb->activationLimit;
+ //    pcb->app = &app_list[r_pcb->app];
+ //    pcb->app_mask = app_mask[r_pcb->app];
+       strncpy(pcb->name,r_pcb->name,16);
+ }
+ static _Bool init_os_called = 0;
+ /**
+  * Initialization of kernel structures and start of the first
+  * task.
+  */
+ void InitOS( void ) {
+       int i;
+       OsPcbType *tmp_pcb;
+       OsStackType int_stack;
+       init_os_called = 1;
+       DEBUG(DEBUG_LOW,"os_init");
+       /* Clear sys */
+       memset(&os_sys,0,sizeof(sys_t));
+       Os_ArchInit();
+       // Assign pcb list and init ready queue
+       os_sys.pcb_list = pcb_list;
+       TAILQ_INIT(& os_sys.ready_head);
+       TAILQ_INIT(& os_sys.pcb_head);
+       // Calc interrupt stack
+       Os_CfgGetInterruptStackInfo(&int_stack);
+       // TODO: 16 is arch dependent
+       os_sys.int_stack = int_stack.top + int_stack.size - 16;
+       // Init counter.. with alarms and schedule tables
+       Os_CounterInit();
+       Os_SchTblInit();
+       // Put all tasks in the pcb list
+       // Put the one that belong in the ready queue there
+       // TODO: we should really hash on priority here to get speed, but I don't care for the moment
+       // TODO: Isn't this just EXTENED tasks ???
+       for( i=0; i < Os_CfgGetTaskCnt(); i++) {
+               tmp_pcb = os_get_pcb(i);
+               assert(tmp_pcb->prio<=OS_TASK_PRIORITY_MAX);
+               os_pcb_rom_copy(tmp_pcb,os_get_rom_pcb(i));
+               if( !(tmp_pcb->proc_type & PROC_ISR) ) {
+                       Os_ContextInit(tmp_pcb);
+               }
+               TAILQ_INIT(&tmp_pcb->resource_head);
+               Os_AddTask(tmp_pcb);
+               DEBUG(DEBUG_LOW,"pid:%d name:%s prio:%d\n",tmp_pcb->pid,tmp_pcb->name,tmp_pcb->prio);
+       }
+       Os_ResourceInit();
+       // Now all tasks should be created.
+ }
+ static void os_start( void ) {
+       OsPcbType *tmp_pcb;
+       // We will be setting up interrupts,
+       // but we don't want them to fire just yet
+       Irq_Disable();
+       assert(init_os_called);
+       /* TODO: fix ugly */
+       /* Call the startup hook */
+       extern struct OsHooks os_conf_global_hooks;
+       os_sys.hooks = &os_conf_global_hooks;
+       if( os_sys.hooks->StartupHook!=NULL ) {
+               os_sys.hooks->StartupHook();
+       }
+       /* Alarm autostart */
+       for(int j=0; j < Os_CfgGetAlarmCnt(); j++ ) {
+               OsAlarmType *alarmPtr;
+               alarmPtr = Os_CfgGetAlarmObj(j);
+               if(alarmPtr->autostartPtr != NULL ) {
+                       const OsAlarmAutostartType *autoPtr = alarmPtr->autostartPtr;
+                       if( os_sys.appMode & autoPtr->appModeRef) {
+                               if( autoPtr->autostartType == ALARM_AUTOSTART_ABSOLUTE ) {
+                                       SetAbsAlarm(j,autoPtr->alarmTime, autoPtr->cycleTime);
+                               } else {
+                                       SetRelAlarm(j,autoPtr->alarmTime, autoPtr->cycleTime);
+                               }
+                       }
+               }
+       }
+       Os_SchTblAutostart();
+       // Set up the systick interrupt
+       {
+               uint32_t sys_freq = McuE_GetSystemClock();
+               Os_SysTickInit();
+               Os_SysTickStart(sys_freq/OsTickFreq);
+       }
+       /* Find highest Autostart task */
+       {
+               OsPcbType *iterPcbPtr;
+               OsPriorityType topPrio = -1;
+               TAILQ_FOREACH(iterPcbPtr,& os_sys.pcb_head,pcb_list) {
+                       if(     iterPcbPtr->autostart ) {
+                               if( iterPcbPtr->prio > topPrio ) {
+                                       tmp_pcb = iterPcbPtr;
+                                       topPrio = iterPcbPtr->prio;
+                               }
+                       }
+               }
+       }
+       // Swap in prio proc.
+       {
+               // FIXME: Do this in a more structured way.. setting os_sys.curr_pcb manually is not the way to go..
+               os_sys.curr_pcb = tmp_pcb;
++
++              // register this auto-start activation
++              if (tmp_pcb->proc_type == PROC_BASIC) {
++                      assert(tmp_pcb->activations < tmp_pcb->activationLimit);
++                      tmp_pcb->activations++;
++              }
++
+               // NOTE! We don't go for os_swap_context() here..
+               // first arg(NULL) is dummy only
+               Os_TaskSwapContextTo(NULL,tmp_pcb);
+               // We should not return here
+               assert(0);
+       }
+ }
+ #if 0
+ static void os_start( void ) {
+ }
+ #endif
+ #define TEST_DATA  12345
+ int test_data = TEST_DATA;
+ int test_bss = 0;
+ void noooo( void ) {
+       while(1);
+ }
+ extern void EcuM_Init();
+ int main( void )
+ {
+       EcuM_Init();
+ }
+ /**
+  * Starts the OS
+  *
+  * @param Mode - Application mode to start in
+  *
+  */
+ void StartOS(AppModeType Mode) {
+       /* Check link file */
+       if (TEST_DATA != test_data) {
+               noooo();
+       }
+       if (test_bss != 0) {
+               noooo();
+       }
+       os_sys.appMode = Mode;
+       Os_CfgValidate();
+       os_start();
+       /** @req OS424 */
+       assert(0);
+ }
+ /**
+  * OS shutdown
+  *
+  * @param Error - Reason for shutdown
+  */
+ /** @req OS071 */
+ void ShutdownOS( StatusType Error ) {
+       if( os_sys.hooks->ShutdownHook != NULL ) {
+               os_sys.hooks->ShutdownHook(Error);
+       }
+       Irq_Disable();
+       /** @req OS425 */
+       while(1) {      }
+ }
index a62669d281ef466aab19dc63b1929355dfd32c08,1575ef85feff47840aa491dd5ed5f50ab711229f..67124188874978bcdc17ec090cf01dab194a9651
- /* -------------------------------- Arctic Core ------------------------------\r
-  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
-  *\r
-  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
-  *\r
-  * This source code is free software; you can redistribute it and/or modify it\r
-  * under the terms of the GNU General Public License version 2 as published by the\r
-  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
-  *\r
-  * This program is distributed in the hope that it will be useful, but\r
-  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
-  * for more details.\r
-  * -------------------------------- Arctic Core ------------------------------*/\r
\r
- #include <sys/types.h>\r
- #include <stdint.h>\r
- #include <string.h>\r
- #include "internal.h"\r
- #include "irq.h"\r
- #if 0\r
\r
\r
- #include <stdint.h>\r
- #include <stdlib.h>\r
- #include <assert.h>\r
- #include <sys/queue.h>\r
- #include <string.h>\r
- #include "internal.h"\r
\r
- #endif\r
\r
\r
- // TODO: remove. Make soft links or whatever\r
- #if defined(CFG_ARM_CM3)\r
- #include "irq_types.h"\r
- //#include "stm32f10x.h"\r
- //#include "stm32f10x_arc.h"\r
- #endif\r
\r
- extern caddr_t *sbrk(int);\r
\r
- #define os_alloc(_x)  sbrk(_x)\r
\r
- OsPcbType * os_alloc_new_pcb( void ) {\r
-       void *h = os_alloc(sizeof(OsPcbType));\r
-       memset(h,0,sizeof(OsPcbType));\r
-       assert(h!=NULL);\r
-       return h;\r
- }\r
\r
- #if 0\r
- typedef void (*Os_IsrEntryType)(void);\r
\r
\r
- typedef Os_IsrInfo_s {\r
-       Os_IsrEntryType entry;\r
-       uint32_t vector;\r
-       uint8_t priority;\r
- } Os_IsrInfoType;\r
- #endif\r
\r
\r
- extern TaskType Os_AddTask( OsPcbType *pcb );\r
\r
- static uint8 stackTop = 0x42;\r
\r
- TaskType Os_Arc_CreateIsr( void (*entry)(void ), uint8_t prio, const char *name )\r
- {\r
-       OsPcbType *pcb = os_alloc_new_pcb();\r
-       strncpy(pcb->name,name,TASK_NAME_SIZE);\r
-       pcb->vector = -1;\r
-       pcb->prio = prio;\r
-       /* TODO: map to interrupt controller priority */\r
-       assert(prio<=OS_TASK_PRIORITY_MAX);\r
-       pcb->proc_type  = PROC_ISR2;\r
-       pcb->state = ST_SUSPENDED;\r
-       pcb->entry = entry;\r
-       pcb->stack.top = &stackTop;\r
\r
-       return Os_AddTask(pcb);\r
- }\r
\r
\r
- #if defined(CFG_ARM_CM3)\r
- extern void Irq_EOI2(void *pc);\r
- #endif\r
\r
\r
- /**\r
-  * Handle ISR type 2 interrupts from interrupt controller.\r
-  *\r
-  * @param stack Ptr to the current stack\r
-  * @param vector The vector that took the interrupt\r
-  */\r
- void *Os_Isr( void *stack, void *pcb_p ) {\r
-       struct OsPcb *pcb;\r
-       struct OsPcb *preempted_pcb;\r
\r
-       os_sys.int_nest_cnt++;\r
\r
-       // Save info for preempted pcb\r
-       preempted_pcb = get_curr_pcb();\r
-       preempted_pcb->stack.curr = stack;\r
-       preempted_pcb->state = ST_READY;\r
-       OS_DEBUG(D_TASK,"Preempted %s\n",preempted_pcb->name);\r
\r
-       Os_StackPerformCheck(preempted_pcb);\r
\r
-       POSTTASKHOOK();\r
\r
-       pcb = (struct OsPcb *)pcb_p;\r
-       pcb->state = ST_RUNNING;\r
-       set_curr_pcb(pcb);\r
\r
-       PRETASKHOOK();\r
\r
-       // We should not get here if we're NON\r
-       if( pcb->scheduling == NON) {\r
-               // TODO:\r
-               // assert(0);\r
-               while(1);\r
-       }\r
\r
- #ifndef CFG_HCS12D\r
-       Irq_Enable();\r
-       pcb->entry();\r
-       Irq_Disable();\r
- #else\r
-       pcb->entry();\r
- #endif\r
\r
-       /** @req OS368 */\r
-       if( Os_IrqAnyDisabled() ) {\r
-               Os_IrqClearAll();\r
-               ERRORHOOK(E_OS_DISABLEDINT);\r
-       }\r
\r
-       /** @req OS369 */\r
-       Os_ResourceCheckAndRelease(pcb);\r
\r
-       pcb->state = ST_SUSPENDED;\r
-       POSTTASKHOOK();\r
\r
-       Irq_EOI();\r
\r
-       --os_sys.int_nest_cnt;\r
\r
-       // TODO: Check stack check marker....\r
-       // We have preempted a task\r
-       if( (os_sys.int_nest_cnt == 0) && (os_sys.scheduler_lock==0) ) { //&& is_idle_task() ) {\r
-               /* If we get here:\r
-                * - the preempted task is saved with large context.\r
-                * - We are on interrupt stack..( this function )\r
-                *\r
-                * if we find a new task:\r
-                * - just switch in the new context( don't save the old because\r
-                *   its already saved )\r
-                */\r
-               OsPcbType *new_pcb;\r
-               new_pcb = Os_TaskGetTop();\r
\r
-               Os_StackPerformCheck(new_pcb);\r
\r
-               if( new_pcb != preempted_pcb ) {\r
-                       OS_DEBUG(D_TASK,"Found candidate %s\n",new_pcb->name);\r
- //#warning Os_TaskSwapContextTo should call the pretaskswaphook\r
- // TODO: This shuould go away!!!!\r
- #if defined(CFG_ARM_CM3)\r
-                       void *p;\r
-                       p = &&really_ugly;\r
-                       Irq_EOI2(p);\r
- really_ugly:\r
- #endif\r
-                       Os_TaskSwapContextTo(NULL,new_pcb);\r
-               } else {\r
-                       if( new_pcb == NULL ) {\r
-                               assert(0);\r
-                       }\r
-                       preempted_pcb->state = ST_RUNNING;\r
-                       set_curr_pcb(preempted_pcb);\r
-               }\r
-       } else {\r
-               set_curr_pcb(preempted_pcb);\r
-               PRETASKHOOK();\r
-       }\r
\r
-       return stack;\r
- }\r
+ /* -------------------------------- Arctic Core ------------------------------
+  * Arctic Core - the open source AUTOSAR platform http://arccore.com
+  *
+  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
+  *
+  * This source code is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU General Public License version 2 as published by the
+  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
+  *
+  * This program is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  * for more details.
+  * -------------------------------- Arctic Core ------------------------------*/
+ #include <sys/types.h>
+ #include <stdint.h>
+ #include <string.h>
+ #include "internal.h"
+ #include "irq.h"
+ #if 0
+ #include <stdint.h>
+ #include <stdlib.h>
+ #include <assert.h>
+ #include <sys/queue.h>
+ #include <string.h>
+ #include "internal.h"
+ #endif
+ // TODO: remove. Make soft links or whatever
+ #if defined(CFG_ARM_CM3)
+ #include "irq_types.h"
+ //#include "stm32f10x.h"
+ //#include "stm32f10x_arc.h"
+ #endif
+ extern caddr_t *sbrk(int);
+ #define os_alloc(_x)  sbrk(_x)
+ OsPcbType * os_alloc_new_pcb( void ) {
+       void *h = os_alloc(sizeof(OsPcbType));
+       memset(h,0,sizeof(OsPcbType));
+       assert(h!=NULL);
+       return h;
+ }
+ #if 0
+ typedef void (*Os_IsrEntryType)(void);
+ typedef Os_IsrInfo_s {
+       Os_IsrEntryType entry;
+       uint32_t vector;
+       uint8_t priority;
+ } Os_IsrInfoType;
+ #endif
+ extern TaskType Os_AddTask( OsPcbType *pcb );
+ static uint8 stackTop = 0x42;
+ /**
+  * Creates an ISR dynamically
+  * @param entry
+  * @param prio
+  * @param name
+  *
+  * @return The PID of the ISR created
+  */
+ TaskType Os_Arc_CreateIsr( void (*entry)(void ), uint8_t prio, const char *name )
+ {
+       OsPcbType *pcb = os_alloc_new_pcb();
+       strncpy(pcb->name,name,TASK_NAME_SIZE);
+       pcb->vector = -1;
+       pcb->prio = prio;
+       /* TODO: map to interrupt controller priority */
+       assert(prio<=OS_TASK_PRIORITY_MAX);
+       pcb->proc_type  = PROC_ISR2;
+       pcb->state = ST_SUSPENDED;
+       pcb->entry = entry;
+       pcb->stack.top = &stackTop;
+       return Os_AddTask(pcb);
+ }
+ #if defined(CFG_ARM_CM3)
+ extern void Irq_EOI2( void );
+ #endif
+ /**
+  * Handle ISR type 2 interrupts from interrupt controller.
+  *
+  * @param stack Ptr to the current stack
+  * @param vector The vector that took the interrupt
+  */
+ void *Os_Isr( void *stack, void *pcb_p ) {
+       struct OsPcb *pcb;
+       struct OsPcb *preempted_pcb;
+       os_sys.int_nest_cnt++;
+       // Save info for preempted pcb
+       preempted_pcb = get_curr_pcb();
+       preempted_pcb->stack.curr = stack;
+       preempted_pcb->state = ST_READY;
+       OS_DEBUG(D_TASK,"Preempted %s\n",preempted_pcb->name);
++      Os_StackPerformCheck(preempted_pcb);
++
+       POSTTASKHOOK();
+       pcb = (struct OsPcb *)pcb_p;
+       pcb->state = ST_RUNNING;
+       set_curr_pcb(pcb);
+       PRETASKHOOK();
+       // We should not get here if we're NON
+       if( pcb->scheduling == NON) {
+               // TODO:
+               // assert(0);
+               while(1);
+       }
++#ifndef CFG_HCS12D
+       Irq_Enable();
+       pcb->entry();
+       Irq_Disable();
++#else
++      pcb->entry();
++#endif
+       /** @req OS368 */
+       if( Os_IrqAnyDisabled() ) {
+               Os_IrqClearAll();
+               ERRORHOOK(E_OS_DISABLEDINT);
+       }
+       /** @req OS369 */
+       Os_ResourceCheckAndRelease(pcb);
+       pcb->state = ST_SUSPENDED;
+       POSTTASKHOOK();
+       Irq_EOI();
+       --os_sys.int_nest_cnt;
+       // TODO: Check stack check marker....
+       // We have preempted a task
+       if( (os_sys.int_nest_cnt == 0) && (os_sys.scheduler_lock==0) ) { //&& is_idle_task() ) {
+               /* If we get here:
+                * - the preempted task is saved with large context.
+                * - We are on interrupt stack..( this function )
+                *
+                * if we find a new task:
+                * - just switch in the new context( don't save the old because
+                *   its already saved )
+                */
+               OsPcbType *new_pcb;
+               new_pcb = Os_TaskGetTop();
++
++              Os_StackPerformCheck(new_pcb);
++
+               if( new_pcb != preempted_pcb ) {
+                       OS_DEBUG(D_TASK,"Found candidate %s\n",new_pcb->name);
+ //#warning Os_TaskSwapContextTo should call the pretaskswaphook
+ // TODO: This shuould go away!!!!
+ #if defined(CFG_ARM_CM3)
+                       Irq_EOI2();
+ #endif
+                       Os_TaskSwapContextTo(NULL,new_pcb);
+               } else {
+                       if( new_pcb == NULL ) {
+                               assert(0);
+                       }
+                       preempted_pcb->state = ST_RUNNING;
+                       set_curr_pcb(preempted_pcb);
+               }
+       } else {
+               set_curr_pcb(preempted_pcb);
+               PRETASKHOOK();
+       }
+       return stack;
+ }
Simple merge
index fc1bca7e70f9191b43b809fc8f3d990e52368327,6f15c325a3d28172fc30925e00b6398020103930..bddc29243aa0313d729ff774cc2a71dc09f3fd64
                return rv;\r
  \r
  extern TickType GetCountValue( OsCounterType *counter );\r
 -
 -
 -static void Os_SchTblUpdateState( OsSchTblType *stbl );
 -
 +void Os_SchTblUpdateState( OsSchTblType *stbl );\r
 +\r
++static void Os_SchTblUpdateState( OsSchTblType *stbl );\r
++\r
  #if 0\r
  enum OsScheduleTableSyncStrategy getSyncStrategy( OsSchTblType *stblPtr ) {\r
        return stblPtr->sync.syncStrategy;\r
@@@ -103,39 -105,42 +105,42 @@@ static void ScheduleTableConsistenyChec
        /** @req OS431 */\r
        if( sTblPtr->sync.syncStrategy == EXPLICIT ) {\r
                assert( sTblPtr->duration <= (sTblPtr->counter->alarm_base.maxallowedvalue +1) );\r
 -      }
 -#endif
 -
 -      /** @req OS401 */
 -      assert(SA_LIST_CNT(&sTblPtr->expirePointList)>=1);
 -
 -
 -
 -      {
 -              int iter;
 -              TickType delta = 0;
 -              TickType minCycle = Os_CounterGetMinCycle(sTblPtr->counter);
 -              TickType maxValue =  Os_CounterGetMaxValue(sTblPtr->counter);
 -
 -              /* - start at offset=0
 -               * - X expiry points = SA_LIST_CNT
 -               * - Final offset.
 -               */
 -              /** @req OS443 */
 -              /** @req OS408 */
 -              for(iter=0; iter  <  SA_LIST_CNT(&sTblPtr->expirePointList) ; iter++) {
 -                      delta = SA_LIST_GET(&sTblPtr->expirePointList,iter)->offset - delta;
 -                      /* initial offset may be zero (OS443) */
 -                      if(iter!=0) {
 -                              assert( delta >=  minCycle );
 -                      }
 -                      assert( delta <=  maxValue );
 -              }
 -
 -              /* Final */
 -              /** @req OS444 */
 -              delta = sTblPtr->duration - SA_LIST_GET(&sTblPtr->expirePointList,iter-1)->offset;
 -              assert( delta >=  minCycle );
 -              assert( delta <=  maxValue );
 -      }
 -
 +      }\r
 +#endif\r
 +\r
 +      /** @req OS401 */\r
 +      assert(SA_LIST_CNT(&sTblPtr->expirePointList)>=1);\r
 +\r
 +\r
 +\r
 +      {\r
 +              int iter;\r
 +              TickType delta = 0;\r
 +              TickType minCycle = Os_CounterGetMinCycle(sTblPtr->counter);\r
 +              TickType maxValue =  Os_CounterGetMaxValue(sTblPtr->counter);\r
 +\r
 +              /* - start at offset=0\r
 +               * - X expiry points = SA_LIST_CNT\r
 +               * - Final offset.\r
 +               */\r
 +              /** @req OS443 */\r
 +              /** @req OS408 */\r
 +              for(iter=0; iter  <  SA_LIST_CNT(&sTblPtr->expirePointList) ; iter++) {\r
 +                      delta = SA_LIST_GET(&sTblPtr->expirePointList,iter)->offset - delta;\r
-                       assert( delta >=  minCycle );\r
++                      /* initial offset may be zero (OS443) */\r
++                      if(iter!=0) {\r
++                              assert( delta >=  minCycle );\r
++                      }\r
 +                      assert( delta <=  maxValue );\r
 +              }\r
 +\r
 +              /* Final */\r
 +              /** @req OS444 */\r
 +              delta = sTblPtr->duration - SA_LIST_GET(&sTblPtr->expirePointList,iter-1)->offset;\r
 +              assert( delta >=  minCycle );\r
 +              assert( delta <=  maxValue );\r
 +      }\r
 +\r
  }\r
  \r
  StatusType StartScheduleTableRel(ScheduleTableType sid, TickType offset) {\r
@@@ -478,86 -483,86 +483,86 @@@ StatusType SetScheduleTableAsync( Sched
  \r
        SCHED_STD_END;\r
  }\r
 -#endif
 -
 -
 -
 -/**
 - * Go through the schedule tables connected to this counter
 - *
 - * @param c_p Pointer to counter object
 - */
 -void Os_SchTblCheck(OsCounterType *c_p) {
 -      /** @req OS002 */
 -      /** @req OS007 */
 -
 -      OsSchTblType *sched_obj;
 -
 -      /* Iterate through the schedule tables */
 -      SLIST_FOREACH(sched_obj,&c_p->sched_head,sched_list) {
 -
 -              if( sched_obj->state == SCHEDULETABLE_STOPPED ) {
 -                      continue;
 -              }
 -
 -#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )
 -              if( sched_obj->sync.syncStrategy == IMPLICIT ) {
 -                      // ....
 -
 -              } else {
 -                      int adj;
 -                      // Handle EXPLICIT
 -                      if( sched_obj->sync.deviation > 0 ) {
 -                              // The sync counter was set back ==
 -                              // we have more time to complete the table
 -                              adj = MIN(sched_obj->sync.deviation, getAdjExpPoint(sched_obj)->maxAdvance );
 -                              sched_obj->sync.deviation -= adj;
 -
 -                      } else if( sched_obj->sync.deviation < 0 ) {
 -                              // The sync counter was set forward ==
 -                              // we have less time to complete the table
 -                              adj = MIN((-sched_obj->sync.deviation), getAdjExpPoint(sched_obj)->maxRetard);
 -                              sched_obj->sync.deviation -= adj;
 -
 -                      } else {
 -                              // all is well
 -                              sched_obj->state = SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS;
 -                      }
 -              }
 -#endif
 -
 -              /* Check if the expire point have been hit */
 -              if( (sched_obj->state == SCHEDULETABLE_RUNNING ||
 -                      sched_obj->state == SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS ) &&
 -                      (c_p->val == sched_obj->expire_val) )
 -              {
 -                      if ( sched_obj->expire_curr_index < SA_LIST_CNT(&sched_obj->expirePointList) ) {
 -                              OsScheduleTableExpiryPointType * action;
 -                              int i;
 -
 -                              action = SA_LIST_GET(&sched_obj->expirePointList,sched_obj->expire_curr_index);
 -
 -                              /** @req OS407 */
 -                              /** @req OS412 */
 -
 -                              /* According to OS412 activate tasks before events */
 -                              for(i=0; i< action->taskListCnt;i++ ) {
 -                                      ActivateTask(action->taskList[i]);
 -                              }
 -
 -                              for(i=0; i< action->eventListCnt;i++ ) {
 -                                      SetEvent( action->eventList[i].task, action->eventList[i].event);
 -                              }
 -                      }
 -                      // Calc new expire val and state
 -                      Os_SchTblUpdateState(sched_obj);
 -              }
 -
 -      }
 -}
 +#endif\r
 +\r
 +\r
 +\r
 +/**\r
 + * Go through the schedule tables connected to this counter\r
 + *\r
 + * @param c_p Pointer to counter object\r
 + */\r
 +void Os_SchTblCheck(OsCounterType *c_p) {\r
 +      /** @req OS002 */\r
 +      /** @req OS007 */\r
 +\r
 +      OsSchTblType *sched_obj;\r
 +\r
 +      /* Iterate through the schedule tables */\r
 +      SLIST_FOREACH(sched_obj,&c_p->sched_head,sched_list) {\r
 +\r
 +              if( sched_obj->state == SCHEDULETABLE_STOPPED ) {\r
 +                      continue;\r
 +              }\r
 +\r
 +#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
 +              if( sched_obj->sync.syncStrategy == IMPLICIT ) {\r
 +                      // ....\r
 +\r
 +              } else {\r
 +                      int adj;\r
 +                      // Handle EXPLICIT\r
 +                      if( sched_obj->sync.deviation > 0 ) {\r
 +                              // The sync counter was set back ==\r
 +                              // we have more time to complete the table\r
 +                              adj = MIN(sched_obj->sync.deviation, getAdjExpPoint(sched_obj)->maxAdvance );\r
 +                              sched_obj->sync.deviation -= adj;\r
 +\r
 +                      } else if( sched_obj->sync.deviation < 0 ) {\r
 +                              // The sync counter was set forward ==\r
 +                              // we have less time to complete the table\r
 +                              adj = MIN((-sched_obj->sync.deviation), getAdjExpPoint(sched_obj)->maxRetard);\r
 +                              sched_obj->sync.deviation -= adj;\r
 +\r
 +                      } else {\r
 +                              // all is well\r
 +                              sched_obj->state = SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS;\r
 +                      }\r
 +              }\r
 +#endif\r
 +\r
 +              /* Check if the expire point have been hit */\r
 +              if( (sched_obj->state == SCHEDULETABLE_RUNNING ||\r
 +                      sched_obj->state == SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS ) &&\r
-                               (c_p->val == sched_obj->expire_val) )\r
++                      (c_p->val == sched_obj->expire_val) )\r
 +              {\r
 +                      if ( sched_obj->expire_curr_index < SA_LIST_CNT(&sched_obj->expirePointList) ) {\r
-                       OsScheduleTableExpiryPointType * action;\r
-                       int i;\r
++                              OsScheduleTableExpiryPointType * action;\r
++                              int i;\r
 +\r
-                       action = SA_LIST_GET(&sched_obj->expirePointList,sched_obj->expire_curr_index);\r
++                              action = SA_LIST_GET(&sched_obj->expirePointList,sched_obj->expire_curr_index);\r
 +\r
-                       /** @req OS407 */\r
-                       /** @req OS412 */\r
++                              /** @req OS407 */\r
++                              /** @req OS412 */\r
 +\r
-                       /* According to OS412 activate tasks before events */\r
-                       for(i=0; i< action->taskListCnt;i++ ) {\r
-                               ActivateTask(action->taskList[i]);\r
-                       }\r
++                              /* According to OS412 activate tasks before events */\r
++                              for(i=0; i< action->taskListCnt;i++ ) {\r
++                                      ActivateTask(action->taskList[i]);\r
++                              }\r
 +\r
-                       for(i=0; i< action->eventListCnt;i++ ) {\r
-                               SetEvent( action->eventList[i].task, action->eventList[i].event);\r
-                       }\r
++                              for(i=0; i< action->eventListCnt;i++ ) {\r
++                                      SetEvent( action->eventList[i].task, action->eventList[i].event);\r
++                              }\r
 +                      }\r
 +                      // Calc new expire val and state\r
 +                      Os_SchTblUpdateState(sched_obj);\r
 +              }\r
 +\r
 +      }\r
 +}\r
  \r
  /**\r
 - *
 + *\r
   */\r
  void Os_SchTblInit( void ) {\r
        OsSchTblType *s_p;\r
                ScheduleTableConsistenyCheck(s_p);\r
        }\r
  }\r
 -
 -void Os_SchTblAutostart( void ) {
 -
 -      for(int j=0; j < Os_CfgGetSchedCnt(); j++ ) {
 -              OsSchTblType *sPtr;
 -              sPtr = Os_CfgGetSched(j);
 -
 -              if( sPtr->autostartPtr != NULL ) {
 -                      const struct OsSchTblAutostart *autoPtr = sPtr->autostartPtr;
 -
 -                      /* Check appmode */
 -                      if( os_sys.appMode & autoPtr->appMode ) {
 -
 -                              /* Start the schedule table */
 -                              switch(autoPtr->type) {
 -                              case SCHTBL_AUTOSTART_ABSOLUTE:
 -                                      StartScheduleTableAbs(j,autoPtr->offset);
 -                                      break;
 -                              case SCHTBL_AUTOSTART_RELATIVE:
 -                                      StartScheduleTableRel(j,autoPtr->offset);
 -                                      break;
 -      #if defined(OS_SC2) || defined(OS_SC4)
 -                              case SCHTBL_AUTOSTART_SYNCHRONE:
 -                                      /* TODO: */
 -                                      break;
 -      #endif
 -                              default:
 -                                      assert(0);              // Illegal value
 -                                      break;
 -                              }
 -                      }
 -              }
 -      }
 -}
 -
 +\r
 +void Os_SchTblAutostart( void ) {\r
 +\r
 +      for(int j=0; j < Os_CfgGetSchedCnt(); j++ ) {\r
 +              OsSchTblType *sPtr;\r
 +              sPtr = Os_CfgGetSched(j);\r
 +\r
 +              if( sPtr->autostartPtr != NULL ) {\r
 +                      const struct OsSchTblAutostart *autoPtr = sPtr->autostartPtr;\r
 +\r
 +                      /* Check appmode */\r
 +                      if( os_sys.appMode & autoPtr->appMode ) {\r
 +\r
 +                              /* Start the schedule table */\r
 +                              switch(autoPtr->type) {\r
 +                              case SCHTBL_AUTOSTART_ABSOLUTE:\r
 +                                      StartScheduleTableAbs(j,autoPtr->offset);\r
 +                                      break;\r
 +                              case SCHTBL_AUTOSTART_RELATIVE:\r
 +                                      StartScheduleTableRel(j,autoPtr->offset);\r
 +                                      break;\r
- #if defined(OS_SC2) || defined(OS_SC4)\r
++      #if defined(OS_SC2) || defined(OS_SC4)\r
 +                              case SCHTBL_AUTOSTART_SYNCHRONE:\r
 +                                      /* TODO: */\r
 +                                      break;\r
- #endif\r
++      #endif\r
 +                              default:\r
 +                                      assert(0);              // Illegal value\r
 +                                      break;\r
 +                              }\r
 +                      }\r
 +              }\r
 +      }\r
 +}\r
 +\r
  \r
  /**\r
 - * Calculates expire value and changes state depending it's state.
 - *
 - * Note!
 - * We can't cheat with the final + initial expire-point, instead we
 - * must setup trigger after the final delay and set the "previous"
 - * table to SCHEDULETABLE_STOPPED and the new to SCHEDULETABLE_RUNNING.
 - *
 - * @param stbl Ptr to a Schedule Table.
 + * Calculates expire value and changes state depending it's state.\r
 + *\r
 + * Note!\r
 + * We can't cheat with the final + initial expire-point, instead we\r
 + * must setup trigger after the final delay and set the "previous"\r
 + * table to SCHEDULETABLE_STOPPED and the new to SCHEDULETABLE_RUNNING.\r
 + *\r
 + * @param stbl Ptr to a Schedule Table.\r
   */\r
- void Os_SchTblUpdateState( OsSchTblType *stbl ) {\r
static void Os_SchTblUpdateState( OsSchTblType *stbl ) {\r
  \r
 -      TickType delta;
 -      TickType initalOffset;
 -      TickType finalOffset;
 -      OsSchTblType *nextStblPtr;
 -      _Bool handleLast = 0;
 -
 -      if( (stbl->expire_curr_index) == (SA_LIST_CNT(&stbl->expirePointList) - 1) ) {
 -              /* We are at the last expiry point */
 -              finalOffset = Os_SchTblGetFinalOffset(stbl);
 -
 -              if (finalOffset != 0) {
 -                      stbl->expire_val =      Os_CounterAdd(
 -                                                      Os_CounterGetValue(stbl->counter),
 -                                                      Os_CounterGetMaxValue(stbl->counter),
 -                                                      finalOffset );
 -
 -                      stbl->expire_curr_index++;
 -                      return;
 -              } else {
 -                      /* Only single shot may have an offset of 0 */
 -                      assert(stbl->repeating == SINGLE_SHOT);
 -                      handleLast = 1;
 -              }
 -      }
 -
 -      if( handleLast ||
 -              ( (stbl->expire_curr_index) == SA_LIST_CNT(&stbl->expirePointList) ) )
 -      {
 -              /* At final offset */
 -              /** @req OS194 */
 -              if( (stbl->repeating == REPEATING) || (stbl->next != NULL) ) {
 -                      if( stbl->next != NULL ) {
 -                              /** @req OS284 */
 -                              nextStblPtr = stbl->next;
 -                              /* NextScheduleTable() have been called */
 -                              assert( nextStblPtr->state==SCHEDULETABLE_NEXT );
 -
 -                              /* We don't care about REPEATING or SINGLE_SHOT here */
 -                              initalOffset = Os_SchTblGetInitialOffset(nextStblPtr);
 -                              stbl->state = SCHEDULETABLE_STOPPED;
 -                              nextStblPtr->state = SCHEDULETABLE_RUNNING;
 -                      } else {
 -                              /** @req OS414 */
 -
 -                              /* REPEATING */
 -                              assert( stbl->repeating == REPEATING );
 -                              initalOffset = Os_SchTblGetInitialOffset(stbl);
 -                      }
 -
 -                      stbl->expire_val =      Os_CounterAdd(
 -                                                      Os_CounterGetValue(stbl->counter),
 -                                                      Os_CounterGetMaxValue(stbl->counter),
 -                                                      initalOffset );
 -
 -              } else {
 -                      assert( stbl->repeating == SINGLE_SHOT );
 -                      /** @req OS009 */
 -                      stbl->state = SCHEDULETABLE_STOPPED;
 -              }
 -              stbl->expire_curr_index = 0;
 -
 -      } else {
 -
 -              delta = SA_LIST_GET(&stbl->expirePointList,stbl->expire_curr_index+1)->offset -
 -                              SA_LIST_GET(&stbl->expirePointList,stbl->expire_curr_index)->offset ;
 -
 -              stbl->expire_val =      Os_CounterAdd(
 -                                              Os_CounterGetValue(stbl->counter),
 -                                              Os_CounterGetMaxValue(stbl->counter),
 -                                              delta );
 -
 -              stbl->expire_curr_index++;
 -
 -      }
 -
 +      TickType delta;\r
 +      TickType initalOffset;\r
 +      TickType finalOffset;\r
 +      OsSchTblType *nextStblPtr;\r
 +      _Bool handleLast = 0;\r
 +\r
\r
\r
 +      if( (stbl->expire_curr_index) == (SA_LIST_CNT(&stbl->expirePointList) - 1) ) {\r
 +              /* We are at the last expiry point */\r
 +              finalOffset = Os_SchTblGetFinalOffset(stbl);\r
 +\r
 +              if (finalOffset != 0) {\r
 +                      stbl->expire_val =      Os_CounterAdd(\r
 +                                                      Os_CounterGetValue(stbl->counter),\r
 +                                                      Os_CounterGetMaxValue(stbl->counter),\r
 +                                                      finalOffset );\r
 +\r
 +                      stbl->expire_curr_index++;\r
 +                      return;\r
 +              } else {\r
 +                      /* Only single shot may have an offset of 0 */\r
 +                      assert(stbl->repeating == SINGLE_SHOT);\r
 +                      handleLast = 1;\r
 +              }\r
 +      }\r
 +\r
 +      if( handleLast ||\r
 +              ( (stbl->expire_curr_index) == SA_LIST_CNT(&stbl->expirePointList) ) )\r
 +      {\r
 +              /* At final offset */\r
 +              /** @req OS194 */\r
 +              if( (stbl->repeating == REPEATING) || (stbl->next != NULL) ) {\r
 +                      if( stbl->next != NULL ) {\r
 +                              /** @req OS284 */\r
 +                              nextStblPtr = stbl->next;\r
 +                              /* NextScheduleTable() have been called */\r
 +                              assert( nextStblPtr->state==SCHEDULETABLE_NEXT );\r
 +\r
 +                              /* We don't care about REPEATING or SINGLE_SHOT here */\r
 +                              initalOffset = Os_SchTblGetInitialOffset(nextStblPtr);\r
 +                              stbl->state = SCHEDULETABLE_STOPPED;\r
 +                              nextStblPtr->state = SCHEDULETABLE_RUNNING;\r
 +                      } else {\r
 +                              /** @req OS414 */\r
 +\r
 +                              /* REPEATING */\r
 +                              assert( stbl->repeating == REPEATING );\r
 +                              initalOffset = Os_SchTblGetInitialOffset(stbl);\r
 +                      }\r
 +\r
 +                      stbl->expire_val =      Os_CounterAdd(\r
 +                                                      Os_CounterGetValue(stbl->counter),\r
 +                                                      Os_CounterGetMaxValue(stbl->counter),\r
 +                                                      initalOffset );\r
 +\r
 +              } else {\r
 +                      assert( stbl->repeating == SINGLE_SHOT );\r
 +                      /** @req OS009 */\r
 +                      stbl->state = SCHEDULETABLE_STOPPED;\r
 +              }\r
 +              stbl->expire_curr_index = 0;\r
 +\r
 +      } else {\r
 +\r
 +              delta = SA_LIST_GET(&stbl->expirePointList,stbl->expire_curr_index+1)->offset -\r
 +                              SA_LIST_GET(&stbl->expirePointList,stbl->expire_curr_index)->offset ;\r
 +\r
 +              stbl->expire_val =      Os_CounterAdd(\r
 +                                              Os_CounterGetValue(stbl->counter),\r
 +                                              Os_CounterGetMaxValue(stbl->counter),\r
 +                                              delta );\r
 +\r
 +              stbl->expire_curr_index++;\r
 +\r
 +      }\r
 +\r
        return;\r
  }\r
  \r
index 534de83dd61e07c26c0ef24304b23be646abf934,c77d2a201546574ac278235d4960aed1b7f105d5..2c0c3faaca59454fe5c33b70690ebe9720660d3a
 -/* -------------------------------- Arctic Core ------------------------------
 - * Arctic Core - the open source AUTOSAR platform http://arccore.com
 - *
 - * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
 - *
 - * This source code is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License version 2 as published by the
 - * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
 - *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 - * for more details.
 - * -------------------------------- Arctic Core ------------------------------*/
 -
 +/* -------------------------------- Arctic Core ------------------------------\r
 + * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
 + *\r
 + * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
 + *\r
 + * This source code is free software; you can redistribute it and/or modify it\r
 + * under the terms of the GNU General Public License version 2 as published by the\r
 + * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
 + *\r
 + * This program is distributed in the hope that it will be useful, but\r
 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
 + * for more details.\r
 + * -------------------------------- Arctic Core ------------------------------*/\r
 +\r
  #include <stdlib.h>\r
 -#include "Os.h"
 -
 -#include "internal.h"
 -#include "arc.h"
 -#include "arch.h"
 -
 -/** @req OS067 */
 -
 -_Bool os_pcb_pid_valid( OsPcbType *restrict pcb ) {
 -      return ( pcb->pid > Os_CfgGetTaskCnt() ) ? 0 : 1;
 -}
 -/**
 - * Start an extended task.
 - * Tasks done:
 - * - Grab the internal resource for the process
 - * - Set it running state.
 - * - Start to execute the process
 - *
 - */
 -void Os_TaskStartExtended( void ) {
 -      OsPcbType *pcb;
 -
 -      PRETASKHOOK();
 -
 -      pcb = Os_TaskGetCurrent();
 -      Os_ResourceGetInternal();
 -      Os_TaskMakeRunning(pcb);
 -
 -      Os_ArchFirstCall();
 -
 -      /** @req OS239 */
 -      Irq_Disable();
 -      if( Os_IrqAnyDisabled() ) {
 -              Os_IrqClearAll();
 -      }
 -
 -// TODO:Dont I have to check this at terminate task also?
 -
 -      /** @req OS069 */
 -      ERRORHOOK(E_OS_MISSINGEND);
 -
 -      /** @req OS052 */
 -      TerminateTask();
 -}
 -
 -/**
 - * Start an basic task.
 - * See extended task.
 - */
 -
 -void Os_TaskStartBasic( void ) {
 -      OsPcbType *pcb;
 -
 -      PRETASKHOOK();
 -
 -      pcb = Os_TaskGetCurrent();
 -      Os_ResourceGetInternal();
 -      Os_TaskMakeRunning(pcb);
 -      Os_ArchFirstCall();
 -
 -
 -      /** @req OS239 */
 -      Irq_Disable();
 -      if( Os_IrqAnyDisabled() ) {
 -              Os_IrqClearAll();
 -      }
 -
 -      /** @req OS069 */
 -      ERRORHOOK(E_OS_MISSINGEND);
 -
 -      /** @req OS052 */
 -      TerminateTask();
 -}
 -
 -
 -static void Os_StackSetup( OsPcbType *pcbPtr ) {
 -      uint8_t *bottom;
 -
 -      /* Find bottom of the stack so that we can place the
 -       * context there.
 -       *
 -       * stack bottom = high address. stack top = low address
 -       */
 -      bottom = (uint8_t *)pcbPtr->stack.top + pcbPtr->stack.size;
 -      pcbPtr->stack.curr = bottom;
 -      // TODO: alignments here..
 -      // TODO :use function os_arch_get_call_size() ??
 -
 -      // Make some space for back-chain.
 -      bottom -= 16;
 -      // Set the current stack so that it points to the context
 -      pcbPtr->stack.curr = bottom - Os_ArchGetScSize();
 -
 -      Os_StackSetEndmark(pcbPtr);
 -}
 -
 -/**
 - * Fill the stack with a predefined pattern
 - *
 - * @param pcbPtr Pointer to the pcb to fill with pattern
 - */
 -static void Os_StackFill(OsPcbType *pcbPtr) {
 -      uint8_t *p = pcbPtr->stack.curr;
 -
 -      assert(pcbPtr->stack.curr > pcbPtr->stack.top);
 -
 -      while (p > (uint8_t *) pcbPtr->stack.top) {
 -              --p;
 -              *p = STACK_PATTERN;
 -      }
 -}
 -
 -#if 0
 -/**
 - *
 - * @param pcbPtr
 - */
 -static void Os_TaskSetEntry(OsPcbType *pcbPtr ) {
 -
 -}
 -#endif
 -
 -
 -/**
 - * Setup the context for a pcb. The context differs for different arch's
 - * so we call the arch dependent functions also.
 - * The context at setup is always a small context.
 - *
 - * @param pcb Ptr to the pcb to setup context for.
 - */
 -void Os_ContextInit( OsPcbType *pcb ) {
 -
 -      if( pcb->autostart ) {
 -              Os_TaskMakeReady(pcb);
 -      } else {
 -              pcb->state = ST_SUSPENDED;
 -      }
 -
 -      Os_StackSetup(pcb);
 -      Os_StackFill(pcb);
 -      Os_ArchSetTaskEntry(pcb);
 -
 -      Os_ArchSetupContext(pcb);
 -}
 -
 -/**
 - *
 - * @param pcb
 - */
 -void Os_ContextReInit( OsPcbType *pcbPtr ) {
 -      Os_StackSetup(pcbPtr);
 -}
 -
 -/**
 - * Search for a specific task in the pcb list.
 - *
 - * @param tid The task id to search for
 - * @return Ptr to the found pcb or NULL
 - */
 -OsPcbType *os_find_task( TaskType tid ) {
 -      OsPcbType *i_pcb;
 -
 -      /* TODO: Implement this as an array */
 -      TAILQ_FOREACH(i_pcb,& os_sys.pcb_head,pcb_list) {
 -              if(i_pcb->pid == tid ) {
 -                      return i_pcb;
 -              }
 -      }
 -      assert(0);
 -      return NULL;
 -}
 -
 -/**
 - * Adds a pcb to the list of pcb's
 - * @param pcb
 - */
 -TaskType Os_AddTask( OsPcbType *pcb ) {
 -      long msr;
 -
 -      Irq_Save(msr);  // Save irq status and disable interrupts
 -
 -      pcb->pid = os_sys.task_cnt;
 -      // Add to list of PCB's
 -      TAILQ_INSERT_TAIL(& os_sys.pcb_head,pcb,pcb_list);
 -      os_sys.task_cnt++;
 -
 -      Irq_Restore(msr);  // Restore interrupts
 -      return pcb->pid;
 -}
 -
 -
 -#define PRIO_ILLEGAL  -100
 -
 -/**
 - * Find the top priority task. Even the running task is included.
 - * TODO: There should be a priority queue (using a heap?) here instead.
 - *        giving O(log n) for instertions and (1) for getting the top
 - *        prio task. The curerent implementation is ehhhh bad.
 - * @return
 - */
 -
 -OsPcbType *Os_TaskGetTop( void ){
 -      OsPcbType *i_pcb;
 -      OsPcbType *top_prio_pcb = NULL;
 -      OsPriorityType top_prio = PRIO_ILLEGAL;
 -
 -      OS_DEBUG(D_TASK,"os_find_top_prio_proc\n");
 -
 -      TAILQ_FOREACH(i_pcb,& os_sys.ready_head,ready_list) {
 -              // all ready task are canidates
 -              if( i_pcb->state & (ST_READY|ST_RUNNING)) {
 -                      if( top_prio != PRIO_ILLEGAL ) {
 -                              if( i_pcb->prio > top_prio ) {
 -                                      top_prio = i_pcb->prio;
 -                                      top_prio_pcb = i_pcb;
 -                              }
 -                      } else {
 -                              top_prio = i_pcb->prio;
 -                              top_prio_pcb = i_pcb;
 -                      }
 -              } else {
 -                      assert(0);
 -              }
 -      }
 -
 -      assert(top_prio_pcb!=NULL);
 -
 -      OS_DEBUG(D_TASK,"Found %s\n",top_prio_pcb->name);
 -
 -      return top_prio_pcb;
 -}
 -
 -
 -#define USE_LDEBUG_PRINTF
 -#include "debug.h"
 -
 -// we come here from
 -// - WaitEvent()
 -//   old_pcb -> WAITING
 -//   new_pcb -> READY(RUNNING)
 -// - Schedule(),
 -//   old_pcb -> READY
 -//   new_pcb -> READY/RUNNING
 -
 -/*
 - * two strategies
 - * 1. When running ->
 - *    - remove from ready queue
 - *    - set state == ST_RUNNING
 - *
 - * 2. When running ->
 - *    * leave in ready queue
 - *    * set state == ST_RUNNING
 - *    - ready queue and ST_READY not the same
 - *    + No need to remove the running process from ready queue
 - */
 -
 -OsPcbType *Os_FindTopPrioTask( void ) {
 -
 -
 -      return NULL;
 -}
 -
 -/**
 - * Tries to Dispatch.
 - *
 - * Used by:
 - *   ActivateTask()
 - *   WaitEvent()
 - *   TerminateTask()
 - *
 - * @param force Force a re-scheduling
 - *
 - */
 -void Os_Dispatch( _Bool force ) {
 -      OsPcbType *pcbPtr;
 -      OsPcbType *currPcbPtr;
 -      (void)force;
 -
 -      assert(os_sys.int_nest_cnt == 0);
 -      assert(os_sys.scheduler_lock == 0 );
 -
 -      pcbPtr = Os_TaskGetTop();
 -      currPcbPtr = Os_TaskGetCurrent();
 -      /* Swap if we found any process or are forced (multiple activations)*/
 -      if( pcbPtr != currPcbPtr ) {
 -              /* Add us to the ready list */
 -              if( currPcbPtr->state & ST_RUNNING ) {
 -                      Os_TaskRunningToReady(currPcbPtr);
 -              }
 -
 -              /*
 -               * Swap context
 -               */
 -              /** @req OS052 */
 -              POSTTASKHOOK();
 -              assert(pcbPtr!=NULL);
 -
 -              Os_ResourceReleaseInternal();
 -
 -#if (OS_STACK_MONITORING == 1)
 -              if( !Os_StackIsEndmarkOk(currPcbPtr) ) {
 -#if (  OS_SC1 == 1) || (  OS_SC2 == 1)
 -                      /** @req OS068 */
 -                      ShutdownOS(E_OS_STACKFAULT);
 -#else
 -#error SC3 or SC4 not supported. Protection hook should be called here
 -#endif
 -              }
 -#endif
 -
 -              Os_ArchSwapContext(currPcbPtr,pcbPtr);
 -
 -              pcbPtr = Os_TaskGetCurrent();
 -              Os_TaskMakeRunning(pcbPtr);
 -
 -              Os_ResourceGetInternal();
 -
 -              PRETASKHOOK();
 -
 -      } else {
 -              if( Os_GetOp() != OP_SET_EVENT ) {
 -
 -                      /* We want to run the same task, again. This only happens
 -                       * when we have multiple activation of a basic task (
 -                       * extended tasks have an activation limit of 1)
 -                       */
 -
 -                      /* Setup the stack again, and just call the basic task */
 -                      Os_StackSetup(pcbPtr);
 -                      Os_ArchSetSpAndCall(pcbPtr->stack.curr,Os_TaskStartBasic);
 -              } else {
 -                      /* Two cases:
 -                       * 1. SetEvent() on itself
 -                       * 2. SetEvent()
 -                       *
 -                       *
 -                       * */
 -
 -              }
 -      }
 -}
 -
 -// We come here from
 -// - os_init
 -
 -volatile static int a1, b1, c1;
 -volatile static OsPcbType *o1;
 -volatile static OsPcbType *n1;
 -
 -void hej(int a, int b, int c, OsPcbType *o, OsPcbType *n) {
 -      a1 = a;
 -      b1 = b;
 -      c1 = c;
 -      o1 = o;
 -      n1 = n;
 -}
 -
 -/**
 - * Called when a task is to be run for the first time.
 - */
 -void Os_TaskSwapContextTo(OsPcbType *old_pcb, OsPcbType *new_pcb ) {
 -
 -      hej(1, 2, 3, old_pcb, new_pcb);
 -
 -      Os_ArchSwapContextTo(old_pcb,new_pcb);
 -      /* TODO: When do we return here ?? */
 -}
 -
 -
 -void Os_Arc_GetStackInfo( TaskType task, StackInfoType *s) {
 -      OsPcbType *pcb  = os_get_pcb(task);
 -
 -      s->curr         = Os_ArchGetStackPtr();
 -      s->top          = pcb->stack.top;
 -      s->at_swap      = pcb->stack.curr;
 -      s->size         = pcb->stack.size;
 -      s->usage        = (void *)Os_StackGetUsage(pcb);
 -}
 -
 -
 -/**
 - * Returns the state of a task (running, ready, waiting, suspended)
 - * at the time of calling GetTaskState.
 - *
 - * @param TaskId  Task reference
 - * @param State   Reference to the state of the task
 - */
 -
 +#include "Os.h"\r
 +\r
 +#include "internal.h"\r
 +#include "arc.h"\r
 +#include "arch.h"\r
 +\r
 +/** @req OS067 */\r
 +\r
 +_Bool os_pcb_pid_valid( OsPcbType *restrict pcb ) {\r
 +      return ( pcb->pid > Os_CfgGetTaskCnt() ) ? 0 : 1;\r
 +}\r
 +/**\r
 + * Start an extended task.\r
 + * Tasks done:\r
 + * - Grab the internal resource for the process\r
 + * - Set it running state.\r
 + * - Start to execute the process\r
 + *\r
 + */\r
 +void Os_TaskStartExtended( void ) {\r
 +      OsPcbType *pcb;\r
 +\r
 +      pcb = Os_TaskGetCurrent();\r
 +      Os_ResourceGetInternal();\r
 +      Os_TaskMakeRunning(pcb);\r
 +\r
 +      PRETASKHOOK();\r
 +\r
 +      Os_ArchFirstCall();\r
 +\r
 +      /** @req OS239 */\r
 +      Irq_Disable();\r
 +      if( Os_IrqAnyDisabled() ) {\r
 +              Os_IrqClearAll();\r
 +      }\r
 +\r
 +// TODO:Dont I have to check this at terminate task also?\r
 +\r
 +      /** @req OS069 */\r
 +      ERRORHOOK(E_OS_MISSINGEND);\r
 +\r
 +      /** @req OS052 */\r
 +      TerminateTask();\r
 +}\r
 +\r
 +/**\r
 + * Start an basic task.\r
 + * See extended task.\r
 + */\r
 +\r
 +void Os_TaskStartBasic( void ) {\r
 +      OsPcbType *pcb;\r
 +\r
 +      pcb = Os_TaskGetCurrent();\r
 +      Os_ResourceGetInternal();\r
 +      Os_TaskMakeRunning(pcb);\r
 +\r
 +      PRETASKHOOK();\r
 +\r
 +      Os_ArchFirstCall();\r
 +\r
 +\r
 +      /** @req OS239 */\r
 +      Irq_Disable();\r
 +      if( Os_IrqAnyDisabled() ) {\r
 +              Os_IrqClearAll();\r
 +      }\r
 +\r
 +      /** @req OS069 */\r
 +      ERRORHOOK(E_OS_MISSINGEND);\r
 +\r
 +      /** @req OS052 */\r
 +      TerminateTask();\r
 +}\r
 +\r
 +\r
 +static void Os_StackSetup( OsPcbType *pcbPtr ) {\r
 +      uint8_t *bottom;\r
 +\r
 +      /* Find bottom of the stack so that we can place the\r
 +       * context there.\r
 +       *\r
 +       * stack bottom = high address. stack top = low address\r
 +       */\r
 +      bottom = (uint8_t *)pcbPtr->stack.top + pcbPtr->stack.size;\r
 +      pcbPtr->stack.curr = bottom;\r
 +      // TODO: alignments here..\r
 +      // TODO :use function os_arch_get_call_size() ??\r
 +\r
 +      // Make some space for back-chain.\r
 +      bottom -= 16;\r
 +      // Set the current stack so that it points to the context\r
 +      pcbPtr->stack.curr = bottom - Os_ArchGetScSize();\r
 +\r
 +      Os_StackSetEndmark(pcbPtr);\r
 +}\r
 +\r
 +/**\r
 + * Fill the stack with a predefined pattern\r
 + *\r
 + * @param pcbPtr Pointer to the pcb to fill with pattern\r
 + */\r
 +static void Os_StackFill(OsPcbType *pcbPtr) {\r
 +      uint8_t *p = pcbPtr->stack.curr;\r
 +\r
 +      assert(pcbPtr->stack.curr > pcbPtr->stack.top);\r
 +\r
 +      while (p > (uint8_t *) pcbPtr->stack.top) {\r
 +              --p;\r
 +              *p = STACK_PATTERN;\r
 +      }\r
 +}\r
 +\r
 +#if 0\r
 +/**\r
 + *\r
 + * @param pcbPtr\r
 + */\r
 +static void Os_TaskSetEntry(OsPcbType *pcbPtr ) {\r
 +\r
 +}\r
 +#endif\r
 +\r
 +\r
 +/**\r
 + * Setup the context for a pcb. The context differs for different arch's\r
 + * so we call the arch dependent functions also.\r
 + * The context at setup is always a small context.\r
 + *\r
 + * @param pcb Ptr to the pcb to setup context for.\r
 + */\r
 +void Os_ContextInit( OsPcbType *pcb ) {\r
 +\r
 +      if( pcb->autostart ) {\r
 +              Os_TaskMakeReady(pcb);\r
 +      } else {\r
 +              pcb->state = ST_SUSPENDED;\r
 +      }\r
 +\r
 +      Os_StackSetup(pcb);\r
 +      Os_StackFill(pcb);\r
 +      Os_ArchSetTaskEntry(pcb);\r
 +\r
 +      Os_ArchSetupContext(pcb);\r
 +}\r
 +\r
 +/**\r
 + *\r
 + * @param pcb\r
 + */\r
 +void Os_ContextReInit( OsPcbType *pcbPtr ) {\r
 +      Os_StackSetup(pcbPtr);\r
 +}\r
 +\r
 +/**\r
 + * Search for a specific task in the pcb list.\r
 + *\r
 + * @param tid The task id to search for\r
 + * @return Ptr to the found pcb or NULL\r
 + */\r
 +OsPcbType *os_find_task( TaskType tid ) {\r
 +      OsPcbType *i_pcb;\r
 +\r
 +      /* TODO: Implement this as an array */\r
 +      TAILQ_FOREACH(i_pcb,& os_sys.pcb_head,pcb_list) {\r
 +              if(i_pcb->pid == tid ) {\r
 +                      return i_pcb;\r
 +              }\r
 +      }\r
 +      assert(0);\r
 +      return NULL;\r
 +}\r
 +\r
 +/**\r
 + * Adds a pcb to the list of pcb's\r
 + * @param pcb\r
 + */\r
 +TaskType Os_AddTask( OsPcbType *pcb ) {\r
 +      long msr;\r
 +\r
 +      Irq_Save(msr);  // Save irq status and disable interrupts\r
 +\r
 +      pcb->pid = os_sys.task_cnt;\r
 +      // Add to list of PCB's\r
 +      TAILQ_INSERT_TAIL(& os_sys.pcb_head,pcb,pcb_list);\r
 +      os_sys.task_cnt++;\r
 +\r
 +      Irq_Restore(msr);  // Restore interrupts\r
 +      return pcb->pid;\r
 +}\r
 +\r
 +\r
 +#define PRIO_ILLEGAL  -100\r
 +\r
 +/**\r
 + * Find the top priority task. Even the running task is included.\r
 + * TODO: There should be a priority queue (using a heap?) here instead.\r
 + *        giving O(log n) for instertions and (1) for getting the top\r
 + *        prio task. The curerent implementation is ehhhh bad.\r
 + * @return\r
 + */\r
 +\r
 +OsPcbType *Os_TaskGetTop( void ){\r
 +      OsPcbType *i_pcb;\r
 +      OsPcbType *top_prio_pcb = NULL;\r
 +      OsPriorityType top_prio = PRIO_ILLEGAL;\r
 +\r
 +      OS_DEBUG(D_TASK,"os_find_top_prio_proc\n");\r
 +\r
 +      TAILQ_FOREACH(i_pcb,& os_sys.ready_head,ready_list) {\r
 +              // all ready task are canidates\r
 +              if( i_pcb->state & (ST_READY|ST_RUNNING)) {\r
 +                      if( top_prio != PRIO_ILLEGAL ) {\r
 +                              if( i_pcb->prio > top_prio ) {\r
 +                                      top_prio = i_pcb->prio;\r
 +                                      top_prio_pcb = i_pcb;\r
 +                              }\r
 +                      } else {\r
 +                              top_prio = i_pcb->prio;\r
 +                              top_prio_pcb = i_pcb;\r
 +                      }\r
 +              } else {\r
 +                      assert(0);\r
 +              }\r
 +      }\r
 +\r
 +      assert(top_prio_pcb!=NULL);\r
 +\r
 +      OS_DEBUG(D_TASK,"Found %s\n",top_prio_pcb->name);\r
 +\r
 +      return top_prio_pcb;\r
 +}\r
 +\r
 +\r
 +#define USE_LDEBUG_PRINTF\r
 +#include "debug.h"\r
 +\r
 +// we come here from\r
 +// - WaitEvent()\r
 +//   old_pcb -> WAITING\r
 +//   new_pcb -> READY(RUNNING)\r
 +// - Schedule(),\r
 +//   old_pcb -> READY\r
 +//   new_pcb -> READY/RUNNING\r
 +\r
 +/*\r
 + * two strategies\r
 + * 1. When running ->\r
 + *    - remove from ready queue\r
 + *    - set state == ST_RUNNING\r
 + *\r
 + * 2. When running ->\r
 + *    * leave in ready queue\r
 + *    * set state == ST_RUNNING\r
 + *    - ready queue and ST_READY not the same\r
 + *    + No need to remove the running process from ready queue\r
 + */\r
 +\r
 +OsPcbType *Os_FindTopPrioTask( void ) {\r
 +\r
 +\r
 +      return NULL;\r
 +}\r
 +\r
 +/**\r
 + * Tries to Dispatch.\r
 + *\r
 + * Used by:\r
 + *   ActivateTask()\r
 + *   WaitEvent()\r
 + *   TerminateTask()\r
 + *   ChainTask()\r
 + *\r
 + * @param force Force a re-scheduling\r
 + *\r
 + */\r
 +void Os_Dispatch( _Bool force ) {\r
 +      OsPcbType *pcbPtr;\r
 +      OsPcbType *currPcbPtr;\r
 +      (void)force;\r
 +\r
 +      assert(os_sys.int_nest_cnt == 0);\r
 +      assert(os_sys.scheduler_lock == 0 );\r
 +\r
 +      pcbPtr = Os_TaskGetTop();\r
 +      currPcbPtr = Os_TaskGetCurrent();\r
 +      /* Swap if we found any process or are forced (multiple activations)*/\r
 +      if( pcbPtr != currPcbPtr ) {\r
 +\r
 +              /* Add us to the ready list */\r
 +              if( currPcbPtr->state & ST_RUNNING ) {\r
 +                      /** @req OS052 */\r
 +                      POSTTASKHOOK();\r
 +                      Os_TaskRunningToReady(currPcbPtr);\r
 +              }\r
 +\r
 +              /*\r
 +               * Swap context\r
 +               */\r
 +              assert(pcbPtr!=NULL);\r
 +\r
 +              Os_ResourceReleaseInternal();\r
 +\r
 +#if (OS_STACK_MONITORING == 1)\r
 +              if( !Os_StackIsEndmarkOk(currPcbPtr) ) {\r
 +#if (  OS_SC1 == 1) || (  OS_SC2 == 1)\r
 +                      /** @req OS068 */\r
 +                      ShutdownOS(E_OS_STACKFAULT);\r
 +#else\r
 +#error SC3 or SC4 not supported. Protection hook should be called here\r
 +#endif\r
 +              }\r
 +#endif\r
 +\r
 +              Os_ArchSwapContext(currPcbPtr,pcbPtr);\r
 +\r
 +              pcbPtr = Os_TaskGetCurrent();\r
 +              Os_TaskMakeRunning(pcbPtr);\r
 +\r
 +              Os_ResourceGetInternal();\r
 +\r
 +              PRETASKHOOK();\r
 +\r
 +      } else {\r
-               /* We want to run the same task, again. This only happens\r
-                * when we have multiple activation of a basic task (\r
-                * extended tasks have an activation limit of 1)\r
-                */\r
++              if( Os_GetOp() != OP_SET_EVENT ) {\r
++\r
++                      /* We want to run the same task, again. This only happens\r
++                       * when we have multiple activation of a basic task (\r
++                       * extended tasks have an activation limit of 1)\r
++                       */\r
 +\r
-               /* Setup the stack again, and just call the basic task */\r
-               Os_StackSetup(pcbPtr);\r
-               Os_ArchSetSpAndCall(pcbPtr->stack.curr,Os_TaskStartBasic);\r
++                      /* Setup the stack again, and just call the basic task */\r
++                      Os_StackSetup(pcbPtr);\r
++                      Os_ArchSetSpAndCall(pcbPtr->stack.curr,Os_TaskStartBasic);\r
++              } else {\r
++                      /* Two cases:\r
++                       * 1. SetEvent() on itself\r
++                       * 2. SetEvent()\r
++                       *\r
++                       *\r
++                       * */\r
++\r
++              }\r
 +      }\r
 +}\r
 +\r
 +// We come here from\r
 +// - os_init\r
 +\r
 +/**\r
 + * Called when a task is to be run for the first time.\r
 + */\r
 +void Os_TaskSwapContextTo(OsPcbType *old_pcb, OsPcbType *new_pcb ) {\r
 +\r
 +      Os_ArchSwapContextTo(old_pcb,new_pcb);\r
 +      /* TODO: When do we return here ?? */\r
 +}\r
 +\r
 +\r
 +void Os_Arc_GetStackInfo( TaskType task, StackInfoType *s) {\r
 +      OsPcbType *pcb  = os_get_pcb(task);\r
 +\r
 +      s->curr         = Os_ArchGetStackPtr();\r
 +      s->top          = pcb->stack.top;\r
 +      s->at_swap      = pcb->stack.curr;\r
 +      s->size         = pcb->stack.size;\r
 +      s->usage        = (void *)Os_StackGetUsage(pcb);\r
 +}\r
 +\r
 +\r
 +/**\r
 + * Returns the state of a task (running, ready, waiting, suspended)\r
 + * at the time of calling GetTaskState.\r
 + *\r
 + * @param TaskId  Task reference\r
 + * @param State   Reference to the state of the task\r
 + */\r
 +\r
  StatusType GetTaskState(TaskType TaskId, TaskStateRefType State) {\r
        state_t curr_state = os_pcb_get_state(os_get_pcb(TaskId));\r
        StatusType rv = E_OK;\r
index 29e457fe5ba63ab7d0a6906233c37118adb8c23c,919a2d4ff2e8068805f784ab4f680d8dc9dec6b9..ec905fd7127e448aabb60d697fc15a48c0a8931c
@@@ -1,17 -1,17 +1,17 @@@
 -/* 
 -* Configuration of module Os (Os_Cfg.c)
 -* 
 -* Created by: 
 -* Configured for (MCU): MPC551x
 -* 
 -* Module editor vendor:  ArcCore
 -* Module editor version: 2.0.7
 -* 
 -* 
 -* Generated by Arctic Studio (http://arccore.com)
 -*           on Tue Jun 08 08:30:59 CEST 2010
 -*/
 -
 +/* \r
 +* Configuration of module Os (Os_Cfg.c)\r
 +* \r
 +* Created by: \r
 +* Configured for (MCU): MPC551x\r
 +* \r
 +* Module editor vendor:  ArcCore\r
 +* Module editor version: 2.0.7\r
 +* \r
 +* \r
 +* Generated by Arctic Studio (http://arccore.com)\r
- *           on Wed May 05 23:09:13 CEST 2010\r
++*           on Tue Jun 08 08:30:59 CEST 2010\r
 +*/\r
 +\r
        \r
  \r
  #include <stdlib.h>\r
index 1c20805fb80165b4b4d7f744cdc1a9fbb98854ff,f71ef2a4d60e17bd5215d97f481dd1339f8ce60f..7de2d394c0d0e72a5b2e5d5ffd662f4d5d15f20f
@@@ -1,22 -1,22 +1,22 @@@
 -/* 
 -* Configuration of module Os (Os_Cfg.h)
 -* 
 -* Created by: 
 -* Configured for (MCU): MPC551x
 -* 
 -* Module editor vendor:  ArcCore
 -* Module editor version: 2.0.7
 -* 
 -* 
 -* Generated by Arctic Studio (http://arccore.com)
 -*           on Tue Jun 08 08:30:59 CEST 2010
 -*/
 -
 -
 -#if (OS_SW_MAJOR_VERSION != 2) 
 -#error "Os: Configuration file version differs from BSW version."
 -#endif
 -
 +/* \r
 +* Configuration of module Os (Os_Cfg.h)\r
 +* \r
 +* Created by: \r
 +* Configured for (MCU): MPC551x\r
 +* \r
 +* Module editor vendor:  ArcCore\r
 +* Module editor version: 2.0.7\r
 +* \r
 +* \r
 +* Generated by Arctic Studio (http://arccore.com)\r
- *           on Wed May 05 23:09:13 CEST 2010\r
++*           on Tue Jun 08 08:30:59 CEST 2010\r
 +*/\r
 +\r
 +\r
 +#if (OS_SW_MAJOR_VERSION != 2) \r
 +#error "Os: Configuration file version differs from BSW version."\r
 +#endif\r
 +\r
  \r
  #ifndef OS_CFG_H_\r
  #define OS_CFG_H_\r
index 1c4d357daa59d6190a730f38a8b0dac55a76cc71,1585a59f53ead415404968a07bbba199c1e06cd0..f729895949301c05a9c8d37f40e5dc29a8d6d867
@@@ -1,90 -1,25 +1,25 @@@
 -/* -------------------------------- Arctic Core ------------------------------
 - * Arctic Core - the open source AUTOSAR platform http://arccore.com
 - *
 - * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
 - *
 - * This source code is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License version 2 as published by the
 - * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
 - *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 - * for more details.
 - * -------------------------------- Arctic Core ------------------------------*/
 -/*
 - * Contains mostly macros for the test-system. Most macro's have the same
 - * name as in embUnit, to make it easier to use.
 - *
 - */
 -
 +/* -------------------------------- Arctic Core ------------------------------\r
 + * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
 + *\r
 + * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
 + *\r
 + * This source code is free software; you can redistribute it and/or modify it\r
 + * under the terms of the GNU General Public License version 2 as published by the\r
 + * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
 + *\r
 + * This program is distributed in the hope that it will be useful, but\r
 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
 + * for more details.\r
 + * -------------------------------- Arctic Core ------------------------------*/\r
\r
- #ifndef OS_TEST_H_\r
- #define OS_TEST_H_\r
\r
- #include "test_framework.h"\r
- #include "debug.h"\r
\r
- typedef void (*test_func_t)( void );\r
\r
- #define TEST_FAIL(_text)              test_fail((_text),  __FILE__,  __LINE__, __FUNCTION__ )\r
- #define TEST_OK()                             test_ok();\r
- #define TEST_ASSERT(_cond)                    if(!(_cond)) { TEST_FAIL(#_cond); }\r
- #define TEST_RUN()                            printf("Running test %d\n",test_nr);\r
\r
\r
- extern int test_suite;\r
- extern int test_nr;\r
\r
- #define TASK_ID_ILL                   99\r
- #define RES_ID_ILL                            99\r
- #define ALARM_ID_ILL                  99\r
- #define SCHTBL_ID_ILL         99\r
- #define COUNTER_ID_ILL                        99\r
\r
- #if 1\r
- #define SECTION_SUP\r
- #define SECTION_USER\r
- #else\r
- #define SECTION_SUP                   __attribute__ ((section(".text_app_sup")))\r
- #define SECTION_USER          __attribute__ ((section(".text_app_user")))\r
- #endif\r
\r
- #define SECTION_BSS_SUPER     __attribute__ ((aligned (16),section(".bss")))\r
- #define SECTION_BSS_USER      __attribute__ ((aligned (16),section(".bss")))\r
\r
- #define OS_STR__(x)           #x\r
- #define OS_STRSTR__(x)        OS_STR__(x)\r
\r
- #define DECLARE_TEST_BTASK(_nr, _task1, _task2, _task3 ) \\r
-               __attribute__ ((section (".test_btask"))) const test_func_t btask_sup_matrix_ ## _nr[3] = { _task1, _task2, _task3 }\r
\r
- #define DECLARE_TEST_ETASK(_nr, _task1, _task2, _task3 ) \\r
-               __attribute__ ((section (".test_etask"))) const test_func_t etask_sup_matrix_ ## _nr[3]  = { _task1, _task2, _task3 }\r
\r
- #define DECLARE_TASKS(_nr) \\r
-       void etask_sup_l_##_nr( void ); \\r
-       void etask_sup_m_##_nr( void ); \\r
-       void etask_sup_h_##_nr( void ); \\r
-       void btask_sup_l_##_nr( void ); \\r
-       void btask_sup_m_##_nr( void ); \\r
-       void btask_sup_h_##_nr( void );\r
\r
\r
 +/*\r
-  * Declare tests\r
++ * Contains mostly macros for the test-system. Most macro's have the same\r
++ * name as in embUnit, to make it easier to use.\r
++ *\r
 + */\r
 +\r
- // Test master processes\r
- void OsIdle(void );\r
- void etask_master( void );\r
- void etask_sup_l( void ) SECTION_SUP;\r
- void etask_sup_m( void ) SECTION_SUP;\r
- void etask_sup_h( void ) SECTION_SUP;\r
\r
- void btask_sup_l( void ) SECTION_SUP;\r
- void btask_sup_m( void ) SECTION_SUP;\r
- void btask_sup_h( void ) SECTION_SUP;\r
\r
+ #ifndef OS_TEST_H_\r
+ #define OS_TEST_H_\r
  \r
- // Tests\r
- DECLARE_TASKS(01);\r
- DECLARE_TASKS(02);\r
- DECLARE_TASKS(03);\r
- DECLARE_TASKS(04);\r
  \r
  #endif /* OS_TEST_H_ */\r
index 2d62b797148a7a4968078322a5877579589014d5,b3dbd23035cbcfa430f8c23a11d37e1210a4f493..d1c7c965b9f5147cda788e1a52352edf5741a2a5
 -/* -------------------------------- Arctic Core ------------------------------
 - * Arctic Core - the open source AUTOSAR platform http://arccore.com
 - *
 - * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
 - *
 - * This source code is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License version 2 as published by the
 - * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
 - *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 - * for more details.
 - * -------------------------------- Arctic Core ------------------------------*/
 -/*
 - * Testsystem Requirements:
 - * - Similar to EmbUnit():
 - *   - EmbUnit is built around methods..this does not work well for an OS so
 - *     use macros, TEST_START() and TEST_END() start and end testcases.
 - *   - TEST_ASSERT() macro the same
 - *   - XML output should be the same
 - *   - Same statistict output
 - * - Be able to survive a known crash and restore to the current testcase
 - *   This would be very useful when testing exception behaviour.
 - * - It would have the test-cases grouped, so it will be easy the remove test that don't work
 - *   - Invent a way to do this pretty for different ARCH's. Today ARCH dependent
 - *     test-cases are #ifdef'd.
 - *     ALT_1: Have different header files for each ARCH that disable certain test-cases ?
 - *
 - * Bad stuff in current implementation:
 - * - The initial thought (see suite_01 ) was to build a rather large testsystem
 - *   that whould have few configurations. Howevent, this does not work well at all for
 - *   systems with that is very low on ROM/RAM.
 - * - I wish there was one place to enable/disable tests. Now it's spread out all over the place.
 - * - I guess the DECLARE_TEST_ETASK() macros was good for a large test-system,
 - *   but it should go away (suite_01)
 - * - Hooks and error handling should be unitfied into one file.
 - * - That test-cases is dependent on the former testcase to increase "test_nr"
 - * - Should be able to see what tests are not run?!
 - *
 - *
 - * Total tests:   150
 - * Not run:       5    (not touched by assert)
 - * Failures:      10
 - * Success:       135
 - * Not Implented: 0
 - *
 - * Next:
 - * 1. Fix statistics
 - * 2. Cleanup of testCnt and other "indexes"
 - * 3. Fix statistics over severaral test_suites. (move to NOLOAD section)
 - *
 - */
 -
 -
 -
 -#include <stdint.h>
 -#include <stdio.h>
 -#include <stdlib.h>
 -#include "Platform_Types.h"
 -#include "test_framework.h"
 -#include "Cpu.h"
 +/* -------------------------------- Arctic Core ------------------------------\r
 + * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
 + *\r
 + * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
 + *\r
 + * This source code is free software; you can redistribute it and/or modify it\r
 + * under the terms of the GNU General Public License version 2 as published by the\r
 + * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
 + *\r
 + * This program is distributed in the hope that it will be useful, but\r
 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
 + * for more details.\r
 + * -------------------------------- Arctic Core ------------------------------*/\r
++/*\r
++ * Testsystem Requirements:\r
++ * - Similar to EmbUnit():\r
++ *   - EmbUnit is built around methods..this does not work well for an OS so\r
++ *     use macros, TEST_START() and TEST_END() start and end testcases.\r
++ *   - TEST_ASSERT() macro the same\r
++ *   - XML output should be the same\r
++ *   - Same statistict output\r
++ * - Be able to survive a known crash and restore to the current testcase\r
++ *   This would be very useful when testing exception behaviour.\r
++ * - It would have the test-cases grouped, so it will be easy the remove test that don't work\r
++ *   - Invent a way to do this pretty for different ARCH's. Today ARCH dependent\r
++ *     test-cases are #ifdef'd.\r
++ *     ALT_1: Have different header files for each ARCH that disable certain test-cases ?\r
++ *\r
++ * Bad stuff in current implementation:\r
++ * - The initial thought (see suite_01 ) was to build a rather large testsystem\r
++ *   that whould have few configurations. Howevent, this does not work well at all for\r
++ *   systems with that is very low on ROM/RAM.\r
++ * - I wish there was one place to enable/disable tests. Now it's spread out all over the place.\r
++ * - I guess the DECLARE_TEST_ETASK() macros was good for a large test-system,\r
++ *   but it should go away (suite_01)\r
++ * - Hooks and error handling should be unitfied into one file.\r
++ * - That test-cases is dependent on the former testcase to increase "test_nr"\r
++ * - Should be able to see what tests are not run?!\r
++ *\r
++ *\r
++ * Total tests:   150\r
++ * Not run:       5    (not touched by assert)\r
++ * Failures:      10\r
++ * Success:       135\r
++ * Not Implented: 0\r
++ *\r
++ * Next:\r
++ * 1. Fix statistics\r
++ * 2. Cleanup of testCnt and other "indexes"\r
++ * 3. Fix statistics over severaral test_suites. (move to NOLOAD section)\r
++ *\r
++ */\r
++\r
++\r
 +\r
 +#include <stdint.h>\r
 +#include <stdio.h>\r
++#include <stdlib.h>\r
 +#include "Platform_Types.h"\r
++#include "test_framework.h"\r
++#include "Cpu.h"\r
  \r
  int test_suite = 1;\r
  int test_nr = 1;\r
  int _test_ok = 0;\r
  int _test_failed = 0;\r
 -
 -
 -int testCnt = 0;
 -
 -
 -struct testStats {
 -      int ok;
 -      int fail;
 -      int notRun;
 -      int notImplemented;
 -};
 -
 -struct test {
 -      uint8_t testSuite;
 -      uint8_t testNr;
 -      uint16_t status;
 -      const char *description;
 -      uint32_t expectedErrMask;
 -};
 -\r
 -struct test testTable[50] = { {0} };
 -
 -
 -void TestInit( void ) {
 -
 -}
 +\r
++\r
 +int testCnt = 0;\r
++\r
++\r
++struct testStats {\r
++      int ok;\r
++      int fail;\r
++      int notRun;\r
++      int notImplemented;\r
++};\r
++\r
 +struct test {\r
 +      uint8_t testSuite;\r
 +      uint8_t testNr;\r
 +      uint16_t status;\r
++      const char *description;\r
++      uint32_t expectedErrMask;\r
 +};\r
 +\r
 +struct test testTable[50] = { {0} };\r
 +\r
 +\r
- void test_done( void ) {\r
++void TestInit( void ) {\r
++\r
++}\r
\r
+ void TestDone( void ) {\r
        printf( "\nTest summary\n"\r
                                "Total: %d\n"\r
                                "OK   : %d\n"\r
                                "FAIL : %d\n", _test_ok + _test_failed, _test_ok, _test_failed);\r
  \r
  }\r
 -
 -/**
 - *
 - * @param text
 - * @param file
 - * @param line
 - * @param function
 +\r
- void test_fail( const char *text,char *file,  int line, const char *function ) {\r
++/**\r
++ *\r
++ * @param text\r
++ * @param file\r
++ * @param line\r
++ * @param function\r
+  */\r
+ void TestFail( const char *text,char *file,  int line, const char *function ) {\r
        printf("%02d %02d FAILED, %s , %d, %s\n",test_suite, test_nr, file, line, function);\r
 -      testTable[testCnt].testSuite = test_suite;
 -      testTable[testCnt].testNr = test_nr;
 -      testTable[testCnt].status |= TEST_FLG_ASSERT;
 -//    testCnt++;
 +      testTable[testCnt].testSuite = test_suite;\r
 +      testTable[testCnt].testNr = test_nr;\r
-       testTable[testCnt].status = 0;\r
++      testTable[testCnt].status |= TEST_FLG_ASSERT;\r
++//    testCnt++;\r
+ //    _test_failed++;\r
+ }\r
 -
 -
 -/**
 - * Set errors that are expected during the test
 - * @param errMask
 - */
 -void testSetErrorMask( uint32_t errMask ) {
 -
 -}
 -
 -
 -void testValidateHook( void ) {
 -
 -}
 -
 -/**
 - * Start a test
 - */
 -void TestStart( const char *str, int testNr ) {
 -      testTable[testCnt].status = TEST_FLG_RUNNING;
 -      testTable[testCnt].testNr = testNr;
 -      testTable[testCnt].description = str;
 -      printf("%3d %3d %s\n",testCnt,testNr,str);
 -}
 -
 -void TestInc( void ) {
 -      testCnt++;
 -}
 -
 -/**
 - * End a testcase.
 - */
 -void TestEnd( void ) {
 -      uint16_t status = testTable[testCnt].status;
 -
 -      if( status & TEST_FLG_NOT_IMPLEMENTED ) {
 -              printf("Not Implemented\n");
 -      } else  if( (status & TEST_FLG_TOUCHED) == 0 ) {
 -              printf("NOT touched\n");
 -      } else  if( status & TEST_FLG_RUNNING ) {
 -              if( status & TEST_FLG_ASSERT ) {
 -
 -              } else {
 -                      /* All is OK */
 -                      testTable[testCnt].status &= TEST_FLG_RUNNING;
 -                      testTable[testCnt].status |= TEST_FLG_OK;
 -                      printf("OK\n");
 -              }
 -      } else {
 -              printf("testEnd() on a test that is not running\n");
 -      }
 -      testCnt++;
 -}
 -
 -void TestExit( int rv ) {
 -      Irq_Disable();
 -      exit(rv);
 -}
 -
 -void TestTouch( void ) {
 -      testTable[testCnt].status |= TEST_FLG_TOUCHED;
 -}
 -
 -void TestNotImplemented( void ) {
 -      testTable[testCnt].status |= TEST_FLG_NOT_IMPLEMENTED;
 -}
 -
++\r
++\r
++/**\r
++ * Set errors that are expected during the test\r
++ * @param errMask\r
++ */\r
++void testSetErrorMask( uint32_t errMask ) {\r
++\r
++}\r
++\r
++\r
++void testValidateHook( void ) {\r
++\r
++}\r
++\r
++/**\r
++ * Start a test\r
++ */\r
++void TestStart( const char *str, int testNr ) {\r
++      testTable[testCnt].status = TEST_FLG_RUNNING;\r
++      testTable[testCnt].testNr = testNr;\r
++      testTable[testCnt].description = str;\r
++      printf("%3d %3d %s\n",testCnt,testNr,str);\r
++}\r
++\r
++void TestInc( void ) {\r
++      testCnt++;\r
++}\r
++\r
++/**\r
++ * End a testcase.\r
++ */\r
++void TestEnd( void ) {\r
++      uint16_t status = testTable[testCnt].status;\r
++\r
++      if( status & TEST_FLG_NOT_IMPLEMENTED ) {\r
++              printf("Not Implemented\n");\r
++      } else  if( (status & TEST_FLG_TOUCHED) == 0 ) {\r
++              printf("NOT touched\n");\r
++      } else  if( status & TEST_FLG_RUNNING ) {\r
++              if( status & TEST_FLG_ASSERT ) {\r
++\r
++              } else {\r
++                      /* All is OK */\r
++                      testTable[testCnt].status &= TEST_FLG_RUNNING;\r
++                      testTable[testCnt].status |= TEST_FLG_OK;\r
++                      printf("OK\n");\r
++              }\r
++      } else {\r
++              printf("testEnd() on a test that is not running\n");\r
++      }\r
 +      testCnt++;\r
-       _test_failed++;\r
 +}\r
 +\r
++void TestExit( int rv ) {\r
++      Irq_Disable();\r
++      exit(rv);\r
++}\r
++\r
++void TestTouch( void ) {\r
++      testTable[testCnt].status |= TEST_FLG_TOUCHED;\r
++}\r
++\r
++void TestNotImplemented( void ) {\r
++      testTable[testCnt].status |= TEST_FLG_NOT_IMPLEMENTED;\r
++}\r
 +\r
- void test_ok( void ) {\r
\r
+ void TestOk( void ) {\r
 -      printf("%02d %02d OK\n",test_suite, test_nr);
 -      testTable[testCnt].testSuite = test_suite;
 -      testTable[testCnt].testNr = test_nr;
 -      testTable[testCnt].status = 1;
 +      printf("%02d %02d OK\n",test_suite, test_nr);\r
 +      testTable[testCnt].testSuite = test_suite;\r
 +      testTable[testCnt].testNr = test_nr;\r
 +      testTable[testCnt].status = 1;\r
        testCnt++;\r
        _test_ok++;\r
  }\r
 -
++\r
index 3693cf4fc30bb10c4ffa994eca79c6a40c10cc83,fac7b0f4e03703ec3e3dfec41eb810bd4bfb47dc..5cc37cac246523e5822095d32cd0e8cfb7349cf1
@@@ -1,25 -1,19 +1,19 @@@
 -/* -------------------------------- Arctic Core ------------------------------
 - * Arctic Core - the open source AUTOSAR platform http://arccore.com
 - *
 - * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
 - *
 - * This source code is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License version 2 as published by the
 - * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
 - *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 - * for more details.
 - * -------------------------------- Arctic Core ------------------------------*/
 -
 -
 +/* -------------------------------- Arctic Core ------------------------------\r
 + * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
 + *\r
 + * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
 + *\r
 + * This source code is free software; you can redistribute it and/or modify it\r
 + * under the terms of the GNU General Public License version 2 as published by the\r
 + * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
 + *\r
 + * This program is distributed in the hope that it will be useful, but\r
 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
 + * for more details.\r
 + * -------------------------------- Arctic Core ------------------------------*/\r
 +\r
 +\r
\r
\r
\r
\r
\r
\r
  /*\r
   * test_framework.h\r
   *\r
  \r
  #ifndef TEST_FRAMEWORK_H_\r
  #define TEST_FRAMEWORK_H_\r
 -
 -/* Test flags */
 -#define TEST_FLG_RUNNING                      1
 -#define TEST_FLG_ASSERT                       (1<<1)
 -#define TEST_FLG_DONE                         (1<<2)
 -#define TEST_FLG_OK                           (1<<3)
 -#define TEST_FLG_NOT_IMPLEMENTED      (1<<4)
 -#define TEST_FLG_TOUCHED                      (1<<5)
 -
 -#define TEST_VALUE_NC                 (-1)
 -
 -#define TASK_ID_ILL                   99
 -#define RES_ID_ILL                            99
 -#define ALARM_ID_ILL                  99
 -#define SCHTBL_ID_ILL         99
 -#define COUNTER_ID_ILL                        99
 -
 -
 -
 -#define TEST_INIT()                   printf("Test init\n");
 -#define TEST_FAIL(_text)              TestFail((_text),  __FILE__,  __LINE__, __FUNCTION__ )
 -#define TEST_OK()                             TestOk();
 -#define TEST_ASSERT(_cond)     TestTouch(); \
 -                                                              if(!(_cond)) { \
 -                                                                      TEST_FAIL(#_cond); \
 -                                                              }
 -
 -/* Start to run a test */
 -#define TEST_RUN()                            printf("Running test %d\n",test_nr);
 -/* Indicate that a test is done */
 -//#define TEST_DONE()
 -#define TEST_START(_str,_nr)          TestStart(_str,_nr)
 -#define TEST_NEXT(_str,_next_nr)      TestEnd(); TestStart(_str,_next_nr);
 -#define TEST_END()                                    TestEnd()
 -#define TEST_NOT_IMPLEMENTED()                TestNotImplemented();
 -
 -typedef struct TestFixture {
 -      const char *description;
 -      int nr;
 -} TestFixtureType;
 +\r
- void test_done( void );\r
++/* Test flags */\r
++#define TEST_FLG_RUNNING                      1\r
++#define TEST_FLG_ASSERT                       (1<<1)\r
++#define TEST_FLG_DONE                         (1<<2)\r
++#define TEST_FLG_OK                           (1<<3)\r
++#define TEST_FLG_NOT_IMPLEMENTED      (1<<4)\r
++#define TEST_FLG_TOUCHED                      (1<<5)\r
++\r
++#define TEST_VALUE_NC                 (-1)\r
++\r
++#define TASK_ID_ILL                   99\r
++#define RES_ID_ILL                            99\r
++#define ALARM_ID_ILL                  99\r
++#define SCHTBL_ID_ILL         99\r
++#define COUNTER_ID_ILL                        99\r
++\r
++\r
++\r
++#define TEST_INIT()                   printf("Test init\n");\r
++#define TEST_FAIL(_text)              TestFail((_text),  __FILE__,  __LINE__, __FUNCTION__ )\r
++#define TEST_OK()                             TestOk();\r
++#define TEST_ASSERT(_cond)     TestTouch(); \\r
++                                                              if(!(_cond)) { \\r
++                                                                      TEST_FAIL(#_cond); \\r
++                                                              }\r
++\r
++/* Start to run a test */\r
++#define TEST_RUN()                            printf("Running test %d\n",test_nr);\r
++/* Indicate that a test is done */\r
++//#define TEST_DONE()\r
++#define TEST_START(_str,_nr)          TestStart(_str,_nr)\r
++#define TEST_NEXT(_str,_next_nr)      TestEnd(); TestStart(_str,_next_nr);\r
++#define TEST_END()                                    TestEnd()\r
++#define TEST_NOT_IMPLEMENTED()                TestNotImplemented();\r
++\r
++typedef struct TestFixture {\r
++      const char *description;\r
++      int nr;\r
++} TestFixtureType;\r
\r
+ void TestDone( void );\r
\r
+ void TestFail( const char *text,char *file,  int line, const char *function );\r
 -void TestOk( void );
++void TestOk( void );\r
+ void TestTouch( void );\r
 -
 -void TestStart( const char *str, int testNr );
 -void TestInc( void );
 -void TestEnd( void );
 -void TestExit( int rv );
 -
 -
 -typedef void (*test_func_t)( void );
 -
 -extern int test_suite;
 -extern int test_nr;
 -
 -/* TODO: Move to a better place */
 -#if defined(CFG_MPC55XX)
 -/* On INTC first 8 interrupt are softtriggered */
 -#define IRQ_SOFTINT_0         INTC_SSCIR0_CLR0
 -#define IRQ_SOFTINT_1         INTC_SSCIR0_CLR1
 -#elif defined(CFG_ARM_CM3)
 -/* Cortex-M3 can softtrigger any interrupt. Use external here. */
 -#define IRQ_SOFTINT_0         EXTI0_IRQn
 -#define IRQ_SOFTINT_1         EXTI1_IRQn
 -#endif
 -
 -#if 1
 -#define SECTION_SUP
 -#define SECTION_USER
 -#else
 -#define SECTION_SUP                   __attribute__ ((section(".text_app_sup")))
 -#define SECTION_USER          __attribute__ ((section(".text_app_user")))
 -#endif
 -
 -#define SECTION_BSS_SUPER     __attribute__ ((aligned (16),section(".bss")))
 -#define SECTION_BSS_USER      __attribute__ ((aligned (16),section(".bss")))
 -
 -#define OS_STR__(x)           #x
 -#define OS_STRSTR__(x)        OS_STR__(x)
 -
 -#define DECLARE_TEST_BTASK(_nr, _task1, _task2, _task3 ) \
 -              __attribute__ ((section (".test_btask"))) const test_func_t btask_sup_matrix_ ## _nr[3] = { _task1, _task2, _task3 }
 -
 -#define DECLARE_TEST_ETASK(_nr, _task1, _task2, _task3 ) \
 -              __attribute__ ((section (".test_etask"))) const test_func_t etask_sup_matrix_ ## _nr[3]  = { _task1, _task2, _task3 }
 -
 -#define DECLARE_TASKS(_nr) \
 -      void etask_sup_l_##_nr( void ); \
 -      void etask_sup_m_##_nr( void ); \
 -      void etask_sup_h_##_nr( void ); \
 -      void btask_sup_l_##_nr( void ); \
 -      void btask_sup_m_##_nr( void ); \
 -      void btask_sup_h_##_nr( void );
 -
 -
 -/*
 - * Declare tests
 - */
 -
 -// Test master processes
 -void OsIdle(void );
 -void etask_master( void );
 -void etask_sup_l( void ) SECTION_SUP;
 -void etask_sup_m( void ) SECTION_SUP;
 -void etask_sup_h( void ) SECTION_SUP;
 -
 -void btask_sup_l( void ) SECTION_SUP;
 -void btask_sup_m( void ) SECTION_SUP;
 -void btask_sup_h( void ) SECTION_SUP;
 -
 -
 -// Tests
 -DECLARE_TASKS(01);
 -DECLARE_TASKS(02);
 -DECLARE_TASKS(03);
 -DECLARE_TASKS(04);
++\r
++void TestStart( const char *str, int testNr );\r
++void TestInc( void );\r
++void TestEnd( void );\r
++void TestExit( int rv );\r
++\r
++\r
++typedef void (*test_func_t)( void );\r
++\r
++extern int test_suite;\r
++extern int test_nr;\r
++\r
++/* TODO: Move to a better place */\r
++#if defined(CFG_MPC55XX)\r
++/* On INTC first 8 interrupt are softtriggered */\r
++#define IRQ_SOFTINT_0         INTC_SSCIR0_CLR0\r
++#define IRQ_SOFTINT_1         INTC_SSCIR0_CLR1\r
++#elif defined(CFG_ARM_CM3)\r
++/* Cortex-M3 can softtrigger any interrupt. Use external here. */\r
++#define IRQ_SOFTINT_0         EXTI0_IRQn\r
++#define IRQ_SOFTINT_1         EXTI1_IRQn\r
++#endif\r
++\r
++#if 1\r
++#define SECTION_SUP\r
++#define SECTION_USER\r
++#else\r
++#define SECTION_SUP                   __attribute__ ((section(".text_app_sup")))\r
++#define SECTION_USER          __attribute__ ((section(".text_app_user")))\r
++#endif\r
++\r
++#define SECTION_BSS_SUPER     __attribute__ ((aligned (16),section(".bss")))\r
++#define SECTION_BSS_USER      __attribute__ ((aligned (16),section(".bss")))\r
++\r
++#define OS_STR__(x)           #x\r
++#define OS_STRSTR__(x)        OS_STR__(x)\r
++\r
++#define DECLARE_TEST_BTASK(_nr, _task1, _task2, _task3 ) \\r
++              __attribute__ ((section (".test_btask"))) const test_func_t btask_sup_matrix_ ## _nr[3] = { _task1, _task2, _task3 }\r
++\r
++#define DECLARE_TEST_ETASK(_nr, _task1, _task2, _task3 ) \\r
++              __attribute__ ((section (".test_etask"))) const test_func_t etask_sup_matrix_ ## _nr[3]  = { _task1, _task2, _task3 }\r
++\r
++#define DECLARE_TASKS(_nr) \\r
++      void etask_sup_l_##_nr( void ); \\r
++      void etask_sup_m_##_nr( void ); \\r
++      void etask_sup_h_##_nr( void ); \\r
++      void btask_sup_l_##_nr( void ); \\r
++      void btask_sup_m_##_nr( void ); \\r
++      void btask_sup_h_##_nr( void );\r
++\r
++\r
++/*\r
++ * Declare tests\r
++ */\r
++\r
++// Test master processes\r
++void OsIdle(void );\r
++void etask_master( void );\r
++void etask_sup_l( void ) SECTION_SUP;\r
++void etask_sup_m( void ) SECTION_SUP;\r
++void etask_sup_h( void ) SECTION_SUP;\r
++\r
++void btask_sup_l( void ) SECTION_SUP;\r
++void btask_sup_m( void ) SECTION_SUP;\r
++void btask_sup_h( void ) SECTION_SUP;\r
++\r
 +\r
- void test_fail( char *text,char *file,  int line , const char *function );\r
- void test_ok( void );\r
++// Tests\r
++DECLARE_TASKS(01);\r
++DECLARE_TASKS(02);\r
++DECLARE_TASKS(03);\r
++DECLARE_TASKS(04);\r
  \r
  #endif /* TEST_FRAMEWORK_H_ */\r