'North Buffer 'This is a final version 4 for ARM Cellputer 'Compatibility code: 2.4 '28.11.08 'PIII version 'Timer implemented $regfile = "89c2051.dat" $crystal = 24000000 '$large 'chip sygnature 'North: 1..30 'East:101..130 Const Sgn = 16 Dim D32 As Long Dim B32(11) As Long ' '1 - 4 : internal vars ' 5 : internal obj '6 - 9 : external vars / internal results ' 10 : external obj ' 11 : common 32-bit data ' Dim Addr As Byte Dim L32 As Byte Dim N32 As Byte Dim Iio As Byte Dim Jio As Byte Dim I As Byte Dim Blcfg As Byte Dim A1 As Byte Dim A2 As Byte Dim Cycles_count As Byte 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(l32 As Byte , N32 As Byte) Declare Sub Send_host 'Addr is a variable 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 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 all P3 = &B01111111 '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 'communication test B32(11) = Sgn + 100 Call Send_int(7 , 11) '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(7 , 11) Addr = B32(11) If Addr = Sgn Then Reset En Call Send_host End If Delay Set En Loop Until Addr = 100 'Command 230: reading and writing input data 'sending data simultaneously to ARM Do Bitwait En , Set Call Rec_host(7 , 11) Addr = B32(11) If Addr = 230 Then Reset En For I = 1 To 23 Call Rec_host(15 , 11) Call Send_int(15 , 11) Next I Addr = 255 End If If Addr = Sgn Then Reset En For I = 1 To 19 Call Rec_host(15 , 11) Call Send_int(15 , 11) Next I Addr = 255 End If Delay Set En Loop Until Addr = 210 'host rechecking Do Bitwait En , Set Call Rec_host(7 , 11) Addr = B32(11) If Addr = Sgn Then Reset En Call Send_host End If Delay Set En Loop Until Addr = 100 'running 'initializations - buffer is empty B32(5) = 0 B32(10) = 0 Set T0int Do Strt: 'interrupt occured If T0int = 1 Then Set Dt Set En Reset Rdi Reset Rdo Reset T0int End If '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 , 11) A1 = B32(11) Select Case A1 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 , 11) A2 = B32(11) 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 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 Reset Ledg For Iio = 0 To 7 If T0int = 1 Then Exit For Dt = Addr.iio Call Bwait_ck(0) Call Bwait_ck(1) Next Iio Set Dt Set Ledg End Sub Sub Rec_host(l32 As Byte , N32 As Byte) D32 = 0 Reset Ledg Set Dt For Iio = 0 To L32 Call Bwait_ck(0) D32.iio = Dt Call Bwait_ck(1) Next Iio If T0int = 0 Then B32(n32) = D32 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 Call Rec_ext(31 , Jio) 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 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 '