main()関数が未定義の場合はArduinoのようにsetup()/loop()関数が呼び出され、処理待ちのときにライブラリ(ADC/RTC/TWI/USART)内から呼び出されるavr8_yield()関数をサポートするライブラリ。
avr8_yield()はmain.cppなどにavr8_yield()を定義したときにだけ呼び出される。
【サンプルコード (Microchip Studio)】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include "avr8_xxxx.h" void avr8_yield(void) { /* 処理待ちのときライブラリ内から呼び出される */ } int main(void) { sysinit(); /* avr8_main.cpp: Set Clock, Begin RTC, Enable Interrupt */ /* setup() */ while (1) { /* loop() */ yield(); } } |
【サンプルコード (Arduino風)】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include "avr8_xxxx.h" void avr8_yield(void) { /* 処理待ちのときライブラリ内から呼び出される */ } void setup(void) { ... } void loop(void) { ... } |
【ライブラリ】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* avr8_main.h - main routine Copyright (c) 2025 Sasapea's Lab. All right reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ #pragma once extern void sysinit(void); extern void yield(void); |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
/* avr8_main.cpp - main routine Copyright (c) 2025 Sasapea's Lab. All right reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include "avr8_main.h" #include "avr8_task.h" #include "avr8_clock.h" #include "avr8_rtc.h" #include "avr8_port.h" #include "avr8_tca.h" #include "avr8_tcb.h" #include "avr8_ac.h" #include "avr8_usart.h" #include "avr8_zcd.h" void sysinit(void) { #if defined(CONFIG_CLOCK_FRQSEL) && defined(CLKCTRL_FRQSEL_gm) Clock::setup(CONFIG_CLOCK_FRQSEL); #else Clock::setup(); #endif #if CONFIG_RTC_USE && !((CONFIG_TASK_USE || CONFIG_ALARM_USE) && (CONFIG_ALARM_TIMER == TIMER_RTC)) Rtc::begin(); Rtc::run(); #endif #if CONFIG_TASK_USE Task::begin(); #elif CONFIG_ALARM_USE AlarmTimer.begin(); #endif sei(); } void avr8_yield(void) __attribute__((weak)); void avr8_yield(void) { } static void yield0(void) { avr8_yield(); #if CONFIG_PORT_POLL && !CONFIG_PORT_ISR Port::poll(); #endif #if CONFIG_TCA_POLL && !CONFIG_TCA_ISR TcaBase::poll(); #endif #if CONFIG_TCB_POLL && !CONFIG_TCB_ISR Tcb::poll(); #endif #if CONFIG_AC_POLL && !CONFIG_AC_ISR Ac::poll(); #endif #if CONFIG_USART_POLL && !CONFIG_USART_ISR Usart::poll(); #endif #if CONFIG_ZCD_POLL && !CONFIG_ZCD_ISR Zcd::poll(); #endif #if CONFIG_TASK_USE Task::yield(); #elif CONFIG_ALARM_USE AlarmTimer.poll(); #endif } void yield(void) { yield0(); } void setup(void) __attribute__((weak)); void setup(void) { } void loop(void) __attribute__((weak)); void loop(void) { } int main(void) __attribute__((weak)); int main(void) { sysinit(); setup(); while (1) { loop(); yield0(); } return 0; } |
【関連投稿】
Microchip AVR8 用のライブラリを自作する。(GPIO)
Microchip AVR8 用のライブラリを自作する。(FUSE)
Microchip AVR8 用のライブラリを自作する。(CLOCK)
Microchip AVR8 用のライブラリを自作する。(RESET)
Microchip AVR8 用のライブラリを自作する。(PORTMUX)
Microchip AVR8 用のライブラリを自作する。(USART)
Microchip AVR8 用のライブラリを自作する。(RTC)
Microchip AVR8 用のライブラリを自作する。(TCA)
Microchip AVR8 用のライブラリを自作する。(TCB)
Microchip AVR8 用のライブラリを自作する。(VREF)
Microchip AVR8 用のライブラリを自作する。(DAC)
Microchip AVR8 用のライブラリを自作する。(AC)
Microchip AVR8 用のライブラリを自作する。(ADC)
Microchip AVR8 用のライブラリを自作する。(ZCD)
Microchip AVR8 用のライブラリを自作する。(SPI)
Microchip AVR8 用のライブラリを自作する。(TWI)
Microchip AVR8 用のライブラリを自作する。(MAIN)
Microchip AVR8 用のライブラリを自作する。(CONFIG)
Microchip AVR8 用のライブラリを自作する。(ALARM)
Microchip AVR8 用のライブラリを自作する。(TASK)
Microchip AVR8 用のライブラリを自作する。(DOWNLOAD)
