inital comit

This commit is contained in:
Mats van Reenen
2020-12-14 16:30:35 +01:00
commit fd389ca33b
10 changed files with 485 additions and 0 deletions

6
src/MPPT.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef MPPT_H
#define MPPT_H
void mppt_vermogenOverride(uint8_t vermogen);
#endif

71
src/communicatie.h Normal file
View File

@@ -0,0 +1,71 @@
#ifndef COMMUNICATIE_H
#define COMMUNICATIE_H
#include <mqueue.h>
// enummeration for packet IDs
typedef enum {
PACKET_UPDATEBELASTING,
PACKET_NOODSTOP,
PACKET_INITPARAMS
} packetID_t;
// packet structures
union {
struct {
packetID_t id = PACKET_NOODSTOP;
bool overheeat;
bool overload;
bool overspeed;
} initAandrijving;
struct {
packetID_t id = PACKET_INITPARAMS;
uint8_t maxVermogen;
uint16_t maxSnelhied;
uint8_t maxTemptratuur;
uint8_t vermogenSetpoint;
} initBelasting;
struct {
packetID_t id = 0x03;
uint8_t maxVermogen;
uint16_t maxSnelhied;
uint8_t maxTemptratuur;
} maxWaardesBelasting;
struct {
packetID_t id = 0x04;
uint8_t rendement;
uint16_t snelheid;
uint16_t stroom;
uint16_t spanning;
};
struct {
packetID_t id = 0x05;
uint16_t snelheidSetpoint;
uint16_t maxSpanning;
uint16_t maxStroom;
} initAandrijving;
struct {
packetID_t id = 0x06;
uint8_t rendement;
uint8_t vermogen;
uint16_t stroom;
uint16_t spanning;
};
} I2CPacket_t;
typedef struct {
uint8_t maxTemperatuur;
uint8_t maxVermogen;
uint16_t maxSnelheid;
} maxwaardes_t;
mqd_t MaxWaardes_mq;
extern void mppt_setpoint(uint8_t vermogen);
#endif

102
src/communicatieBeheer.c Normal file
View File

