Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void vPS_WriteSlaveStrobe(bool bSet)
- {
- if (bSet)
- SET_PORT(GPIOE,B8);
- else
- CLR_PORT(GPIOE,B8);
- }
- static bool inline bPS_ReadMasterStrobe(void)
- {
- if (GPIOE->IDR & B7)
- return true;
- else
- return false;
- }
- static bool inline bPS_ReadCMDorDATA(void)
- {
- if (GPIOE->IDR & B10)
- return true;
- else
- return false;
- }
- static bool inline bPS_ReadEXTRA(void)
- {
- if (GPIOE->IDR & B9)
- return true;
- else
- return false;
- }
- static void vPS_WriteData(u8 u8Val)
- {
- // D0
- if (u8Val & 0x01)
- SET_PORT(GPIOE,B11);
- else
- CLR_PORT(GPIOE,B11);
- // D1
- if (u8Val & 0x02)
- SET_PORT(GPIOE,B12);
- else
- CLR_PORT(GPIOE,B12);
- // D2
- if (u8Val & 0x04)
- SET_PORT(GPIOE,B13);
- else
- CLR_PORT(GPIOE,B13);
- // D3
- if (u8Val & 0x08)
- SET_PORT(GPIOE,B14);
- else
- CLR_PORT(GPIOE,B14);
- // D4
- if (u8Val & 0x10)
- SET_PORT(GPIOE,B15);
- else
- CLR_PORT(GPIOE,B15);
- // D5
- if (u8Val & 0x20)
- SET_PORT(GPIOD,B8);
- else
- CLR_PORT(GPIOD,B8);
- // D6
- if (u8Val & 0x40)
- SET_PORT(GPIOD,B9);
- else
- CLR_PORT(GPIOD,B9);
- // D7
- if (u8Val & 0x80)
- SET_PORT(GPIOD,B10);
- else
- CLR_PORT(GPIOD,B10);
- }
- static u8 u8PS_ReadData(void)
- {
- u8 u8Res;
- u8Res = 0x00;
- // D0
- if (GPIOE->IDR & B11)
- u8Res |= 0x01;
- // D1
- if (GPIOE->IDR & B12)
- u8Res |= 0x02;
- // D2
- if (GPIOE->IDR & B13)
- u8Res |= 0x04;
- // D3
- if (GPIOE->IDR & B14)
- u8Res |= 0x08;
- // D4
- if (GPIOE->IDR & B15)
- u8Res |= 0x10;
- // D5
- if (GPIOD->IDR & B8)
- u8Res |= 0x20;
- // D6
- if (GPIOD->IDR & B9)
- u8Res |= 0x40;
- // D7
- if (GPIOD->IDR & B10)
- u8Res |= 0x80;
- return u8Res;
- }
- static bool bPS_ReadByte(u8 *pu8Val,bool *pbCorD, bool *pbExtra)
- {
- // Make sure the port is an input
- vPS_SetDataPortToInput();
- __DMB();
- while(bPS_ReadMasterStrobe() == true)
- {
- }
- *pbCorD = bPS_ReadCMDorDATA();
- *pbExtra = bPS_ReadEXTRA();
- *pu8Val = u8PS_ReadData();
- __DMB();
- vPS_WriteSlaveStrobe(false);
- while(bPS_ReadMasterStrobe() == false)
- {
- }
- vPS_WriteSlaveStrobe(true);
- __DMB();
- // We're okay
- return true;
- }
- // Use both edges of the strobes to send two bytes
- static bool bPS_ReadMultipleWord(int iCnt,u8 *pu8Data)
- {
- // Make sure the port is an input
- vPS_SetDataPortToInput();
- __DMB();
- while (iCnt--)
- {
- while(bPS_ReadMasterStrobe() == true)
- {
- }
- *pu8Data++ = u8PS_ReadData(); // Read it
- __DMB();
- vPS_WriteSlaveStrobe(false);
- while(bPS_ReadMasterStrobe() == false)
- {
- }
- *pu8Data++ = u8PS_ReadData(); // Read it
- __DMB();
- vPS_WriteSlaveStrobe(true);
- }
- // We're okay
- return true;
- }
- static bool bPS_WriteByte(u8 u8Val)
- {
- while(bPS_ReadMasterStrobe() == true)
- {
- }
- vPS_WriteData(u8Val);
- vPS_SetDataPortToOutput();
- __DMB();
- vPS_WriteSlaveStrobe(false);
- __DMB();
- while(bPS_ReadMasterStrobe() == false)
- {
- }
- vPS_SetDataPortToInput();
- vPS_WriteSlaveStrobe(true);
- __DMB();
- // We're okay
- return true;
- }
- // Use both edges of the strobes to send two bytes
- static bool bPS_WriteMultipleWord(int iCnt,u8 *pu8Data)
- {
- // Wait until the master is reading
- while(bPS_ReadMasterStrobe() == true)
- {
- }
- vPS_SetDataPortToOutput(); // Drive the port lines
- while (iCnt--)
- {
- // Wait until the master is reading
- while(bPS_ReadMasterStrobe() == true)
- {
- }
- vPS_WriteData(*pu8Data++);
- __DMB();
- vPS_WriteSlaveStrobe(false);
- __DMB();
- // Wait for the master to indicate it has read the port
- while(bPS_ReadMasterStrobe() == false)
- {
- }
- vPS_WriteData(*pu8Data++);
- __DMB();
- vPS_WriteSlaveStrobe(true);
- __DMB();
- }
- // We're okay
- return true;
- }
- ////////////// The code in main
- // Handle ParaSys
- while (true)
- {
- if (bPS_ReadByte(&u8CMD,&bCorD,&bExtra))
- {
- // We're only going to respond to bytes sent with bExtra high
- if (bExtra)
- {
- switch(u8CMD)
- {
- case 0x10: // Read a block
- bCmdOK = bPS_ReadByte(&u8DEVICE,&bCorD,&bExtra);
- if (bExtra == false)
- {
- bCmdOK &= bPS_ReadByte(&u8BLOCK,&bCorD,&bExtra);
- if (bExtra == false)
- {
- bCmdOK &= bPS_ReadByte(&u8PART,&bCorD,&bExtra);
- if (bExtra == false)
- {
- // vWriteTxCRLF_UART1();
- // vWriteTxHex8_UART1(u8DEVICE);
- // vWriteTxHex8_UART1(u8BLOCK);
- // vWriteTxHex8_UART1(u8PART);
- // vWriteTxSPACE_UART1();
- // Is this a request for block we have in the buffer?
- if ((u8PART == 0) || (u8DEVICE != u8BR_DEVICE) || (u8BLOCK != u8BR_BLOCK))
- {
- // No, read it
- u8BR_DEVICE = u8DEVICE;
- u8BR_BLOCK = u8BLOCK;
- // Read the SD card
- if (!bReadBasilBlock(u8BR_DEVICE,u8BR_BLOCK,u8BR_BUFFER))
- {
- for(i=0;i<0x1000;i++)
- u8BR_BUFFER[i]=0xE5;
- }
- }
- // We need to write this block
- bPS_WriteMultipleWord(32,&u8BR_BUFFER[u8PART*64]);
- // Done?
- if (u8PART == 0x3F)
- {
- vWriteTxStr_UART1("\r\nRead Block ");
- vWriteTxHex8_UART1(u8DEVICE);
- vWriteTxHex8_UART1(u8BLOCK);
- }
- }
- }
- }
- break;
- case 0x11: // Write a block
- bCmdOK = bPS_ReadByte(&u8DEVICE,&bCorD,&bExtra);
- if (bExtra == false)
- {
- bCmdOK &= bPS_ReadByte(&u8BLOCK,&bCorD,&bExtra);
- if (bExtra == false)
- {
- bCmdOK &= bPS_ReadByte(&u8PART,&bCorD,&bExtra);
- if (bExtra == false)
- {
- // vWriteTxCRLF_UART1();
- // vWriteTxHex8_UART1(u8DEVICE);
- // vWriteTxHex8_UART1(u8BLOCK);
- // vWriteTxHex8_UART1(u8PART);
- // vWriteTxSPACE_UART1();
- // Start a new buffer
- if ((u8PART == 0) || (u8DEVICE != u8BW_DEVICE) || (u8BLOCK != u8BW_BLOCK))
- {
- u8BW_DEVICE = u8DEVICE;
- u8BW_BLOCK = u8BLOCK;
- u8BW_PART = 0;
- }
- // Is this what we're expecting?
- if ((u8PART == u8BW_PART) && (u8DEVICE == u8BW_DEVICE) && (u8BLOCK == u8BW_BLOCK))
- {
- // We need to read this block
- bPS_ReadMultipleWord(32,&u8BW_BUFFER[u8BW_PART*64]);
- // And move to the next part
- u8BW_PART++;
- // Is our buffer full?
- if (u8BW_PART == 0x40)
- {
- vWriteTxStr_UART1("\r\nWrite Block ");
- vWriteTxHex8_UART1(u8DEVICE);
- vWriteTxHex8_UART1(u8BLOCK);
- if (!bWriteBasilBlock(u8BW_DEVICE,u8BW_BLOCK,u8BW_BUFFER))
- {
- vWriteTxStr_UART1(" - FAILED!!!\r\n");
- }
- }
- }
- else
- {
- // Now we need to read and ignore the 64-bytes
- for(i=0;i<64;i++)
- {
- bCmdOK &= bPS_ReadByte(&u8VALUE,&bCorD,&bExtra);
- }
- }
- }
- }
- }
- break;
- case 0x12: // Set a filename
- bCmdOK = bPS_ReadByte(&u8DEVICE,&bCorD,&bExtra);
- if (u8DEVICE < 4)
- {
- u8 *pu8FileName = sDiskFilenames[u8DEVICE];
- if (bExtra == false)
- {
- // Read the filename until a zero
- do {
- bCmdOK &= bPS_ReadByte(&u8VALUE,&bCorD,&bExtra);
- *pu8FileName++ = u8VALUE;
- } while(u8VALUE != 0);
- }
- vWriteTxStr_UART1("\r\nSet Filename ");
- vWriteTxHex8_UART1(u8DEVICE);
- vWriteTxStr_UART1(" [");
- vWriteTxStr_UART1(sDiskFilenames[u8DEVICE]);
- vWriteTxStr_UART1("]");
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement