├── .gitattributes ├── mosc.ntkdigunit ├── project.mk ├── mosc.hpp ├── manifest.json ├── .gitignore ├── ld ├── osc_api.syms ├── userosc.ld └── rules.ld ├── LICENSE ├── README.md ├── mosc.cpp ├── tpl └── _unit.c └── Makefile /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /mosc.ntkdigunit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GuillaumeElias/Nutekt-MOSC/HEAD/mosc.ntkdigunit -------------------------------------------------------------------------------- /project.mk: -------------------------------------------------------------------------------- 1 | # ############################################################################# 2 | # Project Customization 3 | # ############################################################################# 4 | 5 | PROJECT = mosc 6 | 7 | UCSRC = 8 | 9 | UCXXSRC = mosc.cpp 10 | 11 | UINCDIR = 12 | 13 | UDEFS = 14 | 15 | ULIB = 16 | 17 | ULIBDIR = 18 | -------------------------------------------------------------------------------- /mosc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | Guillaume Elias 2020. Use this file at your own peril. 3 | This project is under BSD3 license. See LICENSE file. 4 | */ 5 | 6 | #pragma once 7 | 8 | 9 | #include "userosc.h" 10 | 11 | 12 | typedef struct Osc { 13 | float phase; 14 | uint16_t type; 15 | float pulse_width; 16 | float gain; 17 | 18 | uint16_t interval; 19 | uint16_t fine_interval; 20 | } Osc; -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "header" : 3 | { 4 | "platform" : "nutekt-digital", 5 | "module" : "osc", 6 | "api" : "1.1-0", 7 | "dev_id" : 0, 8 | "prg_id" : 0, 9 | "version" : "0.1-0", 10 | "name" : "mosc", 11 | "num_param" : 6, 12 | "params" : [ 13 | ["interval", 0, 100, "%"], 14 | ["fine interval", 0, 100, "%"], 15 | ["osc1", 0, 4, ""], 16 | ["osc2", 0, 4, ""], 17 | ["PW1" , 0, 100, "%"], 18 | ["PW2" , 0, 100, "%"] 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Emacs Backup Files 2 | *~ 3 | \#*\# 4 | 5 | ## Vim Temp Files 6 | *.swp 7 | 8 | # Object files 9 | *.o 10 | *.ko 11 | *.obj 12 | *.elf 13 | 14 | # Temporary directories 15 | **/.dep/** 16 | **/build/** 17 | tools/gcc/gcc-arm-none-eabi-* 18 | tools/emscripten/emsdk 19 | 20 | # Doxygen documentation 21 | **/docs/html 22 | **/docs/latex 23 | **/docs/doxygen* 24 | 25 | # Precompiled Headers 26 | *.gch 27 | *.pch 28 | 29 | # Libraries 30 | *.lib 31 | *.a 32 | *.la 33 | *.lo 34 | 35 | # Shared objects (inc. Windows DLLs) 36 | *.dll 37 | *.so 38 | *.so.* 39 | *.dylib 40 | 41 | # Executables/Binaries 42 | *.exe 43 | *.out 44 | *.app 45 | *.i*86 46 | *.x86_64 47 | *.hex 48 | *.bin 49 | *.dfu 50 | *.prlgunit 51 | *.mnlgxdunit 52 | *.ntkdigunit 53 | 54 | # Debug files 55 | *.dSYM/ 56 | *.su 57 | 58 | -------------------------------------------------------------------------------- /ld/osc_api.syms: -------------------------------------------------------------------------------- 1 | k_osc_api_version = 0x0800f000; 2 | k_osc_api_platform = 0x0800f004; 3 | midi_to_hz_lut_f = 0x0800f100; 4 | sqrtm2log_lut_f = 0x0800f360; 5 | tanpi_lut_f = 0x0800f764; 6 | log_lut_f = 0x0800fb68; 7 | bitres_lut_f = 0x0800ff6c; 8 | wt_par_lut_f = 0x08010170; 9 | wt_par_notes = 0x08010f8c; 10 | wt_sqr_lut_f = 0x08010f94; 11 | wt_sqr_notes = 0x08011db0; 12 | wt_saw_lut_f = 0x08011db8; 13 | wt_saw_notes = 0x08012bd4; 14 | wt_sine_lut_f = 0x08012bdc; 15 | schetzen_lut_f = 0x08012de0; 16 | cubicsat_lut_f = 0x08012fe4; 17 | wavesA = 0x080131e8; 18 | wavesB = 0x0801546c; 19 | wavesC = 0x080174ec; 20 | wavesD = 0x0801915c; 21 | wavesE = 0x0801abc4; 22 | wavesF = 0x0801ca3c; 23 | _osc_mcu_hash = 0x0801eabc; 24 | _osc_bl_saw_idx = 0x0801eac8; 25 | _osc_bl_sqr_idx = 0x0801ebb0; 26 | _osc_bl_par_idx = 0x0801ec98; 27 | _osc_rand = 0x0801ed80; 28 | _osc_white = 0x0801edb8; 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Guillaume Elias 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nutekt Mosc 2 | Multi Oscillator for Korg Nutekt NTS-1 3 | 4 | ## Features 5 | - 2 oscillators 6 | - Each oscillator can be set to sine/sawtooth/parabolic/square wave 7 | - Tweak the interval between the 2 oscillators (additive synthesis) 8 | - Pulse width modulation 9 | 10 | ## Parameters 11 | 12 | | Parameter | Range | | 13 | | :------------: | :----------: | --------------------------------------------------: | 14 | | SHAPE | 0 -> 100 |level mix between the 2 oscillators (0:osc1 only) | 15 | | interval | 0 -> 100 |interval between the 2 oscillators (in semi-tones) | 16 | | fine interval | 0 -> 100 |fine interval between the 2 oscillators | 17 | | osc1 | 1 -> 5 |1: sine, 2: sawtooth, 3: parabola, 4: square, 5: off | 18 | | osc2 | 1 -> 5 |1: sine, 2: sawtooth, 3: parabola, 4: square, 5: off | 19 | | PW1 | 0 -> 100 |Pulse Width osc1 (square only) | 20 | | PW2 | 0 -> 100 |Pulse Width osc2 (square only) | 21 | 22 | ## Load 23 | - Install [NTS-1 digital librarian](https://www.korg.com/uk/products/dj/nts_1/librarian_contents.php) 24 | - Plug-in your Nutekt NTS-1 25 | - Select right midi port in the librarian preferences 26 | - Import User Unit and select the mosc.ntkdigunit file 27 | - "Send all" 28 | 29 | ## Set-up dev environment 30 | 31 | - Clone the [logue sdk](https://github.com/korginc/logue-sdk). 32 | - Follow the instructions to install tools 33 | - Download/clone this folder and move it under logue-sdk/platform/nutekt-digital 34 | - run "make" command 35 | - Use logue-cli tool to upload the created .ntkdigunit file 36 | 37 | ## License 38 | 39 | This project is under BSD3 license. See LICENSE file. 40 | -------------------------------------------------------------------------------- /ld/userosc.ld: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 3-Clause License 3 | 4 | Copyright (c) 2018, KORG INC. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | //*/ 33 | 34 | /* 35 | * File: userosc.ld 36 | * 37 | * Linker Script for user oscillators 38 | */ 39 | 40 | /* Entry Point */ 41 | ENTRY(_entry) 42 | 43 | /* Specify the memory areas */ 44 | MEMORY 45 | { 46 | SRAM (rx) : org = 0x20000000, len = 32K 47 | } 48 | 49 | /* Include Rules */ 50 | INCLUDE rules.ld 51 | -------------------------------------------------------------------------------- /mosc.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Guillaume Elias 2020. Use this file at your own peril. 3 | This project is under BSD3 license. See LICENSE file. 4 | */ 5 | 6 | #include "userosc.h" 7 | #include "mosc.hpp" 8 | 9 | static Osc osc1; 10 | static Osc osc2; 11 | 12 | //=========================================================================================== 13 | void OSC_INIT(uint32_t platform, uint32_t api) 14 | { 15 | osc1.phase = 0.f; 16 | osc2.phase = 0.f; 17 | 18 | osc1.gain = 0.5f; 19 | osc2.gain = 0.5f; 20 | 21 | osc1.interval = 0; //not used 22 | osc1.fine_interval = 0; //not used 23 | osc2.interval = 0; 24 | osc2.fine_interval = 0; 25 | 26 | osc1.type = 0; 27 | osc2.type = 0; 28 | 29 | osc1.pulse_width = 0.5f; 30 | osc2.pulse_width = 0.5f; 31 | } 32 | 33 | //=========================================================================================== 34 | float osc(float phase, uint16_t type, float pw) 35 | { 36 | switch(type) 37 | { 38 | case 0: 39 | return osc_sinf(phase); 40 | case 1: 41 | return osc_sawf(phase); 42 | case 2: 43 | return osc_parf(phase); 44 | case 3: 45 | return (phase <= pw) ? 0.8f : -0.8f; //square 46 | case 4: 47 | return 0; 48 | } 49 | } 50 | 51 | //=========================================================================================== 52 | float inline boundPhase(float p) 53 | { 54 | return (p <= 0) ? 1.f - p : p - (uint32_t)p; 55 | } 56 | 57 | //=========================================================================================== 58 | void OSC_CYCLE(const user_osc_param_t * const params, 59 | int32_t *yn, 60 | const uint32_t frames) 61 | { 62 | //compute phase increments for both oscillators 63 | const float w0 = osc_w0f_for_note((params->pitch)>>8, params->pitch & 0xFF); 64 | const float w1 = osc_w0f_for_note(((params->pitch)>>8) + osc2.interval, (params->pitch + osc2.fine_interval) & 0xFF); 65 | 66 | //get LFO value 67 | float lfo = q31_to_f32(params->shape_lfo); 68 | 69 | q31_t * __restrict y = (q31_t *)yn; 70 | 71 | const q31_t * y_e = y + frames; 72 | 73 | for (; y != y_e; ) { 74 | 75 | float p0 = boundPhase(osc1.phase); 76 | 77 | // Main signal 78 | const float sig0 = osc_softclipf(0.05f, osc(p0, osc1.type, osc1.pulse_width + lfo) * osc1.gain); 79 | 80 | osc1.phase += w0; 81 | osc1.phase -= (uint32_t)osc1.phase; 82 | 83 | float p1 = boundPhase(osc2.phase); 84 | 85 | // Second signal 86 | const float sig1 = osc_softclipf(0.05f, osc(p1, osc2.type, osc2.pulse_width + lfo) * osc2.gain); 87 | 88 | osc2.phase += w1; 89 | osc2.phase -= (uint32_t)osc2.phase; 90 | 91 | *(y++) = f32_to_q31(sig0 + sig1); 92 | } 93 | } 94 | 95 | //=========================================================================================== 96 | void OSC_NOTEON(const user_osc_param_t * const params) 97 | { 98 | } 99 | 100 | //=========================================================================================== 101 | void OSC_NOTEOFF(const user_osc_param_t * const params) 102 | { 103 | (void)params; 104 | } 105 | 106 | //=========================================================================================== 107 | void OSC_PARAM(uint16_t index, uint16_t value) 108 | { 109 | switch (index) { 110 | case k_user_osc_param_id1: 111 | osc2.interval = value; 112 | break; 113 | case k_user_osc_param_id2: 114 | osc2.fine_interval = value; 115 | break; 116 | case k_user_osc_param_id3: 117 | osc1.type = value; 118 | break; 119 | case k_user_osc_param_id4: 120 | osc2.type = value; 121 | case k_user_osc_param_id5: 122 | osc1.pulse_width=(float)value / 100.f; 123 | break; 124 | case k_user_osc_param_id6: 125 | osc2.pulse_width=(float)value / 100.f; 126 | break; 127 | case k_user_osc_param_shape: 128 | { 129 | float val = param_val_to_f32(value) * 2.f; 130 | osc1.gain = 2.f - val; 131 | osc2.gain = val; 132 | } 133 | case k_user_osc_param_shiftshape: 134 | default: 135 | break; 136 | } 137 | 138 | } 139 | 140 | -------------------------------------------------------------------------------- /ld/rules.ld: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 3-Clause License 3 | 4 | Copyright (c) 2018, KORG INC. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | //*/ 33 | 34 | /* 35 | * File: rules.ld 36 | * 37 | * Linker Rules 38 | */ 39 | 40 | /* ----------------------------------------------------------------------------- */ 41 | /* Define output sections */ 42 | 43 | SECTIONS 44 | { 45 | 46 | .hooks : ALIGN(16) SUBALIGN(16) 47 | { 48 | . = ALIGN(4); 49 | _hooks_start = .; 50 | KEEP(*(.hooks)) 51 | . = ALIGN(4); 52 | _hooks_end = .; 53 | } > SRAM 54 | 55 | /* Constructors */ 56 | .init_array : ALIGN(4) SUBALIGN(4) 57 | { 58 | . = ALIGN(4); 59 | PROVIDE(__init_array_start = .); 60 | KEEP(*(SORT(.init_array.*))) 61 | KEEP(*(.init_array*)) 62 | . = ALIGN(4); 63 | PROVIDE(__init_array_end = .); 64 | } > SRAM 65 | 66 | /* Common Code */ 67 | .text : ALIGN(4) SUBALIGN(4) 68 | { 69 | . = ALIGN(4); 70 | _text_start = .; 71 | *(.text) 72 | *(.text.*) 73 | *(.glue_7) /* glue arm to thumb code */ 74 | *(.glue_7t) /* glue thumb to arm code */ 75 | *(.gcc*) 76 | . = ALIGN(4); 77 | _text_end = .; 78 | } > SRAM 79 | 80 | /* Constants and strings */ 81 | .rodata : ALIGN(4) SUBALIGN(4) 82 | { 83 | . = ALIGN(4); 84 | _rodata_start = .; 85 | *(.rodata) 86 | *(.rodata.*) 87 | . = ALIGN(4); 88 | _rodata_end = .; 89 | } > SRAM 90 | 91 | /* Read-write data */ 92 | .data ALIGN(8) : ALIGN(8) SUBALIGN(8) 93 | { 94 | . = ALIGN(8); 95 | _data_start = .; 96 | *(.data) 97 | *(.data.*) 98 | . = ALIGN(8); 99 | _data_end = .; 100 | } > SRAM 101 | 102 | /* Uninitialized variables */ 103 | .bss (NOLOAD) : ALIGN(4) 104 | { 105 | . = ALIGN(4); 106 | _bss_start = .; 107 | *(.bss) 108 | *(.bss.*) 109 | *(COMMON) 110 | . = ALIGN(4); 111 | _bss_end = .; 112 | } > SRAM 113 | 114 | /* Exception sections */ 115 | .ARM.extab : ALIGN(4) SUBALIGN(4) 116 | { 117 | . = ALIGN(4); 118 | __extab_start = .; 119 | *(.ARM.extab* .gnu.linkonce.armextab.*) 120 | . = ALIGN(4); 121 | __extab_end = .; 122 | } > SRAM 123 | 124 | .ARM.exidx : ALIGN(4) SUBALIGN(4) 125 | { /* Note: Aligning when there's no content for this section throws a warning. Looks like a linker bug. */ 126 | /* . = ALIGN(4); */ 127 | __exidx_start = .; 128 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 129 | /* . = ALIGN(4); */ 130 | __exidx_end = .; 131 | } > SRAM 132 | 133 | .eh_frame_hdr : ALIGN(4) SUBALIGN(4) 134 | { 135 | . = ALIGN(4); 136 | _eh_frame_hdr_start = .; 137 | *(.eh_frame_hdr) 138 | . = ALIGN(4); 139 | _eh_frame_hdr_end = .; 140 | } > SRAM 141 | 142 | .eh_frame : ALIGN(4) SUBALIGN(4) ONLY_IF_RO 143 | { 144 | . = ALIGN(4); 145 | _eh_frame_start = .; 146 | *(.eh_frame) 147 | . = ALIGN(4); 148 | _eh_frame_end = .; 149 | } > SRAM 150 | 151 | /* 152 | /DISCARD/ 153 | { 154 | libc.a ( * ) 155 | libm.a ( * ) 156 | libgcc.a ( * ) 157 | } 158 | //*/ 159 | 160 | /* .ARM.attributes 0 : { *(.ARM.attributes) } //*/ 161 | } 162 | -------------------------------------------------------------------------------- /tpl/_unit.c: -------------------------------------------------------------------------------- 1 | /* 2 | BSD 3-Clause License 3 | 4 | Copyright (c) 2018, KORG INC. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | //*/ 33 | 34 | /** 35 | * @file _unit.c 36 | * @brief Oscillator entry template. 37 | * 38 | * @addtogroup api 39 | * @{ 40 | */ 41 | 42 | #include "userosc.h" 43 | 44 | /*===========================================================================*/ 45 | /* Externs and Types. */ 46 | /*===========================================================================*/ 47 | 48 | /** 49 | * @name Externs and Types. 50 | * @{ 51 | */ 52 | 53 | extern uint8_t _bss_start; 54 | extern uint8_t _bss_end; 55 | 56 | extern void (*__init_array_start []) (void); 57 | extern void (*__init_array_end []) (void); 58 | 59 | typedef void (*__init_fptr)(void); 60 | 61 | /** @} */ 62 | 63 | /*===========================================================================*/ 64 | /* Locals Constants and Vars. */ 65 | /*===========================================================================*/ 66 | 67 | /** 68 | * @name Local Constants and Vars. 69 | * @{ 70 | */ 71 | 72 | __attribute__((used, section(".hooks"))) 73 | static const user_osc_hook_table_t s_hook_table = { 74 | .magic = {'U','O','S','C'}, 75 | .api = USER_API_VERSION, 76 | .platform = USER_TARGET_PLATFORM>>8, 77 | .reserved0 = {0}, 78 | .func_entry = _entry, 79 | .func_cycle = _hook_cycle, 80 | .func_on = _hook_on, 81 | .func_off = _hook_off, 82 | .func_mute = _hook_mute, 83 | .func_value = _hook_value, 84 | .func_param = _hook_param, 85 | .reserved1 = {0} 86 | }; 87 | 88 | /** @} */ 89 | 90 | /*===========================================================================*/ 91 | /* Default Hooks. */ 92 | /*===========================================================================*/ 93 | 94 | /** 95 | * @name Default Hooks. 96 | * @{ 97 | */ 98 | 99 | __attribute__((used)) 100 | void _entry(uint32_t platform, uint32_t api) 101 | { 102 | // Ensure zero-clear BSS segment 103 | uint8_t * __restrict bss_p = (uint8_t *)&_bss_start; 104 | const uint8_t * const bss_e = (uint8_t *)&_bss_end; 105 | 106 | for (; bss_p != bss_e;) 107 | *(bss_p++) = 0; 108 | 109 | // Call constructors if any. 110 | const size_t count = __init_array_end - __init_array_start; 111 | for (size_t i = 0; i $@ 212 | @echo 213 | @$(SZ) $< 214 | @echo 215 | 216 | %.list: %.elf 217 | @echo Creating $@ 218 | @$(OD) -S $< > $@ 219 | 220 | clean: 221 | @echo Cleaning 222 | -rm -fR .dep $(BUILDDIR) $(PKGARCH) 223 | @echo 224 | @echo Done 225 | 226 | package: 227 | @echo Packaging to ./$(PKGARCH) 228 | @mkdir -p $(PKGDIR) 229 | @cp -a $(MANIFEST) $(PKGDIR)/ 230 | @cp -a $(BUILDDIR)/$(PROJECT).bin $(PKGDIR)/$(PAYLOAD) 231 | @$(ZIP) $(ZIP_ARGS) $(PROJECT).zip $(PKGDIR) 232 | @mv $(PROJECT).zip $(PKGARCH) 233 | @echo 234 | @echo Done 235 | --------------------------------------------------------------------------------