New main for ctl apps, some other tweaks.
M adafruit-feather-m0-basic-template.hzp +4 -0
@@ 10,10 10,12 @@ 
     <folder Name="Source Files">
       <file file_name="targets/Adafruit_Feather_M0_Basic/ctl_board.c" />
       <file file_name="targets/Adafruit_Feather_M0_Basic/pin_mapping.h" />
+      <file file_name="targets/Adafruit_Feather_M0_Basic/m0_main_ctl.c" />
     </folder>
     <folder Name="XML">
       <file file_name="packages/Adafruit_Feather_M0_Basic_package.xml" />
       <file file_name="targets/Adafruit_Feather_M0_Basic/project_templates_Adafruit_Feather_M0_Basic.xml" />
+      <file file_name="targets/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" />
     </folder>
     <folder Name="Peripherals">
       <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_common.h" />

          
@@ 41,6 43,8 @@ 
       <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_clocks.h" />
       <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/numeric_utils.c" />
       <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/numeric_utils.h" />
+      <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.c" />
+      <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.h" />
     </folder>
   </project>
 </solution>

          
M packages/Adafruit_Feather_M0_Basic_package.xml +4 -2
@@ 1,5 1,5 @@ 
 <!DOCTYPE CrossStudio_Package_Description_File>
-<package crossstudio_versions="8:3-" build_version="2015121603.1134011344;crossworks_v3;crossworks_v3" dependencies="SAM_D" board_name="Adafruit Feather M0 Basic board" cpu_manufacturer="Atmel" version="1.0" author="Tero Koskinen" replaces="" board_manufacturer="Adafruit" cpu_name="ATSAMD21G18A" cpu_family="" name="Adafruit_Feather_M0_Basic" filetype="hzq" >
+<package crossstudio_versions="8:3-" build_version="2015121603.1134011344;crossworks_v3;crossworks_v3" dependencies="SAM_D" board_name="Feather M0 Basic board" cpu_manufacturer="Atmel" version="1.0" author="Tero Koskinen" replaces="" board_manufacturer="Adafruit" cpu_name="ATSAMD21G18A" cpu_family="" name="Adafruit_Feather_M0_Basic" filetype="hzq" >
   <history>
     <version name="1.0" >
       <description>Initial Release.</description>

          
@@ 7,6 7,8 @@ 
   </history>
 
   <installed_file file_name="packages/Adafruit_Feather_M0_Basic_package.xml" crc32="0x0" />
-  <installed_file file_name="targets/Adafruit_Feather_M0_Basic/ctl_board.c" crc32="0xabb9311c" />
+  <installed_file file_name="targets/Adafruit_Feather_M0_Basic/ctl_board.c" crc32="0x00" />
+  <installed_file file_name="targets/Adafruit_Feather_M0_Basic/m0_main_ctl.c" crc32="0x00" />
+  <installed_file file_name="targets/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" crc32="0x0" />
   <installed_file file_name="targets/Adafruit_Feather_M0_Basic/project_templates_Adafruit_Feather_M0_Basic.xml" crc32="0xf19aed80" />
 </package>

          
A => targets/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml +5 -0
@@ 0,0 1,5 @@ 
+<!DOCTYPE Board_Memory_Definition_File>
+<root name="ATSAMD21G18A">
+  <MemorySegment name="FLASH" start="0x00002000" size="0x0003E000" access="ReadOnly" />
+  <MemorySegment name="RAM" start="0x20000000" size="0x00008000" access="Read/Write" />
+</root>

          
M targets/Adafruit_Feather_M0_Basic/ctl_board.c +2 -2
@@ 155,7 155,7 @@ ctl_board_init(void)
   ctl_uart_set_baud(uart, 9600);
   ctl_uart_puts(uart, "board initialized\r\n");
 
-  // gpio_set_output(D2X_PORT_A, 17); // LED
+  gpio_set_output(D2X_PORT_A, 17); // LED
 }
 
 void

          
