commit fd389ca33bbc7d74b2fe2274924866398f1a85e9 Author: Mats van Reenen Date: Mon Dec 14 16:30:35 2020 +0100 inital comit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a431dc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.settings +/Debug +/targetConfigs +/.ccsproject +/.cproject +/.project \ No newline at end of file diff --git a/local_time.syscfg b/local_time.syscfg new file mode 100644 index 0000000..8adc461 --- /dev/null +++ b/local_time.syscfg @@ -0,0 +1,39 @@ +/** + * These arguments were used when this file was generated. They will be automatically applied on subsequent loads + * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. + * @cliArgs --board "/ti/boards/CC3220S_LAUNCHXL" --product "simplelink_cc32xx_sdk@4_20_00_07" + * @versions {"data":"2020052512","timestamp":"2020052512","tool":"1.5.0+1397","templates":"2020052512"} + */ + +/** + * Import the modules used in this configuration. + */ +const DriverLib = scripting.addModule("/ti/devices/DriverLib"); +const Board = scripting.addModule("/ti/drivers/Board"); +const DMA = scripting.addModule("/ti/drivers/DMA"); +const I2C = scripting.addModule("/ti/drivers/I2C", {}, false); +const I2C1 = I2C.addInstance(); +const Power = scripting.addModule("/ti/drivers/Power"); +const Watchdog = scripting.addModule("/ti/drivers/Watchdog"); +const Watchdog1 = Watchdog.addInstance(); + +/** + * Write custom configuration values to the imported modules. + */ +I2C1.$name = "CONFIG_I2C_0"; +I2C1.$hardware = system.deviceData.board.components.LP_I2C; +I2C1.i2c.sdaPin.$assign = "boosterpack.10"; +I2C1.i2c.sclPin.$assign = "boosterpack.9"; + +Power.ioRetentionShutdown = ["GRP_1"]; +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +Watchdog1.$name = "CONFIG_WATCHDOG_0"; +Watchdog1.watchdog.$assign = "WATCHDOG0"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +I2C1.i2c.$suggestSolution = "I2C0"; diff --git a/msp430/main.c b/msp430/main.c new file mode 100644 index 0000000..492a5e5 --- /dev/null +++ b/msp430/main.c @@ -0,0 +1,112 @@ +#include +#include + +#define READBUFFER_LEN 10 +#define WRITEBUFFER_LEN 10 + +// this buffers store the the receved and send data +unsigned char ReadBuffer[READBUFFER_LEN]; +unsigned char WriteBuffer[WRITEBUFFER_LEN]; + +// the pointers are used to remenber the location it was on the buffer +unsigned char *ReadBuffer_p = &ReadBuffer[0]; +unsigned char *WriteBuffer_p = &WriteBuffer[0]; + +// if it finisched receving/sending a packet this wil become true +bool NewPacket = false; + +enum {SLEEP, WRITE, READ} State; +typedef enum {} PacketID_t; //TODO: add packet ids + +void Setup(void); + +int main(void) +{ + WDTCTL = WDTPW + WDTHOLD; // Stop WDT + + P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0 + P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0 + + Setup(); + State = SLEEP; + + while(1){ + while(!NewPacket){ + //TODO: add sleep mode + } + + __disable_interrupt(); // don't want the interupt to destoy you beautiful packet + NewPacket = false; // recet new packet flag + uint8_t bytesReceved = ReadBuffer_p - &ReadBuffer[0]; + uint8_t data[READBUFFER_LEN]; + + // copy data from the buffer used for the communication so it can receve the next packet + memcpy(&data[0], &ReadBuffer[0], bytesReceved); + + __enable_interrupt(); // data is save + + switch (data[0]){ + case /* packet id */: + /* read packet */ + break; + } + } +} + +/* + * Deze interrupt is beide voor RXIFG en TXIFG. + * Dus vlaggetjes bekijken om te zien wat er gebeurd + */ +#pragma vector = USCIAB0TX_VECTOR +__interrupt void USCIAB0TX_ISR(void) +{ + if(IFG2 & UCB0TXIFG && State == WRITE){ + // Read data from I2C + UCB0TXBUF = *WriteBuffer_p; + WriteBuffer_p++; + if(WriteBuffer_p > &WriteBuffer[WRITEBUFFER_LEN]){ + State = SLEEP; + NewPacket = true; + } + }else if(IFG2 & UCB0RXIFG && State == READ){ + // Write data to I2C + *ReadBuffer_p = UCB0RXBUF; + ReadBuffer_p++; + if(ReadBuffer_p > &ReadBuffer[READBUFFER_LEN]){ + State = WRITE; + } + } +} + +/* + * Hier krijgen we de start/stop condities + */ +#pragma vector = USCIAB0RX_VECTOR +__interrupt void USCIAB0RX_ISR(void) +{ + if(UCB0STAT & UCSTTIFG){ + // start signaal ontvangen + State = READ; + // reset pointers + WriteBuffer_p = &WriteBuffer[0]; + ReadBuffer_p = &ReadBuffer[0]; + }else if(UCB0STAT & UCSTPIFG){ + // stop signaal, klaar met transactie + State = SLEEP; + NewPacket = true; + } + + // Clear interrupt flags + UCB0STAT &= ~(UCSTPIFG + UCSTTIFG); +} + +void Setup(void){ + __disable_interrupt(); + UCB0CTL1 |= UCSWRST; // reset + UCB0CTL0 = UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode + UCB0I2COA = 0x48; // eigen slave adres is 048h + UCB0CTL1 &= ~UCSWRST; // reset uit + UCB0I2CIE |= UCSTPIE + UCSTTIE; // detectie voor start en stop + IE2 |= UCB0RXIE | UCB0TXIE; // interrupts aan + __enable_interrupt(); +} diff --git a/src/MPPT.h b/src/MPPT.h new file mode 100644 index 0000000..1142d28 --- /dev/null +++ b/src/MPPT.h @@ -0,0 +1,6 @@ +#ifndef MPPT_H +#define MPPT_H + +void mppt_vermogenOverride(uint8_t vermogen); + +#endif \ No newline at end of file diff --git a/src/communicatie.h b/src/communicatie.h new file mode 100644 index 0000000..2d8e729 --- /dev/null +++ b/src/communicatie.h @@ -0,0 +1,71 @@ +#ifndef COMMUNICATIE_H +#define COMMUNICATIE_H + +#include + +// 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 \ No newline at end of file diff --git a/src/communicatieBeheer.c b/src/communicatieBeheer.c new file mode 100644 index 0000000..dfd2f85 --- /dev/null +++ b/src/communicatieBeheer.c @@ -0,0 +1,102 @@ +#include + +#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(¶ms); + params.transferMode = I2CSLAVE_MODE_BLOCKING; + params.slaveAddress = COMM_I2C_ADDRESS; + handle = I2CSlave_open(CONFIG_I2C_0, ¶ms); + 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; + } +} diff --git a/src/global.h b/src/global.h new file mode 100644 index 0000000..3d7062e --- /dev/null +++ b/src/global.h @@ -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 \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..8277baa --- /dev/null +++ b/src/main.c @@ -0,0 +1,33 @@ +#include +#include +#include +#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 +} diff --git a/src/noodstop.c b/src/noodstop.c new file mode 100644 index 0000000..ebc1577 --- /dev/null +++ b/src/noodstop.c @@ -0,0 +1,95 @@ +#include +#include +#include + +#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! +} diff --git a/src/systeemBeheer.c b/src/systeemBeheer.c new file mode 100644 index 0000000..fb0dd9c --- /dev/null +++ b/src/systeemBeheer.c @@ -0,0 +1,4 @@ + +void systeemBeheer(){ + +} \ No newline at end of file