// All animations run on a 20ms interrupt-based routine void Animation_init(){ // enable clock for this peripheral (timer2) PCONP_bit.PCTIM2 = 1; // Set prescaler to 4 PCLKSEL1_bit.PCLK_TIMER2 = 0; // Set interrupt flag on compare-match with MR0 T2MCR_bit.MR0I = 1; // Reset MR0 on compare-match T2MCR_bit.MR0R = 1; // This value yields a 20ms interrupt time T2MR0 = 0x57E40; // Init timer 2 interrupt T2IR_bit.MR0INT = 1; VIC_SetVectoredIRQ(Timer2IntrHandler,0,VIC_TIMER2); VICINTENABLE |= 1UL << VIC_TIMER2; // Allocate memory for the animationHolder animationHolder = (Animation*)malloc(sizeof(*animationHolder)); mAnimating = 0; }
/************************************************************************* * Function Name: clock_init * Parameters: Int32U IntrPriority * * Return: none * * Description: Timer init * *************************************************************************/ void clock_init(Int32U IntrPriority) { Ticks = 0; // Init Time0 PCONP_bit.PCTIM0 = 1; // Enable TMR0 clk T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 0; T0MR0 = SYS_GetFpclk(TIMER0_PCLK_OFFSET)/(TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,IntrPriority,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable }
/************************************************************************* * Function Name: TouchScrInit * Parameters: none * * Return: none * * Description: Init Touch screen * *************************************************************************/ void TouchScrInit (void) { // Init variable Touch_temp = Touch = FALSE; X = Y = 0; State = TS_INTR_SETUP_DLY; // Init GPIOs TS_X1_SEL = 1; // ADC0 Ch1 TS_X1_MODE = 2; // disable pulls TS_X2_SEL = 0; // general IO TS_X2_MODE = 3; // enable pull-down TS_Y1_SEL = 0; // general IO TS_Y1_MODE = 2; // disable pulls TS_Y2_SEL = 0; // general IO TS_Y2_MODE = 2; // disable pulls TS_X1_FDIR &= ~TS_X1_MASK; TS_X2_FDIR &= ~TS_X2_MASK; TS_Y1_FDIR |= TS_Y1_MASK; TS_Y2_FDIR |= TS_Y2_MASK; TS_Y1_FSET = TS_Y1_MASK; TS_Y2_FSET = TS_Y2_MASK; // Init Port interrupt TS_X2_INTR_R &= ~TS_X2_MASK; // disable X2 rising edge interrupt TS_X2_INTR_CLR = TS_X2_MASK; EXTINT = 1UL<<3; VIC_SetVectoredIRQ(OnTouchIntr_Handler,TS_INTR_PRIORITY,VIC_EINT3); VICINTENABLE |= 1UL << VIC_EINT3; // Init ADC PCONP_bit.PCAD = 1; // Enable ADC clocks AD0CR_bit.PDN = 1; // converter is operational AD0CR_bit.START = 0; AD0CR_bit.SEL = 1UL<<1; // select Ch1 AD0CR_bit.CLKDIV = SYS_GetFpclk(ADC_PCLK_OFFSET)/ 500000; AD0CR_bit.BURST = 0; // disable burst AD0CR_bit.CLKS = 0; // 10 bits resolution // clear all pending interrupts while(ADSTAT_bit.ADINT) { volatile Int32U Dummy = AD0GDR; } ADINTEN_bit.ADGINTEN = 1; // Enable global interrupt VIC_SetVectoredIRQ(ADC_Intr_Handler,TS_INTR_PRIORITY,VIC_AD0); VICINTENABLE |= 1UL << VIC_AD0; // Init delay timer PCONP_bit.PCTIM1 = 1; // Enable TIM1 clocks T1TCR = 2; // stop and reset timer 1 T1CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T1MCR_bit.MR0S = 1; // stop timer if MR0 matches the TC T1MCR_bit.MR0R = 1; // enable timer reset if MR0 matches the TC T1MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T1PR = (SYS_GetFpclk(TIMER1_PCLK_OFFSET)/ 1000000) - 1; // 1us resolution T1MR0 = TS_SETUP_DLY; T1IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(TimerIntr_Handler,TS_INTR_PRIORITY,VIC_TIMER1); VICINTENABLE |= 1UL << VIC_TIMER1; T1TCR = 1; // start timer 1 }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int main(void) { MamInit(); // Init clock InitClock(); // Init GPIO GpioInit(); // Init VIC init_VIC(); // Enable TIM0 clocks PCONP_bit.PCTIM0 = 1; // enable clock PCLKSEL0_bit.PCLK_TIMER0 = 1; //timer clock = pclk // Init Time0 T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 18-1; T0MR0 = (TIMER0_IN_FREQ)/(18 * TIMER0_TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable __enable_interrupt(); LcdInitPio(); BoardInit(); SysSpiInitPio(); DacInitPio(); AdcInitPio(); InitAdc(); LcdInitModule(); LcdClear(); // LcdLine(10,32,130, 32); // LcdLine(60,10,60, 60); // LcdLine(70,10,70, 60); // LcdRect(10,20,40, 50); // LcdRect(10,1,80, 7); /* SetFont(BIG_FONT); LcdLine(10, 28, 120, 28); LcdLine(10, 45, 120, 45); // LcdRect(10, 30, 50, 43); LcdText(50, 20, 200, 36, "-123456789.0"); */ /* LcdBmp(10, 20, BMP_HN_WIDTH, BMP_HN_HEIGHT, bmp_hn); LcdBmp(10, 35, BMP_O2_WIDTH, BMP_O2_HEIGHT, bmp_o2); DrawCheckBox(8, 8, 0, 1); DrawCheckBox(20, 8, 1, 1);*/ // DrawMainScreen(); DrawParamScreen(); LcdClear(); //DrawMenuScreen(); DrawDOutTestScreen(); LcdDraw(); OutputSet(LCD_LED); InitMessages(); InitKeyb(); InitCursor(); InitAdc(); // SetCursorPos(100, 32); SendMessage(MSG_EDITOR_SCREEN_ACTIVATE); int debug = 0, debug2 = 0; char s[4]; /* LcdClear(); for(char i = 0; i < 16; i++) LcdLine(i * 8, 0, i * 8, 63); LcdDraw(); */ // debug = ReadTemp() / 32; debug = 3855.0 + 20.0 * ((402.0 - 3855.0) / 20.0); unsigned int dac_codes[4] = {0, 0, 0, 0}; dac_codes[0] = debug; // unsigned int dac_codes[4] = {0, 0, 0, 4095}; WriteToDac(dac_codes); // char adc_codes[4] = {0x58, 0, 0, 0}; // char adc_codes2[4] = {0, 0, 0, 0,}; char state = 0; while(1) { /* WriteIntToFram(0, 100); ReadIntFromFram(0, &debug); */ /* WriteToDac(dac_codes); */ /* switch(state) { case 0: //if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_R_ENCODER_PRESSED)) { OutputSet(LED11); OutputClr(LED12); OutputClr(LED13); OutputSet(LED15); ResetTimer(KEYB_TIMER); SendMessage(MSG_CUR_DEACTIVATE); state = 1; }; break; case 1: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_R_ENCODER_PRESSED)) { OutputClr(LED11); OutputSet(LED12); OutputClr(LED13); OutputClr(LED15); ResetTimer(KEYB_TIMER); SendMessage(MSG_CUR_ACTIVATE); state = 0; }; break; case 2: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_KEY_PRESSED)) { OutputClr(LED11); OutputClr(LED12); OutputSet(LED13); OutputClr(LED15); ResetTimer(KEYB_TIMER); state = 3; }; break; case 3: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_KEY_PRESSED)) { OutputClr(LED11); OutputClr(LED12); OutputClr(LED13); OutputSet(LED15); ResetTimer(KEYB_TIMER); state = 0; }; break; }; if (GetMessage(MSG_L_ENCODER_CW)) { debug++; sprintf(s, "%d", debug); // LcdClear(); LcdText(0, 0, 63, 9, s); LcdDraw(); }; if (GetMessage(MSG_L_ENCODER_CCW)) { debug--; sprintf(s, "%d", debug); // LcdClear(); LcdText(0, 0, 63, 9, s); LcdDraw(); }; if (GetMessage(MSG_R_ENCODER_CW)) { debug2++; sprintf(s, "%d", debug2); // LcdClear(); LcdText(100, 0, 127, 9, s); LcdDraw(); }; if (GetMessage(MSG_R_ENCODER_CCW)) { debug2--; sprintf(s, "%d", debug2); // LcdClear(); LcdText(100, 0, 127, 9, s); LcdDraw(); }; */ // ProcessEditorScreen(); // ProcessEditor(); ProcessAdc(); ProcessCursor(); ProcessKeyb(); ProcessMessages(); } }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int main(void) { typedef Int32U ram_unit; // int cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2; // unsigned long int deltaT; static float freq_aveg; int LCD_updatecount; LCD_updatecount = 0; //From uip start unsigned int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; //From uip end /*** COMPARE FIX POINT 523235 ***/ /*** COMPARE FIX POINT 523235 ***/ GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC VIC_Init(); // GLCD init // GLCD_Init (IarLogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well // GLCD_Init (LogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well GLCD_Init (what_is_a_blissPic.pPicStream, NULL); GLCD_Cursor_Dis(0); //From uip // GLCD_Cursor_Dis(0); // GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U)); /*** COMPARE FIX POINT 534252 ***/ /*** COMPARE FIX POINT 534252 ***/ GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32); //From uip // GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_64); // GLCD_Move_Cursor(cursor_x, cursor_y); // GLCD_Cursor_En(0); //From uip start // Sys timer init 1/100 sec tick clock_init(2); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); //From uip end // Init USB Link LED USB_D_LINK_LED_SEL = 0; // GPIO USB_D_LINK_LED_FSET = USB_D_LINK_LED_MASK; USB_D_LINK_LED_FDIR |= USB_D_LINK_LED_MASK; USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; /*-----------------------------------------------------------------*/ // Init AD0[3] for current meassurement PINSEL1_bit.P0_26 = 1; // Assign P26 to AD0[3], page 180 PINMODE1_bit.P0_26 = 2; // //Neither pull-up or pull-down // PCONP_bit.PCAD = 1; // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN // Other initial parameters are already set // AD0CR_bit.SEL = 8; // select Ch3 [1111] current_amp = 0; /*-----------------------------------------------------------------*/ // Init the DAC converter //Clock: In the PCLK_SEL0 register (Table 4�), select PCLK_DAC //PCLKSEL0_bit.PCLK_DAC = 3UL;// **HAS Desided for values yet!** // '11' at bit 23 and 22 (which is CCLK/8) //or use 0x3 for 3UL instead //Pins: Select the DAC pin and pin mode in registers PINSEL1 and PINMODE1 (see Section 9�. //PINSEL1 |= (2UL<<20); // PINSEL1_bit.P0_26 = 1; //?? //PINSEL1_bit.P0_26 = 2UL; //"PINMODE registers control the on-chip pull-up/pull-down resistor feature for all GPIO ports." - page 178 //PINMODE1 |= ________; // See table 128 for values. Write to bit 21:20 //PINMODE1_bit.P0_26 = 2UL; //P0.26MODE = 2UL; //Neither pull-up or pull-down /* ------------------------------------------------------------------*/ // Init ADC converter // Power the ADC converter PINSEL1_bit.P0_25 = 1; // Assign Pin 25 to ADO[2] PINMODE1_bit.P0_25 = 1; // Neither pull-up or pull-dow PCONP_bit.PCAD = 1; // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN AD0CR_bit.PDN = 1; // A/D converter is operational AD0CR_bit.START = 0; // Conversion not started AD0CR_bit.BURST = 0; // disable burst // AD0CR_bit.SEL = 4; // select Ch2 [11] // Select number of clocks for each conversion AD0CR_bit.CLKS = 0; // [000] 11 clocks / 10 bits AD0CR_bit.CLKDIV = SYS_GetFpclk(ADC_PCLK_OFFSET)/ 10000; // 4500000; // Should be equal to 10K samplingrate ADINTEN_bit.ADGINTEN = 1; // Global A/D channels enabled by ADINTEN 7:0 // Since only on channel is used at the moment the global flag is enabled VIC_SetVectoredIRQ(AD0IntrHandler,1,VIC_AD0); // Set the interrupt call VICINTENABLE |= 1UL << VIC_AD0; // Setting parameters for the low-pass filter DACR_previous = 0; // Initialize DACR_temp which is y(i-1) deltaT = 1.0/TIMER0_TICK_PER_SEC; // Set the sample rate // Calculate the R*C for cut-off frequency of the low pass filter alpha = deltaT/(1./(2.*3.1416*100.) + deltaT); // Cut-off = 100 Hz done = 0; // Channel stage /* ------------------------------------------------------------------*/ // Setting the port to P0[11] and P0[19] PINSEL1_bit.P0_19 = 0; // GPIO to P0[19] PINSEL0_bit.P0_11 = 0; // GPIO to P0[11] PINMODE1_bit.P0_19 = 2; // Pin has neither pull up or down PINMODE0_bit.P0_11 = 2; // Pin has neither pull up or down FIO0DIR_bit.P0_19 = 1; FIO0CLR = (1UL<<19); FIO0DIR_bit.P0_11 = 1; FIO0CLR = (1UL<<11); FIO0PIN_bit.P0_19 = 1; FIO0PIN_bit.P0_11 = 1; /* ------------------------------------------------------------------*/ // Enable TIM0 clocks PCONP_bit.PCTIM0 = 1; // enable clock // Init Time0 T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 0; T0MR0 = SYS_GetFpclk(TIMER0_PCLK_OFFSET)/(TIMER0_TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable __enable_interrupt(); GLCD_Ctrl (TRUE); #if 0 SDRAM_Test(); #endif /* // SMB380_Init(); SMB380_GetID(&Smb380Id, &Smb380Ver); SMB380_Data_t XYZT; */ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ //From uip start GLCD_SetFont(&Terminal_18_24_12,0x000000,0x000cd4ff); GLCD_SetWindow(85,10,255,33); GLCD_TextSetPos(0,0); GLCD_print("\f Room Station"); //From uip start /*** COMPARE FIX POINT 458923 ***/ /*** COMPARE FIX POINT 458923 ***/ // GLCD_SetWindow(5,200,319,239); // GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); // Initialize the ethernet device driver do { GLCD_TextSetPos(0,0); } while(!tapdev_init()); GLCD_TextSetPos(0,0); // uIP web server // Initialize the uIP TCP/IP stack. uip_init(); uip_ipaddr(ipaddr, 192,168,0,100); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // Initialize the HTTP server. httpd_init(); /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** WHILE LOOP START ***/ while(1) { /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ uip_len = tapdev_read(uip_buf); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { tapdev_send(uip_buf,uip_len); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } #define AVERAGECOUNT 100000 if(LCD_updatecount <= AVERAGECOUNT) { ++LCD_updatecount; freq_aveg += freq; } else { freq_aveg = freq_aveg/AVERAGECOUNT; updateFreqHistory(freq_aveg); //Must be kept together with freq calculation! GLCD_SetWindow(20,55,150,80); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f Hz %3.3f", freq_aveg); freq_aveg = 0; GLCD_SetWindow(20,90,150,115); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f V %3.3f", sqrtf(vol_rms_result)); updateVoltageHistory(sqrtf(vol_rms_result)); GLCD_SetWindow(20,125,150,150); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f uA %3.3f", sqrtf(current_amp)); GLCD_SetWindow(20,160,150,185); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f uP %3.3f", sqrtf(vol_rms_result)*sqrtf(current_amp)); LCD_updatecount = 0; } }//while(1) loop }//main function