cleanup code
This commit is contained in:
		
							parent
							
								
									250cfbdf2a
								
							
						
					
					
						commit
						147f08464a
					
				
							
								
								
									
										20
									
								
								src/MPPT.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/MPPT.c
									
									
									
									
									
								
							| @ -1,6 +1,7 @@ | ||||
| #include <stdint.h> | ||||
| #include <ti/drivers/PWM.h> | ||||
| 
 | ||||
| #include "debug.h" | ||||
| #include "global.h" | ||||
| #include "MPPT.h" | ||||
| #include "spi.h" | ||||
| @ -8,7 +9,7 @@ | ||||
| #define PWM_MIN 0.001 | ||||
| #define PWM_MAX 0.9 | ||||
| 
 | ||||
| uint8_t mppt_setpoint, mppt_setpointOverrite, mppt_vermogen; | ||||
| uint8_t mppt_setpoint = 0xff, mppt_setpointOverrite, mppt_vermogen; | ||||
| uint8_t *mppt_setpointP; | ||||
| 
 | ||||
| PWM_Handle mppt_pwm; | ||||
| @ -42,11 +43,25 @@ void mppt_init(){ | ||||
|   params.periodValue = 10; // 100 kHz
 | ||||
|   mppt_pwm = PWM_open(CONFIG_PWM_0, ¶ms); | ||||
|   if (mppt_pwm == NULL) { | ||||
|     while (1); | ||||
|     ERROR("faild to open PWM"); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   mppt_setpointP = &mppt_setpoint; | ||||
|   mppt_start(); | ||||
| 
 | ||||
|   // whit until it recevs a valid setpoint
 | ||||
|   while(mppt_setpoint > 250) | ||||
|     usleep(1e3); | ||||
| 
 | ||||
|   // Update status
 | ||||
|   if(Status == INIT){ | ||||
|     Status = MPPT_READY; | ||||
|   }else if(Status == NOODSTOP_READY){ | ||||
|     Status = ALL_READY; | ||||
|   }else{ | ||||
|     ERROR("invalid Status"); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void mppt_setPWM(double d){ | ||||
| @ -134,6 +149,7 @@ void mppt_start(){ | ||||
| } | ||||
| 
 | ||||
| void mppt_deinit(){ | ||||
|   mppt_setpoint = 0xff; | ||||
|   mppt_setPWM(0); | ||||
|   PWM_stop(mppt_pwm); | ||||
| } | ||||
|  | ||||
| @ -33,7 +33,7 @@ void comm_init(){ | ||||
|   SPI_Params_init(&SPI_MSPTrans.params); | ||||
|   SPI_MSPTrans.interface = CONFIG_SPI_MASTER; | ||||
|   SPI_MSPTrans.cs = CONFIG_GPIO_CSMSP; | ||||
|   SPI_ADC.params.frameFormat = SPI_POL0_PHA0; // mode 0
 | ||||
|   SPI_MSPTrans.params.frameFormat = SPI_POL0_PHA0; // mode 0
 | ||||
|   SPI_MSPTrans.params.bitRate = 1E6; // 1 MHz
 | ||||
|   SPI_MSPTrans.trans.count = SPI_PACKET_LENGTH; | ||||
|   SPI_MSPTrans.trans.txBuf = &TransmitBuffer[0]; | ||||
| @ -86,3 +86,5 @@ void comm_init(){ | ||||
|     usleep(SPI_INTERVAL); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| //TODO: add uart code
 | ||||
|  | ||||
							
								
								
									
										10
									
								
								src/debug.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/debug.h
									
									
									
									
									
								
							| @ -1,11 +1,11 @@ | ||||
| #ifndef DEBUG_H | ||||
| #define DEBUG_H | ||||
| 
 | ||||
| #define LOG(msg) ; | ||||
| #define LOG(msg, ...) ; | ||||
| 
 | ||||
| #define ERROR(msg) LOG("ERROR: " msg) | ||||
| #define WARN(msg)  LOG("WARN: " msg) | ||||
| #define DEBUG(msg) LOG("DEBUG: " msg) | ||||
| #define INFO(msg)  LOG("INFO: " msg) | ||||
| #define ERROR(msg, ...) LOG("ERROR: " msg, ##__VA_ARGS__) | ||||
| #define WARN(msg, ...)  LOG("WARN: " msg, ##__VA_ARGS__) | ||||
| #define DEBUG(msg, ...) LOG("DEBUG: " msg, ##__VA_ARGS__) | ||||
| #define INFO(msg, ...)  LOG("INFO: " msg, ##__VA_ARGS__) | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
| @ -4,7 +4,7 @@ | ||||
| #include <pthread.h> | ||||
| #include "ti_drivers_config.h" | ||||
| 
 | ||||
| typedef enum { | ||||
| typedef enum Status_t { | ||||
|   SLEEP, | ||||
|   INIT, | ||||
|   MPPT_READY, | ||||
|  | ||||
| @ -51,12 +51,12 @@ void startSys(){ | ||||
|   treads.noodstop = createSimplePTread(4, &noodstop_start); | ||||
| } | ||||
| void stopSys(){ | ||||
|   //TODO: communication say what the reason for the emergency stop was if thare was one
 | ||||
|   // pthread_exit(treads.comm);
 | ||||
|   pthread_exit(treads.noodstop); | ||||
|   pthread_exit(treads.mppt); | ||||
| 
 | ||||
|   treads.mppt = createSimplePTread(1, &mppt_deinit); | ||||
|   treads.noodstop = createSimplePTread(3, &noodstop_deinit); | ||||
| } | ||||
| 
 | ||||
| void initISR(){ | ||||
| @ -83,6 +83,7 @@ void startSysISR(){ | ||||
| void * mainTask(void *arg){ | ||||
|   Status_t lastState; | ||||
|   while(1){ | ||||
|     INFO("system state changed from %s to %s", lastState, Status); | ||||
|     switch (Status){ | ||||
|       case SLEEP: | ||||
|         stopSys(); | ||||
| @ -90,6 +91,9 @@ void * mainTask(void *arg){ | ||||
|       case INIT: | ||||
|         startInit(); | ||||
|         break; | ||||
|       case ALL_READY: | ||||
|         //TODO: say the system is ready
 | ||||
|         break; | ||||
|       case WORKING: | ||||
|         startSys(); | ||||
|         break; | ||||
| @ -112,5 +116,5 @@ int main(void){ | ||||
|   treads.sysBeheer = createSimplePTread(1, mainTask); | ||||
|   BIOS_start(); // start the BIOS
 | ||||
|   while(1) | ||||
|     usleep(1E6); | ||||
|     sleep(10); | ||||
| } | ||||
|  | ||||
| @ -107,7 +107,7 @@ void noodstop_init(){ | ||||
|       && nood_maxwaardes.maxTempratuur >= 60 && nood_maxwaardes.maxTempratuur <= 120 | ||||
|       && nood_maxwaardes.maxVermogen <= 250 | ||||
|     ){ | ||||
|       break; // stop the loop values are valid
 | ||||
|       break; // stop the loop, values are valid
 | ||||
|     } | ||||
|     usleep(100E3); | ||||
|   } | ||||
| @ -123,11 +123,5 @@ void noodstop_init(){ | ||||
| } | ||||
| 
 | ||||
| void noodstop_start(){ | ||||
|   // start the treath voor het uitlezen van de temptatuur
 | ||||
|   adcThread = createSimplePTread(2, &noodstop_tempratuurHandle); | ||||
| } | ||||
| 
 | ||||
| void noodstop_deinit(){ | ||||
|   // stop threads
 | ||||
|   pthread_exit(adcThread); | ||||
|   noodstop_tempratuurHandle(); | ||||
| } | ||||
|  | ||||
| @ -10,7 +10,6 @@ void noodstop_snelhied(uint16_t snelhied); | ||||
| 
 | ||||
| void noodstop_init(); | ||||
| void noodstop_start(); | ||||
| void noodstop_deinit(); | ||||
| 
 | ||||
| uint8_t noodstop_getTempratuur(); | ||||
| void noodstop_activeerNoodstop(); | ||||
|  | ||||
| @ -4,6 +4,7 @@ | ||||
| #include "debug.h" | ||||
| 
 | ||||
| 
 | ||||
| SPI_Trans_t SPI_ADC; | ||||
| uint8_t ADC_TxBuf[4]; | ||||
| uint8_t ADC_RxBuf[4]; | ||||
| 
 | ||||
| @ -13,7 +14,7 @@ void SPI_Init(){ | ||||
|   // init ADC
 | ||||
|   SPI_Params_init(&SPI_ADC.params); | ||||
|   SPI_ADC.interface = CONFIG_SPI_MASTER; | ||||
|   SPI_ADC.cs = CONFIG_GPIO_CSMSP; | ||||
|   SPI_ADC.cs = CONFIG_GPIO_CSADC; | ||||
|   SPI_ADC.params.frameFormat = SPI_POL0_PHA0; // mode 0
 | ||||
|   SPI_ADC.params.bitRate = 1E6; // 1 MHz
 | ||||
|   SPI_ADC.trans.count = 4; | ||||
| @ -40,7 +41,7 @@ int SPI_trans(SPI_Trans_t *trans){ | ||||
|   SPI_Handaler = &spih; | ||||
| 
 | ||||
|   // open spi connection with paramaters of this one
 | ||||
|   spih = SPI_open(CONFIG_SPI_MASTER, &trans->params); | ||||
|   spih = SPI_open(trans->interface, &trans->params); | ||||
|   if (spih == NULL) { | ||||
|     ERROR("initialising SPI for communicating with the MSP\n"); | ||||
|     return 1; | ||||
|  | ||||
| @ -29,8 +29,6 @@ typedef struct SPI_Trans_t { | ||||
| } SPI_Trans_t; | ||||
| SPI_Handle *SPI_Handaler; | ||||
| 
 | ||||
| SPI_Trans_t SPI_ADC; | ||||
| 
 | ||||
| void SPI_Init(); | ||||
| uint16_t ADC_read(uint8_t ch); | ||||
| int SPI_trans(SPI_Trans_t *trans); | ||||
|  | ||||
| @ -1,4 +0,0 @@ | ||||
| 
 | ||||
| void systeemBeheer(){ | ||||
|    | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user