Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //config.h
- /* ========================================
- *
- * Copyright YOUR COMPANY, THE YEAR
- * All Rights Reserved
- * UNPUBLISHED, LICENSED SOFTWARE.
- *
- * CONFIDENTIAL AND PROPRIETARY INFORMATION
- * WHICH IS THE PROPERTY OF your company.
- *
- * ========================================
- */
- #ifndef CONFIG_H
- #define CONFIG_H
- #define EEPROM_CONFIG_LOCATION 0x00
- //struct for storing Brix Meter config data
- //note: should be no longer than 16 bytes for current storeConfig implementation
- typedef struct _brix_Config
- {
- uint16 u16hostTemperatureTenths;
- int16 i16slaveBrixMeasuredHundredths;
- uint16 u16slaveBrixNonZeroCalPointTenths;
- uint16 u16zeroCalCounts;
- uint16 u16nonzeroCalCounts;
- uint16 u16slavePumpStrengthFixed;
- uint16 u16slavePumpStrengthAuto;
- uint8 u8brixInitializedFlag; //Indicates that the device has been configured before. Leave at end of struct.
- uint8 u8fillerVar1; //variable to fill the 16 bytes
- } brix_Config;
- void storeConfig(void);
- void recallConfig(void);
- #endif
- //[] END OF FILE
- //config.c
- /* ========================================
- *
- * Copyright YOUR COMPANY, THE YEAR
- * All Rights Reserved
- * UNPUBLISHED, LICENSED SOFTWARE.
- *
- * CONFIDENTIAL AND PROPRIETARY INFORMATION
- * WHICH IS THE PROPERTY OF your company.
- *
- * ========================================
- */
- #include <device.h>
- #include "config.h"
- #include "main.h"
- #include "brix.h"
- brix_Config brixConfig = {0,0,0,0,0,0,0,0,0};
- reg8 * EEPROMRegPointer = (reg8 *) CYDEV_EE_BASE;
- reg8 * brixConfigPointer = &brixConfig.u16hostTemperatureTenths;
- //function to store current brix configuration in EEPROM
- void storeConfig(void)
- {
- uint8 writeStatus;
- EEPROM_Start();
- //CySetTemp();
- writeStatus = EEPROM_Write(brixConfigPointer, EEPROM_CONFIG_LOCATION);
- if(writeStatus!=CYRET_SUCCESS)
- {
- if(writeStatus==CYRET_UNKNOWN)
- {
- //failure. do something?
- CY_NOP; //a no-op
- }
- }
- }
- //function to populate brix configuration from EEPROM
- //should populate config with default values if un-initialized
- void recallConfig(void)
- {
- //recall from EEPROM
- int8 index;
- EEPROM_Start();
- for(index = 0; index < SIZEOF_EEPROM_ROW; index++)
- {
- brixConfigPointer[index] = EEPROMRegPointer[index];
- }
- //check for config initialization
- if(!brixConfig.u8brixInitializedFlag)
- {
- //initialize the configuration
- brixConfig.u16hostTemperatureTenths = 0;
- brixConfig.i16slaveBrixMeasuredHundredths = 0;
- brixConfig.u16slaveBrixNonZeroCalPointTenths = 0;
- brixConfig.u16zeroCalCounts = 0;
- brixConfig.u16nonzeroCalCounts = 0;
- //initially, the Brix Meter should be set up for automatic pump strength
- //MAXK: Fix this code
- //brixConfig.u16slavePumpStrengthFixed = HOST_PUMP_AUTO;
- // brixConfig.u16slavePumpStrengthAuto = PUMP_MEAS_DEFAULT;
- //set the initialized flag to show EEPROM has been populated
- brixConfig.u8brixInitializedFlag = TRUE;
- //write that configuration to EEPROM
- storeConfig();
- }
- //MAXK: populate I2C buffer here?
- }
- /* [] END OF FILE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement