![]() |
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 #define CLEAR_REG_8_BIT 0x00 00045 #define DUMMY_DATA 0x00 00046 #define MCP_ACTIVATE ( HW_CS_MCP2515_PORT &= ~( 1<<HW_CS_MCP2515 ) ) 00047 #define MCP_DEACTIVATE ( HW_CS_MCP2515_PORT |= ( 1<<HW_CS_MCP2515 ) ) 00048 #define MASK_ARBITRATOR 0x00 00049 #define MASK_DEVICE 0xFF 00050 00051 00052 /* Structure for error handling ================================== */ 00053 struct errorStr{ 00054 uint8_t recBufOvf0; 00055 uint8_t recBufOvf1; 00056 uint8_t busOffError; 00057 uint8_t transmitPassive; 00058 uint8_t receivePassive; 00059 uint8_t transmitWarning; 00060 uint8_t receiveWarning; 00061 uint8_t errorWarning; 00062 }; 00063 00064 struct errorStr errorStructure; 00065 00066 /* Static variables ================================== */ 00067 static volatile uint8_t readBuffer; 00068 static volatile uint8_t dataToSend; 00069 00070 /* Function declarations ================================== */ 00071 00072 SPI_INIT_STATUS initSpi ( void ); 00073 uint8_t transmitSpi ( uint8_t data ); 00074 CAN_INIT_STATUS initCan ( uint8_t id ); 00075 //void hal_set_module_masks_filters ( uint8_t id, uint8_t moduleMode ); 00076 void hal_set_filter(uint8_t id); 00077 void hal_set_mask(uint8_t id); 00078 00079 /* EEPROM functions */ 00080 void initEEPROM ( void ); 00081 uint8_t readEEPROM ( uint8_t address ); 00082 void writeEEPROM ( uint8_t address, uint8_t data ); 00083 00084 /* Init functions */ 00085 void initInterrupts ( void ); 00086 void initIOPort ( void ); 00087 void initIOPort_appDesigner ( void ); 00088 void initInterrupts_appDesigner ( void ); 00089 void initSPIPorts ( void ); 00090 void initINTPorts ( void ); 00091 void initUSART ( uint16_t baud ); 00092 00093 /* Error handling functions */ 00094 void checkTransmissionErrors ( struct errorStr* readErrStr ); 00095 void clearTransmissionErrors ( void ); 00096 00097 /* Others */ 00098 uint8_t mcp2515TransmitData ( uint8_t mode, uint8_t reg, uint8_t val, uint8_t setClearFlag ); 00099 void triggerSoftwareInterrupt ( uint8_t port); 00100 void initLowLevelProtocolHardware ( void ); 00101 void initUSART ( uint16_t baud ); 00102 void printCharUsart ( char sign ); 00103 void printUsart ( char* str ); 00104 void hal_msg_take ( void ); 00105 void wdtEnable ( uint8_t time ); 00106 void wdtDisable ( void ); 00107 void forceReset ( void ); 00108 00109 #endif