diff --git a/gen/ginc/Platform.php b/gen/ginc/Platform.php new file mode 100644 index 00000000..b6cefac4 --- /dev/null +++ b/gen/ginc/Platform.php @@ -0,0 +1,87 @@ +definitions["ARCH"]== "msp430") + { + return 16; + } + else + { + return 32; + } + } + + function getInterruptHandlerList() + { + require("modules/rtos/gen/ginc/".$this->definitions["ARCH"]."/Os_Internal_Defs.php"); + return $intList; + } +} +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +?> diff --git a/gen/ginc/cortexM0/Os_Internal_Defs.php b/gen/ginc/cortexM0/Os_Internal_Defs.php new file mode 100644 index 00000000..f307ccaf --- /dev/null +++ b/gen/ginc/cortexM0/Os_Internal_Defs.php @@ -0,0 +1,103 @@ +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..987e4756 --- /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 new file mode 100644 index 00000000..410890a8 --- /dev/null +++ b/gen/ginc/msp430/Os_Internal_Defs.php @@ -0,0 +1,93 @@ +definitions["CPU"] ) +{ + case "msp430f5529": + /* Interrupt sources for msp430f5529 + * See externals/drivers/msp430/inc/msp430f5529.h. + * Names in this array are set without the trailing "_VECTOR" string + */ + $intList = array ( + 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 " . $this->definitions["CPU"] . " is not supported."); + break; +} + + +?> diff --git a/gen/ginc/x86/Os_Internal_Defs.php b/gen/ginc/x86/Os_Internal_Defs.php new file mode 100644 index 00000000..90332d96 --- /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 f546f2c0..db1cb896 100644 --- a/gen/inc/Os_Cfg.h.php +++ b/gen/inc/Os_Cfg.h.php @@ -6,6 +6,9 @@ * 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. * @@ -62,6 +65,7 @@ /** \addtogroup FreeOSEK_Os_Global ** @{ */ + /*==================[inclusions]=============================================*/ /*==================[macros]=================================================*/ @@ -71,32 +75,33 @@ #define OSEK_OS_INTERRUPT_MASK ((InterruptFlagsType)0xFFFFFFFFU) 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 */ -/* Definitions of Tasks */ $tasks = $this->helper->multicore->getLocalList("/OSEK", "TASK"); $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"; -if (count($remote_tasks) > 0) +$count = count( $tasks ); + +/* Definitions of Tasks : Tasks that will be executed within the remote core*/ +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 */ @@ -104,55 +109,188 @@ 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(); + + +$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 = $this->config->getList("/OSEK","EVENT"); -foreach ($events as $count=>$event) +$nro_evs= count($events); + +/* task/events matrix creation, and various validations */ +foreach( $tasks as $task_index => $task ) { - print "/** \brief Definition of the Event $event */\n"; - print "#define " . $event . " 0x" . sprintf ("%xU", (1<<$count)) . "\n"; + $empty_array = array(); + $temp_array = $this->config->getList("/OSEK/". $task , "EVENT" ); + + /*for each task we get the defined events*/ + array_push( $matriz , $temp_array ); + array_push( $matrix_n , $empty_array ); + + $nro_ev_task = count($matriz[$task_index]); #max(array_keys($matriz[$task_index])); + + /* Task Type validation: validates that this task is extended */ + $extended = $this->config->getValue("/OSEK/" . $task, "TYPE"); + + if ($extended != "EXTENDED" && $nro_ev_task>0 ) + { + trigger_error("===== OIL ERROR: The task $task should be TYPE: EXTENDED =====\n", E_USER_ERROR); + } + else + { + if ($nro_ev_task == 0 && $extended != "BASIC") + { + 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 !== false ) + { + trigger_error("===== OIL ERROR: The event $evi for task $task is not globally defined =====\n", E_USER_ERROR); + /* stops execution */ + } + else + { + } + } +} + + +/* generation of the shared events between tasks */ +print "\n/** \brief Shared events across tasks */\n\n"; + +$ev_index = 0; +foreach( $events as $ev ) //para cada evento, lo busco en cada array de eventos para la tarea +{ + $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_index => $task ) + { + $key = array_search( $ev, $matriz[$task_index] ); + + if( $key !== false ) //busco el evento en el array de eventos de la tarea. + { + /* lo encontro */ + $count++; + } + } + + + if( $count>1 ) + { + /* there is more that one task with the current event */ + $flags_shared_event--; + + 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 "\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 */ + foreach( $tasks as $task_index => $task ) + { + $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 ); + } + } + + $ev_index++; +} + +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 */ + + 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 "\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; + array_push( $matrix_n[$task_index] , $temp ); + + $flags_exc_event++; + } +} + +/* Last validation: check if events repeats */ +$task_index = 0; +foreach ($matrix_n as $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) + { + if($value>1) + { + throw new Exception("===== OIL ERROR: There are more events that the task can handle. =====\n"); + /* stops execution */ + } + } + $task_index ++; } -print "\n"; /* Define the Resources */ $resources = $this->config->getList("/OSEK","RESOURCE"); 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 @@ -173,7 +311,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"; @@ -189,7 +327,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 @@ -224,6 +364,7 @@ if ($errorhook == "TRUE") { ?> + /** \brief Error Api Variable ** ** This variable contents the api which generate the last error @@ -267,51 +408,52 @@ $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"); +//print_r($intnames); + 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"); @@ -320,13 +462,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 @@ -348,10 +490,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 */ @@ -359,4 +504,3 @@ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_CFG_H_ */ - diff --git a/gen/inc/Os_Internal_Cfg.h.php b/gen/inc/Os_Internal_Cfg.h.php index 78dfa93d..e75cef95 100644 --- a/gen/inc/Os_Internal_Cfg.h.php +++ b/gen/inc/Os_Internal_Cfg.h.php @@ -6,6 +6,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. * @@ -130,21 +132,27 @@ function remove_doubles($a) /* Define the Resources */ $resources = $this->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"; + } } $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" ) @@ -288,7 +296,10 @@ function remove_doubles($a) } helper->multicore->getLocalList("/OSEK", "ALARM"); +$alarms_count = count($alarms); + $count = 0; foreach ($alarms as $alarm) { @@ -298,8 +309,8 @@ function remove_doubles($a) } } ?> -#define ALARM_AUTOSTART_COUNT +#define ALARM_AUTOSTART_COUNT helper->multicore->getLocalList("/OSEK", "COUNTER"); @@ -311,7 +322,7 @@ function remove_doubles($a) $alarms = $this->helper->multicore->getLocalList("/OSEK", "ALARM"); print "/** \brief ALARMS_COUNT define */\n"; -print "#define ALARMS_COUNT " . count($alarms) . "\n\n"; +print "#define ALARMS_COUNT " . $alarms_count . "\n\n"; $preemptive = false; foreach($tasks as $task) @@ -337,11 +348,11 @@ function remove_doubles($a) print "/** \brief NO_EVENTS macro definition */\n"; if(count($events) == 0) { - print "#define NO_EVENTS OSEK_ENABLE\n\n"; + print "#define NO_EVENTS OSEK_ENABLE\n\n"; } else { - print "#define NO_EVENTS OSEK_DISABLE\n\n"; + print "#define NO_EVENTS OSEK_DISABLE\n\n"; } $schedulerpolicy = $this->config->getValue("/OSEK/" . $os[0],"USERESSCHEDULER"); @@ -359,8 +370,6 @@ function remove_doubles($a) print "#define NO_RES_SCHEDULER OSEK_ENABLE\n\n"; break; } - - ?> /*==================[typedef]================================================*/ @@ -596,14 +605,22 @@ function remove_doubles($a) } } +print("\n"); + $appmodes = $this->config->getList("/OSEK","APPMODE"); print "/** \brief AutoStart Array */\n"; print "extern const AutoStartType AutoStart[" . count($appmodes) . "];\n\n"; /* Resources Priorities */ $resources = $this->config->getList("/OSEK","RESOURCE"); -print "/** \brief Resources Priorities */\n"; -print "extern const TaskPriorityType ResourcesPriority[" . count($resources) . "];\n\n"; +$resources_count = count($resources); +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/inc/msp430/Os_Internal_Arch_Cfg.h.php b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php new file mode 100644 index 00000000..1368722a --- /dev/null +++ b/gen/inc/msp430/Os_Internal_Arch_Cfg.h.php @@ -0,0 +1,106 @@ +/******************************************************** + * 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_ + + +/** \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 + ** @{ */ + + +/*==================[inclusions]=============================================*/ + + +/*==================[typedef]================================================*/ + +/** \brief Task Context Type */ +typedef uint16 * TaskContextType; + +/** \brief Task Context Type */ +typedef TaskContextType* TaskContextRefType; + +/*==================[external data declaration]==============================*/ + +loadHelper("modules/rtos/gen/ginc/Multicore.php"); +$this->loadHelper("modules/rtos/gen/ginc/Platform.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) +{ + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); + + print "#define MSP430_ENABLE_". $source . "_HANDLER 1 \n"; +} +?> + +/*==================[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/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 774439c6..4ba61c03 100644 --- a/gen/src/Os_Internal_Cfg.c.php +++ b/gen/src/Os_Internal_Cfg.c.php @@ -6,6 +6,9 @@ * 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. * @@ -63,34 +66,46 @@ 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"); 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"; - print "uint8 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ."];\n"; + 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 . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ."/2];\n"; + } + else + { + print "uint8 StackTask" . $task . "[" . $this->config->getValue("/OSEK/" . $task, "STACK") ."];\n"; + } + print "#endif\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"; $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) { @@ -99,7 +114,7 @@ $count += $this->config->getValue("/OSEK/" . $task, "ACTIVATION"); } } - print "TaskType ReadyList" . $prio . "[" . $count . "];\n\n"; + print "TaskType ReadyList" . $prio . "[" . $count . "];\n"; } $counters = $this->helper->multicore->getLocalList("/OSEK", "COUNTER"); @@ -108,6 +123,7 @@ foreach ($counters as $counter) { $countalarms = 0; + foreach ($alarms as $alarm) { if ($counter == $this->config->getValue("/OSEK/" . $alarm,"COUNTER")) @@ -115,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")) @@ -123,9 +142,9 @@ print " $alarm, /* this alarm has to be incremented with this counter */\n"; } } + print "};\n\n"; } - ?> /*==================[external data definition]===============================*/ @@ -156,7 +175,7 @@ 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[$this->config->getValue("/OSEK/" . $task, "PRIORITY")] . ", /* task priority */\n"; print " " . $this->config->getValue("/OSEK/" . $task, "ACTIVATION"). ", /* task max activations */\n"; @@ -212,24 +231,39 @@ print " 0 /* core */\n"; } print " }"; + print "\n"; } print "\n"; ?> }; -/** \brief RemoteTaskCore Array */ -const TaskCoreType RemoteTasksCore[REMOTE_TASKS_COUNT] = {helper->multicore->getRemoteList("/OSEK", "TASK"); -for($i=0; $i0 ) { - print $this->config->getValue("/OSEK/$rtasks[$i]", "CORE"); - if ($i < (count($rtasks)-1)) + print("\n/** \brief RemoteTaskCore Array */\n"); + print("const TaskCoreType RemoteTasksCore[REMOTE_TASKS_COUNT] = {\n"); + + for($i=0; $i<$rtasks_count; $i++) { - print ", "; + print $this->config->getValue("/OSEK/$rtasks[$i]", "CORE"); + if ($i < (count($rtasks)-1)) + { + print ", "; + } } + + print("};\n"); +} +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); } ?> -}; + /** \brief TaskVar Array */ TaskVariableType TasksVar[TASKS_COUNT]; @@ -285,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"; } @@ -327,141 +361,175 @@ config->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 = $this->config->getList("/OSEK/" . $task, "RESOURCE"); - foreach($resorucestask as $rt) + $count = 0; + foreach ($tasks as $task) { - if ($rt == $resource) + $resorucestask = $this->config->getList("/OSEK/" . $task, "RESOURCE"); + foreach($resorucestask as $rt) { - if ($priority[$this->config->getValue("/OSEK/" . $task, "PRIORITY")] > $count) + if ($rt == $resource) { + if ($priority[$this->config->getValue("/OSEK/" . $task, "PRIORITY")] > $count) + { $count = $priority[$this->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_USER_NOTICE); } -print "\n};\n"; $alarms = $this->helper->multicore->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_" . $this->config->getValue("/OSEK/" . $alarm, "COUNTER") . ", /* Counter */\n"; - $action = $this->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_" . $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 " 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 " 0 /* no counter */\n"; - break; - case "ALARMCALLBACK": - 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"; - 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 ($this->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 " " . $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"; + if ($this->config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + { + $alarms_autostart++; + } + print " {\n"; + 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) + { + case "INCREMENT": + 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"; + break; + case "ACTIVATETASK": + print " NULL, /* no callback */\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 " 0 /* no counter */\n"; + break; + case "ALARMCALLBACK": + 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"; + break; + default: + $this->log->error("Alarm $alarm has an invalid action: $action"); + break; + } + print " },\n"; print " }"; + + } + print "\n};\n\n"; + + #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 ($this->config->getValue("/OSEK/" . $alarm, "AUTOSTART") == "TRUE") + { + if ($first == false) + { + print ",\n"; + } + else + { + $first = false; + } + print " {\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 " }"; + } + } + print "\n};\n\n"; + } + else + { + print "\n/* OIL FILE: THERE ARE NO AUTOSTART ALARMS DEFINED IN THE SYSTEM */\n\n"; } -} -print "\n};\n\n"; $counters = $this->helper->multicore->getLocalList("/OSEK", "COUNTER"); -print "CounterVarType CountersVar[" . count($counters) . "];\n\n"; + print "CounterVarType CountersVar[" . count($counters) . "];\n\n"; $alarms = $this->config->getList("/OSEK","ALARM"); -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) + print "const CounterConstType CountersConst[" . count($counters) . "] = {\n"; + foreach ($counters as $count=>$counter) { - if ($counter == $this->config->getValue("/OSEK/" . $alarm,"COUNTER")) + if ($count!=0) { - $countalarms++; + print ",\n"; } + print " {\n"; + $countalarms = 0; + foreach ($alarms as $alarm) + { + if ($counter == $this->config->getValue("/OSEK/" . $alarm,"COUNTER")) + { + $countalarms++; + } + } + 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 " }"; } - 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 " }"; + 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_USER_NOTICE); } -print "\n};\n\n"; - ?> /** TODO replace the next line with @@ -476,22 +544,52 @@ */ 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 */ +{ +#for each ISR define in the OIL, we define the IRQ handler. foreach ($intnames as $int) { $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) - {?> -void OSEK_ISR2_(void) + { + if($this->definitions["ARCH"] == "msp430") + { + print "interrupt_vec(".$inttype."_VECTOR) \n"; + //print "interrupt_vec($int) \n"; + } +?> +void OSEK_ISR2_(void) { + + /* store the calling context in a variable */ ContextType actualContext = GetCallingContext(); + /* set isr 2 context */ SetActualContext(CONTEXT_ISR2); @@ -501,24 +599,20 @@ /* 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_ENABLE) */ -} - - + AfterIsr2_Schedule() ; } + + /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php index d78900ab..3a89961a 100644 --- a/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/cortexM0/Os_Internal_Arch_Cfg.c.php @@ -5,6 +5,7 @@ /* Copyright 2014, 2015 Mariano Cerdeiro * Copyright 2014, 2015 Pablo Ridolfi * Copyright 2015, Alejandro Permingeat + * * All rights reserved. * * This file is part of CIAA Firmware. @@ -123,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; @@ -294,8 +253,17 @@ 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/cortexM4/Os_Internal_Arch_Cfg.c.php b/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php index bbee2086..84ffe2c5 100644 --- a/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php +++ b/gen/src/cortexM4/Os_Internal_Arch_Cfg.c.php @@ -50,6 +50,15 @@ /** \addtogroup FreeOSEK_Os_Internal ** @{ */ +/* + * modification history (new versions first) + * ----------------------------------------------------------- + * v0.1.4 20150307 MaCe rework port for CIAA-FLS + * v0.1.3 20150303 Apermingeat added K60_120 interrupt sources + * v0.1.2 20141130 PR Added ISR cat. 2 enabling and disabling functions. + * v0.1.1 20141115 PR added LPC43xx interrupt sources, spelling mistake fixed + * v0.1.0 20141115 MaCe initial version + */ /*==================[inclusions]=============================================*/ #include "Os_Internal.h" #if (CPU == lpc43xx) @@ -128,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 new file mode 100644 index 00000000..a6a8bd0e --- /dev/null +++ b/gen/src/msp430/Os_Internal_Arch_Cfg.c.php @@ -0,0 +1,268 @@ +/******************************************************** + * 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 + ** @{ */ + + +/*==================[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]===============================*/ + + +/*==================[internal functions definition]==========================*/ + + +interrupt_vec(UNMI_VECTOR) __attribute__((naked)) /*No Handler set for ISR UNMI_VECTOR (IRQ 20) */ +void OSEK_ISR_UNMI_VECTOR(void) +{ + while (1) + { + } +} + + +interrupt_vec(SYSNMI_VECTOR) __attribute__((naked)) /*No Handler set for ISR SYSNMI_VECTOR (IRQ 21) */ +void OSEK_ISR_SYSNMI_VECTOR(void) +{ + while (1) + { + } +} + +/*==================[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(); + +$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++) +{ + $src_found = 0; + $intcat = 0 ; + + foreach($intnames as $int) + { + /* + handlers that are present in the system (defined in the oil file) + do not add extra code here. + */ + $intcat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); + $source = $this->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"); + } + + break; #the irq was found, break the inner loop + } + } + + 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 + */ + $intcat = 0 ; + $src_found = 1; + } + + 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 "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"; + } + 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 "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 "}\n\n"; + } + } +} +?> + +/** \brief Interrupt enabling and priority setting function */ +void Enable_User_ISRs(void) +{ +helper->multicore->getLocalList("/OSEK", "ISR"); + +foreach ($intnames as $int) +{ + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + //$prio = $config->getValue("/OSEK/" . $int,"PRIORITY"); + + $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); + } +} +?> +} + + +/** \brief Enable user defined category 2 ISRs */ +void Enable_ISR2_Arch(void) +{ +helper->multicore->getLocalList("/OSEK", "ISR"); +foreach ($intnames as $int) +{ + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); + + if($cat == 2) + { + $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); + } + } +} +?> +} + +/** \brief Disable user defined category 2 ISRs */ +void Disable_ISR2_Arch(void) +{ +helper->multicore->getLocalList("/OSEK", "ISR"); +foreach ($intnames as $int) +{ + $source = $this->config->getValue("/OSEK/" . $int,"INTERRUPT"); + $cat = $this->config->getValue("/OSEK/" . $int,"CATEGORY"); + + if($cat == 2) + { + $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); + } + } +} +?> +} + +/** @} 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 0b2571b7..3bc185ef 100644 --- a/inc/Os_Internal.h +++ b/inc/Os_Internal.h @@ -2,6 +2,9 @@ * 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. * @@ -53,12 +56,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" @@ -182,9 +187,26 @@ #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 + +/** \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(); \ + } \ + AfterIsr2_Schedule_Arch(); +#else +#define AfterIsr2_Schedule() AfterIsr2_Schedule_Arch(); +#endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */ + /*==================[typedef]================================================*/ /** \brief ContextType ** @@ -261,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 fa92db68..77e63555 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 @@ -87,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. @@ -241,7 +257,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 ** @@ -263,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 76cb9c4a..5ee72c24 100644 --- a/inc/cortexM4/Os_Internal_Arch.h +++ b/inc/cortexM4/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 @@ -87,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. @@ -239,7 +256,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/mips/Os_Internal_Arch.h b/inc/mips/Os_Internal_Arch.h index 91a5591d..46239bfb 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 ** @@ -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_Arch.h b/inc/msp430/Os_Arch.h new file mode 100644 index 00000000..3e03d675 --- /dev/null +++ b/inc/msp430/Os_Arch.h @@ -0,0 +1,107 @@ +/* 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_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 + ** @{ */ + +/*==================[inclusions]=============================================*/ + +#include "Os_Internal_Arch_Cfg.h" + +/*==================[macros]=================================================*/ + +/** \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() _enable_interrupts(); __asm__ __volatile__ ("nop"); + + +/** \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 + ** 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 + ** 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]================================================*/ + +/*==================[external data declaration]==============================*/ + +/*==================[external functions declaration]=========================*/ + +/** @} 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..cfb3a0b8 --- /dev/null +++ b/inc/msp430/Os_Internal_Arch.h @@ -0,0 +1,348 @@ +/* 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_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 + ** @{ */ + + +/*==================[inclusions]=============================================*/ +#include "msp430.h" +#include "driverlib.h" + +/*==================[macros]=================================================*/ + +/** \brief Default Value for Status Register + ** + ** Enable GIE in SR so that the WDT never stops when we go to user task + **/ +#define DEFAULT_SR ((uint16) 0x00000008) + +/** \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 needed + ** remove the macro and this comment. + **/ +#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() unsigned short SR_BACK___; + + +/** \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() 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 ) \ + { \ + __asm__ __volatile__ ("nop"); \ + _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. + ** 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() __bis_SR_register(LPM3_bits) ; + +/** \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"\ + ); + +/** \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); \ +} + +/** \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); \ +} + + +/** \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() _enable_interrupts(); + +/** \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). + ** NOTE: the nop operation after the dint instruction was inserted + ** to workarround the hw bug cpu39 described in slaz314h.pdf + **/ +#define DisableOSInterrupts() _disable_interrupts(); __asm__ __volatile__ ("nop"); + +/** \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 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) GetPendingIRQ_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 ISR2 Macro + ** + ** This macro is called every time that an ISR Cat 2 is finished + **/ +#define PostIsr2_Arch(isr) GetPendingIRQ_Arch(isr) + +/** \brief ShutdownOs Arch service + ** + ** This macro is called on the ShutdownOS to perform the architecture + ** dependent shutdown actions. + **/ +#define ShutdownOs_Arch() + +/*==================[typedef]================================================*/ + +/*==================[external data declaration]==============================*/ + +/*==================[external functions declaration]=========================*/ +void InitStack_Arch(uint8 TaskID); +uint16_t GetPendingIRQ_Arch( uint16_t irQ_number ); +void MSP430_EnableIRQ(unsigned char irQ_number); +void MSP430_DisableIRQ(unsigned char irQ_number); + +/** @} 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_SystemTick.h b/inc/msp430/StartOs_Arch_SystemTick.h new file mode 100644 index 00000000..2d42b50a --- /dev/null +++ b/inc/msp430/StartOs_Arch_SystemTick.h @@ -0,0 +1,68 @@ +/* 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_System(); +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/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..402fa4dc --- /dev/null +++ b/inc/msp430/msp430f5x_6x/Os_Internal_Arch_Cpu.h @@ -0,0 +1,77 @@ +/* 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_CPU_H_ +#define _OS_INTERNAL_ARCH_CPU_H_ + +/** \brief FreeOSEK Internal Architecture Cpu Dependent Header File + ** + ** \file msp430/msp430f5xx_6xx/Os_Internal_Arch_Cpu.h + ** \arch msp430/msp430f5xx_6xx + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/*==================[cpu macros]=============================================*/ + +#define WORKING_FREQUENCY_MHZ 25.0f// 7.3728 // // in MHZ +#define REF_FREQUENCY_HZ 32768 // in Hz +#define TIC_PERIOD 5 // in ms + +/*==================[inclusions]=============================================*/ + + +/*==================[macros]=================================================*/ + + + +/*==================[typedef]================================================*/ + + +/*==================[external data declaration]==============================*/ + + +/*==================[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/inc/x86/Os_Internal_Arch.h b/inc/x86/Os_Internal_Arch.h index a56ea7d9..80fefa49 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 @@ -408,4 +418,3 @@ extern void OSEK_ISR_HWTimer1(void); /** @} doxygen end group definition */ /*==================[end of file]============================================*/ #endif /* #ifndef _OS_INTERNAL_ARCH_H_ */ - diff --git a/src/ActivateTask.c b/src/ActivateTask.c index 63f95afb..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. * @@ -64,10 +66,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,6 +81,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) { @@ -214,4 +218,3 @@ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/src/ChainTask.c b/src/ChainTask.c index 19127386..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. * @@ -75,6 +77,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..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. * @@ -76,6 +78,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..8c79b9f3 100644 --- a/src/GetResource.c +++ b/src/GetResource.c @@ -2,7 +2,9 @@ * 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. * @@ -79,6 +81,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/Os_Internal.c b/src/Os_Internal.c index 0a0212dd..f15fd80f 100644 --- a/src/Os_Internal.c +++ b/src/Os_Internal.c @@ -115,9 +115,9 @@ void RemoveTask /* get task priority */ priority = TasksConst[TaskID].StaticPriority; - /* conver the priority to the array index */ + /* convert the priority to the array index */ /* do not remove the -1 is needed. for example if READYLIST_COUNT is 4 - * the valida entries for this array are between 0 and 3, so the -1 is needed + * the valid entries for this array are between 0 and 3, so the -1 is needed * since the lower priority is 0. */ priority = (READYLISTS_COUNT-1)-priority; @@ -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; } + + /* for alarms on this counter */ for(loopi = 0; loopi < CountersConst[CounterID].AlarmsCount; loopi++) { @@ -350,7 +354,7 @@ CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncrementTyp } /* return the minimal increment */ - return (CounterIncrementType)MinimalCount; + return (CounterIncrementType) MinimalCount; } #endif /* #if (ALARMS_COUNT != 0) */ @@ -358,4 +362,3 @@ CounterIncrementType IncrementCounter(CounterType CounterID, CounterIncrementTyp /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/src/ReleaseResource.c b/src/ReleaseResource.c index 96d04999..de97457c 100644 --- a/src/ReleaseResource.c +++ b/src/ReleaseResource.c @@ -2,7 +2,9 @@ * 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. * @@ -80,6 +82,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 7b01dc6a..c5c5b049 100644 --- a/src/Schedule.c +++ b/src/Schedule.c @@ -2,6 +2,9 @@ * 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. * @@ -81,12 +84,16 @@ 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 */ @@ -133,8 +140,8 @@ extern StatusType Schedule nextTask = GetNextTask(); /* while until one or boths are not more invalid tasks */ - while ( ( actualTask == INVALID_TASK ) && - ( nextTask == INVALID_TASK) ) + while ( ( INVALID_TASK == actualTask ) && + ( INVALID_TASK == nextTask ) ) { IntSecure_End(); @@ -148,7 +155,7 @@ extern StatusType Schedule }; /* if the actual task is invalid */ - if ( actualTask == INVALID_TASK ) + if ( INVALID_TASK == actualTask ) { /* set task state to running */ TasksVar[nextTask].Flags.State = TASK_ST_RUNNING; @@ -176,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) */ @@ -243,4 +249,3 @@ 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 3d50b173..67e658a1 100644 --- a/src/SetAbsAlarm.c +++ b/src/SetAbsAlarm.c @@ -2,6 +2,9 @@ * 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. * @@ -80,6 +83,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..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. * @@ -77,6 +79,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..776bfa2c 100644 --- a/src/SetRelAlarm.c +++ b/src/SetRelAlarm.c @@ -2,6 +2,9 @@ * 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. * @@ -79,6 +82,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..19230de7 100644 --- a/src/StartOS.c +++ b/src/StartOS.c @@ -2,6 +2,9 @@ * 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. * @@ -76,6 +79,8 @@ void StartOS ** system */ uint8f loopi; + IntSecure_Common(); + IntSecure_Start(); #if (OSEK_MULTICORE == OSEK_ENABLE) @@ -112,6 +117,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) @@ -119,6 +125,7 @@ void StartOS (void)SetRelAlarm(AutoStartAlarm[loopi].Alarm, AutoStartAlarm[loopi].AlarmTime, AutoStartAlarm[loopi].AlarmCycleTime); } } +#endif #if (HOOK_STARTUPHOOK == OSEK_ENABLE) StartupHook(); diff --git a/src/TerminateTask.c b/src/TerminateTask.c index b929389d..f70a74c2 100644 --- a/src/TerminateTask.c +++ b/src/TerminateTask.c @@ -2,6 +2,9 @@ * 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. * @@ -74,6 +77,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. */ @@ -179,3 +184,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 d5d0438e..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. * @@ -78,6 +80,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_Arch.c b/src/msp430/Os_Arch.c new file mode 100644 index 00000000..3609c190 --- /dev/null +++ b/src/msp430/Os_Arch.c @@ -0,0 +1,68 @@ +/* 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 Arch Implementation File + ** + ** \file msp430/Os_Arch.c + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Global + ** @{ */ + + +/*==================[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..082ee779 --- /dev/null +++ b/src/msp430/Os_Internal_Arch.c @@ -0,0 +1,1034 @@ +/* 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 Internal Arch Implementation File + ** + ** \file msp430/Os_Internal_Arch.c + ** \arch msp430 + **/ + +/** \addtogroup FreeOSEK + ** @{ */ +/** \addtogroup FreeOSEK_Os + ** @{ */ +/** \addtogroup FreeOSEK_Os_Internal + ** @{ */ + +/*==================[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( 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 */ + + 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*/ + + /* + reserve space for context change. + */ + *(TasksConst[TaskID].TaskContext) = &(taskStack[taskStackSizeWords - 14]); +} + + +/* 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); + + /* restart the stack for the terminating task */ + 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" ); + + + __bic_SR_register_on_exit(LPM3_bits); + + asm volatile ( "popm #12, r15 \n\t" ); //restore context + 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_TICK_HANDLER(void) +{ + /* + It's not necessary to disable global irqs. + It is done automatically when the SP is cleared. + */ + + /* Clear the IRQ flag */ + HWREG16( TIMER_A2_BASE + TIMER_A_CAPTURECOMPARE_REGISTER_0 ) &= ~CCIFG; + + /* store the calling context in a variable */ + ContextType actualContext = GetCallingContext(); + + /* set isr 2 context */ + SetActualContext(CONTEXT_ISR2); + +#if (ALARMS_COUNT != 0) + /* counter increment */ + CounterIncrementType CounterIncrement = 1; + //(void)CounterIncrement; /* TODO remove me */ + +#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 + + /* call counter interrupt handler */ + CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */ ); //FIXME + +#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 + +#endif /* #if (ALARMS_COUNT != 0) */ + + /* reset context */ + SetActualContext(actualContext); + + AfterIsr2_Schedule(); +} + +/** OSEK_ISR_TIMER2_A1_VECTOR + ** The Pendable Service Call is implementad by using and nonused Timer Channel (1) + ** Is is triggered by setting the IE and IFG lines within the same line in CallTask + ** and JmpTask. + ** 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)) +void OSEK_ISR_CC_HANDLER(void) +{ + asm volatile( " add &TA2IV, PC \n\t" + " reti \n\t" + " jmp CC_Interrupt_REG1 \n\t" + " reti \n\t" + "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 + ); +} + +/* +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 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 + +#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) ); + 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; +#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) ); + UCA0CTL1 |= ( uca0ctl1_bck & (UCRXEIE|UCBRKIE) ); + 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 +} + + +/* +for a given irq_number it disables all the interrupts related to that irq vector. +it backups the actual state of the enabled signals for that vector (enabled by the user application) +*/ +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; + uca1ctl1_bck = UCA1CTL1; + + //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; + + //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; + uca0ctl1_bck = UCA0CTL1; + + //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; +#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; + } +} + +/* +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) +*/ +uint16_t GetPendingIRQ_Arch( uint16_t irQ_number ) +{ + volatile uint16_t dummy; //ignore compiling warning + + switch( irQ_number ) + { +#if( MSP430_ENABLE_RTC_HANDLER== 1) +#error TODO: NOT IMPLEMENTED + 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 + " 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 + +#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 ) + 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 + + " 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 + +#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", + dummy = UCB0IV; + break; +#endif + +#if( MSP430_ENABLE_USCI_A0_HANDLER==1 ) + case 15: // => "USCI_A0", + dummy = UCA0IV; + 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 + } + + return dummy; +} +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ diff --git a/src/msp430/StartOs_Arch.c b/src/msp430/StartOs_Arch.c new file mode 100644 index 00000000..f34a3776 --- /dev/null +++ b/src/msp430/StartOs_Arch.c @@ -0,0 +1,100 @@ +/* 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 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 + ** @{ */ + +/*==================[inclusions]=============================================*/ +#include "Os_Internal.h" +#include "StartOs_Arch_SystemTick.h" + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/*==================[internal data definition]===============================*/ + +/*==================[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]==========================*/ + +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 MSP430ware Libraries or OS buildin Drivers. +} + +/** + */ +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_SystemTick.c b/src/msp430/StartOs_Arch_SystemTick.c new file mode 100644 index 00000000..23e51ed7 --- /dev/null +++ b/src/msp430/StartOs_Arch_SystemTick.c @@ -0,0 +1,161 @@ +/* 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 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 + ** @{ */ + + +/*==================[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]==========================*/ + +/* +Initializes the main system clock +ACLK = REF_FREQUENCY_HZ +MCLK = SMCLK = 14.7456Mhz +*/ +void StartOs_Arch_System() +{ + UCS_turnOffXT1(); + + XT1_XT2_PORT_SEL |= XT1_ENABLE ; //+ XT2_ENABLE; // Setup XT1 and XT2 /* enable xt2 for usb operation*/ + + PMM_setVCore( PMM_CORE_LEVEL_3 ); // Set Vcore to accomodate for max. allowed system speed + + 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 ); + + UCS_initFLLSettle( WORKING_FREQUENCY_KHZ, ( WORKING_FREQUENCY_HZ/REF_FREQUENCY_HZ ) ); + + /* + 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(); + + PMM_optimizeSvsLInLPMFastWake(); // SVSL_OPTIMIZED_IN_LPM_FAST_WAKE(); + PMM_optimizeSvsHInLPMFullPerf(); // SVSH_OPTIMIZED_IN_LPM_FULL_PERF(); + + SVMH_FULL_PERF(); + + 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 */ + 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 ); +} + +/** @} 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 44506788..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. # @@ -239,7 +241,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); } @@ -321,6 +326,8 @@ sub EvaluateResults return $status; } +#TODO remove debug franco + sub readparam { open CFG, "<@_[0]" or die "Config file @_[0] can not be opened: $!"; @@ -344,7 +351,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; @@ -385,6 +398,50 @@ sub halt finish(); } + + +#** \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 +{ + my $myfile = shift; + + #initialize the variable. + @replace = ""; + + push @replace, "VN_ISR1:" . $ISR1."_VECTOR"; + push @replace, "VN_ISR2:" . $ISR2."_VECTOR"; + push @replace, "VN_ISR3:" . $ISR3."_VECTOR"; + + foreach $rep (@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 +# +# +#* +sub Extra_MakeFile_AddOns_Arch +{ + if ("msp430" eq $ARCH) + { + if ("msp430f5x_6x" eq $CPUTYPE) + { + if ("msp430f5529" eq $CPU) + { + #for msp430 architecture the heap_mem_size can't be as high as for cortex. + print FILE "CFLAGS += -D CIAA_HEAP_MEM_SIZE=200"; + } + } + } +} + #** \brief Creates a Project for a test # # \param[in] test test to be generated @@ -397,6 +454,7 @@ sub CreateTestProject my $config = shift; my $base = "out/rtos/$test/$config"; info("Creating Test: $test - Config: $config under $base/$test/$config"); + # create needed directories `mkdir -p $base/etc`; `mkdir -p $base/src`; @@ -404,23 +462,33 @@ sub CreateTestProject `mkdir -p $base/inc`; `mkdir -p $base/inc/$ARCH`; `mkdir -p $base/src/$ARCH`; + # get configuration file for this project $org = "modules/rtos/tst/ctest/etc/" . $test . ".oil"; $dst = "$base/etc/$test-$config.oil"; copy($org, $dst) or die "file can not be copied from $org to $dst: $!"; + # 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 + + # TODO this shall be improved. Definitely. Doing this for another platform was a headache + # CT stand for : ?? + # VN stands for : "Vector Name" push @replace, "CT_ISR1:" . $ISR1; push @replace, "CT_ISR2:" . $ISR2; + push @replace, "VN_ISR1:" . $ISR1."_VECTOR"; #replace vector name + push @replace, "VN_ISR2:" . $ISR2."_VECTOR"; #replace vector name + foreach $rep (@replace) { info("Replacing: $rep"); @rep = split (/:/,$rep); searchandreplace($dst,@rep[0],@rep[1]); } + # create makefile for this project open FILE, "> $base/mak/Makefile" or die "can not open: $!"; print FILE "PROJECT_NAME = $test-$config\n\n"; @@ -440,13 +508,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 @@ -519,6 +595,7 @@ sub logffull #Example: 'full-preemptive' or empty $subtestcase = $ARGV[3]; + #Example: 'ctest_tm_01:Test Sequence 1' or empty $onlytc = $ARGV[2]; @@ -528,11 +605,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"; @@ -544,6 +624,19 @@ sub logffull $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: $!"; mkpath(dirname($logfilefull)); @@ -606,8 +699,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"); @@ -616,7 +712,7 @@ sub logffull foreach $config (@configs) { - $config =~ tr/\r\n//d; + $config =~ tr/\r\n//d; $runthistestcase = 1; $testcasecount++; @@ -679,11 +775,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 @@ -696,31 +795,59 @@ 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")) { $out = $BINDIR . "/" . $test . "-" . $config . ".axf"; } + elsif ( $ARCH eq "msp430") + { + $out = $BINDIR . "/" . $test . "-" . $config . ".out"; + } 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 ("msp430" eq $ARCH) + { + $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"); + + $debug_command = "$PROXY -C $newdbgfile exit"; + + info("$debug_command"); + } + else + { + $debug_command = "$GDB $out -x $dbgfile"; + + info("$debug_command"); + } + if($debug == 0) { - $outdbg = `$GDB $out -x $dbgfile`; + $outdbg = `$debug_command`; + if ($ARCH eq "x86") { # if it fails, then capture ASSERT message with the condition, File and Line that failed and print it! @@ -732,17 +859,30 @@ sub logffull print("ERROR, $Str_Assert\n"); } } - } + } else { + print("=== Modo Debug Del Script de Perl === \n"); exec("$GDB $out"); $outdbg = ""; } + $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) { results("******************************************************"); diff --git a/tst/ctest/dbg/msp430/gcc/debug.scr b/tst/ctest/dbg/msp430/gcc/debug.scr new file mode 100644 index 00000000..7711cd81 --- /dev/null +++ b/tst/ctest/dbg/msp430/gcc/debug.scr @@ -0,0 +1,9 @@ +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 diff --git a/tst/ctest/etc/ctest_em_01.oil b/tst/ctest/etc/ctest_em_01.oil index d5934fdf..e0fb7597 100644 --- a/tst/ctest/etc/ctest_em_01.oil +++ b/tst/ctest/etc/ctest_em_01.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2560; + STACK = 256; TYPE = BASIC; }; @@ -27,13 +27,13 @@ TASK Task2 { SCHEDULE = CT_SCHEDULING_TASK2; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = EXTENDED; RESOURCE = Resource1; EVENT = Event1; } -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; diff --git a/tst/ctest/etc/ctest_ip_01.oil b/tst/ctest/etc/ctest_ip_01.oil index 6cbdc6ab..5580071f 100644 --- a/tst/ctest/etc/ctest_ip_01.oil +++ b/tst/ctest/etc/ctest_ip_01.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2048; + STACK = 256; TYPE = BASIC; }; @@ -27,17 +27,17 @@ TASK Task2 { SCHEDULE = CT_SCHEDULING_TASK2; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; TYPE = BASIC; } -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; } -ISR ISR1 { +ISR VN_ISR1 { CATEGORY = 1; INTERRUPT = CT_ISR1; PRIORITY = 0; diff --git a/tst/ctest/etc/ctest_ip_03.oil b/tst/ctest/etc/ctest_ip_03.oil index 76763947..534c28a7 100644 --- a/tst/ctest/etc/ctest_ip_03.oil +++ b/tst/ctest/etc/ctest_ip_03.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2048; + STACK = 256; TYPE = BASIC; }; @@ -27,7 +27,7 @@ TASK Task2 { SCHEDULE = NON; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; TYPE = BASIC; } @@ -36,7 +36,7 @@ TASK Task3 { SCHEDULE = NON; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; TYPE = BASIC; } @@ -45,11 +45,11 @@ TASK Task4 { SCHEDULE = CT_SCHEDULING_TASK; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; TYPE = BASIC; } -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; diff --git a/tst/ctest/etc/ctest_ip_04.oil b/tst/ctest/etc/ctest_ip_04.oil index 04872857..90e6075b 100644 --- a/tst/ctest/etc/ctest_ip_04.oil +++ b/tst/ctest/etc/ctest_ip_04.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2048; + STACK = 256; TYPE = BASIC; }; @@ -27,7 +27,7 @@ TASK Task2 { SCHEDULE = FULL; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; TYPE = BASIC; } @@ -36,11 +36,11 @@ TASK Task3 { SCHEDULE = CT_SCHEDULING_TASK; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; TYPE = BASIC; } -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; diff --git a/tst/ctest/etc/ctest_rm_01.oil b/tst/ctest/etc/ctest_rm_01.oil index 5ca2a170..f2cd2b22 100644 --- a/tst/ctest/etc/ctest_rm_01.oil +++ b/tst/ctest/etc/ctest_rm_01.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2560; + STACK = 256; TYPE = BASIC; RESOURCE = Resource1; RESOURCE = Resource2; @@ -33,12 +33,12 @@ TASK Task2 { SCHEDULE = CT_SCHEDULING_TASK2; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = BASIC; RESOURCE = ResourceA; } -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; diff --git a/tst/ctest/etc/ctest_rm_02.oil b/tst/ctest/etc/ctest_rm_02.oil index e336ba52..4b118163 100644 --- a/tst/ctest/etc/ctest_rm_02.oil +++ b/tst/ctest/etc/ctest_rm_02.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2560; + STACK = 256; TYPE = BASIC; RESOURCE = Resource1; }; @@ -28,7 +28,7 @@ TASK Task2 { SCHEDULE = NON; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = BASIC; RESOURCE = Resource1; }; @@ -38,7 +38,7 @@ TASK Task3 { SCHEDULE = NON; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = BASIC; }; @@ -47,7 +47,7 @@ TASK Task4 { SCHEDULE = CT_SCHEDULING; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = BASIC; }; diff --git a/tst/ctest/etc/ctest_rm_05.oil b/tst/ctest/etc/ctest_rm_05.oil index b08c9044..171f4c00 100644 --- a/tst/ctest/etc/ctest_rm_05.oil +++ b/tst/ctest/etc/ctest_rm_05.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2560; + STACK = 256; TYPE = BASIC; }; @@ -27,11 +27,11 @@ TASK Task2 { SCHEDULE = CT_SCHEDULING_TASK2; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2560; + STACK = 256; TYPE = BASIC; }; -ISR ISR2 { +ISR VN_ISR2 { CATEGORY = 2; INTERRUPT = CT_ISR2; PRIORITY = 0; diff --git a/tst/ctest/etc/ctest_tm_01.oil b/tst/ctest/etc/ctest_tm_01.oil index 2cd162b8..bc924e51 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/etc/itest_ip_01.oil b/tst/ctest/etc/itest_ip_01.oil index 125ce6e1..d7221d0f 100644 --- a/tst/ctest/etc/itest_ip_01.oil +++ b/tst/ctest/etc/itest_ip_01.oil @@ -18,7 +18,7 @@ TASK Task1 { AUTOSTART = TRUE { APPMODE = AppMode1; }; - STACK = 2048; + STACK = 256; TYPE = BASIC; RESOURCE = Res1; }; @@ -28,11 +28,11 @@ TASK Task2 { SCHEDULE = CT_SCHEDULING_TASK; ACTIVATION = 1; AUTOSTART = FALSE; - STACK = 2048; + STACK = 256; 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..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. * @@ -235,14 +237,28 @@ ** 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 ** @@ -387,7 +403,7 @@ void ConfTestEvaluation } \ } #endif -#if ((cortexM4 == ARCH) || (cortexM0 == ARCH)) +#if ((cortexM4 == ARCH) || (cortexM0 == ARCH) || (msp430 == ARCH) ) #define ASSERT(tc,cond) \ { \ if (cond) \ @@ -405,6 +421,8 @@ void ConfTestEvaluation } #endif + + extern void Sequence ( uint32f seq diff --git a/tst/ctest/inc/msp430/ctest_arch.h b/tst/ctest/inc/msp430/ctest_arch.h new file mode 100644 index 00000000..c06e9b4f --- /dev/null +++ b/tst/ctest/inc/msp430/ctest_arch.h @@ -0,0 +1,77 @@ +/* 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); + + +extern void EnableISR2_Arch(void); + +extern void EnableISR1_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..4e7da3d8 --- /dev/null +++ b/tst/ctest/mak/msp430/msp430f5x_6x/msp430f5529/Makefile @@ -0,0 +1,38 @@ +############################################################################### +# +# 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. +# +############################################################################### +# + +#for testes we add a precompiler definition to alter some macros +#CFLAGS += -DCTESTS_MODIFIERS diff --git a/tst/ctest/src/ctest_em_01.c b/tst/ctest/src/ctest_em_01.c index e769db33..305d75a9 100644 --- a/tst/ctest/src/ctest_em_01.c +++ b/tst/ctest/src/ctest_em_01.c @@ -1,8 +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 @@ -73,6 +77,8 @@ int main void ) { + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -198,7 +204,7 @@ TASK(Task2) ConfTestFinish(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; @@ -220,7 +226,7 @@ ISR(ISR2) } #if ( ISR_CATEGORY_3 == OSEK_ENABLE ) -ISR(ISR3) +ISR(VN_ISR3) { StatusType ret; @@ -238,4 +244,3 @@ ISR(ISR3) /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/tst/ctest/src/ctest_ip_01.c b/tst/ctest/src/ctest_ip_01.c index 9e7757ff..45d6aa3d 100644 --- a/tst/ctest/src/ctest_ip_01.c +++ b/tst/ctest/src/ctest_ip_01.c @@ -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. * @@ -74,6 +76,9 @@ int main void ) { + EnableISR1(); + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -147,7 +152,7 @@ TASK(Task1) ConfTestFinish(); } -ISR(ISR1) +ISR(VN_ISR1) { static uint8 ISR1_Trigger_Number = 0; @@ -170,7 +175,7 @@ ISR(ISR1) } } -ISR(ISR2) +ISR(VN_ISR2) { static uint8 ISR2_Trigger_Number = 0; diff --git a/tst/ctest/src/ctest_ip_03.c b/tst/ctest/src/ctest_ip_03.c index 8a345783..b1f9e3c0 100644 --- a/tst/ctest/src/ctest_ip_03.c +++ b/tst/ctest/src/ctest_ip_03.c @@ -1,4 +1,6 @@ /* Copyright 2014, Mariano Cerdeiro + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -70,6 +72,10 @@ int main void ) { + EnableISR1(); + EnableISR2(); + + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -115,7 +121,7 @@ TASK(Task3) TerminateTask(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; diff --git a/tst/ctest/src/ctest_ip_04.c b/tst/ctest/src/ctest_ip_04.c index d4c99862..65c086bc 100644 --- a/tst/ctest/src/ctest_ip_04.c +++ b/tst/ctest/src/ctest_ip_04.c @@ -1,4 +1,6 @@ /* Copyright 2014, Mariano Cerdeiro + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -70,6 +72,10 @@ int main void ) { + EnableISR1(); + EnableISR2(); + + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -100,7 +106,7 @@ TASK(Task1) TerminateTask(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; diff --git a/tst/ctest/src/ctest_rm_01.c b/tst/ctest/src/ctest_rm_01.c index a6d45803..99ad98f7 100644 --- a/tst/ctest/src/ctest_rm_01.c +++ b/tst/ctest/src/ctest_rm_01.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. * @@ -73,6 +75,8 @@ int main void ) { + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -204,7 +208,7 @@ TASK(Task2) TerminateTask(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; @@ -232,7 +236,7 @@ ISR(ISR2) } #if ( ISR_CATEGORY_3 == OSEK_ENABLE ) -ISR(ISR3) +ISR(VN_ISR3) { StatusType ret; diff --git a/tst/ctest/src/ctest_rm_05.c b/tst/ctest/src/ctest_rm_05.c index 2fdd3c79..be008a03 100644 --- a/tst/ctest/src/ctest_rm_05.c +++ b/tst/ctest/src/ctest_rm_05.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. * @@ -73,6 +75,8 @@ int main void ) { + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -144,7 +148,7 @@ TASK(Task2) TerminateTask(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; @@ -172,7 +176,7 @@ ISR(ISR2) } #if ( ISR_CATEGORY_3 == OSEK_ENABLE ) -ISR(ISR3) +ISR(VN_ISR3) { StatusType ret; diff --git a/tst/ctest/src/ctest_rst.c b/tst/ctest/src/ctest_rst.c index 649fd2a9..dcfa4300 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 - ) +void +) { uint32f loopi; boolean testok = TRUE; @@ -744,10 +744,10 @@ uint32f SequenceCounter; } - void Sequence +void Sequence ( - uint32f seq - ) +uint32f seq +) { if ( (seq) == 0 ) { @@ -763,7 +763,7 @@ uint32f SequenceCounter; } } - void ConfTestFinish +void ConfTestFinish ( void ) @@ -775,4 +775,3 @@ uint32f SequenceCounter; /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/ - diff --git a/tst/ctest/src/ctest_tm_01.c b/tst/ctest/src/ctest_tm_01.c index c7b92ef8..84908864 100644 --- a/tst/ctest/src/ctest_tm_01.c +++ b/tst/ctest/src/ctest_tm_01.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. * @@ -73,6 +75,8 @@ int main void ) { + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -207,7 +211,7 @@ TASK(Task2) TerminateTask(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; TaskType TaskID; @@ -248,7 +252,7 @@ ISR(ISR2) } #if ( ISR_CATEGORY_3 == OSEK_ENABLE ) -ISR(ISR3) +ISR(VN_ISR3) { StatusType ret; diff --git a/tst/ctest/src/itest_ip_01.c b/tst/ctest/src/itest_ip_01.c index e2da5208..5f24d2b2 100644 --- a/tst/ctest/src/itest_ip_01.c +++ b/tst/ctest/src/itest_ip_01.c @@ -1,4 +1,6 @@ /* Copyright 2014 Mariano Cerdeiro + * Copyright 2016, Franco Bucafusco + * All Rights Reserved * * This file is part of CIAA Firmware. * @@ -70,6 +72,8 @@ int main void ) { + EnableISR2(); + /* start OS in AppMode 1 */ StartOS(AppMode1); @@ -103,7 +107,7 @@ TASK(Task1) ConfTestFinish(); } -ISR(ISR2) +ISR(VN_ISR2) { StatusType ret; diff --git a/tst/ctest/src/msp430/ctest_arch.c b/tst/ctest/src/msp430/ctest_arch.c new file mode 100644 index 00000000..8ba14096 --- /dev/null +++ b/tst/ctest/src/msp430/ctest_arch.c @@ -0,0 +1,103 @@ +/* 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 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; +} + +/* Use P2.2 as interrupt for tests */ +extern void TriggerISR1_Arch(void) +{ + /* ACCESS TO THE PORT HW DIRECTLY, WITHOUT DRIVER*/ + P2IFG |= 0x04; +} + +#endif + +/*==================[internal functions definition]==========================*/ + +/*==================[external functions definition]==========================*/ + +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/