@@ -0,0 +1,102 @@
#include <ti/drivers/I2CSlave.h>
#include "communicatie.h"
#define COMM_I2C_ADDRESS 0xB1
extern pthread_t createSimplePTread(int prio, void * fn);
union I2CPacket_t PacketBuffer;
void dataBijhouden(){
//BLOCK: wacht op werken
//??
while(1){
//BLOCK: vermogen DUT aflezen
//??
//BLOCK: Snelheid aflezen
//??
//BLOCK: bereken koppel
//??
//BLOCK: Vermogen belasting aflezen
//??
//BLOCK: Spanning belasting aflezen
//??
//BLOCK: bereken rendement
//??
//BLOCK: Temperatuur aflezen
//??
//BLOCK: sleep 1ms
usleep(1000);
}
}
// communicatie I2C Taak
void comm_i2c(){
//BLOCK: init start begint
//??
//BLOCK: Initialiseer I2C
I2C_init();
//TODO: findout corect driver for this
Slave_Handle handle;
I2CSlave_Params params;
I2CSlave_Params_init(&params);
params.transferMode = I2CSLAVE_MODE_BLOCKING;
params.slaveAddress = COMM_I2C_ADDRESS;
handle = I2CSlave_open(CONFIG_I2C_0, &params);
if (!handle) {
System_printf("I2CSlave did not open");
}
//BLOCK: GPIO init
//??
//BLOCK: maak thread aan om waardes te updaten
createSimplePTread(1, &dataBijhouden);
I2CPacket_t packet;
while(1){
//BLOCK: read package
//TODO: figgerout how it actualy works
I2C_read(handle, &packet, sizeof(Packet));
//BLOCK: send reply
//TODO: figgerout how it actualy works
I2C_send(handle, &PacketBuffer, sizeof(PacketBuffer));
//BLOCK: identificeer package
switch (packet){
case PACKET_UPDATEBELASTING:
//BLOCK: Update setpoint
mppt_setpoint(packet.vermogenSetpoint);
break;
case PACKET_NOODSTOP:
//BLOCK: Update Overheat, Overspeed, overload waardes updaten
//??
break;
case PACKET_INITPARAMS:
//BLOCK: Verstuur data naar noodstop
maxwaardes_t p;
p.maxTemperatuur = packet.maxTemperatuur;
p.maxVermogen = packet.maxVermogen;
p.maxSnelheid = packet.maxSnelheid;
//mq_send(MaxWaardes_mq, (const char*)&p, sizeof(p), 3);
//BLOCK: Verstuur data naar MPPT
mppt_setpoint(packet.vermogenSetpoint);
break;
}
}

17
src/global.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef GLOBALS_H
#define GLOBALS_H
enum {
SLEEP,
INIT,
MPPT_READY,
NOODSTOP_READY,
ALL_READY,
WORKING,
OVERHEAD,
OVERLOAD,
OVERSPEED,
EXT_NOODSTOP
} Status;
#endif

33
src/main.c Normal file
View File

@@ -0,0 +1,33 @@
#include <stdint.h>
#include <pthread.h>
#include <ti/sysbios/BIOS.h>
#include "ti_drivers_config.h"
#define ERROR(msg) return; //TODO: create error handeler
//TODO: maybe detach pthread?
//TODO: add stacksize option
pthread_t createSimplePTread(int prio, void * fn){
struct sched_param priParam;
priParam.sched_priority = prio;
pthread_attr_t pAttrs;
pthread_attr_init(&pAttrs);
pthread_attr_setschedparam(&pAttrs, &priParam);
pthread_t thread;
if( pthread_create(&thread, &pAttrs, fn, NULL) != 0 ){
ERROR("could not create pthread")
}
return thread;
}
int main(void)
{
Board_init(); // initilaze board
BIOS_start(); // start the BIOS
}

95
src/noodstop.c Normal file
View File

@@ -0,0 +1,95 @@
#include <mqueue.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/ADC.h>
#include "global.h"
#include "communicatie.h"
#include "MPPT.h"
struct maxwaardes_t nood_maxwaardes;
extern pthread_t createSimplePTread(int prio, void * fn);
void nood_activeerNoodstop(){
//BLOCK: zet noodstop GPIO als uitgang
//TODO: do it!
//BLOCK: noodstop GPIO = laag
//TODO: do it!
}
void snelhied(uint16_t snelhied){
//TODO: whoosh.
//BLOCK: controleer snelheid
if(snelhied > nood_maxwaardes.maxSnelheid){
//BLOCK: vermogen overwrite = max vermogen
mppt_vermogenOverride(nood_maxwaardes.maxVermogen);
//BLOCK: Wacht 0.5 seconde
usleep(500000);
//BLOCK: activeer noostop
nood_activeerNoodstop();
}
}
void nood_tempratuurHandle(){
do{
//BLOCK: wacht 0.1 seconde
usleep(100000);
//BLOCK: lees ADC uit
//TODO: do it!
//BLOCK: bereken temperatuur
//?? Yeti wat is die formule?
//BLOCK: controleer temperatuur
}while(tempratuur < nood_maxwaardes.maxTemptratuur);
//BLOCK: vermogen override = 0W
mppt_vermogenOverride(0);
//BLOCK: activeer noostop
nood_activeerNoodstop();
}
void nood_noodstopISR(){
//BLOCK: Wacht 0.5 seconde
usleep(500000);
//BLOCK: activeer noostop
nood_activeerNoodstop();
}
void nood_init(){
//BLOCK: ADC init
//TODO: do it!
//BLOCK: GPIO init
//TODO: do it!
//BLOCK: wacht op Max waardes
mq_receive(MaxWaardes_mq, (char*)&nood_maxwaardes, sizeof(nood_maxwaardes), NULL);
//BLOCK: Update status
if(Status == INIT){
Status = NOODSTOP_READY;
}else if(Status == MPPT_READY){
Status = ALL_READY;
}else{
ERROR("invalid Status");
}
//BLOCK: wacht tot status == werken
while(Status != WORKING){
usleep(1000);
}
//BLOCK: maak tread voor ADC
createSimplePTread(1, &nood_tempratuurHandle);
//BLOCK: Maak interrupt voor noodstop signaal
//TODO: do it!
}

4
src/systeemBeheer.c Normal file
View File

@@ -0,0 +1,4 @@
void systeemBeheer(){
}