Hi,
I want a timer which generates every one second. I have tried the code attached in that i changed load value . but didnot worked, Also i notice that system clock is set at 120MHz but when geting it using SysCtlClockget(), it return 9.6MHz why? I calculated and tried both 120MHz & 9.6MHz based Timer load value but not getting exact one second interrupt.
Please Help
Regards
Khodidas
/* * Author : - KHODIDAS DOMADIYA\ * Organization: - Optimzed Solutions Ltd. * Department: -Product ENgineering services. * * Date:- 12-05-2021 * *LED4 PH3 //INDICATION LED *LED5 PF1 //ETHERNET LED *LED6 PF4 //ETHERNET LED *If PSFLT =1 Then powersupply OK, *Indicate TO MAIN as PSFLT * * If FROM MAIN =1 then Start Monitoring, * If LOCKING/TRIPPING =1 then Condition/Health OK * IF ARC,IDSLW,TEMP,MAIN_IN =1 Then Signals are OK * * **UPDATED ON 22-06-2021 * =>AS per Discussion, After poweron and start command,PSFLT must be monitored, it indicates the powersupply fault signal, ifit is low then powersupply is faulty * so do not start monitoring, control and data transfer and generate LOCKING/ TRIPPING as well as TO MAIN (indication to Mainboard,) * *=>according to discussion that On REEAD command, read and send data to ethernet ,erase and reset entire device.ERASE or RESET command is not to be given. *=> Add DIAGNOSTIC Mode, in that during runtime, thresholds can be changeable. and in RUN/NORMAL Mode it is to be set before START command *=> *=> IP ADDRESS USED IS STATIC * * RF_FORWARD_VAL= ADC_OUT_1[2]; //PE3 * RF_REVERSE_VAL= ADC_OUT_1[3]; //PE2 * TEMPERATURE_VAL=ADC_OUT_1[4]; //PK0 * VDS_VAL =ADC_OUT_1[5]; //PK1 * ID_VAL =ADC_OUT_1[0]; //PK2 * VGS_VAL =ADC_OUT_1[1]; //PK3 * *This firmware has been implementaed for the IPMS interlock system for BARC project *It has adc sampling rate per channel is 200KSPS and datalogging rate as per Anexure to PO. *1000 Data points are stored in flash memory * *Initially on Power on it will check and wait for the Ethernet connection from server as this device works as a client. *It has been assigned with static IP , for dynamic IP do the changes in tcpecho.cfg file * *command from server============================================ *For the start of monitoring, control and data transfer use "start" *For halting monitoring, control and data transfer use "stopd" *For reading data from flash storage use "flash" ,this will work only when device is halted. *For erasing flash content use "erase". If flahs was not erased than it will retain last data, hence during next read it may have old data. *For system reset like power on reset use "reset". this command will reset the device like power on reset and hence, it will close ethernet connection,---- * -----and request new connection from server, as connection established, it will wait for start command to run again. * * * Implementation Pending ============================================================ * start and stop using FROM MAIN signal * Staus signal using TO MAIN Signal * * Indication OF leds - For ethernet , default LEDs used * * */ /* * ======== tcpEcho.c ======== */ /* XDCtools Header files */ #include <stdint.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <xdc/std.h> #include <xdc/cfg/global.h> #include <ti/sysbios/hal/Hwi.h> #include <xdc/runtime/Error.h> #include <xdc/runtime/Memory.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Clock.h> #include <ti/sysbios/knl/Task.h> /* NDK Header files */ #include <ti/ndk/inc/netmain.h> #include <ti/ndk/inc/_stack.h> /* TI-RTOS Header files */ #include <ti/drivers/GPIO.h> #include <ti/sysbios/knl/Semaphore.h> /* Example/Board Header files */ #include "Board.h" #include <time.h> #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "inc/hw_gpio.h" #include "driverlib/gpio.h" #include "inc/hw_ints.h" #include "driverlib/interrupt.h" #include "driverlib/timer.h" #include "driverlib/pin_map.h" #include "driverlib/adc.h" //#include "driverlib/rom.h" //#include "driverlib/rom_map.h" #include "inc/hw_i2c.h" #include "driverlib/i2c.h" #include "driverlib/ssi.h" #include "inc/hw_flash.h" #include "driverlib/flash.h" #include <ti/sysbios/hal/Timer.h> //#define dma false //#define flash_en true #include <lcd.h> //============================Ethernet ========================// #define TCPPACKETSIZE 1024 #define TCPPORT 8080 #define NUMTCPWORKERS 3 #define BUF_SIZE 12412 #define FLASH_BASE_ADDR_RFF ((uint32_t *)0x00020000) #define TASKSTACKSIZE 512 Int resource = 0; Int finishCount = 0; UInt32 sleepTickCount; char thbuffer[10]; SOCKET lSocket; struct sockaddr_in sLocalAddr; Timer_Params Timer2; Timer_Handle myTimer; uint32_t timecounter; //============================SYSTEM CLOCK========================// uint32_t g_ui32SysClock; //============================================================// int checkLinkState(void) { return EMAC_isLinkUp(0); } void timerIntHandler(void) { TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // must clear timer flag FROM timer timecounter++; } // Timer start //void Timer_Start(void) //{ // Timer_start(myTimer); //} // //// Timer stop //void Timer_Stop(void) //{ // Timer_stop(myTimer); //} //=======================================================================// // Timer configuration as RTOS base void timer_init(void) { uint32_t ui32Period; //Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // Timer 2 setup code SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // enable Timer 2 periph clks TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); // cfg Timer 2 mode - periodic ui32Period = (SysCtlClockGet() /1000); TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period); // set Timer 2 period IntEnable(INT_TIMER2A); TimerIntRegister(TIMER2_BASE, TIMER_A, timerIntHandler); IntRegister(INT_TIMER2A, timerIntHandler); TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // enables Timer 2 to interrupt CPU TimerEnable(TIMER2_BASE, TIMER_A); // enable Timer 2 IntMasterEnable(); } //void Timer_init() //{ // timer_init(); // Timer_Params_init(&Timer2); // Timer2.arg=0; // Timer2.period= 500; // 20us // //Timer2.period= 1000; //1 ms (Milliseconds) // //Timer2.period= 800; //800 us (Microseconds) // Timer2.periodType=Timer_PeriodType_MICROSECS; // myTimer=Timer_create(2,(Timer_FuncPtr)timerIntHandler,&Timer2,NULL); // Timer_start(myTimer); // // //Timer_stop(myTimer); // //} /* * ======== tcpHandler ======== * Creates new Task to handle new TCP connections. */ Void tcpHandler(UArg arg0, UArg arg1) { fdOpenSession(TaskSelf()); lSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (lSocket < 0) { // System_printf("tcpHandler: socket failed\n"); Task_exit(); return; } memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr)); sLocalAddr.sin_family = AF_INET; sLocalAddr.sin_addr.s_addr = inet_addr("192.168.1.130");//htonl(INADDR_ANY); sLocalAddr.sin_port = htons(arg0); while(connect(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) { SysCtlDelay(400000); } } /* * ======== main ======== */ int main(void) { // Task_Handle taskHandle; // Task_Params taskParams; // Error_Block eb; g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 120000000); /* Call board init functions */ Board_initGeneral(); Board_initGPIO(); Board_initEMAC(); /***********************GPIO FOR LEDs*************************/ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2); GPIODirModeSet(GPIO_PORTK_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2,GPIO_DIR_MODE_OUT); GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2, 0x00); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2); GPIODirModeSet(GPIO_PORTE_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2,GPIO_DIR_MODE_OUT); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2, 0x00); /***********************GPIO FOR SNAP1 & 2*************************/ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE,GPIO_PIN_4|GPIO_PIN_5); GPIODirModeSet(GPIO_PORTL_BASE,GPIO_PIN_4|GPIO_PIN_5,GPIO_DIR_MODE_OUT); GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_4|GPIO_PIN_5, 0x00); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE,GPIO_PIN_0); GPIODirModeSet(GPIO_PORTM_BASE,GPIO_PIN_0,GPIO_DIR_MODE_OUT); GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_0, 0x00); timer_init(); while(1) { GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_PIN_0); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, GPIO_PIN_2); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0, GPIO_PIN_0); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1, GPIO_PIN_1); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, GPIO_PIN_2); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_4|GPIO_PIN_5, GPIO_PIN_4|GPIO_PIN_5); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_4|GPIO_PIN_5, 0x00); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_0, GPIO_PIN_0); SysCtlDelay(g_ui32SysClock/3); GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_0, 0x00); SysCtlDelay(g_ui32SysClock/3); } /* Start BIOS */ BIOS_start(); return (0); }