big update
This commit is contained in:
parent
dfd9b3ba2f
commit
7769a07681
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* 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.30.00.06"
|
||||
* @versions {"data":"2020090214","timestamp":"2020090214","tool":"1.6.0+1543","templates":"2020090214"}
|
||||
* @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"}
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -13,8 +13,10 @@ const Board = scripting.addModule("/ti/drivers/Board");
|
||||
const DMA = scripting.addModule("/ti/drivers/DMA");
|
||||
const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false);
|
||||
const GPIO1 = GPIO.addInstance();
|
||||
const I2C = scripting.addModule("/ti/drivers/I2C", {}, false);
|
||||
const I2C1 = I2C.addInstance();
|
||||
const GPIO2 = GPIO.addInstance();
|
||||
const GPIO3 = GPIO.addInstance();
|
||||
const GPIO4 = GPIO.addInstance();
|
||||
const GPIO5 = GPIO.addInstance();
|
||||
const PWM = scripting.addModule("/ti/drivers/PWM", {}, false);
|
||||
const PWM1 = PWM.addInstance();
|
||||
const Power = scripting.addModule("/ti/drivers/Power");
|
||||
@ -30,12 +32,26 @@ GPIO1.$name = "CONF_GPIO_NOODSTOP";
|
||||
GPIO1.interruptTrigger = "Falling Edge";
|
||||
GPIO1.pull = "Pull Up";
|
||||
GPIO1.mode = "Dynamic";
|
||||
GPIO1.callbackFunction = "noodstop_noodstopISR";
|
||||
GPIO1.callbackFunction = "noodstopISR";
|
||||
|
||||
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";
|
||||
GPIO2.$name = "CONFIG_GPIO_INIT";
|
||||
GPIO2.pull = "Pull Down";
|
||||
GPIO2.callbackFunction = "initISR";
|
||||
GPIO2.interruptTrigger = "Rising Edge";
|
||||
GPIO2.gpioPin.$assign = "boosterpack.7";
|
||||
|
||||
GPIO3.$name = "CONFIG_GPIO_START";
|
||||
GPIO3.callbackFunction = "startSysISR";
|
||||
GPIO3.interruptTrigger = "Both Edges";
|
||||
GPIO3.gpioPin.$assign = "boosterpack.4";
|
||||
|
||||
GPIO4.$name = "CONFIG_GPIO_CSMSP";
|
||||
GPIO4.mode = "Output";
|
||||
GPIO4.initialOutputState = "High";
|
||||
|
||||
GPIO5.$name = "CONFIG_GPIO_CSADC";
|
||||
GPIO5.mode = "Output";
|
||||
GPIO5.initialOutputState = "High";
|
||||
|
||||
PWM1.$name = "CONFIG_PWM_0";
|
||||
PWM1.$hardware = system.deviceData.board.components.LED_RED;
|
||||
@ -53,12 +69,13 @@ Watchdog1.watchdog.$assign = "WATCHDOG0";
|
||||
* 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.
|
||||
*/
|
||||
GPIO1.gpioPin.$suggestSolution = "boosterpack.4";
|
||||
I2C1.i2c.$suggestSolution = "I2C0";
|
||||
GPIO1.gpioPin.$suggestSolution = "boosterpack.18";
|
||||
GPIO4.gpioPin.$suggestSolution = "boosterpack.19";
|
||||
GPIO5.gpioPin.$suggestSolution = "boosterpack.13";
|
||||
PWM1.timer.$suggestSolution = "Timer2";
|
||||
PWM1.timer.pwmPin.$suggestSolution = "boosterpack.29";
|
||||
SPI1.spi.$suggestSolution = "SPI0";
|
||||
SPI1.spi.sclkPin.$suggestSolution = "boosterpack.7";
|
||||
SPI1.spi.sclkPin.$suggestSolution = "boosterpack.17";
|
||||
SPI1.spi.misoPin.$suggestSolution = "boosterpack.14";
|
||||
SPI1.spi.mosiPin.$suggestSolution = "boosterpack.15";
|
||||
SPI1.spi.dmaRxChannel.$suggestSolution = "UDMA_CH30";
|
||||
|
||||
25
pinout.md
Normal file
25
pinout.md
Normal file
@ -0,0 +1,25 @@
|
||||
# pinout
|
||||
|
||||
## GPIO
|
||||
|
||||
| lable | pin |
|
||||
|------------|----:|
|
||||
| start init | P05 |
|
||||
| start sys | P03 |
|
||||
| noodstop | P08 |
|
||||
|
||||
## SPI
|
||||
|
||||
| lable | pin |
|
||||
|--------|----:|
|
||||
| CSK | P45 |
|
||||
| MISO | P06 |
|
||||
| MOSI | P07 |
|
||||
| CS MSP | P18 |
|
||||
| CS ADC | P21 |
|
||||
|
||||
## Other
|
||||
|
||||
| lable | pin |
|
||||
|-------|----:|
|
||||
| PWM | P64 |
|
||||
25
src/MPPT.c
25
src/MPPT.c
@ -3,11 +3,12 @@
|
||||
|
||||
#include "global.h"
|
||||
#include "MPPT.h"
|
||||
#include "spi.h"
|
||||
|
||||
#define PWM_MIN 0.001
|
||||
#define PWM_MAX 0.9
|
||||
|
||||
uint8_t mppt_setpoint, mppt_setpointOverrite;
|
||||
uint8_t mppt_setpoint, mppt_setpointOverrite, mppt_vermogen;
|
||||
uint8_t *mppt_setpointP;
|
||||
|
||||
PWM_Handle mppt_pwm;
|
||||
@ -19,6 +20,16 @@ void mppt_setSetpointOverride(uint8_t vermogen){
|
||||
void mppt_setSetpoint(uint8_t vermogen){
|
||||
mppt_setpoint = vermogen;
|
||||
}
|
||||
uint8_t mppt_getVermogen(){
|
||||
return mppt_vermogen;
|
||||
}
|
||||
|
||||
void mppt_meetVermogen(){
|
||||
uint16_t spanning = ADC_read(ADC_CH2);
|
||||
uint16_t curent = ADC_read(ADC_CH3);
|
||||
//TODO: add real formula for spanning and curent
|
||||
mppt_vermogen = (spanning * curent) / 100;
|
||||
}
|
||||
|
||||
void mppt_init(){
|
||||
PWM_init();
|
||||
@ -28,23 +39,23 @@ void mppt_init(){
|
||||
params.dutyUnits = PWM_DUTY_FRACTION;
|
||||
params.dutyValue = 0;
|
||||
params.periodUnits = PWM_PERIOD_US;
|
||||
params.periodValue = 0;
|
||||
params.periodValue = 10; // 100 kHz
|
||||
mppt_pwm = PWM_open(CONFIG_PWM_0, ¶ms);
|
||||
if (mppt_pwm == NULL) {
|
||||
while (1);
|
||||
}
|
||||
|
||||
mppt_setpointP = &mppt_setpoint;
|
||||
mppt_start();
|
||||
}
|
||||
|
||||
|
||||
void mppt_setPWM(double d){
|
||||
if(d < PWM_MIN){
|
||||
PWM_setDuty(mppt_pwm, 0);
|
||||
return;
|
||||
}
|
||||
if(d > PWM_MAX){
|
||||
d = 0.9;
|
||||
d = PWM_MAX;
|
||||
}
|
||||
PWM_setDuty(mppt_pwm, (uint32_t) ((double) PWM_DUTY_FRACTION_MAX * d));
|
||||
}
|
||||
@ -52,13 +63,15 @@ void mppt_setPWM(double d){
|
||||
void mppt_start(){
|
||||
PWM_start(mppt_pwm);
|
||||
|
||||
//TODO: implement the mppt algaritme
|
||||
double duty = 0, step = 0.01;
|
||||
while(Status == WORKING){
|
||||
while(1){ //(Status == WORKING){
|
||||
mppt_setPWM(duty);
|
||||
duty += step;
|
||||
if(duty > 1){
|
||||
if(duty > 1 || duty < 0){
|
||||
step = -step;
|
||||
duty += step;
|
||||
}
|
||||
usleep(100);
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,14 @@
|
||||
#include <ti/drivers/SPI.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "communicatie.h"
|
||||
#include "spi.h"
|
||||
|
||||
#define SPI_PACKET_LENGTH 4
|
||||
|
||||
|
||||
SPI_Trans_t SPI_MSPTrans;
|
||||
unsigned char ReciveBuffer[SPI_PACKET_LENGTH];
|
||||
unsigned char TransmitBuffer[SPI_PACKET_LENGTH];
|
||||
|
||||
@ -20,37 +25,28 @@ typedef enum {
|
||||
SPIPARM_count
|
||||
} SPI_Register_t;
|
||||
|
||||
// communicatie spi Taak
|
||||
void comm_spi(){
|
||||
// Initialiseer SPI
|
||||
ISP_init();
|
||||
SPI_Params spiParams;
|
||||
SPI_Params_init(&spiParams);
|
||||
spiParams.frameFormat = SPI_POL0_PHA0; // mode0
|
||||
spiParams.bitRate = 1E6; // 1 MHz
|
||||
SPI_Handle masterSpi = SPI_open(CONFIG_SPI_MASTER, &spiParams);
|
||||
if (masterSpi == NULL) {
|
||||
// Display_printf(display, 0, 0, "Error initializing master SPI\n");
|
||||
while (1);
|
||||
} else {
|
||||
// Display_printf(display, 0, 0, "Master SPI initialized\n");
|
||||
}
|
||||
#define SPI_INTERVAL (1/100) / SPIPARM_count // update all params 100 time a second
|
||||
|
||||
// create transaction
|
||||
SPI_Transaction spiTransaction;
|
||||
spiTransaction.count = SPI_PACKET_LENGTH;
|
||||
spiTransaction.txBuf = (void *) TransmitBuffer;
|
||||
spiTransaction.rxBuf = (void *) ReciveBuffer;
|
||||
// communicatie spi Taak
|
||||
void comm_init(){
|
||||
// create SPI transaction
|
||||
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.bitRate = 1E6; // 1 MHz
|
||||
SPI_MSPTrans.trans.count = SPI_PACKET_LENGTH;
|
||||
SPI_MSPTrans.trans.txBuf = &TransmitBuffer[0];
|
||||
SPI_MSPTrans.trans.rxBuf = &ReciveBuffer[0];
|
||||
|
||||
// start the loop
|
||||
TransmitBuffer[0] = 0;
|
||||
while(1){
|
||||
// zero the buffers
|
||||
memset((void *) TransmitBuffer+1, 0, SPI_PACKET_LENGTH-1);
|
||||
memset((void *) ReciveBuffer, 0, SPI_PACKET_LENGTH);
|
||||
memset(&TransmitBuffer[0] + 1, 0, SPI_PACKET_LENGTH-1);
|
||||
// memset(&ReciveBuffer[0], 0, SPI_PACKET_LENGTH);
|
||||
|
||||
// set data in the transmit buffer
|
||||
ReciveBuffer[0] = TransmitBuffer[0];
|
||||
switch(TransmitBuffer[0]){
|
||||
case SPIPARM_vermogen:
|
||||
TransmitBuffer[1] = mppt_getVermogen();
|
||||
@ -59,27 +55,26 @@ void comm_spi(){
|
||||
TransmitBuffer[1] = comm_snelheid;
|
||||
break;
|
||||
case SPIPARM_tempratuur:
|
||||
TransmitBuffer[1] = noodstop_getTemptatuur();
|
||||
TransmitBuffer[1] = noodstop_getTempratuur();
|
||||
break;
|
||||
}
|
||||
|
||||
// do the transaction
|
||||
//TODO: set the CS
|
||||
SPI_transaction(masterSpi, &spiTransaction);
|
||||
SPI_trans(&SPI_MSPTrans);
|
||||
|
||||
// read the data out the recive buffer
|
||||
// read the data out the receive buffer
|
||||
switch (ReciveBuffer[0]){
|
||||
case SPIPARM_maxVermogen:
|
||||
noodstop_setMaxVermogen(ReciveBuffer[2]);
|
||||
break;
|
||||
case SPIPARM_maxSnelheid:
|
||||
noodstop_setMaxSnelheid(ReciveBuffer[2] + ReciveBuffer[3]*0x100);
|
||||
noodstop_setMaxSnelheid(ReciveBuffer[2] + ReciveBuffer[3]*0x100); // littel endian
|
||||
break;
|
||||
case SPIPARM_maxTempratuur:
|
||||
noodstop_setMaxTemptratuur(ReciveBuffer[2]);
|
||||
break;
|
||||
case SPIPARM_setpoint:
|
||||
mppt_setSsetpoint(ReciveBuffer[2]);
|
||||
mppt_setSetpoint(ReciveBuffer[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -88,6 +83,6 @@ void comm_spi(){
|
||||
if(TransmitBuffer[0] == SPIPARM_count)
|
||||
TransmitBuffer[0] = 0;
|
||||
|
||||
usleep(5000);
|
||||
usleep(SPI_INTERVAL);
|
||||
}
|
||||
}
|
||||
@ -1,70 +1,67 @@
|
||||
#ifndef COMMUNICATIE_H
|
||||
#define COMMUNICATIE_H
|
||||
|
||||
#include <ti/drivers/SPI.h>
|
||||
//// enummeration for packet IDs
|
||||
//typedef enum {
|
||||
// PACKET_UPDATEBELASTING,
|
||||
// PACKET_NOODSTOP,
|
||||
// PACKET_INITPARAMS
|
||||
//} packetID_t;
|
||||
//
|
||||
//// packet structures
|
||||
//typedef struct packet_0 {
|
||||
// packetID_t id;
|
||||
// bool overheeat;
|
||||
// bool overload;
|
||||
// bool overspeed;
|
||||
//} noodstop;
|
||||
//
|
||||
//typedef struct packet_1 {
|
||||
// packetID_t id;
|
||||
// uint8_t maxVermogen;
|
||||
// uint16_t maxSnelhied;
|
||||
// uint8_t maxTemptratuur;
|
||||
// uint8_t vermogenSetpoint;
|
||||
//} initBelasting;
|
||||
//
|
||||
//typedef struct packet_2 {
|
||||
// packetID_t id;
|
||||
// uint8_t maxVermogen;
|
||||
// uint16_t maxSnelhied;
|
||||
// uint8_t maxTemptratuur;
|
||||
//} maxWaardesBelasting;
|
||||
//
|
||||
//typedef struct packet_3 {
|
||||
// packetID_t id;
|
||||
// uint8_t rendement;
|
||||
// uint16_t snelheid;
|
||||
// uint16_t stroom;
|
||||
// uint16_t spanning;
|
||||
//} dataBelasting;
|
||||
//
|
||||
//typedef struct packet_4 {
|
||||
// packetID_t id;
|
||||
// uint16_t snelheidSetpoint;
|
||||
// uint16_t maxSpanning;
|
||||
// uint16_t maxStroom;
|
||||
//} initAandrijving;
|
||||
//
|
||||
//typedef struct packet_5 {
|
||||
// packetID_t id;
|
||||
// uint8_t rendement;
|
||||
// uint8_t vermogen;
|
||||
// uint16_t stroom;
|
||||
// uint16_t spanning;
|
||||
//} dataAandrijving;
|
||||
//
|
||||
//typedef union I2CPacket_t {
|
||||
// initAandrijving initA;
|
||||
// initBelasting initB;
|
||||
// maxWaardesBelasting maxB;
|
||||
// dataAandrijving dataA;
|
||||
// dataBelasting. dataB;
|
||||
//} I2CPacket_t;
|
||||
|
||||
// enummeration for packet IDs
|
||||
typedef enum {
|
||||
PACKET_UPDATEBELASTING,
|
||||
PACKET_NOODSTOP,
|
||||
PACKET_INITPARAMS
|
||||
} packetID_t;
|
||||
|
||||
// packet structures
|
||||
typedef struct {
|
||||
packetID_t id;
|
||||
bool overheeat;
|
||||
bool overload;
|
||||
bool overspeed;
|
||||
} noodstop;
|
||||
|
||||
typedef struct {
|
||||
packetID_t id;
|
||||
uint8_t maxVermogen;
|
||||
uint16_t maxSnelhied;
|
||||
uint8_t maxTemptratuur;
|
||||
uint8_t vermogenSetpoint;
|
||||
} initBelasting;
|
||||
|
||||
typedef struct {
|
||||
packetID_t id;
|
||||
uint8_t maxVermogen;
|
||||
uint16_t maxSnelhied;
|
||||
uint8_t maxTemptratuur;
|
||||
} maxWaardesBelasting;
|
||||
|
||||
typedef struct {
|
||||
packetID_t id;
|
||||
uint8_t rendement;
|
||||
uint16_t snelheid;
|
||||
uint16_t stroom;
|
||||
uint16_t spanning;
|
||||
} dataBelasting;
|
||||
|
||||
typedef struct {
|
||||
packetID_t id;
|
||||
uint16_t snelheidSetpoint;
|
||||
uint16_t maxSpanning;
|
||||
uint16_t maxStroom;
|
||||
} initAandrijving;
|
||||
|
||||
typedef struct {
|
||||
packetID_t id;
|
||||
uint8_t rendement;
|
||||
uint8_t vermogen;
|
||||
uint16_t stroom;
|
||||
uint16_t spanning;
|
||||
} dataAandrijving;
|
||||
|
||||
union {
|
||||
initAandrijving;
|
||||
initBelasting;
|
||||
maxWaardesBelasting;
|
||||
dataBelasting;
|
||||
initAandrijving;
|
||||
dataAandrijving;
|
||||
} I2CPacket_t;
|
||||
|
||||
void comm_spi();
|
||||
void comm_init();
|
||||
|
||||
#endif
|
||||
|
||||
11
src/debug.h
Normal file
11
src/debug.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
#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)
|
||||
|
||||
#endif
|
||||
@ -4,7 +4,7 @@
|
||||
#include <pthread.h>
|
||||
#include "ti_drivers_config.h"
|
||||
|
||||
enum {
|
||||
typedef enum {
|
||||
SLEEP,
|
||||
INIT,
|
||||
MPPT_READY,
|
||||
@ -15,7 +15,9 @@ enum {
|
||||
OVERLOAD,
|
||||
OVERSPEED,
|
||||
EXT_NOODSTOP
|
||||
} Status;
|
||||
} Status_t;
|
||||
|
||||
Status_t Status;
|
||||
|
||||
pthread_t createSimplePTread(int prio, void * fn);
|
||||
|
||||
|
||||
97
src/main.c
97
src/main.c
@ -1,13 +1,24 @@
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#include <ti/drivers/GPIO.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "communicatie.h"
|
||||
#include "noodstop.h"
|
||||
#include "MPPT.h"
|
||||
#include "spi.h"
|
||||
|
||||
#define ERROR(msg) return; //TODO: create error handeler
|
||||
struct mainTreads {
|
||||
pthread_t comm;
|
||||
pthread_t noodstop;
|
||||
pthread_t mppt;
|
||||
pthread_t sysBeheer;
|
||||
} treads;
|
||||
|
||||
void * mainTask(void *arg);
|
||||
|
||||
//TODO: maybe detach pthread?
|
||||
//TODO: add stacksize option
|
||||
@ -21,24 +32,84 @@ pthread_t createSimplePTread(int prio, void * fn){
|
||||
|
||||
pthread_t thread;
|
||||
if( pthread_create(&thread, &pAttrs, fn, NULL) != 0 ){
|
||||
ERROR("could not create pthread")
|
||||
ERROR("could not create thread")
|
||||
return 0;
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
void startInit(){
|
||||
createSimplePTread(1, &comm_spi);
|
||||
createSimplePTread(1, &noodstop_init);
|
||||
createSimplePTread(1, &mppt_init);
|
||||
SPI_Init();
|
||||
treads.comm = createSimplePTread(3, &comm_init);
|
||||
treads.noodstop = createSimplePTread(1, &noodstop_init);
|
||||
treads.mppt = createSimplePTread(1, &mppt_init);
|
||||
//TODO: add systeembeheer
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Board_init(); // initilaze board
|
||||
|
||||
//TODO: add logic
|
||||
|
||||
BIOS_start(); // start the BIOS
|
||||
void startSys(){
|
||||
treads.mppt = createSimplePTread(2, &mppt_start);
|
||||
treads.noodstop = createSimplePTread(4, &noodstop_start);
|
||||
}
|
||||
void stopSys(){
|
||||
// pthread_exit(treads.comm);
|
||||
pthread_exit(treads.noodstop);
|
||||
pthread_exit(treads.mppt);
|
||||
|
||||
treads.noodstop = createSimplePTread(3, &noodstop_deinit);
|
||||
}
|
||||
|
||||
void initISR(){
|
||||
if(Status == WORKING || Status == INIT)
|
||||
return;
|
||||
Status = INIT;
|
||||
treads.sysBeheer = createSimplePTread(1, mainTask);
|
||||
}
|
||||
void startSysISR(){
|
||||
if(GPIO_read(CONFIG_GPIO_START)){
|
||||
if(Status != ALL_READY){
|
||||
Status = EXT_NOODSTOP;
|
||||
noodstop_activeerNoodstop();
|
||||
stopSys();
|
||||
return;
|
||||
}else{
|
||||
Status = WORKING;
|
||||
}
|
||||
}else{
|
||||
Status = SLEEP;
|
||||
}
|
||||
}
|
||||
|
||||
void * mainTask(void *arg){
|
||||
Status_t lastState;
|
||||
while(1){
|
||||
switch (Status){
|
||||
case SLEEP:
|
||||
stopSys();
|
||||
break;
|
||||
case INIT:
|
||||
startInit();
|
||||
break;
|
||||
case WORKING:
|
||||
startSys();
|
||||
break;
|
||||
case OVERHEAD:
|
||||
case OVERLOAD:
|
||||
case OVERSPEED:
|
||||
case EXT_NOODSTOP:
|
||||
stopSys();
|
||||
return;
|
||||
}
|
||||
lastState = Status;
|
||||
while(Status == lastState)
|
||||
usleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
Status = SLEEP;
|
||||
Board_init(); // initialise board
|
||||
treads.sysBeheer = createSimplePTread(1, mainTask);
|
||||
BIOS_start(); // start the BIOS
|
||||
while(1)
|
||||
usleep(1E6);
|
||||
}
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
#include <ti/drivers/GPIO.h>
|
||||
#include <ti/drivers/ADC.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "communicatie.h"
|
||||
#include "MPPT.h"
|
||||
#include "spi.h"
|
||||
|
||||
struct {
|
||||
uint8_t maxTempratuur;
|
||||
uint8_t maxVermogen;
|
||||
uint16_t maxSnelheid;
|
||||
} nood_maxwaardes;
|
||||
|
||||
extern pthread_t createSimplePTread(int prio, void * fn);
|
||||
pthread_t adcThread;
|
||||
uint8_t temp;
|
||||
|
||||
void noodstop_setMaxVermogen(uint8_t value){
|
||||
nood_maxwaardes.maxVermogen = value;
|
||||
@ -28,8 +29,6 @@ void noodstop_setMaxTemptratuur(uint8_t value){
|
||||
void noodstop_activeerNoodstop(){
|
||||
// zet noodstop GPIO als uitgang en laag
|
||||
GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_OUT_LOW); //TODO: check config
|
||||
|
||||
// set status
|
||||
}
|
||||
|
||||
void noodstop_snelhied(uint16_t snelhied){
|
||||
@ -47,33 +46,48 @@ void noodstop_snelhied(uint16_t snelhied){
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t noodstop_getTempratuur(){
|
||||
return temp;
|
||||
}
|
||||
|
||||
uint8_t noodstop_readTemp(uint8_t ch){
|
||||
uint16_t v = ADC_read(&SPI_ADC);
|
||||
|
||||
//TODO: add real fomula
|
||||
|
||||
return v >> 2;
|
||||
}
|
||||
|
||||
void noodstop_tempratuurHandle(){
|
||||
uint8_t tempratuur;
|
||||
uint8_t tempB;
|
||||
do{
|
||||
// wacht 0.1 seconde
|
||||
usleep(100E3);
|
||||
|
||||
// lees ADC uit
|
||||
//TODO: do it!
|
||||
|
||||
// bereken temperatuur
|
||||
//?? Yeti wat is die formule?
|
||||
tempratuur = ~0;
|
||||
// read tempretures
|
||||
temp = noodstop_readTemp(ADC_CH0);
|
||||
tempB = noodstop_readTemp(ADC_CH1);
|
||||
if(temp < tempB)
|
||||
temp = tempB;
|
||||
|
||||
// controleer temperatuur
|
||||
}while(tempratuur < nood_maxwaardes.maxTempratuur);
|
||||
}while(temp < nood_maxwaardes.maxTempratuur);
|
||||
|
||||
// vermogen override = 0W
|
||||
mppt_vermogenOverride(0);
|
||||
mppt_setSetpointOverride(0);
|
||||
|
||||
// activeer noostop
|
||||
Status = OVERHEAD;
|
||||
noodstop_activeerNoodstop();
|
||||
}
|
||||
|
||||
void noodstop_noodstopISR(){
|
||||
/** noodstopISR()
|
||||
* ISR for the external emergency stop from the button or other devides
|
||||
* The ISR is created in the syscfg.
|
||||
*/
|
||||
void noodstopISR(){
|
||||
// Wacht 0.5 seconde
|
||||
usleep(500000);
|
||||
usleep(500E3);
|
||||
|
||||
// activeer noostop
|
||||
Status = EXT_NOODSTOP;
|
||||
@ -81,9 +95,6 @@ void noodstop_noodstopISR(){
|
||||
}
|
||||
|
||||
void noodstop_init(){
|
||||
// ADC init
|
||||
//TODO: do it!
|
||||
|
||||
// GPIO init
|
||||
GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_IN_PU); //TODO: check config
|
||||
|
||||
@ -109,24 +120,14 @@ void noodstop_init(){
|
||||
}else{
|
||||
ERROR("invalid Status");
|
||||
}
|
||||
|
||||
// wacht tot status == werken
|
||||
while(Status != WORKING){
|
||||
usleep(1E3);
|
||||
}
|
||||
|
||||
// start the treath voor het uitlezen van de temptatuur
|
||||
pthread_t adcThread = createSimplePTread(1, &noodstop_tempratuurHandle);
|
||||
|
||||
// Maak interrupt voor noodstop signaal
|
||||
//TODO: do it!
|
||||
|
||||
// wait until it stops
|
||||
while(Status = WORKING){
|
||||
usleep(5E3);
|
||||
}
|
||||
|
||||
// stop threadhs
|
||||
Task_delete(adcThread);
|
||||
//TODO: deinit ADC
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -6,8 +6,13 @@
|
||||
void noodstop_setMaxVermogen(uint8_t value);
|
||||
void noodstop_setMaxSnelheid(uint16_t value);
|
||||
void noodstop_setMaxTemptratuur(uint8_t value);
|
||||
|
||||
void noodstop_snelhied(uint16_t snelhied);
|
||||
|
||||
void noodstop_init();
|
||||
void noodstop_start();
|
||||
void noodstop_deinit();
|
||||
|
||||
uint8_t noodstop_getTempratuur();
|
||||
void noodstop_activeerNoodstop();
|
||||
|
||||
#endif
|
||||
58
src/spi.c
Normal file
58
src/spi.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include "spi.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
uint8_t ADC_TxBuf[4];
|
||||
uint8_t ADC_RxBuf[4];
|
||||
|
||||
void SPI_Init(){
|
||||
SPI_init();
|
||||
|
||||
// init ADC
|
||||
SPI_Params_init(&SPI_ADC.params);
|
||||
SPI_ADC.interface = CONFIG_SPI_MASTER;
|
||||
SPI_ADC.cs = CONFIG_GPIO_CSMSP;
|
||||
SPI_ADC.params.frameFormat = SPI_POL0_PHA0; // mode 0
|
||||
SPI_ADC.params.bitRate = 1E6; // 1 MHz
|
||||
SPI_ADC.trans.count = 4;
|
||||
SPI_ADC.trans.txBuf = &ADC_TxBuf;
|
||||
SPI_ADC.trans.rxBuf = &ADC_RxBuf;
|
||||
|
||||
ADC_TxBuf[0] = 1; // set start bit
|
||||
}
|
||||
|
||||
uint16_t ADC_read(uint8_t ch){
|
||||
while(SPI_Handaler != NULL)
|
||||
usleep(10);
|
||||
ADC_TxBuf[1] = ch; // set channel
|
||||
SPI_trans(&SPI_ADC);
|
||||
return (ADC_TxBuf[2] & 0b11) * 0x100 | ADC_TxBuf[3];
|
||||
}
|
||||
|
||||
int SPI_trans(SPI_Trans_t *trans){
|
||||
SPI_Handle spih;
|
||||
|
||||
// wait until last transation is done
|
||||
while(SPI_Handaler != NULL)
|
||||
usleep(10);
|
||||
SPI_Handaler = &spih;
|
||||
|
||||
// open spi connection with paramaters of this one
|
||||
spih = SPI_open(CONFIG_SPI_MASTER, &trans->params);
|
||||
if (spih == NULL) {
|
||||
ERROR("initialising SPI for communicating with the MSP\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// do the transaction
|
||||
GPIO_write(trans->cs, 0);
|
||||
SPI_transfer(spih, &trans->trans);
|
||||
GPIO_write(trans->cs, 1);
|
||||
|
||||
// close it so its can be used next time
|
||||
SPI_close(spih);
|
||||
SPI_Handaler = NULL;
|
||||
return 0;
|
||||
}
|
||||
36
src/spi.h
Normal file
36
src/spi.h
Normal file
@ -0,0 +1,36 @@
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <ti/drivers/GPIO.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ADC_SINGELCH 1 << 7
|
||||
#define ADC_CH0 ADC_SINGELCH | 0 << 4
|
||||
#define ADC_CH1 ADC_SINGELCH | 1 << 4
|
||||
#define ADC_CH2 ADC_SINGELCH | 2 << 4
|
||||
#define ADC_CH3 ADC_SINGELCH | 3 << 4
|
||||
#define ADC_CH4 ADC_SINGELCH | 4 << 4
|
||||
#define ADC_CH5 ADC_SINGELCH | 5 << 4
|
||||
#define ADC_CH6 ADC_SINGELCH | 6 << 4
|
||||
#define ADC_CH7 ADC_SINGELCH | 7 << 4
|
||||
#define ADC_CH01 0 << 4
|
||||
#define ADC_CH10 1 << 4
|
||||
#define ADC_CH23 2 << 4
|
||||
#define ADC_CH32 3 << 4
|
||||
#define ADC_CH45 4 << 4
|
||||
#define ADC_CH54 5 << 4
|
||||
#define ADC_CH67 6 << 4
|
||||
#define ADC_CH76 7 << 4
|
||||
|
||||
typedef struct SPI_Trans_t {
|
||||
SPI_Transaction trans;
|
||||
uint_least8_t interface;
|
||||
SPI_Params params;
|
||||
uint_least8_t cs;
|
||||
} 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);
|
||||
Loading…
x
Reference in New Issue
Block a user