void gdt_initialize (void) { // Null Descriptor set_gate (GDT_NLSEG / sizeof(gdt_entry_t), 0, 0, 0, 0); // Kernel Code Segment set_gate (GDT_KCSEG / sizeof(gdt_entry_t), 0, 0xFFFFFFFF, 0x9A, GDT_FLAGS); // Kernel Data Segment set_gate (GDT_KDSEG / sizeof(gdt_entry_t), 0, 0xFFFFFFFF, 0x92, GDT_FLAGS); // User Code Segment set_gate (GDT_UCSEG / sizeof(gdt_entry_t), 0, 0xFFFFFFFF, 0xFA, GDT_FLAGS); // User Data Segment set_gate (GDT_UDSEG / sizeof(gdt_entry_t), 0, 0xFFFFFFFF, 0xF2, GDT_FLAGS); // TSS // TODO. gdt_ptr_t gdt_ptr; gdt_ptr.limit = sizeof(gdt_entry_t) * GDT_NUM_ENTRIES - 1; gdt_ptr.base = (uintptr_t) &gdt_entries; gdt_set ((uintptr_t) &gdt_ptr); }
unsigned long measureFrequency(char input) { unsigned long freq = 12345678L; // Measured frequency bool done=FALSE; // Control variable for valid output char d=0; //for loop variable P1SEL |= BIT0; // Use P1.0 as TimerA input P1SEL2 &= ~BIT0; // P1DIR &= ~BIT0; // P1OUT &= ~BIT0; // Enable pull down resistor to reduce stray counts P1REN |= BIT0; // // WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTSSEL | WDTIS0; // Use WDT as interval timer // Default to 250 ms gate so that initial call to set_gate() // will switch to 1 s gate set_input(input); // Set input set_gate(0); // Set gate time // for(d=0;d<2;d++){ //measure twice to get the gate time right freq = 0; // Clear frequency TACTL |= TACLR; // Clear TimerA // IFG1 &= ~WDTIFG; // Wait for WDT period to begin while(!(IFG1 & WDTIFG)); // // TACTL |= MC_2; // Start counting - TimerA continuous mode // IFG1 &= ~WDTIFG; // while(!(IFG1 & WDTIFG)) { // While WDT period.. if(TACTL & TAIFG) { // Check for TimerA overflow freq += 0x10000L; // Add 1 to msw of frequency TACTL &= ~TAIFG; // Clear overflow flag } // } // // TACTL &= ~MC_2; // Stop counting - TimerA stop mode if(TACTL & TAIFG) freq += 0x10000L; // Handle TimerA overflow that may have occured between // last check of overflow and stopping TimerA freq |= TAR; // Merge TimerA count with overflow if(WDTCTL & WDTIS0) freq <<= 2; // Multiply by 4 if using 250 ms gate set_gate(freq); // Adjust gate time if necessary } // return freq; //return measured value // }
int main(void) { unsigned long freq = 12345678L; // Measured frequency WDTCTL = WDTPW + WDTHOLD; // Stop watchdog if (CALBC1_16MHZ == 0xFF || CALDCO_16MHZ == 0xFF) { while(1); // If calibration constants erased // do not load, trap CPU!! } DCOCTL = 0; BCSCTL1 = CALBC1_16MHZ; // Set DCO DCOCTL = CALDCO_16MHZ; Setup_LED((unsigned char*)&display_buffer); Init_display(); P1SEL |= BIT0; // Use P1.0 as TimerA input P1SEL2 &= ~BIT0; // P1DIR &= ~BIT0; // P1OUT &= ~BIT0; // Enable pull down resistor to reduce stray counts P1REN |= BIT0; // __eint(); WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTSSEL | WDTIS0; // Use WDT as interval timer // Default to 250 ms gate so that initial call to set_gate() // will switch to 1 s gate and update the LCD set_input(); // Set input and show on LCD //lcd_print("1 Second Gate", 3, 5); // WDTCTL = WDTPW | WDTTMSEL | WDTSSEL; //lcd_print(" 250 ms Gate ", 3, 5); // WDTCTL = WDTPW | WDTTMSEL | WDTSSEL | WDTIS0; for (;;) { freq = 0; // Clear frequency TACTL |= TACLR; // Clear TimerA // IFG1 &= ~WDTIFG; // Wait for WDT period to begin while(!(IFG1 & WDTIFG)); // // TACTL |= MC_2; // Start counting - TimerA continuous mode // IFG1 &= ~WDTIFG; // while(!(IFG1 & WDTIFG)) { // While WDT period.. if(TACTL & TAIFG) { // Check for TimerA overflow freq += 0x10000L; // Add 1 to msw of frequency TACTL &= ~TAIFG; // Clear overflow flag } // } // // TACTL &= ~MC_2; // Stop counting - TimerA stop mode if(TACTL & TAIFG) freq += 0x10000L; // Handle TimerA overflow that may have occured between // last check of overflow and stopping TimerA freq |= TAR; // Merge TimerA count with overflow if(WDTCTL & WDTIS0) freq <<= 2; // Multiply by 4 if using 250 ms gate // print_freq(freq); // Show on LCD // set_gate(freq); // Adjust gate time if necessary // // if(!(P1IN & BIT3)) { // Check if pushbutton down // ++clock_input; // Switch clock input // set_input(); // // } // } }
void init_exceptions() { int i = 0; // add all Exception Interrupts set_gate(0, int0); set_gate(1, int1); set_gate(2, int2); set_gate(3, int3); set_gate(4, int4); set_gate(5, int5); set_gate(6, int6); set_gate(7, int7); set_gate(8, int8); set_gate(9, int9); set_gate(10, int10); set_gate(11, int11); set_gate(12, int12); set_gate(13, int13); set_gate(14, int14); set_gate(15, int15); set_gate(16, int16); set_gate(17, int17); set_gate(18, int18); set_gate(19, int19); set_gate(20, int20); set_gate(21, int21); set_gate(22, int22); set_gate(23, int23); set_gate(24, int24); set_gate(25, int25); set_gate(26, int26); set_gate(27, int27); set_gate(28, int28); set_gate(29, int29); set_gate(30, int30); set_gate(31, int31); i=32; for (; i < 48; i++) set_gate(i, hwint); set_gate(48, int48); load_idtr(); }
/* set idt by interrupt gate */ void set_interrupt_gate(u32 index, u32 addr) { set_gate(index, addr, INTERRUPT_GATE_FLAG); }
/* set idt by trap gate */ void set_trap_gate(u32 index, u32 addr) { set_gate(index, addr, TRAP_GATE_FLAG); }
/** **=========================================================================== ** ** Abstract: main program ** **=========================================================================== */ int main(void) { #if SYS_STARTUP == 0 SystemInit(); #endif nvic_init(); // настройка векторов прерываний led_init(); // инициализация светодиода, индицирующего работу процессора init_calendar(); // инициализация календаря _SPI_init(); // SPI для внешней FRAM // чтение заводских установок read_data(0x7B,0x00,128,(unsigned char*)&_Sys.FR.b1[0]); read_data(0x7B,0x80,128,(unsigned char*)&_Sys.FR.b1[0x80]); read_data(0x7C,0x00,128,(unsigned char*)&_Sys.FR.b1[0x100]); read_data(0x7C,0x80,128,(unsigned char*)&_Sys.FR.b1[0x180]); read_data(0x7D,0x00,128,(unsigned char*)&_Sys.FR.b1[0x200]); read_data(0x7D,0x80,128,(unsigned char*)&_Sys.FR.b1[0x280]); read_data(0x7E,0x00,128,(unsigned char*)&_Sys.FR.b1[0x300]); read_data(0x7E,0x80,128,(unsigned char*)&_Sys.FR.b1[0x380]); // чтение системных настроек контроллера //read_data(0x7F,0x58,1,&rf_ch); read_data(0x7F,0x00,6,(unsigned char*)&_Sys.Mem.b1[0]); _Sys.Adr=_Sys.Mem.b1[0]; if((_Sys.Adr==0)||(_Sys.Adr==0xFF)) _Sys.Adr=0x01; _Sys.Can1_Baudrate=_Sys.Mem.b1[1]; if(_Sys.Can1_Baudrate>5) _Sys.Can1_Baudrate=5; _Sys.Can1_Type = _Sys.Mem.b1[2]; if(_Sys.Can1_Type>1) _Sys.Can1_Type=0; _Sys.Can2_Baudrate=_Sys.Mem.b1[3]; if(_Sys.Can2_Baudrate>5) _Sys.Can2_Baudrate=5; _Sys.Can2_Type = _Sys.Mem.b1[4]; if(_Sys.Can2_Type>1) _Sys.Can2_Type=0; emu_mode = _Sys.Mem.b1[5]; if(emu_mode>2) emu_mode=0; read_data(0x7F,0x4C,4,ip_addr);set_ip(ip_addr); read_data(0x7F,0x50,6,mac_addr);set_mac(mac_addr); read_data(0x7F,0x5A,4,ip_gate);set_gate(ip_gate); read_data(0x7F,0x5E,1,&modbus_master_emu); read_data(0x7F,0x5F,4,ip_mask);set_mask(ip_mask); #if FRAM_YEAR read_data(0x7F,0x56,1,(unsigned char*)×.year); if(times.year>99) times.year=0; #endif read_data(0x7F,0x57,1,(unsigned char*)&pult_dis); read_data(0x7F,0x59,1,(unsigned char*)&sd_dis); /* read_data(0x7F,0x5A,32,ssid_name); read_data(0x7F,0x7A,32,wifi_password); read_data(0x7F,0x9A,1,&wifi_type); read_data(0x7F,0x9B,4,wifi_ip);*/ // начальные значения номеров строк пульта _Sys.S1=0x00;_Sys.S2=0x00;_Sys.S3=0x00;_Sys.S4=0x00; // системные миллисекундные задачи xTaskCreate( R1Task, ( signed portCHAR * ) "R1", configMINIMAL_STACK_SIZE*2, NULL, R1_TASK_PRIORITY, NULL ); xTaskCreate( R5Task, ( signed portCHAR * ) "R5", configMINIMAL_STACK_SIZE*2, NULL, R5_TASK_PRIORITY, NULL ); xTaskCreate( R10Task, ( signed portCHAR * ) "R10", configMINIMAL_STACK_SIZE*2, NULL, R10_TASK_PRIORITY, NULL ); xTaskCreate( R100Task, ( signed portCHAR * ) "R100", configMINIMAL_STACK_SIZE*2, NULL, R100_TASK_PRIORITY, NULL ); xTaskCreate( R1000Task, ( signed portCHAR * ) "R1000", configMINIMAL_STACK_SIZE*2, NULL, R1000_TASK_PRIORITY, NULL ); // служебная вспомогательная задача (светодиод,фильтр ацп,...) xTaskCreate( prvFlashTask, (signed portCHAR *) "Flash", configMINIMAL_STACK_SIZE*2, NULL, mainFLASH_TASK_PRIORITY, NULL ); // стандартный пульт или коммуникационный канал if(pult_dis!=0x31) xTaskCreate( LCDTask, ( signed portCHAR * ) "Lcd", configMINIMAL_STACK_SIZE*2, NULL, LCD_TASK_PRIORITY, NULL ); else xTaskCreate( PultCanTask, ( signed portCHAR * ) "Lcd", configMINIMAL_STACK_SIZE*5, NULL, Canal_TASK_PRIORITY, NULL ); // задача обработки входов/выходов включая модули расширения xTaskCreate( InOutTask, ( signed portCHAR * ) "InOut", configMINIMAL_STACK_SIZE*2, NULL, InOut_TASK_PRIORITY, NULL ); // два основных коммуникационных канала RS485 if(_Sys.Can1_Type==0) xTaskCreate( BinCanTask, ( signed portCHAR * ) "Canal", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); else xTaskCreate( AsciiCanTask, ( signed portCHAR * ) "Canal", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); if(_Sys.Can2_Type==0) xTaskCreate( BinCan2Task, ( signed portCHAR * ) "Canal2", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); else xTaskCreate( AsciiCan2Task, ( signed portCHAR * ) "Canal2", configMINIMAL_STACK_SIZE*2, NULL, Canal_TASK_PRIORITY, NULL ); // WIFI задачи /* if(wifi_ip[0]) { xTaskCreate( WIFITask, ( signed portCHAR * ) "Wifi", configMINIMAL_STACK_SIZE, NULL, WF_TASK_PRIORITY, NULL ); xTaskCreate( SCAN_WIFITask, ( signed portCHAR * ) "SCANWifi", configMINIMAL_STACK_SIZE, NULL, WF_TASK_PRIORITY+1, NULL ); }*/ // проводной ethernet if(ip_addr[0]) xTaskCreate( EthTask, ( signed portCHAR * ) "Eth", configMINIMAL_STACK_SIZE*3, NULL, ETH_TASK_PRIORITY, NULL ); // задача работы с sd картой if(sd_dis==0x31) xTaskCreate( ArchiveTask, ( signed portCHAR * ) "SD_Task", configMINIMAL_STACK_SIZE*2, NULL, SD_TASK_PRIORITY, NULL ); Relkon_init(); // блок инициализации - формируется верхним уровнем (раздел #init релкона) init_timer(); // аппаратный таймер для определения загрузки процессора vTaskStartScheduler(); // старт планировщика задач while (1){} }
/* Initialize IDT entries with type HARDWARE INTERRUPT */ void set_intr_gate(unsigned int table_idx, void* handler) { set_gate(table_idx, INTR_GATE, handler, 0, KERNEL_CS); }
/* Initialize IDT entries with type SOFTWARE INTERRUPT */ void set_system_gate(unsigned int table_idx, void* handler) { set_gate(table_idx, SYS_GATE, handler, 3, KERNEL_CS); }
/* Initialize IDT entries with type EXCEPTION */ void set_trap_gate(unsigned int table_idx, void* handler) { set_gate(table_idx, TRAP_GATE, handler, 0, KERNEL_CS); }