@@ 166,7 166,7 @@ ctl_board_on_button_pressed(CTL_ISR_FN_t
 void
 ctl_board_set_leds(unsigned v)
 {
-  // gpio_set_state(D2X_PORT_A, 17, v != 0);
+  gpio_set_state(D2X_PORT_A, 17, v != 0);
 }
 
 unsigned long

          
A => targets/Adafruit_Feather_M0_Basic/m0_main_ctl.c +79 -0
@@ 0,0 1,79 @@ 
+/*
+ * Example application template for Adafruit Feather M0
+ *
+ * Permissive open source ISC license.
+ *
+ * Copyright (c) 2016 Tero Koskinen <tero.koskinen@iki.fi>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Based on Rowley CrossWorks ctl_main.c
+ *
+ * Remember to build and use Release configuration
+ * if you do not have debug connection to Feather M0.
+ */
+
+#include <string.h>
+#include <ctl_api.h>
+
+#include "libdevice/ctl_uart.h"
+#include "platform_atmel_d21_uart.h"
+
+CTL_TASK_t main_task, new_task;
+
+#define CALLSTACKSIZE 16 // this is only required for AVR builds
+#define STACKSIZE 64          
+unsigned new_task_stack[1+STACKSIZE+1];
+
+void 
+new_task_code(void *p)
+{  
+  unsigned int v=0;
+  CTL_UART_t *uart = d21_uart(0);
+
+  ctl_uart_puts(uart, "new_task_code started\r\n");
+  while (1)
+    {      
+      // task logic goes here      
+      v++;
+      ctl_board_set_leds(v % 2);
+      ctl_timeout_wait(ctl_get_current_time() + ctl_get_ticks_per_second()*10);
+    }  
+}
+
+void
+ctl_handle_error(CTL_ERROR_CODE_t e)
+{
+  while (1);
+}
+
+int main(void)
+{
+  unsigned int v=0;
+  ctl_task_init(&main_task, 255, "main"); // create subsequent tasks whilst running at the highest priority.
+  ctl_start_timer(ctl_increment_tick_from_isr); // start the timer 
+
+  ctl_board_init();
+  ctl_board_set_leds(1);
+
+  memset(new_task_stack, 0xcd, sizeof(new_task_stack));  // write known values into the stack
+  new_task_stack[0]=new_task_stack[1+STACKSIZE]=0xfacefeed; // put marker values at the words before/after the stack
+  ctl_task_run(&new_task, 1, new_task_code, 0, "new_task", STACKSIZE, new_task_stack+1, CALLSTACKSIZE);
+  ctl_task_set_priority(&main_task, 0); // drop to lowest priority to start created tasks running.
+  while (1)
+    {    
+      // power down can go here if supported      
+      v++;
+    }
+  return 0;
+}

          
M targets/Adafruit_Feather_M0_Basic/project_templates_Adafruit_Feather_M0_Basic.xml +13 -11
@@ 1,5 1,5 @@ 
 <projects>
-  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Adafruit Feather M0 Basic" name="Adafruit Feather M0 C/C++ Executable" description="A C/C++ executable for Adafruit Feather M0." type="Executable" template_name="Adafruit_Feather_M0_Basic_EXE">
+  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Feather M0 Basic" name="Feather M0 C/C++ Executable" description="A C/C++ executable for Adafruit Feather M0." type="Executable" template_name="Adafruit_Feather_M0_Basic_EXE">
     <property name="package_dependencies" value="Adafruit_Feather_M0_Basic" />
     <configuration name="THUMB Debug" />
     <configuration name="THUMB Release" />

          
@@ 12,7 12,7 @@ 
     <property name="arm_target_debug_interface_type" value="ADIv5" />
     <property name="arm_target_flash_loader_file_path" value="$(DeviceLoaderFile)" configuration="Flash" />
     <property name="debug_register_definition_file" value="$(DeviceRegisterDefinitionFile)" />
-    <property name="linker_memory_map_file" value="$(DeviceMemoryMapFile)" />
+    <property name="linker_memory_map_file" value="$(TargetsDir)/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" />
     <property name="target_reset_script" value="Reset();" />
     <property name="target_get_partname_script" value="GetPartName()" />
     <property name="target_match_partname_script" value="MatchPartName(&quot;$(Target)&quot;)" />

          
@@ 54,7 54,7 @@ 
       </file>
     </folder>
   </project>
-  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Adafruit Feather M0 Basic" name="Adafruit Feather M0 Assembly Code Only Executable" description="An assembly code only executable for Adafruit Feather M0 Basic." type="Executable" template_name="Adafruit_Feather_M0_Basic_ASM_EXE">
+  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Feather M0 Basic" name="Feather M0 Assembly Code Only Executable" description="An assembly code only executable for Adafruit Feather M0 Basic." type="Executable" template_name="Adafruit_Feather_M0_Basic_ASM_EXE">
     <property name="package_dependencies" value="Adafruit_Feather_M0_Basic" />
     <configuration name="THUMB Debug" />
     <configuration name="THUMB Release" />

          
@@ 67,7 67,7 @@ 
     <property name="arm_target_debug_interface_type" value="ADIv5" />
     <property name="arm_target_flash_loader_file_path" value="$(DeviceLoaderFile)" configuration="Flash" />
     <property name="debug_register_definition_file" value="$(DeviceRegisterDefinitionFile)" />
-    <property name="linker_memory_map_file" value="$(DeviceMemoryMapFile)" />
+    <property name="linker_memory_map_file" value="$(TargetsDir)/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" />
     <property name="target_reset_script" value="Reset();" />
     <property name="target_get_partname_script" value="GetPartName()" />
     <property name="target_match_partname_script" value="MatchPartName(&quot;$(Target)&quot;)" />

          
@@ 96,7 96,7 @@ 
       </file>
     </folder>
   </project>
-  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Adafruit Feather M0 Basic" name="Adafruit Feather M0 Externally Built Executable" description="An externally built executable for Adafruit Feather M0 Basic." type="Externally Built Executable" template_name="Adafruit_Feather_M0_Basic_EXT_EXE">
+  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Feather M0 Basic" name="Feather M0 Externally Built Executable" description="An externally built executable for Adafruit Feather M0 Basic." type="Externally Built Executable" template_name="Adafruit_Feather_M0_Basic_EXT_EXE">
     <property name="package_dependencies" value="Adafruit_Feather_M0_Basic" />
     <configuration name="THUMB Debug" />
     <configuration name="THUMB Release" />

          
@@ 107,7 107,7 @@ 
     <property name="arm_target_debug_interface_type" value="ADIv5" />
     <property name="arm_target_flash_loader_file_path" value="$(DeviceLoaderFile)" configuration="Flash" />
     <property name="debug_register_definition_file" value="$(DeviceRegisterDefinitionFile)" />
-    <property name="linker_memory_map_file" value="$(DeviceMemoryMapFile)" />
+    <property name="linker_memory_map_file" value="$(TargetsDir)/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" />
     <property name="target_reset_script" value="Reset();" />
     <property name="target_get_partname_script" value="GetPartName()" />
     <property name="target_match_partname_script" value="MatchPartName(&quot;$(Target)&quot;)" />

          
@@ 120,7 120,7 @@ 
       </file>
     </folder>
   </project>
-  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Adafruit Feather M0 Basic" name="Adafruit Feather M0 CTL Executable" description="A CrossWorks Tasking Library executable for Adafruit Feather M0." type="Executable" template_name="Adafruit_Feather_M0_Basic_CTL_EXE">
+  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Feather M0 Basic" name="Feather M0 CTL Executable" description="A CrossWorks Tasking Library executable for Adafruit Feather M0." type="Executable" template_name="Adafruit_Feather_M0_Basic_CTL_EXE">
     <property name="package_dependencies" value="Adafruit_Feather_M0_Basic;libctl" />
     <configuration name="THUMB Debug" />
     <configuration name="THUMB Release" />

          
@@ 133,7 133,7 @@ 
     <property name="arm_target_debug_interface_type" value="ADIv5" />
     <property name="arm_target_flash_loader_file_path" value="$(DeviceLoaderFile)" configuration="Flash" />
     <property name="debug_register_definition_file" value="$(DeviceRegisterDefinitionFile)" />
-    <property name="linker_memory_map_file" value="$(DeviceMemoryMapFile)" />
+    <property name="linker_memory_map_file" value="$(TargetsDir)/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" />
     <property name="target_reset_script" value="Reset();" />
     <property name="target_get_partname_script" value="GetPartName()" />
     <property name="target_match_partname_script" value="MatchPartName(&quot;$(Target)&quot;)" />

          
@@ 169,7 169,7 @@ 
       <file name="$(StudioDir)/ctl/source/threads.js" expand="no" />
     </folder>
     <folder name="Source Files" filter="c;cpp;cxx;cc;h;s;asm;inc">
-      <file name="main_ctl.c" source="$(StudioDir)/ctl/source/main_ctl.c" />
+      <file name="m0_main_ctl.c" source="$(TargetsDir)/Adafruit_Feather_M0_Basic/m0_main_ctl.c" />
       <file name="pin_mapping.h" source="$(TargetsDir)/Adafruit_Feather_M0_Basic/pin_mapping.h"/>
     </folder>
     <folder name="Peripherals">

          
@@ 191,6 191,8 @@ 
       <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_eic.c" expand="no"/>
       <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_rtc.h" expand="no"/>
       <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_rtc.c" expand="no"/>
+      <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.c" expand="no"/>
+      <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.h" expand="no"/>
       <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/numeric_utils.h" expand="no"/>
       <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/numeric_utils.c" expand="no"/>
     </folder>

          
@@ 221,7 223,7 @@ 
       <file name="$(PackagesDir)/libraries/libdevice/ctl_uart.h" />
     </folder>
   </project>
-  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Adafruit Feather M0 Basic" name="Adafruit Feather M0 Basic Library" description="A library for Adafruit Feather M0 Basic." type="Library" template_name="Adafruit_Feather_M0_Basic_LIB">
+  <project cpu_manufacturer="Atmel" cpu_name="ATSAMD21G18A" cpu_generic_name="SAM D" board_manufacturer="Adafruit" board_name="Feather M0 Basic" name="Feather M0 Basic Library" description="A library for Adafruit Feather M0 Basic." type="Library" template_name="Adafruit_Feather_M0_Basic_LIB">
     <property name="package_dependencies" value="Adafruit_Feather_M0_Basic" />
     <configuration name="THUMB Debug" />
     <configuration name="THUMB Release" />

          
@@ 234,7 236,7 @@ 
     <property name="arm_target_debug_interface_type" value="ADIv5" />
     <property name="arm_target_flash_loader_file_path" value="$(DeviceLoaderFile)" configuration="Flash" />
     <property name="debug_register_definition_file" value="$(DeviceRegisterDefinitionFile)" />
-    <property name="linker_memory_map_file" value="$(DeviceMemoryMapFile)" />
+    <property name="linker_memory_map_file" value="$(TargetsDir)/Adafruit_Feather_M0_Basic/FeatherM0_MemoryMap.xml" />
     <property name="target_reset_script" value="Reset();" />
     <property name="target_get_partname_script" value="GetPartName()" />
     <property name="target_match_partname_script" value="MatchPartName(&quot;$(Target)&quot;)" />