// Built with BFTC Rev. 1.0.0, lun 25 agosto 2014 15:58:19 /* Copyright 2014 Digital Technology Art SRL This file is part of Blackfin Toolchain (BFTC) project. BFTC 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. BFTC 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 Nome-Programma. If not, see <http://www.gnu.org/licenses/>. */ // Show how to implement an 8 channel fast counter on port PG[7:0]. // The counter is capable to count with a frequency higher then 500KHz // In another way it show the interrupt efficency // #include "main.h" unsigned counter[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; unsigned mask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; // Interrupt service procedure // void PGCallback() { int i; for(i = 0; i < 8; i++) if(*pPORTGIO & mask[i]) { counter[i]++; // Clear the interrupt request *pPORTGIO_CLEAR = mask[i]; } } unsigned char Menu() { printf("\n"); printf("COMMANDS ******************\n"); printf("0 - Clear counts\n"); printf("D - Display counts\n"); printf("> "); return GetChar_Uart0(); } int main(void) { int com, i; Set_PLL(16, 4); // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz Set_Port(); // Set the port according to project set Set_Uart0(115200); // printf is redirected to UART0 // Set an interrupt on the rising edge of the PG0 port Set_PortGInterruptService(PG0 | PG1 | PG2 | PG3 | PG4 | PG5 | PG6 | PG7, PGCallback); Set_PortGInterruptEnable(PG0 | PG1 | PG2 | PG3 | PG4 | PG5 | PG6 | PG7, true); while(1) // Main loop { com = Menu(); switch(com) { case '0': for(i = 0; i < 8; i++) counter[i] = 0; break; case 'D': for(i = 0; i < 8; i++) printf("%8u ", counter[i]); printf("\n"); break; } } return 0; }
1.3.1