'East Buffer 'This is a final version 4 for ARM Cellputer 'Compatibility code: 2.4 '29.12.08 'PIII version 'Timer implemented $regfile = "89c2051.dat" $crystal = 24000000 'chip sygnature 'North: 1..30 'East:101..130 Dim Sgn As Byte Dim D32 As Long Dim B32(13) As Long ' '1 - 4 : internal vars ' 5 : internal obj '6 - 9 : external vars / internal results ' 10 : external obj ' 11 : iter ' 12 : compressed info ' 13 : common 32-bit data ' Dim L32 As Byte Dim N32 As Byte Dim Iio As Byte Dim Jio As Byte Dim I As Byte Dim A1 As Byte Dim A2 As Byte Dim C1 As Byte Dim C2 As Byte Dim Addr As Byte Dim Cycles_count As Byte Dim Actv As Bit Dim T0int As Bit Dim Z As Bit Config Timer0 = Timer , Gate = Internal , Mode = 1 Declare Sub Bwait_ck(z As Bit) Declare Sub Bwait_cki(z As Bit) Declare Sub Bwait_cko(z As Bit) Declare Sub Rec_host 'Addr is a variable Declare Sub Send_host(l32 As Byte , N32 As Byte) Declare Sub Host Declare Sub Rec_int(l32 As Byte , N32 As Byte) Declare Sub Send_int(l32 As Byte , N32 As Byte) Declare Sub Rec_ext(l32 As Byte , N32 As Byte) Declare Sub Send_ext(l32 As Byte , N32 As Byte) Declare Sub Take_int_data Declare Sub Give_int_data Declare Sub Take_ext_data Declare Sub Give_ext_data Declare Sub Get_info Declare Sub Get_results Ledg Alias P3.0 'green En Alias P3.7 'enable pin (output) Dt Alias P1.0 'data pin (input/output) Ck Alias P1.1 'clock pin (input) Cko Alias P1.5 'clock (input) Txo Alias P1.4 'transmitter (output) Rxo Alias P1.3 'receiver (input) Rdo Alias P1.2 'ready (output) Cki Alias P3.5 'clock (input) Txi Alias P3.4 'transmitter (output) Rxi Alias P3.3 'receiver (input) Rdi Alias P3.2 'ready (output) P1 = &B11111111 'set Rdo P3 = &B01111111 'set Rdi, reset En 'initialization On Timer0 Timer_interrupt Enable Interrupts Enable Timer0 Priority Set Timer0 Reset T0int 'motherboard selftest Bitwait Cki , Reset Reset Ledg Reset Rdi Delay Bitwait Cki , Set Set Ledg 'getting address Call Rec_int(7 , 13) Sgn = B32(13) 'external motherboard selftest Bitwait Cko , Reset Reset Ledg Reset Rdo Delay Bitwait Cko , Set Set Ledg Delay Set En 'notification to host Do Bitwait En , Set Call Rec_host If Addr = Sgn Then Reset En Call Send_host(7 , 13) End If Delay Set En Loop Until Addr = 100 'waiting to the end of data transmission Do Bitwait En , Set Call Rec_host Delay Loop Until Addr = 210 'CRC Call Rec_int(31 , 12) 'host rechecking Do Bitwait En , Set Call Rec_host If Addr = Sgn Then Reset En Call Send_host(7 , 13) Call Send_host(31 , 12) End If Delay Set En Loop Until Addr = 100 'running 'initializations - buffer is empty B32(5) = 0 B32(10) = 0 Reset Actv Set T0int Do Strt: If T0int = 1 Then Set Dt Set En Reset Rdi Reset Rdo Reset T0int End If If Actv = 1 Then Call Host 'checking internal ARM Set Rdi Waitms 10 If Cki = 0 Then Reset Rdi Cycles_count = 0 Start Timer0 Call Bwait_cki(1) Call Rec_int(7 , 13) A1 = B32(13) If A1 = 10 Or A1 = 20 Then C1 = A1 Set Actv End If Select Case A1 Case 10 : Call Get_info Case 20 : Call Get_results Case 100 : Call Take_int_data Case 200 : Call Give_int_data End Select Counter0 = 0 If T0int = 1 Then Goto Strt End If Reset Rdi 'checking external ARM Set Rdo Waitms 10 If Cko = 0 Then Reset Rdo Cycles_count = 0 Start Timer0 Call Bwait_cko(1) Call Rec_ext(7 , 13) A2 = B32(13) Select Case A2 Case 100 : Call Take_ext_data Case 200 : Call Give_ext_data End Select Counter0 = 0 End If Reset Rdo Loop End 'IO routines Sub Host 'jesli jest cos do przeslania, to ma na to ok. 8 sek... Reset Ledg Cycles_count = 0 C2 = 0 Start Timer0 Do 'synchronizacja Bitwait En , Set Bitwait En , Reset Call Rec_host 'counter - maybe this cell is already switched off Incr C2 If C2 > 30 Then Actv = 0 If T0int = 1 Then Exit Do If Addr = Sgn Then 'komenda B32(13) = C1 Call Send_host(7 , 13) 'info If C1 = 10 Then 'iteracja Call Send_host(7 , 11) 'NEWS migration statistics 'max i avg fitness (*10) Call Send_host(31 , 12) End If If C1 = 20 Then 'wyniki (*10000) For Jio = 6 To 9 Call Send_host(31 , Jio) Next Jio 'wyniki przeslane End If 'informacja przeslana, skrzynka pusta Reset Actv End If Loop Until Actv = 0 Counter0 = 0 End Sub Sub Bwait_ck(z As Bit) Do : Loop Until Ck = Z Or T0int = 1 End Sub Sub Bwait_cki(z As Bit) Do : Loop Until Cki = Z Or T0int = 1 End Sub Sub Bwait_cko(z As Bit) Do : Loop Until Cko = Z Or T0int = 1 End Sub Sub Send_host(l32 As Byte , N32 As Byte) D32 = B32(n32) Reset Ledg For Iio = 0 To L32 If T0int = 1 Then Exit For Dt = D32.iio Call Bwait_ck(0) Call Bwait_ck(1) Next Iio Set Ledg Set Dt End Sub Sub Rec_host Reset Ledg Set Dt For Iio = 0 To 7 Call Bwait_ck(0) Addr.iio = Dt Call Bwait_ck(1) Next Iio If T0int = 1 Then Addr = 0 Set Ledg End Sub Sub Send_int(l32 As Byte , N32 As Byte) If T0int = 1 Then Exit Sub D32 = B32(n32) Reset Ledg Set Rdi For Iio = 0 To L32 Txi = D32.iio Call Bwait_cki(0) Delay Reset Rdi Call Bwait_cki(1) If T0int = 1 Then Exit For Delay Set Rdi Next Iio Call Bwait_cki(0) Delay Reset Rdi Call Bwait_cki(1) Set Ledg End Sub Sub Rec_int(l32 As Byte , N32 As Byte) D32 = 0 If T0int = 1 Then Exit Sub Reset Ledg Set Rdi For Iio = 0 To L32 Call Bwait_cki(0) D32.iio = Rxi Delay Reset Rdi Call Bwait_cki(1) If T0int = 1 Then Exit For Delay Set Rdi Next Iio Call Bwait_cki(0) Delay Reset Rdi Call Bwait_cki(1) If T0int = 0 Then B32(n32) = D32 Set Ledg End Sub Sub Send_ext(l32 As Byte , N32 As Byte) If T0int = 1 Then Exit Sub D32 = B32(n32) Reset Ledg Set Rdo For Iio = 0 To L32 Txo = D32.iio Call Bwait_cko(0) Delay Reset Rdo Call Bwait_cko(1) If T0int = 1 Then Exit For Delay Set Rdo Next Iio Call Bwait_cko(0) Delay Reset Rdo Call Bwait_cko(1) Set Ledg End Sub Sub Rec_ext(l32 As Byte , N32 As Byte) D32 = 0 If T0int = 1 Then Exit Sub Reset Ledg Set Rdo For Iio = 0 To L32 Call Bwait_cko(0) D32.iio = Rxo Delay Reset Rdo Call Bwait_cko(1) If T0int = 1 Then Exit For Delay Set Rdo Next Iio Call Bwait_cko(0) Delay Reset Rdo Call Bwait_cko(1) If T0int = 0 Then B32(n32) = D32 Set Ledg End Sub Sub Take_int_data For Jio = 1 To 5 Call Rec_int(31 , Jio) Next Jio If T0int = 1 Then B32(5) = 0 End Sub Sub Give_int_data For Jio = 6 To 10 Call Send_int(31 , Jio) Next Jio End Sub Sub Take_ext_data For Jio = 6 To 10 If C1 < 20 Then Call Rec_ext(31 , Jio) Else Call Rec_ext(31 , 13) End If Next Jio If T0int = 1 Then B32(10) = 0 End Sub Sub Give_ext_data For Jio = 1 To 5 Call Send_ext(31 , Jio) Next Jio End Sub Sub Get_info 'iteracja Call Rec_int(7 , 11) 'NEWS migration statistics 'max i avg fitness (*10) Call Rec_int(31 , 12) End Sub Sub Get_results 'wyniki (*10000) For Jio = 6 To 9 Call Rec_int(31 , Jio) Next Jio End Sub Timer_interrupt: 'reset counter Counter0 = 0 'every 33ms Inc Cycles_count 'every 8sec If Cycles_count = 250 Then Set T0int Else Start Timer0 End If Return