inital comit
This commit is contained in:
commit
fd389ca33b
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/.settings
|
||||||
|
/Debug
|
||||||
|
/targetConfigs
|
||||||
|
/.ccsproject
|
||||||
|
/.cproject
|
||||||
|
/.project
|
||||||
39
local_time.syscfg
Normal file
39
local_time.syscfg
Normal file
@ -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";
|
||||||
112
msp430/main.c
Normal file
112
msp430/main.c
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#include <msp430.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
||||||
6
src/MPPT.h
Normal file
6
src/MPPT.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef MPPT_H
|
||||||
|
#define MPPT_H
|
||||||
|
|
||||||
|
void mppt_vermogenOverride(uint8_t vermogen);
|
||||||
|
|
||||||
|
#endif
|
||||||
71
src/communicatie.h
Normal file
71
src/communicatie.h
Normal 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
102
src/communicatieBeheer.c
Normal 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(¶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;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/global.h
Normal file
17
src/global.h
Normal 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
33
src/main.c
Normal 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
95
src/noodstop.c
Normal 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
4
src/systeemBeheer.c
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
void systeemBeheer(){
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user