Advertisement
Guest User

PSoC3 EEPROM example

a guest
Nov 1st, 2011
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.02 KB | None | 0 0
  1. //config.h
  2.  
  3. /* ========================================
  4.  *
  5.  * Copyright YOUR COMPANY, THE YEAR
  6.  * All Rights Reserved
  7.  * UNPUBLISHED, LICENSED SOFTWARE.
  8.  *
  9.  * CONFIDENTIAL AND PROPRIETARY INFORMATION
  10.  * WHICH IS THE PROPERTY OF your company.
  11.  *
  12.  * ========================================
  13. */
  14. #ifndef CONFIG_H
  15. #define CONFIG_H
  16.  
  17. #define EEPROM_CONFIG_LOCATION 0x00
  18.  
  19. //struct for storing Brix Meter config data
  20. //note: should be no longer than 16 bytes for current storeConfig implementation
  21. typedef struct _brix_Config
  22. {
  23.     uint16 u16hostTemperatureTenths;
  24.     int16 i16slaveBrixMeasuredHundredths;
  25.     uint16 u16slaveBrixNonZeroCalPointTenths;
  26.     uint16 u16zeroCalCounts;
  27.     uint16 u16nonzeroCalCounts;
  28.     uint16 u16slavePumpStrengthFixed;
  29.     uint16 u16slavePumpStrengthAuto;
  30.     uint8 u8brixInitializedFlag; //Indicates that the device has been configured before. Leave at end of struct.
  31.     uint8 u8fillerVar1; //variable to fill the 16 bytes
  32. } brix_Config;
  33.  
  34. void storeConfig(void);
  35.  
  36. void recallConfig(void);
  37.  
  38. #endif
  39. //[] END OF FILE
  40.  
  41. //config.c
  42.  
  43. /* ========================================
  44.  *
  45.  * Copyright YOUR COMPANY, THE YEAR
  46.  * All Rights Reserved
  47.  * UNPUBLISHED, LICENSED SOFTWARE.
  48.  *
  49.  * CONFIDENTIAL AND PROPRIETARY INFORMATION
  50.  * WHICH IS THE PROPERTY OF your company.
  51.  *
  52.  * ========================================
  53. */
  54. #include <device.h>
  55. #include "config.h"
  56. #include "main.h"
  57. #include "brix.h"
  58.  
  59. brix_Config brixConfig = {0,0,0,0,0,0,0,0,0};
  60. reg8 * EEPROMRegPointer = (reg8 *) CYDEV_EE_BASE;
  61. reg8 * brixConfigPointer = &brixConfig.u16hostTemperatureTenths;
  62.  
  63.  
  64. //function to store current brix configuration in EEPROM
  65. void storeConfig(void)
  66. {
  67.     uint8 writeStatus;
  68.     EEPROM_Start();
  69.     //CySetTemp();
  70.     writeStatus = EEPROM_Write(brixConfigPointer, EEPROM_CONFIG_LOCATION);
  71.    
  72.     if(writeStatus!=CYRET_SUCCESS)
  73.     {
  74.         if(writeStatus==CYRET_UNKNOWN)
  75.         {
  76.             //failure. do something?
  77.             CY_NOP; //a no-op
  78.         }
  79.     }
  80. }
  81.  
  82. //function to populate brix configuration from EEPROM
  83. //should populate config with default values if un-initialized
  84. void recallConfig(void)
  85. {
  86.     //recall from EEPROM
  87.     int8 index;
  88.    
  89.     EEPROM_Start();
  90.    
  91.     for(index = 0; index < SIZEOF_EEPROM_ROW; index++)
  92.     {
  93.         brixConfigPointer[index] = EEPROMRegPointer[index];
  94.     }
  95.    
  96.     //check for config initialization
  97.     if(!brixConfig.u8brixInitializedFlag)
  98.     {
  99.         //initialize the configuration
  100.         brixConfig.u16hostTemperatureTenths = 0;
  101.         brixConfig.i16slaveBrixMeasuredHundredths = 0;
  102.         brixConfig.u16slaveBrixNonZeroCalPointTenths = 0;
  103.         brixConfig.u16zeroCalCounts = 0;
  104.         brixConfig.u16nonzeroCalCounts = 0;
  105.         //initially, the Brix Meter should be set up for automatic pump strength
  106.         //MAXK: Fix this code
  107.         //brixConfig.u16slavePumpStrengthFixed = HOST_PUMP_AUTO;
  108. //      brixConfig.u16slavePumpStrengthAuto = PUMP_MEAS_DEFAULT;
  109.         //set the initialized flag to show EEPROM has been populated
  110.         brixConfig.u8brixInitializedFlag = TRUE;
  111.        
  112.         //write that configuration to EEPROM
  113.         storeConfig();
  114.     }
  115.     //MAXK: populate I2C buffer here?
  116. }
  117.  
  118. /* [] END OF FILE */
  119.  
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement