From cedc619ed02fcb04f06f20e468f0b44a373c5ae5 Mon Sep 17 00:00:00 2001 From: fbucafusco Date: Wed, 2 Mar 2016 18:36:49 -0300 Subject: [PATCH 01/42] agrego modulos rtos para 430 --- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 118 +++++ gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 407 ++++++++++++++++++ inc/msp430/Os_Arch.h | 153 +++++++ inc/msp430/Os_Internal_Arch.h | 283 ++++++++++++ inc/msp430/StartOs_Arch_SysTick.h | 2 + .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 120 ++++++ src/msp430/Os_Arch.c | 73 ++++ src/msp430/Os_Internal_Arch.c | 150 +++++++ src/msp430/PendSV.s | 125 ++++++ src/msp430/StartOs_Arch.c | 95 ++++ src/msp430/StartOs_Arch_SysTick.c | 93 ++++ 11 files changed, 1619 insertions(+) create mode 100644 gen/inc/msp430/Os_Internal_Arch_Cfg.h.php create mode 100644 gen/src/msp430/Os_Internal_Arch_Cfg.c.php create mode 100644 inc/msp430/Os_Arch.h create mode 100644 inc/msp430/Os_Internal_Arch.h create mode 100644 inc/msp430/StartOs_Arch_SysTick.h create mode 100644 inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h create mode 100644 src/msp430/Os_Arch.c create mode 100644 src/msp430/Os_Internal_Arch.c create mode 100644 src/msp430/PendSV.s create mode 100644 src/msp430/StartOs_Arch.c create mode 100644 src/msp430/StartOs_Arch_SysTick.c diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php new file mode 100644 index 00000000..581b648a --- /dev/null +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -0,0 +1,118 @@ +/******************************************************** + * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* + ********************************************************/ + +/* Copyright 2016, Franco Bucafusco + * All rights reserved. + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _OS_INTERNAL_ARCH_CFG_H_ +#define _OS_INTERNAL_ARCH_CFG_H_ + +/***************************************************************************** + * update the tmparch directory on the \file doxygen comment with your + * architecture + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/** \brief FreeOSEK Os Generated Internal Architecture Configuration Header File + ** + ** This file content the internal generated architecture dependent + ** configuration of FreeOSEK. + ** + ** \file msp430/Os_Internal_Arch_Cfg.h + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/***************************************************************************** + * add your name to the developers and create for you a nick with + * 3 or 4 letters. Please do not use any given nick. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/***************************************************************************** + * add a new version to this file, add the date, your initials and the main + * changes, only main changes shall be listed here. A detailed message log + * is saved in svn log and on the tracker system since every svn login message + * shalle indicate the related tracker id. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * v0.1.0 20162202 FB First version for msp430 processors. + */ + +/*==================[inclusions]=============================================*/ +/***************************************************************************** + * Please define here all needed macros of your configuration that can + * be configured or are used in Osek_Internal_Arch_Cfg.c.php + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[typedef]================================================*/ + +/** \brief Task Context Type */ +typedef uint32 * TaskContextType; + +/** \brief Task Context Type */ +typedef TaskContextType* TaskContextRefType; + +/*==================[external data declaration]==============================*/ +/***************************************************************************** + * Please declare here all exported data defined + * Osek_Internal_Arch_Cfg.c.php + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external functions declaration]=========================*/ +/* +void Enable_User_ISRs(void); +void Enable_ISR2_Arch(void); +void Disable_ISR2_Arch(void); +*/ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _OS_INTERNAL_ARCH_CFG_H_ */ + diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php new file mode 100644 index 00000000..50617b4e --- /dev/null +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -0,0 +1,407 @@ +/******************************************************** + * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* + ********************************************************/ + +/* Copyright 2016, Franco Bucafusco + * All rights reserved. + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os Generated Internal Achitecture Configuration Implementation File + ** + ** \file msp430/Os_Internal_Arch_Cfg.c + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * v0.1.0 20160221 initial version + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal.h" + +#if(CPU == msp430f5x_6x) +/* THIS IS A DIRTY WORKAROUND :( ciaa/Firmware#309*/ +#undef FALSE +#undef TRUE +//#include "chip.h" +#endif + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ +#if (CPU == msp430f5529) + /* Reset_Handler is defined in startup_MK60F15.S_CPP */ +//COMENTADO BUCK void Reset_Handler( void ); + +//COMENTADO BUCK extern uint32_t __StackTop; +#else +#error Not supported CPU +#endif + +/** \brief Handlers used by OSEK */ +//extern void SysTick_Handler(void); +//extern void PendSV_Handler(void); + +/*==================[internal functions definition]==========================*/ +/* Default exception handlers */ +/*__attribute__ ((section(".after_vectors"))) +void NMI_Handler(void) +{ + while (1) +{ + } +} + +__attribute__ ((section(".after_vectors"))) +void HardFault_Handler(void) +{ + while (1) { + } +} + +__attribute__ ((section(".after_vectors"))) +void MemManage_Handler(void) { + while (1) { + } +} + +__attribute__ ((section(".after_vectors"))) +void BusFault_Handler(void) { + while (1) { + } +} + +__attribute__ ((section(".after_vectors"))) +void UsageFault_Handler(void) { + while (1) { + } +} + +__attribute__ ((section(".after_vectors"))) +void SVC_Handler(void) { + while (1) { + } +} + +__attribute__ ((section(".after_vectors"))) +void DebugMon_Handler(void) { + while (1) { + } +} +*/ + +/*==================[external functions definition]==========================*/ + "DMA0_DMA16", + 1 => "DMA1_DMA17", + 2 => "DMA2_DMA18", + 3 => "DMA3_DMA19", + 4 => "DMA4_DMA20", + 5 => "DMA5_DMA21", + 6 => "DMA6_DMA22", + 7 => "DMA7_DMA23", + 8 => "DMA8_DMA24", + 9 => "DMA9_DMA25", + 10 => "DMA10_DMA26", + 11 => "DMA11_DMA27", + 12 => "DMA12_DMA28", + 13 => "DMA13_DMA29", + 14 => "DMA14_DMA30", + 15 => "DMA15_DMA31", + 16 => "DMA_ERR", + 17 => "MCM", + 18 => "FTFE", + 19 => "Read_Collision", + 20 => "LVD_LVW", + 21 => "LLW", + 22 => "WDG", + 23 => "RNG", + 24 => "I2C0", + 25 => "I2C1", + 26 => "SPI0", + 27 => "SPI1", + 28 => "SPI2", + 29 => "CAN0_READ", + 30 => "CAN0_BOFF", + 31 => "CAN0_ERR", + 32 => "CAN0_TXW", + 33 => "CAN0_RXW", + 34 => "CAN0_WAKEUP", + 35 => "I2S0_TX", + 36 => "I2S0_RR", + 37 => "CAN1_READ", + 38 => "CAN1_BOFF", + 39 => "CAN1_EERROR", + 40 => "CAN1_TXW", + 41 => "CAN1_RXW", + 42 => "CAN1_WAKEUP", + 43 => "RES59", + 44 => "UART0_LON", + 45 => "UART0", + 46 => "UART0_ERR", + 47 => "UART1", + 48 => "UART1_ERR", + 49 => "UART2", + 50 => "UART2_ERR", + 51 => "UART3", + 52 => "UART3_ERR", + 53 => "UART4", + 54 => "UART4_ERR", + 55 => "UART5", + 56 => "UART5_ERR", + 57 => "ADC0", + 58 => "ADC1", + 59 => "CMP0", + 60 => "CMP1", + 61 => "CMP2", + 62 => "FTM0", + 63 => "FTM1", + 64 => "FTM2", + 65 => "CMT", + 66 => "RTC", + 67 => "RTC_SEC", + 68 => "PIT0", + 69 => "PIT1", + 70 => "PIT2", + 71 => "PIT3", + 72 => "PDB0", + 73 => "USB0", + 74 => "USBDCD", + 75 => "ENET_1588_Timer", + 76 => "ENET_TX", + 77 => "ENET_RX", + 78 => "ENET_ERR", + 79 => "RES95", + 80 => "SDHC", + 81 => "DAC0", + 82 => "DAC1", + 83 => "TSI0", + 84 => "MCG", + 85 => "LPTimer", + 86 => "RES102", + 87 => "PORTA", + 88 => "PORTB", + 89 => "PORTC", + 90 => "PORTD", + 91 => "PORTE", + 92 => "PORTF", + 93 => "RES109", + 94 => "SWI", + 95 => "NFC", + 96 => "USBHS", + 97 => "RES113", + 98 => "CMP3", + 99 => "RES115", + 100 => "RES116", + 101 => "FTM3", + 102 => "ADC2", + 103 => "ADC3", + 104 => "I2S1_TX", + 105 => "I2S1_RX", + ); + break; + + default: + $this->log->error("the CPU " . $definitions["CPU"] . " is not supported."); + break; +} + +$MAX_INT_COUNT = max(array_keys($intList))+1; + +if ($definitions["CPU"] == "msp430f5529") : ?> +__attribute__ ((section(".isr_vector"))) +void (* const g_pfnVectors[])(void) = { + /* System ISRs */ + &__StackTop, /* The initial stack pointer */ + Reset_Handler, /* The reset handler */ + NMI_Handler, /* The NMI handler */ + HardFault_Handler, /* The hard fault handler */ + MemManage_Handler, /* The MPU fault handler */ + BusFault_Handler, /* The bus fault handler */ + UsageFault_Handler, /* The usage fault handler */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + SVC_Handler, /* SVCall handler */ + DebugMon_Handler, /* Debug monitor handler */ + 0, /* Reserved */ + PendSV_Handler, /* The PendSV handler */ + SysTick_Handler, /* The SysTick handler */ + +/** \brief LPC4337 Interrupt vector */ +__attribute__ ((section(".isr_vector"))) +void (* const g_pfnVectors[])(void) = { + /* System ISRs */ + &_vStackTop, /* The initial stack pointer */ + ResetISR, /* The reset handler */ + NMI_Handler, /* The NMI handler */ + HardFault_Handler, /* The hard fault handler */ + MemManage_Handler, /* The MPU fault handler */ + BusFault_Handler, /* The bus fault handler */ + UsageFault_Handler, /* The usage fault handler */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + SVC_Handler, /* SVCall handler */ + DebugMon_Handler, /* Debug monitor handler */ + 0, /* Reserved */ + PendSV_Handler, /* The PendSV handler */ + SysTick_Handler, /* The SysTick handler */ +log->error("Not supported CPU: " . $definitions["CPU"]); + endif; +?> + /*** User Interruptions ***/ +getValue("/OSEK/" . $int,"CATEGORY"); + $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); + + if($intList[$i] == $source) + { + if ($intcat == 2) + { + print " OSEK_ISR2_$int, /* 0x".dechex($i+16)." 0x".str_pad(strtoupper(dechex(($i+16)*4)), 8, "0", STR_PAD_LEFT)." ISR for " . $intList[$i] . " (IRQ $i) Category 2 */\n"; + $src_found = 1; + } elseif ($intcat == 1) + { + print " OSEK_ISR_$int, /* 0x".dechex($i+16)." 0x".str_pad(strtoupper(dechex(($i+16)*4)), 8, "0", STR_PAD_LEFT)." ISR for " . $intList[$i] . " (IRQ $i) Category 1 */\n"; + $src_found = 1; + } else + { + $this->log->error("Interrupt $int type $inttype has an invalid category $intcat"); + } + } + } + if($src_found == 0) + { + print " OSEK_ISR_NoHandler, /* 0x".dechex($i+16)." 0x".str_pad(strtoupper(dechex(($i+16)*4)), 8, "0", STR_PAD_LEFT)." - No Handler set for ISR " . $intList[$i] . " (IRQ $i) */\n"; + } +} +?> +}; + +/** \brief Interrupt enabling and priority setting function */ +void Enable_User_ISRs(void) +{ +getValue("/OSEK/" . $int,"INTERRUPT"); + $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); + + print " /* Enabling IRQ $source with priority $prio */\n"; + print " NVIC_EnableIRQ(" . array_search($source, $intList) . ");\n"; + print " NVIC_SetPriority(" . array_search($source, $intList) . ", $prio);\n\n"; +} +?> +} + +/** \brief Enable user defined category 2 ISRs */ +void Enable_ISR2_Arch(void) +{ +getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + + if($cat == 2) + { + print " /* Enabling IRQ $source */\n"; + print " NVIC_EnableIRQ(" . array_search($source, $intList) . ");\n"; + } +} +?> +} + +/** \brief Disable user defined category 2 ISRs */ +void Disable_ISR2_Arch(void) +{ +getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + + if($cat == 2) + { + print " /* Disabling IRQ $source */\n"; + print " NVIC_DisableIRQ(" . array_search($source, $intList) . ");\n"; + } +} +?> +} + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ + diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h new file mode 100644 index 00000000..686b702f --- /dev/null +++ b/inc/msp430/Os_Arch.h @@ -0,0 +1,153 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _OS_ARCH_H_ +#define _OS_ARCH_H_ + +/** \brief FreeOSEK Os Architecture Dependent Header File + ** + ** This file is included form os.h and defines macros + ** and types which depends on the architecture. + ** + ** \file msp430/Os_Arch.h + ** \arch msp430 + ** + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Global + ** @{ */ + +/***************************************************************************** + * add your name to the developers and create for you a nick with + * 3 or 4 letters. Please do not use any given nick. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/***************************************************************************** + * add a new version to this file, add the date, your initials and the main + * changes, only main changes shall be listed here. A detailed message log + * is saved in svn log and on the tracker system since every svn login message + * shalle indicate the related tracker id. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/* + * modification history (new versions first) + * ---------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + +/*==================[inclusions]=============================================*/ + +#include "Os_Internal_Arch_Cfg.h" + +/*==================[macros]=================================================*/ +/***************************************************************************** + * Please define here all needed macros that will be visible to the OS user + * for this architecutre. This means that anyone including os.h will have + * access to this definitions if the actual architecutre is used. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/** \brief Enable All Interrupts Arch */ +#define EnableAllInterrupts_Arch() ResumeAllInterrupts_Arch() + +/** \brief Disable All Interrupts Arch */ +#define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() + +/** \brief Resume All Interrupts Arch + ** + ** This macro shall resume (enable) all interrupts. + **/ +#define ResumeAllInterrupts_Arch() __asm volatile("cpsie i") + +/** \brief Suspend All Interrupts Arch + ** + ** This macro shall suspend (disable) all interrupts. + **/ +#define SuspendAllInterrupts_Arch() __asm volatile("cpsid i") + +/** \brief Resume OS Interrupts Arch + ** + ** This macro shall resume (enable) all interrupts configured on the + ** FreeOSEK OIL configuration file as ISR2. + **/ +#define ResumeOSInterrupts_Arch() Enable_ISR2_Arch() + +/** \brief Suspend OS Interrupts Arch + ** + ** This macro shall suspend (disable) all interrupts configured on the + ** FreeOSEK OIL configuration file as ISR2. + **/ +#define SuspendOSInterrupts_Arch() Disable_ISR2_Arch() + +/*==================[typedef]================================================*/ +/***************************************************************************** + * Please define here all needed types that will be visible to the OS user + * for this architecutre. This means that anyone including os.h will have + * access to these type definitions if the actual architecutre is used. + * Normaly no type has to be declared here. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external data declaration]==============================*/ +/***************************************************************************** + * Please declare here all exported data defined in Osek_Arch.c that will + * be visible to the OS user for this architectire. This means that anyone + * including os.h will have access to these variables, if the actual + * architecutre is used. Normaly no variables has to be declared here. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external functions declaration]=========================*/ +/***************************************************************************** + * Please declare here all exported functions defined in Osek_Arch.c that will + * be visible to the OS user for this architectire. This means that anyone + * including os.h will have access to these variables, if the actual + * architecutre is used. Normaly no variables has to be declared here. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _OS_ARCH_H_ */ + diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h new file mode 100644 index 00000000..a17c3049 --- /dev/null +++ b/inc/msp430/Os_Internal_Arch.h @@ -0,0 +1,283 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _OS_INTERNAL_ARCH_H_ +#define _OS_INTERNAL_ARCH_H_ + +/** \brief FreeOSEK Internal Architecture Dependent Header File + ** + ** \file msp430/Os_Internal_Arch.h + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + +/*==================[inclusions]=============================================*/ + + +/*==================[macros]=================================================*/ +/** \brief Extra size reserved for each stack + ** + ** This macro shall be set to the amount of extra stack needed for each task + ** in the simulation of the rtos in systems like windows/linux. In real + ** embedded hw this macro shall be set to 0. + ** + ** TASK_STAC_ADDITIONAL_STACK bytes of extra stack are reserver for each task + ** running on the system. + **/ +#define TASK_STACK_ADDITIONAL_SIZE 0 + +/** \brief Osek_Internal_Arch_Cpu.h inclusion needed macro + ** + ** This define makes the Osek_Internal.h file to include the + ** Osek_Internal_Arch_Cpu file which is not standard for all architectures. + ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede + ** remove the macro and this comment. + **/ +#define OSEK_INLCUDE_INTERNAL_ARCH_CPU + +extern void * Osek_OldTaskPtr_Arch; +extern void * Osek_NewTaskPtr_Arch; +extern TaskType TerminatingTask; + +/** \brief Interrupt Secure Start Macro + ** + ** This macro will be used internaly by the OS in any part of code that + ** has to be executed atomic. + **/ +#define IntSecure_Start() SuspendAllInterrupts() + +/** \brief Interrupt Secure End Macro + ** + ** This macro is the countra part of IntSecure_Start() + **/ +#define IntSecure_End() ResumeAllInterrupts() + +/** \brief osekpause + ** + ** This macro is called by the scheduler when not task has to be executed. + ** If a background task is configured by the user (a full preemptive task + ** with lower priority and which never ends) this macro will never be called. + ** In other case the macro will be called any time that the OS has nothing + ** else to execute. The macro may sleep the cpu for a short time to avoid + ** overheating and full power consumption or may halt the processor always + ** that all wakeup reasons are right configured. If nothing is running + ** nothing my activate any task so we will keep sleeping until anything + ** occurs, like for example an interrupt. + ** + **/ +#define osekpause() __asm volatile("wfi") + +/** \brief Call to an other Task + ** + ** This function jmps to the indicated task. + **/ +#define CallTask(actualtask, nexttask) \ +{ \ + Osek_OldTaskPtr_Arch = (void*)TasksConst[(actualtask)].TaskContext; \ + Osek_NewTaskPtr_Arch = (void*)TasksConst[(nexttask)].TaskContext; \ + __asm__ __volatile__ ( \ + /* Call PendSV */ \ + "push {r0,r1} \n\t" \ + /* Activate bit PENDSVSET in Interrupt Control State Register (ICSR) */ \ + "ldr r0,=0xE000ED04 \n\t" \ + "ldr r1,[r0] \n\t" \ + "orr r1,1<<28 \n\t" \ + "str r1,[r0] \n\t" \ + "pop {r0,r1} \n\t" \ + ); \ +} + +/** \brief Jmp to an other Task + ** + ** This function jmps to the indicated task. + **/ +#define JmpTask(task) \ +{ \ + extern TaskType WaitingTask; \ + if(WaitingTask != INVALID_TASK) \ + { \ + Osek_OldTaskPtr_Arch = (void*)TasksConst[WaitingTask].TaskContext; \ + WaitingTask = INVALID_TASK; \ + } \ + else \ + { \ + Osek_OldTaskPtr_Arch = (void*)0; \ + } \ + Osek_NewTaskPtr_Arch = (void*)TasksConst[(task)].TaskContext; \ + __asm__ __volatile__ ( \ + /* Call PendSV */ \ + "push {r0,r1} \n\t" \ + /* Activate bit PENDSVSET in Interrupt Control State Register (ICSR) */ \ + "ldr r0,=0xE000ED04 \n\t" \ + "ldr r1,[r0] \n\t" \ + "orr r1,1<<28 \n\t" \ + "str r1,[r0] \n\t" \ + "pop {r0,r1} \n\t" \ + ); \ +} + +/** \brief Save context */ +#define SaveContext(task) \ +{ \ + extern TaskType WaitingTask; \ + if(TasksVar[GetRunningTask()].Flags.State == TASK_ST_WAITING) \ + { \ + WaitingTask = GetRunningTask(); \ + } \ + flag = 0; \ + /* remove of the Ready List */ \ + RemoveTask(GetRunningTask()); \ + /* set system context */ \ + SetActualContext(CONTEXT_SYS); \ + /* set running task to invalid */ \ + SetRunningTask(INVALID_TASK); \ + /* finish cirtical code */ \ + IntSecure_End(); \ + /* call scheduler */ \ + Schedule(); \ + /* add this call in order to maintain counter balance when returning */ \ + IntSecure_Start(); \ +} + +/** \brief */ +#define ResetStack(task) \ +{ \ + TerminatingTask = (task); \ +} + +/** \brief Set the entry point for a task */ +#define SetEntryPoint(task) \ +{ \ + TerminatingTask = (task); \ +} + +/** \brief Enable OS Interruptions + ** + ** Enable OS configured interrupts (ISR1 and ISR2). This macro + ** is called only ones in StartUp.c function. + **/ +#define EnableOSInterrupts() __asm volatile("cpsie i") + +/** \brief Enable Interruptions + ** + ** Enable not OS configured interrupts (ISR1 and ISR2). This macro + ** is called only ones in StartUp.c function. + ** + ** This macro may be empty. Maybe will be removed on the future, + ** please use it only if necessary, in other case use EnableOSInterrupts. + **/ +#define EnableInterrupts() EnableOSInterrupts() + + +/** \brief Disable OS Interruptions + ** + ** Disable OS configured interrupts (ISR1 and ISR2). + **/ +#define DisableOSInterrupts() __asm volatile("cpsid i") + +/** \brief Disable Interruptions + ** + ** Disable not OS configured interrupts (ISR1 and ISR2). This macro + ** is called only ones in StartUp.c function. + ** + ** This macro may be empty. Maybe will be removed on the future, + ** please use it only if necessary, in other case use DisableOSInterrupts. + **/ +#define DisableInterrupts() DisableOSInterrupts() + +/** \brief Get Counter Actual Value + ** + ** This macro returns the actual value of the a counter + ** + ** \param[in] CounterID id of the counter to be readed + ** \return Actual value of the counter + **/ +#define GetCounter_Arch(CounterID) (CountersVar[CounterID].Time) + +/** \brief Pre ISR Macro + ** + ** This macro is called every time that an ISR Cat 2 is started + **/ +#define PreIsr2_Arch(isr) + +/** \brief Post ISR Macro + ** + ** This macro is called every time that an ISR Cat 2 is finished + **/ +#define PostIsr2_Arch(isr) Schedule_WOChecks() + +/** \brief ShutdownOs Arch service + ** + ** This macro is called on the ShutdownOS to perform the architecture + ** dependent shutdown actions. + **/ +#define ShutdownOs_Arch() + +/*==================[typedef]================================================*/ +/***************************************************************************** + * Please define here all needed types that will be used only internal by + * the OS and only for this architecture and which will not depend on the + * configuraiton. Normaly this section shall be empty. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external data declaration]==============================*/ +/***************************************************************************** + * Please declare here all exported data defined in Osek_Internal_Arch.c + * that will be visible only internal to the OS for this architectire. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external functions declaration]=========================*/ +void InitStack_Arch(uint8 TaskID); + + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ + diff --git a/inc/msp430/StartOs_Arch_SysTick.h b/inc/msp430/StartOs_Arch_SysTick.h new file mode 100644 index 00000000..e05e8c59 --- /dev/null +++ b/inc/msp430/StartOs_Arch_SysTick.h @@ -0,0 +1,2 @@ + +void StartOs_Arch_SysTick(void); diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h new file mode 100644 index 00000000..a09eb4b2 --- /dev/null +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -0,0 +1,120 @@ +/* Copyright 2014, ACSE & CADIEEL + * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ + * CADIEEL: http://www.cadieel.org.ar + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _OS_INTERNAL_ARCH_CPU_H_ +#define _OS_INTERNAL_ARCH_CPU_H_ + +/** \brief FreeOSEK Internal Architecture Cpu Dependent Header File + ** + ** \file cortexM4/lpc4000/Os_Internal_Arch_Cpu.h + ** \arch cortexM4/lpc4000 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/***************************************************************************** + * add your name to the developers and create for you a nick with + * 3 or 4 letters. Please do not use any given nick. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/***************************************************************************** + * add a new version to this file, add the date, your initials and the main + * changes, only main changes shall be listed here. A detailed message log + * is saved in svn log and on the tracker system since every svn login message + * shalle indicate the related tracker id. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20140608 v0.1.1 PR First version for LPC4337 microcontroller. + */ + +/*==================[cpu macros]=============================================*/ +/***************************************************************************** + * Please define here all cpu macros available for this cputype. arm7 and + * cpy family lpc2xxx is given as example, please remove all arm7 and lpc2xxx + * related macros + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[inclusions]=============================================*/ +/***************************************************************************** + * Include the right macros for every cpu. Please remove all arm7 and lpc2xxx + * related macros. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[macros]=================================================*/ +/***************************************************************************** + * use this section to defined any necessary macros for a specific cpu of + * your family. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[typedef]================================================*/ +/***************************************************************************** + * use this section to defined any necessary types for a specific cpu of + * your family. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external data declaration]==============================*/ +/***************************************************************************** + * use this section to declare any necessary variables for a specific cpu of + * your family. + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ + +/*==================[external functions declaration]=========================*/ +void StartOs_Arch_Cpu(void); + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _OS_INTERNAL_ARCH_CPU_H_ */ + diff --git a/src/msp430/Os_Arch.c b/src/msp430/Os_Arch.c new file mode 100644 index 00000000..4ff82f8e --- /dev/null +++ b/src/msp430/Os_Arch.c @@ -0,0 +1,73 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os Arch Implementation File + ** + ** \file msp430/Os_Arch.c + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Global + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal.h" + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ + diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c new file mode 100644 index 00000000..e42ae59f --- /dev/null +++ b/src/msp430/Os_Internal_Arch.c @@ -0,0 +1,150 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os Internal Arch Implementation File + ** + ** \file cortexM4/Os_Internal_Arch.c + ** \arch cortexM4 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version for msp430 processors + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal.h" + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ +void* Osek_NewTaskPtr_Arch; + +void* Osek_OldTaskPtr_Arch; + +/*==================[internal data definition]===============================*/ + +TaskType TerminatingTask = INVALID_TASK; +TaskType WaitingTask = INVALID_TASK; + +/*==================[external data definition]===============================*/ + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ + +void ReturnHook_Arch(void) +{ + /* Tasks shouldn't return here... */ + while(1) + osekpause(); +} + +void CheckTerminatingTask_Arch(void) +{ + if(TerminatingTask != INVALID_TASK) + { + InitStack_Arch(TerminatingTask); + } + TerminatingTask = INVALID_TASK; +} + +/* Task Stack Initialization */ +void InitStack_Arch(uint8 TaskID) +{ + + uint32 * taskStack = (uint32 *)TasksConst[TaskID].StackPtr; + int taskStackSizeWords = TasksConst[TaskID].StackSize/4; + + taskStack[taskStackSizeWords-1] = 1<<24; /* xPSR.T = 1 */ + taskStack[taskStackSizeWords-2] = (uint32) TasksConst[TaskID].EntryPoint; /*PC*/ + taskStack[taskStackSizeWords-3] = (uint32) ReturnHook_Arch; /* stacked LR */ + taskStack[taskStackSizeWords-9] = 0xFFFFFFFD; /* current LR, return using PSP */ + + *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 17]); + +} + +/* Periodic Interrupt Timer, included in all Cortex-M4 processors */ +void SysTick_Handler(void) +{ + /* store the calling context in a variable */ + ContextType actualContext = GetCallingContext(); + /* set isr 2 context */ + SetActualContext(CONTEXT_ISR2); + +#if (ALARMS_COUNT != 0) + /* counter increment */ + static CounterIncrementType CounterIncrement = 1; + (void)CounterIncrement; /* TODO remove me */ + + /* increment the disable interrupt conter to avoid enable the interrupts */ + IntSecure_Start(); + + /* call counter interrupt handler */ + CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */ + + /* set the disable interrupt counter back */ + IntSecure_End(); + +#endif /* #if (ALARMS_COUNT != 0) */ + + /* reset context */ + SetActualContext(actualContext); + +#if (NON_PREEMPTIVE == OSEK_DISABLE) + /* check if the actual task is preemptive */ + if ( ( CONTEXT_TASK == actualContext ) && + ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) + { + /* this shall force a call to the scheduler */ + PostIsr2_Arch(isr); + } +#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */ +} + + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ + diff --git a/src/msp430/PendSV.s b/src/msp430/PendSV.s new file mode 100644 index 00000000..4f4f4985 --- /dev/null +++ b/src/msp430/PendSV.s @@ -0,0 +1,125 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief Cortex-M PendSV Interrupt Handler, used for context switch. + ** + ** \file cortexM4/PendSV.s + ** \arch cortexM4 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + .thumb_func + .syntax unified + +/* .section .after_vectors */ + + .global PendSV_Handler + .extern Osek_OldTaskPtr_Arch,Osek_NewTaskPtr_Arch,CheckTerminatingTask_Arch + +/* Pendable Service Call, used for context-switching in all Cortex-M processors */ +PendSV_Handler: + /* disable IRQs */ + cpsid f + + /* reinicio el stack de la tarea que termino */ + push {lr} + bl CheckTerminatingTask_Arch + pop {lr} + + /* uso el sp correspondiente, segun si vengo de user o kernel */ + tst lr,4 + ite eq + mrseq r0,msp + mrsne r0,psp + + /* FPU context saving */ + tst lr,0x10 + it eq + vstmdbeq r0!,{s16-s31} + + /* Integer context saving */ + stmdb r0!,{r4-r11,lr} + + /* restituyo MSP, por si existen irqs anidadas */ + tst lr,4 + it eq + msreq msp,r0 + + /* guardo stack actual si corresponde */ + ldr r1,=Osek_OldTaskPtr_Arch + ldr r1,[r1] + cmp r1,0 + it ne + strne r0,[r1] + + /* cargo stack siguiente */ + ldr r1,=Osek_NewTaskPtr_Arch + ldr r1,[r1] + ldr r0,[r1] + + /* recupero contexto actual */ + ldmia r0!,{r4-r11,lr} + + /* recupero contexto FPU si es necesario */ + tst lr,0x10 + it eq + vldmiaeq r0!,{s16-s31} + + /* Me fijo si tengo que volver a modo privilegiado. + Actualizo el registro CONTROL */ + mrs r1,control + tst lr,4 + ittee eq + /* modo thread -> privilegiado, usar MSP */ + biceq r1,3 + msreq msp,r0 + /* modo thread -> privilegiado, usar PSP */ + orrne r1,2 + msrne psp,r0 + + msr control,r1 + + /* enable IRQs */ + cpsie f + + bx lr diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c new file mode 100644 index 00000000..cd4f6edb --- /dev/null +++ b/src/msp430/StartOs_Arch.c @@ -0,0 +1,95 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os StartOs Architecture Dependece Implementation File + ** + ** This file implements the StartOs Arch API + ** + ** \file msp430/StartOs_Arch.c + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal.h" +#include "StartOs_Arch_SysTick.h" + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ +void StartOs_Arch_Cpu(void) +{ + StartOs_Arch_SysTick(); + Enable_User_ISRs(); +} + +void StartOs_Arch(void) +{ + uint8f loopi; + + /* init every task */ + for( loopi = 0; loopi < TASKS_COUNT; loopi++) + { + InitStack_Arch(loopi); + } + + /* CPU dependent initialisation */ + StartOs_Arch_Cpu(); +} + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ + diff --git a/src/msp430/StartOs_Arch_SysTick.c b/src/msp430/StartOs_Arch_SysTick.c new file mode 100644 index 00000000..24fe778f --- /dev/null +++ b/src/msp430/StartOs_Arch_SysTick.c @@ -0,0 +1,93 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief Start the system counter + ** + ** This file includes the function to start the system counter + ** + **/ + +/** \addtogroup CIAA_Firmware CIAA Firmware + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal_Arch_Cpu.h" +#include "ciaaPlatforms.h" +#if (CPU == msp430f5529) +//#include "chip.h" +#endif + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ +void StartOs_Arch_SysTick(void) +{ + /* Activate MemFault, UsageFault and BusFault exceptions */ + SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk; + + /* Set lowest priority for SysTick and PendSV */ + NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); + + /* Activate SysTick */ + SystemCoreClockUpdate(); + SysTick_Config(SystemCoreClock/1000); + + /* Update priority set by SysTick_Config */ + NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); +} + + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ + From c59724f2ecd07b7096d41f5227e6db17a3b37e67 Mon Sep 17 00:00:00 2001 From: fbucafusco Date: Wed, 2 Mar 2016 18:40:19 -0300 Subject: [PATCH 02/42] port msp430 --- inc/msp430/Os_Arch.h | 4 ++-- inc/msp430/Os_Internal_Arch.h | 11 +++++++-- src/msp430/Os_Internal_Arch.c | 37 ++++++++++++++++++++++++------- src/msp430/PendSV.s | 12 +++++----- src/msp430/StartOs_Arch_SysTick.c | 15 ++++++++----- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index 686b702f..ca666598 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -93,13 +93,13 @@ ** ** This macro shall resume (enable) all interrupts. **/ -#define ResumeAllInterrupts_Arch() __asm volatile("cpsie i") +#define ResumeAllInterrupts_Arch() __asm volatile("eint") /** \brief Suspend All Interrupts Arch ** ** This macro shall suspend (disable) all interrupts. **/ -#define SuspendAllInterrupts_Arch() __asm volatile("cpsid i") +#define SuspendAllInterrupts_Arch() __asm volatile("dint") /** \brief Resume OS Interrupts Arch ** diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index a17c3049..428ef683 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -71,7 +71,7 @@ ** ** This define makes the Osek_Internal.h file to include the ** Osek_Internal_Arch_Cpu file which is not standard for all architectures. - ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede + ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is needed ** remove the macro and this comment. **/ #define OSEK_INLCUDE_INTERNAL_ARCH_CPU @@ -106,12 +106,19 @@ extern TaskType TerminatingTask; ** occurs, like for example an interrupt. ** **/ -#define osekpause() __asm volatile("wfi") +#define osekpause() __asm volatile("nop") //TODO revisar los low power modes + /** \brief Call to an other Task ** ** This function jmps to the indicated task. **/ + /* + NOTA FRANCO PARA PORT: + ESTA FUNCION SIMPLEMENTE CARGA EN Osek_OldTaskPtr_Arch Y Osek_NewTaskPtr_Arch + EL INDICE DE TAREAS, Y SETEA EL BIT DE PEND SVR PARA QUE CUANDO PUEDA, EL NVIC + EJECTUE EL HANDLER PendSV_Handler que se encuentra en PendSV.s + */ #define CallTask(actualtask, nexttask) \ { \ Osek_OldTaskPtr_Arch = (void*)TasksConst[(actualtask)].TaskContext; \ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index e42ae59f..701645b1 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -1,4 +1,5 @@ /* Copyright 2016, Franco Bucafusco + * All rights reserved. * * This file is part of CIAA Firmware. * @@ -32,8 +33,8 @@ /** \brief FreeOSEK Os Internal Arch Implementation File ** - ** \file cortexM4/Os_Internal_Arch.c - ** \arch cortexM4 + ** \file msp430/Os_Internal_Arch.c + ** \arch msp430 **/ /** \addtogroup FreeOSEK @@ -76,7 +77,7 @@ void ReturnHook_Arch(void) { /* Tasks shouldn't return here... */ while(1) - osekpause(); + osekpause(); } void CheckTerminatingTask_Arch(void) @@ -91,8 +92,7 @@ void CheckTerminatingTask_Arch(void) /* Task Stack Initialization */ void InitStack_Arch(uint8 TaskID) { - - uint32 * taskStack = (uint32 *)TasksConst[TaskID].StackPtr; + uint32 * taskStack = (uint32 *)TasksConst[TaskID].StackPtr; int taskStackSizeWords = TasksConst[TaskID].StackSize/4; taskStack[taskStackSizeWords-1] = 1<<24; /* xPSR.T = 1 */ @@ -101,14 +101,35 @@ void InitStack_Arch(uint8 TaskID) taskStack[taskStackSizeWords-9] = 0xFFFFFFFD; /* current LR, return using PSP */ *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 17]); - } -/* Periodic Interrupt Timer, included in all Cortex-M4 processors */ -void SysTick_Handler(void) + +/** + EL TICK SE IMPLEMENTA UTILIZANDO EL PRESCALER DEL MODULO RTC_A + DEL UC. + LA SALIDA PS0 SE USA COMO FUENTE DE TICK. SE PUEDE CONFIGURAR VALORES DE aprox 1ms (1/1024) +*/ +void RTC_A_Handler(void) { + + temporario2 = RTCIV; + if( temporario2 == RTC_RT0PSIFG ) + { + //tick handler + __no_operation(); + } + + if(temporario2 == RTC_RT1PSIFG ) + { + //swi handler + __no_operation(); + RT1PS = 0x00; + } + + /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); + /* set isr 2 context */ SetActualContext(CONTEXT_ISR2); diff --git a/src/msp430/PendSV.s b/src/msp430/PendSV.s index 4f4f4985..7be4ece2 100644 --- a/src/msp430/PendSV.s +++ b/src/msp430/PendSV.s @@ -30,10 +30,10 @@ * */ -/** \brief Cortex-M PendSV Interrupt Handler, used for context switch. +/** \brief MSP430 PendSV Interrupt Handler, used for context switch. ** - ** \file cortexM4/PendSV.s - ** \arch cortexM4 + ** \file msp430/PendSV.s + ** \arch msp430 **/ /** \addtogroup FreeOSEK @@ -48,7 +48,7 @@ * ----------------------------------------------------------- * 20160222 v0.1.0 FB initial version */ - .thumb_func + /* .thumb_func*/ .syntax unified /* .section .after_vectors */ @@ -59,7 +59,7 @@ /* Pendable Service Call, used for context-switching in all Cortex-M processors */ PendSV_Handler: /* disable IRQs */ - cpsid f + dint /* PORTED */ /* reinicio el stack de la tarea que termino */ push {lr} @@ -120,6 +120,6 @@ PendSV_Handler: msr control,r1 /* enable IRQs */ - cpsie f + eint /* PORTED */ bx lr diff --git a/src/msp430/StartOs_Arch_SysTick.c b/src/msp430/StartOs_Arch_SysTick.c index 24fe778f..ec5e8f8c 100644 --- a/src/msp430/StartOs_Arch_SysTick.c +++ b/src/msp430/StartOs_Arch_SysTick.c @@ -53,7 +53,7 @@ #include "Os_Internal_Arch_Cpu.h" #include "ciaaPlatforms.h" #if (CPU == msp430f5529) -//#include "chip.h" +#include "msp430.h" #endif /*==================[macros and definitions]=================================*/ @@ -71,18 +71,21 @@ /*==================[external functions definition]==========================*/ void StartOs_Arch_SysTick(void) { +/*notas franco + aqui tengo que inicializar el timer que vaya a disparar el tick del sistema. */ + /* Activate MemFault, UsageFault and BusFault exceptions */ - SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk; +// SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk; /* Set lowest priority for SysTick and PendSV */ - NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); + // NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); /* Activate SysTick */ - SystemCoreClockUpdate(); - SysTick_Config(SystemCoreClock/1000); + // SystemCoreClockUpdate(); + // SysTick_Config(SystemCoreClock/1000); /* Update priority set by SysTick_Config */ - NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); + // NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); } From 8266f4248c789a3e603e3fd51900521d4eab7970 Mon Sep 17 00:00:00 2001 From: fbucafusco Date: Sun, 6 Mar 2016 21:14:13 -0300 Subject: [PATCH 03/42] se avanza con el porting. Se agregan rutinas de cambio de contexto --- inc/msp430/StartOs_Arch_SystemTick.h | 66 +++++++++++++++++++ src/msp430/StartOs_Arch_SystemTick.c | 95 ++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 inc/msp430/StartOs_Arch_SystemTick.h create mode 100644 src/msp430/StartOs_Arch_SystemTick.c diff --git a/inc/msp430/StartOs_Arch_SystemTick.h b/inc/msp430/StartOs_Arch_SystemTick.h new file mode 100644 index 00000000..a5b0a18b --- /dev/null +++ b/inc/msp430/StartOs_Arch_SystemTick.h @@ -0,0 +1,66 @@ +/* Copyright 2016, Franco Bucafusco + * All rights reserved. + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + + #ifndef _STARTOS_ARCH_SYSTICK_H_ + #define _STARTOS_ARCH_SYSTICK_H_ + + /** \brief FreeOSEK Internal Architecture Dependent Header File for System + ** Tick timer. + ** + ** \file msp430/Os_Internal_Arch_SysTick.h + ** \arch msp430 + **/ + + /** \addtogroup FreeOSEK + ** @{ */ + /** \addtogroup FreeOSEK_Os + ** @{ */ + /** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + + /*==================[inclusions]=============================================*/ + + /*==================[macros]=================================================*/ + + /*==================[typedef]================================================*/ + + /*==================[external data declaration]==============================*/ + + /*==================[external functions declaration]=========================*/ + void StartOs_Arch_SystemTick(void); + + /** @} doxygen end group definition */ + /** @} doxygen end group definition */ + /** @} doxygen end group definition */ + /*==================[end of file]============================================*/ + #endif /* _STARTOS_ARCH_SYSTICK_H_ */ diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c new file mode 100644 index 00000000..563ba8b2 --- /dev/null +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -0,0 +1,95 @@ +/* Copyright 2016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief Start the system counter + ** + ** This file includes the function to start the system counter + ** + **/ + +/** \addtogroup CIAA_Firmware CIAA Firmware + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20160222 v0.1.0 FB initial version + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal_Arch_Cpu.h" +#include "ciaaPlatforms.h" +#if (CPU == msp430f5529) +#include "msp430.h" +#endif + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ +void StartOs_Arch_SystemTick(void) +{ + /*notas franco + aqui tengo que inicializar el timer que vaya a disparar el tick del sistema. */ + + /* Activate MemFault, UsageFault and BusFault exceptions */ + // SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk; + + /* Set lowest priority for SysTick and PendSV */ + // NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); + + /* Activate SysTick */ + // SystemCoreClockUpdate(); + // SysTick_Config(SystemCoreClock/1000); + + /* Update priority set by SysTick_Config */ + // NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); +} + + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ From e8e837d86c921fe42e9ce0cc7734845e495f5cab Mon Sep 17 00:00:00 2001 From: fbucafusco Date: Sun, 6 Mar 2016 21:19:37 -0300 Subject: [PATCH 04/42] se avanza con el porting. Se agregan rutinas de cambio de contexto --- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 3 +- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 11 +- inc/msp430/Os_Internal_Arch.h | 100 ++++++++----- inc/msp430/StartOs_Arch_SysTick.h | 2 - .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 9 +- src/msp430/Os_Internal_Arch.c | 133 ++++++++++-------- src/msp430/PendSV.s | 125 ---------------- src/msp430/StartOs_Arch.c | 25 ++-- src/msp430/StartOs_Arch_SysTick.c | 96 ------------- 9 files changed, 165 insertions(+), 339 deletions(-) delete mode 100644 inc/msp430/StartOs_Arch_SysTick.h delete mode 100644 src/msp430/PendSV.s delete mode 100644 src/msp430/StartOs_Arch_SysTick.c diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index 581b648a..469cb181 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -91,7 +91,7 @@ /*==================[typedef]================================================*/ /** \brief Task Context Type */ -typedef uint32 * TaskContextType; +typedef uint16 * TaskContextType; /** \brief Task Context Type */ typedef TaskContextType* TaskContextRefType; @@ -115,4 +115,3 @@ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_CFG_H_ */ - diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 50617b4e..70c15e75 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -61,7 +61,7 @@ /* THIS IS A DIRTY WORKAROUND :( ciaa/Firmware#309*/ #undef FALSE #undef TRUE -//#include "chip.h" +#include "msp430.h" #endif /*==================[macros and definitions]=================================*/ @@ -89,15 +89,15 @@ /*==================[internal functions definition]==========================*/ /* Default exception handlers */ /*__attribute__ ((section(".after_vectors"))) -void NMI_Handler(void) +void NMI_Handler(void) { - while (1) + while (1) { } } __attribute__ ((section(".after_vectors"))) -void HardFault_Handler(void) +void HardFault_Handler(void) { while (1) { } @@ -139,7 +139,7 @@ switch ($definitions["CPU"]) { case "msp430f5529": - /* Interrupt sources for msp430f5529. + /* Interrupt sources for msp430f5529. */ $intList = array ( 0 => "DMA0_DMA16", @@ -404,4 +404,3 @@ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 428ef683..64ecf397 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -49,13 +49,23 @@ /* * modification history (new versions first) * ----------------------------------------------------------- - * 20160222 v0.1.0 FB initial version + * 20160222 v0.1.0 FB initial version */ /*==================[inclusions]=============================================*/ - +#include "msp430.h" /*==================[macros]=================================================*/ + +/** \brief Default Value for Status Register + ** + ** Enable GIE in SR so that the WDT never stops when we go to user task + ** Enable SCG0 for 25MHZ CPU execution + + **/ +#define DEFAULT_SR ((uint16)0x0048) + + /** \brief Extra size reserved for each stack ** ** This macro shall be set to the amount of extra stack needed for each task @@ -106,33 +116,61 @@ extern TaskType TerminatingTask; ** occurs, like for example an interrupt. ** **/ -#define osekpause() __asm volatile("nop") //TODO revisar los low power modes +#define osekpause() asm volatile("nop") //TODO revisar los low power modes +/** \brief SAVE_CONTEXT + ** + ** This macro is called by the context switch routine. + ** + **/ +#define SAVE_CONTEXT() \ + asm volatile ( "push r4 \n\t" \ + "push r5 \n\t" \ + "push r6 \n\t" \ + "push r7 \n\t" \ + "push r8 \n\t" \ + "push r9 \n\t" \ + "push r10 \n\t" \ + "push r11 \n\t" \ + "push r12 \n\t" \ + "push r13 \n\t" \ + "push r14 \n\t" \ + "push r15 \n\t" \ + ); + +#define RESTORE_CONTEXT() \ + asm volatile ( "pop r15 \n\t" \ + "pop r14 \n\t" \ + "pop r13 \n\t" \ + "pop r12 \n\t" \ + "pop r11 \n\t" \ + "pop r10 \n\t" \ + "pop r9 \n\t" \ + "pop r8 \n\t" \ + "pop r7 \n\t" \ + "pop r6 \n\t" \ + "pop r5 \n\t" \ + "pop r4 \n\t" \ + "reti \n\t" \ + ); /** \brief Call to an other Task ** ** This function jmps to the indicated task. **/ /* - NOTA FRANCO PARA PORT: - ESTA FUNCION SIMPLEMENTE CARGA EN Osek_OldTaskPtr_Arch Y Osek_NewTaskPtr_Arch - EL INDICE DE TAREAS, Y SETEA EL BIT DE PEND SVR PARA QUE CUANDO PUEDA, EL NVIC - EJECTUE EL HANDLER PendSV_Handler que se encuentra en PendSV.s - */ -#define CallTask(actualtask, nexttask) \ -{ \ - Osek_OldTaskPtr_Arch = (void*)TasksConst[(actualtask)].TaskContext; \ - Osek_NewTaskPtr_Arch = (void*)TasksConst[(nexttask)].TaskContext; \ - __asm__ __volatile__ ( \ - /* Call PendSV */ \ - "push {r0,r1} \n\t" \ - /* Activate bit PENDSVSET in Interrupt Control State Register (ICSR) */ \ - "ldr r0,=0xE000ED04 \n\t" \ - "ldr r1,[r0] \n\t" \ - "orr r1,1<<28 \n\t" \ - "str r1,[r0] \n\t" \ - "pop {r0,r1} \n\t" \ - ); \ + this way of triggering the RTC1PSIFG wroks as follows: + 1st this portion of the RTC module is unused. + 2nd The IRQ jumps with a change from 0 to 1 + 3rd As the IE flag is set, changing all the lines from 0 to 1 + ensures the IFG flag to be set. + */ +#define CallTask(actualtask, nexttask) \ +{ \ + Osek_OldTaskPtr_Arch = (void*) TasksConst[(actualtask)].TaskContext; \ + Osek_NewTaskPtr_Arch = (void*) TasksConst[(nexttask)].TaskContext; \ + RT1PS = 0x00; /*Clear the prescaler output */ \ + RT1PS = 0xff; /*Set the prescaler output in all ones. */ \ } /** \brief Jmp to an other Task @@ -152,16 +190,9 @@ extern TaskType TerminatingTask; Osek_OldTaskPtr_Arch = (void*)0; \ } \ Osek_NewTaskPtr_Arch = (void*)TasksConst[(task)].TaskContext; \ - __asm__ __volatile__ ( \ - /* Call PendSV */ \ - "push {r0,r1} \n\t" \ - /* Activate bit PENDSVSET in Interrupt Control State Register (ICSR) */ \ - "ldr r0,=0xE000ED04 \n\t" \ - "ldr r1,[r0] \n\t" \ - "orr r1,1<<28 \n\t" \ - "str r1,[r0] \n\t" \ - "pop {r0,r1} \n\t" \ - ); \ + /* next action will trigger rtc xxIRQ*/ \ + RT1PS = 0x00; /*Clear the prescaler output */ \ + RT1PS = 0xff; /*Set the prescaler output in all ones. */ \ } /** \brief Save context */ @@ -204,7 +235,7 @@ extern TaskType TerminatingTask; ** Enable OS configured interrupts (ISR1 and ISR2). This macro ** is called only ones in StartUp.c function. **/ -#define EnableOSInterrupts() __asm volatile("cpsie i") +#define EnableOSInterrupts() __asm volatile("eint") /** \brief Enable Interruptions ** @@ -221,7 +252,7 @@ extern TaskType TerminatingTask; ** ** Disable OS configured interrupts (ISR1 and ISR2). **/ -#define DisableOSInterrupts() __asm volatile("cpsid i") +#define DisableOSInterrupts() __asm volatile("dint") /** \brief Disable Interruptions ** @@ -287,4 +318,3 @@ void InitStack_Arch(uint8 TaskID); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ - diff --git a/inc/msp430/StartOs_Arch_SysTick.h b/inc/msp430/StartOs_Arch_SysTick.h deleted file mode 100644 index e05e8c59..00000000 --- a/inc/msp430/StartOs_Arch_SysTick.h +++ /dev/null @@ -1,2 +0,0 @@ - -void StartOs_Arch_SysTick(void); diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index a09eb4b2..50fa6730 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -1,6 +1,4 @@ -/* Copyright 2014, ACSE & CADIEEL - * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ - * CADIEEL: http://www.cadieel.org.ar +/* Copyright 201, Franco Bucafusco * * This file is part of CIAA Firmware. * @@ -37,8 +35,8 @@ /** \brief FreeOSEK Internal Architecture Cpu Dependent Header File ** - ** \file cortexM4/lpc4000/Os_Internal_Arch_Cpu.h - ** \arch cortexM4/lpc4000 + ** \file cortexM4/msp430f5xx_6xx/Os_Internal_Arch_Cpu.h + ** \arch cortexM4/msp430f5xx_6xx **/ /** \addtogroup FreeOSEK @@ -54,6 +52,7 @@ * * PLEASE REMOVE THIS COMMENT *****************************************************************************/ + /***************************************************************************** * add a new version to this file, add the date, your initials and the main * changes, only main changes shall be listed here. A detailed message log diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 701645b1..33a9e0a5 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -46,7 +46,7 @@ /* * modification history (new versions first) - * ----------------------------------------------------------- + * ----------------------------------------------------------- * 20160222 v0.1.0 FB initial version for msp430 processors */ @@ -59,7 +59,6 @@ /*==================[internal functions declaration]=========================*/ void* Osek_NewTaskPtr_Arch; - void* Osek_OldTaskPtr_Arch; /*==================[internal data definition]===============================*/ @@ -75,92 +74,117 @@ TaskType WaitingTask = INVALID_TASK; void ReturnHook_Arch(void) { - /* Tasks shouldn't return here... */ - while(1) - osekpause(); + /* Tasks shouldn't return here... */ + while(1) + { + osekpause(); + } } void CheckTerminatingTask_Arch(void) { - if(TerminatingTask != INVALID_TASK) - { - InitStack_Arch(TerminatingTask); - } - TerminatingTask = INVALID_TASK; + if( TerminatingTask != INVALID_TASK ) + { + InitStack_Arch( TerminatingTask ); + } + TerminatingTask = INVALID_TASK; } /* Task Stack Initialization */ void InitStack_Arch(uint8 TaskID) { - uint32 * taskStack = (uint32 *)TasksConst[TaskID].StackPtr; - int taskStackSizeWords = TasksConst[TaskID].StackSize/4; + uint16 * taskStack = (uint16 *)TasksConst[TaskID].StackPtr; /* stack bottom */ + + int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ - taskStack[taskStackSizeWords-1] = 1<<24; /* xPSR.T = 1 */ - taskStack[taskStackSizeWords-2] = (uint32) TasksConst[TaskID].EntryPoint; /*PC*/ - taskStack[taskStackSizeWords-3] = (uint32) ReturnHook_Arch; /* stacked LR */ - taskStack[taskStackSizeWords-9] = 0xFFFFFFFD; /* current LR, return using PSP */ + taskStack[taskStackSizeWords-1] = (uint32) TasksConst[TaskID].EntryPoint; /*PC*/ + taskStack[taskStackSizeWords-3] = DEFAULT_SR; /*SP*/ - *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 17]); + /* la ubicacion, reservando 13 registro para el cambio de contexto + */ + *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 15]); } /** - EL TICK SE IMPLEMENTA UTILIZANDO EL PRESCALER DEL MODULO RTC_A + EL TICK SE IMPLEMENTA UTILIZANDO EL PRESCALER DEL MODULO RTC_A DEL UC. LA SALIDA PS0 SE USA COMO FUENTE DE TICK. SE PUEDE CONFIGURAR VALORES DE aprox 1ms (1/1024) */ void RTC_A_Handler(void) { + /* + It's not necessary to disable global irqs. + It is done automatically when the SP is cleared. + */ + unsigned char iv = RTCIV; - temporario2 = RTCIV; - if( temporario2 == RTC_RT0PSIFG ) - { - //tick handler - __no_operation(); - } - - if(temporario2 == RTC_RT1PSIFG ) - { - //swi handler - __no_operation(); - RT1PS = 0x00; - } + if( iv == RTC_RT0PSIFG ) + { + /* This handler service the periodic interrupt. + */ + /* store the calling context in a variable */ + ContextType actualContext = GetCallingContext(); - /* store the calling context in a variable */ - ContextType actualContext = GetCallingContext(); - - /* set isr 2 context */ - SetActualContext(CONTEXT_ISR2); + /* set isr 2 context */ + SetActualContext(CONTEXT_ISR2); #if (ALARMS_COUNT != 0) - /* counter increment */ - static CounterIncrementType CounterIncrement = 1; - (void)CounterIncrement; /* TODO remove me */ + /* counter increment */ + static CounterIncrementType CounterIncrement = 1; + (void)CounterIncrement; /* TODO remove me */ - /* increment the disable interrupt conter to avoid enable the interrupts */ - IntSecure_Start(); + /* increment the disable interrupt conter to avoid enable the interrupts */ + IntSecure_Start(); - /* call counter interrupt handler */ - CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */ + /* call counter interrupt handler */ + CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */ - /* set the disable interrupt counter back */ - IntSecure_End(); + /* set the disable interrupt counter back */ + IntSecure_End(); #endif /* #if (ALARMS_COUNT != 0) */ - /* reset context */ - SetActualContext(actualContext); + /* reset context */ + SetActualContext(actualContext); #if (NON_PREEMPTIVE == OSEK_DISABLE) - /* check if the actual task is preemptive */ - if ( ( CONTEXT_TASK == actualContext ) && - ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) - { - /* this shall force a call to the scheduler */ - PostIsr2_Arch(isr); - } + /* check if the actual task is preemptive */ + if ( ( CONTEXT_TASK == actualContext ) && ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) + { + /* this shall force a call to the scheduler */ + PostIsr2_Arch(isr); + } #endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */ + + return; /*return from Tick ISR */ + } + + if( iv == RTC_RT1PSIFG ) + { + //swi handler + //ver de hacerla en asm o en c. + //basicamente es la funcion del context switch. pendSV + + /* reinicio el stack de la tarea que termino */ + CheckTerminatingTask_Arch(); + + SAVE_CONTEXT(); + + /* exchange stack pointers */ + if( Osek_OldTaskPtr_Arch != NULL ) + { + // Osek_OldTaskPtr_Arch = SP; + + asm volatile ( "mov SP, Osek_OldTaskPtr_Arch \n\t" ); + } +asm volatile ( "mov Osek_NewTaskPtr_Arch, SP \n\t" ); +// SP = Osek_NewTaskPtr_Arch ; + + RESTORE_CONTEXT() + RT1PS = 0x00; + } } @@ -168,4 +192,3 @@ void RTC_A_Handler(void) /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/src/msp430/PendSV.s b/src/msp430/PendSV.s deleted file mode 100644 index 7be4ece2..00000000 --- a/src/msp430/PendSV.s +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright 2016, Franco Bucafusco - * - * This file is part of CIAA Firmware. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** \brief MSP430 PendSV Interrupt Handler, used for context switch. - ** - ** \file msp430/PendSV.s - ** \arch msp430 - **/ - -/** \addtogroup FreeOSEK - ** @{ */ -/** \addtogroup FreeOSEK_Os - ** @{ */ -/** \addtogroup FreeOSEK_Os_Internal - ** @{ */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FB initial version - */ - /* .thumb_func*/ - .syntax unified - -/* .section .after_vectors */ - - .global PendSV_Handler - .extern Osek_OldTaskPtr_Arch,Osek_NewTaskPtr_Arch,CheckTerminatingTask_Arch - -/* Pendable Service Call, used for context-switching in all Cortex-M processors */ -PendSV_Handler: - /* disable IRQs */ - dint /* PORTED */ - - /* reinicio el stack de la tarea que termino */ - push {lr} - bl CheckTerminatingTask_Arch - pop {lr} - - /* uso el sp correspondiente, segun si vengo de user o kernel */ - tst lr,4 - ite eq - mrseq r0,msp - mrsne r0,psp - - /* FPU context saving */ - tst lr,0x10 - it eq - vstmdbeq r0!,{s16-s31} - - /* Integer context saving */ - stmdb r0!,{r4-r11,lr} - - /* restituyo MSP, por si existen irqs anidadas */ - tst lr,4 - it eq - msreq msp,r0 - - /* guardo stack actual si corresponde */ - ldr r1,=Osek_OldTaskPtr_Arch - ldr r1,[r1] - cmp r1,0 - it ne - strne r0,[r1] - - /* cargo stack siguiente */ - ldr r1,=Osek_NewTaskPtr_Arch - ldr r1,[r1] - ldr r0,[r1] - - /* recupero contexto actual */ - ldmia r0!,{r4-r11,lr} - - /* recupero contexto FPU si es necesario */ - tst lr,0x10 - it eq - vldmiaeq r0!,{s16-s31} - - /* Me fijo si tengo que volver a modo privilegiado. - Actualizo el registro CONTROL */ - mrs r1,control - tst lr,4 - ittee eq - /* modo thread -> privilegiado, usar MSP */ - biceq r1,3 - msreq msp,r0 - /* modo thread -> privilegiado, usar PSP */ - orrne r1,2 - msrne psp,r0 - - msr control,r1 - - /* enable IRQs */ - eint /* PORTED */ - - bx lr diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index cd4f6edb..bdc66fbb 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -48,12 +48,12 @@ /* * modification history (new versions first) * ----------------------------------------------------------- - * 20160222 v0.1.0 FB initial version + * 20160222 v0.1.0 FB initial version */ /*==================[inclusions]=============================================*/ #include "Os_Internal.h" -#include "StartOs_Arch_SysTick.h" +#include "StartOs_Arch_SystemTick.h" /*==================[macros and definitions]=================================*/ @@ -70,26 +70,25 @@ /*==================[external functions definition]==========================*/ void StartOs_Arch_Cpu(void) { - StartOs_Arch_SysTick(); - Enable_User_ISRs(); + StartOs_Arch_Tick(); + Enable_User_ISRs(); } void StartOs_Arch(void) { - uint8f loopi; + uint8f loopi; - /* init every task */ - for( loopi = 0; loopi < TASKS_COUNT; loopi++) - { - InitStack_Arch(loopi); - } + /* init every task */ + for( loopi = 0; loopi < TASKS_COUNT; loopi++) + { + InitStack_Arch(loopi); + } - /* CPU dependent initialisation */ - StartOs_Arch_Cpu(); + /* CPU dependent initialisation */ + StartOs_Arch_Cpu(); } /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/src/msp430/StartOs_Arch_SysTick.c b/src/msp430/StartOs_Arch_SysTick.c deleted file mode 100644 index ec5e8f8c..00000000 --- a/src/msp430/StartOs_Arch_SysTick.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2016, Franco Bucafusco - * - * This file is part of CIAA Firmware. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** \brief Start the system counter - ** - ** This file includes the function to start the system counter - ** - **/ - -/** \addtogroup CIAA_Firmware CIAA Firmware - ** @{ */ -/** \addtogroup FreeOSEK_Os - ** @{ */ -/** \addtogroup FreeOSEK_Os_Internal - ** @{ */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FB initial version - */ - -/*==================[inclusions]=============================================*/ -#include "Os_Internal_Arch_Cpu.h" -#include "ciaaPlatforms.h" -#if (CPU == msp430f5529) -#include "msp430.h" -#endif - -/*==================[macros and definitions]=================================*/ - -/*==================[internal data declaration]==============================*/ - -/*==================[internal functions declaration]=========================*/ - -/*==================[internal data definition]===============================*/ - -/*==================[external data definition]===============================*/ - -/*==================[internal functions definition]==========================*/ - -/*==================[external functions definition]==========================*/ -void StartOs_Arch_SysTick(void) -{ -/*notas franco - aqui tengo que inicializar el timer que vaya a disparar el tick del sistema. */ - - /* Activate MemFault, UsageFault and BusFault exceptions */ -// SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk; - - /* Set lowest priority for SysTick and PendSV */ - // NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); - - /* Activate SysTick */ - // SystemCoreClockUpdate(); - // SysTick_Config(SystemCoreClock/1000); - - /* Update priority set by SysTick_Config */ - // NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); -} - - -/** @} doxygen end group definition */ -/** @} doxygen end group definition */ -/** @} doxygen end group definition */ -/*==================[end of file]============================================*/ - From 279e8a2a722f4c1ebbb6dc51759d18e1a3d0985d Mon Sep 17 00:00:00 2001 From: fbucafusco Date: Sat, 2 Apr 2016 21:49:43 -0300 Subject: [PATCH 05/42] se avanza con la definicion de los PHP para el make generate. La definicion de ISR(x) en os.h es condicional --- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 324 +++++------------- .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 15 +- inc/os.h | 3 +- src/msp430/StartOs_Arch.c | 6 +- 4 files changed, 108 insertions(+), 240 deletions(-) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 70c15e75..37ae01bb 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -70,240 +70,83 @@ /*==================[internal functions declaration]=========================*/ -/*==================[internal data definition]===============================*/ - -/*==================[external data definition]===============================*/ -#if (CPU == msp430f5529) - /* Reset_Handler is defined in startup_MK60F15.S_CPP */ -//COMENTADO BUCK void Reset_Handler( void ); - -//COMENTADO BUCK extern uint32_t __StackTop; -#else -#error Not supported CPU -#endif - -/** \brief Handlers used by OSEK */ -//extern void SysTick_Handler(void); -//extern void PendSV_Handler(void); - -/*==================[internal functions definition]==========================*/ -/* Default exception handlers */ -/*__attribute__ ((section(".after_vectors"))) -void NMI_Handler(void) -{ - while (1) +__attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +OSEK_ISR_UNMI_VECTOR() { - } + while (1) + { + } } - -__attribute__ ((section(".after_vectors"))) -void HardFault_Handler(void) +__attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +OSEK_ISR_SYSNMI_VECTOR() { - while (1) { - } -} - -__attribute__ ((section(".after_vectors"))) -void MemManage_Handler(void) { - while (1) { - } -} - -__attribute__ ((section(".after_vectors"))) -void BusFault_Handler(void) { - while (1) { - } -} - -__attribute__ ((section(".after_vectors"))) -void UsageFault_Handler(void) { - while (1) { - } -} - -__attribute__ ((section(".after_vectors"))) -void SVC_Handler(void) { - while (1) { - } + while (1) + { + } } -__attribute__ ((section(".after_vectors"))) -void DebugMon_Handler(void) { - while (1) { - } -} -*/ +/*==================[internal data definition]===============================*/ -/*==================[external functions definition]==========================*/ +/*==================[external data definition]===============================*/ "DMA0_DMA16", - 1 => "DMA1_DMA17", - 2 => "DMA2_DMA18", - 3 => "DMA3_DMA19", - 4 => "DMA4_DMA20", - 5 => "DMA5_DMA21", - 6 => "DMA6_DMA22", - 7 => "DMA7_DMA23", - 8 => "DMA8_DMA24", - 9 => "DMA9_DMA25", - 10 => "DMA10_DMA26", - 11 => "DMA11_DMA27", - 12 => "DMA12_DMA28", - 13 => "DMA13_DMA29", - 14 => "DMA14_DMA30", - 15 => "DMA15_DMA31", - 16 => "DMA_ERR", - 17 => "MCM", - 18 => "FTFE", - 19 => "Read_Collision", - 20 => "LVD_LVW", - 21 => "LLW", - 22 => "WDG", - 23 => "RNG", - 24 => "I2C0", - 25 => "I2C1", - 26 => "SPI0", - 27 => "SPI1", - 28 => "SPI2", - 29 => "CAN0_READ", - 30 => "CAN0_BOFF", - 31 => "CAN0_ERR", - 32 => "CAN0_TXW", - 33 => "CAN0_RXW", - 34 => "CAN0_WAKEUP", - 35 => "I2S0_TX", - 36 => "I2S0_RR", - 37 => "CAN1_READ", - 38 => "CAN1_BOFF", - 39 => "CAN1_EERROR", - 40 => "CAN1_TXW", - 41 => "CAN1_RXW", - 42 => "CAN1_WAKEUP", - 43 => "RES59", - 44 => "UART0_LON", - 45 => "UART0", - 46 => "UART0_ERR", - 47 => "UART1", - 48 => "UART1_ERR", - 49 => "UART2", - 50 => "UART2_ERR", - 51 => "UART3", - 52 => "UART3_ERR", - 53 => "UART4", - 54 => "UART4_ERR", - 55 => "UART5", - 56 => "UART5_ERR", - 57 => "ADC0", - 58 => "ADC1", - 59 => "CMP0", - 60 => "CMP1", - 61 => "CMP2", - 62 => "FTM0", - 63 => "FTM1", - 64 => "FTM2", - 65 => "CMT", - 66 => "RTC", - 67 => "RTC_SEC", - 68 => "PIT0", - 69 => "PIT1", - 70 => "PIT2", - 71 => "PIT3", - 72 => "PDB0", - 73 => "USB0", - 74 => "USBDCD", - 75 => "ENET_1588_Timer", - 76 => "ENET_TX", - 77 => "ENET_RX", - 78 => "ENET_ERR", - 79 => "RES95", - 80 => "SDHC", - 81 => "DAC0", - 82 => "DAC1", - 83 => "TSI0", - 84 => "MCG", - 85 => "LPTimer", - 86 => "RES102", - 87 => "PORTA", - 88 => "PORTB", - 89 => "PORTC", - 90 => "PORTD", - 91 => "PORTE", - 92 => "PORTF", - 93 => "RES109", - 94 => "SWI", - 95 => "NFC", - 96 => "USBHS", - 97 => "RES113", - 98 => "CMP3", - 99 => "RES115", - 100 => "RES116", - 101 => "FTM3", - 102 => "ADC2", - 103 => "ADC3", - 104 => "I2S1_TX", - 105 => "I2S1_RX", + 0 => "RTC", + 1 => "PORT2", + 2 => "TIMER2_A1", + 3 => "TIMER2_A0", + 4 => "USCI_B1", + 5 => "USCI_A1", + 6 => "PORT1", + 7 => "TIMER1_A1", + 8 => "TIMER1_A0", + 9 => "DMA", + 10 => "USB_UBM", + 11 => "TIMER0_A1", + 12 => "TIMER0_A0", + 13 => "ADC12", + 14 => "USCI_B0", + 15 => "USCI_A0", + 16 => "WDT", + 17 => "TIMER0_B1", + 18 => "TIMER0_B0", + 19 => "COMP_B", + 20 => "UNMI", + 21 => "SYSNMI", + 22 => "RESET", ); break; default: - $this->log->error("the CPU " . $definitions["CPU"] . " is not supported."); + error("the CPU " . $definitions["CPU"] . " is not supported."); break; } $MAX_INT_COUNT = max(array_keys($intList))+1; -if ($definitions["CPU"] == "msp430f5529") : ?> -__attribute__ ((section(".isr_vector"))) -void (* const g_pfnVectors[])(void) = { - /* System ISRs */ - &__StackTop, /* The initial stack pointer */ - Reset_Handler, /* The reset handler */ - NMI_Handler, /* The NMI handler */ - HardFault_Handler, /* The hard fault handler */ - MemManage_Handler, /* The MPU fault handler */ - BusFault_Handler, /* The bus fault handler */ - UsageFault_Handler, /* The usage fault handler */ - 0, /* Reserved */ - 0, /* Reserved */ - 0, /* Reserved */ - 0, /* Reserved */ - SVC_Handler, /* SVCall handler */ - DebugMon_Handler, /* Debug monitor handler */ - 0, /* Reserved */ - PendSV_Handler, /* The PendSV handler */ - SysTick_Handler, /* The SysTick handler */ - -/** \brief LPC4337 Interrupt vector */ -__attribute__ ((section(".isr_vector"))) -void (* const g_pfnVectors[])(void) = { - /* System ISRs */ - &_vStackTop, /* The initial stack pointer */ - ResetISR, /* The reset handler */ - NMI_Handler, /* The NMI handler */ - HardFault_Handler, /* The hard fault handler */ - MemManage_Handler, /* The MPU fault handler */ - BusFault_Handler, /* The bus fault handler */ - UsageFault_Handler, /* The usage fault handler */ - 0, /* Reserved */ - 0, /* Reserved */ - 0, /* Reserved */ - 0, /* Reserved */ - SVC_Handler, /* SVCall handler */ - DebugMon_Handler, /* Debug monitor handler */ - 0, /* Reserved */ - PendSV_Handler, /* The PendSV handler */ - SysTick_Handler, /* The SysTick handler */ -log->error("Not supported CPU: " . $definitions["CPU"]); - endif; +#if (CPU == msp430f5529) + +#else +#error Not supported CPU +#endif + +/** \brief Handlers used by OSEK */ + + +/*==================[internal functions definition]==========================*/ +/* Default exception handlers */ ?> - /*** User Interruptions ***/ + + +/*==================[external functions definition]==========================*/ + + /*** Non Used Interrupt handlers ***/ getValue("/OSEK/" . $int,"CATEGORY"); $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); if($intList[$i] == $source) { - if ($intcat == 2) - { - print " OSEK_ISR2_$int, /* 0x".dechex($i+16)." 0x".str_pad(strtoupper(dechex(($i+16)*4)), 8, "0", STR_PAD_LEFT)." ISR for " . $intList[$i] . " (IRQ $i) Category 2 */\n"; + if ($intcat == 2) + { $src_found = 1; - } elseif ($intcat == 1) - { - print " OSEK_ISR_$int, /* 0x".dechex($i+16)." 0x".str_pad(strtoupper(dechex(($i+16)*4)), 8, "0", STR_PAD_LEFT)." ISR for " . $intList[$i] . " (IRQ $i) Category 1 */\n"; + } elseif ($intcat == 1) + { $src_found = 1; - } else - { - $this->log->error("Interrupt $int type $inttype has an invalid category $intcat"); - } + } + else + { + $this->log->error("Interrupt $int type $inttype has an invalid category $intcat"); + } } } + + if( $intList[$i]=="RTC" || $intList[$i]=="RESET" || $intList[$i]=="UNMI" || $intList[$i]=="SYSNMI" ) + { + /* + This part forces irq_handlers not to be defined here. + RTC: Use for OSEK periodic interrupt + RESET: defined by gcc + UNMI: defined in this file + SYSNMI: defined in this file + */ + $src_found = 1; + } + if($src_found == 0) { - print " OSEK_ISR_NoHandler, /* 0x".dechex($i+16)." 0x".str_pad(strtoupper(dechex(($i+16)*4)), 8, "0", STR_PAD_LEFT)." - No Handler set for ISR " . $intList[$i] . " (IRQ $i) */\n"; + print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; + print "OSEK_ISR_$intList[$i]_VECTOR()\n"; + print "{\n"; + print "}\n"; } } ?> -}; /** \brief Interrupt enabling and priority setting function */ void Enable_User_ISRs(void) @@ -347,15 +209,15 @@ getValue("/OSEK/" . $int,"INTERRUPT"); + $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); - + print " source: $source int: $int"; print " /* Enabling IRQ $source with priority $prio */\n"; - print " NVIC_EnableIRQ(" . array_search($source, $intList) . ");\n"; - print " NVIC_SetPriority(" . array_search($source, $intList) . ", $prio);\n\n"; + print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; } ?> } @@ -374,7 +236,7 @@ if($cat == 2) { print " /* Enabling IRQ $source */\n"; - print " NVIC_EnableIRQ(" . array_search($source, $intList) . ");\n"; + print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; } } ?> @@ -394,7 +256,7 @@ if($cat == 2) { print " /* Disabling IRQ $source */\n"; - print " NVIC_DisableIRQ(" . array_search($source, $intList) . ");\n"; + print " MSP430_DisableIRQ(" . array_search($source, $intList) . ");\n"; } } ?> diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index 50fa6730..41664b43 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -85,12 +85,14 @@ *****************************************************************************/ /*==================[macros]=================================================*/ -/***************************************************************************** - * use this section to defined any necessary macros for a specific cpu of - * your family. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ + + /** \brief ISR macro definition + ** + ** This macro shall be used to start the definition of all ISR category 1 or 2. + ** + ** \param[in] name name of the ISR category 1 or 2. + **/ + #define ISR(name) __attribute__( (__interrupt__(name))) void OSEK_ISR_ ## name (void) /*==================[typedef]================================================*/ /***************************************************************************** @@ -116,4 +118,3 @@ void StartOs_Arch_Cpu(void); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_CPU_H_ */ - diff --git a/inc/os.h b/inc/os.h index 209f39bf..cb5de2cc 100644 --- a/inc/os.h +++ b/inc/os.h @@ -65,6 +65,7 @@ **/ #define TASK(name) void OSEK_TASK_ ## name (void) +#ifndef ISR /** \brief ISR macro definition ** ** This macro shall be used to start the definition of all ISR category 1 or 2. @@ -72,6 +73,7 @@ ** \param[in] name name of the ISR category 1 or 2. **/ #define ISR(name) void OSEK_ISR_ ## name (void) +#endif /** \brief ALARMCALLBACK macro definition **/ @@ -666,4 +668,3 @@ extern StatusType CancelAlarm(AlarmType AlarmID); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_H_ */ - diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index bdc66fbb..83cb6289 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -68,12 +68,16 @@ /*==================[internal functions definition]==========================*/ /*==================[external functions definition]==========================*/ + + void StartOs_Arch_Cpu(void) { - StartOs_Arch_Tick(); + StartOs_Arch_SystemTick(); Enable_User_ISRs(); } +/** + */ void StartOs_Arch(void) { uint8f loopi; From afcff099f5b4671268bc1ab2ab8064a4893e477d Mon Sep 17 00:00:00 2001 From: fbucafusco Date: Tue, 19 Apr 2016 19:49:30 -0300 Subject: [PATCH 06/42] 1ra version funcional para msp430 --- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 17 ++- inc/msp430/Os_Arch.h | 5 +- inc/msp430/Os_Internal_Arch.h | 36 ++++-- inc/msp430/StartOs_Arch_SystemTick.h | 1 + .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 14 +-- inc/os.h | 6 +- src/msp430/Os_Internal_Arch.c | 113 ++++++++++-------- src/msp430/StartOs_Arch.c | 2 +- src/msp430/StartOs_Arch_SystemTick.c | 89 ++++++++++++-- 9 files changed, 186 insertions(+), 97 deletions(-) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 37ae01bb..d7102d92 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -71,14 +71,14 @@ /*==================[internal functions declaration]=========================*/ __attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ -OSEK_ISR_UNMI_VECTOR() +void OSEK_ISR_UNMI_VECTOR(void) { while (1) { } } __attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ -OSEK_ISR_SYSNMI_VECTOR() +void OSEK_ISR_SYSNMI_VECTOR(void) { while (1) { @@ -181,14 +181,14 @@ } } - if( $intList[$i]=="RTC" || $intList[$i]=="RESET" || $intList[$i]=="UNMI" || $intList[$i]=="SYSNMI" ) + if( $intList[$i]=="TIMER2_A1" || $intList[$i]=="TIMER2_A0" || $intList[$i]=="RESET" || $intList[$i]=="UNMI" || $intList[$i]=="SYSNMI" ) { /* This part forces irq_handlers not to be defined here. - RTC: Use for OSEK periodic interrupt - RESET: defined by gcc - UNMI: defined in this file - SYSNMI: defined in this file + TIMER2_XX: Use for OSEK periodic interrupt + RESET: defined by gcc @ compile time. + UNMI: defined in this file + SYSNMI: defined in this file */ $src_found = 1; } @@ -196,7 +196,7 @@ if($src_found == 0) { print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; - print "OSEK_ISR_$intList[$i]_VECTOR()\n"; + print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; print "{\n"; print "}\n"; } @@ -215,7 +215,6 @@ $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); - print " source: $source int: $int"; print " /* Enabling IRQ $source with priority $prio */\n"; print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; } diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index ca666598..a226f1d0 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -98,8 +98,11 @@ /** \brief Suspend All Interrupts Arch ** ** This macro shall suspend (disable) all interrupts. + ** NOTE: the nop operation after the dint instruction was inserted + ** to workarround the hw bug cpu39 describer in slaz314h.pdf **/ -#define SuspendAllInterrupts_Arch() __asm volatile("dint") +#define SuspendAllInterrupts_Arch() __asm volatile("dint"); \ + __asm volatile("nop"); /** \brief Resume OS Interrupts Arch ** diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 64ecf397..b481fe46 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -54,6 +54,7 @@ /*==================[inclusions]=============================================*/ #include "msp430.h" +#include "driverlib.h" /*==================[macros]=================================================*/ @@ -61,7 +62,6 @@ ** ** Enable GIE in SR so that the WDT never stops when we go to user task ** Enable SCG0 for 25MHZ CPU execution - **/ #define DEFAULT_SR ((uint16)0x0048) @@ -86,8 +86,10 @@ **/ #define OSEK_INLCUDE_INTERNAL_ARCH_CPU -extern void * Osek_OldTaskPtr_Arch; -extern void * Osek_NewTaskPtr_Arch; + +extern void *Osek_OldTaskPtr_Arch; +extern void *Osek_NewTaskPtr_Arch; + extern TaskType TerminatingTask; /** \brief Interrupt Secure Start Macro @@ -154,6 +156,8 @@ extern TaskType TerminatingTask; "reti \n\t" \ ); +#define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); + /** \brief Call to an other Task ** ** This function jmps to the indicated task. @@ -167,10 +171,10 @@ extern TaskType TerminatingTask; */ #define CallTask(actualtask, nexttask) \ { \ - Osek_OldTaskPtr_Arch = (void*) TasksConst[(actualtask)].TaskContext; \ - Osek_NewTaskPtr_Arch = (void*) TasksConst[(nexttask)].TaskContext; \ - RT1PS = 0x00; /*Clear the prescaler output */ \ - RT1PS = 0xff; /*Set the prescaler output in all ones. */ \ + Osek_OldTaskPtr_Arch = (void*) *(TasksConst[(actualtask)].TaskContext); \ + Osek_NewTaskPtr_Arch = (void*) *(TasksConst[(nexttask)].TaskContext); \ + /* next action will trigger assigned IRQ for the SWI */ \ + HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ } /** \brief Jmp to an other Task @@ -182,19 +186,20 @@ extern TaskType TerminatingTask; extern TaskType WaitingTask; \ if(WaitingTask != INVALID_TASK) \ { \ - Osek_OldTaskPtr_Arch = (void*)TasksConst[WaitingTask].TaskContext; \ + Osek_OldTaskPtr_Arch = (void*) *(TasksConst[WaitingTask].TaskContext);\ WaitingTask = INVALID_TASK; \ } \ else \ { \ Osek_OldTaskPtr_Arch = (void*)0; \ } \ - Osek_NewTaskPtr_Arch = (void*)TasksConst[(task)].TaskContext; \ - /* next action will trigger rtc xxIRQ*/ \ - RT1PS = 0x00; /*Clear the prescaler output */ \ - RT1PS = 0xff; /*Set the prescaler output in all ones. */ \ + Osek_NewTaskPtr_Arch = (void*) *(TasksConst[(task)].TaskContext); \ + /* next action will trigger assigned IRQ for the SWI */ \ + HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ } + + /** \brief Save context */ #define SaveContext(task) \ { \ @@ -251,8 +256,13 @@ extern TaskType TerminatingTask; /** \brief Disable OS Interruptions ** ** Disable OS configured interrupts (ISR1 and ISR2). + ** NOTE: the nop operation after the dint instruction was inserted + ** to workarround the hw bug cpu39 describer in slaz314h.pdf **/ -#define DisableOSInterrupts() __asm volatile("dint") +#define DisableOSInterrupts() __asm volatile("dint"); \ + __asm volatile("nop"); + + /** \brief Disable Interruptions ** diff --git a/inc/msp430/StartOs_Arch_SystemTick.h b/inc/msp430/StartOs_Arch_SystemTick.h index a5b0a18b..3ef5ae5a 100644 --- a/inc/msp430/StartOs_Arch_SystemTick.h +++ b/inc/msp430/StartOs_Arch_SystemTick.h @@ -57,6 +57,7 @@ /*==================[external data declaration]==============================*/ /*==================[external functions declaration]=========================*/ + void StartOs_Arch_System(); void StartOs_Arch_SystemTick(void); /** @} doxygen end group definition */ diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index 41664b43..9be3882a 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -35,8 +35,8 @@ /** \brief FreeOSEK Internal Architecture Cpu Dependent Header File ** - ** \file cortexM4/msp430f5xx_6xx/Os_Internal_Arch_Cpu.h - ** \arch cortexM4/msp430f5xx_6xx + ** \file msp430/msp430f5xx_6xx/Os_Internal_Arch_Cpu.h + ** \arch msp430/msp430f5xx_6xx **/ /** \addtogroup FreeOSEK @@ -68,13 +68,9 @@ */ /*==================[cpu macros]=============================================*/ -/***************************************************************************** - * Please define here all cpu macros available for this cputype. arm7 and - * cpy family lpc2xxx is given as example, please remove all arm7 and lpc2xxx - * related macros - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ +#define WORKING_FREQUENCY_MHZ 14.7456// 7.3728 // // en MHZ +#define REF_FREQUENCY_HZ 32768 // en Hz +#define TIC_PERIOD 5 // EN ms /*==================[inclusions]=============================================*/ /***************************************************************************** diff --git a/inc/os.h b/inc/os.h index cb5de2cc..f46d9617 100644 --- a/inc/os.h +++ b/inc/os.h @@ -65,15 +65,17 @@ **/ #define TASK(name) void OSEK_TASK_ ## name (void) -#ifndef ISR +/* +#ifndef ISR*/ /** \brief ISR macro definition ** ** This macro shall be used to start the definition of all ISR category 1 or 2. ** ** \param[in] name name of the ISR category 1 or 2. **/ + /* #define ISR(name) void OSEK_ISR_ ## name (void) -#endif +#endif*/ /** \brief ALARMCALLBACK macro definition **/ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 33a9e0a5..6fb80f50 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -58,8 +58,8 @@ /*==================[internal data declaration]==============================*/ /*==================[internal functions declaration]=========================*/ -void* Osek_NewTaskPtr_Arch; -void* Osek_OldTaskPtr_Arch; +void * Osek_NewTaskPtr_Arch; +void * Osek_OldTaskPtr_Arch; /*==================[internal data definition]===============================*/ @@ -98,74 +98,87 @@ void InitStack_Arch(uint8 TaskID) int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ taskStack[taskStackSizeWords-1] = (uint32) TasksConst[TaskID].EntryPoint; /*PC*/ - taskStack[taskStackSizeWords-3] = DEFAULT_SR; /*SP*/ + taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ /* la ubicacion, reservando 13 registro para el cambio de contexto */ - *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 15]); + *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 14]); } /** - EL TICK SE IMPLEMENTA UTILIZANDO EL PRESCALER DEL MODULO RTC_A - DEL UC. - LA SALIDA PS0 SE USA COMO FUENTE DE TICK. SE PUEDE CONFIGURAR VALORES DE aprox 1ms (1/1024) + OSEK periodic interrupt is implemented using TimerA_2 timer module. */ -void RTC_A_Handler(void) +__attribute__( (__interrupt__(TIMER2_A0_VECTOR),naked)) +void OSEK_ISR_TIMER2_A0_VECTOR(void) { /* It's not necessary to disable global irqs. It is done automatically when the SP is cleared. */ - unsigned char iv = RTCIV; - - if( iv == RTC_RT0PSIFG ) - { - /* This handler service the periodic interrupt. - */ + /* This handler service the periodic interrupt. + */ + /* Clear the IRQ flag*/ + Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_0); - /* store the calling context in a variable */ - ContextType actualContext = GetCallingContext(); + /* store the calling context in a variable */ + ContextType actualContext = GetCallingContext(); - /* set isr 2 context */ - SetActualContext(CONTEXT_ISR2); + /* set isr 2 context */ + SetActualContext(CONTEXT_ISR2); #if (ALARMS_COUNT != 0) - /* counter increment */ - static CounterIncrementType CounterIncrement = 1; - (void)CounterIncrement; /* TODO remove me */ + /* counter increment */ + static CounterIncrementType CounterIncrement = 1; + (void)CounterIncrement; /* TODO remove me */ - /* increment the disable interrupt conter to avoid enable the interrupts */ - IntSecure_Start(); + /* increment the disable interrupt conter to avoid enable the interrupts */ + IntSecure_Start(); - /* call counter interrupt handler */ - CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */ - - /* set the disable interrupt counter back */ - IntSecure_End(); + /* call counter interrupt handler */ + CounterIncrement = IncrementCounter(0, TIC_PERIOD ); + /* set the disable interrupt counter back */ + IntSecure_End(); #endif /* #if (ALARMS_COUNT != 0) */ - /* reset context */ - SetActualContext(actualContext); + /* reset context */ + SetActualContext(actualContext); #if (NON_PREEMPTIVE == OSEK_DISABLE) - /* check if the actual task is preemptive */ - if ( ( CONTEXT_TASK == actualContext ) && ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) - { - /* this shall force a call to the scheduler */ - PostIsr2_Arch(isr); - } + /* check if the actual task is preemptive */ + if ( ( CONTEXT_TASK == actualContext ) && ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) + { + /* this shall force a call to the scheduler */ + PostIsr2_Arch(isr); + } #endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */ - return; /*return from Tick ISR */ - } + RETURN_FROM_NAKED_ISR(); /*return from Tick ISR */ +} - if( iv == RTC_RT1PSIFG ) +/* +otros CCIFG (1 2 o 3) +*/ +__attribute__( (__interrupt__(TIMER2_A1_VECTOR),naked)) +void OSEK_ISR_TIMER2_A1_VECTOR(void) +{ + /* + It's not necessary to disable global irqs. + It is done automatically when the SP is cleared. + */ + + //swi handler + //ver de hacerla en asm o en c. + //basicamente es la funcion del context switch. similar al pendSV + + /* Clear the IRQ flag*/ //VERIFICAR TAIV PORQUE LA IRQ PUEDE HABER SURGIDO DE OTRO CCRX + unsigned short local_taiv = TA2IV; + + if( local_taiv & TA2IV_TACCR1) // { - //swi handler - //ver de hacerla en asm o en c. - //basicamente es la funcion del context switch. pendSV + Timer_A_disableCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1 ); + Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1); /* reinicio el stack de la tarea que termino */ CheckTerminatingTask_Arch(); @@ -173,21 +186,21 @@ void RTC_A_Handler(void) SAVE_CONTEXT(); /* exchange stack pointers */ - if( Osek_OldTaskPtr_Arch != NULL ) - { - // Osek_OldTaskPtr_Arch = SP; + if( Osek_OldTaskPtr_Arch != NULL ) + { + asm volatile ( "mov SP, Osek_OldTaskPtr_Arch \n\t" ); + } - asm volatile ( "mov SP, Osek_OldTaskPtr_Arch \n\t" ); - } -asm volatile ( "mov Osek_NewTaskPtr_Arch, SP \n\t" ); -// SP = Osek_NewTaskPtr_Arch ; + asm volatile ( "mov Osek_NewTaskPtr_Arch, SP \n\t" ); RESTORE_CONTEXT() - RT1PS = 0x00; } + + RETURN_FROM_NAKED_ISR(); } + /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index 83cb6289..8af263be 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -69,9 +69,9 @@ /*==================[external functions definition]==========================*/ - void StartOs_Arch_Cpu(void) { + StartOs_Arch_System(); //TODO: this should be placed in other file. For cortex processors is placed within the reset vector handler. StartOs_Arch_SystemTick(); Enable_User_ISRs(); } diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c index 563ba8b2..a4e66372 100644 --- a/src/msp430/StartOs_Arch_SystemTick.c +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -52,40 +52,105 @@ /*==================[inclusions]=============================================*/ #include "Os_Internal_Arch_Cpu.h" #include "ciaaPlatforms.h" + #if (CPU == msp430f5529) #include "msp430.h" +#include "driverlib.h" #endif /*==================[macros and definitions]=================================*/ +#define SVMH_FULL_PERF() PMMCTL0_H = 0xA5; SVSMLCTL |= (SVMLFP); PMMCTL0_H = 0x00; + + + +#define WORKING_FREQUENCY_KHZ (unsigned long)(WORKING_FREQUENCY_MHZ*1e3) // en KHZ +#define WORKING_FREQUENCY_HZ (unsigned long)(WORKING_FREQUENCY_MHZ*1e6) // en Hz + +#define XT1_XT2_PORT_DIR P5DIR +#define XT1_XT2_PORT_OUT P5OUT +#define XT1_XT2_PORT_SEL P5SEL +#define XT1_ENABLE (BIT4 + BIT5) +#define XT2_ENABLE (BIT2 + BIT3) + +#define VALOR_MS(A) (unsigned short)( ( ( ( unsigned long )A*REF_FREQUENCY_HZ)/1000 ) ) + /*==================[internal data declaration]==============================*/ /*==================[internal functions declaration]=========================*/ /*==================[internal data definition]===============================*/ +const Timer_A_initUpModeParam tick_timer_init_params = +{ + .clockSource = TIMER_A_CLOCKSOURCE_ACLK, + .clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1, + .timerPeriod = VALOR_MS( TIC_PERIOD ) , + .timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE, + .captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE, + .timerClear = TIMER_A_SKIP_CLEAR, + .startTimer = true, +}; + +const Timer_A_initCaptureModeParam swi_init_params = +{ + .captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1, + .captureMode = TIMER_A_CAPTUREMODE_NO_CAPTURE, //FUNCIONA? SI NO, PROBAR CON TIMER_A_CAPTUREMODE_RISING_EDGE + .captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_GND, + .synchronizeCaptureSource = TIMER_A_CAPTURE_ASYNCHRONOUS, + .captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE, + .captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE, /* this is set for completion of the structure, but no needed*/ +}; /*==================[external data definition]===============================*/ /*==================[internal functions definition]==========================*/ /*==================[external functions definition]==========================*/ -void StartOs_Arch_SystemTick(void) + +/* +Initializes the main system clock +ACLK = REF_FREQUENCY_HZ +MCLK = SMCLK = 14.7456Mhz +*/ +void StartOs_Arch_System() { - /*notas franco - aqui tengo que inicializar el timer que vaya a disparar el tick del sistema. */ + UCS_turnOffXT1(); - /* Activate MemFault, UsageFault and BusFault exceptions */ - // SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk; + XT1_XT2_PORT_SEL |= XT1_ENABLE + XT2_ENABLE; // Setup XT1 and XT2 - /* Set lowest priority for SysTick and PendSV */ - // NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); + PMM_setVCore( 3 ); // Set Vcore to accomodate for max. allowed system speed + + UCS_turnOnLFXT1( UCS_XT1_DRIVE_0 , UCS_XCAP_1 ); // Use 32.768kHz XTAL as reference + + UCS_initClockSignal( UCS_FLLREF , UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 ); + + UCS_initFLLSettle( WORKING_FREQUENCY_KHZ, ( WORKING_FREQUENCY_HZ/REF_FREQUENCY_HZ ) ); + + /* + ESTA LINEAS SON PARA ESTABLECER LA CONFIGURACION DEL MODULO PMM PARA QUE ESTE EN FULL PERFORMACN Y FAST WAKE UP MODE. + SI NO ESTA CONFIGURADO ASI, AL DESPERTARSE DE UN LPM, EL ARRANQUE DEL DCO NO ES AGIL Y PARA EL CASO DE LA RECEPCION DE LA + UART Y SE PIERDE EL PRIMER uint8_t DE DATOS. + ESTO ES, PORQUE EL TIEMPO DE ENCENDIDO ES MAYOR QUE UN BIT DE LA COMUNICACION. + */ + PMM_enableSvsLInLPMFastWake(); // SVSL_ENABLED_IN_LPM_FAST_WAKE(); + PMM_enableSvsHInLPMFullPerf(); // SVSH_ENABLED_IN_LPM_FULL_PERF() ; + + PMM_optimizeSvsLInLPMFastWake(); // SVSL_OPTIMIZED_IN_LPM_FAST_WAKE(); + PMM_optimizeSvsHInLPMFullPerf(); // SVSH_OPTIMIZED_IN_LPM_FULL_PERF(); + + SVMH_FULL_PERF(); + + PMM_disableSvsL();// DISABLE_SVSL() ; +} + +void StartOs_Arch_SystemTick(void) +{ + /* Activate SystemTick */ + Timer_A_initUpMode( TIMER_A2_BASE , (Timer_A_initUpModeParam*) &tick_timer_init_params); - /* Activate SysTick */ - // SystemCoreClockUpdate(); - // SysTick_Config(SystemCoreClock/1000); + /* Configuration of the channel 1 to simulate the PendSV IRQ from cortex arquitecture.*/ + Timer_A_initCaptureMode( TIMER_A2_BASE ,(Timer_A_initCaptureModeParam*) &swi_init_params ); - /* Update priority set by SysTick_Config */ - // NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); } From dfc300e176c554f6d674b26d14e13c6cd65eaf4a Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 8 May 2016 22:23:06 -0300 Subject: [PATCH 07/42] se comienza a portar los tests de conformidad --- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 42 +++------ gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 34 +++---- inc/msp430/Os_Arch.h | 27 ++---- inc/msp430/Os_Internal_Arch.h | 35 ++----- inc/msp430/StartOs_Arch_SystemTick.h | 52 +++++------ .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 39 +++----- inc/os.h | 7 +- src/Os_Internal.c | 13 ++- src/Schedule.c | 7 +- src/msp430/Os_Arch.c | 11 ++- src/msp430/Os_Internal_Arch.c | 56 ++++++----- src/msp430/StartOs_Arch.c | 10 +- src/msp430/StartOs_Arch_SystemTick.c | 83 +++++++++-------- tst/ctest/bin/ctest.pl | 92 ++++++++++++++++++- tst/ctest/dbg/msp430/gcc/debug.scr | 12 +++ tst/ctest/etc/ctest_tm_01.oil | 2 +- tst/ctest/inc/ctest.h | 5 +- tst/ctest/inc/msp430/ctest_arch.h | 72 +++++++++++++++ .../msp430/msp430f5x_6x/msp430f5529/Makefile | 35 +++++++ tst/ctest/src/ctest_tm_01.c | 5 +- tst/ctest/src/msp430/ctest_arch.c | 92 +++++++++++++++++++ 21 files changed, 507 insertions(+), 224 deletions(-) create mode 100644 tst/ctest/dbg/msp430/gcc/debug.scr create mode 100644 tst/ctest/inc/msp430/ctest_arch.h create mode 100755 tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile create mode 100644 tst/ctest/src/msp430/ctest_arch.c diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index 469cb181..e1b03dc7 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -60,33 +60,21 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ -/***************************************************************************** - * add your name to the developers and create for you a nick with - * 3 or 4 letters. Please do not use any given nick. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ -/***************************************************************************** - * add a new version to this file, add the date, your initials and the main - * changes, only main changes shall be listed here. A detailed message log - * is saved in svn log and on the tracker system since every svn login message - * shalle indicate the related tracker id. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ + /* + * Initials Name + * --------------------------- + * FBUC Franco Bucafusco + * + */ + /* * modification history (new versions first) * ----------------------------------------------------------- - * v0.1.0 20162202 FB First version for msp430 processors. + * v0.1.0 20162202 FBUC First version for msp430 processors. */ /*==================[inclusions]=============================================*/ -/***************************************************************************** - * Please define here all needed macros of your configuration that can - * be configured or are used in Osek_Internal_Arch_Cfg.c.php - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ + /*==================[typedef]================================================*/ @@ -97,19 +85,15 @@ typedef TaskContextType* TaskContextRefType; /*==================[external data declaration]==============================*/ -/***************************************************************************** - * Please declare here all exported data defined - * Osek_Internal_Arch_Cfg.c.php - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ + /*==================[external functions declaration]=========================*/ -/* + void Enable_User_ISRs(void); void Enable_ISR2_Arch(void); void Disable_ISR2_Arch(void); -*/ + + /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index d7102d92..53731e97 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -70,20 +70,6 @@ /*==================[internal functions declaration]=========================*/ -__attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ -void OSEK_ISR_UNMI_VECTOR(void) -{ - while (1) - { - } -} -__attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ -void OSEK_ISR_SYSNMI_VECTOR(void) -{ - while (1) - { - } -} /*==================[internal data definition]===============================*/ @@ -141,11 +127,27 @@ /*==================[internal functions definition]==========================*/ /* Default exception handlers */ -?> +?> /*==================[external functions definition]==========================*/ +__attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +void OSEK_ISR_UNMI_VECTOR(void) +{ + while (1) + { + } +} + +__attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +void OSEK_ISR_SYSNMI_VECTOR(void) +{ + while (1) + { + } +} + /*** Non Used Interrupt handlers ***/ $base/mak/Makefile" or die "can not open: $!"; print FILE "PROJECT_NAME = $test-$config\n\n"; @@ -441,13 +496,21 @@ sub CreateTestProject print FILE " modules\$(DS)rtos\n\n"; print FILE "rtos_GEN_FILES += modules\$(DS)rtos\$(DS)tst\$(DS)ctest\$(DS)gen\$(DS)inc\$(DS)ctest_cfg.h.php\n\n"; print FILE "CFLAGS += -D$test\n"; + + #adds extra makefile options based on the architecture + Extra_MakeFile_AddOns_Arch(); + close FILE; + #copy needed files copy("modules/rtos/tst/ctest/src/$test.c","$base/src/$test.c"); copy("modules/rtos/tst/ctest/inc/$test.h","$base/inc/$test.h"); copy("modules/rtos/tst/ctest/inc/ctest.h","$base/inc/ctest.h"); copy("modules/rtos/tst/ctest/inc/$ARCH/ctest_arch.h","$base/inc/$ARCH/ctest_arch.h"); copy("modules/rtos/tst/ctest/src/$ARCH/ctest_arch.c","$base/src/$ARCH/ctest_arch.c"); + + #last replacement for IRQ vector name definitions + Extra_IRQ_Vector_Replace("$base/src/$test.c"); } sub finish @@ -520,6 +583,7 @@ sub logffull #Example: 'full-preemptive' or empty $subtestcase = $ARGV[3]; + #Example: 'ctest_tm_01:Test Sequence 1' or empty $onlytc = $ARGV[2]; @@ -544,6 +608,20 @@ sub logffull $ISR1 = "UART1"; $ISR2 = "UART0"; } + +if ("msp430" eq $ARCH) +{ + if ("msp430f5x_6x" eq $CPUTYPE) + { + if ("msp430f5529" eq $CPU) + { + $ISR1 = "PORT2"; + $ISR2 = "PORT1"; + $ISR3 = "PORT3"; #TODO For Interrupt type 3 when enable. + } + } +} + mkpath(dirname($logfile)); open LOGFILE, "> $logfile" or die "can not open $logfile for append: $!"; @@ -700,6 +778,7 @@ sub logffull info("running \"make $linker2RAM PROJECT_PATH=out/rtos/$test/$config MAKE_DEPENDENCIES=0\""); $outmake = `make $linker2RAM PROJECT_PATH=out/rtos/$test/$config MAKE_DEPENDENCIES=0`; $outmakestatus = $?; + info("make status: $outmakestatus"); logffull("make output:\n$outmake"); if ($debug) @@ -712,17 +791,24 @@ sub logffull { $out = $BINDIR . "/" . $test . "-" . $config . ".axf"; } + elsif ( $ARCH eq "msp430") + { + $out = $BINDIR . "/" . $test . "-" . $config . ".bin"; + } else { $out = $BINDIR . "/" . $test . "-" . $config . ".exe"; } + info("debug of $test in $out"); $dbgfile = "modules/rtos/tst/ctest/dbg/" . $ARCH . "/gcc/debug.scr"; info("$GDB $out -x $dbgfile"); + if($debug == 0) { $outdbg = `$GDB $out -x $dbgfile`; - if ($ARCH eq "x86") + + if ($ARCH eq "x86") { # if it fails, then capture ASSERT message with the condition, File and Line that failed and print it! my $Test_Asserted = index($outdbg, "ASSERT"); diff --git a/tst/ctest/dbg/msp430/gcc/debug.scr b/tst/ctest/dbg/msp430/gcc/debug.scr new file mode 100644 index 00000000..e6f81eb7 --- /dev/null +++ b/tst/ctest/dbg/msp430/gcc/debug.scr @@ -0,0 +1,12 @@ +target remote localhost:2000 +load +set $pc = __reset_vector +break ConfTestFinish +continue +dump value out/rtos/TestResults.bin TestResults +dump value out/rtos/TestResultsOk.bin TestResultsOk +dump value out/rtos/SequenceCounter.bin SequenceCounter +dump value out/rtos/SequenceCounterOk.bin SequenceCounterOk +dump value out/rtos/ConfTestResult.bin ConfTestResult +kill +quit diff --git a/tst/ctest/etc/ctest_tm_01.oil b/tst/ctest/etc/ctest_tm_01.oil index 5c34b0cf..728a8f81 100644 --- a/tst/ctest/etc/ctest_tm_01.oil +++ b/tst/ctest/etc/ctest_tm_01.oil @@ -31,7 +31,7 @@ TASK Task2 { TYPE = BASIC; } -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; diff --git a/tst/ctest/inc/ctest.h b/tst/ctest/inc/ctest.h index 61b4e521..fe066039 100644 --- a/tst/ctest/inc/ctest.h +++ b/tst/ctest/inc/ctest.h @@ -387,7 +387,7 @@ void ConfTestEvaluation } \ } #endif -#if ((cortexM4 == ARCH) || (cortexM0 == ARCH)) +#if ((cortexM4 == ARCH) || (cortexM0 == ARCH) || (msp430 == ARCH) ) #define ASSERT(tc,cond) \ { \ if (cond) \ @@ -405,6 +405,8 @@ void ConfTestEvaluation } #endif + + extern void Sequence ( uint32f seq @@ -420,4 +422,3 @@ extern void ConfTestFinish /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _CTEST_H_ */ - diff --git a/tst/ctest/inc/msp430/ctest_arch.h b/tst/ctest/inc/msp430/ctest_arch.h new file mode 100644 index 00000000..b2494fc2 --- /dev/null +++ b/tst/ctest/inc/msp430/ctest_arch.h @@ -0,0 +1,72 @@ +/* Copyright 20016, Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _CTEST_ARCH_H_ +#define _CTEST_ARCH_H_ +/** \brief FreeOSEK Os Conformance Test + ** + ** \file FreeOSEK/Os/tst/ctest/inc/posix/ctest_arch.h + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_CT Conformance Test + ** @{ */ + +/*==================[inclusions]=============================================*/ +#include "ciaaPlatforms.h" + +/*==================[macros]=================================================*/ +#if (CPUTYPE == msp430f5x_6x) +/* Use P1.7 as interrupt for tests */ +extern void TriggerISR2_Arch(void); + +/* Use P2.2 as interrupt for tests */ +extern void TriggerISR1_Arch(void); + +#else + #error please define CPU variable! +#endif + +/*==================[typedef]================================================*/ + +/*==================[external data declaration]==============================*/ + +/*==================[external functions declaration]=========================*/ + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _CTEST_ARCH_H_ */ diff --git a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile new file mode 100755 index 00000000..41ef1bc6 --- /dev/null +++ b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile @@ -0,0 +1,35 @@ +############################################################################### +# +# Copyright 2016, Franco Bucafusco (BuckLabs) +# +# This file is part of CIAA Firmware. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################### +# + diff --git a/tst/ctest/src/ctest_tm_01.c b/tst/ctest/src/ctest_tm_01.c index c7b92ef8..5d2c5447 100644 --- a/tst/ctest/src/ctest_tm_01.c +++ b/tst/ctest/src/ctest_tm_01.c @@ -207,7 +207,7 @@ TASK(Task2) TerminateTask(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; TaskType TaskID; @@ -248,7 +248,7 @@ ISR(ISR2) } #if ( ISR_CATEGORY_3 == OSEK_ENABLE ) -ISR(ISR3) +ISR(VN_ISR3) { StatusType ret; @@ -293,4 +293,3 @@ ISR(ISR3) /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/tst/ctest/src/msp430/ctest_arch.c b/tst/ctest/src/msp430/ctest_arch.c new file mode 100644 index 00000000..70b8160e --- /dev/null +++ b/tst/ctest/src/msp430/ctest_arch.c @@ -0,0 +1,92 @@ +/* Copyright 2016, Franco Bucafusco + * All rights reserved. + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os Conformance Test + ** + ** \file FreeOSEK/Os/tst/ctest/inc/posix/ctest_arch.h + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_CT Conformance Test + ** @{ */ + +/*==================[inclusions]=============================================*/ +#include "ciaaPlatforms.h" +#include "ctest_arch.h" +#if (CPU == msp430f5529) +#include "msp430.h" +#endif + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ +#if (CPUTYPE == msp430f5x_6x) + + +/* Use P1.7 as interrupt for tests */ +extern void TriggerISR2_Arch(void) +{ + /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ + P1IE |= 0x80; + P1IFG |= 0x80; +} + +/* Use P2.2 as interrupt for tests */ +extern void TriggerISR1_Arch(void) +{ + /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ + P2IE |= 0x04; + P2IFG |= 0x04; +} + + + +#endif + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ From 12f9d153de23fdbd2cec1a1db2a38890b3d91d5c Mon Sep 17 00:00:00 2001 From: FRANCO Date: Mon, 30 May 2016 01:04:19 -0300 Subject: [PATCH 08/42] - se corrigen algunas cosas para los tests --- .../gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 101 +++++++ .../gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 269 ++++++++++++++++++ tst/ctest/bin/ctest.pl | 60 ++-- tst/ctest/dbg/msp430/gcc/debug.scr | 2 +- tst/ctest/src/msp430/ctest_arch.c | 5 +- 5 files changed, 414 insertions(+), 23 deletions(-) create mode 100644 generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php create mode 100644 generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php diff --git a/generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php new file mode 100644 index 00000000..e1b03dc7 --- /dev/null +++ b/generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -0,0 +1,101 @@ +/******************************************************** + * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* + ********************************************************/ + +/* Copyright 2016, Franco Bucafusco + * All rights reserved. + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _OS_INTERNAL_ARCH_CFG_H_ +#define _OS_INTERNAL_ARCH_CFG_H_ + +/***************************************************************************** + * update the tmparch directory on the \file doxygen comment with your + * architecture + * + * PLEASE REMOVE THIS COMMENT + *****************************************************************************/ +/** \brief FreeOSEK Os Generated Internal Architecture Configuration Header File + ** + ** This file content the internal generated architecture dependent + ** configuration of FreeOSEK. + ** + ** \file msp430/Os_Internal_Arch_Cfg.h + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + + /* + * Initials Name + * --------------------------- + * FBUC Franco Bucafusco + * + */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * v0.1.0 20162202 FBUC First version for msp430 processors. + */ + +/*==================[inclusions]=============================================*/ + + +/*==================[typedef]================================================*/ + +/** \brief Task Context Type */ +typedef uint16 * TaskContextType; + +/** \brief Task Context Type */ +typedef TaskContextType* TaskContextRefType; + +/*==================[external data declaration]==============================*/ + + +/*==================[external functions declaration]=========================*/ + +void Enable_User_ISRs(void); +void Enable_ISR2_Arch(void); +void Disable_ISR2_Arch(void); + + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _OS_INTERNAL_ARCH_CFG_H_ */ diff --git a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php new file mode 100644 index 00000000..56ac45b5 --- /dev/null +++ b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -0,0 +1,269 @@ +/******************************************************** + * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* + ********************************************************/ + +/* Copyright 2016, Franco Bucafusco + * All rights reserved. + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os Generated Internal Achitecture Configuration Implementation File + ** + ** \file msp430/Os_Internal_Arch_Cfg.c + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * v0.1.0 20160221 initial version + */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal.h" + +#if(CPU == msp430f5x_6x) +/* THIS IS A DIRTY WORKAROUND :( ciaa/Firmware#309*/ +#undef FALSE +#undef TRUE +#include "msp430.h" +#endif + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + + +/*==================[internal data definition]===============================*/ + +/*==================[external data definition]===============================*/ + "RTC", + 1 => "PORT2", + 2 => "TIMER2_A1", + 3 => "TIMER2_A0", + 4 => "USCI_B1", + 5 => "USCI_A1", + 6 => "PORT1", + 7 => "TIMER1_A1", + 8 => "TIMER1_A0", + 9 => "DMA", + 10 => "USB_UBM", + 11 => "TIMER0_A1", + 12 => "TIMER0_A0", + 13 => "ADC12", + 14 => "USCI_B0", + 15 => "USCI_A0", + 16 => "WDT", + 17 => "TIMER0_B1", + 18 => "TIMER0_B0", + 19 => "COMP_B", + 20 => "UNMI", + 21 => "SYSNMI", + 22 => "RESET", + ); + break; + + default: + error("the CPU " . $definitions["CPU"] . " is not supported."); + break; +} + +$MAX_INT_COUNT = max(array_keys($intList))+1; + +#if (CPU == msp430f5529) + +#else +#error Not supported CPU +#endif + +/** \brief Handlers used by OSEK */ + + +/*==================[internal functions definition]==========================*/ +/* Default exception handlers */ + +?> + +/*==================[external functions definition]==========================*/ + +__attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +void OSEK_ISR_UNMI_VECTOR(void) +{ + while (1) + { + } +} + +__attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +void OSEK_ISR_SYSNMI_VECTOR(void) +{ + while (1) + { + } +} + + /*** Non Used Interrupt handlers ***/ +getList("/OSEK", "ISR"); + +for($i=0; $i < $MAX_INT_COUNT; $i++) +{ + $src_found = 0; + + foreach ($intnames as $int) + { + /* + handlers that are present in the system (defined in the oil file) + do not add extra code here. + */ + $intcat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); + + if($intList[$i] == $source) + { + if ($intcat == 2) + { + $src_found = 1; + } elseif ($intcat == 1) + { + $src_found = 1; + } + else + { + $this->log->error("Interrupt $int type $inttype has an invalid category $intcat"); + } + } + } + + if( $intList[$i]=="TIMER2_A1" || $intList[$i]=="TIMER2_A0" || $intList[$i]=="RESET" || $intList[$i]=="UNMI" || $intList[$i]=="SYSNMI" ) + { + /* + This part forces irq_handlers not to be defined here. + TIMER2_XX: Use for OSEK periodic interrupt + RESET: defined by gcc @ compile time. + UNMI: defined in this file + SYSNMI: defined in this file + */ + $src_found = 1; + } + + if($src_found == 0) + { + print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; + print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; + print "{\n"; + print "}\n"; + } +} +?> + +/** \brief Interrupt enabling and priority setting function */ +void Enable_User_ISRs(void) +{ +getList("/OSEK", "ISR"); + +foreach ($intnames as $int) +{ + $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); + $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); + + print " /* Enabling IRQ $source with priority $prio */\n"; + print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; +} +?> +} + +/** \brief Enable user defined category 2 ISRs */ +void Enable_ISR2_Arch(void) +{ +getList("/OSEK", "ISR"); +foreach ($intnames as $int) +{ + $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + + if($cat == 2) + { + print " /* Enabling IRQ $source */\n"; + print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; + } +} +?> +} + +/** \brief Disable user defined category 2 ISRs */ +void Disable_ISR2_Arch(void) +{ +getList("/OSEK", "ISR"); +foreach ($intnames as $int) +{ + $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + + if($cat == 2) + { + print " /* Disabling IRQ $source */\n"; + print " MSP430_DisableIRQ(" . array_search($source, $intList) . ");\n"; + } +} +?> +} + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ diff --git a/tst/ctest/bin/ctest.pl b/tst/ctest/bin/ctest.pl index e768e65d..6ddb35ce 100755 --- a/tst/ctest/bin/ctest.pl +++ b/tst/ctest/bin/ctest.pl @@ -321,6 +321,8 @@ sub EvaluateResults return $status; } +#TODO remove debug franco + sub readparam { open CFG, "<@_[0]" or die "Config file @_[0] can not be opened: $!"; @@ -389,9 +391,9 @@ sub halt #** \brief It replaces extra definitions for IRQ for other files # TODO: use this function for every replacement passing the @replace variable as parameter -# +# #* -sub Extra_IRQ_Vector_Replace +sub Extra_IRQ_Vector_Replace { my $myfile = shift; @@ -407,10 +409,10 @@ sub Extra_IRQ_Vector_Replace info("Replacing: $rep in $myfile"); @rep = split (/:/,$rep); searchandreplace($myfile,@rep[0],@rep[1]); - } + } } -#** \brief Add extra options for the makefile file based on the architecture +#** \brief Add extra options for the makefile file based on the architecture # # #* @@ -422,7 +424,7 @@ sub Extra_MakeFile_AddOns_Arch { if ("msp430f5529" eq $CPU) { - #for msp430 architecture the heap_mem_size can't be as high as for cortex. + #for msp430 architecture the heap_mem_size can't be as high as for cortex. print FILE "CFLAGS += -D CIAA_HEAP_MEM_SIZE=200"; } } @@ -458,14 +460,14 @@ sub CreateTestProject # prepare the configuration for this project # removes carry return + line-feed $testfn =~ tr/\r\n//d; - + @replace = GetTestSequencesCon($TESTS, $testfn, $config); # TODO this shall be improved. Definitely. Doing this for another platform was a headache # CT stand for : ?? - # VN stands for : "Vector Name" + # VN stands for : "Vector Name" push @replace, "CT_ISR1:" . $ISR1; - push @replace, "CT_ISR2:" . $ISR2; + push @replace, "CT_ISR2:" . $ISR2; push @replace, "VN_ISR1:" . $ISR1."_VECTOR"; #replace vector name push @replace, "VN_ISR2:" . $ISR2."_VECTOR"; #replace vector name @@ -498,8 +500,8 @@ sub CreateTestProject print FILE "CFLAGS += -D$test\n"; #adds extra makefile options based on the architecture - Extra_MakeFile_AddOns_Arch(); - + Extra_MakeFile_AddOns_Arch(); + close FILE; #copy needed files @@ -508,7 +510,7 @@ sub CreateTestProject copy("modules/rtos/tst/ctest/inc/ctest.h","$base/inc/ctest.h"); copy("modules/rtos/tst/ctest/inc/$ARCH/ctest_arch.h","$base/inc/$ARCH/ctest_arch.h"); copy("modules/rtos/tst/ctest/src/$ARCH/ctest_arch.c","$base/src/$ARCH/ctest_arch.c"); - + #last replacement for IRQ vector name definitions Extra_IRQ_Vector_Replace("$base/src/$test.c"); } @@ -585,7 +587,7 @@ sub logffull $subtestcase = $ARGV[3]; #Example: 'ctest_tm_01:Test Sequence 1' or empty -$onlytc = $ARGV[2]; +$onlytc = $ARGV[2]; $cfgfile = $ARGV[1]; @@ -593,11 +595,14 @@ sub logffull info("Removing old files"); system("rm -rf out/rtos/*"); + readparam($cfgfile); # TODO this has to be improved + $ISR1 = "GPIO1"; $ISR2 = "GPIO0"; + if ("k60_120" eq $CPUTYPE) { $ISR1 = "PORTB"; @@ -608,7 +613,7 @@ sub logffull $ISR1 = "UART1"; $ISR2 = "UART0"; } - + if ("msp430" eq $ARCH) { if ("msp430f5x_6x" eq $CPUTYPE) @@ -622,7 +627,6 @@ sub logffull } } - mkpath(dirname($logfile)); open LOGFILE, "> $logfile" or die "can not open $logfile for append: $!"; mkpath(dirname($logfilefull)); @@ -685,8 +689,11 @@ sub logffull print "Debug Mode: Enabled!\n"; } + foreach $testfn (@tests) { + print "\n"; #add a gap in the output + @test = split(/:/,$testfn); $test = @test[0]; info("Testing $test"); @@ -695,7 +702,7 @@ sub logffull foreach $config (@configs) { - $config =~ tr/\r\n//d; + $config =~ tr/\r\n//d; $runthistestcase = 1; $testcasecount++; @@ -758,11 +765,14 @@ sub logffull info("WARNING: skipping make generate of $test"); $outmakegeneratestatus = 0; } + logtimestamp(SUMMARYFILE); + if ($outmakegeneratestatus == 0) { # Make project skipping make dependencies info("make of $test"); + if($RAM_EXEC != 0) { # make Link2RAM rule @@ -775,16 +785,19 @@ sub logffull $linker2RAM = ""; info("Setting Linker option: Link2FLASH"); } + info("running \"make $linker2RAM PROJECT_PATH=out/rtos/$test/$config MAKE_DEPENDENCIES=0\""); $outmake = `make $linker2RAM PROJECT_PATH=out/rtos/$test/$config MAKE_DEPENDENCIES=0`; $outmakestatus = $?; info("make status: $outmakestatus"); logffull("make output:\n$outmake"); + if ($debug) { print "$outmake"; } + if ($outmakestatus == 0) { if (($ARCH eq "cortexM4") || ($ARCH eq "cortexM0")) @@ -793,7 +806,7 @@ sub logffull } elsif ( $ARCH eq "msp430") { - $out = $BINDIR . "/" . $test . "-" . $config . ".bin"; + $out = $BINDIR . "/" . $test . "-" . $config . ".out"; } else { @@ -806,8 +819,17 @@ sub logffull if($debug == 0) { + #print("probando debug\n"); + #before calling gdb, for msp430, I have to run the proxy (mspdebug) + #how is done in cortex with open ocd? TODO + + if( $ARCH eq "msp430" ) #degun franco + { + info("Running $MSPDEBUG_BIN $MSPDEBUG_PROTOCOL"); + } + $outdbg = `$GDB $out -x $dbgfile`; - + if ($ARCH eq "x86") { # if it fails, then capture ASSERT message with the condition, File and Line that failed and print it! @@ -819,12 +841,14 @@ sub logffull print("ERROR, $Str_Assert\n"); } } - } + } else { + print("probando\n"); exec("$GDB $out"); $outdbg = ""; } + $outdbgstatus = $?; info("debug status: $outdbgstatus"); info("debug output:\n$outdbg"); diff --git a/tst/ctest/dbg/msp430/gcc/debug.scr b/tst/ctest/dbg/msp430/gcc/debug.scr index e6f81eb7..ec981ae8 100644 --- a/tst/ctest/dbg/msp430/gcc/debug.scr +++ b/tst/ctest/dbg/msp430/gcc/debug.scr @@ -1,6 +1,6 @@ target remote localhost:2000 load -set $pc = __reset_vector +set $pc = __msp430_resetvec_hook break ConfTestFinish continue dump value out/rtos/TestResults.bin TestResults diff --git a/tst/ctest/src/msp430/ctest_arch.c b/tst/ctest/src/msp430/ctest_arch.c index 70b8160e..a7ff7d8e 100644 --- a/tst/ctest/src/msp430/ctest_arch.c +++ b/tst/ctest/src/msp430/ctest_arch.c @@ -47,7 +47,7 @@ #include "ciaaPlatforms.h" #include "ctest_arch.h" #if (CPU == msp430f5529) -#include "msp430.h" +#include "msp430.h" #endif /*==================[macros and definitions]=================================*/ @@ -60,7 +60,6 @@ /*==================[external data definition]===============================*/ #if (CPUTYPE == msp430f5x_6x) - /* Use P1.7 as interrupt for tests */ extern void TriggerISR2_Arch(void) @@ -77,8 +76,6 @@ extern void TriggerISR1_Arch(void) P2IE |= 0x04; P2IFG |= 0x04; } - - #endif From 364dcfbccaffc57328836b955d8c0e6e77e855ca Mon Sep 17 00:00:00 2001 From: FRANCO Date: Tue, 31 May 2016 07:47:13 -0300 Subject: [PATCH 09/42] - cambio minimo --- src/msp430/StartOs_Arch_SystemTick.c | 2 ++ tst/ctest/etc/ctest_tm_01.oil | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c index d039814a..0354e08b 100644 --- a/src/msp430/StartOs_Arch_SystemTick.c +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -119,6 +119,8 @@ MCLK = SMCLK = 14.7456Mhz */ void StartOs_Arch_System() { + WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //TODO LEER https://sourceware.org/ml/newlib/2015/msg00627.html + UCS_turnOffXT1(); XT1_XT2_PORT_SEL |= XT1_ENABLE + XT2_ENABLE; // Setup XT1 and XT2 diff --git a/tst/ctest/etc/ctest_tm_01.oil b/tst/ctest/etc/ctest_tm_01.oil index 728a8f81..bc924e51 100644 --- a/tst/ctest/etc/ctest_tm_01.oil +++ b/tst/ctest/etc/ctest_tm_01.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2560; + STACK = 256; TYPE = BASIC; }; @@ -27,7 +27,7 @@ TASK Task2 { SCHEDULE = CT_SCHEDULING_TASK2; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = BASIC; } From 72299a65fc030e53ba37e97f969d3fe75d29811b Mon Sep 17 00:00:00 2001 From: FRANCO Date: Wed, 1 Jun 2016 01:11:56 -0300 Subject: [PATCH 10/42] - se agrega al makefile del test para msp430 una definicion para el precompilador, para que genere diferencias en la compilacion de algunos objetos. - se modifica la generacion del array para los stacks de cada tarea. para msp430, se definen como uint16 --- gen/src/Os_Internal_Cfg.c.php | 21 ++++++++++++++++--- .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 5 ++++- .../msp430/msp430f5x_6x/msp430f5529/Makefile | 2 ++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 5d507aa8..b1f61b38 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -6,6 +6,7 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016 Franco Bucafusco * * This file is part of CIAA Firmware. * @@ -70,7 +71,17 @@ print "#if ( x86 == ARCH )\n"; print "uint8 StackTask" . $task . "[" . $config->getValue("/OSEK/" . $task, "STACK") ." + TASK_STACK_ADDITIONAL_SIZE];\n"; print "#else\n"; - print "uint8 StackTask" . $task . "[" . $config->getValue("/OSEK/" . $task, "STACK") ."];\n"; + if( $definitions["ARCH"]== "msp430") + { + #msp430 requieres bus alligmented memory access. So, if the compiler allocates this array as uint8 it could start at an even address. + #we force the compiler to locate this array alligned declaring it as an uint16 (with the size divided by two) + print "uint16 StackTask" . $task . "[" . $config->getValue("/OSEK/" . $task, "STACK") ."/2];\n"; + } + else + { + print "uint8 StackTask" . $task . "[" . $config->getValue("/OSEK/" . $task, "STACK") ."];\n"; + } + print "#endif\n"; } print "\n"; @@ -478,7 +489,12 @@ $intcat = $config->getValue("/OSEK/" . $int,"CATEGORY"); if ($intcat == 2) - {?> + { + if($definitions["ARCH"] == "msp430") + { + print "__attribute__( (__interrupt__($int))) /*Wrapper ISR handler for $int */\n"; + } + ?> void OSEK_ISR2_(void) { /* store the calling context in a variable */ @@ -512,4 +528,3 @@ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index 3a66ebc4..be445674 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -85,8 +85,11 @@ ** ** \param[in] name name of the ISR category 1 or 2. **/ + #ifdef CTESTS_MODIFIERS +#define ISR(name) void OSEK_ISR_ ## name (void) + #else #define ISR(name) __attribute__( (__interrupt__(name))) void OSEK_ISR_ ## name (void) - +#endif /*==================[typedef]================================================*/ diff --git a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile index 41ef1bc6..37a952a7 100755 --- a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile +++ b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile @@ -33,3 +33,5 @@ ############################################################################### # +#for testes we add a precompiler definition to alter some macros +CFLAGS += -DCTESTS_MODIFIERS From 0ec29811347a67deac4f3d5c69f5c096dee1f3c0 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Fri, 3 Jun 2016 00:32:52 -0300 Subject: [PATCH 11/42] - Se corrige context switch para msp430 --- inc/msp430/Os_Internal_Arch.h | 67 +++++++++++++++++------------------ src/msp430/Os_Internal_Arch.c | 10 +++--- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 1eb039ac..6cfc549d 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -45,7 +45,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - + /* * Initials Name * --------------------------- @@ -119,9 +119,7 @@ extern TaskType TerminatingTask; ** else to execute. The macro may sleep the cpu for a short time to avoid ** overheating and full power consumption or may halt the processor always ** that all wakeup reasons are right configured. If nothing is running - ** nothing my activate any task so we will keep sleeping until anything - ** occurs, like for example an interrupt. - ** + ** nothing my activate any task so we **/ #define osekpause() asm volatile("nop") //TODO revisar los low power modes @@ -130,35 +128,34 @@ extern TaskType TerminatingTask; ** This macro is called by the context switch routine. ** **/ -#define SAVE_CONTEXT() \ - asm volatile ( "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ +#define SAVE_CONTEXT() \ + asm volatile ( "push r4\n\t"\ + "push r5\n\t"\ + "push r6\n\t"\ + "push r7\n\t"\ + "push r8\n\t"\ + "push r9\n\t"\ + "push r10\n\t"\ + "push r11\n\t"\ + "push r12\n\t"\ + "push r13\n\t"\ + "push r14\n\t"\ + "push r15\n\t"\ ); -#define RESTORE_CONTEXT() \ - asm volatile ( "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "reti \n\t" \ +#define RESTORE_CONTEXT() \ + asm volatile ( "pop r15\n\t"\ + "pop r14\n\t"\ + "pop r13\n\t"\ + "pop r12\n\t"\ + "pop r11\n\t"\ + "pop r10\n\t"\ + "pop r9\n\t"\ + "pop r8\n\t"\ + "pop r7\n\t"\ + "pop r6\n\t"\ + "pop r5\n\t"\ + "pop r4\n\t"\ ); #define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); @@ -169,8 +166,8 @@ extern TaskType TerminatingTask; **/ #define CallTask(actualtask, nexttask) \ { \ - Osek_OldTaskPtr_Arch = (void*) *(TasksConst[(actualtask)].TaskContext); \ - Osek_NewTaskPtr_Arch = (void*) *(TasksConst[(nexttask)].TaskContext); \ + Osek_OldTaskPtr_Arch = (void*) (TasksConst[(actualtask)].TaskContext); \ + Osek_NewTaskPtr_Arch = (void*) (TasksConst[(nexttask)].TaskContext); \ /* next action will trigger assigned IRQ for the SWI */ \ HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ } @@ -184,14 +181,14 @@ extern TaskType TerminatingTask; extern TaskType WaitingTask; \ if(WaitingTask != INVALID_TASK) \ { \ - Osek_OldTaskPtr_Arch = (void*) *(TasksConst[WaitingTask].TaskContext);\ + Osek_OldTaskPtr_Arch = (void*) (TasksConst[WaitingTask].TaskContext);\ WaitingTask = INVALID_TASK; \ } \ else \ { \ Osek_OldTaskPtr_Arch = (void*)0; \ } \ - Osek_NewTaskPtr_Arch = (void*) *(TasksConst[(task)].TaskContext); \ + Osek_NewTaskPtr_Arch = (void*) (TasksConst[(task)].TaskContext); \ /* next action will trigger assigned IRQ for the SWI */ \ HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ } diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index dc494748..3daffce6 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -104,7 +104,7 @@ void InitStack_Arch(uint8 TaskID) int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ - taskStack[taskStackSizeWords-1] = (uint32) TasksConst[TaskID].EntryPoint; /*PC*/ + taskStack[taskStackSizeWords-1] = (uint16) TasksConst[TaskID].EntryPoint; /*PC*/ taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ /* la ubicacion, reservando 13 registro para el cambio de contexto @@ -196,13 +196,15 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) /* exchange stack pointers */ if( Osek_OldTaskPtr_Arch != NULL ) { - asm volatile ( "mov SP, Osek_OldTaskPtr_Arch \n\t" ); + asm volatile ( "mov &Osek_OldTaskPtr_Arch, r6 \n\t" ); + asm volatile ( "mov SP, @r6 \n\t" ); } + asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); + asm volatile ( "mov @r6, SP \n\t" ); - asm volatile ( "mov Osek_NewTaskPtr_Arch, SP \n\t" ); /* Context restore r4 to r15 - It Includes the reti instruction. + It does not Include the reti instruction. */ RESTORE_CONTEXT() } From f77f2b1843fa01bdac67853640f3aecf2a58e25b Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 5 Jun 2016 00:51:14 -0300 Subject: [PATCH 12/42] - cambios en manejo de irq en diferentes lugares del codigo --- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 14 + gen/src/Os_Internal_Cfg.c.php | 18 +- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 1 + inc/msp430/Os_Arch.h | 32 +- inc/msp430/Os_Internal_Arch.h | 11 +- src/ActivateTask.c | 7 +- src/ChainTask.c | 2 + src/ClearEvent.c | 2 + src/GetResource.c | 2 + src/ReleaseResource.c | 2 + src/Schedule.c | 6 + src/SetAbsAlarm.c | 2 + src/SetEvent.c | 2 + src/SetRelAlarm.c | 2 + src/StartOS.c | 2 + src/TerminateTask.c | 2 + src/WaitEvent.c | 2 + src/msp430/Os_Internal_Arch.c | 634 +++++++++++++++++++++- src/msp430/StartOs_Arch.c | 2 +- 19 files changed, 732 insertions(+), 13 deletions(-) diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index e1b03dc7..88412cf3 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -85,6 +85,20 @@ typedef TaskContextType* TaskContextRefType; /*==================[external data declaration]==============================*/ +getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + + print "#define MSP430_ENABLE_". $source . "_HANDLER 1 \n"; + +} +?> + /*==================[external functions declaration]=========================*/ diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index b1f61b38..3d9408f4 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -65,6 +65,18 @@ /* get tasks */ $tasks = getLocalList("/OSEK", "TASK"); +/* +if( $definitions["ARCH"]== "msp430") +{ + $stack_element_type = "uint16"; +} +else +{ + $stack_element_type = "uint8"; +} + +$stack_element_cast_type = "(". $stack_element_type . "*)"; */ //TODO DELETE + foreach ($tasks as $task) { print "/** \brief $task stack */\n"; @@ -162,7 +174,11 @@ print " {\n"; print " OSEK_TASK_$task, /* task entry point */\n"; print " &ContextTask" . $task . ", /* pointer to task context */\n"; - print " StackTask" . $task . ", /* pointer stack memory */\n"; + + + print " (StackPtrType) StackTask" . $task . ", /* pointer stack memory */\n"; + + print " sizeof(StackTask" . $task . "), /* stack size */\n"; print " " . $priority[$config->getValue("/OSEK/" . $task, "PRIORITY")] . ", /* task priority */\n"; print " " . $config->getValue("/OSEK/" . $task, "ACTIVATION"). ", /* task max activations */\n"; diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 53731e97..5b76f8c5 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -223,6 +223,7 @@ ?> } + /** \brief Enable user defined category 2 ISRs */ void Enable_ISR2_Arch(void) { diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index d7077a24..45146fbd 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -57,7 +57,7 @@ * */ - + /* * modification history (new versions first) * ---------------------------------------------------------- @@ -83,11 +83,14 @@ /** \brief Disable All Interrupts Arch */ #define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() -/** \brief Resume All Interrupts Arch + + +/** \brief All Interrupts Arch Common Objects ** - ** This macro shall resume (enable) all interrupts. + ** This macro shall define common objects to imlement Suspend and Resume **/ -#define ResumeAllInterrupts_Arch() __asm volatile("eint") +#define CommonAllInterrupts() unsigned short SR_BACK___; + /** \brief Suspend All Interrupts Arch ** @@ -95,8 +98,27 @@ ** NOTE: the nop operation after the dint instruction was inserted ** to workarround the hw bug cpu39 describer in slaz314h.pdf **/ + + +#define SuspendAllInterrupts_Arch() __asm volatile("mov SR, SR_BACK___");\ + __asm volatile("dint"); \ + __asm volatile("nop"); + +/* #define SuspendAllInterrupts_Arch() __asm volatile("dint"); \ - __asm volatile("nop"); + __asm volatile("nop"); +*/ + +/** \brief Resume All Interrupts Arch +** +** This macro shall resume (enable) all interrupts. +**/ +/* + #define ResumeAllInterrupts_Arch() __asm volatile("eint") +*/ + +#define ResumeAllInterrupts_Arch() if( SR_BACK___ & 0x0008 ) __asm volatile("eint"); + /** \brief Resume OS Interrupts Arch ** diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 6cfc549d..ceff4bd6 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -97,6 +97,15 @@ extern void *Osek_NewTaskPtr_Arch; extern TaskType TerminatingTask; + +/** \brief Define common objects for using IntSecure_Start and IntSecure_End- + ** + ** This macro will be used internaly by the OS in any part of code that + ** has to be executed atomic. It should be placed after IntSecure_Start or IntSecure_End is called + **/ +#define IntSecure_Common() CommonAllInterrupts() + + /** \brief Interrupt Secure Start Macro ** ** This macro will be used internaly by the OS in any part of code that @@ -276,7 +285,7 @@ extern TaskType TerminatingTask; **/ #define GetCounter_Arch(CounterID) (CountersVar[CounterID].Time) -/** \brief Pre ISR Macro +/** \brief Pre ISR Macrol ** ** This macro is called every time that an ISR Cat 2 is started **/ diff --git a/src/ActivateTask.c b/src/ActivateTask.c index 63f95afb..cc3c1dfd 100644 --- a/src/ActivateTask.c +++ b/src/ActivateTask.c @@ -79,6 +79,8 @@ /* \req OSEK_SYS_3.1.7-1/3 Possible return values in Standard mode are E_OK or E_OS_LIMIT */ StatusType ret = E_OK; + IntSecure_Common(); + #if (OSEK_MULTICORE == OSEK_ENABLE) if ((TaskID - TASKS_COUNT) < REMOTE_TASKS_COUNT) { @@ -111,7 +113,7 @@ else #endif { - IntSecure_Start(); + IntSecure_Start(); /* check if the task is susspended */ /* \req OSEK_SYS_3.1.1-1/2 The task TaskID shall be transferred from the @@ -167,7 +169,7 @@ } } - IntSecure_End(); + IntSecure_End(); #if (NON_PREEMPTIVE == OSEK_DISABLE) /* check if called from a Task Context */ @@ -214,4 +216,3 @@ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/src/ChainTask.c b/src/ChainTask.c index 19127386..1524dee7 100644 --- a/src/ChainTask.c +++ b/src/ChainTask.c @@ -75,6 +75,8 @@ StatusType ChainTask StatusType ret = E_OK; + IntSecure_Common(); + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) if ( taskid >= TASKS_COUNT ) { diff --git a/src/ClearEvent.c b/src/ClearEvent.c index 0863f813..925f4604 100644 --- a/src/ClearEvent.c +++ b/src/ClearEvent.c @@ -76,6 +76,8 @@ StatusType ClearEvent /* \req OSEK_SYS_3.16.2 Possible return values in Standard mode is E_OK */ StatusType ret = E_OK; + IntSecure_Common(); + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) if ( GetCallingContext() != CONTEXT_TASK ) { diff --git a/src/GetResource.c b/src/GetResource.c index 3267b7c2..9a4d7906 100644 --- a/src/GetResource.c +++ b/src/GetResource.c @@ -79,6 +79,8 @@ StatusType GetResource /* \req OSEK_SYS_3.13.2: Possible return values in Standard mode is E_OK */ StatusType ret = E_OK; + IntSecure_Common(); + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) if ( /* only if one or more resources were defined */ diff --git a/src/ReleaseResource.c b/src/ReleaseResource.c index 96d04999..25effb20 100644 --- a/src/ReleaseResource.c +++ b/src/ReleaseResource.c @@ -80,6 +80,8 @@ StatusType ReleaseResource * E_OK */ StatusType ret = E_OK; + IntSecure_Common(); + #if (RESOURCES_COUNT != 0) uint8 loopi; #endif /* #if (RESOURCES_COUNT != 0) */ diff --git a/src/Schedule.c b/src/Schedule.c index 631558e7..ed05a75e 100644 --- a/src/Schedule.c +++ b/src/Schedule.c @@ -1,5 +1,6 @@ /* Copyright 2008, 2009, 2014, 2015 Mariano Cerdeiro * Copyright 2014, ACSE & CADIEEL + * Copyright 2016, Franco Bucafusco * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * @@ -81,12 +82,17 @@ extern StatusType Schedule /* \req OSEK_SYS_3.4.4 Possible return values in Standard mode is E_OK */ StatusType ret = E_OK; + + TaskType nextTask; TaskType actualTask; + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) ContextType actualContext; #endif +IntSecure_Common(); + IntSecure_Start(); /* get actual running task */ diff --git a/src/SetAbsAlarm.c b/src/SetAbsAlarm.c index 3d50b173..4b45cd04 100644 --- a/src/SetAbsAlarm.c +++ b/src/SetAbsAlarm.c @@ -80,6 +80,8 @@ StatusType SetAbsAlarm ** E_OS_STATE */ StatusType ret = E_OK; + IntSecure_Common(); + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) /* check if the alarm id is in range */ if(AlarmID >= ALARMS_COUNT) diff --git a/src/SetEvent.c b/src/SetEvent.c index 34d4d85f..dec86e41 100644 --- a/src/SetEvent.c +++ b/src/SetEvent.c @@ -77,6 +77,8 @@ StatusType SetEvent /* \req OSEK_SYS_3.15.2: Possible return values in Standard mode is E_OK */ StatusType ret = E_OK; + IntSecure_Common(); + #if (OSEK_MULTICORE == OSEK_ENABLE) if ((TaskID - TASKS_COUNT) < REMOTE_TASKS_COUNT) { diff --git a/src/SetRelAlarm.c b/src/SetRelAlarm.c index 9db4f1d5..0bcb2c1b 100644 --- a/src/SetRelAlarm.c +++ b/src/SetRelAlarm.c @@ -79,6 +79,8 @@ StatusType SetRelAlarm ** E_OK, E_OS_STATE */ StatusType ret = E_OK; + IntSecure_Common(); + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) /* check if the alarm id is in range */ if(AlarmID >= ALARMS_COUNT) diff --git a/src/StartOS.c b/src/StartOS.c index 938304fd..d0e29072 100644 --- a/src/StartOS.c +++ b/src/StartOS.c @@ -76,6 +76,8 @@ void StartOS ** system */ uint8f loopi; + IntSecure_Common(); + IntSecure_Start(); #if (OSEK_MULTICORE == OSEK_ENABLE) diff --git a/src/TerminateTask.c b/src/TerminateTask.c index b929389d..45ae79e8 100644 --- a/src/TerminateTask.c +++ b/src/TerminateTask.c @@ -74,6 +74,8 @@ StatusType TerminateTask StatusType ret = E_OK; + IntSecure_Common(); + /* \req OSEK_SYS_3.2.4 If the version with extended status is used, the ** service returns in case of error, and provides a status which can be ** evaluated in the application. */ diff --git a/src/WaitEvent.c b/src/WaitEvent.c index d5d0438e..0e7fe0ec 100644 --- a/src/WaitEvent.c +++ b/src/WaitEvent.c @@ -78,6 +78,8 @@ StatusType WaitEvent /* \req OSEK_SYS_3.18.3 Possible return values in Standard mode is E_OK */ StatusType ret = E_OK; + IntSecure_Common(); + #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) if ( GetCallingContext() != CONTEXT_TASK ) { diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 3daffce6..ef801c16 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -140,13 +140,13 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) (void)CounterIncrement; /* TODO remove me */ /* increment the disable interrupt conter to avoid enable the interrupts */ - IntSecure_Start(); +// IntSecure_Start(); //MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS /* call counter interrupt handler */ CounterIncrement = IncrementCounter(0, TIC_PERIOD ); /* set the disable interrupt counter back */ - IntSecure_End(); +// IntSecure_End(); //MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS #endif /* #if (ALARMS_COUNT != 0) */ /* reset context */ @@ -213,6 +213,636 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) } +/* +MSP430 hasn't a way of dissabling "all the vector" at once, without touching the +individual sub IE flags. +So, when dissable the IRQ handler the system must backup the current available IRQ flags, from +all the possible regiters, to be restored later in the EnableIRQ. +*/ +#if( MSP430_ENABLE_RTC_HANDLER== 1) +unsigned char rtcctl0_bck = 0; +unsigned char rtcps0ctl_bck = 0; //the RTCPS0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char rtcps1ctl_bck = 0; //the RTCPS1CTL is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_PORT2_HANDLER== 1) +unsigned char p2ie_bck = 0; +#endif + +#if( MSP430_ENABLE_PORT1_HANDLER==1 ) +unsigned char p1ie_bck = 0; +#endif + +#if( MSP430_ENABLE_TIMER2_A1_HANDLER== 1) +unsigned char ta2ctl_bck = 0; //the TA2CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta2cctl1_bck = 0; //the TA2CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta2cctl2_bck = 0; //the TA2CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) +unsigned char ta2cctl0_bck = 0; +#endif + +#if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) +unsigned char ta1ctl_bck = 0; //the TA1CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1cctl0_bck = 0; //the TA1CCTL0 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1cctl1_bck = 0; //the TA1CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1cctl2_bck = 0; //the TA1CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) +unsigned char ta0ctl_bck = 0; //the TA0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl1_bck = 0; //the TA0CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl2_bck = 0; //the TA0CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl3_bck = 0; //the TA0CCTL3 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl4_bck = 0; //the TA0CCTL4 is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) +unsigned char ta0cctl0_bck = 0; //the TA0CCTL0 is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) +unsigned char tb0ctl_bck = 0; //the TB0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl1_bck = 0; //the TB0CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl2_bck = 0; //the TB0CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl3_bck = 0; //the TB0CCTL3 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl4_bck = 0; //the TB0CCTL4 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl5_bck = 0; //the TB0CCTL5 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl6_bck = 0; //the TB0CCTL6 is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) +unsigned char tb0cctl0_bck = 0; //the TB0CCTL0 is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_DMA_HANDLER==1 ) +unsigned char dma0ctl_bck = 0; //the DMA0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char dma1ctl_bck = 0; //the DMA1CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char dma2ctl_bck = 0; //the DMA2CTL is 16bit wide, but the IRQ flags are in the lower byte +#endif + +#if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) +unsigned char uca0ie_bck = 0; +unsigned char uca1ie_bck = 0; +#endif + +#if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) +unsigned char ucb0ie_bck = 0; +#endif + +#if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) +unsigned char ucb1ie_bck = 0; +#endif + +#if( MSP430_ENABLE_ADC12_HANDLER==1 ) +unsigned char adc12ctl0_bck = 0; //the ADC12CTL0 is 16bit wide, but the IRQ flags are in the lower byte +unsigned short adc12ie_bck = 0; +#endif + +//TODO: OPTIMIZAR SOLO AGREGANDO LOS CASES BASADOS EN LOS ISR QUE DEFINA EL USUARIO EN EL OIL + +/** +Enable the backed up IRQ signals (done within MSP430_DisableIRQ). +SEE SLAS590 (TABLE 4) +*/ +void MSP430_EnableIRQ(unsigned char irQ_number) +{ + switch( irQ_number ) + { +#if( MSP430_ENABLE_RTC_HANDLER== 1) + case 0: // => "RTC", + /* RTCRDYIE, RTCTEVIE, RTCAIE, RT0PSIE, RT1PSIE */ + /**/ + RTCCTL0 |= ( rtcctl0_bck & (RTCTEVIE|RTCAIE|RTCRDYIE) ); + RTCPS0CTL |= ( rtcps0ctl_bck & RT0PSIE ); + RTCPS1CTL |= ( rtcps1ctl_bck & RT1PSIE ); + break; +#endif + +#if( MSP430_ENABLE_PORT2_HANDLER==1) + case 1 : //=> "PORT2", + /* P2IE.0 to P2IE.7*/ + P2IE = p2ie_bck; + break; +#endif + +#if( MSP430_ENABLE_TIMER2_A1_HANDLER==1) + case 2 : //=> "TIMER2_A1", + /* TA2CCR1 CCIE1 to TA2CCR2 CCIE2, TA2IE*/ + TA2CTL |= ( ta2ctl_bck & TAIE ); + TA2CCTL1 |= ( ta2cctl1_bck & CCIE ); + TA2CCTL2 |= ( ta2cctl2_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) + case 3 : //=> "TIMER2_A0", + /* TA2CCR0 CCIE0 */ + TA2CCTL0 |= ( ta2cctl0_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) + case 4 : //=> "USCI_B1", + /* UCB1RXIE, UCB1TXIE */ + UCB1IE |= ( ucb1ie_bck & (UCRXIE|UCTXIE) ); + break; +#endif + +#if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) + case 5 : //=> "USCI_A1", + /* UCA1RXIE, UCA1TXIE */ + UCA1IE |= ( uca1ie_bck & (UCRXIE|UCTXIE) ); + break; +#endif + +#if( MSP430_ENABLE_PORT1_HANDLER==1 ) + case 6 : //=> "PORT1", + /* P1IE.0 to P1IE.7 */ + P1IE = p1ie_bck; + break; +#endif + +#if( MSP430_ENABLE_TIMER1_A1_HANDLER==1 ) + case 7 : //=> "TIMER1_A1", + /* TA1CCR1 CCIE1 to TA1CCR2 CCIE2 TA1IE*/ + TA1CTL |= ( ta1ctl_bck & TAIE ); + TA1CCTL1 |= ( ta1cctl1_bck & CCIE ); + TA1CCTL2 |= ( ta1cctl2_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) + case 8 : //=> "TIMER1_A0", + /* TA1CCR0 CCIE0 */ + TA1CCTL0 |= ( ta1cctl0_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_DMA_HANDLER==1 ) + case 9 : //=> "DMA", + /* DMA0IE, DMA1IE, DMA2IE */ + DMA0CTL |= ( dma0ctl_bck & DMAIE ); + DMA1CTL |= ( dma1ctl_bck & DMAIE ); + DMA2CTL |= ( dma2ctl_bck & DMAIE ); + break; +#endif + +#if( MSP430_ENABLE_USB_UBM_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 10: // => "USB_UBM", + /* USB interrupts */ + USBPWRCTL |= VBOFFIE|VBONIE|VUOVLIE; + USBPLLIR |= USBOORIE|USBLOSIE|USBOOLIE; + USBIEPCNF_0 |=USBIIE; + USBOEPCNF_0 |=USBIIE; + USBIEPIE = 0XFF; + USBOEPIE = 0XFF; + USBMAINT |=UTIE; + USBIE |= RSTRIE|SUSRIE|RESRIE|SETUPIE|STPOWIE; + + USBIEPCNF_0 |= USBIIE; + USBOEPCNF_0 |= USBIIE; + + USBIEPCNF_1 |= USBIIE; + USBOEPCNF_1 |= USBIIE; + USBIEPCNF_2 |= USBIIE; + USBOEPCNF_2 |= USBIIE; + USBIEPCNF_3 |= USBIIE; + USBOEPCNF_3 |= USBIIE; + USBIEPCNF_4 |= USBIIE; + USBOEPCNF_4 |= USBIIE; + USBIEPCNF_5 |= USBIIE; + USBOEPCNF_5 |= USBIIE; + USBIEPCNF_6 |= USBIIE; + USBOEPCNF_6 |= USBIIE; + USBIEPCNF_7 |= USBIIE; + USBOEPCNF_7 |= USBIIE; + break; +#endif + +#if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) + case 11: // => "TIMER0_A1", + /* TA0CCR1 CCIE1 to TA0CCR4 CCIE4 TA0IE */ + TA0CTL |= ( ta0ctl_bck & TAIE ); + TA0CCTL1 |= ( ta0cctl1_bck & CCIE ); + TA0CCTL2 |= ( ta0cctl2_bck & CCIE ); + TA0CCTL3 |= ( ta0cctl3_bck & CCIE ); + TA0CCTL4 |= ( ta0cctl4_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) + case 12: // => "TIMER0_A0", + /* TA0CCR0 CCIE0 */ + TA0CCTL0 |= ( ta0cctl0_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_ADC12_HANDLER==1 ) + case 13: // => "ADC12", + /* ADC12IE0 to ADC12IE15 */ + ADC12CTL0 |= ( adc12ctl0_bck & (ADC12OVIE|ADC12TOVIE) ); + ADC12IE = adc12ie_bck; + break; +#endif + +#if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) + case 14: // => "USCI_B0", + /* UCB0RXIE, UCB0TXIE */ + UCB0IE |= ( ucb0ie_bck & (UCRXIE|UCTXIE) ); + break; +#endif + +#if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) + case 15: // => "USCI_A0", + /* UCA0RXIE, UCA0TXIE */ + UCA0IE |= ( uca0ie_bck & (UCRXIE|UCTXIE) ); + break; +#endif + +#if( MSP430_ENABLE_WDT_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 16: // => "WDT", + /* WDTIE */ + break; +#endif + +#if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) + case 17: // => "TIMER0_B1", + /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ + TB0CTL |= ( tb0ctl_bck & TAIE ); + TB0CCTL1 |= ( tb0cctl1_bck & CCIE ); + TB0CCTL2 |= ( tb0cctl2_bck & CCIE ); + TB0CCTL3 |= ( tb0cctl3_bck & CCIE ); + TB0CCTL4 |= ( tb0cctl4_bck & CCIE ); + TB0CCTL5 |= ( tb0cctl5_bck & CCIE ); + TB0CCTL6 |= ( tb0cctl6_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) + case 18: // => "TIMER0_B0", + /* TB0CCR0 CCIE0 */ + TB0CCTL0 |= ( tb0cctl0_bck & CCIE ); + break; +#endif + +#if( MSP430_ENABLE_COMP_B_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 19: // => "COMP_B", + /* Comparator B interrupt flags */ + break; +#endif + +#if( MSP430_ENABLE_UNMI_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 20: // => "UNMI", + break; +#endif + +#if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) +#error SHOULD NOT BE IMPLEMENTED + case 21: // => "SYSNMI", + /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ + break; +#endif + +#if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) +#error SHOULD NOT BE IMPLEMENTED + case 22: // => "RESET" + /* WDTIE, KEYV */ + break; +#endif + + + default: + break; +} + //TODO: remove system IRQ vectors and OS + //TODO: FALTA USB +} + + +/* +*/ +void MSP430_DisableIRQ(unsigned char irQ_number) +{ + switch(irQ_number) + { +#if( MSP430_ENABLE_RTC_HANDLER== 1) + case 0: // => "RTC", + /* RTCRDYIE, RTCTEVIE, RTCAIE, RT0PSIE, RT1PSIE */ + + //backup the register/s + rtcctl0_bck = RTCCTL0 ; + rtcps0ctl_bck = RTCPS0CTL ; + rtcps1ctl_bck = RTCPS1CTL ; + + //clear all flags + RTCCTL0 &=~( RTCTEVIE|RTCAIE|RTCRDYIE); + RTCPS0CTL &=~ RT0PSIE; + RTCPS1CTL &=~ RT1PSIE; + break; +#endif + +#if( MSP430_ENABLE_PORT2_HANDLER== 1) + case 1 : //=> "PORT2", + /* P2IE.0 to P2IE.7*/ + + //backup the register/s + p2ie_bck = P2IE; + + //clear all flags + P2IE = 0x00; + break; +#endif + +#if( MSP430_ENABLE_TIMER2_A1_HANDLER== 1) + case 2 : //=> "TIMER2_A1", + /* TA2CCR1 CCIE1 to TA2CCR2 CCIE2, TA2IE*/ + + //backup the register/s + ta2ctl_bck = TA2CTL ; + ta2cctl1_bck = TA2CCTL1; + ta2cctl2_bck = TA2CCTL2; + + //clear all flags + TA2CTL &=~ TAIE; + TA2CCTL1 &=~ CCIE; + TA2CCTL2 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) + case 3 : //=> "TIMER2_A0", + /* TA2CCR0 CCIE0 */ + + //backup the register/s + ta2cctl0_bck = TA2CCTL0; + + //clear all flags + TA2CCTL0 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) + case 4 : //=> "USCI_B1", + /* UCB1RXIE, UCB1TXIE */ + + //backup the register/s + ucb1ie_bck = UCB1IE; + + //clear all flags + UCB1IE &=~ (UCRXIE|UCTXIE); + break; +#endif + +#if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) + case 5 : //=> "USCI_A1", + /* UCA1RXIE, UCA1TXIE */ + + //backup the register/s + uca1ie_bck = UCA1IE; + + //clear all flags + UCA1IE &=~ (UCRXIE|UCTXIE); + break; +#endif + +#if( MSP430_ENABLE_PORT1_HANDLER== 1) + case 6 : //=> "PORT1", + /* P1IE.0 to P1IE.7 */ + //backup the register/s + p1ie_bck = P1IE; + + //clear all flags + P1IE = 0x00; + break; +#endif + +#if( MSP430_ENABLE_TIMER1_A1_HANDLER==1 ) + case 7 : //=> "TIMER1_A1", + /* TA1CCR1 CCIE1 to TA1CCR2 CCIE2 TA1IE*/ + + //backup the register/s + ta1ctl_bck = TA1CTL ; + ta1cctl1_bck = TA1CCTL1; + ta1cctl2_bck = TA1CCTL2; + + //clear all flags + TA1CTL &=~ TAIE; + TA1CCTL1 &=~ CCIE; + TA1CCTL2 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) + case 8 : //=> "TIMER1_A0", + /* TA1CCR0 CCIE0 */ + //backup the register/s + ta1cctl0_bck = TA1CCTL0; + + //clear all flags + TA1CCTL0 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_DMA_HANDLER==1 ) + case 9 : //=> "DMA", + /* DMA0IE, DMA1IE, DMA2IE */ + + //backup the register/s + dma0ctl_bck = DMA0CTL; + dma1ctl_bck = DMA1CTL; + dma2ctl_bck = DMA2CTL; + + //clear all flags + DMA0CTL &=~ DMAIE; + DMA1CTL &=~ DMAIE; + DMA2CTL &=~ DMAIE; + break; +#endif + +#if( MSP430_ENABLE_USB_UBM_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 10: // => "USB_UBM", + /* USB interrupts */ + USBPWRCTL &=~ (VBOFFIE|VBONIE|VUOVLIE); + USBPLLIR &=~ (USBOORIE|USBLOSIE|USBOOLIE); + USBIEPCNF_0 &=~ USBIIE; + USBOEPCNF_0 &=~ USBIIE; + USBIEPIE = 0XFF; + USBOEPIE = 0XFF; + USBMAINT &=~ UTIE; + USBIE &=~ (RSTRIE|SUSRIE|RESRIE|SETUPIE|STPOWIE); + + USBIEPCNF_0 &=~ USBIIE; + USBOEPCNF_0 &=~ USBIIE; + + USBIEPCNF_1 &=~ USBIIE; + USBOEPCNF_1 &=~ USBIIE; + USBIEPCNF_2 &=~ USBIIE; + USBOEPCNF_2 &=~ USBIIE; + USBIEPCNF_3 &=~ USBIIE; + USBOEPCNF_3 &=~ USBIIE; + USBIEPCNF_4 &=~ USBIIE; + USBOEPCNF_4 &=~ USBIIE; + USBIEPCNF_5 &=~ USBIIE; + USBOEPCNF_5 &=~ USBIIE; + USBIEPCNF_6 &=~ USBIIE; + USBOEPCNF_6 &=~ USBIIE; + USBIEPCNF_7 &=~ USBIIE; + USBOEPCNF_7 &=~ USBIIE; + break; +#endif + +#if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) + case 11: // => "TIMER0_A1", + /* TA0CCR1 CCIE1 to TA0CCR4 CCIE4 TA0IE */ + + //backup the register/s + ta0ctl_bck= TA0CTL ; + ta0cctl1_bck= TA0CCTL1; + ta0cctl2_bck= TA0CCTL2; + ta0cctl3_bck= TA0CCTL3; + ta0cctl4_bck= TA0CCTL4; + + //clear all flags + TA0CTL &=~ TAIE; + TA0CCTL1 &=~ CCIE; + TA0CCTL2 &=~ CCIE; + TA0CCTL3 &=~ CCIE; + TA0CCTL4 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) + case 12: // => "TIMER0_A0", + /* TA0CCR0 CCIE0 */ + //backup the register/s + ta0cctl0_bck = TA0CCTL0; + + //clear all flags + TA0CCTL0 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_ADC12_HANDLER==1 ) + case 13: // => "ADC12", + /* ADC12IE0 to ADC12IE15 */ + + //backup the register/s + adc12ctl0_bck = ADC12CTL0; + adc12ie_bck = ADC12IE; + + //clear all flags + ADC12CTL0 &=~ (ADC12OVIE|ADC12TOVIE); + ADC12IE = 0x0000; + break; +#endif + +#if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) + case 14: // => "USCI_B0", + /* UCB0RXIE, UCB0TXIE */ + + //backup the register/s + ucb0ie_bck = UCB0IEUCB0IE; + + //clear all flags + UCB0IE &=~ (UCRXIE|UCTXIE); + break; +#endif + +#if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) + case 15: // => "USCI_A0", + /* UCA0RXIE, UCA0TXIE */ + + + //backup the register/s + uca0ie_bck = UCA0IE; + + //clear all flags + UCA0IE &=~ (UCRXIE|UCTXIE); + break; +#endif + +#if( MSP430_ENABLE_WDT_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 16: // => "WDT", + /* WDTIE */ + break; +#endif + +#if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) + case 17: // => "TIMER0_B1", + /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ + + //backup the register/s + tb0ctl_bck = TB0CTL ; + tb0cctl1_bck = TB0CCTL1 ; + tb0cctl2_bck = TB0CCTL2 ; + tb0cctl3_bck = TB0CCTL3 ; + tb0cctl4_bck = TB0CCTL4 ; + tb0cctl5_bck = TB0CCTL5 ; + tb0cctl6_bck = TB0CCTL6 ; + + //clear all flags + TB0CTL &=~ TAIE; + TB0CCTL1 &=~ CCIE; + TB0CCTL2 &=~ CCIE; + TB0CCTL3 &=~ CCIE; + TB0CCTL4 &=~ CCIE; + TB0CCTL5 &=~ CCIE; + TB0CCTL6 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) + case 18: // => "TIMER0_B0", + /* TB0CCR0 CCIE0 */ + + //backup the register/s + tb0cctl0_bck = TB0CCTL0; + + //clear all flags + TB0CCTL0 &=~ CCIE; + break; +#endif + +#if( MSP430_ENABLE_COMP_B_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 19: // => "COMP_B", + /* Comparator B interrupt flags */ + break; +#endif + +#if( MSP430_ENABLE_UNMI_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 20: // => "UNMI", + break; +#endif + +#if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) +#error SHOULD NOT BE IMPLEMENTED + case 21: // => "SYSNMI", + /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ + break; +#endif + +#if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) +#error SHOULD NOT BE IMPLEMENTED + case 22: // => "RESET" + /* WDTIE, KEYV */ + break; +#endif + + default: + break; + } +} + /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index 5ed2d115..a008bd72 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -81,7 +81,7 @@ void StartOs_Arch_Cpu(void) { StartOs_Arch_System(); //TODO: this should be placed in other file. For cortex processors is placed within the reset vector handler. StartOs_Arch_SystemTick(); - Enable_User_ISRs(); + //Enable_User_ISRs(); //USER ISRs SHOULD BE ENABLED BY THE USER USING a_MSP430ware Libraries or OS buildin Drivers. } /** From bfcf08b01516fa2a422490fc7940b4418a19c848 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 5 Jun 2016 18:20:34 -0300 Subject: [PATCH 13/42] - se corrigen bugs en interrupciones de cambio de contexto y de tick. - se corrige bug relacionado con bug de hw. - --- inc/msp430/Os_Arch.h | 17 +++++++++------ inc/msp430/Os_Internal_Arch.h | 2 +- src/ActivateTask.c | 6 ++--- src/Schedule.c | 2 +- src/msp430/Os_Arch.c | 2 ++ src/msp430/Os_Internal_Arch.c | 41 ++++++++++++++++++++--------------- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index 45146fbd..ec5a20a7 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -70,7 +70,7 @@ /*==================[macros]=================================================*/ /***************************************************************************** - * Please define here all needed macros that will be visible to the OS user + * Please define here all needed macros that will be visiblsee to the OS user * for this architecutre. This means that anyone including os.h will have * access to this definitions if the actual architecutre is used. * @@ -83,13 +83,12 @@ /** \brief Disable All Interrupts Arch */ #define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() - - + /** \brief All Interrupts Arch Common Objects ** ** This macro shall define common objects to imlement Suspend and Resume **/ -#define CommonAllInterrupts() unsigned short SR_BACK___; +#define CommonAllInterrupts() volatile unsigned short SR_BACK___; /** \brief Suspend All Interrupts Arch @@ -99,8 +98,8 @@ ** to workarround the hw bug cpu39 describer in slaz314h.pdf **/ - -#define SuspendAllInterrupts_Arch() __asm volatile("mov SR, SR_BACK___");\ +//__asm volatile("mov SR, SR_BACK___"); +#define SuspendAllInterrupts_Arch() SR_BACK___ = _get_SR_register(); \ __asm volatile("dint"); \ __asm volatile("nop"); @@ -117,7 +116,11 @@ #define ResumeAllInterrupts_Arch() __asm volatile("eint") */ -#define ResumeAllInterrupts_Arch() if( SR_BACK___ & 0x0008 ) __asm volatile("eint"); +#define ResumeAllInterrupts_Arch() if( SR_BACK___ & GIE ) \ + { \ + __asm volatile("eint"); \ + __asm volatile("nop");\ + } \ /** \brief Resume OS Interrupts Arch diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index ceff4bd6..cdf7f370 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -244,7 +244,7 @@ extern TaskType TerminatingTask; ** Enable OS configured interrupts (ISR1 and ISR2). This macro ** is called only ones in StartUp.c function. **/ -#define EnableOSInterrupts() __asm volatile("eint") +#define EnableOSInterrupts() __asm volatile("eint"); __asm volatile("nop"); /** \brief Enable Interruptions ** diff --git a/src/ActivateTask.c b/src/ActivateTask.c index cc3c1dfd..932b85d1 100644 --- a/src/ActivateTask.c +++ b/src/ActivateTask.c @@ -64,10 +64,10 @@ /*==================[internal functions definition]==========================*/ /*==================[external functions definition]==========================*/ - StatusType ActivateTask +StatusType ActivateTask ( TaskType TaskID - ) +) { /* \req OSEK_SYS_3.1 The system service StatusType * ActivateTask ( TaskType TaskID ) shall be defined. */ @@ -79,7 +79,7 @@ /* \req OSEK_SYS_3.1.7-1/3 Possible return values in Standard mode are E_OK or E_OS_LIMIT */ StatusType ret = E_OK; - IntSecure_Common(); + IntSecure_Common(); #if (OSEK_MULTICORE == OSEK_ENABLE) if ((TaskID - TASKS_COUNT) < REMOTE_TASKS_COUNT) diff --git a/src/Schedule.c b/src/Schedule.c index ed05a75e..b2e5dea4 100644 --- a/src/Schedule.c +++ b/src/Schedule.c @@ -91,7 +91,7 @@ extern StatusType Schedule ContextType actualContext; #endif -IntSecure_Common(); + IntSecure_Common(); IntSecure_Start(); diff --git a/src/msp430/Os_Arch.c b/src/msp430/Os_Arch.c index 03867917..14ebd35a 100644 --- a/src/msp430/Os_Arch.c +++ b/src/msp430/Os_Arch.c @@ -74,6 +74,8 @@ /*==================[external functions definition]==========================*/ + + /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index ef801c16..85c7b91e 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -113,19 +113,8 @@ void InitStack_Arch(uint8 TaskID) } -/** - OSEK periodic interrupt is implemented using TimerA_2 timer module. -*/ -__attribute__( (__interrupt__(TIMER2_A0_VECTOR),naked)) -void OSEK_ISR_TIMER2_A0_VECTOR(void) +inline void TickProcess() { - /* - It's not necessary to disable global irqs. - It is done automatically when the SP is cleared. - */ - /* This handler service the periodic interrupt. - */ - /* Clear the IRQ flag*/ Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_0); /* store the calling context in a variable */ @@ -160,6 +149,22 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) PostIsr2_Arch(isr); } #endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */ +} + +/** + OSEK periodic interrupt is implemented using TimerA_2 timer module. +*/ +__attribute__( (__interrupt__(TIMER2_A0_VECTOR) ,naked )) // +void OSEK_ISR_TIMER2_A0_VECTOR(void) +{ + /* + It's not necessary to disable global irqs. + It is done automatically when the SP is cleared. + */ + /* This handler service the periodic interrupt. + */ + /* Clear the IRQ flag*/ + TickProcess(); RETURN_FROM_NAKED_ISR(); /*return from Tick ISR */ } @@ -174,11 +179,11 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) __attribute__( (__interrupt__(TIMER2_A1_VECTOR),naked)) void OSEK_ISR_TIMER2_A1_VECTOR(void) { - /* Clear the IRQ flag*/ - unsigned short local_taiv = TA2IV; + register unsigned short local_taiv = TA2IV; if( local_taiv & TA2IV_TACCR1) // { + /* Clear the IRQ flag*/ Timer_A_disableCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1 ); Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1); @@ -188,10 +193,10 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) /* Context save r4 to r15 r0 = PC automatically saved by HW when handler is serviced r1 = SP - r3 = SR automatically saved by HW when handler is serviced - r4 = CG doesn't care + r2 = SR automatically saved by HW when handler is serviced + r3 = CG doesn't care */ - SAVE_CONTEXT(); + SAVE_CONTEXT(); /* exchange stack pointers */ if( Osek_OldTaskPtr_Arch != NULL ) @@ -206,7 +211,7 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) Context restore r4 to r15 It does not Include the reti instruction. */ - RESTORE_CONTEXT() + RESTORE_CONTEXT() } RETURN_FROM_NAKED_ISR(); /*return from ISR*/ From 75c15b6a1293d2ff5e2bdafc08c9e7e5f64d601b Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 5 Jun 2016 19:41:56 -0300 Subject: [PATCH 14/42] - Post and Pre ISR2 macro/functiones are called parametrized egains the IRQ handler that is executed. - The array where each architecture defines the IRQ handler list, is placed in a separated file than Os_Internal_Arch_Cfg.c.php --- gen/src/Os_Internal_Cfg.c.php | 28 ++++++------ gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 54 +---------------------- gen/src/msp430/Os_Internal_Defs.php | 46 +++++++++++++++++++ 3 files changed, 62 insertions(+), 66 deletions(-) create mode 100644 gen/src/msp430/Os_Internal_Defs.php diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 3d9408f4..0b7992ec 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -65,18 +65,6 @@ /* get tasks */ $tasks = getLocalList("/OSEK", "TASK"); -/* -if( $definitions["ARCH"]== "msp430") -{ - $stack_element_type = "uint16"; -} -else -{ - $stack_element_type = "uint8"; -} - -$stack_element_cast_type = "(". $stack_element_type . "*)"; */ //TODO DELETE - foreach ($tasks as $task) { print "/** \brief $task stack */\n"; @@ -498,7 +486,13 @@ /*==================[external functions definition]==========================*/ getValue("/OSEK/" . $int,"INTERRUPT"); @@ -513,8 +507,14 @@ ?> void OSEK_ISR2_(void) { + /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); + /* set isr 2 context */ SetActualContext(CONTEXT_ISR2); @@ -530,7 +530,9 @@ ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) { /* this shall force a call to the scheduler */ - PostIsr2_Arch(isr); + } #endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */ } diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 5b76f8c5..a3715bb2 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -75,59 +75,7 @@ /*==================[external data definition]===============================*/ "RTC", - 1 => "PORT2", - 2 => "TIMER2_A1", - 3 => "TIMER2_A0", - 4 => "USCI_B1", - 5 => "USCI_A1", - 6 => "PORT1", - 7 => "TIMER1_A1", - 8 => "TIMER1_A0", - 9 => "DMA", - 10 => "USB_UBM", - 11 => "TIMER0_A1", - 12 => "TIMER0_A0", - 13 => "ADC12", - 14 => "USCI_B0", - 15 => "USCI_A0", - 16 => "WDT", - 17 => "TIMER0_B1", - 18 => "TIMER0_B0", - 19 => "COMP_B", - 20 => "UNMI", - 21 => "SYSNMI", - 22 => "RESET", - ); - break; - - default: - error("the CPU " . $definitions["CPU"] . " is not supported."); - break; -} - -$MAX_INT_COUNT = max(array_keys($intList))+1; - -#if (CPU == msp430f5529) - -#else -#error Not supported CPU -#endif - -/** \brief Handlers used by OSEK */ - - -/*==================[internal functions definition]==========================*/ -/* Default exception handlers */ - +include 'Os_Internal_Defs.php'; ?> /*==================[external functions definition]==========================*/ diff --git a/gen/src/msp430/Os_Internal_Defs.php b/gen/src/msp430/Os_Internal_Defs.php new file mode 100644 index 00000000..5f09a5bc --- /dev/null +++ b/gen/src/msp430/Os_Internal_Defs.php @@ -0,0 +1,46 @@ + "RTC", + 1 => "PORT2", + 2 => "TIMER2_A1", + 3 => "TIMER2_A0", + 4 => "USCI_B1", + 5 => "USCI_A1", + 6 => "PORT1", + 7 => "TIMER1_A1", + 8 => "TIMER1_A0", + 9 => "DMA", + 10 => "USB_UBM", + 11 => "TIMER0_A1", + 12 => "TIMER0_A0", + 13 => "ADC12", + 14 => "USCI_B0", + 15 => "USCI_A0", + 16 => "WDT", + 17 => "TIMER0_B1", + 18 => "TIMER0_B0", + 19 => "COMP_B", + 20 => "UNMI", + 21 => "SYSNMI", + 22 => "RESET", + ); + break; + + default: + error("the CPU " . $definitions["CPU"] . " is not supported."); + break; +} + +$MAX_INT_COUNT = max(array_keys($intList))+1; + +?> From 94b37968444f4e3b6ecc26d28b7aa70ce2eb22d8 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 5 Jun 2016 22:15:14 -0300 Subject: [PATCH 15/42] - Se agrega funcion PreIsr2_Arch() y se ejecuta en todas los handlers de IRQ de tipo 2. - 1er Test Funcional TM 01 funcionando! --- gen/src/msp430/Os_Internal_Defs.php | 51 ++++++- inc/msp430/Os_Internal_Arch.h | 4 +- src/msp430/Os_Arch.c | 2 +- src/msp430/Os_Internal_Arch.c | 228 +++++++++++++++++++++++++++- 4 files changed, 274 insertions(+), 11 deletions(-) diff --git a/gen/src/msp430/Os_Internal_Defs.php b/gen/src/msp430/Os_Internal_Defs.php index 5f09a5bc..1daeb39f 100644 --- a/gen/src/msp430/Os_Internal_Defs.php +++ b/gen/src/msp430/Os_Internal_Defs.php @@ -1,7 +1,56 @@ +/******************************************************** + * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* + ********************************************************/ + +/* + * Copyright 2016 Franco Bucafusco + * + * This file is part of CIAA Firmware. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** \brief FreeOSEK Os Support File for MSP430 Architectures. + ** + ** \file Os_Internal_Defs.php + ** + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + "RTC", + break; +#endif + +#if( MSP430_ENABLE_PORT2_HANDLER== 1) + case 1 : //=> "PORT2", + dummy = P2IV; + /* There is no need to clear the flag manually: From MSP430f5529 User manually + + " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If +another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + + */ + + break; +#endif + +#if( MSP430_ENABLE_TIMER2_A1_HANDLER== 1) +#error TODO: SHOULD NOT BE IMPLEMENTED. THIS IRQ IS RESERVED FOR RTOS FUNCTIONALITY + case 2 : //=> "TIMER2_A1", + + break; +#endif + +#if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 3 : //=> "TIMER2_A0", + + break; +#endif + +#if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 4 : //=> "USCI_B1", + + break; +#endif + +#if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 5 : //=> "USCI_A1", + + break; +#endif + +#if( MSP430_ENABLE_PORT1_HANDLER== 1) + case 6 : //=> "PORT1", + dummy = P1IV; + /* There is no need to clear the flag manually: From MSP430f5529 User manually + + " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If +another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + + */ + + /* if( P1IV_P1IFG0==dummy ) + { + // P1IFG &= ~0x01; + } + else if( P1IV_P1IFG1==dummy ) + { + // P1IFG &= ~0x02; + } + else if( P1IV_P1IFG2==dummy ) + { + // P1IFG &= ~0x04; + } + else if( P1IV_P1IFG3==dummy ) + { + // P1IFG &= ~0x08; + } + else if( P1IV_P1IFG4==dummy ) + { + //P1IFG &= ~0x10; + } + else if( P1IV_P1IFG5==dummy ) + { + //P1IFG &= ~0x20; + } + else if( P1IV_P1IFG6==dummy ) + { + // P1IFG &= ~0x40; + } + else if( P1IV_P1IFG7==dummy ) + { + //P1IFG &= ~0x80; + }*/ + break; +#endif + +#if( MSP430_ENABLE_TIMER1_A1_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 7 : //=> "TIMER1_A1", + + break; +#endif + +#if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 8 : //=> "TIMER1_A0", + + break; +#endif + +#if( MSP430_ENABLE_DMA_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 9 : //=> "DMA", + + break; +#endif + +#if( MSP430_ENABLE_USB_UBM_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 10: // => "USB_UBM", + + break; +#endif + +#if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 11: // => "TIMER0_A1", + + break; +#endif + +#if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 12: // => "TIMER0_A0", + + break; +#endif + +#if( MSP430_ENABLE_ADC12_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 13: // => "ADC12", + + break; +#endif + +#if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) + case 14: // => "USCI_B0", + + break; +#endif + +#if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 15: // => "USCI_A0", + + break; +#endif + +#if( MSP430_ENABLE_WDT_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 16: // => "WDT", + /* WDTIE */ + break; +#endif + +#if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 17: // => "TIMER0_B1", + + break; +#endif + +#if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 18: // => "TIMER0_B0", + + break; +#endif + +#if( MSP430_ENABLE_COMP_B_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 19: // => "COMP_B", + /* Comparator B interrupt flags */ + break; +#endif + +#if( MSP430_ENABLE_UNMI_HANDLER==1 ) +#error TODO: NOT IMPLEMENTED + case 20: // => "UNMI", + break; +#endif + +#if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) +#error SHOULD NOT BE IMPLEMENTED + case 21: // => "SYSNMI", + /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ + break; +#endif + +#if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) +#error SHOULD NOT BE IMPLEMENTED + case 22: // => "RESET" + /* WDTIE, KEYV */ + break; +#endif + } +} /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ From ad536bc299c62eeee88eb13507f1b3eb1b9101dc Mon Sep 17 00:00:00 2001 From: FRANCO Date: Mon, 6 Jun 2016 00:37:16 -0300 Subject: [PATCH 16/42] - se mejoran algunos phps y se implementa el wrapper de las irq tipo 1 --- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 5 +- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 26 ++++- .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 6 +- inc/os.h | 6 +- src/msp430/Os_Internal_Arch.c | 94 +++++++++---------- 5 files changed, 75 insertions(+), 62 deletions(-) diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index 88412cf3..12aa5f4c 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -94,13 +94,10 @@ $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); - print "#define MSP430_ENABLE_". $source . "_HANDLER 1 \n"; - + print "#define MSP430_ENABLE_". $source . "_HANDLER 1 \n"; } ?> - - /*==================[external functions declaration]=========================*/ void Enable_User_ISRs(void); diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index a3715bb2..9934c1ff 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -96,17 +96,16 @@ } } - /*** Non Used Interrupt handlers ***/ +/*** Non Used Interrupt handlers ***/ log->error("Interrupt $int type $inttype has an invalid category $intcat"); } + + break; #the irq was found, break the inner loop } } @@ -145,10 +146,25 @@ if($src_found == 0) { + #for an undefined ISR witihn the OIL file, we defiene a DUMMY handler. print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; print "{\n"; - print "}\n"; + print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile + print "}\n\n"; + } + else + { + if( $intcat == 1 ) + { + #for an ISR type 1 witihn the OIL file, we defiene a ISR wrapper that calls the ISR defined by the user somewhere. + print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) \n"; + print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]) somewhere */ \n"; + print "{\n"; + print " OSEK_ISR_$intList[$i]_VECTOR();\n"; + print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile + print "}\n\n"; + } } } ?> diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index be445674..78dfd81a 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -84,12 +84,14 @@ ** This macro shall be used to start the definition of all ISR category 1 or 2. ** ** \param[in] name name of the ISR category 1 or 2. - **/ + **//* #ifdef CTESTS_MODIFIERS #define ISR(name) void OSEK_ISR_ ## name (void) #else #define ISR(name) __attribute__( (__interrupt__(name))) void OSEK_ISR_ ## name (void) -#endif +#endif*/ +//#define ISR(name) __attribute__( (__interrupt__(name))) void OSEK_ISR_ ## name (void) + /*==================[typedef]================================================*/ diff --git a/inc/os.h b/inc/os.h index 28d94060..c3329980 100644 --- a/inc/os.h +++ b/inc/os.h @@ -74,10 +74,10 @@ ** \param[in] name name of the ISR category 1 or 2. **/ -/* -#ifndef ISR + /* +#ifndef ISR*/ #define ISR(name) void OSEK_ISR_ ## name (void) -#endif +/*#endif */ /** \brief ALARMCALLBACK macro definition diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index f438e554..f5a843df 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -766,7 +766,6 @@ void MSP430_DisableIRQ(unsigned char irQ_number) case 15: // => "USCI_A0", /* UCA0RXIE, UCA0TXIE */ - //backup the register/s uca0ie_bck = UCA0IE; @@ -787,7 +786,7 @@ void MSP430_DisableIRQ(unsigned char irQ_number) /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ //backup the register/s - tb0ctl_bck = TB0CTL ; + tb0ctl_bck = TB0CTL ; tb0cctl1_bck = TB0CCTL1 ; tb0cctl2_bck = TB0CCTL2 ; tb0cctl3_bck = TB0CCTL3 ; @@ -867,14 +866,13 @@ void PreIsr2_Arch(unsigned short irQ_number) #if( MSP430_ENABLE_PORT2_HANDLER== 1) case 1 : //=> "PORT2", - dummy = P2IV; - /* There is no need to clear the flag manually: From MSP430f5529 User manually - - " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If -another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + dummy = P2IV; + /* There is no need to clear the flag manually: From MSP430f5529 User manually - */ + " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If + another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + */ break; #endif @@ -908,46 +906,46 @@ another interrupt flag is set, another interrupt is immediately generated after #if( MSP430_ENABLE_PORT1_HANDLER== 1) case 6 : //=> "PORT1", - dummy = P1IV; - /* There is no need to clear the flag manually: From MSP430f5529 User manually - - " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If -another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " - - */ - - /* if( P1IV_P1IFG0==dummy ) - { - // P1IFG &= ~0x01; - } - else if( P1IV_P1IFG1==dummy ) - { - // P1IFG &= ~0x02; - } - else if( P1IV_P1IFG2==dummy ) - { - // P1IFG &= ~0x04; - } - else if( P1IV_P1IFG3==dummy ) - { - // P1IFG &= ~0x08; - } - else if( P1IV_P1IFG4==dummy ) - { - //P1IFG &= ~0x10; - } - else if( P1IV_P1IFG5==dummy ) - { - //P1IFG &= ~0x20; - } - else if( P1IV_P1IFG6==dummy ) - { - // P1IFG &= ~0x40; - } - else if( P1IV_P1IFG7==dummy ) - { - //P1IFG &= ~0x80; - }*/ + dummy = P1IV; + /* There is no need to clear the flag manually: From MSP430f5529 User manually + + " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If + another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + + */ + + /* if( P1IV_P1IFG0==dummy ) + { + // P1IFG &= ~0x01; + } + else if( P1IV_P1IFG1==dummy ) + { + // P1IFG &= ~0x02; + } + else if( P1IV_P1IFG2==dummy ) + { + // P1IFG &= ~0x04; + } + else if( P1IV_P1IFG3==dummy ) + { + // P1IFG &= ~0x08; + } + else if( P1IV_P1IFG4==dummy ) + { + //P1IFG &= ~0x10; + } + else if( P1IV_P1IFG5==dummy ) + { + //P1IFG &= ~0x20; + } + else if( P1IV_P1IFG6==dummy ) + { + // P1IFG &= ~0x40; + } + else if( P1IV_P1IFG7==dummy ) + { + //P1IFG &= ~0x80; + }*/ break; #endif From ee565aa40a3ffaeb4eea988e9202c5ebefed56bb Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sat, 11 Jun 2016 18:57:54 -0300 Subject: [PATCH 17/42] =?UTF-8?q?-=20se=20resuelve=20el=20tema=20de=20las?= =?UTF-8?q?=20IRQ=20de=20tipo=202.=20-=20Ahora=20se=20limpian=20flags=20pe?= =?UTF-8?q?ndientes=20dentro=20de=20PostIsr2=5FArch=20y=20no=20en=20"Pre..?= =?UTF-8?q?.".=20Eso=20permite=20al=20usuario=20evaluar=20cual=20es=20la?= =?UTF-8?q?=20IRQ=20pendiente,=20en=20el=20handler=20definido=20por=20?= =?UTF-8?q?=C3=A9l.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/src/Os_Internal_Cfg.c.php | 41 ++++++++++++++++------------------- inc/Os_Internal.h | 17 ++++++++++++++- inc/msp430/Os_Internal_Arch.h | 8 +++---- inc/x86/Os_Internal_Arch.h | 4 +--- src/msp430/Os_Internal_Arch.c | 17 +++++++-------- 5 files changed, 48 insertions(+), 39 deletions(-) diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 0b7992ec..08cf91da 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -83,6 +83,7 @@ } print "#endif\n"; + print "\n"; } print "\n"; @@ -90,8 +91,8 @@ { print "/** \brief $task context */\n"; print "TaskContextType ContextTask" . $task . ";\n"; + print "\n"; } -print "\n"; /* Ready List */ foreach ($priority as $prio) @@ -105,7 +106,8 @@ $count += $config->getValue("/OSEK/" . $task, "ACTIVATION"); } } - print "TaskType ReadyList" . $prio . "[" . $count . "];\n\n"; + print "TaskType ReadyList" . $prio . "[" . $count . "];\n"; + print "\n"; } $counters = getLocalList("/OSEK", "COUNTER"); @@ -222,6 +224,7 @@ print " 0 /* core */\n"; } print " }"; + print "\n"; } print "\n"; ?> @@ -500,18 +503,19 @@ if ($intcat == 2) { - if($definitions["ARCH"] == "msp430") - { - print "__attribute__( (__interrupt__($int))) /*Wrapper ISR handler for $int */\n"; - } - ?> + $key = array_search( $inttype , $intList ); + if($definitions["ARCH"] == "msp430") + { + print "/* Wrapper ISR handler for $int */\n"; + print "__attribute__( (__interrupt__($int)))\n"; + } +?> void OSEK_ISR2_(void) { + /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); @@ -524,22 +528,15 @@ /* reset context */ SetActualContext(actualContext); -#if (NON_PREEMPTIVE == OSEK_DISABLE) - /* check if the actual task is preemptive */ - if ( ( CONTEXT_TASK == actualContext ) && - ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) - { - /* this shall force a call to the scheduler */ - - } -#endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */ + + + AfterIsr2_Schedule() ; } /** @} doxygen end group definition */ diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index 0b2571b7..966b5946 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -185,6 +185,22 @@ #define Schedule_WOChecks() Schedule() #endif + +/** \brief AfterIsr2_Schedule + ** + ** This macro conditionally calls the schedule if there is any task with "Full Schedule" attribute. + ** + **/ +#if ( NON_PREEMPTIVE == OSEK_DISABLE ) +#define AfterIsr2_Schedule() if( ( CONTEXT_TASK == actualContext ) && \ + ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) \ + { \ + Schedule_WOChecks(); \ + } +#else +#define AfterIsr2_Schedule() +#endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */ + /*==================[typedef]================================================*/ /** \brief ContextType ** @@ -261,4 +277,3 @@ extern CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncre /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_H_ */ - diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 97cbffd7..7838c47d 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -287,15 +287,15 @@ extern TaskType TerminatingTask; /** \brief Pre ISR Macrol ** - ** This function is called every time that an ISR Cat 2 is started + ** This macro is called every time that an ISR Cat 2 is started **/ - void PreIsr2_Arch(unsigned short isr); +#define PreIsr2_Arch(isr) /** \brief Post ISR Macro ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) Schedule_WOChecks() +#define PostIsr2_Arch(isr) ClearPendingIRQ_Arch(isr) /** \brief ShutdownOs Arch service ** @@ -310,7 +310,7 @@ extern TaskType TerminatingTask; /*==================[external functions declaration]=========================*/ void InitStack_Arch(uint8 TaskID); - +void ClearPendingIRQ_Arch(unsigned short irQ_number); /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/inc/x86/Os_Internal_Arch.h b/inc/x86/Os_Internal_Arch.h index a56ea7d9..6c03adc0 100644 --- a/inc/x86/Os_Internal_Arch.h +++ b/inc/x86/Os_Internal_Arch.h @@ -252,8 +252,7 @@ ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) \ - Schedule_WOChecks(); +#define PostIsr2_Arch(isr) #if ( CPUTYPE == ia64 ) #define SaveOsStack() \ @@ -408,4 +407,3 @@ extern void OSEK_ISR_HWTimer1(void); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ - diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index f5a843df..0b803005 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -141,14 +141,7 @@ inline void TickProcess() /* reset context */ SetActualContext(actualContext); -#if (NON_PREEMPTIVE == OSEK_DISABLE) - /* check if the actual task is preemptive */ - if ( ( CONTEXT_TASK == actualContext ) && ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) - { - /* this shall force a call to the scheduler */ - PostIsr2_Arch(isr); - } -#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */ + AfterIsr2_Schedule(); } /** @@ -166,6 +159,12 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) /* Clear the IRQ flag*/ TickProcess(); + /* + This handler calls TickProcess because it is defined as naked, and therefore the compiler do not save regiters. + The same happens with the RETI instruction that is inserted in the last macro. + Calling the function, the compiler saves the neede registers. + */ + RETURN_FROM_NAKED_ISR(); /*return from Tick ISR */ } @@ -852,7 +851,7 @@ void MSP430_DisableIRQ(unsigned char irQ_number) /* for a given irq_number it clear the flag that made the handler to be called. */ -void PreIsr2_Arch(unsigned short irQ_number) +void ClearPendingIRQ_Arch(unsigned short irQ_number) { volatile unsigned char dummy; From d60b912bc7c776697d2a8c04155ea3d406078552 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 12 Jun 2016 14:32:36 -0300 Subject: [PATCH 18/42] - Modificaciones para MSP430-GCC 4_00_01_00 - Avance con ejecucion de tests en cadena. --- gen/src/Os_Internal_Cfg.c.php | 2 +- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 8 ++++---- .../fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 6 +++--- inc/msp430/Os_Internal_Arch.h | 4 +++- inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h | 4 ++-- src/msp430/Os_Internal_Arch.c | 10 ++++++---- tst/ctest/dbg/msp430/gcc/debug.scr | 3 ++- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 08cf91da..a6dc7c8a 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -507,7 +507,7 @@ if($definitions["ARCH"] == "msp430") { print "/* Wrapper ISR handler for $int */\n"; - print "__attribute__( (__interrupt__($int)))\n"; + print "__attribute__( (__interrupt_vec__($int)))\n"; } ?> void OSEK_ISR2_(void) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 9934c1ff..23add8c0 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -80,7 +80,7 @@ /*==================[external functions definition]==========================*/ -__attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +__attribute__( (__interrupt_vec__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ void OSEK_ISR_UNMI_VECTOR(void) { while (1) @@ -88,7 +88,7 @@ } } -__attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +__attribute__( (__interrupt_vec__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ void OSEK_ISR_SYSNMI_VECTOR(void) { while (1) @@ -147,7 +147,7 @@ if($src_found == 0) { #for an undefined ISR witihn the OIL file, we defiene a DUMMY handler. - print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; + print "__attribute__( (__interrupt_vec__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; print "{\n"; print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile @@ -158,7 +158,7 @@ if( $intcat == 1 ) { #for an ISR type 1 witihn the OIL file, we defiene a ISR wrapper that calls the ISR defined by the user somewhere. - print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) \n"; + print "__attribute__( (__interrupt_vec__($intList[$i]_VECTOR),naked)) \n"; print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]) somewhere */ \n"; print "{\n"; print " OSEK_ISR_$intList[$i]_VECTOR();\n"; diff --git a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 56ac45b5..7f83488e 100644 --- a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -132,7 +132,7 @@ /*==================[external functions definition]==========================*/ -__attribute__( (__interrupt__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +__attribute__( (__interrupt_vec__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ void OSEK_ISR_UNMI_VECTOR(void) { while (1) @@ -140,7 +140,7 @@ } } -__attribute__( (__interrupt__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +__attribute__( (__interrupt_vec__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ void OSEK_ISR_SYSNMI_VECTOR(void) { while (1) @@ -197,7 +197,7 @@ if($src_found == 0) { - print "__attribute__( (__interrupt__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; + print "__attribute__( (__interrupt_vec__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; print "{\n"; print "}\n"; diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 7838c47d..7ca833b0 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -295,7 +295,7 @@ extern TaskType TerminatingTask; ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) ClearPendingIRQ_Arch(isr) +#define PostIsr2_Arch(isr) ClearPendingIRQ_Arch(isr) /** \brief ShutdownOs Arch service ** @@ -311,6 +311,8 @@ extern TaskType TerminatingTask; /*==================[external functions declaration]=========================*/ void InitStack_Arch(uint8 TaskID); void ClearPendingIRQ_Arch(unsigned short irQ_number); +void MSP430_EnableIRQ(unsigned char irQ_number); +void MSP430_DisableIRQ(unsigned char irQ_number); /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index 78dfd81a..500a18e8 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -88,9 +88,9 @@ #ifdef CTESTS_MODIFIERS #define ISR(name) void OSEK_ISR_ ## name (void) #else -#define ISR(name) __attribute__( (__interrupt__(name))) void OSEK_ISR_ ## name (void) +#define ISR(name) __attribute__( (__interrupt_vec__(name))) void OSEK_ISR_ ## name (void) #endif*/ -//#define ISR(name) __attribute__( (__interrupt__(name))) void OSEK_ISR_ ## name (void) +//#define ISR(name) __attribute__( (__interrupt_vec__(name))) void OSEK_ISR_ ## name (void) /*==================[typedef]================================================*/ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 0b803005..b2e69941 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -113,8 +113,9 @@ void InitStack_Arch(uint8 TaskID) } -inline void TickProcess() +void TickProcess() { + /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_0); /* store the calling context in a variable */ @@ -147,7 +148,7 @@ inline void TickProcess() /** OSEK periodic interrupt is implemented using TimerA_2 timer module. */ -__attribute__( (__interrupt__(TIMER2_A0_VECTOR) ,naked )) // +__attribute__( (__interrupt_vec__(TIMER2_A0_VECTOR) ,naked )) // void OSEK_ISR_TIMER2_A0_VECTOR(void) { /* @@ -175,7 +176,7 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) ** Note 1: It's not necessary to disable global irqs. ** It is done automatically when the SP is cleared by HW **/ -__attribute__( (__interrupt__(TIMER2_A1_VECTOR),naked)) +__attribute__( (__interrupt_vec__(TIMER2_A1_VECTOR),naked)) void OSEK_ISR_TIMER2_A1_VECTOR(void) { register unsigned short local_taiv = TA2IV; @@ -183,6 +184,7 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) if( local_taiv & TA2IV_TACCR1) // { /* Clear the IRQ flag*/ + /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ Timer_A_disableCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1 ); Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1); @@ -853,7 +855,7 @@ for a given irq_number it clear the flag that made the handler to be called. */ void ClearPendingIRQ_Arch(unsigned short irQ_number) { - volatile unsigned char dummy; + volatile unsigned char dummy; //ignore compiling warning switch(irQ_number) { diff --git a/tst/ctest/dbg/msp430/gcc/debug.scr b/tst/ctest/dbg/msp430/gcc/debug.scr index ec981ae8..2dc38bea 100644 --- a/tst/ctest/dbg/msp430/gcc/debug.scr +++ b/tst/ctest/dbg/msp430/gcc/debug.scr @@ -1,6 +1,7 @@ target remote localhost:2000 +monitor erase load -set $pc = __msp430_resetvec_hook +monitor reset break ConfTestFinish continue dump value out/rtos/TestResults.bin TestResults From 4c64fe38ff1337c7eb16a2f25cb9bd736c33966e Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 12 Jun 2016 16:20:10 -0300 Subject: [PATCH 19/42] Correccion de migracion anterior --- gen/src/Os_Internal_Cfg.c.php | 8 +++++--- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 15 +++++++++------ .../gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 6 +++--- inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h | 4 ++-- src/msp430/Os_Internal_Arch.c | 5 +++-- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index a6dc7c8a..71d83b58 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -503,11 +503,13 @@ if ($intcat == 2) { + print "/* Wrapper ISR handler for $int */\n"; + $key = array_search( $inttype , $intList ); if($definitions["ARCH"] == "msp430") - { - print "/* Wrapper ISR handler for $int */\n"; - print "__attribute__( (__interrupt_vec__($int)))\n"; + { + #print "__attribute__( (__interrupt_vec($int)))\n"; + print "interrupt_vec($int) \n"; } ?> void OSEK_ISR2_(void) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 23add8c0..53de6b7a 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -79,8 +79,8 @@ ?> /*==================[external functions definition]==========================*/ - -__attribute__( (__interrupt_vec__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +//__attribute__( (__interrupt_vec(UNMI_VECTOR),naked)) +interrupt_vec(UNMI_VECTOR) __attribute__((naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ void OSEK_ISR_UNMI_VECTOR(void) { while (1) @@ -88,7 +88,8 @@ } } -__attribute__( (__interrupt_vec__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +//__attribute__( (__interrupt_vec(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +interrupt_vec(SYSNMI_VECTOR) __attribute__((naked)) void OSEK_ISR_SYSNMI_VECTOR(void) { while (1) @@ -147,8 +148,9 @@ if($src_found == 0) { #for an undefined ISR witihn the OIL file, we defiene a DUMMY handler. - print "__attribute__( (__interrupt_vec__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; - print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; + #print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; + print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked)) \n"; + print "void OSEK_ISR_$intList[$i]_VECTOR(void) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */ \n"; print "{\n"; print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile print "}\n\n"; @@ -158,7 +160,8 @@ if( $intcat == 1 ) { #for an ISR type 1 witihn the OIL file, we defiene a ISR wrapper that calls the ISR defined by the user somewhere. - print "__attribute__( (__interrupt_vec__($intList[$i]_VECTOR),naked)) \n"; + #print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) \n"; + print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked))"; print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]) somewhere */ \n"; print "{\n"; print " OSEK_ISR_$intList[$i]_VECTOR();\n"; diff --git a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 7f83488e..8102e070 100644 --- a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -132,7 +132,7 @@ /*==================[external functions definition]==========================*/ -__attribute__( (__interrupt_vec__(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +__attribute__( (__interrupt_vec(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ void OSEK_ISR_UNMI_VECTOR(void) { while (1) @@ -140,7 +140,7 @@ } } -__attribute__( (__interrupt_vec__(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +__attribute__( (__interrupt_vec(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ void OSEK_ISR_SYSNMI_VECTOR(void) { while (1) @@ -197,7 +197,7 @@ if($src_found == 0) { - print "__attribute__( (__interrupt_vec__($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; + print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; print "{\n"; print "}\n"; diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index 500a18e8..83889d0d 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -88,9 +88,9 @@ #ifdef CTESTS_MODIFIERS #define ISR(name) void OSEK_ISR_ ## name (void) #else -#define ISR(name) __attribute__( (__interrupt_vec__(name))) void OSEK_ISR_ ## name (void) +#define ISR(name) __attribute__( (interrupt_vec(name))) void OSEK_ISR_ ## name (void) #endif*/ -//#define ISR(name) __attribute__( (__interrupt_vec__(name))) void OSEK_ISR_ ## name (void) +//#define ISR(name) __attribute__( (interrupt_vec(name))) void OSEK_ISR_ ## name (void) /*==================[typedef]================================================*/ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index b2e69941..159d96c4 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -148,7 +148,8 @@ void TickProcess() /** OSEK periodic interrupt is implemented using TimerA_2 timer module. */ -__attribute__( (__interrupt_vec__(TIMER2_A0_VECTOR) ,naked )) // +//__attribute__( (interrupt_vec(TIMER2_A0_VECTOR) ,naked )) // +interrupt_vec(TIMER2_A0_VECTOR) __attribute__((naked)) void OSEK_ISR_TIMER2_A0_VECTOR(void) { /* @@ -176,7 +177,7 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) ** Note 1: It's not necessary to disable global irqs. ** It is done automatically when the SP is cleared by HW **/ -__attribute__( (__interrupt_vec__(TIMER2_A1_VECTOR),naked)) +interrupt_vec(TIMER2_A1_VECTOR) __attribute__((naked)) void OSEK_ISR_TIMER2_A1_VECTOR(void) { register unsigned short local_taiv = TA2IV; From 20f9a6b57f951c23677ebc81cf57f101ab609595 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Mon, 13 Jun 2016 00:57:57 -0300 Subject: [PATCH 20/42] - deplaced some assembly lines for intrinsic functions defined by TI. - FreeOSEK for MSP430 uses mspdebug to run tests (without gdb) --- inc/msp430/Os_Arch.h | 23 ++++----------- inc/msp430/Os_Internal_Arch.h | 11 +++++-- src/msp430/Os_Internal_Arch.c | 2 +- tst/ctest/bin/ctest.pl | 46 +++++++++++++++++++++--------- tst/ctest/dbg/msp430/gcc/debug.scr | 23 +++++++-------- 5 files changed, 58 insertions(+), 47 deletions(-) diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index ec5a20a7..b8d12e03 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -83,7 +83,7 @@ /** \brief Disable All Interrupts Arch */ #define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() - + /** \brief All Interrupts Arch Common Objects ** ** This macro shall define common objects to imlement Suspend and Resume @@ -96,33 +96,22 @@ ** This macro shall suspend (disable) all interrupts. ** NOTE: the nop operation after the dint instruction was inserted ** to workarround the hw bug cpu39 describer in slaz314h.pdf + ** Also noted in Slau208, page 59. **/ - -//__asm volatile("mov SR, SR_BACK___"); #define SuspendAllInterrupts_Arch() SR_BACK___ = _get_SR_register(); \ - __asm volatile("dint"); \ - __asm volatile("nop"); + _disable_interrupts() ; + -/* -#define SuspendAllInterrupts_Arch() __asm volatile("dint"); \ - __asm volatile("nop"); -*/ /** \brief Resume All Interrupts Arch ** ** This macro shall resume (enable) all interrupts. **/ -/* - #define ResumeAllInterrupts_Arch() __asm volatile("eint") -*/ - #define ResumeAllInterrupts_Arch() if( SR_BACK___ & GIE ) \ { \ - __asm volatile("eint"); \ - __asm volatile("nop");\ + _enable_interrupts() ; \ } \ - - + /** \brief Resume OS Interrupts Arch ** ** This macro shall resume (enable) all interrupts configured on the diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 7ca833b0..bf9892a1 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -244,7 +244,10 @@ extern TaskType TerminatingTask; ** Enable OS configured interrupts (ISR1 and ISR2). This macro ** is called only ones in StartUp.c function. **/ -#define EnableOSInterrupts() __asm volatile("eint"); __asm volatile("nop"); +#define EnableOSInterrupts() _enable_interrupts(); + + + /** \brief Enable Interruptions ** @@ -263,8 +266,10 @@ extern TaskType TerminatingTask; ** NOTE: the nop operation after the dint instruction was inserted ** to workarround the hw bug cpu39 described in slaz314h.pdf **/ -#define DisableOSInterrupts() __asm volatile("dint"); \ - __asm volatile("nop"); +#define DisableOSInterrupts() _disable_interrupts(); + + + /** \brief Disable Interruptions ** diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 159d96c4..35cb8c4f 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -208,7 +208,7 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) } asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); asm volatile ( "mov @r6, SP \n\t" ); - + /* Context restore r4 to r15 It does not Include the reti instruction. diff --git a/tst/ctest/bin/ctest.pl b/tst/ctest/bin/ctest.pl index 6ddb35ce..baa45070 100755 --- a/tst/ctest/bin/ctest.pl +++ b/tst/ctest/bin/ctest.pl @@ -239,7 +239,10 @@ sub searchandreplace $s = @_[1]; $r = @_[2]; - `perl -pi -e 's/$s/$r/' $file`; + print "File: $file S: $s R: $r\n"; + + #`perl -pi -e 's/$s/$r/g' $file`; + `perl -pi -e 's{$s}{$r}g' $file`; close(OUT); } @@ -346,7 +349,13 @@ sub readparam when ("TESTS") { $TESTS = $val; } when ("RES") { $RES = $val; } when ("TESTCASES") { $TESTCASES = $val; } - default { } + default + { + if ("msp430" eq $ARCH) + { + $PROXY = $val; + } + } } } close CFG; @@ -815,20 +824,29 @@ sub logffull info("debug of $test in $out"); $dbgfile = "modules/rtos/tst/ctest/dbg/" . $ARCH . "/gcc/debug.scr"; - info("$GDB $out -x $dbgfile"); - if($debug == 0) + if ("msp430" eq $ARCH) + { + $newdbgfile = "out/rtos/$test/debug_script.scr"; + #for MSP430 the binary file is appended inside the script + copy($dbgfile,$newdbgfile ) or die "Script copy failed: $!"; + searchandreplace($newdbgfile ,"filename","$out"); + + $debug_command = "$PROXY -C $newdbgfile exit"; + + info("$debug_command"); + } + else { - #print("probando debug\n"); - #before calling gdb, for msp430, I have to run the proxy (mspdebug) - #how is done in cortex with open ocd? TODO + $debug_command = "$GDB $out -x $dbgfile"; - if( $ARCH eq "msp430" ) #degun franco - { - info("Running $MSPDEBUG_BIN $MSPDEBUG_PROTOCOL"); - } + info("$debug_command"); + } - $outdbg = `$GDB $out -x $dbgfile`; + if($debug == 0) + { + #$outdbg = `$GDB $out -x $dbgfile`; + $outdbg = `$debug_command`; if ($ARCH eq "x86") { @@ -844,7 +862,7 @@ sub logffull } else { - print("probando\n"); + print("=== Modo Debug Del Script de Perl === \n"); exec("$GDB $out"); $outdbg = ""; } @@ -853,7 +871,9 @@ sub logffull info("debug status: $outdbgstatus"); info("debug output:\n$outdbg"); logffull("$GDB output:\n$outgdb"); + $outdbgstatus = 0; + if ($outdbgstatus == 0) { results("******************************************************"); diff --git a/tst/ctest/dbg/msp430/gcc/debug.scr b/tst/ctest/dbg/msp430/gcc/debug.scr index 2dc38bea..2ac22606 100644 --- a/tst/ctest/dbg/msp430/gcc/debug.scr +++ b/tst/ctest/dbg/msp430/gcc/debug.scr @@ -1,13 +1,10 @@ -target remote localhost:2000 -monitor erase -load -monitor reset -break ConfTestFinish -continue -dump value out/rtos/TestResults.bin TestResults -dump value out/rtos/TestResultsOk.bin TestResultsOk -dump value out/rtos/SequenceCounter.bin SequenceCounter -dump value out/rtos/SequenceCounterOk.bin SequenceCounterOk -dump value out/rtos/ConfTestResult.bin ConfTestResult -kill -quit +opt fet_block_size 512 +prog filename +reset +setbreak ConfTestFinish +run +save_raw TestResults 35 out/rtos/TestResults.bin +save_raw TestResultsOk 35 out/rtos/TestResultsOk.bin +save_raw SequenceCounter 4 out/rtos/SequenceCounter.bin +save_raw SequenceCounterOk 4 out/rtos/SequenceCounterOk.bin +save_raw ConfTestResult 1 out/rtos/ConfTestResult.bin From de4962a9b9a258e2464107cc3e7d626fd020bb82 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Fri, 17 Jun 2016 01:36:03 -0300 Subject: [PATCH 21/42] - se mejora el generador, rspecto de la parte que asigna flags para los eventos. - Se corrigen algunas cosas del .pl --- gen/inc/Os_Cfg.h.php | 199 ++++++++++++++++++++-- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 4 +- 2 files changed, 188 insertions(+), 15 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index f52e3871..85ad78d6 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -71,9 +71,9 @@ #define OSEK_OS_INTERRUPT_MASK ((InterruptFlagsType)0xFFFFFFFFU) 0) { foreach ($remote_tasks as $task) @@ -95,23 +96,194 @@ print "\n"; } -/* Define the Applications Modes */ -$appmodes = $config->getList("/OSEK","APPMODE"); +/* +DEFINE EVENTS +*/ -foreach ($appmodes as $count=>$appmode) +/* the max ammount of events is defined by the bit width of EventTypeMask type*/ +if( $definitions["ARCH"]== "msp430") { - print "/** \brief Definition of the Application Mode $appmode */\n"; - print "#define " . $appmode . " " . $count . "\n"; + $max_amount_events = 16; } -print "\n"; +else +{ + $max_amount_events = 32; +} + +$flags_shared_event = $max_amount_events; /* it stores the number of bit for flags that are shared across tasks */ + +$matriz = array( ); /* it stores the events' name for each task */ +$matrix_n = array(); /* it stores the events' assigned number for each task */ + +$events = $config->getList("/OSEK","EVENT"); /* obtain all possible events from oil file */ +//$nro_evs= max(array_keys($events))+1; +$nro_evs= count($events); +#print("cantidad de eventos: $nro_evs \n"); + +/* task/events matrix creation, and various validations */ +$task_index = 0; +foreach( $tasks as $task ) +{ + $empty_array = array(); + + /*for each task we get the defined events*/ + array_push( $matriz , $config->getList("/OSEK/". $task , "EVENT" ) ); + array_push( $matrix_n , $empty_array ); + + $nro_ev_task = count($matriz[$task_index]); #max(array_keys($matriz[$task_index])); + + //print("evento $nro_ev_task"); + + /* Task Type validation: validates that this task is extended */ + $extended = $config->getValue("/OSEK/" . $task, "TYPE"); + + if ($extended != "EXTENDED" && $nro_ev_task>0 ) + { + throw new Exception("===== OIL ERROR: The task $task could be TYPE: EXTENDED =====\n"); + } + else + { + // print("es extended"); + if ($nro_ev_task == 0 ) + { +//print("es extended mal"); + trigger_error("===== OIL WARNING: The task $task could be TYPE: BASIC =====\n", E_USER_WARNING); + } + } + + /* Task Event Validation: validates that the defined event within the task is globally defined */ + foreach( $matriz[$task_index] as $evi ) + { + /* search the task event in the global event array */ + $key = array_search( $events , $matriz[$task_index] ); + if($key===0 ) + { + throw new Exception("===== OIL ERROR: The event $evi for task $task is not globally defined =====\n"); + /* stops execution */ + } + else + { + } + } + + $task_index++; +} + +/* generation of the shared events between tasks */ +print "\n/** \brief Shared events across tasks */\n\n"; +foreach( $events as $ev ) //para cada evento, lo busco en cada +{ + //print( "//Procesando evento $ev \n" ); + $count = 0; //cuenta la cantidad de ocurrencias + $task_index = 0; + + foreach( $tasks as $task ) + { + $events_for_task = $config->getList("/OSEK/". $task , "EVENT" ); + $key = array_search( $ev, $matriz[$task_index] ); //busco el evento en el array de eventos de la tarea. + + if($key===0 ) + { + $count++; + unset($matriz[$task_index][$key]); //LO SACO DE LA TABLA DE EVENTOS DE LA TAREA + } + else + { + } + $task_index++; + } + + if($count>1) + { + /* there is more that one task with the current event */ + $flags_shared_event--; + + if($flags_shared_event<0 ) + { + throw new Exception("===== OIL ERROR: There are more than $max_amount_events events defined. =====\n"); + /* stops execution */ + } + + print "/** \brief Definition of the Event: $ev */\n"; + print "#define " . $ev . " 0x" . sprintf ("%xU", (1<<$flags_shared_event)) . "\n"; + + /* this shared's event number is stored in matrix_n */ + $task_index = 0; + foreach( $tasks as $task ) + { + array_push( $matrix_n[$task_index] , $flags_shared_event ); + $task_index++; + } + } +} + +print "\n\n/** \brief Exclusive events for each task */\n\n"; + +$task_index =0; + + +foreach( $tasks as $task ) +{ + $flags_exc_event = 0; /* it stores the number of bit for flags that are exclusively for one task */ + foreach( $matriz[$task_index] as $ev ) + { + if($flags_exc_event>$max_amount_events ) + { + throw new Exception("===== OIL ERROR: There are more than $max_amount_events events defined. =====\n"); + /* stops execution */ + } + + print "/** \brief Definition of the Event: $ev for task: $task*/\n"; + print "#define " . $ev . " 0x" . sprintf ("%xU", (1<<$flags_exc_event)) . "\n"; + + $temp = $flags_exc_event; + array_push( $matrix_n[$task_index] , $temp ); + + $flags_exc_event++; + } + + $task_index++; +} + +/* Last validation: check if events repeats */ +$task_index =0; +foreach ($matrix_n as $array) +{ + #print_r($array); + $count_values = array_count_values($matrix_n[$task_index]) ; /* it counts the times that repeats an event number, all of them should be 1*/ + #print_r($count_values); + foreach ($count_values as $key => $value) + { + #print_r($value); + if($value>1) + { + throw new Exception("===== OIL ERROR: There are more events that the task can handle. =====\n"); + /* stops execution */ + } + } + $task_index ++; +} + /* Define the Events */ -$events = $config->getList("/OSEK","EVENT"); -foreach ($events as $count=>$event) +//$events = $config->getList("/OSEK","EVENT"); + +//foreach ($events as $count=>$event) +//{ +// print "/** \brief Definition of the Event $event */\n"; +// print "#define " . $event . " 0x" . sprintf ("%xU", (1<<$count)) . "\n"; +//} +//print "\n"; + + +/* Define the Applications Modes */ +$appmodes = $config->getList("/OSEK","APPMODE"); + +foreach ($appmodes as $count=>$appmode) { - print "/** \brief Definition of the Event $event */\n"; - print "#define " . $event . " 0x" . sprintf ("%xU", (1<<$count)) . "\n"; + print "/** \brief Definition of the Application Mode $appmode */\n"; + print "#define " . $appmode . " " . $count . "\n"; } print "\n"; @@ -355,4 +527,3 @@ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_CFG_H_ */ - diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 53de6b7a..f7529e8c 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -105,7 +105,8 @@ for($i=0; $i < $MAX_INT_COUNT; $i++) { $src_found = 0; - + $intcat = 0 ; + foreach($intnames as $int) { /* @@ -142,6 +143,7 @@ UNMI: defined in this file SYSNMI: defined in this file */ + $intcat = 0 ; $src_found = 1; } From 8dbfe10e22bdffd775d91b41d23a1ad96260143f Mon Sep 17 00:00:00 2001 From: FRANCO Date: Fri, 17 Jun 2016 13:26:47 -0300 Subject: [PATCH 22/42] - minimum changes --- gen/inc/Os_Cfg.h.php | 40 ++++++++++++--------- gen/inc/Os_Internal_Cfg.h.php | 13 +++++++ gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php | 10 ++++++ gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php | 9 +++++ gen/src/mips/Os_Internal_Arch_Cfg.c.php | 5 +++ tst/ctest/bin/ctest.pl | 2 +- 6 files changed, 62 insertions(+), 17 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 85ad78d6..73917452 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -3,6 +3,7 @@ ********************************************************/ /* Copyright 2008, 2009, 2015 Mariano Cerdeiro + * Copyright 2016 Franco Bucafusco * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar @@ -62,6 +63,15 @@ /** \addtogroup FreeOSEK_Os_Global ** @{ */ +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20150619 v0.1.4 MaCe fix issue #279 + * 20090719 v0.1.3 MaCe rename file to Os_ + * 20090424 v0.1.2 MaCe add counters defines + * 20090128 v0.1.1 MaCe add MEMMAP off configuration + * 20080810 v0.1.0 MaCe initial version + */ /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ @@ -96,9 +106,18 @@ print "\n"; } -/* -DEFINE EVENTS -*/ +/* Define the Applications Modes */ +$appmodes = $config->getList("/OSEK","APPMODE"); + +foreach ($appmodes as $count=>$appmode) +{ + print "/** \brief Definition of the Application Mode $appmode */\n"; + print "#define " . $appmode . " " . $count . "\n"; +} +print "\n"; + + +/* Define the Events */ /* the max ammount of events is defined by the bit width of EventTypeMask type*/ if( $definitions["ARCH"]== "msp430") @@ -263,10 +282,8 @@ } $task_index ++; } - - -/* Define the Events */ - +print "\n"; + //$events = $config->getList("/OSEK","EVENT"); //foreach ($events as $count=>$event) @@ -277,15 +294,6 @@ //print "\n"; -/* Define the Applications Modes */ -$appmodes = $config->getList("/OSEK","APPMODE"); - -foreach ($appmodes as $count=>$appmode) -{ - print "/** \brief Definition of the Application Mode $appmode */\n"; - print "#define " . $appmode . " " . $count . "\n"; -} -print "\n"; /* Define the Resources */ $resources = $config->getList("/OSEK","RESOURCE"); diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index a4740a58..024ed335 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -53,6 +53,19 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ + +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * 20090719 v0.1.7 MaCe rename file to Os_ + * 20090331 v0.1.6 MaCe add USERESSCHEDULER evaluation + * 20090330 v0.1.5 MaCe add NO_EVENTS macro + * 20090327 v0.1.4 MaCe add declaration of the start task for the app. modes + * 20090131 v0.1.3 MaCe add extern to CountersVar declaration + * 20090130 v0.1.2 MaCe add OSEK_MEMMAP check + * 20090128 v0.1.1 MaCe remove OSEK_ENABLE and OSEK_DISABLE macro, now defined in OpenGEN + * 20080713 v0.1.0 MaCe initial version + */ Date: Fri, 17 Jun 2016 18:54:51 -0300 Subject: [PATCH 23/42] - Bug in event definition generation, resolved - Change in the way of generate exceptions - Added ALARM_COUNT in Os_Internal_Cfg - Added conditional compilation of alarms objects (Const and Var) if ALARM_COUNT=0 - Added conditional compilation of resource objects (Const and Var) if RESOURCE_COUNT=0 - For MSP430 ISR(x) validation was added. In case the user writes down a wrong ISR name, an exception ocurr. - --- gen/inc/Os_Cfg.h.php | 45 ++-- gen/inc/Os_Internal_Cfg.h.php | 7 +- gen/src/Os_Internal_Cfg.c.php | 265 ++++++++++++-------- gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php | 12 +- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 40 ++- src/StartOS.c | 3 +- 6 files changed, 230 insertions(+), 142 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 73917452..428a050d 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -144,9 +144,10 @@ foreach( $tasks as $task ) { $empty_array = array(); + $temp_array = $config->getList("/OSEK/". $task , "EVENT" ); /*for each task we get the defined events*/ - array_push( $matriz , $config->getList("/OSEK/". $task , "EVENT" ) ); + array_push( $matriz , $temp_array ); array_push( $matrix_n , $empty_array ); $nro_ev_task = count($matriz[$task_index]); #max(array_keys($matriz[$task_index])); @@ -158,7 +159,7 @@ if ($extended != "EXTENDED" && $nro_ev_task>0 ) { - throw new Exception("===== OIL ERROR: The task $task could be TYPE: EXTENDED =====\n"); + trigger_error("===== OIL ERROR: The task $task could be TYPE: EXTENDED =====\n", E_USER_ERROR); } else { @@ -175,9 +176,9 @@ { /* search the task event in the global event array */ $key = array_search( $events , $matriz[$task_index] ); - if($key===0 ) + if( $key !== false ) { - throw new Exception("===== OIL ERROR: The event $evi for task $task is not globally defined =====\n"); + trigger_error("===== OIL ERROR: The event $evi for task $task is not globally defined =====\n", E_USER_ERROR); /* stops execution */ } else @@ -188,30 +189,35 @@ $task_index++; } + /* generation of the shared events between tasks */ print "\n/** \brief Shared events across tasks */\n\n"; -foreach( $events as $ev ) //para cada evento, lo busco en cada +$ev_index = 0; + +foreach( $events as $ev ) //para cada evento, lo busco en cada array de eventos para la tarea { //print( "//Procesando evento $ev \n" ); - $count = 0; //cuenta la cantidad de ocurrencias $task_index = 0; + $count=0; //almacena la cuenta de cuantas tareas tiene el evento + $task_single_event = ""; //almacena la ultima tarea en la cual encontro el evento + foreach( $tasks as $task ) { - $events_for_task = $config->getList("/OSEK/". $task , "EVENT" ); - $key = array_search( $ev, $matriz[$task_index] ); //busco el evento en el array de eventos de la tarea. + #$events_for_task = $config->getList("/OSEK/". $task , "EVENT" ); + $key = array_search( $ev, $matriz[$task_index] ); - if($key===0 ) + if( $key !== false ) //busco el evento en el array de eventos de la tarea. { + /* lo encontro */ $count++; - unset($matriz[$task_index][$key]); //LO SACO DE LA TABLA DE EVENTOS DE LA TAREA - } - else - { } + $task_index++; } + //print_r("\n$ev $count \n" ); + if($count>1) { /* there is more that one task with the current event */ @@ -219,7 +225,7 @@ if($flags_shared_event<0 ) { - throw new Exception("===== OIL ERROR: There are more than $max_amount_events events defined. =====\n"); + trigger_error("===== OIL ERROR: There are more than $max_amount_events events defined. =====\n", E_USER_ERROR); /* stops execution */ } @@ -230,20 +236,21 @@ $task_index = 0; foreach( $tasks as $task ) { + unset($matriz[$task_index][$ev]); //LO SACO DE LA TABLA DE EVENTOS DE LA TAREA array_push( $matrix_n[$task_index] , $flags_shared_event ); $task_index++; } } + + $ev_index++; } print "\n\n/** \brief Exclusive events for each task */\n\n"; - -$task_index =0; - - +$task_index = 0; foreach( $tasks as $task ) { $flags_exc_event = 0; /* it stores the number of bit for flags that are exclusively for one task */ + foreach( $matriz[$task_index] as $ev ) { if($flags_exc_event>$max_amount_events ) @@ -283,7 +290,7 @@ $task_index ++; } print "\n"; - + //$events = $config->getList("/OSEK","EVENT"); //foreach ($events as $count=>$event) diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index 024ed335..5213ed39 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -314,8 +314,8 @@ function remove_doubles($a) } } ?> -#define ALARM_AUTOSTART_COUNT - +#define ALARM_COUNT +#define ALARM_AUTOSTART_COUNT getList("/OSEK","RESOURCE"); +$resources_count = count($resources); print "/** \brief Resources Priorities */\n"; -print "extern const TaskPriorityType ResourcesPriority[" . count($resources) . "];\n\n"; +print "extern const TaskPriorityType ResourcesPriority[" . $resources_count . "];\n\n"; print "/** \brief Ready Const List */\n"; print "extern const ReadyConstType ReadyConst[" . count($priority) . "];\n\n"; diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 71d83b58..634449a8 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -231,16 +231,27 @@ }; /** \brief RemoteTaskCore Array */ -const TaskCoreType RemoteTasksCore[REMOTE_TASKS_COUNT] = {0 ) { - print $config->getValue("/OSEK/$rtasks[$i]", "CORE"); - if ($i < (count($rtasks)-1)) + for($i=0; $i<$rtasks_count; $i++) { - print ", "; + print $config->getValue("/OSEK/$rtasks[$i]", "CORE"); + if ($i < (count($rtasks)-1)) + { + print ", "; + } } } +else +{ + print "\n/* OIL FILE: THERE ARE NO REMOTE TASKS DEFINED IN THE SYSTEM */\n"; + trigger_error("===== OIL INFO: There are no REMOTE TASKS define in the OIL file =====\n", E_NOTICE); +} ?> }; @@ -340,141 +351,175 @@ getList("/OSEK","RESOURCE"); -print "/** \brief Resources Priorities */\n"; -print "const TaskPriorityType ResourcesPriority[" . count($resources) . "] = {\n"; -$c = 0; -foreach ($resources as $resource) +$resources_count = count($resources); + +if( $resources_count>0 ) { - $count = 0; - foreach ($tasks as $task) + print "/** \brief Resources Priorities */\n"; + print "const TaskPriorityType ResourcesPriority[" . count($resources) . "] = {\n"; + $c = 0; + foreach ($resources as $resource) { - $resorucestask = $config->getList("/OSEK/" . $task, "RESOURCE"); - foreach($resorucestask as $rt) + $count = 0; + foreach ($tasks as $task) { - if ($rt == $resource) + $resorucestask = $config->getList("/OSEK/" . $task, "RESOURCE"); + foreach($resorucestask as $rt) { - if ($priority[$config->getValue("/OSEK/" . $task, "PRIORITY")] > $count) + if ($rt == $resource) { - $count = $priority[$config->getValue("/OSEK/" . $task, "PRIORITY")]; + if ($priority[$config->getValue("/OSEK/" . $task, "PRIORITY")] > $count) + { + $count = $priority[$config->getValue("/OSEK/" . $task, "PRIORITY")]; + } } } } - } - if ($c++ != 0) print ",\n"; - print " $count"; + if ($c++ != 0) print ",\n"; + print " $count"; + } + print "\n};\n"; +} +else +{ + print "\n/* OIL FILE: THERE ARE NO RESOURCES DEFINED IN THE SYSTEM */\n"; + trigger_error("===== OIL INFO: There are no RESOURCES define in the OIL file =====\n", E_NOTICE); } -print "\n};\n"; $alarms = getLocalList("/OSEK", "ALARM"); -print "/** TODO replace next line with: \n"; -print " ** AlarmVarType AlarmsVar[" . count($alarms) . "]; */\n"; -print "AlarmVarType AlarmsVar[" . count($alarms) . "];\n\n"; - -print "const AlarmConstType AlarmsConst[" . count($alarms) . "] = {\n"; +$alarms_count = count($alarms); +$alarms_autostart = 0; -foreach ($alarms as $count=>$alarm) +if( $alarms_count> 0 ) { - if ($count != 0) - { - print ",\n"; - } - print " {\n"; - print " OSEK_COUNTER_" . $config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; - $action = $config->getValue("/OSEK/" . $alarm, "ACTION"); - print " " . $action . ", /* Alarm action */\n"; - print " {\n"; - switch ($action) - { - case "INCREMENT": - print " NULL, /* no callback */\n"; - print " 0, /* no task id */\n"; - print " 0, /* no event */\n"; - print " OSEK_COUNTER_" . $config->getValue("/OSEK/" . $alarm . "/INCREMENT","COUNTER") . " /* counter */\n"; - break; - case "ACTIVATETASK": - print " NULL, /* no callback */\n"; - print " " . $config->getValue("/OSEK/" . $alarm . "/ACTIVATETASK","TASK") . ", /* TaskID */\n"; - print " 0, /* no event */\n"; - print " 0 /* no counter */\n"; - break; - case "SETEVENT": - print " NULL, /* no callback */\n"; - print " " . $config->getValue("/OSEK/" . $alarm . "/SETEVENT","TASK") . ", /* TaskID */\n"; - print " " . $config->getValue("/OSEK/" . $alarm . "/SETEVENT","EVENT") . ", /* no event */\n"; - print " 0 /* no counter */\n"; - break; - case "ALARMCALLBACK": - print " OSEK_CALLBACK_" . $config->getValue("/OSEK/" . $alarm . "/ALARMCALLBACK", "ALARMCALLBACKNAME") . ", /* callback */\n"; - print " 0, /* no taskid */\n"; - print " 0, /* no event */\n"; - print " 0 /* no counter */\n"; - break; - default: - $this->log->error("Alarm $alarm has an invalid action: $action"); - break; - } - print " },\n"; - print " }"; + print "/** TODO replace next line with: \n"; + print " ** AlarmVarType AlarmsVar[" . count($alarms) . "]; */\n"; + print "AlarmVarType AlarmsVar[" . count($alarms) . "];\n\n"; -} -print "\n};\n\n"; + print "const AlarmConstType AlarmsConst[" . count($alarms) . "] = {\n"; -print "const AutoStartAlarmType AutoStartAlarm[ALARM_AUTOSTART_COUNT] = {\n"; -$first = true; -foreach ($alarms as $count=>$alarm) -{ - if ($config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + foreach ($alarms as $count=>$alarm) { - if ($first == false) + if ($count != 0) { print ",\n"; - } else { - $first = false; } - print " {\n"; - - print " " . $config->getValue("/OSEK/" . $alarm, "APPMODE") . ", /* Application Mode */\n"; - // print " OSEK_COUNTER_" . $config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; - print " $alarm, /* Alarms */\n"; - print " " . $config->getValue("/OSEK/" . $alarm, "ALARMTIME") . ", /* Alarm Time */\n"; - print " " . $config->getValue("/OSEK/" . $alarm, "CYCLETIME") . " /* Alarm Time */\n"; + if ($config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + { + $alarms_autostart++; + } + print " {\n"; + print " OSEK_COUNTER_" . $config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; + $action = $config->getValue("/OSEK/" . $alarm, "ACTION"); + print " " . $action . ", /* Alarm action */\n"; + print " {\n"; + switch ($action) + { + case "INCREMENT": + print " NULL, /* no callback */\n"; + print " 0, /* no task id */\n"; + print " 0, /* no event */\n"; + print " OSEK_COUNTER_" . $config->getValue("/OSEK/" . $alarm . "/INCREMENT","COUNTER") . " /* counter */\n"; + break; + case "ACTIVATETASK": + print " NULL, /* no callback */\n"; + print " " . $config->getValue("/OSEK/" . $alarm . "/ACTIVATETASK","TASK") . ", /* TaskID */\n"; + print " 0, /* no event */\n"; + print " 0 /* no counter */\n"; + break; + case "SETEVENT": + print " NULL, /* no callback */\n"; + print " " . $config->getValue("/OSEK/" . $alarm . "/SETEVENT","TASK") . ", /* TaskID */\n"; + print " " . $config->getValue("/OSEK/" . $alarm . "/SETEVENT","EVENT") . ", /* no event */\n"; + print " 0 /* no counter */\n"; + break; + case "ALARMCALLBACK": + print " OSEK_CALLBACK_" . $config->getValue("/OSEK/" . $alarm . "/ALARMCALLBACK", "ALARMCALLBACKNAME") . ", /* callback */\n"; + print " 0, /* no taskid */\n"; + print " 0, /* no event */\n"; + print " 0 /* no counter */\n"; + break; + default: + $this->log->error("Alarm $alarm has an invalid action: $action"); + break; + } + print " },\n"; print " }"; + } -} -print "\n};\n\n"; + print "\n};\n\n"; -$counters = getLocalList("/OSEK", "COUNTER"); + #print("#if( ALARM_AUTOSTART_COUNT>0 )\n"); + if($alarms_autostart>0) + { + print "const AutoStartAlarmType AutoStartAlarm[ALARM_AUTOSTART_COUNT] = {\n"; + $first = true; + foreach ($alarms as $count=>$alarm) + { + if ($config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + { + if ($first == false) + { + print ",\n"; + } + else + { + $first = false; + } + print " {\n"; + + print " " . $config->getValue("/OSEK/" . $alarm, "APPMODE") . ", /* Application Mode */\n"; + // print " OSEK_COUNTER_" . $config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; + print " $alarm, /* Alarms */\n"; + print " " . $config->getValue("/OSEK/" . $alarm, "ALARMTIME") . ", /* Alarm Time */\n"; + print " " . $config->getValue("/OSEK/" . $alarm, "CYCLETIME") . " /* Alarm Time */\n"; + print " }"; + } + } + print "\n};\n\n"; + } + else + { + print "\n/* OIL FILE: THERE ARE NO AUTOSTART ALARMS DEFINED IN THE SYSTEM */\n"; + } -print "CounterVarType CountersVar[" . count($counters) . "];\n\n"; + $counters = getLocalList("/OSEK", "COUNTER"); -$alarms = $config->getList("/OSEK","ALARM"); + print "CounterVarType CountersVar[" . count($counters) . "];\n\n"; -print "const CounterConstType CountersConst[" . count($counters) . "] = {\n"; -foreach ($counters as $count=>$counter) -{ - if ($count!=0) - { - print ",\n"; - } - print " {\n"; - $countalarms = 0; - foreach ($alarms as $alarm) + $alarms = $config->getList("/OSEK","ALARM"); + + print "const CounterConstType CountersConst[" . count($counters) . "] = {\n"; + foreach ($counters as $count=>$counter) { - if ($counter == $config->getValue("/OSEK/" . $alarm,"COUNTER")) + if ($count!=0) { - $countalarms++; + print ",\n"; } + print " {\n"; + $countalarms = 0; + foreach ($alarms as $alarm) + { + if ($counter == $config->getValue("/OSEK/" . $alarm,"COUNTER")) + { + $countalarms++; + } + } + print " $countalarms, /* quantity of alarms for this counter */\n"; + print " (AlarmType*)OSEK_ALARMLIST_" . $counter . ", /* alarms list */\n"; + print " " . $config->getValue("/OSEK/" . $counter,"MAXALLOWEDVALUE") . ", /* max allowed value */\n"; + print " " . $config->getValue("/OSEK/" . $counter,"MINCYCLE") . ", /* min cycle */\n"; + print " " . $config->getValue("/OSEK/" . $counter,"TICKSPERBASE") . " /* ticks per base */\n"; + print " }"; } - print " $countalarms, /* quantity of alarms for this counter */\n"; - print " (AlarmType*)OSEK_ALARMLIST_" . $counter . ", /* alarms list */\n"; - print " " . $config->getValue("/OSEK/" . $counter,"MAXALLOWEDVALUE") . ", /* max allowed value */\n"; - print " " . $config->getValue("/OSEK/" . $counter,"MINCYCLE") . ", /* min cycle */\n"; - print " " . $config->getValue("/OSEK/" . $counter,"TICKSPERBASE") . " /* ticks per base */\n"; - print " }"; + print "\n};\n\n"; +} +else +{ + print "\n/* OIL FILE: THERE ARE NO ALARMS DEFINED IN THE SYSTEM */\n"; + trigger_error("===== OIL INFO: There are no ALARMS define in the OIL file =====\n", E_NOTICE); } -print "\n};\n\n"; - ?> /** TODO replace the next line with @@ -507,7 +552,7 @@ $key = array_search( $inttype , $intList ); if($definitions["ARCH"] == "msp430") - { + { #print "__attribute__( (__interrupt_vec($int)))\n"; print "interrupt_vec($int) \n"; } diff --git a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php index 191d9aa6..efa13f29 100644 --- a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php @@ -294,8 +294,16 @@ if($cat == 2) { - print " /* Disabling IRQ $source */\n"; - print " NVIC_DisableIRQ(" . array_search($source, $intList) . ");\n"; + $key = array_search($source, $intList); + if( $key !== false ) + { + print " /* Disabling IRQ $source */\n"; + print " NVIC_DisableIRQ(" . $key . ");\n"; + } + else + { + trigger_error("===== OIL ERROR: The IRQ name :$source is not valid for this processor =====\n", E_USER_ERROR); + } } } ?> diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index f7529e8c..3b623a04 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -106,7 +106,7 @@ { $src_found = 0; $intcat = 0 ; - + foreach($intnames as $int) { /* @@ -186,8 +186,18 @@ $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); - print " /* Enabling IRQ $source with priority $prio */\n"; - print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; + + $key = array_search($source, $intList); + if( $key !== false ) + { + print " /* Enabling IRQ $source with priority $prio */\n"; + print " MSP430_EnableIRQ(" . $key. ");\n"; + } + else + { + trigger_error("===== OIL ERROR: The IRQ name :$source is not valid for this processor =====\n", E_USER_ERROR); + } + } ?> } @@ -206,8 +216,16 @@ if($cat == 2) { - print " /* Enabling IRQ $source */\n"; - print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; + $key = array_search($source, $intList); + if( $key !== false ) + { + print " /* Enabling IRQ $source */\n"; + print " MSP430_EnableIRQ(" . $key. ");\n"; + } + else + { + trigger_error("===== OIL ERROR: The IRQ name :$source is not valid for this processor =====\n", E_USER_ERROR); + } } } ?> @@ -226,8 +244,16 @@ if($cat == 2) { - print " /* Disabling IRQ $source */\n"; - print " MSP430_DisableIRQ(" . array_search($source, $intList) . ");\n"; + $key = array_search($source, $intList); + if( $key !== false ) + { + print " /* Disabling IRQ $source */\n"; + print " MSP430_DisableIRQ(" . $key . ");\n"; + } + else + { + trigger_error("===== OIL ERROR: The IRQ name :$source is not valid for this processor =====\n", E_USER_ERROR); + } } } ?> diff --git a/src/StartOS.c b/src/StartOS.c index d0e29072..f6f3079f 100644 --- a/src/StartOS.c +++ b/src/StartOS.c @@ -114,6 +114,7 @@ void StartOS ActivateTask(AutoStart[Mode].TasksRef[loopi]); } +#if( ALARM_AUTOSTART_COUNT>0 ) for (loopi = 0; loopi < ALARM_AUTOSTART_COUNT; loopi++) { if (AutoStartAlarm[loopi].Mode == Mode) @@ -121,6 +122,7 @@ void StartOS (void)SetRelAlarm(AutoStartAlarm[loopi].Alarm, AutoStartAlarm[loopi].AlarmTime, AutoStartAlarm[loopi].AlarmCycleTime); } } +#endif #if (HOOK_STARTUPHOOK == OSEK_ENABLE) StartupHook(); @@ -145,4 +147,3 @@ void StartOS /** @} doxygen end group definition */ /** @} doxygen endVar group definition */ /*==================[end of file]============================================*/ - From febf713cc732fbc18f856472d2aa630040784f67 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Fri, 17 Jun 2016 20:24:55 -0300 Subject: [PATCH 24/42] - correcciones de bugs --- gen/inc/Os_Cfg.h.php | 7 ++-- gen/inc/Os_Internal_Cfg.h.php | 46 ++++++++++++++++------- gen/src/Os_Internal_Cfg.c.php | 43 +++++++++++++-------- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 2 - 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 428a050d..043d1a39 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -236,7 +236,8 @@ $task_index = 0; foreach( $tasks as $task ) { - unset($matriz[$task_index][$ev]); //LO SACO DE LA TABLA DE EVENTOS DE LA TAREA + $key = array_search( $ev, $matriz[$task_index] ); //EL EVENTO TIENE QUE EXISTIR SI O SI. + unset($matriz[$task_index][$key]); //LO SACO DE LA TABLA DE EVENTOS DE LA TAREA array_push( $matrix_n[$task_index] , $flags_shared_event ); $task_index++; } @@ -244,7 +245,7 @@ $ev_index++; } - +//print_r($matriz); print "\n\n/** \brief Exclusive events for each task */\n\n"; $task_index = 0; foreach( $tasks as $task ) @@ -300,8 +301,6 @@ //} //print "\n"; - - /* Define the Resources */ $resources = $config->getList("/OSEK","RESOURCE"); diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index 5213ed39..af79a634 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -146,16 +146,32 @@ function remove_doubles($a) /* Define the Resources */ $resources = $config->getList("/OSEK","RESOURCE"); -if(count($resources)>31) +$resources_count = count($resources); +if( $resources_count>31 ) { $this->log->error("more than 31 resources were defined"); } else { - print "/** \brief Count of resources */\n"; - print "#define RESOURCES_COUNT " . count($resources) . "\n\n"; + if( $resources_count > 0) + { + print "/** \brief Count of resources */\n"; + print "#define RESOURCES_COUNT " . $resources_count . "\n\n"; + } } +$resources = $config->getList("/OSEK","RESOURCE"); +$resources_count = count($resources); +if( $resources_count > 0) +{ + print "/** \brief Resources Priorities */\n"; + print "extern const TaskPriorityType ResourcesPriority[" . $resources_count . "];\n\n"; +} + + + + + $os = $config->getList("/OSEK","OS"); if (count($os)>1) { @@ -304,7 +320,10 @@ function remove_doubles($a) } -#define ALARM_COUNT + #define ALARM_AUTOSTART_COUNT getValue("/OSEK/" . $os[0],"USERESSCHEDULER"); @@ -375,8 +394,6 @@ function remove_doubles($a) print "#define NO_RES_SCHEDULER OSEK_ENABLE\n\n"; break; } - - ?> /*==================[typedef]================================================*/ @@ -619,8 +636,11 @@ function remove_doubles($a) /* Resources Priorities */ $resources = $config->getList("/OSEK","RESOURCE"); $resources_count = count($resources); -print "/** \brief Resources Priorities */\n"; -print "extern const TaskPriorityType ResourcesPriority[" . $resources_count . "];\n\n"; +if( $resources_count > 0) +{ + print "/** \brief Resources Priorities */\n"; + print "extern const TaskPriorityType ResourcesPriority[" . $resources_count . "];\n\n"; +} print "/** \brief Ready Const List */\n"; print "extern const ReadyConstType ReadyConst[" . count($priority) . "];\n\n"; diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 634449a8..c376e4a6 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -250,7 +250,7 @@ else { print "\n/* OIL FILE: THERE ARE NO REMOTE TASKS DEFINED IN THE SYSTEM */\n"; - trigger_error("===== OIL INFO: There are no REMOTE TASKS define in the OIL file =====\n", E_NOTICE); + trigger_error("===== OIL INFO: There are no REMOTE TASKS define in the OIL file =====\n", E_USER_NOTICE); } ?> }; @@ -384,7 +384,7 @@ else { print "\n/* OIL FILE: THERE ARE NO RESOURCES DEFINED IN THE SYSTEM */\n"; - trigger_error("===== OIL INFO: There are no RESOURCES define in the OIL file =====\n", E_NOTICE); + trigger_error("===== OIL INFO: There are no RESOURCES define in the OIL file =====\n", E_USER_NOTICE); } $alarms = getLocalList("/OSEK", "ALARM"); @@ -481,7 +481,7 @@ } else { - print "\n/* OIL FILE: THERE ARE NO AUTOSTART ALARMS DEFINED IN THE SYSTEM */\n"; + print "\n/* OIL FILE: THERE ARE NO AUTOSTART ALARMS DEFINED IN THE SYSTEM */\n\n"; } $counters = getLocalList("/OSEK", "COUNTER"); @@ -518,7 +518,7 @@ else { print "\n/* OIL FILE: THERE ARE NO ALARMS DEFINED IN THE SYSTEM */\n"; - trigger_error("===== OIL INFO: There are no ALARMS define in the OIL file =====\n", E_NOTICE); + trigger_error("===== OIL INFO: There are no ALARMS define in the OIL file =====\n", E_USER_NOTICE); } ?> @@ -534,11 +534,14 @@ /*==================[external functions definition]==========================*/ 0 ) /*it only process averything if there is any ISR define within the OIL */ +{ + #includes the array where all IRQ array is defined, base on the architecture. + include ''.$definitions["ARCH"].'/Os_Internal_Defs.php'; #for each ISR define in the OIL, we define the IRQ handler. foreach ($intnames as $int) @@ -549,19 +552,25 @@ if ($intcat == 2) { print "/* Wrapper ISR handler for $int */\n"; - - $key = array_search( $inttype , $intList ); + if($definitions["ARCH"] == "msp430") { - #print "__attribute__( (__interrupt_vec($int)))\n"; print "interrupt_vec($int) \n"; } ?> void OSEK_ISR2_(void) { - + /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); @@ -576,14 +585,16 @@ SetActualContext(actualContext); - + AfterIsr2_Schedule() ; } - /** @} doxygen end group definition */ diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 3b623a04..4f68f403 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -186,7 +186,6 @@ $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); - $key = array_search($source, $intList); if( $key !== false ) { @@ -197,7 +196,6 @@ { trigger_error("===== OIL ERROR: The IRQ name :$source is not valid for this processor =====\n", E_USER_ERROR); } - } ?> } From 543fe168c69ee295a35e5efad1715209af07342d Mon Sep 17 00:00:00 2001 From: FRANCO Date: Fri, 17 Jun 2016 22:41:07 -0300 Subject: [PATCH 25/42] - se remueve bug --- gen/inc/Os_Cfg.h.php | 1 + gen/inc/Os_Internal_Cfg.h.php | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 043d1a39..951ac6b6 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -72,6 +72,7 @@ * 20090128 v0.1.1 MaCe add MEMMAP off configuration * 20080810 v0.1.0 MaCe initial version */ + /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index af79a634..cb321068 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -160,17 +160,6 @@ function remove_doubles($a) } } -$resources = $config->getList("/OSEK","RESOURCE"); -$resources_count = count($resources); -if( $resources_count > 0) -{ - print "/** \brief Resources Priorities */\n"; - print "extern const TaskPriorityType ResourcesPriority[" . $resources_count . "];\n\n"; -} - - - - $os = $config->getList("/OSEK","OS"); if (count($os)>1) @@ -642,6 +631,8 @@ function remove_doubles($a) print "extern const TaskPriorityType ResourcesPriority[" . $resources_count . "];\n\n"; } + + print "/** \brief Ready Const List */\n"; print "extern const ReadyConstType ReadyConst[" . count($priority) . "];\n\n"; print "/** \brief Ready Variable List */\n"; From b8748ac0c59d02b5bdb505178555e69283264276 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sat, 18 Jun 2016 02:58:56 -0300 Subject: [PATCH 26/42] - bugs corrections - reduction of stack size for some tests. --- gen/src/Os_Internal_Cfg.c.php | 13 ++++++------- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 2 +- inc/msp430/Os_Arch.h | 11 +++++++++-- tst/ctest/etc/ctest_em_01.oil | 6 +++--- tst/ctest/etc/ctest_ip_01.oil | 8 ++++---- tst/ctest/etc/ctest_ip_03.oil | 10 +++++----- tst/ctest/etc/ctest_ip_04.oil | 8 ++++---- tst/ctest/etc/ctest_rm_01.oil | 6 +++--- tst/ctest/etc/ctest_rm_02.oil | 8 ++++---- tst/ctest/etc/ctest_rm_05.oil | 6 +++--- tst/ctest/etc/itest_ip_01.oil | 6 +++--- tst/ctest/src/ctest_em_01.c | 5 ++--- tst/ctest/src/ctest_ip_01.c | 5 ++--- tst/ctest/src/ctest_ip_03.c | 3 +-- tst/ctest/src/ctest_ip_04.c | 3 +-- tst/ctest/src/ctest_rm_01.c | 5 ++--- tst/ctest/src/ctest_rm_05.c | 5 ++--- tst/ctest/src/itest_ip_01.c | 2 +- 18 files changed, 56 insertions(+), 56 deletions(-) diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index c376e4a6..1d7baf99 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -535,7 +535,6 @@ /*==================[external functions definition]==========================*/ 0 ) /*it only process averything if there is any ISR define within the OIL */ @@ -549,16 +548,16 @@ $inttype = $config->getValue("/OSEK/" . $int,"INTERRUPT"); $intcat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + print("/* Wrapper ISR handler for $int */\n"); + if ($intcat == 2) { - print "/* Wrapper ISR handler for $int */\n"; - if($definitions["ARCH"] == "msp430") { print "interrupt_vec($int) \n"; } ?> -void OSEK_ISR2_(void) +void OSEK_ISR2_(void) { - + AfterIsr2_Schedule() ; } - Date: Sat, 18 Jun 2016 16:05:33 -0300 Subject: [PATCH 27/42] - se modifican IntSecureXXX --- inc/msp430/Os_Arch.h | 30 ++++++------------------------ inc/msp430/Os_Internal_Arch.h | 10 +++++++--- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index 0d63bc9a..86985238 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -78,17 +78,10 @@ *****************************************************************************/ /** \brief Enable All Interrupts Arch */ -#define EnableAllInterrupts_Arch() ResumeAllInterrupts_Arch() +#define EnableAllInterrupts_Arch() ResumeAllInterrupts_Arch() /** \brief Disable All Interrupts Arch */ -#define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() - - -/** \brief All Interrupts Arch Common Objects - ** - ** This macro shall define common objects to imlement Suspend and Resume - **/ -#define CommonAllInterrupts() volatile unsigned short SR_BACK___; +#define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() /** \brief Suspend All Interrupts Arch @@ -99,39 +92,28 @@ ** Also noted in Slau208, page 59. **/ -#define SuspendAllInterrupts_Arch() SR_BACK___ = _get_SR_register(); \ - _disable_interrupts() ; - -//#define SuspendAllInterrupts_Arch() _disable_interrupts() ; +#define SuspendAllInterrupts_Arch() _disable_interrupts() ; /** \brief Resume All Interrupts Arch ** ** This macro shall resume (enable) all interrupts. **/ - -#define ResumeAllInterrupts_Arch() if( SR_BACK___ & GIE ) \ - { \ - _enable_interrupts() ; \ - } \ - - -//#define ResumeAllInterrupts_Arch() _enable_interrupts() ; - +#define ResumeAllInterrupts_Arch() _enable_interrupts() ; /** \brief Resume OS Interrupts Arch ** ** This macro shall resume (enable) all interrupts configured on the ** FreeOSEK OIL configuration file as ISR2. **/ -#define ResumeOSInterrupts_Arch() Enable_ISR2_Arch() +#define ResumeOSInterrupts_Arch() Enable_ISR2_Arch() /** \brief Suspend OS Interrupts Arch ** ** This macro shall suspend (disable) all interrupts configured on the ** FreeOSEK OIL configuration file as ISR2. **/ -#define SuspendOSInterrupts_Arch() Disable_ISR2_Arch() +#define SuspendOSInterrupts_Arch() Disable_ISR2_Arch() /*==================[typedef]================================================*/ /***************************************************************************** diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index bf9892a1..9e3d9090 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -103,7 +103,7 @@ extern TaskType TerminatingTask; ** This macro will be used internaly by the OS in any part of code that ** has to be executed atomic. It should be placed after IntSecure_Start or IntSecure_End is called **/ -#define IntSecure_Common() CommonAllInterrupts() +#define IntSecure_Common() volatile unsigned short SR_BACK___; /** \brief Interrupt Secure Start Macro @@ -111,13 +111,17 @@ extern TaskType TerminatingTask; ** This macro will be used internaly by the OS in any part of code that ** has to be executed atomic. **/ -#define IntSecure_Start() SuspendAllInterrupts() +#define IntSecure_Start() SR_BACK___ = _get_SR_register(); \ + _disable_interrupts() ; /** \brief Interrupt Secure End Macro ** ** This macro is the countra part of IntSecure_Start() **/ -#define IntSecure_End() ResumeAllInterrupts() +#define IntSecure_End() if( SR_BACK___ & GIE ) \ + { \ + _enable_interrupts() ; \ + } \ /** \brief osekpause ** From 583590922efbaaa6288fd2a5c6a1b1cf727c118a Mon Sep 17 00:00:00 2001 From: FRANCO Date: Mon, 20 Jun 2016 12:45:29 -0300 Subject: [PATCH 28/42] - debug script for testing is places within each project folder for msp430 - add nop after dint instruction for msp430 - the watchdog is disabled after reset instead within Os' start functions for msp430 - updated internal arch routines for msp430 --- gen/inc/Os_Cfg.h.php | 4 +- gen/inc/Os_Internal_Cfg.h.php | 2 + gen/src/Os_Internal_Cfg.c.php | 4 -- inc/msp430/Os_Arch.h | 3 +- inc/msp430/Os_Internal_Arch.h | 10 ++-- src/msp430/Os_Internal_Arch.c | 57 ++++++------------- src/msp430/StartOs_Arch.c | 6 ++ src/msp430/StartOs_Arch_SystemTick.c | 2 +- tst/ctest/bin/ctest.pl | 2 +- .../msp430/msp430f5x_6x/msp430f5529/Makefile | 2 +- 10 files changed, 37 insertions(+), 55 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 951ac6b6..f2b3cf5e 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -72,7 +72,7 @@ * 20090128 v0.1.1 MaCe add MEMMAP off configuration * 20080810 v0.1.0 MaCe initial version */ - + /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ @@ -160,7 +160,7 @@ if ($extended != "EXTENDED" && $nro_ev_task>0 ) { - trigger_error("===== OIL ERROR: The task $task could be TYPE: EXTENDED =====\n", E_USER_ERROR); + trigger_error("===== OIL ERROR: The task $task should be TYPE: EXTENDED =====\n", E_USER_ERROR); } else { diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index cb321068..b27604ab 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -618,6 +618,8 @@ function remove_doubles($a) } } +print("\n"); + $appmodes = $config->getList("/OSEK","APPMODE"); print "/** \brief AutoStart Array */\n"; print "extern const AutoStartType AutoStart[" . count($appmodes) . "];\n\n"; diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 1d7baf99..aa913b38 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -164,11 +164,7 @@ print " {\n"; print " OSEK_TASK_$task, /* task entry point */\n"; print " &ContextTask" . $task . ", /* pointer to task context */\n"; - - print " (StackPtrType) StackTask" . $task . ", /* pointer stack memory */\n"; - - print " sizeof(StackTask" . $task . "), /* stack size */\n"; print " " . $priority[$config->getValue("/OSEK/" . $task, "PRIORITY")] . ", /* task priority */\n"; print " " . $config->getValue("/OSEK/" . $task, "ACTIVATION"). ", /* task max activations */\n"; diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index 86985238..0ed3a6e0 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -92,7 +92,8 @@ ** Also noted in Slau208, page 59. **/ -#define SuspendAllInterrupts_Arch() _disable_interrupts() ; +#define SuspendAllInterrupts_Arch() _disable_interrupts() ; __asm__ __volatile__ ("nop"); + /** \brief Resume All Interrupts Arch diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 9e3d9090..e7776f46 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -101,9 +101,9 @@ extern TaskType TerminatingTask; /** \brief Define common objects for using IntSecure_Start and IntSecure_End- ** ** This macro will be used internaly by the OS in any part of code that - ** has to be executed atomic. It should be placed after IntSecure_Start or IntSecure_End is called + ** has to be executed atomic. It should be placed before IntSecure_Start or IntSecure_End is called **/ -#define IntSecure_Common() volatile unsigned short SR_BACK___; +#define IntSecure_Common() unsigned short SR_BACK___; /** \brief Interrupt Secure Start Macro @@ -112,7 +112,8 @@ extern TaskType TerminatingTask; ** has to be executed atomic. **/ #define IntSecure_Start() SR_BACK___ = _get_SR_register(); \ - _disable_interrupts() ; + _disable_interrupts() ; \ + __asm__ __volatile__ ("nop"); /** \brief Interrupt Secure End Macro ** @@ -270,8 +271,7 @@ extern TaskType TerminatingTask; ** NOTE: the nop operation after the dint instruction was inserted ** to workarround the hw bug cpu39 described in slaz314h.pdf **/ -#define DisableOSInterrupts() _disable_interrupts(); - +#define DisableOSInterrupts() _disable_interrupts(); __asm__ __volatile__ ("nop"); diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 35cb8c4f..cd7bbeae 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -290,10 +290,16 @@ unsigned char dma2ctl_bck = 0; //the DMA2CTL is 16bit wide, but the IRQ flags #endif #if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) -unsigned char uca0ie_bck = 0; +unsigned char uca1ctl1_bck = 0; unsigned char uca1ie_bck = 0; #endif +#if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) +unsigned char uca0ctl1_bck = 0; +unsigned char uca0ie_bck = 0; +#endif + + #if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) unsigned char ucb0ie_bck = 0; #endif @@ -360,7 +366,8 @@ void MSP430_EnableIRQ(unsigned char irQ_number) #if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) case 5 : //=> "USCI_A1", /* UCA1RXIE, UCA1TXIE */ - UCA1IE |= ( uca1ie_bck & (UCRXIE|UCTXIE) ); + UCA1IE |= ( uca1ie_bck & (UCRXIE|UCTXIE) ); + UCA1CTL1 |= ( uca1ctl1_bck & (UCRXEIE|UCBRKIE) ); break; #endif @@ -466,6 +473,7 @@ void MSP430_EnableIRQ(unsigned char irQ_number) case 15: // => "USCI_A0", /* UCA0RXIE, UCA0TXIE */ UCA0IE |= ( uca0ie_bck & (UCRXIE|UCTXIE) ); + UCA0CTL1 |= ( uca0ctl1_bck & (UCRXEIE|UCBRKIE) ); break; #endif @@ -614,9 +622,11 @@ void MSP430_DisableIRQ(unsigned char irQ_number) //backup the register/s uca1ie_bck = UCA1IE; + uca1ctl1_bck = UCA1CTL1; //clear all flags UCA1IE &=~ (UCRXIE|UCTXIE); + UCA1CTL1 &=~ (UCRXEIE|UCBRKIE); break; #endif @@ -770,9 +780,11 @@ void MSP430_DisableIRQ(unsigned char irQ_number) //backup the register/s uca0ie_bck = UCA0IE; + uca0ctl1_bck = UCA0CTL1; //clear all flags - UCA0IE &=~ (UCRXIE|UCTXIE); + UCA0IE &=~ (UCRXIE|UCTXIE); + UCA0CTL1 &=~ (UCRXEIE|UCBRKIE); break; #endif @@ -900,9 +912,8 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) #endif #if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) -#error TODO: NOT IMPLEMENTED case 5 : //=> "USCI_A1", - + dummy = UCA1IV; break; #endif @@ -915,39 +926,6 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " */ - - /* if( P1IV_P1IFG0==dummy ) - { - // P1IFG &= ~0x01; - } - else if( P1IV_P1IFG1==dummy ) - { - // P1IFG &= ~0x02; - } - else if( P1IV_P1IFG2==dummy ) - { - // P1IFG &= ~0x04; - } - else if( P1IV_P1IFG3==dummy ) - { - // P1IFG &= ~0x08; - } - else if( P1IV_P1IFG4==dummy ) - { - //P1IFG &= ~0x10; - } - else if( P1IV_P1IFG5==dummy ) - { - //P1IFG &= ~0x20; - } - else if( P1IV_P1IFG6==dummy ) - { - // P1IFG &= ~0x40; - } - else if( P1IV_P1IFG7==dummy ) - { - //P1IFG &= ~0x80; - }*/ break; #endif @@ -1007,9 +985,8 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) #endif #if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) -#error TODO: NOT IMPLEMENTED case 15: // => "USCI_A0", - + dummy = UCA0IV; break; #endif diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index a008bd72..7aeeae26 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -74,6 +74,12 @@ /*==================[external data definition]===============================*/ /*==================[internal functions definition]==========================*/ +static void __attribute__((naked, section(".crt_0042"), used)) +disable_watchdog (void) +{ + //https://sourceware.org/ml/newlib/2015/msg00627.html + WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer +} /*==================[external functions definition]==========================*/ diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c index 0354e08b..ad36c8b5 100644 --- a/src/msp430/StartOs_Arch_SystemTick.c +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -119,7 +119,7 @@ MCLK = SMCLK = 14.7456Mhz */ void StartOs_Arch_System() { - WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //TODO LEER https://sourceware.org/ml/newlib/2015/msg00627.html + UCS_turnOffXT1(); diff --git a/tst/ctest/bin/ctest.pl b/tst/ctest/bin/ctest.pl index 5526b114..47952da1 100755 --- a/tst/ctest/bin/ctest.pl +++ b/tst/ctest/bin/ctest.pl @@ -827,7 +827,7 @@ sub logffull if ("msp430" eq $ARCH) { - $newdbgfile = "out/rtos/$test/debug_script.scr"; + $newdbgfile = "out/rtos/$test/$config/debug_script.scr"; #for MSP430 the binary file is appended inside the script copy($dbgfile,$newdbgfile ) or die "Script copy failed: $!"; searchandreplace($newdbgfile ,"filename","$out"); diff --git a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile index 37a952a7..32ba467c 100755 --- a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile +++ b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile @@ -34,4 +34,4 @@ # #for testes we add a precompiler definition to alter some macros -CFLAGS += -DCTESTS_MODIFIERS +#CFLAGS += -DCTESTS_MODIFIERS From 59b21089f604c420c37b994987a0ff23f78b779a Mon Sep 17 00:00:00 2001 From: FRANCO Date: Mon, 20 Jun 2016 18:01:37 -0300 Subject: [PATCH 29/42] - add clearing iinterrupt flags for ISR Type 1. --- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 4 +++- inc/msp430/Os_Internal_Arch.h | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index e5142072..065c66b3 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -164,9 +164,11 @@ #for an ISR type 1 witihn the OIL file, we defiene a ISR wrapper that calls the ISR defined by the user somewhere. #print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) \n"; print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked))\n"; - print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]) somewhere */ \n"; + print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]_VECTOR) somewhere */ \n"; print "{\n"; + print " PreIsr1_Arch($i);\n"; print " OSEK_ISR_$intList[$i]_VECTOR();\n"; + print " PostIsr1_Arch($i);\n"; print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile print "}\n\n"; } diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index e7776f46..e25b4058 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -294,13 +294,27 @@ extern TaskType TerminatingTask; **/ #define GetCounter_Arch(CounterID) (CountersVar[CounterID].Time) -/** \brief Pre ISR Macrol + +/** \brief Pre ISR1 Macro + ** + ** This macro is called every time that an ISR Cat 1 is started + **/ +#define PreIsr1_Arch(isr) + + +/** \brief Post ISR1 Macro + ** + ** This macro is called every time that an ISR Cat 1 is finished + **/ +#define PostIsr1_Arch(isr) ClearPendingIRQ_Arch(isr) + +/** \brief Pre ISR Macro ** ** This macro is called every time that an ISR Cat 2 is started **/ #define PreIsr2_Arch(isr) -/** \brief Post ISR Macro +/** \brief Post ISR2 Macro ** ** This macro is called every time that an ISR Cat 2 is finished **/ From d25b067c00b5b262a22d6477517e55c66ebc7180 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Wed, 22 Jun 2016 00:57:46 -0300 Subject: [PATCH 30/42] ALL CTESTS RUNNING OK - modifications in regard ip tests where there were no explicit interrupt enabling by the "user" --- src/msp430/Os_Internal_Arch.c | 6 +++--- tst/ctest/dbg/msp430/gcc/debug.scr | 1 - tst/ctest/inc/ctest.h | 20 ++++++++++++++++++-- tst/ctest/inc/msp430/ctest_arch.h | 5 +++++ tst/ctest/src/ctest_ip_01.c | 3 +++ tst/ctest/src/ctest_ip_03.c | 4 ++++ tst/ctest/src/ctest_ip_04.c | 4 ++++ tst/ctest/src/ctest_rst.c | 5 ++--- tst/ctest/src/msp430/ctest_arch.c | 18 ++++++++++++++++-- 9 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index cd7bbeae..2b891995 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -208,7 +208,7 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) } asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); asm volatile ( "mov @r6, SP \n\t" ); - + /* Context restore r4 to r15 It does not Include the reti instruction. @@ -336,7 +336,7 @@ void MSP430_EnableIRQ(unsigned char irQ_number) #if( MSP430_ENABLE_PORT2_HANDLER==1) case 1 : //=> "PORT2", /* P2IE.0 to P2IE.7*/ - P2IE = p2ie_bck; + P2IE |= p2ie_bck; break; #endif @@ -374,7 +374,7 @@ void MSP430_EnableIRQ(unsigned char irQ_number) #if( MSP430_ENABLE_PORT1_HANDLER==1 ) case 6 : //=> "PORT1", /* P1IE.0 to P1IE.7 */ - P1IE = p1ie_bck; + P1IE |= p1ie_bck; break; #endif diff --git a/tst/ctest/dbg/msp430/gcc/debug.scr b/tst/ctest/dbg/msp430/gcc/debug.scr index 2ac22606..7711cd81 100644 --- a/tst/ctest/dbg/msp430/gcc/debug.scr +++ b/tst/ctest/dbg/msp430/gcc/debug.scr @@ -1,4 +1,3 @@ -opt fet_block_size 512 prog filename reset setbreak ConfTestFinish diff --git a/tst/ctest/inc/ctest.h b/tst/ctest/inc/ctest.h index fe066039..f83d47f4 100644 --- a/tst/ctest/inc/ctest.h +++ b/tst/ctest/inc/ctest.h @@ -235,14 +235,30 @@ ** This macro shall implement a mechanismus to trigger the ISR1 interruption **/ #define TriggerISR1() \ - TriggerISR1_Arch() + TriggerISR1_Arch() /** \brief ISR2 Trigger Macro ** ** This macro shall implement a mechanismus to trigger the ISR2 interruption **/ #define TriggerISR2() \ - TriggerISR2_Arch() + TriggerISR2_Arch() + +/** \brief ISR1 Enable Macro + ** + ** This macro shall implement a mechanism to enable the ISR1 interruption + **/ +#define EnableISR1() \ + EnableISR1_Arch() + +/** \brief ISR2 Enable Macro + ** + ** This macro shall implement a mechanism to enable the ISR2 interruption + **/ +#define EnableISR2() \ + EnableISR2_Arch() + + /** \brief Initialise Alarm Counter Macro ** diff --git a/tst/ctest/inc/msp430/ctest_arch.h b/tst/ctest/inc/msp430/ctest_arch.h index b2494fc2..c06e9b4f 100644 --- a/tst/ctest/inc/msp430/ctest_arch.h +++ b/tst/ctest/inc/msp430/ctest_arch.h @@ -55,6 +55,11 @@ extern void TriggerISR2_Arch(void); /* Use P2.2 as interrupt for tests */ extern void TriggerISR1_Arch(void); + +extern void EnableISR2_Arch(void); + +extern void EnableISR1_Arch(void); + #else #error please define CPU variable! #endif diff --git a/tst/ctest/src/ctest_ip_01.c b/tst/ctest/src/ctest_ip_01.c index 23f48514..e0983948 100644 --- a/tst/ctest/src/ctest_ip_01.c +++ b/tst/ctest/src/ctest_ip_01.c @@ -74,6 +74,9 @@ int main void ) { + EnableISR1(); + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); diff --git a/tst/ctest/src/ctest_ip_03.c b/tst/ctest/src/ctest_ip_03.c index d696aea9..4941955a 100644 --- a/tst/ctest/src/ctest_ip_03.c +++ b/tst/ctest/src/ctest_ip_03.c @@ -70,6 +70,10 @@ int main void ) { + EnableISR1(); + EnableISR2(); + + /* start OS in AppMode 1 */ StartOS(AppMode1); diff --git a/tst/ctest/src/ctest_ip_04.c b/tst/ctest/src/ctest_ip_04.c index fc359943..c93eb648 100644 --- a/tst/ctest/src/ctest_ip_04.c +++ b/tst/ctest/src/ctest_ip_04.c @@ -70,6 +70,10 @@ int main void ) { + EnableISR1(); + EnableISR2(); + + /* start OS in AppMode 1 */ StartOS(AppMode1); diff --git a/tst/ctest/src/ctest_rst.c b/tst/ctest/src/ctest_rst.c index 649fd2a9..f0007e6e 100644 --- a/tst/ctest/src/ctest_rst.c +++ b/tst/ctest/src/ctest_rst.c @@ -717,10 +717,10 @@ uint32f SequenceCounter; /*==================[internal functions definition]==========================*/ /*==================[external functions definition]==========================*/ - void ConfTestEvaluation +void ConfTestEvaluation ( void - ) +) { uint32f loopi; boolean testok = TRUE; @@ -775,4 +775,3 @@ uint32f SequenceCounter; /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/tst/ctest/src/msp430/ctest_arch.c b/tst/ctest/src/msp430/ctest_arch.c index a7ff7d8e..8ba14096 100644 --- a/tst/ctest/src/msp430/ctest_arch.c +++ b/tst/ctest/src/msp430/ctest_arch.c @@ -61,11 +61,26 @@ /*==================[external data definition]===============================*/ #if (CPUTYPE == msp430f5x_6x) + /* Use P1.7 as interrupt for tests */ -extern void TriggerISR2_Arch(void) +extern void EnableISR2_Arch(void) { /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ P1IE |= 0x80; +} + +/* Use P2.2 as interrupt for tests */ +extern void EnableISR1_Arch(void) +{ + /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ + P2IE |= 0x04; +} + + +/* Use P1.7 as interrupt for tests */ +extern void TriggerISR2_Arch(void) +{ + /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ P1IFG |= 0x80; } @@ -73,7 +88,6 @@ extern void TriggerISR2_Arch(void) extern void TriggerISR1_Arch(void) { /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ - P2IE |= 0x04; P2IFG |= 0x04; } From 2c2c6de8a798211db1cc55901405fe989e068f87 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Thu, 23 Jun 2016 01:10:03 -0300 Subject: [PATCH 31/42] ALL TESTS PASSED - comments and headers corrections - add EnableISR function in each test that requieres to trigger ISR type 2. --- gen/inc/Os_Cfg.h.php | 17 ++++------------- gen/inc/Os_Internal_Cfg.h.php | 15 ++------------- gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php | 13 +++---------- inc/Os_Internal.h | 1 + inc/os.h | 8 +------- tst/ctest/src/ctest_em_01.c | 3 +++ tst/ctest/src/ctest_ip_01.c | 1 + tst/ctest/src/ctest_ip_03.c | 2 ++ tst/ctest/src/ctest_ip_04.c | 2 ++ tst/ctest/src/ctest_rm_01.c | 4 ++++ tst/ctest/src/ctest_rm_05.c | 3 +++ tst/ctest/src/ctest_tm_01.c | 3 +++ tst/ctest/src/itest_ip_01.c | 3 +++ 13 files changed, 32 insertions(+), 43 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index f2b3cf5e..1474f540 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -3,10 +3,10 @@ ********************************************************/ /* Copyright 2008, 2009, 2015 Mariano Cerdeiro - * Copyright 2016 Franco Bucafusco * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016 Franco Bucafusco * * This file is part of CIAA Firmware. * @@ -63,16 +63,7 @@ /** \addtogroup FreeOSEK_Os_Global ** @{ */ -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20150619 v0.1.4 MaCe fix issue #279 - * 20090719 v0.1.3 MaCe rename file to Os_ - * 20090424 v0.1.2 MaCe add counters defines - * 20090128 v0.1.1 MaCe add MEMMAP off configuration - * 20080810 v0.1.0 MaCe initial version - */ - + /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ @@ -82,7 +73,7 @@ #define OSEK_OS_INTERRUPT_MASK ((InterruptFlagsType)0xFFFFFFFFU) 0) { foreach ($remote_tasks as $task) diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index b27604ab..0ba4d775 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -6,6 +6,7 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016 Franco Bucafusco * * This file is part of CIAA Firmware. * @@ -53,19 +54,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20090719 v0.1.7 MaCe rename file to Os_ - * 20090331 v0.1.6 MaCe add USERESSCHEDULER evaluation - * 20090330 v0.1.5 MaCe add NO_EVENTS macro - * 20090327 v0.1.4 MaCe add declaration of the start task for the app. modes - * 20090131 v0.1.3 MaCe add extern to CountersVar declaration - * 20090130 v0.1.2 MaCe add OSEK_MEMMAP check - * 20090128 v0.1.1 MaCe remove OSEK_ENABLE and OSEK_DISABLE macro, now defined in OpenGEN - * 20080713 v0.1.0 MaCe initial version - */ + Date: Fri, 1 Jul 2016 01:26:00 -0300 Subject: [PATCH 32/42] Luego del Rebase 1 - Se corrigen scripts para que compile blinking. --- gen/{src => ginc}/msp430/Os_Internal_Defs.php | 5 +-- gen/inc/Os_Cfg.h.php | 14 +++--- gen/inc/Os_Internal_Cfg.h.php | 6 ++- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 12 +++-- gen/src/Os_Internal_Cfg.c.php | 10 ++--- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 45 ++++++++++--------- .../gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 40 +---------------- 7 files changed, 53 insertions(+), 79 deletions(-) rename gen/{src => ginc}/msp430/Os_Internal_Defs.php (96%) diff --git a/gen/src/msp430/Os_Internal_Defs.php b/gen/ginc/msp430/Os_Internal_Defs.php similarity index 96% rename from gen/src/msp430/Os_Internal_Defs.php rename to gen/ginc/msp430/Os_Internal_Defs.php index 1daeb39f..d0a58b5c 100644 --- a/gen/src/msp430/Os_Internal_Defs.php +++ b/gen/ginc/msp430/Os_Internal_Defs.php @@ -51,7 +51,7 @@ definitions["CPU"]) { case "msp430f5529": /* Interrupt sources for msp430f5529 @@ -86,10 +86,9 @@ break; default: - error("the CPU " . $definitions["CPU"] . " is not supported."); + $this->log->error("the CPU " . $this->definitions["CPU"] . " is not supported."); break; } $MAX_INT_COUNT = max(array_keys($intList))+1; - ?> diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index e2435626..6443b1ae 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -63,7 +63,7 @@ /** \addtogroup FreeOSEK_Os_Global ** @{ */ - + /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ @@ -115,7 +115,7 @@ /* Define the Events */ /* the max ammount of events is defined by the bit width of EventTypeMask type*/ -if( $definitions["ARCH"]== "msp430") +if( $this->definitions["ARCH"]== "msp430") { $max_amount_events = 16; } @@ -129,7 +129,7 @@ $matriz = array( ); /* it stores the events' name for each task */ $matrix_n = array(); /* it stores the events' assigned number for each task */ -$events = $config->getList("/OSEK","EVENT"); +$events = $this->config->getList("/OSEK","EVENT"); //$nro_evs= max(array_keys($events))+1; $nro_evs= count($events); #print("cantidad de eventos: $nro_evs \n"); @@ -139,7 +139,7 @@ foreach( $tasks as $task ) { $empty_array = array(); - $temp_array = $config->getList("/OSEK/". $task , "EVENT" ); + $temp_array = $this->config->getList("/OSEK/". $task , "EVENT" ); /*for each task we get the defined events*/ array_push( $matriz , $temp_array ); @@ -150,7 +150,7 @@ //print("evento $nro_ev_task"); /* Task Type validation: validates that this task is extended */ - $extended = $config->getValue("/OSEK/" . $task, "TYPE"); + $extended = $this->config->getValue("/OSEK/" . $task, "TYPE"); if ($extended != "EXTENDED" && $nro_ev_task>0 ) { @@ -199,7 +199,7 @@ foreach( $tasks as $task ) { - #$events_for_task = $config->getList("/OSEK/". $task , "EVENT" ); + #$events_for_task = $this->config->getList("/OSEK/". $task , "EVENT" ); $key = array_search( $ev, $matriz[$task_index] ); if( $key !== false ) //busco el evento en el array de eventos de la tarea. @@ -287,7 +287,7 @@ } print "\n"; -//$events = $config->getList("/OSEK","EVENT"); +//$events = $this->config->getList("/OSEK","EVENT"); //foreach ($events as $count=>$event) //{ diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index 76c42c78..934b07a0 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -146,11 +146,13 @@ function remove_doubles($a) } -$os = $config->getList("/OSEK","OS"); +$os = $this->config->getList("/OSEK","OS"); + if (count($os)>1) { $this->log->error("More than one OS defined on the configuration"); } + $osattr = $this->config->getValue("/OSEK/" . $os[0],"STATUS"); print "/** \brief Error Checking Type */\n"; if ( $osattr == "EXTENDED" ) @@ -605,7 +607,7 @@ function remove_doubles($a) print("\n"); -$appmodes = $config->getList("/OSEK","APPMODE"); +$appmodes = $this->config->getList("/OSEK","APPMODE"); print "/** \brief AutoStart Array */\n"; print "extern const AutoStartType AutoStart[" . count($appmodes) . "];\n\n"; diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index 12aa5f4c..ab229993 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -85,14 +85,20 @@ typedef TaskContextType* TaskContextRefType; /*==================[external data declaration]==============================*/ + loadHelper("modules/rtos/gen/ginc/Multicore.php"); + +require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); + +$intnames = $this->helper->multicore->getLocalList("/OSEK", "ISR"); + foreach ($intnames as $int) { - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); print "#define MSP430_ENABLE_". $source . "_HANDLER 1 \n"; } diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index d06882b2..95cbd4ea 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -74,11 +74,11 @@ print "#if ( x86 == ARCH )\n"; print "uint8 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ." + TASK_STACK_ADDITIONAL_SIZE];\n"; print "#else\n"; - if( $definitions["ARCH"]== "msp430") + if( $this->definitions["ARCH"]== "msp430") { #msp430 requieres bus alligmented memory access. So, if the compiler allocates this array as uint8 it could start at an even address. #we force the compiler to locate this array alligned declaring it as an uint16 (with the size divided by two) - print "uint16 StackTask" . $task . "[" . $config->getValue("/OSEK/" . $task, "STACK") ."/2];\n"; + print "uint16 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ."/2];\n"; } else { @@ -407,7 +407,7 @@ { print ",\n"; } - if ($config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + if ($this->config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") { $alarms_autostart++; } @@ -546,7 +546,7 @@ if( count($intnames)>0 ) /*it only process averything if there is any ISR define within the OIL */ { #includes the array where all IRQ array is defined, base on the architecture. - include ''.$definitions["ARCH"].'/Os_Internal_Defs.php'; +require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); #for each ISR define in the OIL, we define the IRQ handler. foreach ($intnames as $int) @@ -558,7 +558,7 @@ if ($intcat == 2) { - if($definitions["ARCH"] == "msp430") + if($this->definitions["ARCH"] == "msp430") { print "interrupt_vec($int) \n"; } diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 065c66b3..8abe0dcf 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -74,12 +74,11 @@ /*==================[internal data definition]===============================*/ /*==================[external data definition]===============================*/ - -/*==================[external functions definition]==========================*/ -//__attribute__( (__interrupt_vec(UNMI_VECTOR),naked)) + +/*==================[internal functions definition]==========================*/ + + interrupt_vec(UNMI_VECTOR) __attribute__((naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ void OSEK_ISR_UNMI_VECTOR(void) { @@ -88,8 +87,8 @@ } } -//__attribute__( (__interrupt_vec(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ -interrupt_vec(SYSNMI_VECTOR) __attribute__((naked)) + +interrupt_vec(SYSNMI_VECTOR) __attribute__((naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ void OSEK_ISR_SYSNMI_VECTOR(void) { while (1) @@ -97,11 +96,17 @@ } } +/*==================[external functions definition]==========================*/ +loadHelper("modules/rtos/gen/ginc/Multicore.php"); + +require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); +?> /*** Non Used Interrupt handlers ***/ helper->multicore->getLocalList("/OSEK", "ISR"); for($i=0; $i < $MAX_INT_COUNT; $i++) { $src_found = 0; @@ -113,8 +118,8 @@ handlers that are present in the system (defined in the oil file) do not add extra code here. */ - $intcat = $config->getValue("/OSEK/" . $int,"CATEGORY"); - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); + $intcat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); if($intList[$i] == $source) { @@ -168,7 +173,7 @@ print "{\n"; print " PreIsr1_Arch($i);\n"; print " OSEK_ISR_$intList[$i]_VECTOR();\n"; - print " PostIsr1_Arch($i);\n"; + print " PostIsr1_Arch($i);\n"; print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile print "}\n\n"; } @@ -181,12 +186,12 @@ { helper->multicore->getLocalList("/OSEK", "ISR"); foreach ($intnames as $int) { - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $prio = $this->config->getValue("/OSEK/" . $int,"PRIORITY"); $key = array_search($source, $intList); if( $key !== false ) @@ -208,11 +213,11 @@ { helper->multicore->getLocalList("/OSEK", "ISR"); foreach ($intnames as $int) { - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); if($cat == 2) { @@ -236,11 +241,11 @@ { helper->multicore->getLocalList("/OSEK", "ISR"); foreach ($intnames as $int) { - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); if($cat == 2) { diff --git a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 8102e070..32d70870 100644 --- a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -75,46 +75,8 @@ /*==================[external data definition]===============================*/ "RTC", - 1 => "PORT2", - 2 => "TIMER2_A1", - 3 => "TIMER2_A0", - 4 => "USCI_B1", - 5 => "USCI_A1", - 6 => "PORT1", - 7 => "TIMER1_A1", - 8 => "TIMER1_A0", - 9 => "DMA", - 10 => "USB_UBM", - 11 => "TIMER0_A1", - 12 => "TIMER0_A0", - 13 => "ADC12", - 14 => "USCI_B0", - 15 => "USCI_A0", - 16 => "WDT", - 17 => "TIMER0_B1", - 18 => "TIMER0_B0", - 19 => "COMP_B", - 20 => "UNMI", - 21 => "SYSNMI", - 22 => "RESET", - ); - break; - - default: - error("the CPU " . $definitions["CPU"] . " is not supported."); - break; -} -$MAX_INT_COUNT = max(array_keys($intList))+1; +require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); #if (CPU == msp430f5529) From 9735117f040f50cff549b89420a26ec8da643462 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sat, 2 Jul 2016 12:00:15 -0300 Subject: [PATCH 33/42] - Added Platform Helper to AID generation process - Resolved a false error in task validation - Removed the NO REMOTE TASK WARNING --- gen/ginc/Platform.php | 81 ++++++++++++++++++++++++++++ gen/ginc/msp430/Os_Internal_Defs.php | 5 +- gen/inc/Os_Cfg.h.php | 20 +++---- gen/src/Os_Internal_Cfg.c.php | 2 +- inc/cortexM4/Os_Internal_Arch.h | 8 +++ inc/msp430/Os_Arch.h | 39 +++----------- inc/msp430/Os_Internal_Arch.h | 56 +++++++++---------- 7 files changed, 135 insertions(+), 76 deletions(-) create mode 100644 gen/ginc/Platform.php diff --git a/gen/ginc/Platform.php b/gen/ginc/Platform.php new file mode 100644 index 00000000..d112ce06 --- /dev/null +++ b/gen/ginc/Platform.php @@ -0,0 +1,81 @@ +definitions["ARCH"]."/Os_Internal_Defs.php"); + +/*=================[user functions]==========================================*/ + +class Platform extends Helper +{ + public function __construct($config, $definitions, $log) + { + parent::__construct($config, $definitions, $log); + } + + /** \brief Returns the bitwidth of the int type of the choosen platform. + * return the number of bits that has the type int + */ + function getIntWidth() + { + /*TODO: should this be based on CIAAPLATFORM_REGLENGTH definition within ciaaPlatforms.h ? */ + if( $this->definitions["ARCH"]== "msp430") + { + return 16; + } + else + { + return 32; + } + } + +} +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +?> diff --git a/gen/ginc/msp430/Os_Internal_Defs.php b/gen/ginc/msp430/Os_Internal_Defs.php index d0a58b5c..e0bc349e 100644 --- a/gen/ginc/msp430/Os_Internal_Defs.php +++ b/gen/ginc/msp430/Os_Internal_Defs.php @@ -1,3 +1,4 @@ +definitions["CPU"]) { diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 6443b1ae..1e8c7540 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -74,8 +74,10 @@ loadHelper("modules/rtos/gen/ginc/Multicore.php"); +$this->loadHelper("modules/rtos/gen/ginc/Platform.php"); /* Definitions of Tasks : Tasks that will be executed within the local core */ +/* TODO: validate that tasks has different names */ $tasks = $this->helper->multicore->getLocalList("/OSEK", "TASK"); $remote_tasks = $this->helper->multicore->getRemoteList("/OSEK", "TASK"); $os = $this->config->getList("/OSEK","OS"); @@ -111,18 +113,12 @@ } print "\n"; - /* Define the Events */ -/* the max ammount of events is defined by the bit width of EventTypeMask type*/ -if( $this->definitions["ARCH"]== "msp430") -{ - $max_amount_events = 16; -} -else -{ - $max_amount_events = 32; -} +/* the max ammount of events is defined by the bit width of EventMaskType type */ +$max_amount_events = $this->helper->platform->getIntWidth(); + +//print("cant eventos max ".$max_amount_events."\n"); $flags_shared_event = $max_amount_events; /* it stores the number of bit for flags that are shared across tasks */ @@ -147,7 +143,7 @@ $nro_ev_task = count($matriz[$task_index]); #max(array_keys($matriz[$task_index])); - //print("evento $nro_ev_task"); + // print("tarea $task eventos $nro_ev_task"); /* Task Type validation: validates that this task is extended */ $extended = $this->config->getValue("/OSEK/" . $task, "TYPE"); @@ -159,7 +155,7 @@ else { // print("es extended"); - if ($nro_ev_task == 0 ) + if ($nro_ev_task == 0 && $extended != "BASIC") { //print("es extended mal"); trigger_error("===== OIL WARNING: The task $task could be TYPE: BASIC =====\n", E_USER_WARNING); diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 95cbd4ea..a26ad382 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -252,7 +252,7 @@ else { print "\n/* OIL FILE: THERE ARE NO REMOTE TASKS DEFINED IN THE SYSTEM */\n"; - trigger_error("===== OIL INFO: There are no REMOTE TASKS define in the OIL file =====\n", E_USER_NOTICE); + //trigger_error("===== OIL INFO: There are no REMOTE TASKS define in the OIL file =====\n", E_USER_NOTICE); } ?> }; diff --git a/inc/cortexM4/Os_Internal_Arch.h b/inc/cortexM4/Os_Internal_Arch.h index 76cb9c4a..aa9deb14 100644 --- a/inc/cortexM4/Os_Internal_Arch.h +++ b/inc/cortexM4/Os_Internal_Arch.h @@ -74,6 +74,14 @@ extern void * Osek_OldTaskPtr_Arch; extern void * Osek_NewTaskPtr_Arch; extern TaskType TerminatingTask; + +/** \brief Define common objects for using IntSecure_Start and IntSecure_End- + ** + ** This macro will be used internaly by the OS in any part of code that + ** has to be executed atomic. It should be placed before IntSecure_Start or IntSecure_End is called + **/ +#define IntSecure_Common() + /** \brief Interrupt Secure Start Macro ** ** This macro will be used internaly by the OS in any part of code that diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index 0ed3a6e0..411e5957 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -83,6 +83,12 @@ /** \brief Disable All Interrupts Arch */ #define DisableAllInterrupts_Arch() SuspendAllInterrupts_Arch() +/** \brief Resume All Interrupts Arch +** +** This macro shall resume (enable) all interrupts. +**/ +#define ResumeAllInterrupts_Arch() _enable_interrupts() ; + /** \brief Suspend All Interrupts Arch ** @@ -91,17 +97,8 @@ ** to workarround the hw bug cpu39 describer in slaz314h.pdf ** Also noted in Slau208, page 59. **/ - #define SuspendAllInterrupts_Arch() _disable_interrupts() ; __asm__ __volatile__ ("nop"); - - -/** \brief Resume All Interrupts Arch -** -** This macro shall resume (enable) all interrupts. -**/ -#define ResumeAllInterrupts_Arch() _enable_interrupts() ; - /** \brief Resume OS Interrupts Arch ** ** This macro shall resume (enable) all interrupts configured on the @@ -117,34 +114,10 @@ #define SuspendOSInterrupts_Arch() Disable_ISR2_Arch() /*==================[typedef]================================================*/ -/***************************************************************************** - * Please define here all needed types that will be visible to the OS user - * for this architecutre. This means that anyone including os.h will have - * access to these type definitions if the actual architecutre is used. - * Normaly no type has to be declared here. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ /*==================[external data declaration]==============================*/ -/***************************************************************************** - * Please declare here all exported data defined in Osek_Arch.c that will - * be visible to the OS user for this architectire. This means that anyone - * including os.h will have access to these variables, if the actual - * architecutre is used. Normaly no variables has to be declared here. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ /*==================[external functions declaration]=========================*/ -/***************************************************************************** - * Please declare here all exported functions defined in Osek_Arch.c that will - * be visible to the OS user for this architectire. This means that anyone - * including os.h will have access to these variables, if the actual - * architecutre is used. Normaly no variables has to be declared here. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index e25b4058..36129528 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -133,8 +133,11 @@ extern TaskType TerminatingTask; ** else to execute. The macro may sleep the cpu for a short time to avoid ** overheating and full power consumption or may halt the processor always ** that all wakeup reasons are right configured. If nothing is running - ** nothing my activate any task so we + ** nothing my activate any task so we will keep sleeping until anything + ** occurs, like for example an interrupt. + ** **/ + #define osekpause() asm volatile("nop") //TODO revisar los low power modes /** \brief SAVE_CONTEXT @@ -172,39 +175,43 @@ extern TaskType TerminatingTask; "pop r4\n\t"\ ); +/** \brief Call to an other Task + ** + ** This macro sholud be inserted before a naked interrupt handler ends. +*/ #define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); /** \brief Call to an other Task ** ** This function jmps to the indicated task. **/ -#define CallTask(actualtask, nexttask) \ -{ \ - Osek_OldTaskPtr_Arch = (void*) (TasksConst[(actualtask)].TaskContext); \ - Osek_NewTaskPtr_Arch = (void*) (TasksConst[(nexttask)].TaskContext); \ - /* next action will trigger assigned IRQ for the SWI */ \ - HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ +#define CallTask(actualtask, nexttask) \ +{ \ + Osek_OldTaskPtr_Arch = (void*) (TasksConst[(actualtask)].TaskContext); \ + Osek_NewTaskPtr_Arch = (void*) (TasksConst[(nexttask)].TaskContext); \ + /* next action will trigger assigned IRQ for the SWI */ \ + HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ } /** \brief Jmp to an other Task ** ** This function jmps to the indicated task. **/ -#define JmpTask(task) \ -{ \ - extern TaskType WaitingTask; \ - if(WaitingTask != INVALID_TASK) \ - { \ - Osek_OldTaskPtr_Arch = (void*) (TasksConst[WaitingTask].TaskContext);\ - WaitingTask = INVALID_TASK; \ - } \ - else \ - { \ - Osek_OldTaskPtr_Arch = (void*)0; \ - } \ - Osek_NewTaskPtr_Arch = (void*) (TasksConst[(task)].TaskContext); \ - /* next action will trigger assigned IRQ for the SWI */ \ - HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ +#define JmpTask(task) \ +{ \ + extern TaskType WaitingTask; \ + if(WaitingTask != INVALID_TASK) \ + { \ + Osek_OldTaskPtr_Arch = (void*) (TasksConst[WaitingTask].TaskContext); \ + WaitingTask = INVALID_TASK; \ + } \ + else \ + { \ + Osek_OldTaskPtr_Arch = (void*)0; \ + } \ + Osek_NewTaskPtr_Arch = (void*) (TasksConst[(task)].TaskContext); \ + /* next action will trigger assigned IRQ for the SWI */ \ + HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) |= (CCIFG|CCIE); \ } @@ -251,9 +258,6 @@ extern TaskType TerminatingTask; **/ #define EnableOSInterrupts() _enable_interrupts(); - - - /** \brief Enable Interruptions ** ** Enable not OS configured interrupts (ISR1 and ISR2). This macro @@ -273,8 +277,6 @@ extern TaskType TerminatingTask; **/ #define DisableOSInterrupts() _disable_interrupts(); __asm__ __volatile__ ("nop"); - - /** \brief Disable Interruptions ** ** Disable not OS configured interrupts (ISR1 and ISR2). This macro From 96dbb60e715815608774767c8699f6a9246d6544 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sat, 2 Jul 2016 12:47:59 -0300 Subject: [PATCH 34/42] - the $intList is retrieved from Platform.php --- gen/ginc/Platform.php | 10 +++++++++- gen/inc/Os_Cfg.h.php | 4 ---- gen/src/Os_Internal_Cfg.c.php | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gen/ginc/Platform.php b/gen/ginc/Platform.php index d112ce06..f28ef343 100644 --- a/gen/ginc/Platform.php +++ b/gen/ginc/Platform.php @@ -47,7 +47,7 @@ /*==================[inclusions]=============================================*/ require_once('Helper.php'); -require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); + /*=================[user functions]==========================================*/ @@ -64,6 +64,7 @@ public function __construct($config, $definitions, $log) function getIntWidth() { /*TODO: should this be based on CIAAPLATFORM_REGLENGTH definition within ciaaPlatforms.h ? */ + if( $this->definitions["ARCH"]== "msp430") { return 16; @@ -74,6 +75,13 @@ function getIntWidth() } } + function getInterruptHandlerList() + { + print("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php\n"); + + require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); + return $intList; + } } /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 1e8c7540..5b826aa7 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -143,8 +143,6 @@ $nro_ev_task = count($matriz[$task_index]); #max(array_keys($matriz[$task_index])); - // print("tarea $task eventos $nro_ev_task"); - /* Task Type validation: validates that this task is extended */ $extended = $this->config->getValue("/OSEK/" . $task, "TYPE"); @@ -154,10 +152,8 @@ } else { - // print("es extended"); if ($nro_ev_task == 0 && $extended != "BASIC") { -//print("es extended mal"); trigger_error("===== OIL WARNING: The task $task could be TYPE: BASIC =====\n", E_USER_WARNING); } } diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index a26ad382..2893533b 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -64,6 +64,10 @@ loadHelper("modules/rtos/gen/ginc/Multicore.php"); +$this->loadHelper("modules/rtos/gen/ginc/Platform.php"); + +/* get Interrupt list for platform */ +$intList = $this->helper->platform->getInterruptHandlerList(); /* get tasks */ $tasks = $this->helper->multicore->getLocalList("/OSEK", "TASK"); @@ -546,7 +550,7 @@ if( count($intnames)>0 ) /*it only process averything if there is any ISR define within the OIL */ { #includes the array where all IRQ array is defined, base on the architecture. -require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); +//require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); #for each ISR define in the OIL, we define the IRQ handler. foreach ($intnames as $int) From 6ef8a373a5ec7f8db6bb260a1f0a3ebeb8f29319 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 3 Jul 2016 17:49:30 -0300 Subject: [PATCH 35/42] - added Os_Internal_Defs.php for other platforms - some improvements in php templates - remove history and initials --- gen/ginc/Platform.php | 4 +- .../ginc/cortexM0/Os_Internal_Defs.php | 112 ++++---- gen/ginc/cortexM4/Os_Internal_Defs.php | 239 ++++++++++++++++++ gen/ginc/mips/Os_Internal_Defs.php | 63 +++++ gen/ginc/msp430/Os_Internal_Defs.php | 6 +- gen/ginc/x86/Os_Internal_Defs.php | 53 ++++ gen/inc/Os_Cfg.h.php | 119 ++++----- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 7 +- gen/src/Os_Internal_Cfg.c.php | 72 +++--- gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php | 53 +--- gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php | 184 +------------- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 22 +- .../gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 231 ----------------- inc/Os_Internal.h | 6 +- inc/msp430/Os_Internal_Arch.h | 16 +- .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 19 +- inc/x86/Os_Internal_Arch.h | 10 + 17 files changed, 547 insertions(+), 669 deletions(-) rename generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php => gen/ginc/cortexM0/Os_Internal_Defs.php (52%) create mode 100644 gen/ginc/cortexM4/Os_Internal_Defs.php create mode 100644 gen/ginc/mips/Os_Internal_Defs.php create mode 100644 gen/ginc/x86/Os_Internal_Defs.php delete mode 100644 generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php diff --git a/gen/ginc/Platform.php b/gen/ginc/Platform.php index f28ef343..e16d4506 100644 --- a/gen/ginc/Platform.php +++ b/gen/ginc/Platform.php @@ -76,9 +76,7 @@ function getIntWidth() } function getInterruptHandlerList() - { - print("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php\n"); - + { require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); return $intList; } diff --git a/generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/ginc/cortexM0/Os_Internal_Defs.php similarity index 52% rename from generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php rename to gen/ginc/cortexM0/Os_Internal_Defs.php index e1b03dc7..994a42ed 100644 --- a/generator/tests/ftest/fixtures/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/ginc/cortexM0/Os_Internal_Defs.php @@ -1,9 +1,11 @@ +definitions["CPU"]) +{ + case "lpc4337": + /* Interrupt sources for LPC43xx (Cortex-M0 core). + * See externals/platforms/cortexM0/lpc43xx/inc/cmsis_43xx_m0app.h. + */ + $intList = array ( + 0 => "RTC", + 1 => "M4CORE", + 2 => "DMA", + 3 => "RES1", + 4 => "FLASH_EEPROM_ATIMER", + 5 => "ETH", + 6 => "SDIO", + 7 => "LCD", + 8 => "USB0", + 9 => "USB1", + 10 => "SCT", + 11 => "RIT_WWDT", + 12 => "TIMER0", + 13 => "GINT1", + 14 => "PIN_INT4", + 15 => "TIMER3", + 16 => "MCPWM", + 17 => "ADC0", + 18 => "I2C0_I2C1", + 19 => "SGPIO", + 20 => "SPI_DAC", + 21 => "ADC1", + 22 => "SSP0_SSP1", + 23 => "EVENTROUTER", + 24 => "UART0", + 25 => "UART1", + 26 => "UART2_CCAN1", + 27 => "UART3", + 28 => "I2S0_I2S1_QEI", + 29 => "CCAN_0", + 30 => "ADCHS", + 31 => "M0SUB", + ); + break; + + default: + $this->log->error("the CPU " . $this->definitions["CPU"] . " is not supported."); + break; +} + + +?> diff --git a/gen/ginc/cortexM4/Os_Internal_Defs.php b/gen/ginc/cortexM4/Os_Internal_Defs.php new file mode 100644 index 00000000..63ed3cfb --- /dev/null +++ b/gen/ginc/cortexM4/Os_Internal_Defs.php @@ -0,0 +1,239 @@ +definitions["CPU"]) +{ + case "mk60fx512vlq15": + /* Interrupt sources for MK60F12. + * See externals/platforms/cortexM4/k60_120/inc/device/MK60F12/MK60F12.h. + */ + $intList = array ( + 0 => "DMA0_DMA16", + 1 => "DMA1_DMA17", + 2 => "DMA2_DMA18", + 3 => "DMA3_DMA19", + 4 => "DMA4_DMA20", + 5 => "DMA5_DMA21", + 6 => "DMA6_DMA22", + 7 => "DMA7_DMA23", + 8 => "DMA8_DMA24", + 9 => "DMA9_DMA25", + 10 => "DMA10_DMA26", + 11 => "DMA11_DMA27", + 12 => "DMA12_DMA28", + 13 => "DMA13_DMA29", + 14 => "DMA14_DMA30", + 15 => "DMA15_DMA31", + 16 => "DMA_ERR", + 17 => "MCM", + 18 => "FTFE", + 19 => "Read_Collision", + 20 => "LVD_LVW", + 21 => "LLW", + 22 => "WDG", + 23 => "RNG", + 24 => "I2C0", + 25 => "I2C1", + 26 => "SPI0", + 27 => "SPI1", + 28 => "SPI2", + 29 => "CAN0_READ", + 30 => "CAN0_BOFF", + 31 => "CAN0_ERR", + 32 => "CAN0_TXW", + 33 => "CAN0_RXW", + 34 => "CAN0_WAKEUP", + 35 => "I2S0_TX", + 36 => "I2S0_RR", + 37 => "CAN1_READ", + 38 => "CAN1_BOFF", + 39 => "CAN1_EERROR", + 40 => "CAN1_TXW", + 41 => "CAN1_RXW", + 42 => "CAN1_WAKEUP", + 43 => "RES59", + 44 => "UART0_LON", + 45 => "UART0", + 46 => "UART0_ERR", + 47 => "UART1", + 48 => "UART1_ERR", + 49 => "UART2", + 50 => "UART2_ERR", + 51 => "UART3", + 52 => "UART3_ERR", + 53 => "UART4", + 54 => "UART4_ERR", + 55 => "UART5", + 56 => "UART5_ERR", + 57 => "ADC0", + 58 => "ADC1", + 59 => "CMP0", + 60 => "CMP1", + 61 => "CMP2", + 62 => "FTM0", + 63 => "FTM1", + 64 => "FTM2", + 65 => "CMT", + 66 => "RTC", + 67 => "RTC_SEC", + 68 => "PIT0", + 69 => "PIT1", + 70 => "PIT2", + 71 => "PIT3", + 72 => "PDB0", + 73 => "USB0", + 74 => "USBDCD", + 75 => "ENET_1588_Timer", + 76 => "ENET_TX", + 77 => "ENET_RX", + 78 => "ENET_ERR", + 79 => "RES95", + 80 => "SDHC", + 81 => "DAC0", + 82 => "DAC1", + 83 => "TSI0", + 84 => "MCG", + 85 => "LPTimer", + 86 => "RES102", + 87 => "PORTA", + 88 => "PORTB", + 89 => "PORTC", + 90 => "PORTD", + 91 => "PORTE", + 92 => "PORTF", + 93 => "RES109", + 94 => "SWI", + 95 => "NFC", + 96 => "USBHS", + 97 => "RES113", + 98 => "CMP3", + 99 => "RES115", + 100 => "RES116", + 101 => "FTM3", + 102 => "ADC2", + 103 => "ADC3", + 104 => "I2S1_TX", + 105 => "I2S1_RX", + ); + break; + + case "lpc4337": + /* Interrupt sources for LPC43xx. + * See externals/platforms/cortexM4/lpc43xx/inc/cmsis_43xx.h. + */ + $intList = array ( + 0 => "DAC", + 1 => "M0APP", + 2 => "DMA", + 3 => "RES1", + 4 => "FLASH_EEPROM", + 5 => "ETH", + 6 => "SDIO", + 7 => "LCD", + 8 => "USB0", + 9 => "USB1", + 10 => "SCT", + 11 => "RIT", + 12 => "TIMER0", + 13 => "TIMER1", + 14 => "TIMER2", + 15 => "TIMER3", + 16 => "MCPWM", + 17 => "ADC0", + 18 => "I2C0", + 19 => "I2C1", + 20 => "SPI", + 21 => "ADC1", + 22 => "SSP0", + 23 => "SSP1", + 24 => "UART0", + 25 => "UART1", + 26 => "UART2", + 27 => "UART3", + 28 => "I2S0", + 29 => "I2S1", + 30 => "SPIFI", + 31 => "SGPIO", + 32 => "GPIO0", + 33 => "GPIO1", + 34 => "GPIO2", + 35 => "GPIO3", + 36 => "GPIO4", + 37 => "GPIO5", + 38 => "GPIO6", + 39 => "GPIO7", + 40 => "GINT0", + 41 => "GINT1", + 42 => "EVRT", + 43 => "CAN1", + 44 => "RES6", + 45 => "ADCHS", + 46 => "ATIMER", + 47 => "RTC", + 48 => "RES8", + 49 => "WDT", + 50 => "M0SUB", + 51 => "CAN0", + 52 => "QEI" + ); + break; + + default: + $this->log->error("the CPU " . $this->definitions["CPU"] . " is not supported."); + break; +} + + +?> diff --git a/gen/ginc/mips/Os_Internal_Defs.php b/gen/ginc/mips/Os_Internal_Defs.php new file mode 100644 index 00000000..363f56fe --- /dev/null +++ b/gen/ginc/mips/Os_Internal_Defs.php @@ -0,0 +1,63 @@ +definitions["CPU"]) +{ + + + default: + $this->log->error("the CPU " . $this->definitions["CPU"] . " is not supported."); + break; +} + + +?> diff --git a/gen/ginc/msp430/Os_Internal_Defs.php b/gen/ginc/msp430/Os_Internal_Defs.php index e0bc349e..410890a8 100644 --- a/gen/ginc/msp430/Os_Internal_Defs.php +++ b/gen/ginc/msp430/Os_Internal_Defs.php @@ -48,9 +48,9 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - + /** \brief Handlers used by OSEK */ -switch ($this->definitions["CPU"]) +switch ( $this->definitions["CPU"] ) { case "msp430f5529": /* Interrupt sources for msp430f5529 @@ -89,5 +89,5 @@ break; } -$MAX_INT_COUNT = max(array_keys($intList))+1; + ?> diff --git a/gen/ginc/x86/Os_Internal_Defs.php b/gen/ginc/x86/Os_Internal_Defs.php new file mode 100644 index 00000000..19f198a7 --- /dev/null +++ b/gen/ginc/x86/Os_Internal_Defs.php @@ -0,0 +1,53 @@ + diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 5b826aa7..a796ce98 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -82,25 +82,23 @@ $remote_tasks = $this->helper->multicore->getRemoteList("/OSEK", "TASK"); $os = $this->config->getList("/OSEK","OS"); -$count = 0; -foreach ($tasks as $task) +foreach ($tasks as $task_idx => $task) { - print "/** \brief Task Definition */\n"; - print "#define $task $count\n"; - $count++; + print "\n/** \brief Task Definition */\n"; + print "#define $task $task_idx\n"; } -print "\n"; + +$count = count( $tasks ); /* Definitions of Tasks : Tasks that will be executed within the remote core*/ -if (count($remote_tasks) > 0) +if( count($remote_tasks) > 0) { foreach ($remote_tasks as $task) { - print "/** \brief Remote Task Definition */\n"; + print "\n/** \brief Remote Task Definition */\n"; print "#define $task $count\n"; $count++; } - print "\n"; } /* Define the Applications Modes */ @@ -108,21 +106,19 @@ foreach ($appmodes as $count=>$appmode) { - print "/** \brief Definition of the Application Mode $appmode */\n"; + print "\n/** \brief Definition of the Application Mode $appmode */\n"; print "#define " . $appmode . " " . $count . "\n"; } -print "\n"; /* Define the Events */ /* the max ammount of events is defined by the bit width of EventMaskType type */ $max_amount_events = $this->helper->platform->getIntWidth(); - -//print("cant eventos max ".$max_amount_events."\n"); + $flags_shared_event = $max_amount_events; /* it stores the number of bit for flags that are shared across tasks */ -$matriz = array( ); /* it stores the events' name for each task */ +$matriz = array(); /* it stores the events' name for each task */ $matrix_n = array(); /* it stores the events' assigned number for each task */ $events = $this->config->getList("/OSEK","EVENT"); @@ -131,9 +127,8 @@ #print("cantidad de eventos: $nro_evs \n"); /* task/events matrix creation, and various validations */ -$task_index = 0; -foreach( $tasks as $task ) -{ +foreach( $tasks as $task_index => $task ) +{ $empty_array = array(); $temp_array = $this->config->getList("/OSEK/". $task , "EVENT" ); @@ -172,26 +167,20 @@ { } } - - $task_index++; } /* generation of the shared events between tasks */ print "\n/** \brief Shared events across tasks */\n\n"; -$ev_index = 0; +$ev_index = 0; foreach( $events as $ev ) //para cada evento, lo busco en cada array de eventos para la tarea { - //print( "//Procesando evento $ev \n" ); - $task_index = 0; - $count=0; //almacena la cuenta de cuantas tareas tiene el evento $task_single_event = ""; //almacena la ultima tarea en la cual encontro el evento - foreach( $tasks as $task ) + foreach( $tasks as $task_index => $task ) { - #$events_for_task = $this->config->getList("/OSEK/". $task , "EVENT" ); $key = array_search( $ev, $matriz[$task_index] ); if( $key !== false ) //busco el evento en el array de eventos de la tarea. @@ -199,43 +188,38 @@ /* lo encontro */ $count++; } - - $task_index++; } + - //print_r("\n$ev $count \n" ); - - if($count>1) + if( $count>1 ) { /* there is more that one task with the current event */ $flags_shared_event--; - if($flags_shared_event<0 ) + if( $flags_shared_event<0 ) { trigger_error("===== OIL ERROR: There are more than $max_amount_events events defined. =====\n", E_USER_ERROR); /* stops execution */ } - print "/** \brief Definition of the Event: $ev */\n"; + print "\n/** \brief Definition of the Event: $ev */\n"; print "#define " . $ev . " 0x" . sprintf ("%xU", (1<<$flags_shared_event)) . "\n"; /* this shared's event number is stored in matrix_n */ - $task_index = 0; - foreach( $tasks as $task ) + foreach( $tasks as $task_index => $task ) { - $key = array_search( $ev, $matriz[$task_index] ); //EL EVENTO TIENE QUE EXISTIR SI O SI. + $key = array_search( $ev, $matriz[$task_index] ); //EL EVENTO TIENE QUE EXISTIR SI O SI. unset($matriz[$task_index][$key]); //LO SACO DE LA TABLA DE EVENTOS DE LA TAREA array_push( $matrix_n[$task_index] , $flags_shared_event ); - $task_index++; } } $ev_index++; } + //print_r($matriz); -print "\n\n/** \brief Exclusive events for each task */\n\n"; -$task_index = 0; -foreach( $tasks as $task ) +print "\n/** \brief Exclusive events for each task */\n\n"; +foreach( $tasks as $task_index=> $task ) { $flags_exc_event = 0; /* it stores the number of bit for flags that are exclusively for one task */ @@ -247,7 +231,7 @@ /* stops execution */ } - print "/** \brief Definition of the Event: $ev for task: $task*/\n"; + print "\n/** \brief Definition of the Event: $ev for task: $task*/\n"; print "#define " . $ev . " 0x" . sprintf ("%xU", (1<<$flags_exc_event)) . "\n"; $temp = $flags_exc_event; @@ -256,11 +240,10 @@ $flags_exc_event++; } - $task_index++; } /* Last validation: check if events repeats */ -$task_index =0; +$task_index = 0; foreach ($matrix_n as $array) { #print_r($array); @@ -277,7 +260,6 @@ } $task_index ++; } -print "\n"; //$events = $this->config->getList("/OSEK","EVENT"); @@ -293,35 +275,33 @@ foreach ($resources as $count=>$resource) { - print "/** \brief Definition of the resource $resource */\n"; + print "\n/** \brief Definition of the resource $resource */\n"; print "#define " . $resource . " ((ResourceType)" . $count . ")\n"; } -print "\n"; /* Define the Alarms */ $alarms = $this->helper->multicore->getLocalList("/OSEK", "ALARM"); foreach ($alarms as $count=>$alarm) { - print "/** \brief Definition of the Alarm $alarm */\n"; + print "\n/** \brief Definition of the Alarm $alarm */\n"; print "#define " . $alarm . " " . $count . "\n"; } -print "\n"; /* Define the Counters */ $counters = $this->helper->multicore->getLocalList("/OSEK", "COUNTER"); foreach ($counters as $count=>$counter) { - print "/** \brief Definition of the Counter $counter */\n"; + print "\n/** \brief Definition of the Counter $counter */\n"; print "#define " . $counter . " " . $count . "\n"; } -print "\n"; $errorhook=$this->config->getValue("/OSEK/" . $os[0],"ERRORHOOK"); if ($errorhook == "TRUE") { ?> + /** \brief OS Error Get Service Id */ /* \req OSEK_ERR_0.1 The macro OSErrorGetServiceId() shall provide the service * identifier with a OSServiceIdType type where the error has been risen @@ -342,7 +322,7 @@ } $memmap = $this->config->getValue("/OSEK/" . $os[0],"MEMMAP"); -print "/** \brief OSEK_MEMMAP macro (OSEK_DISABLE not MemMap is used for FreeOSEK, OSEK_ENABLE\n ** MemMap is used for FreeOSEK) */\n"; +print "\n/** \brief OSEK_MEMMAP macro (OSEK_DISABLE not MemMap is used for FreeOSEK, OSEK_ENABLE\n ** MemMap is used for FreeOSEK) */\n"; if ($memmap == "TRUE") { print "#define OSEK_MEMMAP OSEK_ENABLE\n"; @@ -358,7 +338,9 @@ } $osattr = $this->config->getValue("/OSEK/" . $os[0],"STATUS"); -if ($osattr == "EXTENDED") : ?> +if ($osattr == "EXTENDED") : +?> + /** \brief Schedule this Task if higher priority Task are Active ** ** \remarks if the system is configured with extended errors the @@ -393,6 +375,7 @@ if ($errorhook == "TRUE") { ?> + /** \brief Error Api Variable ** ** This variable contents the api which generate the last error @@ -436,51 +419,50 @@ $pretaskhook=$this->config->getValue("/OSEK/" . $os[0],"PRETASKHOOK"); if ($pretaskhook == "TRUE") { - print "/** \brief Pre Task Hook */\n"; - print "extern void PreTaskHook(void);\n\n"; + print "\n/** \brief Pre Task Hook */\n"; + print "extern void PreTaskHook(void);\n"; } + $posttaskhook=$this->config->getValue("/OSEK/" . $os[0],"POSTTASKHOOK"); if ($posttaskhook == "TRUE") { - print "/** \brief Post Task Hook */\n"; - print "extern void PostTaskHook(void);\n\n"; + print "\n/** \brief Post Task Hook */\n"; + print "extern void PostTaskHook(void);\n"; } $shutdownhook=$this->config->getValue("/OSEK/" . $os[0],"SHUTDOWNHOOK"); if ($shutdownhook == "TRUE") { - print "/** \brief Shutdown Hook */\n"; - print "extern void ShutdownHook(void);\n\n"; + print "\n/** \brief Shutdown Hook */\n"; + print "extern void ShutdownHook(void);\n"; } $startuphook=$this->config->getValue("/OSEK/" . $os[0],"STARTUPHOOK"); if ($startuphook == "TRUE") { - print "/** \brief Startup Hook */\n"; - print "extern void StartupHook(void);\n\n"; + print "\n/** \brief Startup Hook */\n"; + print "extern void StartupHook(void);\n"; } $errorhook=$this->config->getValue("/OSEK/" . $os[0],"ERRORHOOK"); if ($errorhook == "TRUE") { - print "/** \brief Error Hook */\n"; - print "extern void ErrorHook(void);\n\n"; + print "\n/** \brief Error Hook */\n"; + print "extern void ErrorHook(void);\n"; } /* Declare Tasks */ foreach ($tasks as $count=>$task) { - print "/** \brief Task Declaration of Task $task */\n"; + print "\n/** \brief Task Declaration of Task $task */\n"; print "DeclareTask($task);\n"; } -print "\n"; $intnames = $this->helper->multicore->getLocalList("/OSEK", "ISR"); foreach ($intnames as $count=>$int) { - print "/** \brief ISR Declaration */\n"; + print "\n/** \brief ISR Declaration */\n"; print "extern void OSEK_ISR_$int(void); /* Interrupt Handler $int */\n"; } -print "\n"; $alarms = $this->helper->multicore->getLocalList("/OSEK", "ALARM"); @@ -489,13 +471,13 @@ $action = $this->config->getValue("/OSEK/" . $alarm, "ACTION"); if ($action == "ALARMCALLBACK") { - print "/** \brief Alarm Callback declaration */\n"; + print "\n/** \brief Alarm Callback declaration */\n"; print "extern void OSEK_CALLBACK_" . $this->config->getValue("/OSEK/" . $alarm . "/ALARMCALLBACK", "ALARMCALLBACKNAME") . "(void);\n"; } } -print "\n"; $osattr = $this->config->getValue("/OSEK/" . $os[0],"STATUS"); ?> + /** \brief Schedule this Task if higher priority Task are Active ** ** This API shall Schedule the calling Task if a higher priority Task @@ -517,10 +499,13 @@ ** \return E_OS_CALLEVEL if call at interrupt level ** \return E_OS_RESOURCE if the calling task occupies resources **/ + extern StatusType Schedule_Int(boolean PerformChecks); + extern StatusType Schedule(void); + /** @} doxygen end group definition */ diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index ab229993..22715f81 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -90,9 +90,14 @@ /* Macros for Disable / Enable User ISR for any catergory (this optimize the processing of Enabling and Disablen System IRQs)*/ $this->loadHelper("modules/rtos/gen/ginc/Multicore.php"); +$this->loadHelper("modules/rtos/gen/ginc/Platform.php"); -require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); +/* get Avalible Interrupt list for platform */ +$intList = $this->helper->platform->getInterruptHandlerList(); +$MAX_INT_COUNT = max(array_keys($intList))+1; + +/* get Interrupt names from OIL */ $intnames = $this->helper->multicore->getLocalList("/OSEK", "ISR"); foreach ($intnames as $int) diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 2893533b..089862d1 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -74,7 +74,7 @@ foreach ($tasks as $task) { - print "/** \brief $task stack */\n"; + print "\n/** \brief $task stack */\n"; print "#if ( x86 == ARCH )\n"; print "uint8 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ." + TASK_STACK_ADDITIONAL_SIZE];\n"; print "#else\n"; @@ -86,28 +86,24 @@ } else { - print "uint8 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ."];\n"; + print "uint8 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ."];\n"; } print "#endif\n"; - print "\n"; } -print "\n"; foreach ($tasks as $task) { - print "/** \brief $task context */\n"; + print "\n/** \brief $task context */\n"; print "TaskContextType ContextTask" . $task . ";\n"; - print "\n"; } -print "\n"; $priority = $this->config->priority2osekPriority($tasks); /* Ready List */ foreach ($priority as $prio) { - print "/** \brief Ready List for Priority $prio */\n"; + print "\n/** \brief Ready List for Priority $prio */\n"; $count = 0; foreach ($tasks as $task) { @@ -117,7 +113,6 @@ } } print "TaskType ReadyList" . $prio . "[" . $count . "];\n"; - print "\n"; } $counters = $this->helper->multicore->getLocalList("/OSEK", "COUNTER"); @@ -143,7 +138,6 @@ } print "};\n\n"; } - ?> /*==================[external data definition]===============================*/ @@ -236,22 +230,25 @@ ?> }; -/** \brief RemoteTaskCore Array */ -const TaskCoreType RemoteTasksCore[REMOTE_TASKS_COUNT] = { helper->multicore->getRemoteList("/OSEK", "TASK"); $rtasks_count = count($rtasks); if( $rtasks_count>0 ) { + print("\n/** \brief RemoteTaskCore Array */\n"); + print("const TaskCoreType RemoteTasksCore[REMOTE_TASKS_COUNT] = {\n"); + for($i=0; $i<$rtasks_count; $i++) { - print $this->config->getValue("/OSEK/$rtasks[$i]", "CORE"); + print $this->config->getValue("/OSEK/$rtasks[$i]", "CORE"); if ($i < (count($rtasks)-1)) { print ", "; } } + + print("};\n"); } else { @@ -259,7 +256,7 @@ //trigger_error("===== OIL INFO: There are no REMOTE TASKS define in the OIL file =====\n", E_USER_NOTICE); } ?> -}; + /** \brief TaskVar Array */ TaskVariableType TasksVar[TASKS_COUNT]; @@ -416,8 +413,8 @@ $alarms_autostart++; } print " {\n"; - print " OSEK_COUNTER_" . $this->config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; - $action = $this->config->getValue("/OSEK/" . $alarm, "ACTION"); + print " OSEK_COUNTER_" . $this->config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; + $action = $this->config->getValue("/OSEK/" . $alarm, "ACTION"); print " " . $action . ", /* Alarm action */\n"; print " {\n"; switch ($action) @@ -426,22 +423,22 @@ print " NULL, /* no callback */\n"; print " 0, /* no task id */\n"; print " 0, /* no event */\n"; - print " OSEK_COUNTER_" . $this->config->getValue("/OSEK/" . $alarm . "/INCREMENT","COUNTER") . " /* counter */\n"; + print " OSEK_COUNTER_" . $this->config->getValue("/OSEK/" . $alarm . "/INCREMENT","COUNTER") . " /* counter */\n"; break; case "ACTIVATETASK": print " NULL, /* no callback */\n"; - print " " . $this->config->getValue("/OSEK/" . $alarm . "/ACTIVATETASK","TASK") . ", /* TaskID */\n"; + print " " . $this->config->getValue("/OSEK/" . $alarm . "/ACTIVATETASK","TASK") . ", /* TaskID */\n"; print " 0, /* no event */\n"; print " 0 /* no counter */\n"; break; case "SETEVENT": print " NULL, /* no callback */\n"; - print " " . $this->config->getValue("/OSEK/" . $alarm . "/SETEVENT","TASK") . ", /* TaskID */\n"; - print " " . $this->config->getValue("/OSEK/" . $alarm . "/SETEVENT","EVENT") . ", /* no event */\n"; + print " " . $this->config->getValue("/OSEK/" . $alarm . "/SETEVENT","TASK") . ", /* TaskID */\n"; + print " " . $this->config->getValue("/OSEK/" . $alarm . "/SETEVENT","EVENT") . ", /* no event */\n"; print " 0 /* no counter */\n"; break; case "ALARMCALLBACK": - print " OSEK_CALLBACK_" . $this->config->getValue("/OSEK/" . $alarm . "/ALARMCALLBACK", "ALARMCALLBACKNAME") . ", /* callback */\n"; + print " OSEK_CALLBACK_" . $this->config->getValue("/OSEK/" . $alarm . "/ALARMCALLBACK", "ALARMCALLBACKNAME") . ", /* callback */\n"; print " 0, /* no taskid */\n"; print " 0, /* no event */\n"; print " 0 /* no counter */\n"; @@ -463,7 +460,7 @@ $first = true; foreach ($alarms as $count=>$alarm) { - if ($this->config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + if ($this->config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") { if ($first == false) { @@ -475,11 +472,11 @@ } print " {\n"; - print " " . $this->config->getValue("/OSEK/" . $alarm, "APPMODE") . ", /* Application Mode */\n"; - // print " OSEK_COUNTER_" . $this->config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; + print " " . $this->config->getValue("/OSEK/" . $alarm, "APPMODE") . ", /* Application Mode */\n"; + // print " OSEK_COUNTER_" . $this->config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; print " $alarm, /* Alarms */\n"; - print " " . $this->config->getValue("/OSEK/" . $alarm, "ALARMTIME") . ", /* Alarm Time */\n"; - print " " . $this->config->getValue("/OSEK/" . $alarm, "CYCLETIME") . " /* Alarm Time */\n"; + print " " . $this->config->getValue("/OSEK/" . $alarm, "ALARMTIME") . ", /* Alarm Time */\n"; + print " " . $this->config->getValue("/OSEK/" . $alarm, "CYCLETIME") . " /* Alarm Time */\n"; print " }"; } } @@ -514,9 +511,9 @@ } print " $countalarms, /* quantity of alarms for this counter */\n"; print " (AlarmType*)OSEK_ALARMLIST_" . $counter . ", /* alarms list */\n"; - print " " . $this->config->getValue("/OSEK/" . $counter,"MAXALLOWEDVALUE") . ", /* max allowed value */\n"; - print " " . $this->config->getValue("/OSEK/" . $counter,"MINCYCLE") . ", /* min cycle */\n"; - print " " . $this->config->getValue("/OSEK/" . $counter,"TICKSPERBASE") . " /* ticks per base */\n"; + print " " . $this->config->getValue("/OSEK/" . $counter,"MAXALLOWEDVALUE") . ", /* max allowed value */\n"; + print " " . $this->config->getValue("/OSEK/" . $counter,"MINCYCLE") . ", /* min cycle */\n"; + print " " . $this->config->getValue("/OSEK/" . $counter,"TICKSPERBASE") . " /* ticks per base */\n"; print " }"; } print "\n};\n\n"; @@ -540,18 +537,16 @@ */ uint8 ErrorHookRunning = 0; -/*==================[internal functions definition]==========================*/ - /*==================[external functions definition]==========================*/ + +/*==================[internal functions definition]==========================*/ helper->multicore->getLocalList("/OSEK", "ISR"); + if( count($intnames)>0 ) /*it only process averything if there is any ISR define within the OIL */ { - #includes the array where all IRQ array is defined, base on the architecture. -//require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); - #for each ISR define in the OIL, we define the IRQ handler. foreach ($intnames as $int) { @@ -569,17 +564,18 @@ ?> void OSEK_ISR2_(void) { - +?> /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); diff --git a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php index 3ec72102..55879c47 100644 --- a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php @@ -4,8 +4,7 @@ /* Copyright 2014, 2015 Mariano Cerdeiro * Copyright 2014, 2015 Pablo Ridolfi - * Copyright 2015, Alejandro Permingeat - * Copyright 2016, Franco Bucafusco + * Copyright 2015, Alejandro Permingeat * * All rights reserved. * @@ -125,52 +124,10 @@ /*==================[external functions definition]==========================*/ definitions["CPU"]) -{ - case "lpc4337": - /* Interrupt sources for LPC43xx (Cortex-M0 core). - * See externals/platforms/cortexM0/lpc43xx/inc/cmsis_43xx_m0app.h. - */ - $intList = array ( - 0 => "RTC", - 1 => "M4CORE", - 2 => "DMA", - 3 => "RES1", - 4 => "FLASH_EEPROM_ATIMER", - 5 => "ETH", - 6 => "SDIO", - 7 => "LCD", - 8 => "USB0", - 9 => "USB1", - 10 => "SCT", - 11 => "RIT_WWDT", - 12 => "TIMER0", - 13 => "GINT1", - 14 => "PIN_INT4", - 15 => "TIMER3", - 16 => "MCPWM", - 17 => "ADC0", - 18 => "I2C0_I2C1", - 19 => "SGPIO", - 20 => "SPI_DAC", - 21 => "ADC1", - 22 => "SSP0_SSP1", - 23 => "EVENTROUTER", - 24 => "UART0", - 25 => "UART1", - 26 => "UART2_CCAN1", - 27 => "UART3", - 28 => "I2S0_I2S1_QEI", - 29 => "CCAN_0", - 30 => "ADCHS", - 31 => "M0SUB", - ); - break; +$this->loadHelper("modules/rtos/gen/ginc/Platform.php"); - default: - error("the CPU " . $this->definitions["CPU"] . " is not supported."); - break; -} +/* get Interrupt list for platform */ +$intList = $this->helper->platform->getInterruptHandlerList(); $MAX_INT_COUNT = max(array_keys($intList))+1; @@ -297,7 +254,7 @@ if($cat == 2) { $key = array_search($source, $intList); - + if( $key !== false ) { print " /* Disabling IRQ $source */\n"; diff --git a/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php b/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php index b14a9e49..84ffe2c5 100644 --- a/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php @@ -137,188 +137,10 @@ /*==================[external functions definition]==========================*/ loadHelper("modules/rtos/gen/ginc/Multicore.php"); +$this->loadHelper("modules/rtos/gen/ginc/Platform.php"); -switch ($this->definitions["CPU"]) -{ - case "mk60fx512vlq15": - /* Interrupt sources for MK60F12. - * See externals/platforms/cortexM4/k60_120/inc/device/MK60F12/MK60F12.h. - */ - $intList = array ( - 0 => "DMA0_DMA16", - 1 => "DMA1_DMA17", - 2 => "DMA2_DMA18", - 3 => "DMA3_DMA19", - 4 => "DMA4_DMA20", - 5 => "DMA5_DMA21", - 6 => "DMA6_DMA22", - 7 => "DMA7_DMA23", - 8 => "DMA8_DMA24", - 9 => "DMA9_DMA25", - 10 => "DMA10_DMA26", - 11 => "DMA11_DMA27", - 12 => "DMA12_DMA28", - 13 => "DMA13_DMA29", - 14 => "DMA14_DMA30", - 15 => "DMA15_DMA31", - 16 => "DMA_ERR", - 17 => "MCM", - 18 => "FTFE", - 19 => "Read_Collision", - 20 => "LVD_LVW", - 21 => "LLW", - 22 => "WDG", - 23 => "RNG", - 24 => "I2C0", - 25 => "I2C1", - 26 => "SPI0", - 27 => "SPI1", - 28 => "SPI2", - 29 => "CAN0_READ", - 30 => "CAN0_BOFF", - 31 => "CAN0_ERR", - 32 => "CAN0_TXW", - 33 => "CAN0_RXW", - 34 => "CAN0_WAKEUP", - 35 => "I2S0_TX", - 36 => "I2S0_RR", - 37 => "CAN1_READ", - 38 => "CAN1_BOFF", - 39 => "CAN1_EERROR", - 40 => "CAN1_TXW", - 41 => "CAN1_RXW", - 42 => "CAN1_WAKEUP", - 43 => "RES59", - 44 => "UART0_LON", - 45 => "UART0", - 46 => "UART0_ERR", - 47 => "UART1", - 48 => "UART1_ERR", - 49 => "UART2", - 50 => "UART2_ERR", - 51 => "UART3", - 52 => "UART3_ERR", - 53 => "UART4", - 54 => "UART4_ERR", - 55 => "UART5", - 56 => "UART5_ERR", - 57 => "ADC0", - 58 => "ADC1", - 59 => "CMP0", - 60 => "CMP1", - 61 => "CMP2", - 62 => "FTM0", - 63 => "FTM1", - 64 => "FTM2", - 65 => "CMT", - 66 => "RTC", - 67 => "RTC_SEC", - 68 => "PIT0", - 69 => "PIT1", - 70 => "PIT2", - 71 => "PIT3", - 72 => "PDB0", - 73 => "USB0", - 74 => "USBDCD", - 75 => "ENET_1588_Timer", - 76 => "ENET_TX", - 77 => "ENET_RX", - 78 => "ENET_ERR", - 79 => "RES95", - 80 => "SDHC", - 81 => "DAC0", - 82 => "DAC1", - 83 => "TSI0", - 84 => "MCG", - 85 => "LPTimer", - 86 => "RES102", - 87 => "PORTA", - 88 => "PORTB", - 89 => "PORTC", - 90 => "PORTD", - 91 => "PORTE", - 92 => "PORTF", - 93 => "RES109", - 94 => "SWI", - 95 => "NFC", - 96 => "USBHS", - 97 => "RES113", - 98 => "CMP3", - 99 => "RES115", - 100 => "RES116", - 101 => "FTM3", - 102 => "ADC2", - 103 => "ADC3", - 104 => "I2S1_TX", - 105 => "I2S1_RX", - ); - break; - - case "lpc4337": - /* Interrupt sources for LPC43xx. - * See externals/platforms/cortexM4/lpc43xx/inc/cmsis_43xx.h. - */ - $intList = array ( - 0 => "DAC", - 1 => "M0APP", - 2 => "DMA", - 3 => "RES1", - 4 => "FLASH_EEPROM", - 5 => "ETH", - 6 => "SDIO", - 7 => "LCD", - 8 => "USB0", - 9 => "USB1", - 10 => "SCT", - 11 => "RIT", - 12 => "TIMER0", - 13 => "TIMER1", - 14 => "TIMER2", - 15 => "TIMER3", - 16 => "MCPWM", - 17 => "ADC0", - 18 => "I2C0", - 19 => "I2C1", - 20 => "SPI", - 21 => "ADC1", - 22 => "SSP0", - 23 => "SSP1", - 24 => "UART0", - 25 => "UART1", - 26 => "UART2", - 27 => "UART3", - 28 => "I2S0", - 29 => "I2S1", - 30 => "SPIFI", - 31 => "SGPIO", - 32 => "GPIO0", - 33 => "GPIO1", - 34 => "GPIO2", - 35 => "GPIO3", - 36 => "GPIO4", - 37 => "GPIO5", - 38 => "GPIO6", - 39 => "GPIO7", - 40 => "GINT0", - 41 => "GINT1", - 42 => "EVRT", - 43 => "CAN1", - 44 => "RES6", - 45 => "ADCHS", - 46 => "ATIMER", - 47 => "RTC", - 48 => "RES8", - 49 => "WDT", - 50 => "M0SUB", - 51 => "CAN0", - 52 => "QEI" - ); - break; - - default: - $this->log->error("the CPU " . $this->definitions["CPU"] . " is not supported."); - break; -} +/* get Interrupt list for platform */ +$intList = $this->helper->platform->getInterruptHandlerList(); $MAX_INT_COUNT = max(array_keys($intList))+1; diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 8abe0dcf..93c6b03c 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -47,12 +47,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * v0.1.0 20160221 initial version - */ + /*==================[inclusions]=============================================*/ #include "Os_Internal.h" @@ -97,14 +92,19 @@ } /*==================[external functions definition]==========================*/ -loadHelper("modules/rtos/gen/ginc/Multicore.php"); +$this->loadHelper("modules/rtos/gen/ginc/Platform.php"); + +/* get Interrupt list for platform */ +$intList = $this->helper->platform->getInterruptHandlerList(); -require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); +$MAX_INT_COUNT = max(array_keys($intList))+1; ?> + /*** Non Used Interrupt handlers ***/ -helper->multicore->getLocalList("/OSEK", "ISR"); for($i=0; $i < $MAX_INT_COUNT; $i++) @@ -191,12 +191,12 @@ foreach ($intnames as $int) { $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); - $prio = $this->config->getValue("/OSEK/" . $int,"PRIORITY"); + //$prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); $key = array_search($source, $intList); if( $key !== false ) { - print " /* Enabling IRQ $source with priority $prio */\n"; + print " /* Enabling IRQ $source */\n"; print " MSP430_EnableIRQ(" . $key. ");\n"; } else diff --git a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php deleted file mode 100644 index 32d70870..00000000 --- a/generator/tests/ftest/fixtures/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************** - * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* - ********************************************************/ - -/* Copyright 2016, Franco Bucafusco - * All rights reserved. - * - * This file is part of CIAA Firmware. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** \brief FreeOSEK Os Generated Internal Achitecture Configuration Implementation File - ** - ** \file msp430/Os_Internal_Arch_Cfg.c - ** \arch msp430 - **/ - -/** \addtogroup FreeOSEK - ** @{ */ -/** \addtogroup FreeOSEK_Os - ** @{ */ -/** \addtogroup FreeOSEK_Os_Internal - ** @{ */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * v0.1.0 20160221 initial version - */ - -/*==================[inclusions]=============================================*/ -#include "Os_Internal.h" - -#if(CPU == msp430f5x_6x) -/* THIS IS A DIRTY WORKAROUND :( ciaa/Firmware#309*/ -#undef FALSE -#undef TRUE -#include "msp430.h" -#endif - -/*==================[macros and definitions]=================================*/ - -/*==================[internal data declaration]==============================*/ - -/*==================[internal functions declaration]=========================*/ - - -/*==================[internal data definition]===============================*/ - -/*==================[external data definition]===============================*/ -definitions["ARCH"]."/Os_Internal_Defs.php"); - -#if (CPU == msp430f5529) - -#else -#error Not supported CPU -#endif - -/** \brief Handlers used by OSEK */ - - -/*==================[internal functions definition]==========================*/ -/* Default exception handlers */ - -?> - -/*==================[external functions definition]==========================*/ - -__attribute__( (__interrupt_vec(UNMI_VECTOR),naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ -void OSEK_ISR_UNMI_VECTOR(void) -{ - while (1) - { - } -} - -__attribute__( (__interrupt_vec(SYSNMI_VECTOR),naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ -void OSEK_ISR_SYSNMI_VECTOR(void) -{ - while (1) - { - } -} - - /*** Non Used Interrupt handlers ***/ -getList("/OSEK", "ISR"); - -for($i=0; $i < $MAX_INT_COUNT; $i++) -{ - $src_found = 0; - - foreach ($intnames as $int) - { - /* - handlers that are present in the system (defined in the oil file) - do not add extra code here. - */ - $intcat = $config->getValue("/OSEK/" . $int,"CATEGORY"); - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - - if($intList[$i] == $source) - { - if ($intcat == 2) - { - $src_found = 1; - } elseif ($intcat == 1) - { - $src_found = 1; - } - else - { - $this->log->error("Interrupt $int type $inttype has an invalid category $intcat"); - } - } - } - - if( $intList[$i]=="TIMER2_A1" || $intList[$i]=="TIMER2_A0" || $intList[$i]=="RESET" || $intList[$i]=="UNMI" || $intList[$i]=="SYSNMI" ) - { - /* - This part forces irq_handlers not to be defined here. - TIMER2_XX: Use for OSEK periodic interrupt - RESET: defined by gcc @ compile time. - UNMI: defined in this file - SYSNMI: defined in this file - */ - $src_found = 1; - } - - if($src_found == 0) - { - print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; - print "void OSEK_ISR_$intList[$i]_VECTOR(void)\n"; - print "{\n"; - print "}\n"; - } -} -?> - -/** \brief Interrupt enabling and priority setting function */ -void Enable_User_ISRs(void) -{ -getList("/OSEK", "ISR"); - -foreach ($intnames as $int) -{ - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); - - print " /* Enabling IRQ $source with priority $prio */\n"; - print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; -} -?> -} - -/** \brief Enable user defined category 2 ISRs */ -void Enable_ISR2_Arch(void) -{ -getList("/OSEK", "ISR"); -foreach ($intnames as $int) -{ - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); - - if($cat == 2) - { - print " /* Enabling IRQ $source */\n"; - print " MSP430_EnableIRQ(" . array_search($source, $intList) . ");\n"; - } -} -?> -} - -/** \brief Disable user defined category 2 ISRs */ -void Disable_ISR2_Arch(void) -{ -getList("/OSEK", "ISR"); -foreach ($intnames as $int) -{ - $source = $config->getValue("/OSEK/" . $int,"INTERRUPT"); - $cat = $config->getValue("/OSEK/" . $int,"CATEGORY"); - - if($cat == 2) - { - print " /* Disabling IRQ $source */\n"; - print " MSP430_DisableIRQ(" . array_search($source, $intList) . ");\n"; - } -} -?> -} - -/** @} doxygen end group definition */ -/** @} doxygen end group definition */ -/** @} doxygen end group definition */ -/*==================[end of file]============================================*/ diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index 26681b9e..38b3dd95 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -54,12 +54,14 @@ /*==================[inclusions]=============================================*/ #include "os.h" #include "Os_Internal_Arch.h" -#ifdef OSEK_INLCUDE_INTERNAL_ARCH_CPU + +#ifdef OSEK_INCLUDE_INTERNAL_ARCH_CPU /** Os_Internal_Arch_Cpu.h is only included if the macro ** OSEK_INCLUDE_INTERNAL_ARCH_CPU is defined on ** Os_Internal_Arch.h **/ #include "Os_Internal_Arch_Cpu.h" -#endif /* #ifdef OSEK_INLCUDE_INTERNAL_ARCH_CPU */ +#endif /* OSEK_INCLUDE_INTERNAL_ARCH_CPU */ + #include "Os_Internal_Arch_Cfg.h" #include "Os_Internal_Cfg.h" #include "ciaaPlatforms.h" diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 36129528..3c30ceb8 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -45,19 +45,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - - /* - * Initials Name - * --------------------------- - * FBUC Franco Bucafusco - * - */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FBUC initial version - */ + /*==================[inclusions]=============================================*/ #include "msp430.h" @@ -90,7 +78,7 @@ ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is needed ** remove the macro and this comment. **/ -#define OSEK_INLCUDE_INTERNAL_ARCH_CPU +#define OSEK_INCLUDE_INTERNAL_ARCH_CPU extern void *Osek_OldTaskPtr_Arch; extern void *Osek_NewTaskPtr_Arch; diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index 83889d0d..d667497a 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -70,27 +70,16 @@ /*==================[cpu macros]=============================================*/ /* TODO: relocate these definitions */ -#define WORKING_FREQUENCY_MHZ 14.7456// 7.3728 // // en MHZ -#define REF_FREQUENCY_HZ 32768 // en Hz -#define TIC_PERIOD 5 // EN ms +#define WORKING_FREQUENCY_MHZ 14.7456// 7.3728 // // in MHZ +#define REF_FREQUENCY_HZ 32768 // in Hz +#define TIC_PERIOD 5 // in ms /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ -/** \brief ISR macro definition - ** - ** This macro shall be used to start the definition of all ISR category 1 or 2. - ** - ** \param[in] name name of the ISR category 1 or 2. - **//* - #ifdef CTESTS_MODIFIERS -#define ISR(name) void OSEK_ISR_ ## name (void) - #else -#define ISR(name) __attribute__( (interrupt_vec(name))) void OSEK_ISR_ ## name (void) -#endif*/ -//#define ISR(name) __attribute__( (interrupt_vec(name))) void OSEK_ISR_ ## name (void) + /*==================[typedef]================================================*/ diff --git a/inc/x86/Os_Internal_Arch.h b/inc/x86/Os_Internal_Arch.h index 6c03adc0..d53eda57 100644 --- a/inc/x86/Os_Internal_Arch.h +++ b/inc/x86/Os_Internal_Arch.h @@ -76,6 +76,16 @@ /** \brief ia64 cputype definition */ #define ia64 2 + +/** \brief Define common objects for using IntSecure_Start and IntSecure_End- + ** + ** This macro will be used internaly by the OS in any part of code that + ** has to be executed atomic. It should be placed before IntSecure_Start or IntSecure_End is called + **/ +#define IntSecure_Common() + + + /** \brief Interrupt Secure Start Macro ** ** This macro shall be used to disable the interrupts From d924726727d9bc3bf7d0d4708c2cf0fa18fc021b Mon Sep 17 00:00:00 2001 From: FRANCO Date: Thu, 7 Jul 2016 02:23:03 -0300 Subject: [PATCH 36/42] - fix trailing spaces - added "All Rights Reserved" where missing. - Remove some empty lines - Added EOF line where missing - Remove History - Corrected identation. - Added missing definitions for some arch. --- gen/ginc/Platform.php | 2 +- gen/ginc/cortexM0/Os_Internal_Defs.php | 2 +- gen/ginc/mips/Os_Internal_Defs.php | 2 +- gen/ginc/x86/Os_Internal_Defs.php | 4 +- gen/inc/Os_Cfg.h.php | 24 +- gen/inc/Os_Internal_Cfg.h.php | 2 +- gen/inc/msp430/Os_Internal_Arch_Cfg.h.php | 19 +- gen/src/Os_Cfg.c.php | 1 + gen/src/Os_Internal_Cfg.c.php | 1 + gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php | 2 +- gen/src/mips/Os_Internal_Arch_Cfg.c.php | 5 - gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 2 +- inc/Os_Internal.h | 14 +- inc/cortexM0/Os_Internal_Arch.h | 10 +- inc/cortexM4/Os_Internal_Arch.h | 4 +- inc/mips/Os_Internal_Arch.h | 2 +- inc/msp430/Os_Arch.h | 25 +- inc/msp430/Os_Internal_Arch.h | 8 +- inc/msp430/StartOs_Arch_SystemTick.h | 1 + .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 26 +- inc/tmparch/Os_Internal_Arch.h | 2 +- inc/x86/Os_Internal_Arch.h | 4 +- src/ActivateTask.c | 6 +- src/ChainTask.c | 2 + src/ClearEvent.c | 2 + src/GetResource.c | 3 +- src/Os_Internal.c | 8 - src/ReleaseResource.c | 3 +- src/Schedule.c | 4 +- src/SetAbsAlarm.c | 2 + src/SetEvent.c | 2 + src/SetRelAlarm.c | 2 + src/StartOS.c | 3 + src/TerminateTask.c | 3 + src/WaitEvent.c | 2 + src/msp430/Os_Arch.c | 16 +- src/msp430/Os_Internal_Arch.c | 1113 ++++++++--------- src/msp430/StartOs_Arch.c | 42 +- src/msp430/StartOs_Arch_SystemTick.c | 83 +- tst/ctest/bin/ctest.pl | 54 +- tst/ctest/inc/ctest.h | 5 +- .../msp430/msp430f5x_6x/msp430f5529/Makefile | 3 +- tst/ctest/src/ctest_em_01.c | 2 +- tst/ctest/src/ctest_ip_01.c | 2 + tst/ctest/src/ctest_ip_03.c | 1 + tst/ctest/src/ctest_ip_04.c | 1 + tst/ctest/src/ctest_rm_01.c | 3 +- tst/ctest/src/ctest_rm_05.c | 4 +- tst/ctest/src/ctest_rst.c | 10 +- tst/ctest/src/ctest_tm_01.c | 4 +- tst/ctest/src/itest_ip_01.c | 3 +- 51 files changed, 743 insertions(+), 807 deletions(-) diff --git a/gen/ginc/Platform.php b/gen/ginc/Platform.php index e16d4506..b6cefac4 100644 --- a/gen/ginc/Platform.php +++ b/gen/ginc/Platform.php @@ -76,7 +76,7 @@ function getIntWidth() } function getInterruptHandlerList() - { + { require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); return $intList; } diff --git a/gen/ginc/cortexM0/Os_Internal_Defs.php b/gen/ginc/cortexM0/Os_Internal_Defs.php index 994a42ed..f307ccaf 100644 --- a/gen/ginc/cortexM0/Os_Internal_Defs.php +++ b/gen/ginc/cortexM0/Os_Internal_Defs.php @@ -5,7 +5,7 @@ /* Copyright 2014, 2015 Mariano Cerdeiro * Copyright 2014, 2015 Pablo Ridolfi - * Copyright 2015, Alejandro Permingeat + * Copyright 2015, Alejandro Permingeat * * This file is part of CIAA Firmware. * diff --git a/gen/ginc/mips/Os_Internal_Defs.php b/gen/ginc/mips/Os_Internal_Defs.php index 363f56fe..987e4756 100644 --- a/gen/ginc/mips/Os_Internal_Defs.php +++ b/gen/ginc/mips/Os_Internal_Defs.php @@ -52,7 +52,7 @@ switch ($this->definitions["CPU"]) { - + default: $this->log->error("the CPU " . $this->definitions["CPU"] . " is not supported."); diff --git a/gen/ginc/x86/Os_Internal_Defs.php b/gen/ginc/x86/Os_Internal_Defs.php index 19f198a7..90332d96 100644 --- a/gen/ginc/x86/Os_Internal_Defs.php +++ b/gen/ginc/x86/Os_Internal_Defs.php @@ -3,7 +3,7 @@ * DO NOT CHANGE THIS FILE, IT IS GENERATED AUTOMATICALY* ********************************************************/ -/* Copyright 2014, 2015 Mariano Cerdeiro +/* Copyright 2014, 2015 Mariano Cerdeiro * * This file is part of CIAA Firmware. * @@ -47,7 +47,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - + ?> diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index a796ce98..556d9413 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -7,6 +7,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016 Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -85,10 +86,10 @@ foreach ($tasks as $task_idx => $task) { print "\n/** \brief Task Definition */\n"; - print "#define $task $task_idx\n"; + print "#define $task $task_idx\n"; } -$count = count( $tasks ); +$count = count( $tasks ); /* Definitions of Tasks : Tasks that will be executed within the remote core*/ if( count($remote_tasks) > 0) @@ -114,7 +115,7 @@ /* the max ammount of events is defined by the bit width of EventMaskType type */ $max_amount_events = $this->helper->platform->getIntWidth(); - + $flags_shared_event = $max_amount_events; /* it stores the number of bit for flags that are shared across tasks */ @@ -128,7 +129,7 @@ /* task/events matrix creation, and various validations */ foreach( $tasks as $task_index => $task ) -{ +{ $empty_array = array(); $temp_array = $this->config->getList("/OSEK/". $task , "EVENT" ); @@ -189,7 +190,7 @@ $count++; } } - + if( $count>1 ) { @@ -217,7 +218,6 @@ $ev_index++; } -//print_r($matriz); print "\n/** \brief Exclusive events for each task */\n\n"; foreach( $tasks as $task_index=> $task ) { @@ -239,19 +239,16 @@ $flags_exc_event++; } - } /* Last validation: check if events repeats */ $task_index = 0; foreach ($matrix_n as $array) { - #print_r($array); $count_values = array_count_values($matrix_n[$task_index]) ; /* it counts the times that repeats an event number, all of them should be 1*/ #print_r($count_values); foreach ($count_values as $key => $value) { - #print_r($value); if($value>1) { throw new Exception("===== OIL ERROR: There are more events that the task can handle. =====\n"); @@ -261,15 +258,6 @@ $task_index ++; } -//$events = $this->config->getList("/OSEK","EVENT"); - -//foreach ($events as $count=>$event) -//{ -// print "/** \brief Definition of the Event $event */\n"; -// print "#define " . $event . " 0x" . sprintf ("%xU", (1<<$count)) . "\n"; -//} -//print "\n"; - /* Define the Resources */ $resources = $this->config->getList("/OSEK","RESOURCE"); diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index 934b07a0..e75cef95 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -7,6 +7,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016 Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -145,7 +146,6 @@ function remove_doubles($a) } } - $os = $this->config->getList("/OSEK","OS"); if (count($os)>1) diff --git a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php index 22715f81..1368722a 100644 --- a/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -38,12 +38,7 @@ #ifndef _OS_INTERNAL_ARCH_CFG_H_ #define _OS_INTERNAL_ARCH_CFG_H_ -/***************************************************************************** - * update the tmparch directory on the \file doxygen comment with your - * architecture - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ + /** \brief FreeOSEK Os Generated Internal Architecture Configuration Header File ** ** This file content the internal generated architecture dependent @@ -60,18 +55,6 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - /* - * Initials Name - * --------------------------- - * FBUC Franco Bucafusco - * - */ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * v0.1.0 20162202 FBUC First version for msp430 processors. - */ /*==================[inclusions]=============================================*/ diff --git a/gen/src/Os_Cfg.c.php b/gen/src/Os_Cfg.c.php index e3577bc4..30dfaeac 100644 --- a/gen/src/Os_Cfg.c.php +++ b/gen/src/Os_Cfg.c.php @@ -62,6 +62,7 @@ config->getList("/OSEK","OS"); $errorhook=$this->config->getValue("/OSEK/" . $os[0],"ERRORHOOK"); + if ($errorhook == "TRUE") { ?> diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 089862d1..93752da6 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -7,6 +7,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016 Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php index 55879c47..3a89961a 100644 --- a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php @@ -4,7 +4,7 @@ /* Copyright 2014, 2015 Mariano Cerdeiro * Copyright 2014, 2015 Pablo Ridolfi - * Copyright 2015, Alejandro Permingeat + * Copyright 2015, Alejandro Permingeat * * All rights reserved. * diff --git a/gen/src/mips/Os_Internal_Arch_Cfg.c.php b/gen/src/mips/Os_Internal_Arch_Cfg.c.php index 484ae3e8..4a60c5b2 100644 --- a/gen/src/mips/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/mips/Os_Internal_Arch_Cfg.c.php @@ -48,11 +48,6 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * v0.1.0 20141223 MaCe initial version to compile for pic32 - */ /*==================[inclusions]=============================================*/ #include "Os_Internal.h" diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 93c6b03c..73ae6b4a 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -47,7 +47,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - + /*==================[inclusions]=============================================*/ #include "Os_Internal.h" diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index 38b3dd95..3a7295bc 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -4,6 +4,8 @@ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco * + * All Rights Reserved + * * This file is part of CIAA Firmware. * * Redistribution and use in source and binary forms, with or without @@ -185,7 +187,7 @@ #elif (ERROR_CHECKING_TYPE == ERROR_CHECKING_STANDARD) /* if standard error checking is used, the scheduler does not perform any check * and cann be called irectly */ -#define Schedule_WOChecks() Schedule() +#define Schedule_WOChecks() Schedule() #endif @@ -195,11 +197,11 @@ ** **/ #if ( NON_PREEMPTIVE == OSEK_DISABLE ) -#define AfterIsr2_Schedule() if( ( CONTEXT_TASK == actualContext ) && \ - ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) \ - { \ - Schedule_WOChecks(); \ - } +#define AfterIsr2_Schedule() if( ( CONTEXT_TASK == actualContext ) && \ + ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) \ + { \ + Schedule_WOChecks(); \ + } #else #define AfterIsr2_Schedule() #endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */ diff --git a/inc/cortexM0/Os_Internal_Arch.h b/inc/cortexM0/Os_Internal_Arch.h index fa92db68..b87946fe 100644 --- a/inc/cortexM0/Os_Internal_Arch.h +++ b/inc/cortexM0/Os_Internal_Arch.h @@ -68,12 +68,20 @@ ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede ** remove the macro and this comment. **/ -#define OSEK_INLCUDE_INTERNAL_ARCH_CPU +#define OSEK_INCLUDE_INTERNAL_ARCH_CPU extern void * Osek_OldTaskPtr_Arch; extern void * Osek_NewTaskPtr_Arch; extern TaskType TerminatingTask; + +/** \brief Define common objects for using IntSecure_Start and IntSecure_End- + ** + ** This macro will be used internaly by the OS in any part of code that + ** has to be executed atomic. It should be placed before IntSecure_Start or IntSecure_End is called + **/ +#define IntSecure_Common() + /** \brief Interrupt Secure Start Macro ** ** This macro will be used internaly by the OS in any part of code that diff --git a/inc/cortexM4/Os_Internal_Arch.h b/inc/cortexM4/Os_Internal_Arch.h index aa9deb14..8d77a08c 100644 --- a/inc/cortexM4/Os_Internal_Arch.h +++ b/inc/cortexM4/Os_Internal_Arch.h @@ -68,7 +68,7 @@ ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede ** remove the macro and this comment. **/ -#define OSEK_INLCUDE_INTERNAL_ARCH_CPU +#define OSEK_INCLUDE_INTERNAL_ARCH_CPU extern void * Osek_OldTaskPtr_Arch; extern void * Osek_NewTaskPtr_Arch; @@ -80,7 +80,7 @@ extern TaskType TerminatingTask; ** This macro will be used internaly by the OS in any part of code that ** has to be executed atomic. It should be placed before IntSecure_Start or IntSecure_End is called **/ -#define IntSecure_Common() +#define IntSecure_Common() /** \brief Interrupt Secure Start Macro ** diff --git a/inc/mips/Os_Internal_Arch.h b/inc/mips/Os_Internal_Arch.h index 91a5591d..8f76489a 100644 --- a/inc/mips/Os_Internal_Arch.h +++ b/inc/mips/Os_Internal_Arch.h @@ -57,7 +57,7 @@ ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede ** remove the macro and this comment. **/ -#define OSEK_INLCUDE_INTERNAL_ARCH_CPU +#define OSEK_INCLUDE_INTERNAL_ARCH_CPU /** \brief Interrupt Secure Start Macro ** diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index 411e5957..cd22a693 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -1,4 +1,6 @@ /* Copyright 2016, Franco Bucafusco + * + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -50,32 +52,11 @@ /** \addtogroup FreeOSEK_Os_Global ** @{ */ - /* - * Initials Name - * --------------------------- - * FBUC Franco Bucafusco - * - */ - - -/* - * modification history (new versions first) - * ---------------------------------------------------------- - * 20160222 v0.1.0 FBUC initial version - */ - /*==================[inclusions]=============================================*/ #include "Os_Internal_Arch_Cfg.h" /*==================[macros]=================================================*/ -/***************************************************************************** - * Please define here all needed macros that will be visiblsee to the OS user - * for this architecutre. This means that anyone including os.h will have - * access to this definitions if the actual architecutre is used. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ /** \brief Enable All Interrupts Arch */ #define EnableAllInterrupts_Arch() ResumeAllInterrupts_Arch() @@ -98,7 +79,7 @@ ** Also noted in Slau208, page 59. **/ #define SuspendAllInterrupts_Arch() _disable_interrupts() ; __asm__ __volatile__ ("nop"); - + /** \brief Resume OS Interrupts Arch ** ** This macro shall resume (enable) all interrupts configured on the diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 3c30ceb8..1d742792 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -1,4 +1,6 @@ /* Copyright 2016, Franco Bucafusco + * + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -45,7 +47,7 @@ ** @{ */ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - + /*==================[inclusions]=============================================*/ #include "msp430.h" @@ -173,7 +175,7 @@ extern TaskType TerminatingTask; ** ** This function jmps to the indicated task. **/ -#define CallTask(actualtask, nexttask) \ +#define CallTask(actualtask, nexttask) \ { \ Osek_OldTaskPtr_Arch = (void*) (TasksConst[(actualtask)].TaskContext); \ Osek_NewTaskPtr_Arch = (void*) (TasksConst[(nexttask)].TaskContext); \ @@ -185,7 +187,7 @@ extern TaskType TerminatingTask; ** ** This function jmps to the indicated task. **/ -#define JmpTask(task) \ +#define JmpTask(task) \ { \ extern TaskType WaitingTask; \ if(WaitingTask != INVALID_TASK) \ diff --git a/inc/msp430/StartOs_Arch_SystemTick.h b/inc/msp430/StartOs_Arch_SystemTick.h index 05e53470..2d42b50a 100644 --- a/inc/msp430/StartOs_Arch_SystemTick.h +++ b/inc/msp430/StartOs_Arch_SystemTick.h @@ -1,4 +1,5 @@ /* Copyright 2016, Franco Bucafusco + * * All rights reserved. * * This file is part of CIAA Firmware. diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index d667497a..f0ef2744 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -1,4 +1,6 @@ /* Copyright 2016, Franco Bucafusco + * + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -46,31 +48,11 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ -/***************************************************************************** - * add your name to the developers and create for you a nick with - * 3 or 4 letters. Please do not use any given nick. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ - -/***************************************************************************** - * add a new version to this file, add the date, your initials and the main - * changes, only main changes shall be listed here. A detailed message log - * is saved in svn log and on the tracker system since every svn login message - * shalle indicate the related tracker id. - * - * PLEASE REMOVE THIS COMMENT - *****************************************************************************/ -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20140608 v0.1.1 PR First version for LPC4337 microcontroller. - */ + /*==================[cpu macros]=============================================*/ -/* TODO: relocate these definitions */ -#define WORKING_FREQUENCY_MHZ 14.7456// 7.3728 // // in MHZ +#define WORKING_FREQUENCY_MHZ 14.7456f// 7.3728 // // in MHZ #define REF_FREQUENCY_HZ 32768 // in Hz #define TIC_PERIOD 5 // in ms diff --git a/inc/tmparch/Os_Internal_Arch.h b/inc/tmparch/Os_Internal_Arch.h index e4e4539c..cb4a4dc7 100644 --- a/inc/tmparch/Os_Internal_Arch.h +++ b/inc/tmparch/Os_Internal_Arch.h @@ -101,7 +101,7 @@ ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede ** remove the macro and this comment. **/ -#define OSEK_INLCUDE_INTERNAL_ARCH_CPU +#define OSEK_INCLUDE_INTERNAL_ARCH_CPU #error update the following macro and remove this comment /** \brief Interrupt Secure Start Macro diff --git a/inc/x86/Os_Internal_Arch.h b/inc/x86/Os_Internal_Arch.h index d53eda57..e902d331 100644 --- a/inc/x86/Os_Internal_Arch.h +++ b/inc/x86/Os_Internal_Arch.h @@ -82,7 +82,7 @@ ** This macro will be used internaly by the OS in any part of code that ** has to be executed atomic. It should be placed before IntSecure_Start or IntSecure_End is called **/ -#define IntSecure_Common() +#define IntSecure_Common() @@ -262,7 +262,7 @@ ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) +#define PostIsr2_Arch(isr) #if ( CPUTYPE == ia64 ) #define SaveOsStack() \ diff --git a/src/ActivateTask.c b/src/ActivateTask.c index 932b85d1..95f3e3db 100644 --- a/src/ActivateTask.c +++ b/src/ActivateTask.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -113,7 +115,7 @@ StatusType ActivateTask else #endif { - IntSecure_Start(); + IntSecure_Start(); /* check if the task is susspended */ /* \req OSEK_SYS_3.1.1-1/2 The task TaskID shall be transferred from the @@ -169,7 +171,7 @@ StatusType ActivateTask } } - IntSecure_End(); + IntSecure_End(); #if (NON_PREEMPTIVE == OSEK_DISABLE) /* check if called from a Task Context */ diff --git a/src/ChainTask.c b/src/ChainTask.c index 1524dee7..a46266b2 100644 --- a/src/ChainTask.c +++ b/src/ChainTask.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/ClearEvent.c b/src/ClearEvent.c index 925f4604..d215175a 100644 --- a/src/ClearEvent.c +++ b/src/ClearEvent.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/GetResource.c b/src/GetResource.c index 9a4d7906..7eac3100 100644 --- a/src/GetResource.c +++ b/src/GetResource.c @@ -2,7 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar - * All rights reserved. + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/Os_Internal.c b/src/Os_Internal.c index 20867a7f..2bc086d2 100644 --- a/src/Os_Internal.c +++ b/src/Os_Internal.c @@ -64,9 +64,6 @@ ContextType ActualContext; /*==================[internal functions definition]==========================*/ /*==================[external functions definition]==========================*/ - -/** AddReady -*/ void AddReady(TaskType TaskID) { TaskPriorityType priority; @@ -108,8 +105,6 @@ void AddReady(TaskType TaskID) ReadyVar[priority].ListCount++; } -/** RemoveTask -*/ void RemoveTask ( TaskType TaskID @@ -120,7 +115,6 @@ void RemoveTask /* get task priority */ priority = TasksConst[TaskID].StaticPriority; - /* convert the priority to the array index */ /* do not remove the -1 is needed. for example if READYLIST_COUNT is 4 * the valid entries for this array are between 0 and 3, so the -1 is needed @@ -145,8 +139,6 @@ void RemoveTask ReadyVar[priority].ListCount--; } -/** GetNextTask -*/ TaskType GetNextTask ( void diff --git a/src/ReleaseResource.c b/src/ReleaseResource.c index 25effb20..fe184e15 100644 --- a/src/ReleaseResource.c +++ b/src/ReleaseResource.c @@ -2,7 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar - * All rights reserved. + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/Schedule.c b/src/Schedule.c index b2e5dea4..4ab4f000 100644 --- a/src/Schedule.c +++ b/src/Schedule.c @@ -1,8 +1,10 @@ /* Copyright 2008, 2009, 2014, 2015 Mariano Cerdeiro * Copyright 2014, ACSE & CADIEEL - * Copyright 2016, Franco Bucafusco * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/SetAbsAlarm.c b/src/SetAbsAlarm.c index 4b45cd04..005d1b26 100644 --- a/src/SetAbsAlarm.c +++ b/src/SetAbsAlarm.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/SetEvent.c b/src/SetEvent.c index dec86e41..a0b969b9 100644 --- a/src/SetEvent.c +++ b/src/SetEvent.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/SetRelAlarm.c b/src/SetRelAlarm.c index 0bcb2c1b..c67c3144 100644 --- a/src/SetRelAlarm.c +++ b/src/SetRelAlarm.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/StartOS.c b/src/StartOS.c index f6f3079f..f46c20c3 100644 --- a/src/StartOS.c +++ b/src/StartOS.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -147,3 +149,4 @@ void StartOS /** @} doxygen end group definition */ /** @} doxygen endVar group definition */ /*==================[end of file]============================================*/ + diff --git a/src/TerminateTask.c b/src/TerminateTask.c index 45ae79e8..aa837868 100644 --- a/src/TerminateTask.c +++ b/src/TerminateTask.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -181,3 +183,4 @@ StatusType TerminateTask /** @} doxygen endVar group definition */ /** @} doxygen endVar group definition */ /*==================[end of file]============================================*/ + diff --git a/src/WaitEvent.c b/src/WaitEvent.c index 0e7fe0ec..6b9c3ccc 100644 --- a/src/WaitEvent.c +++ b/src/WaitEvent.c @@ -2,6 +2,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/src/msp430/Os_Arch.c b/src/msp430/Os_Arch.c index c0b9af2f..3609c190 100644 --- a/src/msp430/Os_Arch.c +++ b/src/msp430/Os_Arch.c @@ -1,4 +1,5 @@ /* Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -44,19 +45,6 @@ ** @{ */ -/* -* Initials Name -* --------------------------- -* FBUC Franco Bucafusco -* -*/ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FBUC initial version - */ - /*==================[inclusions]=============================================*/ #include "Os_Internal.h" @@ -74,8 +62,6 @@ /*==================[external functions definition]==========================*/ - - /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 2b891995..321b0217 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -44,19 +44,6 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ -/* -* Initials Name -* --------------------------- -* FBUC Franco Bucafusco -* -*/ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FBUC initial version for msp430 processors - */ - /*==================[inclusions]=============================================*/ #include "Os_Internal.h" @@ -70,8 +57,8 @@ void * Osek_OldTaskPtr_Arch; /*==================[internal data definition]===============================*/ -TaskType TerminatingTask = INVALID_TASK; -TaskType WaitingTask = INVALID_TASK; +TaskType TerminatingTask = INVALID_TASK; +TaskType WaitingTask = INVALID_TASK; /*==================[external data definition]===============================*/ @@ -81,93 +68,99 @@ TaskType WaitingTask = INVALID_TASK; void ReturnHook_Arch(void) { - /* Tasks shouldn't return here... */ - while(1) - { - osekpause(); - } + /* Tasks shouldn't return here... */ + while(1) + { + osekpause(); + } } void CheckTerminatingTask_Arch(void) { - if( TerminatingTask != INVALID_TASK ) - { - InitStack_Arch( TerminatingTask ); - } - TerminatingTask = INVALID_TASK; + if( INVALID_TASK != TerminatingTask ) + { + InitStack_Arch( TerminatingTask ); + } + TerminatingTask = INVALID_TASK; } /* Task Stack Initialization */ void InitStack_Arch(uint8 TaskID) { - uint16 * taskStack = (uint16 *)TasksConst[TaskID].StackPtr; /* stack bottom */ + uint16 * taskStack = (uint16 *)TasksConst[TaskID].StackPtr; /* stack bottom */ - int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ + int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ - taskStack[taskStackSizeWords-1] = (uint16) TasksConst[TaskID].EntryPoint; /*PC*/ - taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ + taskStack[taskStackSizeWords-1] = (uint16) TasksConst[TaskID].EntryPoint; /*PC*/ + taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ - /* la ubicacion, reservando 13 registro para el cambio de contexto - */ - *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 14]); + /* la ubicacion, reservando 13 registro para el cambio de contexto + */ + *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 14]); } void TickProcess() { - /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ - Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_0); + /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ + Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_0); - /* store the calling context in a variable */ - ContextType actualContext = GetCallingContext(); + /* store the calling context in a variable */ + ContextType actualContext = GetCallingContext(); - /* set isr 2 context */ - SetActualContext(CONTEXT_ISR2); + /* set isr 2 context */ + SetActualContext(CONTEXT_ISR2); #if (ALARMS_COUNT != 0) - /* counter increment */ - static CounterIncrementType CounterIncrement = 1; - (void)CounterIncrement; /* TODO remove me */ + /* counter increment */ + static CounterIncrementType CounterIncrement = 1; + (void)CounterIncrement; /* TODO remove me */ - /* increment the disable interrupt conter to avoid enable the interrupts */ - // IntSecure_Start(); //MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS +#if 0 + /* increment the disable interrupt conter to avoid enable the interrupts. + Disabled because MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS */ + IntSecure_Start(); +#endif + + /* call counter interrupt handler */ + CounterIncrement = IncrementCounter(0, TIC_PERIOD ); - /* call counter interrupt handler */ - CounterIncrement = IncrementCounter(0, TIC_PERIOD ); +#if 0 + /* set the disable interrupt counter back. + Disabled because MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS */ + IntSecure_End(); +#endif - /* set the disable interrupt counter back */ - // IntSecure_End(); //MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS #endif /* #if (ALARMS_COUNT != 0) */ - /* reset context */ - SetActualContext(actualContext); + /* reset context */ + SetActualContext(actualContext); - AfterIsr2_Schedule(); + AfterIsr2_Schedule(); } /** - OSEK periodic interrupt is implemented using TimerA_2 timer module. +OSEK periodic interrupt is implemented using TimerA_2 timer module. */ -//__attribute__( (interrupt_vec(TIMER2_A0_VECTOR) ,naked )) // interrupt_vec(TIMER2_A0_VECTOR) __attribute__((naked)) void OSEK_ISR_TIMER2_A0_VECTOR(void) { - /* - It's not necessary to disable global irqs. - It is done automatically when the SP is cleared. - */ - /* This handler service the periodic interrupt. - */ - /* Clear the IRQ flag*/ - TickProcess(); - - /* - This handler calls TickProcess because it is defined as naked, and therefore the compiler do not save regiters. - The same happens with the RETI instruction that is inserted in the last macro. - Calling the function, the compiler saves the neede registers. - */ - - RETURN_FROM_NAKED_ISR(); /*return from Tick ISR */ + /* + It's not necessary to disable global irqs. + It is done automatically when the SP is cleared. + */ + /* This handler service the periodic interrupt. + */ + /* Clear the IRQ flag*/ + TickProcess(); + + /* + This handler calls TickProcess because it is defined as naked, and therefore the compiler do not save regiters. + The same happens with the RETI instruction that is inserted in the last macro. + Calling the function, the compiler saves the neede registers. + */ + + RETURN_FROM_NAKED_ISR(); /*return from Tick ISR */ } /** OSEK_ISR_TIMER2_A1_VECTOR @@ -180,43 +173,43 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) interrupt_vec(TIMER2_A1_VECTOR) __attribute__((naked)) void OSEK_ISR_TIMER2_A1_VECTOR(void) { - register unsigned short local_taiv = TA2IV; - - if( local_taiv & TA2IV_TACCR1) // - { - /* Clear the IRQ flag*/ - /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ - Timer_A_disableCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1 ); - Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1); - - /* reinicio el stack de la tarea que termino */ - CheckTerminatingTask_Arch(); - - /* Context save r4 to r15 - r0 = PC automatically saved by HW when handler is serviced - r1 = SP - r2 = SR automatically saved by HW when handler is serviced - r3 = CG doesn't care - */ - SAVE_CONTEXT(); - - /* exchange stack pointers */ - if( Osek_OldTaskPtr_Arch != NULL ) - { - asm volatile ( "mov &Osek_OldTaskPtr_Arch, r6 \n\t" ); - asm volatile ( "mov SP, @r6 \n\t" ); - } - asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); - asm volatile ( "mov @r6, SP \n\t" ); - - /* - Context restore r4 to r15 - It does not Include the reti instruction. - */ - RESTORE_CONTEXT() - } - - RETURN_FROM_NAKED_ISR(); /*return from ISR*/ + register unsigned short local_taiv = TA2IV; + + if( local_taiv & TA2IV_TACCR1) // + { + /* Clear the IRQ flag*/ + /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ + Timer_A_disableCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1 ); + Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1); + + /* reinicio el stack de la tarea que termino */ + CheckTerminatingTask_Arch(); + + /* Context save r4 to r15 + r0 = PC automatically saved by HW when handler is serviced + r1 = SP + r2 = SR automatically saved by HW when handler is serviced + r3 = CG doesn't care + */ + SAVE_CONTEXT(); + + /* exchange stack pointers */ + if( NULL != Osek_OldTaskPtr_Arch ) + { + asm volatile ( "mov &Osek_OldTaskPtr_Arch, r6 \n\t" ); + asm volatile ( "mov SP, @r6 \n\t" ); + } + asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); + asm volatile ( "mov @r6, SP \n\t" ); + + /* + Context restore r4 to r15 + It does not Include the reti instruction. + */ + RESTORE_CONTEXT() + } + + RETURN_FROM_NAKED_ISR(); /*return from ISR*/ } @@ -227,90 +220,90 @@ So, when dissable the IRQ handler the system must backup the current available I all the possible regiters, to be restored later in the EnableIRQ. */ #if( MSP430_ENABLE_RTC_HANDLER== 1) -unsigned char rtcctl0_bck = 0; -unsigned char rtcps0ctl_bck = 0; //the RTCPS0CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char rtcps1ctl_bck = 0; //the RTCPS1CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char rtcctl0_bck = 0; +unsigned char rtcps0ctl_bck = 0; //the RTCPS0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char rtcps1ctl_bck = 0; //the RTCPS1CTL is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_PORT2_HANDLER== 1) -unsigned char p2ie_bck = 0; +unsigned char p2ie_bck = 0; #endif #if( MSP430_ENABLE_PORT1_HANDLER==1 ) -unsigned char p1ie_bck = 0; +unsigned char p1ie_bck = 0; #endif #if( MSP430_ENABLE_TIMER2_A1_HANDLER== 1) -unsigned char ta2ctl_bck = 0; //the TA2CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta2cctl1_bck = 0; //the TA2CCTL1 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta2cctl2_bck = 0; //the TA2CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta2ctl_bck = 0; //the TA2CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta2cctl1_bck = 0; //the TA2CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta2cctl2_bck = 0; //the TA2CCTL2 is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) -unsigned char ta2cctl0_bck = 0; +unsigned char ta2cctl0_bck = 0; #endif #if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) -unsigned char ta1ctl_bck = 0; //the TA1CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta1cctl0_bck = 0; //the TA1CCTL0 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta1cctl1_bck = 0; //the TA1CCTL1 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta1cctl2_bck = 0; //the TA1CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1ctl_bck = 0; //the TA1CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1cctl0_bck = 0; //the TA1CCTL0 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1cctl1_bck = 0; //the TA1CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta1cctl2_bck = 0; //the TA1CCTL2 is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) -unsigned char ta0ctl_bck = 0; //the TA0CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta0cctl1_bck = 0; //the TA0CCTL1 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta0cctl2_bck = 0; //the TA0CCTL2 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta0cctl3_bck = 0; //the TA0CCTL3 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char ta0cctl4_bck = 0; //the TA0CCTL4 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0ctl_bck = 0; //the TA0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl1_bck = 0; //the TA0CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl2_bck = 0; //the TA0CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl3_bck = 0; //the TA0CCTL3 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl4_bck = 0; //the TA0CCTL4 is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) -unsigned char ta0cctl0_bck = 0; //the TA0CCTL0 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char ta0cctl0_bck = 0; //the TA0CCTL0 is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) -unsigned char tb0ctl_bck = 0; //the TB0CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char tb0cctl1_bck = 0; //the TB0CCTL1 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char tb0cctl2_bck = 0; //the TB0CCTL2 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char tb0cctl3_bck = 0; //the TB0CCTL3 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char tb0cctl4_bck = 0; //the TB0CCTL4 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char tb0cctl5_bck = 0; //the TB0CCTL5 is 16bit wide, but the IRQ flags are in the lower byte -unsigned char tb0cctl6_bck = 0; //the TB0CCTL6 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0ctl_bck = 0; //the TB0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl1_bck = 0; //the TB0CCTL1 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl2_bck = 0; //the TB0CCTL2 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl3_bck = 0; //the TB0CCTL3 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl4_bck = 0; //the TB0CCTL4 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl5_bck = 0; //the TB0CCTL5 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl6_bck = 0; //the TB0CCTL6 is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) -unsigned char tb0cctl0_bck = 0; //the TB0CCTL0 is 16bit wide, but the IRQ flags are in the lower byte +unsigned char tb0cctl0_bck = 0; //the TB0CCTL0 is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_DMA_HANDLER==1 ) -unsigned char dma0ctl_bck = 0; //the DMA0CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char dma1ctl_bck = 0; //the DMA1CTL is 16bit wide, but the IRQ flags are in the lower byte -unsigned char dma2ctl_bck = 0; //the DMA2CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char dma0ctl_bck = 0; //the DMA0CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char dma1ctl_bck = 0; //the DMA1CTL is 16bit wide, but the IRQ flags are in the lower byte +unsigned char dma2ctl_bck = 0; //the DMA2CTL is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) unsigned char uca1ctl1_bck = 0; -unsigned char uca1ie_bck = 0; +unsigned char uca1ie_bck = 0; #endif #if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) unsigned char uca0ctl1_bck = 0; -unsigned char uca0ie_bck = 0; +unsigned char uca0ie_bck = 0; #endif #if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) -unsigned char ucb0ie_bck = 0; +unsigned char ucb0ie_bck = 0; #endif #if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) -unsigned char ucb1ie_bck = 0; +unsigned char ucb1ie_bck = 0; #endif #if( MSP430_ENABLE_ADC12_HANDLER==1 ) -unsigned char adc12ctl0_bck = 0; //the ADC12CTL0 is 16bit wide, but the IRQ flags are in the lower byte -unsigned short adc12ie_bck = 0; +unsigned char adc12ctl0_bck = 0; //the ADC12CTL0 is 16bit wide, but the IRQ flags are in the lower byte +unsigned short adc12ie_bck = 0; #endif //TODO: OPTIMIZAR SOLO AGREGANDO LOS CASES BASADOS EN LOS ISR QUE DEFINA EL USUARIO EN EL OIL @@ -321,222 +314,220 @@ SEE SLAS590 (TABLE 4) */ void MSP430_EnableIRQ(unsigned char irQ_number) { - switch( irQ_number ) - { + switch( irQ_number ) + { #if( MSP430_ENABLE_RTC_HANDLER== 1) - case 0: // => "RTC", - /* RTCRDYIE, RTCTEVIE, RTCAIE, RT0PSIE, RT1PSIE */ - /**/ - RTCCTL0 |= ( rtcctl0_bck & (RTCTEVIE|RTCAIE|RTCRDYIE) ); - RTCPS0CTL |= ( rtcps0ctl_bck & RT0PSIE ); - RTCPS1CTL |= ( rtcps1ctl_bck & RT1PSIE ); - break; + case 0: // => "RTC", + /* RTCRDYIE, RTCTEVIE, RTCAIE, RT0PSIE, RT1PSIE */ + /**/ + RTCCTL0 |= ( rtcctl0_bck & (RTCTEVIE|RTCAIE|RTCRDYIE) ); + RTCPS0CTL |= ( rtcps0ctl_bck & RT0PSIE ); + RTCPS1CTL |= ( rtcps1ctl_bck & RT1PSIE ); + break; #endif #if( MSP430_ENABLE_PORT2_HANDLER==1) - case 1 : //=> "PORT2", - /* P2IE.0 to P2IE.7*/ - P2IE |= p2ie_bck; - break; + case 1 : //=> "PORT2", + /* P2IE.0 to P2IE.7*/ + P2IE |= p2ie_bck; + break; #endif #if( MSP430_ENABLE_TIMER2_A1_HANDLER==1) - case 2 : //=> "TIMER2_A1", - /* TA2CCR1 CCIE1 to TA2CCR2 CCIE2, TA2IE*/ - TA2CTL |= ( ta2ctl_bck & TAIE ); - TA2CCTL1 |= ( ta2cctl1_bck & CCIE ); - TA2CCTL2 |= ( ta2cctl2_bck & CCIE ); - break; + case 2 : //=> "TIMER2_A1", + /* TA2CCR1 CCIE1 to TA2CCR2 CCIE2, TA2IE*/ + TA2CTL |= ( ta2ctl_bck & TAIE ); + TA2CCTL1 |= ( ta2cctl1_bck & CCIE ); + TA2CCTL2 |= ( ta2cctl2_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) - case 3 : //=> "TIMER2_A0", - /* TA2CCR0 CCIE0 */ - TA2CCTL0 |= ( ta2cctl0_bck & CCIE ); - break; + case 3 : //=> "TIMER2_A0", + /* TA2CCR0 CCIE0 */ + TA2CCTL0 |= ( ta2cctl0_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) - case 4 : //=> "USCI_B1", - /* UCB1RXIE, UCB1TXIE */ - UCB1IE |= ( ucb1ie_bck & (UCRXIE|UCTXIE) ); - break; + case 4 : //=> "USCI_B1", + /* UCB1RXIE, UCB1TXIE */ + UCB1IE |= ( ucb1ie_bck & (UCRXIE|UCTXIE) ); + break; #endif #if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) - case 5 : //=> "USCI_A1", - /* UCA1RXIE, UCA1TXIE */ - UCA1IE |= ( uca1ie_bck & (UCRXIE|UCTXIE) ); - UCA1CTL1 |= ( uca1ctl1_bck & (UCRXEIE|UCBRKIE) ); - break; + case 5 : //=> "USCI_A1", + /* UCA1RXIE, UCA1TXIE */ + UCA1IE |= ( uca1ie_bck & (UCRXIE|UCTXIE) ); + UCA1CTL1 |= ( uca1ctl1_bck & (UCRXEIE|UCBRKIE) ); + break; #endif #if( MSP430_ENABLE_PORT1_HANDLER==1 ) - case 6 : //=> "PORT1", - /* P1IE.0 to P1IE.7 */ - P1IE |= p1ie_bck; - break; + case 6 : //=> "PORT1", + /* P1IE.0 to P1IE.7 */ + P1IE |= p1ie_bck; + break; #endif #if( MSP430_ENABLE_TIMER1_A1_HANDLER==1 ) - case 7 : //=> "TIMER1_A1", - /* TA1CCR1 CCIE1 to TA1CCR2 CCIE2 TA1IE*/ - TA1CTL |= ( ta1ctl_bck & TAIE ); - TA1CCTL1 |= ( ta1cctl1_bck & CCIE ); - TA1CCTL2 |= ( ta1cctl2_bck & CCIE ); - break; + case 7 : //=> "TIMER1_A1", + /* TA1CCR1 CCIE1 to TA1CCR2 CCIE2 TA1IE*/ + TA1CTL |= ( ta1ctl_bck & TAIE ); + TA1CCTL1 |= ( ta1cctl1_bck & CCIE ); + TA1CCTL2 |= ( ta1cctl2_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) - case 8 : //=> "TIMER1_A0", - /* TA1CCR0 CCIE0 */ - TA1CCTL0 |= ( ta1cctl0_bck & CCIE ); - break; + case 8 : //=> "TIMER1_A0", + /* TA1CCR0 CCIE0 */ + TA1CCTL0 |= ( ta1cctl0_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_DMA_HANDLER==1 ) - case 9 : //=> "DMA", - /* DMA0IE, DMA1IE, DMA2IE */ - DMA0CTL |= ( dma0ctl_bck & DMAIE ); - DMA1CTL |= ( dma1ctl_bck & DMAIE ); - DMA2CTL |= ( dma2ctl_bck & DMAIE ); - break; + case 9 : //=> "DMA", + /* DMA0IE, DMA1IE, DMA2IE */ + DMA0CTL |= ( dma0ctl_bck & DMAIE ); + DMA1CTL |= ( dma1ctl_bck & DMAIE ); + DMA2CTL |= ( dma2ctl_bck & DMAIE ); + break; #endif #if( MSP430_ENABLE_USB_UBM_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 10: // => "USB_UBM", - /* USB interrupts */ - USBPWRCTL |= VBOFFIE|VBONIE|VUOVLIE; - USBPLLIR |= USBOORIE|USBLOSIE|USBOOLIE; - USBIEPCNF_0 |=USBIIE; - USBOEPCNF_0 |=USBIIE; - USBIEPIE = 0XFF; - USBOEPIE = 0XFF; - USBMAINT |=UTIE; - USBIE |= RSTRIE|SUSRIE|RESRIE|SETUPIE|STPOWIE; - - USBIEPCNF_0 |= USBIIE; - USBOEPCNF_0 |= USBIIE; - - USBIEPCNF_1 |= USBIIE; - USBOEPCNF_1 |= USBIIE; - USBIEPCNF_2 |= USBIIE; - USBOEPCNF_2 |= USBIIE; - USBIEPCNF_3 |= USBIIE; - USBOEPCNF_3 |= USBIIE; - USBIEPCNF_4 |= USBIIE; - USBOEPCNF_4 |= USBIIE; - USBIEPCNF_5 |= USBIIE; - USBOEPCNF_5 |= USBIIE; - USBIEPCNF_6 |= USBIIE; - USBOEPCNF_6 |= USBIIE; - USBIEPCNF_7 |= USBIIE; - USBOEPCNF_7 |= USBIIE; - break; + case 10: // => "USB_UBM", + /* USB interrupts */ + USBPWRCTL |= VBOFFIE|VBONIE|VUOVLIE; + USBPLLIR |= USBOORIE|USBLOSIE|USBOOLIE; + USBIEPCNF_0 |=USBIIE; + USBOEPCNF_0 |=USBIIE; + USBIEPIE = 0XFF; + USBOEPIE = 0XFF; + USBMAINT |=UTIE; + USBIE |= RSTRIE|SUSRIE|RESRIE|SETUPIE|STPOWIE; + + USBIEPCNF_0 |= USBIIE; + USBOEPCNF_0 |= USBIIE; + + USBIEPCNF_1 |= USBIIE; + USBOEPCNF_1 |= USBIIE; + USBIEPCNF_2 |= USBIIE; + USBOEPCNF_2 |= USBIIE; + USBIEPCNF_3 |= USBIIE; + USBOEPCNF_3 |= USBIIE; + USBIEPCNF_4 |= USBIIE; + USBOEPCNF_4 |= USBIIE; + USBIEPCNF_5 |= USBIIE; + USBOEPCNF_5 |= USBIIE; + USBIEPCNF_6 |= USBIIE; + USBOEPCNF_6 |= USBIIE; + USBIEPCNF_7 |= USBIIE; + USBOEPCNF_7 |= USBIIE; + break; #endif #if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) - case 11: // => "TIMER0_A1", - /* TA0CCR1 CCIE1 to TA0CCR4 CCIE4 TA0IE */ - TA0CTL |= ( ta0ctl_bck & TAIE ); - TA0CCTL1 |= ( ta0cctl1_bck & CCIE ); - TA0CCTL2 |= ( ta0cctl2_bck & CCIE ); - TA0CCTL3 |= ( ta0cctl3_bck & CCIE ); - TA0CCTL4 |= ( ta0cctl4_bck & CCIE ); - break; + case 11: // => "TIMER0_A1", + /* TA0CCR1 CCIE1 to TA0CCR4 CCIE4 TA0IE */ + TA0CTL |= ( ta0ctl_bck & TAIE ); + TA0CCTL1 |= ( ta0cctl1_bck & CCIE ); + TA0CCTL2 |= ( ta0cctl2_bck & CCIE ); + TA0CCTL3 |= ( ta0cctl3_bck & CCIE ); + TA0CCTL4 |= ( ta0cctl4_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) - case 12: // => "TIMER0_A0", - /* TA0CCR0 CCIE0 */ - TA0CCTL0 |= ( ta0cctl0_bck & CCIE ); - break; + case 12: // => "TIMER0_A0", + /* TA0CCR0 CCIE0 */ + TA0CCTL0 |= ( ta0cctl0_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_ADC12_HANDLER==1 ) - case 13: // => "ADC12", - /* ADC12IE0 to ADC12IE15 */ - ADC12CTL0 |= ( adc12ctl0_bck & (ADC12OVIE|ADC12TOVIE) ); - ADC12IE = adc12ie_bck; - break; + case 13: // => "ADC12", + /* ADC12IE0 to ADC12IE15 */ + ADC12CTL0 |= ( adc12ctl0_bck & (ADC12OVIE|ADC12TOVIE) ); + ADC12IE = adc12ie_bck; + break; #endif #if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) - case 14: // => "USCI_B0", - /* UCB0RXIE, UCB0TXIE */ - UCB0IE |= ( ucb0ie_bck & (UCRXIE|UCTXIE) ); - break; + case 14: // => "USCI_B0", + /* UCB0RXIE, UCB0TXIE */ + UCB0IE |= ( ucb0ie_bck & (UCRXIE|UCTXIE) ); + break; #endif #if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) - case 15: // => "USCI_A0", - /* UCA0RXIE, UCA0TXIE */ - UCA0IE |= ( uca0ie_bck & (UCRXIE|UCTXIE) ); - UCA0CTL1 |= ( uca0ctl1_bck & (UCRXEIE|UCBRKIE) ); - break; + case 15: // => "USCI_A0", + /* UCA0RXIE, UCA0TXIE */ + UCA0IE |= ( uca0ie_bck & (UCRXIE|UCTXIE) ); + UCA0CTL1 |= ( uca0ctl1_bck & (UCRXEIE|UCBRKIE) ); + break; #endif #if( MSP430_ENABLE_WDT_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 16: // => "WDT", - /* WDTIE */ - break; + case 16: // => "WDT", + /* WDTIE */ + break; #endif #if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) - case 17: // => "TIMER0_B1", - /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ - TB0CTL |= ( tb0ctl_bck & TAIE ); - TB0CCTL1 |= ( tb0cctl1_bck & CCIE ); - TB0CCTL2 |= ( tb0cctl2_bck & CCIE ); - TB0CCTL3 |= ( tb0cctl3_bck & CCIE ); - TB0CCTL4 |= ( tb0cctl4_bck & CCIE ); - TB0CCTL5 |= ( tb0cctl5_bck & CCIE ); - TB0CCTL6 |= ( tb0cctl6_bck & CCIE ); - break; + case 17: // => "TIMER0_B1", + /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ + TB0CTL |= ( tb0ctl_bck & TAIE ); + TB0CCTL1 |= ( tb0cctl1_bck & CCIE ); + TB0CCTL2 |= ( tb0cctl2_bck & CCIE ); + TB0CCTL3 |= ( tb0cctl3_bck & CCIE ); + TB0CCTL4 |= ( tb0cctl4_bck & CCIE ); + TB0CCTL5 |= ( tb0cctl5_bck & CCIE ); + TB0CCTL6 |= ( tb0cctl6_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) - case 18: // => "TIMER0_B0", - /* TB0CCR0 CCIE0 */ - TB0CCTL0 |= ( tb0cctl0_bck & CCIE ); - break; + case 18: // => "TIMER0_B0", + /* TB0CCR0 CCIE0 */ + TB0CCTL0 |= ( tb0cctl0_bck & CCIE ); + break; #endif #if( MSP430_ENABLE_COMP_B_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 19: // => "COMP_B", - /* Comparator B interrupt flags */ - break; + case 19: // => "COMP_B", + /* Comparator B interrupt flags */ + break; #endif #if( MSP430_ENABLE_UNMI_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 20: // => "UNMI", - break; + case 20: // => "UNMI", + break; #endif #if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) #error SHOULD NOT BE IMPLEMENTED - case 21: // => "SYSNMI", - /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ - break; + case 21: // => "SYSNMI", + /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ + break; #endif #if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) #error SHOULD NOT BE IMPLEMENTED - case 22: // => "RESET" - /* WDTIE, KEYV */ - break; -#endif - - - default: - break; - } - //TODO: remove system IRQ vectors and OS - //TODO: FALTA USB + case 22: // => "RESET" + /* WDTIE, KEYV */ + break; +#endif + default: + break; + } + //TODO: remove system IRQ vectors and OS + //TODO: FALTA USB } @@ -546,321 +537,321 @@ it backups the actual state of the enabled signals for that vector (enabled by t */ void MSP430_DisableIRQ(unsigned char irQ_number) { - switch(irQ_number) - { + switch(irQ_number) + { #if( MSP430_ENABLE_RTC_HANDLER== 1) - case 0: // => "RTC", - /* RTCRDYIE, RTCTEVIE, RTCAIE, RT0PSIE, RT1PSIE */ + case 0: // => "RTC", + /* RTCRDYIE, RTCTEVIE, RTCAIE, RT0PSIE, RT1PSIE */ - //backup the register/s - rtcctl0_bck = RTCCTL0 ; - rtcps0ctl_bck = RTCPS0CTL ; - rtcps1ctl_bck = RTCPS1CTL ; + //backup the register/s + rtcctl0_bck = RTCCTL0 ; + rtcps0ctl_bck = RTCPS0CTL ; + rtcps1ctl_bck = RTCPS1CTL ; - //clear all flags - RTCCTL0 &=~( RTCTEVIE|RTCAIE|RTCRDYIE); - RTCPS0CTL &=~ RT0PSIE; - RTCPS1CTL &=~ RT1PSIE; - break; + //clear all flags + RTCCTL0 &=~( RTCTEVIE|RTCAIE|RTCRDYIE); + RTCPS0CTL &=~ RT0PSIE; + RTCPS1CTL &=~ RT1PSIE; + break; #endif #if( MSP430_ENABLE_PORT2_HANDLER== 1) - case 1 : //=> "PORT2", - /* P2IE.0 to P2IE.7*/ + case 1 : //=> "PORT2", + /* P2IE.0 to P2IE.7*/ - //backup the register/s - p2ie_bck = P2IE; + //backup the register/s + p2ie_bck = P2IE; - //clear all flags - P2IE = 0x00; - break; + //clear all flags + P2IE = 0x00; + break; #endif #if( MSP430_ENABLE_TIMER2_A1_HANDLER== 1) - case 2 : //=> "TIMER2_A1", - /* TA2CCR1 CCIE1 to TA2CCR2 CCIE2, TA2IE*/ + case 2 : //=> "TIMER2_A1", + /* TA2CCR1 CCIE1 to TA2CCR2 CCIE2, TA2IE*/ - //backup the register/s - ta2ctl_bck = TA2CTL ; - ta2cctl1_bck = TA2CCTL1; - ta2cctl2_bck = TA2CCTL2; + //backup the register/s + ta2ctl_bck = TA2CTL ; + ta2cctl1_bck = TA2CCTL1; + ta2cctl2_bck = TA2CCTL2; - //clear all flags - TA2CTL &=~ TAIE; - TA2CCTL1 &=~ CCIE; - TA2CCTL2 &=~ CCIE; - break; + //clear all flags + TA2CTL &=~ TAIE; + TA2CCTL1 &=~ CCIE; + TA2CCTL2 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) - case 3 : //=> "TIMER2_A0", - /* TA2CCR0 CCIE0 */ + case 3 : //=> "TIMER2_A0", + /* TA2CCR0 CCIE0 */ - //backup the register/s - ta2cctl0_bck = TA2CCTL0; + //backup the register/s + ta2cctl0_bck = TA2CCTL0; - //clear all flags - TA2CCTL0 &=~ CCIE; - break; + //clear all flags + TA2CCTL0 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) - case 4 : //=> "USCI_B1", - /* UCB1RXIE, UCB1TXIE */ + case 4 : //=> "USCI_B1", + /* UCB1RXIE, UCB1TXIE */ - //backup the register/s - ucb1ie_bck = UCB1IE; + //backup the register/s + ucb1ie_bck = UCB1IE; - //clear all flags - UCB1IE &=~ (UCRXIE|UCTXIE); - break; + //clear all flags + UCB1IE &=~ (UCRXIE|UCTXIE); + break; #endif #if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) - case 5 : //=> "USCI_A1", - /* UCA1RXIE, UCA1TXIE */ + case 5 : //=> "USCI_A1", + /* UCA1RXIE, UCA1TXIE */ - //backup the register/s - uca1ie_bck = UCA1IE; - uca1ctl1_bck = UCA1CTL1; + //backup the register/s + uca1ie_bck = UCA1IE; + uca1ctl1_bck = UCA1CTL1; - //clear all flags - UCA1IE &=~ (UCRXIE|UCTXIE); - UCA1CTL1 &=~ (UCRXEIE|UCBRKIE); - break; + //clear all flags + UCA1IE &=~ (UCRXIE|UCTXIE); + UCA1CTL1 &=~ (UCRXEIE|UCBRKIE); + break; #endif #if( MSP430_ENABLE_PORT1_HANDLER== 1) - case 6 : //=> "PORT1", - /* P1IE.0 to P1IE.7 */ - //backup the register/s - p1ie_bck = P1IE; + case 6 : //=> "PORT1", + /* P1IE.0 to P1IE.7 */ + //backup the register/s + p1ie_bck = P1IE; - //clear all flags - P1IE = 0x00; - break; + //clear all flags + P1IE = 0x00; + break; #endif #if( MSP430_ENABLE_TIMER1_A1_HANDLER==1 ) - case 7 : //=> "TIMER1_A1", - /* TA1CCR1 CCIE1 to TA1CCR2 CCIE2 TA1IE*/ + case 7 : //=> "TIMER1_A1", + /* TA1CCR1 CCIE1 to TA1CCR2 CCIE2 TA1IE*/ - //backup the register/s - ta1ctl_bck = TA1CTL ; - ta1cctl1_bck = TA1CCTL1; - ta1cctl2_bck = TA1CCTL2; + //backup the register/s + ta1ctl_bck = TA1CTL ; + ta1cctl1_bck = TA1CCTL1; + ta1cctl2_bck = TA1CCTL2; - //clear all flags - TA1CTL &=~ TAIE; - TA1CCTL1 &=~ CCIE; - TA1CCTL2 &=~ CCIE; - break; + //clear all flags + TA1CTL &=~ TAIE; + TA1CCTL1 &=~ CCIE; + TA1CCTL2 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) - case 8 : //=> "TIMER1_A0", - /* TA1CCR0 CCIE0 */ - //backup the register/s - ta1cctl0_bck = TA1CCTL0; + case 8 : //=> "TIMER1_A0", + /* TA1CCR0 CCIE0 */ + //backup the register/s + ta1cctl0_bck = TA1CCTL0; - //clear all flags - TA1CCTL0 &=~ CCIE; - break; + //clear all flags + TA1CCTL0 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_DMA_HANDLER==1 ) - case 9 : //=> "DMA", - /* DMA0IE, DMA1IE, DMA2IE */ + case 9 : //=> "DMA", + /* DMA0IE, DMA1IE, DMA2IE */ - //backup the register/s - dma0ctl_bck = DMA0CTL; - dma1ctl_bck = DMA1CTL; - dma2ctl_bck = DMA2CTL; + //backup the register/s + dma0ctl_bck = DMA0CTL; + dma1ctl_bck = DMA1CTL; + dma2ctl_bck = DMA2CTL; - //clear all flags - DMA0CTL &=~ DMAIE; - DMA1CTL &=~ DMAIE; - DMA2CTL &=~ DMAIE; - break; + //clear all flags + DMA0CTL &=~ DMAIE; + DMA1CTL &=~ DMAIE; + DMA2CTL &=~ DMAIE; + break; #endif #if( MSP430_ENABLE_USB_UBM_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 10: // => "USB_UBM", - /* USB interrupts */ - USBPWRCTL &=~ (VBOFFIE|VBONIE|VUOVLIE); - USBPLLIR &=~ (USBOORIE|USBLOSIE|USBOOLIE); - USBIEPCNF_0 &=~ USBIIE; - USBOEPCNF_0 &=~ USBIIE; - USBIEPIE = 0XFF; - USBOEPIE = 0XFF; - USBMAINT &=~ UTIE; - USBIE &=~ (RSTRIE|SUSRIE|RESRIE|SETUPIE|STPOWIE); - - USBIEPCNF_0 &=~ USBIIE; - USBOEPCNF_0 &=~ USBIIE; - - USBIEPCNF_1 &=~ USBIIE; - USBOEPCNF_1 &=~ USBIIE; - USBIEPCNF_2 &=~ USBIIE; - USBOEPCNF_2 &=~ USBIIE; - USBIEPCNF_3 &=~ USBIIE; - USBOEPCNF_3 &=~ USBIIE; - USBIEPCNF_4 &=~ USBIIE; - USBOEPCNF_4 &=~ USBIIE; - USBIEPCNF_5 &=~ USBIIE; - USBOEPCNF_5 &=~ USBIIE; - USBIEPCNF_6 &=~ USBIIE; - USBOEPCNF_6 &=~ USBIIE; - USBIEPCNF_7 &=~ USBIIE; - USBOEPCNF_7 &=~ USBIIE; - break; + case 10: // => "USB_UBM", + /* USB interrupts */ + USBPWRCTL &=~ (VBOFFIE|VBONIE|VUOVLIE); + USBPLLIR &=~ (USBOORIE|USBLOSIE|USBOOLIE); + USBIEPCNF_0 &=~ USBIIE; + USBOEPCNF_0 &=~ USBIIE; + USBIEPIE = 0XFF; + USBOEPIE = 0XFF; + USBMAINT &=~ UTIE; + USBIE &=~ (RSTRIE|SUSRIE|RESRIE|SETUPIE|STPOWIE); + + USBIEPCNF_0 &=~ USBIIE; + USBOEPCNF_0 &=~ USBIIE; + + USBIEPCNF_1 &=~ USBIIE; + USBOEPCNF_1 &=~ USBIIE; + USBIEPCNF_2 &=~ USBIIE; + USBOEPCNF_2 &=~ USBIIE; + USBIEPCNF_3 &=~ USBIIE; + USBOEPCNF_3 &=~ USBIIE; + USBIEPCNF_4 &=~ USBIIE; + USBOEPCNF_4 &=~ USBIIE; + USBIEPCNF_5 &=~ USBIIE; + USBOEPCNF_5 &=~ USBIIE; + USBIEPCNF_6 &=~ USBIIE; + USBOEPCNF_6 &=~ USBIIE; + USBIEPCNF_7 &=~ USBIIE; + USBOEPCNF_7 &=~ USBIIE; + break; #endif #if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) - case 11: // => "TIMER0_A1", - /* TA0CCR1 CCIE1 to TA0CCR4 CCIE4 TA0IE */ + case 11: // => "TIMER0_A1", + /* TA0CCR1 CCIE1 to TA0CCR4 CCIE4 TA0IE */ - //backup the register/s - ta0ctl_bck= TA0CTL ; - ta0cctl1_bck= TA0CCTL1; - ta0cctl2_bck= TA0CCTL2; - ta0cctl3_bck= TA0CCTL3; - ta0cctl4_bck= TA0CCTL4; + //backup the register/s + ta0ctl_bck= TA0CTL ; + ta0cctl1_bck= TA0CCTL1; + ta0cctl2_bck= TA0CCTL2; + ta0cctl3_bck= TA0CCTL3; + ta0cctl4_bck= TA0CCTL4; - //clear all flags - TA0CTL &=~ TAIE; - TA0CCTL1 &=~ CCIE; - TA0CCTL2 &=~ CCIE; - TA0CCTL3 &=~ CCIE; - TA0CCTL4 &=~ CCIE; - break; + //clear all flags + TA0CTL &=~ TAIE; + TA0CCTL1 &=~ CCIE; + TA0CCTL2 &=~ CCIE; + TA0CCTL3 &=~ CCIE; + TA0CCTL4 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) - case 12: // => "TIMER0_A0", - /* TA0CCR0 CCIE0 */ - //backup the register/s - ta0cctl0_bck = TA0CCTL0; + case 12: // => "TIMER0_A0", + /* TA0CCR0 CCIE0 */ + //backup the register/s + ta0cctl0_bck = TA0CCTL0; - //clear all flags - TA0CCTL0 &=~ CCIE; - break; + //clear all flags + TA0CCTL0 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_ADC12_HANDLER==1 ) - case 13: // => "ADC12", - /* ADC12IE0 to ADC12IE15 */ + case 13: // => "ADC12", + /* ADC12IE0 to ADC12IE15 */ - //backup the register/s - adc12ctl0_bck = ADC12CTL0; - adc12ie_bck = ADC12IE; + //backup the register/s + adc12ctl0_bck = ADC12CTL0; + adc12ie_bck = ADC12IE; - //clear all flags - ADC12CTL0 &=~ (ADC12OVIE|ADC12TOVIE); - ADC12IE = 0x0000; - break; + //clear all flags + ADC12CTL0 &=~ (ADC12OVIE|ADC12TOVIE); + ADC12IE = 0x0000; + break; #endif #if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) - case 14: // => "USCI_B0", - /* UCB0RXIE, UCB0TXIE */ + case 14: // => "USCI_B0", + /* UCB0RXIE, UCB0TXIE */ - //backup the register/s - ucb0ie_bck = UCB0IEUCB0IE; + //backup the register/s + ucb0ie_bck = UCB0IEUCB0IE; - //clear all flags - UCB0IE &=~ (UCRXIE|UCTXIE); - break; + //clear all flags + UCB0IE &=~ (UCRXIE|UCTXIE); + break; #endif #if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) - case 15: // => "USCI_A0", - /* UCA0RXIE, UCA0TXIE */ + case 15: // => "USCI_A0", + /* UCA0RXIE, UCA0TXIE */ - //backup the register/s - uca0ie_bck = UCA0IE; - uca0ctl1_bck = UCA0CTL1; + //backup the register/s + uca0ie_bck = UCA0IE; + uca0ctl1_bck = UCA0CTL1; - //clear all flags - UCA0IE &=~ (UCRXIE|UCTXIE); - UCA0CTL1 &=~ (UCRXEIE|UCBRKIE); - break; + //clear all flags + UCA0IE &=~ (UCRXIE|UCTXIE); + UCA0CTL1 &=~ (UCRXEIE|UCBRKIE); + break; #endif #if( MSP430_ENABLE_WDT_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 16: // => "WDT", - /* WDTIE */ - break; + case 16: // => "WDT", + /* WDTIE */ + break; #endif #if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) - case 17: // => "TIMER0_B1", - /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ - - //backup the register/s - tb0ctl_bck = TB0CTL ; - tb0cctl1_bck = TB0CCTL1 ; - tb0cctl2_bck = TB0CCTL2 ; - tb0cctl3_bck = TB0CCTL3 ; - tb0cctl4_bck = TB0CCTL4 ; - tb0cctl5_bck = TB0CCTL5 ; - tb0cctl6_bck = TB0CCTL6 ; - - //clear all flags - TB0CTL &=~ TAIE; - TB0CCTL1 &=~ CCIE; - TB0CCTL2 &=~ CCIE; - TB0CCTL3 &=~ CCIE; - TB0CCTL4 &=~ CCIE; - TB0CCTL5 &=~ CCIE; - TB0CCTL6 &=~ CCIE; - break; + case 17: // => "TIMER0_B1", + /* TB0CCR1 CCIE1 to TB0CCR6 CCIE6 TB0IE */ + + //backup the register/s + tb0ctl_bck = TB0CTL ; + tb0cctl1_bck = TB0CCTL1 ; + tb0cctl2_bck = TB0CCTL2 ; + tb0cctl3_bck = TB0CCTL3 ; + tb0cctl4_bck = TB0CCTL4 ; + tb0cctl5_bck = TB0CCTL5 ; + tb0cctl6_bck = TB0CCTL6 ; + + //clear all flags + TB0CTL &=~ TAIE; + TB0CCTL1 &=~ CCIE; + TB0CCTL2 &=~ CCIE; + TB0CCTL3 &=~ CCIE; + TB0CCTL4 &=~ CCIE; + TB0CCTL5 &=~ CCIE; + TB0CCTL6 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) - case 18: // => "TIMER0_B0", - /* TB0CCR0 CCIE0 */ + case 18: // => "TIMER0_B0", + /* TB0CCR0 CCIE0 */ - //backup the register/s - tb0cctl0_bck = TB0CCTL0; + //backup the register/s + tb0cctl0_bck = TB0CCTL0; - //clear all flags - TB0CCTL0 &=~ CCIE; - break; + //clear all flags + TB0CCTL0 &=~ CCIE; + break; #endif #if( MSP430_ENABLE_COMP_B_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 19: // => "COMP_B", - /* Comparator B interrupt flags */ - break; + case 19: // => "COMP_B", + /* Comparator B interrupt flags */ + break; #endif #if( MSP430_ENABLE_UNMI_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 20: // => "UNMI", - break; + case 20: // => "UNMI", + break; #endif #if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) #error SHOULD NOT BE IMPLEMENTED - case 21: // => "SYSNMI", - /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ - break; + case 21: // => "SYSNMI", + /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ + break; #endif #if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) #error SHOULD NOT BE IMPLEMENTED - case 22: // => "RESET" - /* WDTIE, KEYV */ - break; + case 22: // => "RESET" + /* WDTIE, KEYV */ + break; #endif - default: - break; - } + default: + break; + } } /* @@ -868,176 +859,176 @@ for a given irq_number it clear the flag that made the handler to be called. */ void ClearPendingIRQ_Arch(unsigned short irQ_number) { - volatile unsigned char dummy; //ignore compiling warning + volatile unsigned char dummy; //ignore compiling warning - switch(irQ_number) - { + switch(irQ_number) + { #if( MSP430_ENABLE_RTC_HANDLER== 1) #error TODO: NOT IMPLEMENTED - case 0: // => "RTC", - break; + case 0: // => "RTC", + break; #endif #if( MSP430_ENABLE_PORT2_HANDLER== 1) - case 1 : //=> "PORT2", - dummy = P2IV; - /* There is no need to clear the flag manually: From MSP430f5529 User manually + case 1 : //=> "PORT2", + dummy = P2IV; + /* There is no need to clear the flag manually: From MSP430f5529 User manually - " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If - another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If + another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " - */ - break; + */ + break; #endif #if( MSP430_ENABLE_TIMER2_A1_HANDLER== 1) #error TODO: SHOULD NOT BE IMPLEMENTED. THIS IRQ IS RESERVED FOR RTOS FUNCTIONALITY - case 2 : //=> "TIMER2_A1", + case 2 : //=> "TIMER2_A1", - break; + break; #endif #if( MSP430_ENABLE_TIMER2_A0_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 3 : //=> "TIMER2_A0", + case 3 : //=> "TIMER2_A0", - break; + break; #endif #if( MSP430_ENABLE_USCI_B1_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 4 : //=> "USCI_B1", + case 4 : //=> "USCI_B1", - break; + break; #endif #if( MSP430_ENABLE_USCI_A1_HANDLER==1 ) - case 5 : //=> "USCI_A1", - dummy = UCA1IV; - break; + case 5 : //=> "USCI_A1", + dummy = UCA1IV; + break; #endif #if( MSP430_ENABLE_PORT1_HANDLER== 1) - case 6 : //=> "PORT1", - dummy = P1IV; - /* There is no need to clear the flag manually: From MSP430f5529 User manually + case 6 : //=> "PORT1", + dummy = P1IV; + /* There is no need to clear the flag manually: From MSP430f5529 User manually - " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If - another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " + " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If + another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " - */ - break; + */ + break; #endif #if( MSP430_ENABLE_TIMER1_A1_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 7 : //=> "TIMER1_A1", + case 7 : //=> "TIMER1_A1", - break; + break; #endif #if( MSP430_ENABLE_TIMER1_A0_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 8 : //=> "TIMER1_A0", + case 8 : //=> "TIMER1_A0", - break; + break; #endif #if( MSP430_ENABLE_DMA_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 9 : //=> "DMA", + case 9 : //=> "DMA", - break; + break; #endif #if( MSP430_ENABLE_USB_UBM_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 10: // => "USB_UBM", + case 10: // => "USB_UBM", - break; + break; #endif #if( MSP430_ENABLE_TIMER0_A1_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 11: // => "TIMER0_A1", + case 11: // => "TIMER0_A1", - break; + break; #endif #if( MSP430_ENABLE_TIMER0_A0_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 12: // => "TIMER0_A0", + case 12: // => "TIMER0_A0", - break; + break; #endif #if( MSP430_ENABLE_ADC12_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 13: // => "ADC12", + case 13: // => "ADC12", - break; + break; #endif #if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) - case 14: // => "USCI_B0", + case 14: // => "USCI_B0", - break; + break; #endif #if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) - case 15: // => "USCI_A0", - dummy = UCA0IV; - break; + case 15: // => "USCI_A0", + dummy = UCA0IV; + break; #endif #if( MSP430_ENABLE_WDT_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 16: // => "WDT", - /* WDTIE */ - break; + case 16: // => "WDT", + /* WDTIE */ + break; #endif #if( MSP430_ENABLE_TIMER0_B1_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 17: // => "TIMER0_B1", + case 17: // => "TIMER0_B1", - break; + break; #endif #if( MSP430_ENABLE_TIMER0_B0_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 18: // => "TIMER0_B0", + case 18: // => "TIMER0_B0", - break; + break; #endif #if( MSP430_ENABLE_COMP_B_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 19: // => "COMP_B", - /* Comparator B interrupt flags */ - break; + case 19: // => "COMP_B", + /* Comparator B interrupt flags */ + break; #endif #if( MSP430_ENABLE_UNMI_HANDLER==1 ) #error TODO: NOT IMPLEMENTED - case 20: // => "UNMI", - break; + case 20: // => "UNMI", + break; #endif #if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) #error SHOULD NOT BE IMPLEMENTED - case 21: // => "SYSNMI", - /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ - break; + case 21: // => "SYSNMI", + /* NMIIE, OFIE, ACCVIE, BUSIE SVMLIE, SVMHIE, DLYLIE, DLYHIE, VLRLIE, VLRHIE, VMAIE, JMBNIE, JMBOUTIE */ + break; #endif #if( MSP430_ENABLE_SYSNMI_HANDLER==1 ) #error SHOULD NOT BE IMPLEMENTED - case 22: // => "RESET" - /* WDTIE, KEYV */ - break; + case 22: // => "RESET" + /* WDTIE, KEYV */ + break; #endif - } + } } /** @} doxygen end group definition */ /** @} doxygen end group definition */ diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index 7aeeae26..3fd12c2d 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -1,4 +1,6 @@ /* Copyright 2016, Franco Bucafusco + * + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -45,20 +47,6 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - -/* -* Initials Name -* --------------------------- -* FBUC Franco Bucafusco -* -*/ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FBUC initial version - */ - /*==================[inclusions]=============================================*/ #include "Os_Internal.h" #include "StartOs_Arch_SystemTick.h" @@ -77,33 +65,33 @@ static void __attribute__((naked, section(".crt_0042"), used)) disable_watchdog (void) { - //https://sourceware.org/ml/newlib/2015/msg00627.html - WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer + //https://sourceware.org/ml/newlib/2015/msg00627.html + WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer } /*==================[external functions definition]==========================*/ void StartOs_Arch_Cpu(void) { - StartOs_Arch_System(); //TODO: this should be placed in other file. For cortex processors is placed within the reset vector handler. - StartOs_Arch_SystemTick(); - //Enable_User_ISRs(); //USER ISRs SHOULD BE ENABLED BY THE USER USING a_MSP430ware Libraries or OS buildin Drivers. + StartOs_Arch_System(); //TODO: this should be placed in other file. For cortex processors is placed within the reset vector handler. + StartOs_Arch_SystemTick(); + //Enable_User_ISRs(); //USER ISRs SHOULD BE ENABLED BY THE USER USING a_MSP430ware Libraries or OS buildin Drivers. } /** */ void StartOs_Arch(void) { - uint8f loopi; + uint8f loopi; - /* init every task */ - for( loopi = 0; loopi < TASKS_COUNT; loopi++) - { - InitStack_Arch(loopi); - } + /* init every task */ + for( loopi = 0; loopi < TASKS_COUNT; loopi++) + { + InitStack_Arch(loopi); + } - /* CPU dependent initialisation */ - StartOs_Arch_Cpu(); + /* CPU dependent initialisation */ + StartOs_Arch_Cpu(); } /** @} doxygen end group definition */ diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c index ad36c8b5..a2cc1b30 100644 --- a/src/msp430/StartOs_Arch_SystemTick.c +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -1,5 +1,6 @@ /* Copyright 2016, Franco Bucafusco * + * All Rights Reserved * This file is part of CIAA Firmware. * * Redistribution and use in source and binary forms, with or without @@ -43,18 +44,6 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ -/* -* Initials Name -* --------------------------- -* FBUC Franco Bucafusco -* -*/ - -/* - * modification history (new versions first) - * ----------------------------------------------------------- - * 20160222 v0.1.0 FBUC initial version - */ /*==================[inclusions]=============================================*/ #include "Os_Internal_Arch_Cpu.h" @@ -87,23 +76,23 @@ /*==================[internal data definition]===============================*/ const Timer_A_initUpModeParam tick_timer_init_params = { - .clockSource = TIMER_A_CLOCKSOURCE_ACLK, - .clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1, - .timerPeriod = VALOR_MS( TIC_PERIOD ) , - .timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE, - .captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE, - .timerClear = TIMER_A_SKIP_CLEAR, - .startTimer = true, + .clockSource = TIMER_A_CLOCKSOURCE_ACLK, + .clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1, + .timerPeriod = VALOR_MS( TIC_PERIOD ) , + .timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE, + .captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE, + .timerClear = TIMER_A_SKIP_CLEAR, + .startTimer = true, }; const Timer_A_initCaptureModeParam swi_init_params = { - .captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1, - .captureMode = TIMER_A_CAPTUREMODE_NO_CAPTURE, //FUNCIONA? SI NO, PROBAR CON TIMER_A_CAPTUREMODE_RISING_EDGE - .captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_GND, - .synchronizeCaptureSource = TIMER_A_CAPTURE_ASYNCHRONOUS, - .captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE, - .captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE, /* this is set for completion of the structure, but no needed*/ + .captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1, + .captureMode = TIMER_A_CAPTUREMODE_NO_CAPTURE, //FUNCIONA? SI NO, PROBAR CON TIMER_A_CAPTUREMODE_RISING_EDGE + .captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_GND, + .synchronizeCaptureSource = TIMER_A_CAPTURE_ASYNCHRONOUS, + .captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE, + .captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE, /* this is set for completion of the structure, but no needed*/ }; /*==================[external data definition]===============================*/ @@ -121,42 +110,42 @@ void StartOs_Arch_System() { - UCS_turnOffXT1(); + UCS_turnOffXT1(); - XT1_XT2_PORT_SEL |= XT1_ENABLE + XT2_ENABLE; // Setup XT1 and XT2 + XT1_XT2_PORT_SEL |= XT1_ENABLE + XT2_ENABLE; // Setup XT1 and XT2 - PMM_setVCore( 3 ); // Set Vcore to accomodate for max. allowed system speed + PMM_setVCore( 3 ); // Set Vcore to accomodate for max. allowed system speed - UCS_turnOnLFXT1( UCS_XT1_DRIVE_0 , UCS_XCAP_1 ); // Use 32.768kHz XTAL as reference + UCS_turnOnLFXT1( UCS_XT1_DRIVE_0 , UCS_XCAP_1 ); // Use 32.768kHz XTAL as reference - UCS_initClockSignal( UCS_FLLREF , UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 ); + UCS_initClockSignal( UCS_FLLREF , UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 ); - UCS_initFLLSettle( WORKING_FREQUENCY_KHZ, ( WORKING_FREQUENCY_HZ/REF_FREQUENCY_HZ ) ); + UCS_initFLLSettle( WORKING_FREQUENCY_KHZ, ( WORKING_FREQUENCY_HZ/REF_FREQUENCY_HZ ) ); - /* - ESTA LINEAS SON PARA ESTABLECER LA CONFIGURACION DEL MODULO PMM PARA QUE ESTE EN FULL PERFORMACN Y FAST WAKE UP MODE. - SI NO ESTA CONFIGURADO ASI, AL DESPERTARSE DE UN LPM, EL ARRANQUE DEL DCO NO ES AGIL Y PARA EL CASO DE LA RECEPCION DE LA - UART Y SE PIERDE EL PRIMER uint8_t DE DATOS. - ESTO ES, PORQUE EL TIEMPO DE ENCENDIDO ES MAYOR QUE UN BIT DE LA COMUNICACION. - */ - PMM_enableSvsLInLPMFastWake(); // SVSL_ENABLED_IN_LPM_FAST_WAKE(); - PMM_enableSvsHInLPMFullPerf(); // SVSH_ENABLED_IN_LPM_FULL_PERF() ; + /* + ESTA LINEAS SON PARA ESTABLECER LA CONFIGURACION DEL MODULO PMM PARA QUE ESTE EN FULL PERFORMACN Y FAST WAKE UP MODE. + SI NO ESTA CONFIGURADO ASI, AL DESPERTARSE DE UN LPM, EL ARRANQUE DEL DCO NO ES AGIL Y PARA EL CASO DE LA RECEPCION DE LA + UART Y SE PIERDE EL PRIMER uint8_t DE DATOS. + ESTO ES, PORQUE EL TIEMPO DE ENCENDIDO ES MAYOR QUE UN BIT DE LA COMUNICACION. + */ + PMM_enableSvsLInLPMFastWake(); // SVSL_ENABLED_IN_LPM_FAST_WAKE(); + PMM_enableSvsHInLPMFullPerf(); // SVSH_ENABLED_IN_LPM_FULL_PERF() ; - PMM_optimizeSvsLInLPMFastWake(); // SVSL_OPTIMIZED_IN_LPM_FAST_WAKE(); - PMM_optimizeSvsHInLPMFullPerf(); // SVSH_OPTIMIZED_IN_LPM_FULL_PERF(); + PMM_optimizeSvsLInLPMFastWake(); // SVSL_OPTIMIZED_IN_LPM_FAST_WAKE(); + PMM_optimizeSvsHInLPMFullPerf(); // SVSH_OPTIMIZED_IN_LPM_FULL_PERF(); - SVMH_FULL_PERF(); + SVMH_FULL_PERF(); - PMM_disableSvsL();// DISABLE_SVSL() ; + PMM_disableSvsL();// DISABLE_SVSL() ; } void StartOs_Arch_SystemTick(void) { - /* Activate SystemTick */ - Timer_A_initUpMode( TIMER_A2_BASE , (Timer_A_initUpModeParam*) &tick_timer_init_params); + /* Activate SystemTick */ + Timer_A_initUpMode( TIMER_A2_BASE , (Timer_A_initUpModeParam*) &tick_timer_init_params); - /* Configuration of the channel 1 to simulate the PendSV IRQ from cortex arquitecture.*/ - Timer_A_initCaptureMode( TIMER_A2_BASE ,(Timer_A_initCaptureModeParam*) &swi_init_params ); + /* Configuration of the channel 1 to simulate the PendSV IRQ from cortex arquitecture.*/ + Timer_A_initCaptureMode( TIMER_A2_BASE ,(Timer_A_initCaptureModeParam*) &swi_init_params ); } /** @} doxygen end group definition */ diff --git a/tst/ctest/bin/ctest.pl b/tst/ctest/bin/ctest.pl index 62e6b87e..65f8b6d1 100755 --- a/tst/ctest/bin/ctest.pl +++ b/tst/ctest/bin/ctest.pl @@ -4,6 +4,8 @@ # Copyright 2014, ACSE & CADIEEL # ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ # CADIEEL: http://www.cadieel.org.ar +# Copyright 2016, Franco Bucafusco +# All Rights Reserved # # This file is part of CIAA Firmware. # @@ -473,7 +475,7 @@ sub CreateTestProject @replace = GetTestSequencesCon($TESTS, $testfn, $config); # TODO this shall be improved. Definitely. Doing this for another platform was a headache - # CT stand for : ?? + # CT stand for : ?? # VN stands for : "Vector Name" push @replace, "CT_ISR1:" . $ISR1; push @replace, "CT_ISR2:" . $ISR2; @@ -507,8 +509,8 @@ sub CreateTestProject print FILE "rtos_GEN_FILES += modules\$(DS)rtos\$(DS)tst\$(DS)ctest\$(DS)gen\$(DS)inc\$(DS)ctest_cfg.h.php\n\n"; print FILE "CFLAGS += -D$test\n"; - #adds extra makefile options based on the architecture - Extra_MakeFile_AddOns_Arch(); + #adds extra makefile options based on the architecture + Extra_MakeFile_AddOns_Arch(); close FILE; @@ -519,8 +521,8 @@ sub CreateTestProject copy("modules/rtos/tst/ctest/inc/$ARCH/ctest_arch.h","$base/inc/$ARCH/ctest_arch.h"); copy("modules/rtos/tst/ctest/src/$ARCH/ctest_arch.c","$base/src/$ARCH/ctest_arch.c"); - #last replacement for IRQ vector name definitions - Extra_IRQ_Vector_Replace("$base/src/$test.c"); + #last replacement for IRQ vector name definitions + Extra_IRQ_Vector_Replace("$base/src/$test.c"); } sub finish @@ -595,7 +597,7 @@ sub logffull $subtestcase = $ARGV[3]; #Example: 'ctest_tm_01:Test Sequence 1' or empty -$onlytc = $ARGV[2]; +$onlytc = $ARGV[2]; $cfgfile = $ARGV[1]; @@ -624,15 +626,15 @@ sub logffull if ("msp430" eq $ARCH) { - if ("msp430f5x_6x" eq $CPUTYPE) - { - if ("msp430f5529" eq $CPU) - { - $ISR1 = "PORT2"; - $ISR2 = "PORT1"; - $ISR3 = "PORT3"; #TODO For Interrupt type 3 when enable. - } - } + if ("msp430f5x_6x" eq $CPUTYPE) + { + if ("msp430f5529" eq $CPU) + { + $ISR1 = "PORT2"; + $ISR2 = "PORT1"; + $ISR3 = "PORT3"; #TODO For Interrupt type 3 when enable. + } + } } mkpath(dirname($logfile)); @@ -812,10 +814,10 @@ sub logffull { $out = $BINDIR . "/" . $test . "-" . $config . ".axf"; } - elsif ( $ARCH eq "msp430") - { + elsif ( $ARCH eq "msp430") + { $out = $BINDIR . "/" . $test . "-" . $config . ".out"; - } + } else { $out = $BINDIR . "/" . $test . "-" . $config . ".exe"; @@ -844,10 +846,9 @@ sub logffull if($debug == 0) { - #$outdbg = `$GDB $out -x $dbgfile`; $outdbg = `$debug_command`; - if ($ARCH eq "x86") + if ($ARCH eq "x86") { # if it fails, then capture ASSERT message with the condition, File and Line that failed and print it! my $Test_Asserted = index($outdbg, "ASSERT"); @@ -867,11 +868,20 @@ sub logffull } $outdbgstatus = $?; + info("debug status: $outdbgstatus"); info("debug output:\n$outdbg"); - logffull("$GDB output:\n$outgdb"); - $outdbgstatus = 0; + if ("msp430" eq $ARCH) + { + logffull("mspdebug output:\n$outgdb"); + } + else + { + logffull("$GDB output:\n$outgdb"); + } + + $outdbgstatus = 0; if ($outdbgstatus == 0) { diff --git a/tst/ctest/inc/ctest.h b/tst/ctest/inc/ctest.h index f83d47f4..8b30a23c 100644 --- a/tst/ctest/inc/ctest.h +++ b/tst/ctest/inc/ctest.h @@ -3,6 +3,8 @@ * Copyright 2014, ACSE & CADIEEL * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -258,8 +260,6 @@ #define EnableISR2() \ EnableISR2_Arch() - - /** \brief Initialise Alarm Counter Macro ** ** This macro shall implement a mechanismus to initialise the alarm counter @@ -438,3 +438,4 @@ extern void ConfTestFinish /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _CTEST_H_ */ + diff --git a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile index 32ba467c..4e7da3d8 100755 --- a/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile +++ b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile @@ -1,6 +1,7 @@ ############################################################################### # -# Copyright 2016, Franco Bucafusco (BuckLabs) +# Copyright 2016, Franco Bucafusco +# All Rights Reserved # # This file is part of CIAA Firmware. # diff --git a/tst/ctest/src/ctest_em_01.c b/tst/ctest/src/ctest_em_01.c index eb682d69..e8cf3973 100644 --- a/tst/ctest/src/ctest_em_01.c +++ b/tst/ctest/src/ctest_em_01.c @@ -75,7 +75,7 @@ int main ) { EnableISR2(); - + /* start OS in AppMode 1 */ StartOS(AppMode1); diff --git a/tst/ctest/src/ctest_ip_01.c b/tst/ctest/src/ctest_ip_01.c index 7b6ac148..45d6aa3d 100644 --- a/tst/ctest/src/ctest_ip_01.c +++ b/tst/ctest/src/ctest_ip_01.c @@ -4,6 +4,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -209,3 +210,4 @@ TASK(Task2) /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ + diff --git a/tst/ctest/src/ctest_ip_03.c b/tst/ctest/src/ctest_ip_03.c index df2c9d02..b1f9e3c0 100644 --- a/tst/ctest/src/ctest_ip_03.c +++ b/tst/ctest/src/ctest_ip_03.c @@ -1,5 +1,6 @@ /* Copyright 2014, Mariano Cerdeiro * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/tst/ctest/src/ctest_ip_04.c b/tst/ctest/src/ctest_ip_04.c index 4309cd58..65c086bc 100644 --- a/tst/ctest/src/ctest_ip_04.c +++ b/tst/ctest/src/ctest_ip_04.c @@ -1,5 +1,6 @@ /* Copyright 2014, Mariano Cerdeiro * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * diff --git a/tst/ctest/src/ctest_rm_01.c b/tst/ctest/src/ctest_rm_01.c index 78e1cfdb..99ad98f7 100644 --- a/tst/ctest/src/ctest_rm_01.c +++ b/tst/ctest/src/ctest_rm_01.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -75,7 +76,7 @@ int main ) { EnableISR2(); - + /* start OS in AppMode 1 */ StartOS(AppMode1); diff --git a/tst/ctest/src/ctest_rm_05.c b/tst/ctest/src/ctest_rm_05.c index 00262690..be008a03 100644 --- a/tst/ctest/src/ctest_rm_05.c +++ b/tst/ctest/src/ctest_rm_05.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -75,7 +76,7 @@ int main ) { EnableISR2(); - + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -193,3 +194,4 @@ ISR(VN_ISR3) /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ + diff --git a/tst/ctest/src/ctest_rst.c b/tst/ctest/src/ctest_rst.c index f0007e6e..dcfa4300 100644 --- a/tst/ctest/src/ctest_rst.c +++ b/tst/ctest/src/ctest_rst.c @@ -719,7 +719,7 @@ uint32f SequenceCounter; /*==================[external functions definition]==========================*/ void ConfTestEvaluation ( - void +void ) { uint32f loopi; @@ -744,10 +744,10 @@ void ConfTestEvaluation } - void Sequence +void Sequence ( - uint32f seq - ) +uint32f seq +) { if ( (seq) == 0 ) { @@ -763,7 +763,7 @@ void ConfTestEvaluation } } - void ConfTestFinish +void ConfTestFinish ( void ) diff --git a/tst/ctest/src/ctest_tm_01.c b/tst/ctest/src/ctest_tm_01.c index cebc3cc3..84908864 100644 --- a/tst/ctest/src/ctest_tm_01.c +++ b/tst/ctest/src/ctest_tm_01.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -75,7 +76,7 @@ int main ) { EnableISR2(); - + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -296,3 +297,4 @@ ISR(VN_ISR3) /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ + diff --git a/tst/ctest/src/itest_ip_01.c b/tst/ctest/src/itest_ip_01.c index caf42f05..5f24d2b2 100644 --- a/tst/ctest/src/itest_ip_01.c +++ b/tst/ctest/src/itest_ip_01.c @@ -1,5 +1,6 @@ /* Copyright 2014 Mariano Cerdeiro * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -72,7 +73,7 @@ int main ) { EnableISR2(); - + /* start OS in AppMode 1 */ StartOS(AppMode1); From 23aaecb7e8af051689a29201a9cd970b06df9af0 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Tue, 11 Oct 2016 07:07:07 -0300 Subject: [PATCH 37/42] minor changes --- gen/inc/Os_Cfg.h.php | 9 ++++++--- gen/src/Os_Internal_Cfg.c.php | 15 ++++++++++++--- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 2 -- inc/Os_Internal.h | 1 + inc/msp430/Os_Internal_Arch.h | 6 +++--- inc/tmparch/Os_Internal_Arch.h | 2 +- inc/x86/Os_Internal_Arch.h | 3 ++- src/GetResource.c | 1 + src/ReleaseResource.c | 1 + src/Schedule.c | 2 +- src/SetAbsAlarm.c | 1 + src/SetRelAlarm.c | 1 + src/StartOS.c | 1 + src/TerminateTask.c | 1 + src/msp430/Os_Internal_Arch.c | 21 ++++++++++++++------- 15 files changed, 46 insertions(+), 21 deletions(-) diff --git a/gen/inc/Os_Cfg.h.php b/gen/inc/Os_Cfg.h.php index 556d9413..db1cb896 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -7,6 +7,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016 Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. @@ -79,6 +80,7 @@ /* Definitions of Tasks : Tasks that will be executed within the local core */ /* TODO: validate that tasks has different names */ + $tasks = $this->helper->multicore->getLocalList("/OSEK", "TASK"); $remote_tasks = $this->helper->multicore->getRemoteList("/OSEK", "TASK"); $os = $this->config->getList("/OSEK","OS"); @@ -123,9 +125,8 @@ $matrix_n = array(); /* it stores the events' assigned number for each task */ $events = $this->config->getList("/OSEK","EVENT"); -//$nro_evs= max(array_keys($events))+1; + $nro_evs= count($events); -#print("cantidad de eventos: $nro_evs \n"); /* task/events matrix creation, and various validations */ foreach( $tasks as $task_index => $task ) @@ -225,7 +226,7 @@ foreach( $matriz[$task_index] as $ev ) { - if($flags_exc_event>$max_amount_events ) + if( $flags_exc_event>$max_amount_events ) { throw new Exception("===== OIL ERROR: There are more than $max_amount_events events defined. =====\n"); /* stops execution */ @@ -446,6 +447,8 @@ $intnames = $this->helper->multicore->getLocalList("/OSEK", "ISR"); +//print_r($intnames); + foreach ($intnames as $count=>$int) { print "\n/** \brief ISR Declaration */\n"; diff --git a/gen/src/Os_Internal_Cfg.c.php b/gen/src/Os_Internal_Cfg.c.php index 93752da6..4ba61c03 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -7,6 +7,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016 Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. @@ -122,6 +123,7 @@ foreach ($counters as $counter) { $countalarms = 0; + foreach ($alarms as $alarm) { if ($counter == $this->config->getValue("/OSEK/" . $alarm,"COUNTER")) @@ -129,7 +131,10 @@ $countalarms++; } } - print "const AlarmType OSEK_ALARMLIST_" . $counter . "[" . $countalarms . "] = {\n"; + + print "\nconst AlarmType OSEK_ALARMLIST_" . $counter . "[" . $countalarms . "] = \n"; + print "{\n"; + foreach ($alarms as $alarm) { if ($counter == $this->config->getValue("/OSEK/" . $alarm,"COUNTER")) @@ -137,6 +142,7 @@ print " $alarm, /* this alarm has to be incremented with this counter */\n"; } } + print "};\n\n"; } ?> @@ -313,7 +319,7 @@ } } print " " . count($tasksinmode) .", /* Total Auto Start Tasks in this Application Mode */\n"; - if (count($tasksinmode)>0) + if( count($tasksinmode)>0 ) { print " (TaskRefType)TasksAppMode" . $appmode . " /* Pointer to the list of Auto Start Stacks on this Application Mode */\n"; } @@ -554,13 +560,16 @@ $inttype = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); $intcat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); + //print $inttype ." ".$intcat ." ". $intList[$i] ." ".$int ."\n"; + print("/* Wrapper ISR handler for $int */\n"); if ($intcat == 2) { if($this->definitions["ARCH"] == "msp430") { - print "interrupt_vec($int) \n"; + print "interrupt_vec(".$inttype."_VECTOR) \n"; + //print "interrupt_vec($int) \n"; } ?> void OSEK_ISR2_(void) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 73ae6b4a..45c427aa 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -155,7 +155,6 @@ if($src_found == 0) { #for an undefined ISR witihn the OIL file, we defiene a DUMMY handler. - #print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */\n"; print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked)) \n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */ \n"; print "{\n"; @@ -167,7 +166,6 @@ if( $intcat == 1 ) { #for an ISR type 1 witihn the OIL file, we defiene a ISR wrapper that calls the ISR defined by the user somewhere. - #print "__attribute__( (__interrupt_vec($intList[$i]_VECTOR),naked)) \n"; print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked))\n"; print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]_VECTOR) somewhere */ \n"; print "{\n"; diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index 3a7295bc..fc3f3696 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -282,3 +282,4 @@ extern CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncre /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_H_ */ + diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 1d742792..5ce1def4 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -298,7 +298,7 @@ extern TaskType TerminatingTask; ** ** This macro is called every time that an ISR Cat 1 is finished **/ -#define PostIsr1_Arch(isr) ClearPendingIRQ_Arch(isr) +#define PostIsr1_Arch(isr) GetPendingIRQ_Arch(isr) /** \brief Pre ISR Macro ** @@ -310,7 +310,7 @@ extern TaskType TerminatingTask; ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) ClearPendingIRQ_Arch(isr) +#define PostIsr2_Arch(isr) GetPendingIRQ_Arch(isr) /** \brief ShutdownOs Arch service ** @@ -325,7 +325,7 @@ extern TaskType TerminatingTask; /*==================[external functions declaration]=========================*/ void InitStack_Arch(uint8 TaskID); -void ClearPendingIRQ_Arch(unsigned short irQ_number); +uint16_t GetPendingIRQ_Arch( uint16_t irQ_number ); void MSP430_EnableIRQ(unsigned char irQ_number); void MSP430_DisableIRQ(unsigned char irQ_number); diff --git a/inc/tmparch/Os_Internal_Arch.h b/inc/tmparch/Os_Internal_Arch.h index cb4a4dc7..e4e4539c 100644 --- a/inc/tmparch/Os_Internal_Arch.h +++ b/inc/tmparch/Os_Internal_Arch.h @@ -101,7 +101,7 @@ ** If for the actual architecture no Osek_Internal_Arch_Cpu.h is neede ** remove the macro and this comment. **/ -#define OSEK_INCLUDE_INTERNAL_ARCH_CPU +#define OSEK_INLCUDE_INTERNAL_ARCH_CPU #error update the following macro and remove this comment /** \brief Interrupt Secure Start Macro diff --git a/inc/x86/Os_Internal_Arch.h b/inc/x86/Os_Internal_Arch.h index e902d331..80fefa49 100644 --- a/inc/x86/Os_Internal_Arch.h +++ b/inc/x86/Os_Internal_Arch.h @@ -262,7 +262,8 @@ ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) +#define PostIsr2_Arch(isr) \ + Schedule_WOChecks(); #if ( CPUTYPE == ia64 ) #define SaveOsStack() \ diff --git a/src/GetResource.c b/src/GetResource.c index 7eac3100..8c79b9f3 100644 --- a/src/GetResource.c +++ b/src/GetResource.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. diff --git a/src/ReleaseResource.c b/src/ReleaseResource.c index fe184e15..de97457c 100644 --- a/src/ReleaseResource.c +++ b/src/ReleaseResource.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. diff --git a/src/Schedule.c b/src/Schedule.c index 4ab4f000..40bdd50a 100644 --- a/src/Schedule.c +++ b/src/Schedule.c @@ -85,7 +85,6 @@ extern StatusType Schedule /* \req OSEK_SYS_3.4.4 Possible return values in Standard mode is E_OK */ StatusType ret = E_OK; - TaskType nextTask; TaskType actualTask; @@ -251,3 +250,4 @@ extern StatusType Schedule /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ + diff --git a/src/SetAbsAlarm.c b/src/SetAbsAlarm.c index 005d1b26..67e658a1 100644 --- a/src/SetAbsAlarm.c +++ b/src/SetAbsAlarm.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. diff --git a/src/SetRelAlarm.c b/src/SetRelAlarm.c index c67c3144..776bfa2c 100644 --- a/src/SetRelAlarm.c +++ b/src/SetRelAlarm.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. diff --git a/src/StartOS.c b/src/StartOS.c index f46c20c3..19230de7 100644 --- a/src/StartOS.c +++ b/src/StartOS.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. diff --git a/src/TerminateTask.c b/src/TerminateTask.c index aa837868..f70a74c2 100644 --- a/src/TerminateTask.c +++ b/src/TerminateTask.c @@ -3,6 +3,7 @@ * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * Copyright 2016, Franco Bucafusco + * * All Rights Reserved * * This file is part of CIAA Firmware. diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 321b0217..c0765c7e 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -856,12 +856,16 @@ void MSP430_DisableIRQ(unsigned char irQ_number) /* for a given irq_number it clear the flag that made the handler to be called. +it returns the irq flag, based on the irQ_number +the returned value depends on which peripheral irQ_number belongs. + +For PORTx: the returned value is the port pin (0-7) (not the PxIV register value) */ -void ClearPendingIRQ_Arch(unsigned short irQ_number) +uint16_t GetPendingIRQ_Arch( uint16_t irQ_number ) { - volatile unsigned char dummy; //ignore compiling warning + volatile uint16_t dummy; //ignore compiling warning - switch(irQ_number) + switch( irQ_number ) { #if( MSP430_ENABLE_RTC_HANDLER== 1) #error TODO: NOT IMPLEMENTED @@ -873,11 +877,11 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) case 1 : //=> "PORT2", dummy = P2IV; /* There is no need to clear the flag manually: From MSP430f5529 User manually - " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " - */ + + dummy= (dummy-2)/2; /* with the P2IV we calculate the bit corresponding the source of interrupt.*/ break; #endif @@ -915,8 +919,9 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) " Any access (read or write) of the P1IV register automatically resets the highest pending interrupt flag. If another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt " - */ + + dummy= (dummy-2)/2; /* with the P2IV we calculate the bit corresponding the source of interrupt.*/ break; #endif @@ -971,7 +976,7 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) #if( MSP430_ENABLE_USCI_B0_HANDLER==1 ) case 14: // => "USCI_B0", - + dummy = UCB0IV; break; #endif @@ -1029,6 +1034,8 @@ void ClearPendingIRQ_Arch(unsigned short irQ_number) break; #endif } + + return dummy; } /** @} doxygen end group definition */ /** @} doxygen end group definition */ From 925f1ec1da29cf7b150a3206c12dddd9b4fccf27 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Wed, 9 Nov 2016 01:44:36 -0300 Subject: [PATCH 38/42] - many context change corrections - added debug pins (to remove later) --- inc/Os_Internal.h | 2 +- inc/cortexM0/Os_Internal_Arch.h | 2 +- inc/cortexM4/Os_Internal_Arch.h | 3 +-- inc/msp430/Os_Arch.h | 2 +- inc/msp430/Os_Internal_Arch.h | 33 +++++++++++++++++++++++---------- tst/ctest/src/ctest_em_01.c | 3 +++ 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index fc3f3696..1aac5943 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -201,6 +201,7 @@ ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) \ { \ Schedule_WOChecks(); \ + AfterIsr2_Schedule_Arch(); \ } #else #define AfterIsr2_Schedule() @@ -282,4 +283,3 @@ extern CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncre /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_H_ */ - diff --git a/inc/cortexM0/Os_Internal_Arch.h b/inc/cortexM0/Os_Internal_Arch.h index b87946fe..8cd5a97b 100644 --- a/inc/cortexM0/Os_Internal_Arch.h +++ b/inc/cortexM0/Os_Internal_Arch.h @@ -249,7 +249,7 @@ extern TaskType TerminatingTask; ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) Schedule_WOChecks() +#define PostIsr2_Arch(isr) /** \brief ShutdownOs Arch service ** diff --git a/inc/cortexM4/Os_Internal_Arch.h b/inc/cortexM4/Os_Internal_Arch.h index 8d77a08c..92285696 100644 --- a/inc/cortexM4/Os_Internal_Arch.h +++ b/inc/cortexM4/Os_Internal_Arch.h @@ -247,7 +247,7 @@ extern TaskType TerminatingTask; ** ** This macro is called every time that an ISR Cat 2 is finished **/ -#define PostIsr2_Arch(isr) Schedule_WOChecks() +#define PostIsr2_Arch(isr) /** \brief ShutdownOs Arch service ** @@ -282,4 +282,3 @@ void InitStack_Arch(uint8 TaskID); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ - diff --git a/inc/msp430/Os_Arch.h b/inc/msp430/Os_Arch.h index cd22a693..3e03d675 100644 --- a/inc/msp430/Os_Arch.h +++ b/inc/msp430/Os_Arch.h @@ -68,7 +68,7 @@ ** ** This macro shall resume (enable) all interrupts. **/ -#define ResumeAllInterrupts_Arch() _enable_interrupts() ; +#define ResumeAllInterrupts_Arch() _enable_interrupts(); __asm__ __volatile__ ("nop"); /** \brief Suspend All Interrupts Arch diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 5ce1def4..d5093157 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -60,7 +60,7 @@ ** Enable GIE in SR so that the WDT never stops when we go to user task ** Enable SCG0 for 25MHZ CPU execution **/ -#define DEFAULT_SR ((uint16)0x0048) +#define DEFAULT_SR ((uint16)0x00000048) /** \brief Extra size reserved for each stack ** @@ -101,18 +101,20 @@ extern TaskType TerminatingTask; ** This macro will be used internaly by the OS in any part of code that ** has to be executed atomic. **/ -#define IntSecure_Start() SR_BACK___ = _get_SR_register(); \ - _disable_interrupts() ; \ - __asm__ __volatile__ ("nop"); + +#define IntSecure_Start() SR_BACK___ = _get_SR_register(); \ + _disable_interrupts() ; \ + __asm__ __volatile__ ("nop"); \ /** \brief Interrupt Secure End Macro ** ** This macro is the countra part of IntSecure_Start() **/ -#define IntSecure_End() if( SR_BACK___ & GIE ) \ - { \ - _enable_interrupts() ; \ - } \ +#define IntSecure_End() if( SR_BACK___ & GIE ) \ + { \ + __asm__ __volatile__ ("nop"); \ + _enable_interrupts() ; \ + } \ /** \brief osekpause ** @@ -128,7 +130,7 @@ extern TaskType TerminatingTask; ** **/ -#define osekpause() asm volatile("nop") //TODO revisar los low power modes +#define osekpause() asm volatile("nop") //TODO revisar los low power modes /** \brief SAVE_CONTEXT ** @@ -169,7 +171,18 @@ extern TaskType TerminatingTask; ** ** This macro sholud be inserted before a naked interrupt handler ends. */ -#define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); +#define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); + +/** \brief Some architectures could need an extra processing before calling Schedule from an ISR + ** + ** For MSP430 it checks if the SWI was set during the last Schedule call. + If pending, ISR context and chain with the SWI handler directly (in order to optimice latencies). + **/ +#define AfterIsr2_Schedule_Arch() if( HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) & (CCIFG|CCIE) ) \ + { \ + /* the irq handler falls through OSEK_ISR_CHANGE_CONTEXT */ \ + asm volatile( " br #OSEK_ISR_CHANGE_CONTEXT \n\t" ); \ + } \ /** \brief Call to an other Task ** diff --git a/tst/ctest/src/ctest_em_01.c b/tst/ctest/src/ctest_em_01.c index e8cf3973..305d75a9 100644 --- a/tst/ctest/src/ctest_em_01.c +++ b/tst/ctest/src/ctest_em_01.c @@ -1,9 +1,12 @@ /* Copyright 2008, 2009 Mariano Cerdeiro * Copyright 2014, ACSE & CADIEEL * Copyright 2016, Franco Bucafusco + * * ACSE: http://www.sase.com.ar/asociacion-civil-sistemas-embebidos/ciaa/ * CADIEEL: http://www.cadieel.org.ar * + * All Rights Reserved + * * This file is part of CIAA Firmware. * * Redistribution and use in source and binary forms, with or without From a901debad8b12e2332ad09ba9b0f99094dd08a7c Mon Sep 17 00:00:00 2001 From: FRANCO Date: Wed, 9 Nov 2016 22:49:45 -0300 Subject: [PATCH 39/42] Removed naked attribute from ISR where not needed Added LPM support by osekpause --- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 8 +- inc/Os_Internal.h | 1 - inc/msp430/Os_Internal_Arch.h | 23 +--- src/Os_Internal.c | 14 ++- src/msp430/Os_Internal_Arch.c | 145 ++++++++++++---------- 5 files changed, 96 insertions(+), 95 deletions(-) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 45c427aa..448b6a74 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -155,10 +155,10 @@ if($src_found == 0) { #for an undefined ISR witihn the OIL file, we defiene a DUMMY handler. - print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked)) \n"; + print "interrupt_vec($intList[$i]_VECTOR) /*__attribute__((naked))*/ \n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */ \n"; print "{\n"; - print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile + print " /* RETURN_FROM_NAKED_ISR();*/ /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile print "}\n\n"; } else @@ -166,13 +166,13 @@ if( $intcat == 1 ) { #for an ISR type 1 witihn the OIL file, we defiene a ISR wrapper that calls the ISR defined by the user somewhere. - print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked))\n"; + print "interrupt_vec($intList[$i]_VECTOR) /*__attribute__((naked))*/\n"; print "void OSEK_ISR_$intList[$i]_VECTOR_WRAPPER(void) /*Wrapper function for ISR $intList[$i]_VECTOR (IRQ $i). User should define ISR($intList[$i]_VECTOR) somewhere */ \n"; print "{\n"; print " PreIsr1_Arch($i);\n"; print " OSEK_ISR_$intList[$i]_VECTOR();\n"; print " PostIsr1_Arch($i);\n"; - print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile + print " /* RETURN_FROM_NAKED_ISR();* /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile print "}\n\n"; } } diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index 1aac5943..3a7295bc 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -201,7 +201,6 @@ ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) \ { \ Schedule_WOChecks(); \ - AfterIsr2_Schedule_Arch(); \ } #else #define AfterIsr2_Schedule() diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index d5093157..0c249aa6 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -110,11 +110,11 @@ extern TaskType TerminatingTask; ** ** This macro is the countra part of IntSecure_Start() **/ -#define IntSecure_End() if( SR_BACK___ & GIE ) \ - { \ - __asm__ __volatile__ ("nop"); \ +#define IntSecure_End() if( SR_BACK___ & GIE ) \ + { \ + __asm__ __volatile__ ("nop"); \ _enable_interrupts() ; \ - } \ + } \ /** \brief osekpause ** @@ -129,8 +129,7 @@ extern TaskType TerminatingTask; ** occurs, like for example an interrupt. ** **/ - -#define osekpause() asm volatile("nop") //TODO revisar los low power modes +#define osekpause() __bis_SR_register(LPM3_bits) ; /** \brief SAVE_CONTEXT ** @@ -173,16 +172,7 @@ extern TaskType TerminatingTask; */ #define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); -/** \brief Some architectures could need an extra processing before calling Schedule from an ISR - ** - ** For MSP430 it checks if the SWI was set during the last Schedule call. - If pending, ISR context and chain with the SWI handler directly (in order to optimice latencies). - **/ -#define AfterIsr2_Schedule_Arch() if( HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) & (CCIFG|CCIE) ) \ - { \ - /* the irq handler falls through OSEK_ISR_CHANGE_CONTEXT */ \ - asm volatile( " br #OSEK_ISR_CHANGE_CONTEXT \n\t" ); \ - } \ + \ /** \brief Call to an other Task ** @@ -218,7 +208,6 @@ extern TaskType TerminatingTask; } - /** \brief Save context */ #define SaveContext(task) \ { \ diff --git a/src/Os_Internal.c b/src/Os_Internal.c index 2bc086d2..3c2f048e 100644 --- a/src/Os_Internal.c +++ b/src/Os_Internal.c @@ -209,6 +209,7 @@ AlarmIncrementType IncrementAlarm(AlarmType AlarmID, AlarmIncrementType Incremen AlarmIncrementType AlarmCount; CounterIncrementType CounterIncrement; + /* init arlarms count */ AlarmCount = 0; @@ -227,7 +228,7 @@ AlarmIncrementType IncrementAlarm(AlarmType AlarmID, AlarmIncrementType Incremen expire one or more times */ /* check if new alarm time has to be set */ - if(AlarmsVar[AlarmID].AlarmCycleTime == 0) + if( AlarmsVar[AlarmID].AlarmCycleTime == 0 ) { /* in case of a non cyclic alarm */ @@ -278,12 +279,13 @@ AlarmIncrementType IncrementAlarm(AlarmType AlarmID, AlarmIncrementType Incremen for ( ;AlarmCount > 0; AlarmCount--) { /* check alarm actions differents to INCREMENT */ - switch(AlarmsConst[AlarmID].AlarmAction) + switch( AlarmsConst[AlarmID].AlarmAction ) { case ACTIVATETASK: /* activate task */ ActivateTask(AlarmsConst[AlarmID].AlarmActionInfo.TaskID); break; + case ALARMCALLBACK: /* callback */ if(AlarmsConst[AlarmID].AlarmActionInfo.CallbackFunction != NULL) @@ -319,7 +321,7 @@ CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncrementTyp AlarmIncrementType TmpCount; /* increment counter */ - CountersVar[CounterID].Time+=Increment; + CountersVar[CounterID].Time += Increment; /* check if the timer has an overvlow */ while ( CountersVar[CounterID].Time >= CountersConst[CounterID].MaxAllowedValue ) @@ -328,6 +330,8 @@ CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncrementTyp CountersVar[CounterID].Time -= CountersConst[CounterID].MaxAllowedValue; } +asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OUT xor 0x04; // DEBUG LP + /* for alarms on this counter */ for(loopi = 0; loopi < CountersConst[CounterID].AlarmsCount; loopi++) { @@ -348,9 +352,9 @@ CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncrementTyp } } } - +asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OUT xor 0x04; // DEBUG LP /* return the minimal increment */ - return (CounterIncrementType)MinimalCount; + return (CounterIncrementType) MinimalCount; } #endif /* #if (ALARMS_COUNT != 0) */ diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index c0765c7e..8e433479 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -60,6 +60,7 @@ void * Osek_OldTaskPtr_Arch; TaskType TerminatingTask = INVALID_TASK; TaskType WaitingTask = INVALID_TASK; + /*==================[external data definition]===============================*/ /*==================[internal functions definition]==========================*/ @@ -87,12 +88,12 @@ void CheckTerminatingTask_Arch(void) /* Task Stack Initialization */ void InitStack_Arch(uint8 TaskID) { - uint16 * taskStack = (uint16 *)TasksConst[TaskID].StackPtr; /* stack bottom */ + uint16 * taskStack = (uint16 *)TasksConst[TaskID].StackPtr; /* stack bottom */ - int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ + int taskStackSizeWords = TasksConst[TaskID].StackSize/2; /* calculation of the size of the stack in words units (16bits) */ taskStack[taskStackSizeWords-1] = (uint16) TasksConst[TaskID].EntryPoint; /*PC*/ - taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ + taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ /* la ubicacion, reservando 13 registro para el cambio de contexto */ @@ -100,10 +101,54 @@ void InitStack_Arch(uint8 TaskID) } -void TickProcess() +/* this function does the context change. + */ +interrupt_vec() __attribute__((naked)) +void OSEK_ISR_CHANGE_CONTEXT() +{ + /* Clear the IRQ flag*/ + HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) &= ~(CCIE|CCIFG); + + /* reinicio el stack de la tarea que termino */ + CheckTerminatingTask_Arch(); + + /* exchange stack pointers */ + if( NULL != Osek_OldTaskPtr_Arch ) + { + asm volatile ( "mov &Osek_OldTaskPtr_Arch, r6 \n\t" );//I copy the address of Osek_OldTaskPtr_Arch into r6 + asm volatile ( "mov SP, @r6 \n\t" ); //I save the stack pointer. + } + + asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); + asm volatile ( "mov @r6, SP \n\t" ); + + asm volatile( " bic.b #3, &0X223 \n\t" ); //P4OUT &= ~(0x01|0x02); // DEBUG LP + + __bic_SR_register_on_exit(LPM3_bits); + + asm volatile ( "popm #12, r15 \n\t" ); //simulo unstacking que hicieron los popm de los handlers... + asm volatile ( "reti \n\t" ); +} + + +/** +OSEK periodic interrupt is implemented using TimerA_2 timer module. +*/ +interrupt_vec(TIMER2_A0_VECTOR) //__attribute__((naked)) +void OSEK_ISR_TIMER2_A0_VECTOR(void) { - /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ - Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_0); + /* + It's not necessary to disable global irqs. + It is done automatically when the SP is cleared. + */ + + asm volatile( " bis.b #4, &0x0223 \n\t" //P4OUT |= 0x04; // DEBUG LP + " bis.b #1, &0x0223 \n\t" //P4OUT |= 0x01; // DEBUG LP + /*" pushm #12, r15 ;16-bit words \n\t"*/ //context save + ); + + /* Clear the IRQ flag*/ + HWREG16( TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_0 ) &= ~CCIFG; /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); @@ -113,8 +158,8 @@ void TickProcess() #if (ALARMS_COUNT != 0) /* counter increment */ - static CounterIncrementType CounterIncrement = 1; - (void)CounterIncrement; /* TODO remove me */ + CounterIncrementType CounterIncrement = 1; + //(void)CounterIncrement; /* TODO remove me */ #if 0 /* increment the disable interrupt conter to avoid enable the interrupts. @@ -122,8 +167,10 @@ void TickProcess() IntSecure_Start(); #endif +asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OUT xor 0x04; // DEBUG LP + /* call counter interrupt handler */ - CounterIncrement = IncrementCounter(0, TIC_PERIOD ); + CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */ ); //FIXME #if 0 /* set the disable interrupt counter back. @@ -136,31 +183,16 @@ void TickProcess() /* reset context */ SetActualContext(actualContext); + asm volatile( " bic.b #1, &0X223 \n\t" ); //P4OUT &= ~0x01; // DEBUG LP + AfterIsr2_Schedule(); -} -/** -OSEK periodic interrupt is implemented using TimerA_2 timer module. -*/ -interrupt_vec(TIMER2_A0_VECTOR) __attribute__((naked)) -void OSEK_ISR_TIMER2_A0_VECTOR(void) -{ - /* - It's not necessary to disable global irqs. - It is done automatically when the SP is cleared. - */ - /* This handler service the periodic interrupt. - */ - /* Clear the IRQ flag*/ - TickProcess(); - /* - This handler calls TickProcess because it is defined as naked, and therefore the compiler do not save regiters. - The same happens with the RETI instruction that is inserted in the last macro. - Calling the function, the compiler saves the neede registers. - */ + __bic_SR_register_on_exit(LPM3_bits); - RETURN_FROM_NAKED_ISR(); /*return from Tick ISR */ + /* AfterIsr2_Schedule is a conditional execution that*/ +/* asm volatile ( "popm #12, r15 \n\t" ); //simulo unstacking que hicieron los popm de los hanlders... + asm volatile ( "reti \n\t" );*/ } /** OSEK_ISR_TIMER2_A1_VECTOR @@ -170,49 +202,26 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) ** Note 1: It's not necessary to disable global irqs. ** It is done automatically when the SP is cleared by HW **/ -interrupt_vec(TIMER2_A1_VECTOR) __attribute__((naked)) +interrupt_vec(TIMER2_A1_VECTOR) __attribute__((naked)) void OSEK_ISR_TIMER2_A1_VECTOR(void) { - register unsigned short local_taiv = TA2IV; + asm volatile( " add &TA2IV, PC \n\t" + " reti \n\t" + " jmp OSEK_ISR_TIMER2_A1_VECTOR_REG1 \n\t" + " reti \n\t" + "OSEK_ISR_TIMER2_A1_VECTOR_REG1: \n\t" + " bis.b #2, &0X223 \n\t" //P4OUT |= 0x02; // DEBUG LP + " pushm #12, r15 ;16-bit words \n\t" //context save + " br #OSEK_ISR_CHANGE_CONTEXT \n\t" // the irq handler falls through OSEK_ISR_CHANGE_CONTEXT + ); - if( local_taiv & TA2IV_TACCR1) // - { - /* Clear the IRQ flag*/ - /* TODO this could be improved by accesing directly to the registers. remember that this handlers should be as fast as possible.*/ - Timer_A_disableCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1 ); - Timer_A_clearCaptureCompareInterrupt( TIMER_A2_BASE , TIMER_A_CAPTURECOMPARE_REGISTER_1); - - /* reinicio el stack de la tarea que termino */ - CheckTerminatingTask_Arch(); - - /* Context save r4 to r15 - r0 = PC automatically saved by HW when handler is serviced - r1 = SP - r2 = SR automatically saved by HW when handler is serviced - r3 = CG doesn't care - */ - SAVE_CONTEXT(); - - /* exchange stack pointers */ - if( NULL != Osek_OldTaskPtr_Arch ) - { - asm volatile ( "mov &Osek_OldTaskPtr_Arch, r6 \n\t" ); - asm volatile ( "mov SP, @r6 \n\t" ); - } - asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); - asm volatile ( "mov @r6, SP \n\t" ); - - /* - Context restore r4 to r15 - It does not Include the reti instruction. - */ - RESTORE_CONTEXT() - } - - RETURN_FROM_NAKED_ISR(); /*return from ISR*/ + /* + TI MSP430 EABI says that the Irq Handlers should save ALL the regiters after an IRQ call. + GCC inserts automatically 1 pushm (or many push) to save from r15 to r4. + THAT behavior is used as context save action. + */ } - /* MSP430 hasn't a way of dissabling "all the vector" at once, without touching the individual sub IE flags. From 6722c25d8274694d7e6317a5717f700888ade3c5 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Sun, 13 Nov 2016 15:04:50 -0300 Subject: [PATCH 40/42] - remove debug lines - some LPM corrections --- gen/src/msp430/Os_Internal_Arch_Cfg.c.php | 4 +-- inc/Os_Internal.h | 5 ++-- inc/cortexM0/Os_Internal_Arch.h | 9 ++++++ inc/cortexM4/Os_Internal_Arch.h | 10 +++++++ inc/mips/Os_Internal_Arch.h | 9 ++++++ inc/msp430/Os_Internal_Arch.h | 15 ++++++++-- .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 2 -- src/Os_Internal.c | 4 +-- src/Schedule.c | 2 -- src/msp430/Os_Internal_Arch.c | 30 ++++++++----------- src/msp430/StartOs_Arch.c | 2 +- 11 files changed, 61 insertions(+), 31 deletions(-) diff --git a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php index 448b6a74..a6a8bd0e 100644 --- a/gen/src/msp430/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -155,10 +155,10 @@ if($src_found == 0) { #for an undefined ISR witihn the OIL file, we defiene a DUMMY handler. - print "interrupt_vec($intList[$i]_VECTOR) /*__attribute__((naked))*/ \n"; + print "interrupt_vec($intList[$i]_VECTOR) __attribute__((naked)) \n"; print "void OSEK_ISR_$intList[$i]_VECTOR(void) /*No Handler set for ISR $intList[$i]_VECTOR (IRQ $i) */ \n"; print "{\n"; - print " /* RETURN_FROM_NAKED_ISR();*/ /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile + print " RETURN_FROM_NAKED_ISR(); /*return from ISR*/\n"; #this includes the RETI intruction. Is inserted here becase the naked attribute removes it when compile print "}\n\n"; } else diff --git a/inc/Os_Internal.h b/inc/Os_Internal.h index 3a7295bc..3bc185ef 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -201,9 +201,10 @@ ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) \ { \ Schedule_WOChecks(); \ - } + } \ + AfterIsr2_Schedule_Arch(); #else -#define AfterIsr2_Schedule() +#define AfterIsr2_Schedule() AfterIsr2_Schedule_Arch(); #endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */ /*==================[typedef]================================================*/ diff --git a/inc/cortexM0/Os_Internal_Arch.h b/inc/cortexM0/Os_Internal_Arch.h index 8cd5a97b..77e63555 100644 --- a/inc/cortexM0/Os_Internal_Arch.h +++ b/inc/cortexM0/Os_Internal_Arch.h @@ -95,6 +95,14 @@ extern TaskType TerminatingTask; **/ #define IntSecure_End() ResumeAllInterrupts() +/* +** \brief AfterIsr2_Schedule_Arch + ** + ** Some architectures need to execute a forced action when returning from ISR handler. + ** +*/ +#define AfterIsr2_Schedule_Arch() + /** \brief osekpause ** ** This macro is called by the scheduler when not task has to be executed. @@ -271,3 +279,4 @@ void InitStack_Arch(uint8 TaskID); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ + diff --git a/inc/cortexM4/Os_Internal_Arch.h b/inc/cortexM4/Os_Internal_Arch.h index 92285696..5ee72c24 100644 --- a/inc/cortexM4/Os_Internal_Arch.h +++ b/inc/cortexM4/Os_Internal_Arch.h @@ -95,6 +95,15 @@ extern TaskType TerminatingTask; **/ #define IntSecure_End() ResumeAllInterrupts() +/* +** \brief AfterIsr2_Schedule_Arch + ** + ** Some architectures need to execute a forced action when returning from ISR handler. + ** +*/ +#define AfterIsr2_Schedule_Arch() + + /** \brief osekpause ** ** This macro is called by the scheduler when not task has to be executed. @@ -282,3 +291,4 @@ void InitStack_Arch(uint8 TaskID); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ + diff --git a/inc/mips/Os_Internal_Arch.h b/inc/mips/Os_Internal_Arch.h index 8f76489a..46239bfb 100644 --- a/inc/mips/Os_Internal_Arch.h +++ b/inc/mips/Os_Internal_Arch.h @@ -72,6 +72,15 @@ **/ #define IntSecure_End() ResumeAllInterrupts() + +/* +** \brief AfterIsr2_Schedule_Arch + ** + ** Some architectures need to execute a forced action when returning from ISR handler. + ** +*/ +#define AfterIsr2_Schedule_Arch() + /** \brief osekpause ** ** This macro is called by the scheduler when not task has to be executed. diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index 0c249aa6..b1505372 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -104,7 +104,8 @@ extern TaskType TerminatingTask; #define IntSecure_Start() SR_BACK___ = _get_SR_register(); \ _disable_interrupts() ; \ - __asm__ __volatile__ ("nop"); \ + __asm__ __volatile__ ("nop"); + /** \brief Interrupt Secure End Macro ** @@ -116,6 +117,16 @@ extern TaskType TerminatingTask; _enable_interrupts() ; \ } \ + +/* +** \brief AfterIsr2_Schedule_Arch + ** + ** Some architectures need to execute a forced action when returning from ISR handler. + ** +*/ +#define AfterIsr2_Schedule_Arch() __bic_SR_register_on_exit( LPM3_bits ); + + /** \brief osekpause ** ** This macro is called by the scheduler when not task has to be executed. @@ -172,7 +183,7 @@ extern TaskType TerminatingTask; */ #define RETURN_FROM_NAKED_ISR() asm volatile ("reti \n\t"); - \ + /** \brief Call to an other Task ** diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index f0ef2744..c49650bf 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -48,8 +48,6 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ - - /*==================[cpu macros]=============================================*/ #define WORKING_FREQUENCY_MHZ 14.7456f// 7.3728 // // in MHZ diff --git a/src/Os_Internal.c b/src/Os_Internal.c index 3c2f048e..f15fd80f 100644 --- a/src/Os_Internal.c +++ b/src/Os_Internal.c @@ -330,7 +330,7 @@ CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncrementTyp CountersVar[CounterID].Time -= CountersConst[CounterID].MaxAllowedValue; } -asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OUT xor 0x04; // DEBUG LP + /* for alarms on this counter */ for(loopi = 0; loopi < CountersConst[CounterID].AlarmsCount; loopi++) @@ -352,7 +352,7 @@ asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OU } } } -asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OUT xor 0x04; // DEBUG LP + /* return the minimal increment */ return (CounterIncrementType) MinimalCount; } diff --git a/src/Schedule.c b/src/Schedule.c index 40bdd50a..c5c5b049 100644 --- a/src/Schedule.c +++ b/src/Schedule.c @@ -183,7 +183,6 @@ extern StatusType Schedule ** the priority of the calling task is ready */ if ( TasksConst[nextTask].StaticPriority > TasksVar[actualTask].ActualPriority ) { - #if (HOOK_POSTTASKHOOK == OSEK_ENABLE) PostTaskHook(); #endif /* #if (HOOK_POSTTASKHOOK == OSEK_ENABLE) */ @@ -250,4 +249,3 @@ extern StatusType Schedule /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index 8e433479..df3504cb 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -122,7 +122,6 @@ void OSEK_ISR_CHANGE_CONTEXT() asm volatile ( "mov &Osek_NewTaskPtr_Arch, r6 \n\t" ); asm volatile ( "mov @r6, SP \n\t" ); - asm volatile( " bic.b #3, &0X223 \n\t" ); //P4OUT &= ~(0x01|0x02); // DEBUG LP __bic_SR_register_on_exit(LPM3_bits); @@ -141,11 +140,10 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) It's not necessary to disable global irqs. It is done automatically when the SP is cleared. */ - - asm volatile( " bis.b #4, &0x0223 \n\t" //P4OUT |= 0x04; // DEBUG LP - " bis.b #1, &0x0223 \n\t" //P4OUT |= 0x01; // DEBUG LP - /*" pushm #12, r15 ;16-bit words \n\t"*/ //context save - ); +/* + asm volatile( + " pushm #12, r15 ;16-bit words \n\t" //context save + );*/ /* Clear the IRQ flag*/ HWREG16( TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_0 ) &= ~CCIFG; @@ -167,8 +165,6 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) IntSecure_Start(); #endif -asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OUT xor 0x04; // DEBUG LP - /* call counter interrupt handler */ CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */ ); //FIXME @@ -183,16 +179,15 @@ asm volatile( " xor.b #4, &0x0223 \n\t"); //P4OU /* reset context */ SetActualContext(actualContext); - asm volatile( " bic.b #1, &0X223 \n\t" ); //P4OUT &= ~0x01; // DEBUG LP - - AfterIsr2_Schedule(); + AfterIsr2_Schedule(); - - __bic_SR_register_on_exit(LPM3_bits); - - /* AfterIsr2_Schedule is a conditional execution that*/ -/* asm volatile ( "popm #12, r15 \n\t" ); //simulo unstacking que hicieron los popm de los hanlders... - asm volatile ( "reti \n\t" );*/ + /* if during alarms update status, any alarm triggered its action, ActivateTask or SetEvent could have called to Schedule + so, in that case, we need to unlock the CPU in the return of the handler, by exiting the LPM. */ + /*if( ( CONTEXT_TASK == actualContext ) && + ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) + { + AfterIsr2_Schedule_Arch(); + }*/ } /** OSEK_ISR_TIMER2_A1_VECTOR @@ -210,7 +205,6 @@ void OSEK_ISR_TIMER2_A1_VECTOR(void) " jmp OSEK_ISR_TIMER2_A1_VECTOR_REG1 \n\t" " reti \n\t" "OSEK_ISR_TIMER2_A1_VECTOR_REG1: \n\t" - " bis.b #2, &0X223 \n\t" //P4OUT |= 0x02; // DEBUG LP " pushm #12, r15 ;16-bit words \n\t" //context save " br #OSEK_ISR_CHANGE_CONTEXT \n\t" // the irq handler falls through OSEK_ISR_CHANGE_CONTEXT ); diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c index 3fd12c2d..f34a3776 100644 --- a/src/msp430/StartOs_Arch.c +++ b/src/msp430/StartOs_Arch.c @@ -75,7 +75,7 @@ void StartOs_Arch_Cpu(void) { StartOs_Arch_System(); //TODO: this should be placed in other file. For cortex processors is placed within the reset vector handler. StartOs_Arch_SystemTick(); - //Enable_User_ISRs(); //USER ISRs SHOULD BE ENABLED BY THE USER USING a_MSP430ware Libraries or OS buildin Drivers. + //Enable_User_ISRs(); //USER ISRs SHOULD BE ENABLED BY THE USER USING MSP430ware Libraries or OS buildin Drivers. } /** From 40cbef87ae870271fc93bcf675634725f9d68796 Mon Sep 17 00:00:00 2001 From: FRANCO Date: Wed, 16 Nov 2016 08:07:13 -0300 Subject: [PATCH 41/42] - comments - os isrs handlers rename --- src/msp430/Os_Internal_Arch.c | 58 +++++++++++----------------- src/msp430/StartOs_Arch_SystemTick.c | 10 ++--- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/msp430/Os_Internal_Arch.c b/src/msp430/Os_Internal_Arch.c index df3504cb..082ee779 100644 --- a/src/msp430/Os_Internal_Arch.c +++ b/src/msp430/Os_Internal_Arch.c @@ -95,21 +95,21 @@ void InitStack_Arch(uint8 TaskID) taskStack[taskStackSizeWords-1] = (uint16) TasksConst[TaskID].EntryPoint; /*PC*/ taskStack[taskStackSizeWords-2] = DEFAULT_SR; /*SP*/ - /* la ubicacion, reservando 13 registro para el cambio de contexto + /* + reserve space for context change. */ *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 14]); } -/* this function does the context change. - */ -interrupt_vec() __attribute__((naked)) +/* this function does the context change */ +interrupt_vec() __attribute__((naked)) //this line cheats the compiler to think that this is an actual ISR, in order to use __bic_SR_register_on_exit intrinsic void OSEK_ISR_CHANGE_CONTEXT() { /* Clear the IRQ flag*/ HWREG16(TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_1) &= ~(CCIE|CCIFG); - /* reinicio el stack de la tarea que termino */ + /* restart the stack for the terminating task */ CheckTerminatingTask_Arch(); /* exchange stack pointers */ @@ -125,7 +125,7 @@ void OSEK_ISR_CHANGE_CONTEXT() __bic_SR_register_on_exit(LPM3_bits); - asm volatile ( "popm #12, r15 \n\t" ); //simulo unstacking que hicieron los popm de los handlers... + asm volatile ( "popm #12, r15 \n\t" ); //restore context asm volatile ( "reti \n\t" ); } @@ -134,18 +134,14 @@ void OSEK_ISR_CHANGE_CONTEXT() OSEK periodic interrupt is implemented using TimerA_2 timer module. */ interrupt_vec(TIMER2_A0_VECTOR) //__attribute__((naked)) -void OSEK_ISR_TIMER2_A0_VECTOR(void) +void OSEK_ISR_TICK_HANDLER(void) { /* It's not necessary to disable global irqs. It is done automatically when the SP is cleared. */ -/* - asm volatile( - " pushm #12, r15 ;16-bit words \n\t" //context save - );*/ - /* Clear the IRQ flag*/ + /* Clear the IRQ flag */ HWREG16( TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_0 ) &= ~CCIFG; /* store the calling context in a variable */ @@ -162,6 +158,9 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) #if 0 /* increment the disable interrupt conter to avoid enable the interrupts. Disabled because MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS */ + /* + OSEK is prepared to nest ISR. That is not implemented for MSP430. If implemented in the future, this commented block needs to be active. + */ IntSecure_Start(); #endif @@ -171,6 +170,9 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) #if 0 /* set the disable interrupt counter back. Disabled because MSP430 AUTOMATICALLY DISABLES GLOBAL IRQ AT IRQ HANDLERS */ + /* + OSEK is prepared to nest ISR. That is not implemented for MSP430. If implemented in the future, this commented block needs to be active. + */ IntSecure_End(); #endif @@ -179,15 +181,7 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) /* reset context */ SetActualContext(actualContext); - AfterIsr2_Schedule(); - - /* if during alarms update status, any alarm triggered its action, ActivateTask or SetEvent could have called to Schedule - so, in that case, we need to unlock the CPU in the return of the handler, by exiting the LPM. */ - /*if( ( CONTEXT_TASK == actualContext ) && - ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) ) - { - AfterIsr2_Schedule_Arch(); - }*/ + AfterIsr2_Schedule(); } /** OSEK_ISR_TIMER2_A1_VECTOR @@ -198,22 +192,16 @@ void OSEK_ISR_TIMER2_A0_VECTOR(void) ** It is done automatically when the SP is cleared by HW **/ interrupt_vec(TIMER2_A1_VECTOR) __attribute__((naked)) -void OSEK_ISR_TIMER2_A1_VECTOR(void) +void OSEK_ISR_CC_HANDLER(void) { asm volatile( " add &TA2IV, PC \n\t" " reti \n\t" - " jmp OSEK_ISR_TIMER2_A1_VECTOR_REG1 \n\t" + " jmp CC_Interrupt_REG1 \n\t" " reti \n\t" - "OSEK_ISR_TIMER2_A1_VECTOR_REG1: \n\t" - " pushm #12, r15 ;16-bit words \n\t" //context save + "CC_Interrupt_REG1: \n\t" + " pushm #12, r15 ;16-bit words \n\t" //context save " br #OSEK_ISR_CHANGE_CONTEXT \n\t" // the irq handler falls through OSEK_ISR_CHANGE_CONTEXT ); - - /* - TI MSP430 EABI says that the Irq Handlers should save ALL the regiters after an IRQ call. - GCC inserts automatically 1 pushm (or many push) to save from r15 to r4. - THAT behavior is used as context save action. - */ } /* @@ -222,14 +210,14 @@ individual sub IE flags. So, when dissable the IRQ handler the system must backup the current available IRQ flags, from all the possible regiters, to be restored later in the EnableIRQ. */ -#if( MSP430_ENABLE_RTC_HANDLER== 1) -unsigned char rtcctl0_bck = 0; -unsigned char rtcps0ctl_bck = 0; //the RTCPS0CTL is 16bit wide, but the IRQ flags are in the lower byte +#if( MSP430_ENABLE_RTC_HANDLER == 1) +unsigned char rtcctl0_bck = 0; +unsigned char rtcps0ctl_bck = 0; //the RTCPS0CTL is 16bit wide, but the IRQ flags are in the lower byte unsigned char rtcps1ctl_bck = 0; //the RTCPS1CTL is 16bit wide, but the IRQ flags are in the lower byte #endif #if( MSP430_ENABLE_PORT2_HANDLER== 1) -unsigned char p2ie_bck = 0; +unsigned char p2ie_bck = 0; #endif #if( MSP430_ENABLE_PORT1_HANDLER==1 ) diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c index a2cc1b30..bf624885 100644 --- a/src/msp430/StartOs_Arch_SystemTick.c +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -108,8 +108,6 @@ MCLK = SMCLK = 14.7456Mhz */ void StartOs_Arch_System() { - - UCS_turnOffXT1(); XT1_XT2_PORT_SEL |= XT1_ENABLE + XT2_ENABLE; // Setup XT1 and XT2 @@ -123,10 +121,8 @@ void StartOs_Arch_System() UCS_initFLLSettle( WORKING_FREQUENCY_KHZ, ( WORKING_FREQUENCY_HZ/REF_FREQUENCY_HZ ) ); /* - ESTA LINEAS SON PARA ESTABLECER LA CONFIGURACION DEL MODULO PMM PARA QUE ESTE EN FULL PERFORMACN Y FAST WAKE UP MODE. - SI NO ESTA CONFIGURADO ASI, AL DESPERTARSE DE UN LPM, EL ARRANQUE DEL DCO NO ES AGIL Y PARA EL CASO DE LA RECEPCION DE LA - UART Y SE PIERDE EL PRIMER uint8_t DE DATOS. - ESTO ES, PORQUE EL TIEMPO DE ENCENDIDO ES MAYOR QUE UN BIT DE LA COMUNICACION. + These lines set PMM module in FULL PERFORMANCE and FASTWAKE UP. + In case this is not set, DCO statup is slower than an UART Start bit, and when receiving in LPM , the 1st byte will fail. */ PMM_enableSvsLInLPMFastWake(); // SVSL_ENABLED_IN_LPM_FAST_WAKE(); PMM_enableSvsHInLPMFullPerf(); // SVSH_ENABLED_IN_LPM_FULL_PERF() ; @@ -136,7 +132,7 @@ void StartOs_Arch_System() SVMH_FULL_PERF(); - PMM_disableSvsL();// DISABLE_SVSL() ; + PMM_disableSvsL(); // DISABLE_SVSL() ; } void StartOs_Arch_SystemTick(void) From 7335436aa79665d302e2d9f6f043a4b11065ccbd Mon Sep 17 00:00:00 2001 From: FRANCO Date: Thu, 17 Nov 2016 15:06:44 -0300 Subject: [PATCH 42/42] - change the default sr fo allow fll to be enabled - change the working frequency to 25MHz --- inc/msp430/Os_Internal_Arch.h | 3 +-- .../msp430f5x_6x/Os_Internal_Arch_Cpu.h | 2 +- src/msp430/StartOs_Arch_SystemTick.c | 27 +++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/inc/msp430/Os_Internal_Arch.h b/inc/msp430/Os_Internal_Arch.h index b1505372..cfb3a0b8 100644 --- a/inc/msp430/Os_Internal_Arch.h +++ b/inc/msp430/Os_Internal_Arch.h @@ -58,9 +58,8 @@ /** \brief Default Value for Status Register ** ** Enable GIE in SR so that the WDT never stops when we go to user task - ** Enable SCG0 for 25MHZ CPU execution **/ -#define DEFAULT_SR ((uint16)0x00000048) +#define DEFAULT_SR ((uint16) 0x00000008) /** \brief Extra size reserved for each stack ** diff --git a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h index c49650bf..402fa4dc 100644 --- a/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -50,7 +50,7 @@ /*==================[cpu macros]=============================================*/ -#define WORKING_FREQUENCY_MHZ 14.7456f// 7.3728 // // in MHZ +#define WORKING_FREQUENCY_MHZ 25.0f// 7.3728 // // in MHZ #define REF_FREQUENCY_HZ 32768 // in Hz #define TIC_PERIOD 5 // in ms diff --git a/src/msp430/StartOs_Arch_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c index bf624885..23e51ed7 100644 --- a/src/msp430/StartOs_Arch_SystemTick.c +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -56,7 +56,7 @@ /*==================[macros and definitions]=================================*/ -#define SVMH_FULL_PERF() PMMCTL0_H = 0xA5; SVSMLCTL |= (SVMLFP); PMMCTL0_H = 0x00; +#define SVMH_FULL_PERF() PMMCTL0_H = 0xA5; SVSMLCTL |= (SVMLFP); PMMCTL0_H = 0x00; #define WORKING_FREQUENCY_KHZ (unsigned long)(WORKING_FREQUENCY_MHZ*1e3) // en KHZ #define WORKING_FREQUENCY_HZ (unsigned long)(WORKING_FREQUENCY_MHZ*1e6) // en Hz @@ -110,11 +110,15 @@ void StartOs_Arch_System() { UCS_turnOffXT1(); - XT1_XT2_PORT_SEL |= XT1_ENABLE + XT2_ENABLE; // Setup XT1 and XT2 + XT1_XT2_PORT_SEL |= XT1_ENABLE ; //+ XT2_ENABLE; // Setup XT1 and XT2 /* enable xt2 for usb operation*/ - PMM_setVCore( 3 ); // Set Vcore to accomodate for max. allowed system speed + PMM_setVCore( PMM_CORE_LEVEL_3 ); // Set Vcore to accomodate for max. allowed system speed - UCS_turnOnLFXT1( UCS_XT1_DRIVE_0 , UCS_XCAP_1 ); // Use 32.768kHz XTAL as reference + UCS_initClockSignal( UCS_ACLK , UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 ); /* ACLK FROM 32768HZ */ + UCS_turnOnLFXT1( UCS_XT1_DRIVE_0 , UCS_XCAP_0 ); /* Use 32.768kHz XTAL as reference */ + + UCS_initClockSignal( UCS_MCLK , UCS_DCOCLK_SELECT , UCS_CLOCK_DIVIDER_1 ); /* ACLK FROM 32768HZ */ + UCS_initClockSignal( UCS_SMCLK , UCS_DCOCLK_SELECT , UCS_CLOCK_DIVIDER_1 ); /* ACLK FROM 32768HZ */ UCS_initClockSignal( UCS_FLLREF , UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 ); @@ -125,16 +129,23 @@ void StartOs_Arch_System() In case this is not set, DCO statup is slower than an UART Start bit, and when receiving in LPM , the 1st byte will fail. */ PMM_enableSvsLInLPMFastWake(); // SVSL_ENABLED_IN_LPM_FAST_WAKE(); - PMM_enableSvsHInLPMFullPerf(); // SVSH_ENABLED_IN_LPM_FULL_PERF() ; + PMM_enableSvsHInLPMFullPerf(); // SVSH_ENABLED_IN_LPM_FULL_PERF(); - PMM_optimizeSvsLInLPMFastWake(); // SVSL_OPTIMIZED_IN_LPM_FAST_WAKE(); - PMM_optimizeSvsHInLPMFullPerf(); // SVSH_OPTIMIZED_IN_LPM_FULL_PERF(); + PMM_optimizeSvsLInLPMFastWake(); // SVSL_OPTIMIZED_IN_LPM_FAST_WAKE(); + PMM_optimizeSvsHInLPMFullPerf(); // SVSH_OPTIMIZED_IN_LPM_FULL_PERF(); SVMH_FULL_PERF(); - PMM_disableSvsL(); // DISABLE_SVSL() ; + PMM_disableSvsL(); // DISABLE_SVSL() ; + + //DEBUG LP + /*P7DIR|=0X80; //mclk + P7SEL|=0X80; //mclk + P2DIR|=0X04; //smclk //tecla s2! + P2SEL|=0X04; //smclk //tecla s2!*/ } + void StartOs_Arch_SystemTick(void) { /* Activate SystemTick */