// $RCSfile: vm_lib.c,v $Revision: 1.4 $Date: 2005/03/11 15:08:57 #include "allnodes.h" #include "node1.h" #include "vm_lib.h" //----- global variables -------------------------------------------------------- unsigned int * P_hw_timer_ctrl; unsigned int ProgC; // VM Program Counter int SUbind = -1; unsigned int EndProg = 1; // 1= True, 0=false: may be useful to inspect the state of the VM as well as to abort the execution of a program; unsigned int * P_hw_timer; // Points to the HW timer register unsigned int * TX_reg; // LSS PORT // This is the location used by irq3 task to signal it needs the LSS port. When signalled, (TRUE), // ls must wait for a specified amount of time continuing checking for free (FALSE) volatile unsigned int Irq3_flag = FALSE; //----- local variables -------------------------------------------------------- static int irq_number; static int spec_table_len; //----- local functions -------------------------------------------------------- void disable_IRQ3_VM (void); void init_HW_timer (unsigned int usecs); void init_vm_tables (int spec_table_len); //----- init_VM_lib -------------------------------------------------------- void init_VM_lib(unsigned int *p_timer_ctrl_val, unsigned int * p_timer_load_val, int irq_number_val, unsigned int * p_tx_reg, int sp_table_len) { // initialize VM pointer to HW registers P_hw_timer_ctrl = p_timer_ctrl_val; // Points to the HW timer control register P_hw_timer = p_timer_load_val; // Points to the HW timer control register TX_reg = p_tx_reg; // init interrupt number and other static vars irq_number = irq_number_val; spec_table_len = sp_table_len; // loads the VM programs init_vm_tables(spec_table_len); } //----- VM_init_spec_table -------------------------------------------------------- //! To copy the configured spectroscopy table into the VM working table void VM_init_spec_table(unsigned int * Conf_Spectroscopy_table, int word_num) { int i; for (i=0; i< word_num; i++) VM_Spectroscopy_table[i] = Conf_Spectroscopy_table[i]; } //----- prepare_VM_total_power -------------------------------------------------------- //! To init VM data required for total power void prepare_VM_total_power(unsigned int aid, unsigned int flush_event, unsigned int mon_event) { Code[VM_LEN - spec_table_len + AID_SP_IDX] = aid; VM_Spectroscopy_table[HIF_EVENT_CODE_IDX] = flush_event; /* event that triggers hs_flush */ VM_Spectroscopy_table[HIF_EVENT_COUNTER_CODE_IDX] = mon_event; /* event that triggers vm_mon */ } //----- prepare_VM_slow_chop -------------------------------------------------------- //! To init VM data required for slow chop void prepare_VM_slow_chop(unsigned int aid, unsigned int flush_event, unsigned int mon_event, unsigned int rot1, unsigned int rot2) { Code[VM_LEN - spec_table_len + AID_SP_IDX] = aid; VM_Spectroscopy_table[HIF_EVENT_CODE_IDX] = flush_event; /* event that triggers hs_flush */ VM_Spectroscopy_table[HIF_EVENT_COUNTER_CODE_IDX] = mon_event; /* event that triggers vm_mon */ // commands for the chopper VM_Spectroscopy_table[HIF_CPR_CH_ROT1_IDX] = rot1; VM_Spectroscopy_table[HIF_CPR_CH_ROT2_IDX] = rot2; } //----- prepare_VM_freq_switch -------------------------------------------------------- //! To init VM data required for frequency switch void prepare_VM_freq_switch(unsigned int aid, unsigned int flush_event, unsigned int mon_event, unsigned int freq1, unsigned int freq2) { Code[VM_LEN - spec_table_len + AID_SP_IDX] = aid; VM_Spectroscopy_table[HIF_EVENT_CODE_IDX] = flush_event; /* event that triggers hs_flush */ VM_Spectroscopy_table[HIF_EVENT_COUNTER_CODE_IDX] = mon_event; /* event that triggers vm_mon */ // commands for the chopper VM_Spectroscopy_table[HIF_CPR_CH_ROT1_IDX] = freq1; VM_Spectroscopy_table[HIF_CPR_CH_ROT2_IDX] = freq2; } //----- prepare_VM_fast_chop -------------------------------------------------------- //! To init VM data required for fast chop void prepare_VM_fast_chop(unsigned int aid, unsigned int flush_event, unsigned int mon_event, unsigned int rot1, unsigned int rot2, unsigned int n_wbs, unsigned int hrs_trans, unsigned int hrs_per_wbs_idx) { VM_Spectroscopy_table[hrs_per_wbs_idx] = 1; // always 1 in fast chop Code[VM_LEN - spec_table_len + AID_SP_IDX] = aid; VM_Spectroscopy_table[HIF_EVENT_CODE_IDX] = flush_event; /* event that triggers hs_flush */ VM_Spectroscopy_table[HIF_EVENT_COUNTER_CODE_IDX] = mon_event; /* event that triggers vm_mon */ // commands for the chopper VM_Spectroscopy_table[HIF_CPR_CH_ROT1_IDX] = rot1; VM_Spectroscopy_table[HIF_CPR_CH_ROT2_IDX] = rot2; VM_Spectroscopy_table[HIF_N_WBS1_IDX] = n_wbs; VM_Spectroscopy_table[HIF_N_HRS_TRANS_IDX] = hrs_trans; } //----- disable_IRQ3_VM -------------------------------------------------------- //! To disable IRQ3 and put the Hardware timer in stop state. void disable_IRQ3_VM (void) { * P_hw_timer_ctrl = 0x1; // Stop counting, disable IRQ, Reset Timer KS_ISRDisable(irq_number); return; } //------------------------- stop_VM -------------------------------------------- // switch VM off void stop_VM (void) { disable_IRQ3_VM(); // disable IRQ3 Irq3_flag = FALSE; // Enable LSS operation. Force no pending requests EndProg = TRUE; // Means that VM is not running } //------------------------- start_VM ------------------------------------------- void start_VM (int VM_program) { Irq3_flag = FALSE; // Enable LSS operation. Force no pending requests EndProg = FALSE; ProgC = Code[VM_program]; // choose the VM program SUbind = -1; // initialize the VM stack pointer init_HW_timer(1000); // starts the hw timer with a delay of 1000 microsecs KS_ISREnable(irq_number); // Virtual machine starts now (after 1 msec) } //------------- init_HW_timer -------------------------------------------------- //! To make the HW timer operational. /*Starts the timer after writing the appropriate registers; argument usecs is the delay expressed in microseconds */ void init_HW_timer (unsigned int usecs) { *P_hw_timer_ctrl = 0x1; // Disable IRQ, Stop count, Reset Timer *P_hw_timer_ctrl = 0x0; // Disable IRQ, Stop Count, Active Timer *P_hw_timer = usecs; // # of microseconds of periodic IRQ3 KS_ISREnable(irq_number); // enable the irq3 *P_hw_timer_ctrl = 0x6; // Enable IRQ, Start count, Active Timer } /*************************************************************************************************************** *************************************************************************************************************** VIRTUAL MACHINE MEMORY AREA *************************************************************************************************************** ***************************************************************************************************************/ // VM program memory unsigned int Code[VM_LEN] = { 0x00000008, 0x00000200, 0x00000400, 0x00000800, 0x00000800, 0x00000800, 0x00000800, 0x00000800 }; // lens of VM programs #define TOTAL_POWER_PROG_LEN 183 #define SLOW_CHOP_PROG_LEN 213 #define FAST_CHOP_PROG_LEN 261 unsigned int VMPROG_total_power[TOTAL_POWER_PROG_LEN] = { 0x1200000c, 0x00000002, 0x4b0c1fc3, 0x4000006a, 0x400000a3, 0x08000bb8, 0x01000001, 0x09000001, 0xd7200000, 0xdb200000, 0xd7300000, 0xdb300000, 0x40000063, 0x0050000b, 0x0060000b, 0x32060002, 0x3000000b, 0x12000000, 0x000186a0, 0x40000055, 0x02000000, 0x20000008, 0x40000055, 0xfc000003, 0x1200000c, 0x00000000, 0x400000b3, 0x20030002, 0x32030002, 0x3000001a, 0x40000063, 0x0050000b, 0x0060000b, 0x20000005, 0x40000055, 0xff800000, 0x1200000c, 0x00000001, 0x400000b3, 0x20000004, 0x40000055, 0xff900000, 0x40000063, 0x0050000b, 0x0060000b, 0xd7400000, 0x1200000c, 0x00000004, 0x400000b3, 0xdb400000, 0x1200000c, 0x00000005, 0x400000b3, 0x11000003, 0x3203ffe8, 0x32060002, 0x30000011, 0x20000007, 0x40000055, 0xfc000005, 0x12000000, 0x00002ee0, 0x40000055, 0xe4000006, 0x1200000c, 0x00000002, 0x400000b3, 0xe8000006, 0x1200000c, 0x00000003, 0x400000b3, 0x11000006, 0x3206ffcd, 0x01000000, 0x490d1fc4, 0x5700000d, 0x50000000, 0x34000001, 0x41000000, 0x1200000c, 0x00000bb8, 0x210c0c01, 0x3400000c, 0x30000004, 0x220c000c, 0x0900000c, 0x01000000, 0x08000bb8, 0x01000001, 0x09000001, 0x41000000, 0x4a0b0009, 0x10000009, 0x3409000a, 0x30000003, 0x12000009, 0x000000bb, 0x41000000, 0x12000001, 0x000007d0, 0x49041f87, 0x1200000c, 0x00000003, 0x3504000c, 0x30000004, 0x12000004, 0x00000002, 0x30000007, 0x1200000c, 0x00000006, 0x3504000c, 0x30000003, 0x12000004, 0x00000005, 0x15000004, 0x000003e8, 0x49031f81, 0x20020003, 0x12000009, 0x000000bb, 0x1200000a, 0x000000be, 0x49061f80, 0x49051f84, 0x1200000c, 0x00000003, 0x3505000c, 0x30000004, 0x12000005, 0x00000002, 0x30000007, 0x1200000c, 0x00000006, 0x3505000c, 0x30000003, 0x12000005, 0x00000005, 0x15000005, 0x000003e8, 0x49071f86, 0x15000007, 0x000003e8, 0x49081f85, 0x15000008, 0x000003e8, 0x200c0001, 0x1500000c, 0x00000006, 0x210d0c05, 0x210d0d04, 0x230d0d02, 0x3407000d, 0x200d0007, 0x2207070d, 0x41000000, 0x1200000d, 0x00001fc6, 0x1200000c, 0x00000000, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x41000000, 0x1300000c, 0x00001fc6, 0x4a0d000c, 0x1000000d, 0x4c0d000c, 0x490d1fc5, 0x5700000d, 0x41000000, 0x03000000, 0x03200000, 0x03100000, 0x03300000}; unsigned int VMPROG_slow_chop[SLOW_CHOP_PROG_LEN] = { 0x1200000c, 0x00000002, 0x4b0c1fc3, 0x4000026d, 0x400002b4, 0x08000bb8, 0x01000001, 0x09000001, 0xd7200000, 0xdb200000, 0xd7300000, 0xdb300000, 0x4000025f, 0x0050000b, 0x0060000b, 0x32060002, 0x3000000f, 0x12000000, 0x000186a0, 0x40000251, 0x40000266, 0x32100003, 0x02000000, 0x30000002, 0x04000010, 0x20000008, 0x40000251, 0xfc000003, 0x1200000c, 0x00000000, 0x400002c4, 0x20030002, 0x32030002, 0x3000001a, 0x4000025f, 0x0050000b, 0x0060000b, 0x20000005, 0x40000251, 0xff800000, 0x1200000c, 0x00000001, 0x400002c4, 0x20000004, 0x40000251, 0xff900000, 0x4000025f, 0x0050000b, 0x0060000b, 0xd7400000, 0x1200000c, 0x00000004, 0x400002c4, 0xdb400000, 0x1200000c, 0x00000005, 0x400002c4, 0x11000003, 0x3203ffe8, 0x32060002, 0x30000011, 0x20000007, 0x40000251, 0xfc000005, 0x12000000, 0x00002ee0, 0x40000251, 0xe4000006, 0x1200000c, 0x00000002, 0x400002c4, 0xe8000006, 0x1200000c, 0x00000003, 0x400002c4, 0x11000006, 0x3206ffc8, 0x01000000, 0x490d1fc4, 0x5700000d, 0x50000000, 0x34000001, 0x41000000, 0x1200000c, 0x00000bb8, 0x210c0c01, 0x3400000c, 0x30000004, 0x220c000c, 0x0900000c, 0x01000000, 0x08000bb8, 0x01000001, 0x09000001, 0x41000000, 0x4a0b0009, 0x10000009, 0x3409000a, 0x30000003, 0x12000009, 0x000002cc, 0x41000000, 0x4a10000e, 0x1000000e, 0x340e000f, 0x30000003, 0x1200000e, 0x000002d1, 0x41000000, 0x12000001, 0x000007d0, 0x49041f87, 0x1200000c, 0x00000003, 0x3504000c, 0x30000004, 0x12000004, 0x00000002, 0x30000007, 0x1200000c, 0x00000006, 0x3504000c, 0x30000003, 0x12000004, 0x00000005, 0x15000004, 0x000003e8, 0x49031f81, 0x20020003, 0x12000009, 0x000002cc, 0x1200000a, 0x000002cf, 0x1200000e, 0x000002d0, 0x490c1fa0, 0x490d1fa1, 0x4c0c000e, 0x1000000e, 0x4c0d000e, 0x1000000e, 0x1000000e, 0x4c0c000e, 0x1200000e, 0x000002d0, 0x1200000f, 0x000002d4, 0x49061f80, 0x49051f84, 0x1200000c, 0x00000003, 0x3505000c, 0x30000004, 0x12000005, 0x00000002, 0x30000007, 0x1200000c, 0x00000006, 0x3505000c, 0x30000003, 0x12000005, 0x00000005, 0x15000005, 0x000003e8, 0x49071f86, 0x15000007, 0x000003e8, 0x49081f85, 0x15000008, 0x000003e8, 0x200c0001, 0x1500000c, 0x00000006, 0x210d0c05, 0x210d0d04, 0x230d0d02, 0x3407000d, 0x200d0007, 0x2207070d, 0x41000000, 0x1200000d, 0x00001fc6, 0x1200000c, 0x00000000, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x41000000, 0x1300000c, 0x00001fc6, 0x4a0d000c, 0x1000000d, 0x4c0d000c, 0x490d1fc5, 0x5700000d, 0x41000000, 0x03000000, 0x03200000, 0x03100000, 0x03300000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}; unsigned int VMPROG_fast_chop[FAST_CHOP_PROG_LEN] = { 0x1200000c, 0x00000002, 0x4b0c1fc3, 0x40000496, 0x400004e7, 0x08000bb8, 0x01000001, 0x09000001, 0x32060002, 0x3000006d, 0x32150002, 0x3000006b, 0xd7200000, 0xdb200000, 0xd7300000, 0xdb300000, 0x40000488, 0x0050000b, 0x0060000b, 0x12000000, 0x000186a0, 0x4000047a, 0x20140015, 0x4000048f, 0x04000010, 0x20000008, 0x4000047a, 0xfc000003, 0x1200000c, 0x00000000, 0x400004f7, 0x20030002, 0x32030002, 0x3000001a, 0x40000488, 0x0050000b, 0x0060000b, 0x20000005, 0x4000047a, 0xff800000, 0x1200000c, 0x00000001, 0x400004f7, 0x20000004, 0x4000047a, 0xff900000, 0x40000488, 0x0050000b, 0x0060000b, 0xd7400000, 0x1200000c, 0x00000004, 0x400004f7, 0xdb400000, 0x1200000c, 0x00000005, 0x400004f7, 0x11000003, 0x3203ffe8, 0x32140002, 0x30000006, 0x20000007, 0x4000047a, 0xfc000005, 0x11000014, 0x3214ffd6, 0x12000000, 0x00002ee0, 0x4000047a, 0x12000016, 0x00000002, 0xe4000006, 0x1200000c, 0x00000002, 0x400004f7, 0xe8000006, 0x1200000c, 0x00000003, 0x400004f7, 0x20180017, 0x32180005, 0x12000000, 0x000dbba0, 0x4000047a, 0x3000001e, 0x4000048f, 0x04000010, 0x40000488, 0x0050000b, 0x0060000b, 0x20000005, 0x4000047a, 0xff800000, 0x1200000c, 0x00000001, 0x400004f7, 0x20000004, 0x4000047a, 0xff900000, 0x40000488, 0x0050000b, 0x0060000b, 0xd7400000, 0x1200000c, 0x00000004, 0x400004f7, 0xdb400000, 0x1200000c, 0x00000005, 0x400004f7, 0x11000018, 0x3218ffe6, 0x20000019, 0x4000047a, 0x11000016, 0x3216ffd4, 0x11000006, 0x3206ffa1, 0x01000000, 0x490d1fc4, 0x5700000d, 0x50000000, 0x34000001, 0x41000000, 0x1200000c, 0x00000bb8, 0x210c0c01, 0x3400000c, 0x30000004, 0x220c000c, 0x0900000c, 0x01000000, 0x08000bb8, 0x01000001, 0x09000001, 0x41000000, 0x4a0b0009, 0x10000009, 0x3409000a, 0x30000003, 0x12000009, 0x000004ff, 0x41000000, 0x4a10000e, 0x1000000e, 0x340e000f, 0x30000003, 0x1200000e, 0x00000503, 0x41000000, 0x12000001, 0x000007d0, 0x49041f87, 0x1200000c, 0x00000003, 0x3504000c, 0x30000004, 0x12000004, 0x00000002, 0x30000007, 0x1200000c, 0x00000006, 0x3504000c, 0x30000003, 0x12000004, 0x00000005, 0x15000004, 0x000003e8, 0x49031f81, 0x20020003, 0x49171f9f, 0x12000009, 0x000004ff, 0x1200000a, 0x00000502, 0x1200000e, 0x00000503, 0x490c1fa0, 0x490d1fa1, 0x4c0c000e, 0x1000000e, 0x4c0d000e, 0x1200000e, 0x00000503, 0x1200000f, 0x00000504, 0x49061f80, 0x49151f9e, 0x49051f84, 0x1200000c, 0x00000003, 0x3505000c, 0x30000004, 0x12000005, 0x00000002, 0x30000007, 0x1200000c, 0x00000006, 0x3505000c, 0x30000003, 0x12000005, 0x00000005, 0x15000005, 0x000003e8, 0x49071f86, 0x15000007, 0x000003e8, 0x49081f85, 0x15000008, 0x000003e8, 0x200c0001, 0x1500000c, 0x00000006, 0x210d0c05, 0x210d0d04, 0x230d0d02, 0x3407000d, 0x200d0007, 0x2207070d, 0x200c0001, 0x1500000c, 0x00000007, 0x210d0c05, 0x210d0d04, 0x230d0d17, 0x1200000c, 0x000dbba0, 0x340c000d, 0x200d000c, 0x22190c0d, 0x41000000, 0x1200000d, 0x00001fc6, 0x1200000c, 0x00000000, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x1000000d, 0x4c0c000d, 0x41000000, 0x1300000c, 0x00001fc6, 0x4a0d000c, 0x1000000d, 0x4c0d000c, 0x490d1fc5, 0x5700000d, 0x41000000, 0x03000000, 0x03200000, 0x03100000, 0x03300000, 0x00000000, 0x00000000}; // VM spectroscpy table unsigned int * VM_Spectroscopy_table; // the spec table for the VM //----------- init_vm_tables --------------------------------------------------- void init_vm_tables (int spec_table_len) { int start, i; // copy total power program start = Code[0]; for (i = 0; i < TOTAL_POWER_PROG_LEN; i++) Code[start + i] = VMPROG_total_power[i]; // copy slow chop program start = Code[1]; for (i = 0; i < SLOW_CHOP_PROG_LEN; i++) Code[start + i] = VMPROG_slow_chop[i]; // copy fast chop program start = Code[2]; for (i = 0; i < FAST_CHOP_PROG_LEN; i++) Code[start + i] = VMPROG_fast_chop[i]; // init the pointer to the spectroscopy table VM_Spectroscopy_table = &Code[VM_LEN - spec_table_len]; }