}\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
{\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
\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
\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
* 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
\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
* 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
}\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
/**\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
/**\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
- \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
- /*\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
+
+
- \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
+
+
+
+
+
- \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
+
+
+
+
+
- \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
+
+
+
+
+
-/*
-* 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
-/*
-* 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
- \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
+
+
+
+
+
- /* -------------------------------- 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_*/
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
*/\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
# 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
/^\.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
-/* -------------------------------- 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
\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
*/\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
#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
#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
/* 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
- /* -------------------------------- 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) { }
+
+ }
+
+
+
- /* -------------------------------- 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;
+ }
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
/** @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
\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
-/* -------------------------------- 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
-/*
-* 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
-/*
-* 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
-/* -------------------------------- 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
-/* -------------------------------- 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
-/* -------------------------------- 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