functions.h
Go to the documentation of this file.
00001 /***********************************************************************/
00010  #ifndef FUNCTIONS_H_
00011  #define FUNCTIONS_H_
00012  
00013  #include <stdlib.h>
00014  #include "uCmaskFile.h"
00015  #include "MCP2515control.h"
00016  #include "config.h"
00017  
00018  /* Enum: SPI - SPI_INIT_STATUS */
00021  typedef enum {
00022         SPI_INIT_OK = 0,        
00023         SPI_INIT_FAILED
00024  } SPI_INIT_STATUS;
00025  
00026  /* Enum: SPI - SPI_TRANS_STATUS */
00029  typedef enum {
00030         SPI_TRANS_OK = 0,       
00031         SPI_TRANS_FAILED
00032  } SPI_TRANS_STATUS;
00033  
00034  
00035  /* Enum: CAN_INIT_STATUS */
00038  typedef enum {
00039         CAN_INIT_OK = 0,        
00040         CAN_INIT_FAILED
00041  } CAN_INIT_STATUS;
00042  
00043 
00044  /* Needed pre-processor directives =============================== */
00045  #define        MCP_ACTIVATE            ( HW_CS_MCP2515_PORT &= ~( 1<<HW_CS_MCP2515 ) )
00046  #define        MCP_DEACTIVATE          ( HW_CS_MCP2515_PORT |= ( 1<<HW_CS_MCP2515 ) )
00047  #define        MASK_ARBITRATOR         0x00
00048  #define        MASK_DEVICE                     0xFF
00049  #define        DUMMY_DATA                      0x00
00050  //#define      CLEAR_REG_8_BIT         0x00
00051  
00052 
00053  /* Structure for error handling ================================== */
00054  struct errorStr{
00055         uint8_t recBufOvf0;
00056         uint8_t recBufOvf1;
00057         uint8_t busOffError;
00058         uint8_t transmitPassive; 
00059         uint8_t receivePassive;
00060         uint8_t transmitWarning; 
00061         uint8_t receiveWarning;
00062         uint8_t errorWarning;
00063  };
00064  
00065  struct errorStr errorStructure;
00066  
00067  /* Static variables ================================== */
00068  static volatile uint8_t readBuffer;    
00069  static volatile uint8_t dataToSend;
00070  
00071  /* Function declarations ================================== */
00072  /* ======================================================== */
00073  
00074  
00075  /* CAN handling  */
00076  SPI_INIT_STATUS initSpi ( void );
00077  uint8_t transmitSpi ( uint8_t data );
00078  CAN_INIT_STATUS initCan ( uint8_t id );
00079  void hal_set_filter(uint8_t id);
00080  void hal_set_mask(uint8_t id);
00081  
00082  /* EEPROM functions */
00083  void initEEPROM ( void );
00084  uint8_t readEEPROM ( uint8_t address );
00085  void writeEEPROM ( uint8_t address, uint8_t data );
00086  
00087  /* Init interrupts/ports functions */
00088  void initInterrupts ( void );
00089  void initIOPort ( void );
00090  void initIOPort_appDesigner ( void );
00091  void initInterrupts_appDesigner ( void );
00092  void initSPIPorts ( void );
00093  void initINTPorts ( void );
00094  void initUSART ( uint16_t baud );
00095   
00096  /* Error handling functions */ 
00097  void checkTransmissionErrors ( struct errorStr* readErrStr );
00098  void clearTransmissionErrors ( void );
00099  
00100  /* Others */ 
00101  uint8_t mcp2515TransmitData ( uint8_t mode, uint8_t reg, uint8_t val, uint8_t setClearFlag );
00102  void triggerSoftwareInterrupt ( uint8_t port);
00103  void initLowLevelProtocolHardware ( void );
00104  void initUSART ( uint16_t baud );
00105  void printCharUsart ( char sign );
00106  void printUsart ( char* str );
00107  void hal_msg_take ( void );
00108  void wdtEnable ( uint8_t time );
00109  void wdtDisable ( void );
00110  void forceReset ( void );
00111  
00112  #endif
 All Classes Files Functions Enumerations Enumerator Defines