パルスカウンターは32bitでパルスをカウントしリファレンスカウントに到達したときに割り込みやウェイクアップを行うことができる。2つのカウンタを連結し64bitのパルスカウンターとして使うことも可能。
【ライブラリ】
| 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 | /*   pulscounter.h - Puls Counter Library for NXP-JN516x   Copyright (c) 2022 Sasapea's Lab. All right reserved.   This library is free software; you can redistribute it and/or   modify it under the terms of the GNU Lesser General Public   License as published by the Free Software Foundation; either   version 2.1 of the License, or (at your option) any later version.   This library 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   Lesser General Public License for more details.   You should have received a copy of the GNU Lesser General   Public License along with this library; if not, write to the   Free Software Foundation, Inc., 59 Temple Place, Suite 330,   Boston, MA  02111-1307  USA */ #pragma once #include <jendefs.h> #include <AppHardwareApi.h> #include "sysctrl.h" /*    I/O Ports       Pulse Counter 0: DIO1/DIO4       Pulse Counter 1: DIO8/DIO5  */ class PulsCounter {   public:     typedef enum     {       COUNTER_0 = E_AHI_PC_0, // Pulse Counter 0 or combined counter       COUNTER_1 = E_AHI_PC_1, // Pulse Counter 1     } COUNTER;     typedef enum     {       SAMPLES_0 = 0, // No debounce (maximum input frequency of 100kHz)       SAMPLES_2 = 2, // 2 samples (maximum input frequency of 3.7kHz)       SAMPLES_4 = 4, // 4 samples (maximum input frequency of 2.2kHz)       SAMPLES_8 = 8, // 8 samples (maximum input frequency of 1.2kHz)     } SAMPLES;     typedef enum     {       COMBINE_OFF = E_AHI_PC_COMBINE_OFF, // 0 - Pulse counters not combined       COMBINE_ON0 = E_AHI_PC_COMBINE_ON0, // 1 - Counters combined using PC0 input       COMBINE_ON1 = E_AHI_PC_COMBINE_ON1, // 2 - Counters combined using PC1 input     } COMBINE;     static     bool configure(COUNTER counter, bool falling, SAMPLES samples = SAMPLES_0, COMBINE combine = COMBINE_OFF, PR_HWINT_APPCALLBACK prPcCallback = 0)     {       switch (counter)       {         case COUNTER_0: SysCtrl::interrupt(SysCtrl::INTSRC_PC0, prPcCallback); break;         case COUNTER_1: SysCtrl::interrupt(SysCtrl::INTSRC_PC1, prPcCallback); break;       }       return bAHI_PulseCounterConfigure(counter, falling, samples, combine, prPcCallback != 0);     }     static     void location(COUNTER counter, bool location)     {       // location:       //   TRUE  - DIO4 (Pulse Counter 0) or DIO5 (Pulse Counter 1)       //   FALSE - DIO1 (Pulse Counter 0) or DIO8 (Pulse Counter 1)       vAHI_PulseCounterSetLocation(counter, location);     }     static     bool reference(COUNTER counter, uint32 count)     {       return bAHI_SetPulseCounterRef(counter, count);     }     static     bool start(COUNTER counter)     {       return bAHI_StartPulseCounter(counter);     }     static     bool stop(COUNTER counter)     {       return bAHI_StopPulseCounter(counter);     }     static     bool status(COUNTER counter)     {       switch (counter)       {         case COUNTER_0: return u32AHI_PulseCounterStatus() & E_AHI_SYSCTRL_PC0_MASK;         case COUNTER_1: return u32AHI_PulseCounterStatus() & E_AHI_SYSCTRL_PC1_MASK;       }       return false;     } }; | 
次回は、Infraredの予定。
【関連投稿】
NXP JN516X (TWELITE) をプログラミングする(開発環境の構築)
NXP JN516X (TWELITE) をプログラミングする(メイン・ルーチン)
NXP JN516X (TWELITE) をプログラミングする(TICKTIMER)
NXP JN516X (TWELITE) をプログラミングする(UART)
NXP JN516X (TWELITE) をプログラミングする(SYSTEM)
NXP JN516X (TWELITE) をプログラミングする(GPIO)
NXP JN516X (TWELITE) をプログラミングする(TIMER)
NXP JN516X (TWELITE) をプログラミングする(ALARM)
NXP JN516X (TWELITE) をプログラミングする(WAKETIMER)
NXP JN516X (TWELITE) をプログラミングする(WATCHDOG)
NXP JN516X (TWELITE) をプログラミングする(I2C)
NXP JN516X (TWELITE) をプログラミングする(SPI)
NXP JN516X (TWELITE) をプログラミングする(ADC)
NXP JN516X (TWELITE) をプログラミングする(COMPARATOR)
NXP JN516X (TWELITE) をプログラミングする(CLOCK)
NXP JN516X (TWELITE) をプログラミングする(BROWNOUT)
NXP JN516X (TWELITE) をプログラミングする(PULSCOUNTER)
NXP JN516X (TWELITE) をプログラミングする(INFRARED)
NXP JN516X (TWELITE) をプログラミングする(RANDOM-GENERATOR)
NXP JN516X (TWELITE) をプログラミングする(FLASH)
NXP JN516X (TWELITE) をプログラミングする(EEPROM)
NXP JN516X (TWELITE) をプログラミングする(WPAN)
NXP JN516X (TWELITE) をプログラミングする(Eclipse-CDT+MWSTAGE)
NXP JN516X (TWELITE) をプログラミングする(乗算と除算)
NXP JN516X (TWELITE) をプログラミングする(マルチタスク)
NXP JN516X (TWELITE) をプログラミングする(フラッシュ・プログラマー)
NXP JN516X (TWELITE) をプログラミングする(OTA UPDATE)
NXP JN516X (TWELITE) をプログラミングする(TWELITE CUE/MC3630)
NXP JN516X (TWELITE) をプログラミングする(LED)
NXP JN516X (TWELITE) をプログラミングする(AES)
NXP JN516X (TWELITE) をプログラミングする(Downloads)
