Subversion Repositories HomeAutomation

Rev

Rev 363 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *                  MAC Module Defs for Microchip Stack
  4.  *
  5.  *********************************************************************
  6.  * FileName:        MAC.h
  7.  * Dependencies:    StackTsk.h
  8.  * Processor:       PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
  9.  * Complier:        Microchip C18 v3.02 or higher
  10.  *                  Microchip C30 v2.01 or higher
  11.  * Company:         Microchip Technology, Inc.
  12.  *
  13.  * Software License Agreement
  14.  *
  15.  * This software is owned by Microchip Technology Inc. ("Microchip")
  16.  * and is supplied to you for use exclusively as described in the
  17.  * associated software agreement.  This software is protected by
  18.  * software and other intellectual property laws.  Any use in
  19.  * violation of the software license may subject the user to criminal
  20.  * sanctions as well as civil liability.  Copyright 2006 Microchip
  21.  * Technology Inc.  All rights reserved.
  22.  *
  23.  * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL
  24.  * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED
  25.  * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
  26.  * INFRINGEMENT.  Microchip shall in no event be liable for special,
  27.  * incidental, or consequential damages.
  28.  *
  29.  *
  30.  * Author               Date        Comment
  31.  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32.  * Nilesh Rajbharti     4/27/01     Original        (Rev 1.0)
  33.  * Nilesh Rajbharti     11/27/01    Added SLIP
  34.  * Nilesh Rajbharti     2/9/02      Cleanup
  35.  * Nilesh Rajbharti     5/22/02     Rev 2.0 (See version.log for detail)
  36.  * Howard Schlunder     6/28/04     Added ENC28J60 specific features
  37.  * Howard Schlunder     11/29/04    Added Get/SetLEDConfig macros
  38.  ********************************************************************/
  39.  
  40. #ifndef MAC_H
  41. #define MAC_H
  42.  
  43. #include "..\Include\StackTsk.h"
  44. #include "..\Include\ENC28J60.h"
  45.  
  46.  
  47. #define MAC_IP      (0u)
  48. #define MAC_ARP     (0x6u)
  49. #define MAC_UNKNOWN (0x0ffu)
  50.  
  51. #define INVALID_BUFFER  (0xffu)
  52.  
  53. /*
  54.  * Microchip Ethernet controller specific MAC items
  55.  */
  56.  
  57. // Duplex configuration options
  58. typedef enum _DUPLEX {
  59.     HALF = 0,
  60.     FULL = 1,
  61.     USE_PHY = 2
  62. } DUPLEX;
  63.  
  64. typedef enum _CLK_CONFIG {
  65.     Divide1,
  66.     Divide2,
  67.     Divide3,
  68.     Divide4,
  69.     Divide8
  70. } CLK_CONFIG;
  71. void    MACSetDuplex(DUPLEX DuplexState);
  72. WORD    CalcIPBufferChecksum(WORD len);
  73.  
  74. void    MACPowerDown(void);
  75. void    MACPowerUp(void);
  76. WORD    MACCalcRxChecksum(WORD offset, WORD len);
  77. WORD    MACCalcTxChecksum(WORD offset, WORD len);
  78. void    MACCopyRxToTx(WORD RxOffset, WORD TxOffset, WORD len);
  79. void    WritePHYReg(BYTE Register, WORD Data);
  80. PHYREG  ReadPHYReg(BYTE Register);
  81. void    SetRXHashTableEntry(MAC_ADDR DestMACAddr);
  82.  
  83. /******************************************************************************
  84.  * Macro:           void SetLEDConfig(WORD NewConfig)
  85.  *
  86.  * PreCondition:    SPI bus must be initialized (done in MACInit()).
  87.  *
  88.  * Input:           NewConfig - xxx0: Pulse stretching disabled
  89.  *                              xxx2: Pulse stretch to 40ms (default)
  90.  *                              xxx6: Pulse stretch to 73ms
  91.  *                              xxxA: Pulse stretch to 139ms
  92.  *                             
  93.  *                              xx1x: LEDB - TX
  94.  *                              xx2x: LEDB - RX (default)
  95.  *                              xx3x: LEDB - collisions
  96.  *                              xx4x: LEDB - link
  97.  *                              xx5x: LEDB - duplex
  98.  *                              xx7x: LEDB - TX and RX
  99.  *                              xx8x: LEDB - on
  100.  *                              xx9x: LEDB - off
  101.  *                              xxAx: LEDB - blink fast
  102.  *                              xxBx: LEDB - blink slow
  103.  *                              xxCx: LEDB - link and RX
  104.  *                              xxDx: LEDB - link and TX and RX
  105.  *                              xxEx: LEDB - duplex and collisions
  106.  *
  107.  *                              x1xx: LEDA - TX
  108.  *                              x2xx: LEDA - RX
  109.  *                              x3xx: LEDA - collisions
  110.  *                              x4xx: LEDA - link (default)
  111.  *                              x5xx: LEDA - duplex
  112.  *                              x7xx: LEDA - TX and RX
  113.  *                              x8xx: LEDA - on
  114.  *                              x9xx: LEDA - off
  115.  *                              xAxx: LEDA - blink fast
  116.  *                              xBxx: LEDA - blink slow
  117.  *                              xCxx: LEDA - link and RX
  118.  *                              xDxx: LEDA - link and TX and RX
  119.  *                              xExx: LEDA - duplex and collisions
  120.  *
  121.  * Output:          None
  122.  *
  123.  * Side Effects:    None
  124.  *
  125.  * Overview:        Writes the value of NewConfig into the PHLCON PHY register.  
  126.  *                  The LED pins will beginning outputting the new
  127.  *                  configuration immediately.
  128.  *
  129.  * Note:            
  130.  *****************************************************************************/
  131. #define SetLEDConfig(NewConfig)     WritePHYReg(PHLCON, NewConfig)
  132.  
  133.  
  134. /******************************************************************************
  135.  * Macro:           WORD GetLEDConfig(void)
  136.  *
  137.  * PreCondition:    SPI bus must be initialized (done in MACInit()).
  138.  *
  139.  * Input:           None
  140.  *
  141.  * Output:          WORD -  xxx0: Pulse stretching disabled
  142.  *                          xxx2: Pulse stretch to 40ms (default)
  143.  *                          xxx6: Pulse stretch to 73ms
  144.  *                          xxxA: Pulse stretch to 139ms
  145.  *                             
  146.  *                          xx1x: LEDB - TX
  147.  *                          xx2x: LEDB - RX (default)
  148.  *                          xx3x: LEDB - collisions
  149.  *                          xx4x: LEDB - link
  150.  *                          xx5x: LEDB - duplex
  151.  *                          xx7x: LEDB - TX and RX
  152.  *                          xx8x: LEDB - on
  153.  *                          xx9x: LEDB - off
  154.  *                          xxAx: LEDB - blink fast
  155.  *                          xxBx: LEDB - blink slow
  156.  *                          xxCx: LEDB - link and RX
  157.  *                          xxDx: LEDB - link and TX and RX
  158.  *                          xxEx: LEDB - duplex and collisions
  159.  *
  160.  *                          x1xx: LEDA - TX
  161.  *                          x2xx: LEDA - RX
  162.  *                          x3xx: LEDA - collisions
  163.  *                          x4xx: LEDA - link (default)
  164.  *                          x5xx: LEDA - duplex
  165.  *                          x7xx: LEDA - TX and RX
  166.  *                          x8xx: LEDA - on
  167.  *                          x9xx: LEDA - off
  168.  *                          xAxx: LEDA - blink fast
  169.  *                          xBxx: LEDA - blink slow
  170.  *                          xCxx: LEDA - link and RX
  171.  *                          xDxx: LEDA - link and TX and RX
  172.  *                          xExx: LEDA - duplex and collisions
  173.  *
  174.  * Side Effects:    None
  175.  *
  176.  * Overview:        Returns the current value of the PHLCON register.
  177.  *
  178.  * Note:            None
  179.  *****************************************************************************/
  180. #define GetLEDConfig()      ReadPHYReg(PHLCON).Val
  181.  
  182.  
  183. void    MACInit(void);
  184. BOOL    MACIsLinked(void);
  185.  
  186. BOOL    MACGetHeader(MAC_ADDR *remote, BYTE* type);
  187. void    MACSetRxBuffer(WORD offset);
  188. BYTE    MACGet(void);
  189. WORD    MACGetArray(BYTE *val, WORD len);
  190. void    MACDiscardRx(void);
  191. WORD    MACGetFreeRxSize(void);
  192.  
  193. void    MACPutHeader(MAC_ADDR *remote,
  194.                      BYTE type,
  195.                      WORD dataLen);
  196. BOOL    MACIsTxReady(BOOL HighPriority);
  197. void    MACSetTxBuffer(BUFFER buffer, WORD offset);
  198. void    MACPut(BYTE val);
  199. void    MACPutArray(BYTE *val, WORD len);
  200. void    MACDiscardTx(BUFFER buffer);
  201. void    MACFlush(void);
  202. BUFFER  MACGetTxBuffer(BOOL HighPriority);
  203.  
  204.  
  205. extern BUFFER CurrentTxBuffer;
  206.  
  207. #if defined(STACK_USE_SLIP)
  208. #define NICCurrentTxBuffer      (0)
  209. #endif
  210.  
  211.  
  212.  
  213. #endif
  214.