big update

This commit is contained in:
Mats van Reenen 2021-01-21 21:56:54 +01:00
parent dfd9b3ba2f
commit 7769a07681
13 changed files with 745 additions and 514 deletions

View File

@ -1,8 +1,8 @@
/** /**
* These arguments were used when this file was generated. They will be automatically applied on subsequent loads * 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. * 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" * @cliArgs --board "/ti/boards/CC3220S_LAUNCHXL" --product "simplelink_cc32xx_sdk@4_20_00_07"
* @versions {"data":"2020090214","timestamp":"2020090214","tool":"1.6.0+1543","templates":"2020090214"} * @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 DMA = scripting.addModule("/ti/drivers/DMA");
const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false); const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false);
const GPIO1 = GPIO.addInstance(); const GPIO1 = GPIO.addInstance();
const I2C = scripting.addModule("/ti/drivers/I2C", {}, false); const GPIO2 = GPIO.addInstance();
const I2C1 = I2C.addInstance(); const GPIO3 = GPIO.addInstance();
const GPIO4 = GPIO.addInstance();
const GPIO5 = GPIO.addInstance();
const PWM = scripting.addModule("/ti/drivers/PWM", {}, false); const PWM = scripting.addModule("/ti/drivers/PWM", {}, false);
const PWM1 = PWM.addInstance(); const PWM1 = PWM.addInstance();
const Power = scripting.addModule("/ti/drivers/Power"); const Power = scripting.addModule("/ti/drivers/Power");
@ -30,12 +32,26 @@ GPIO1.$name = "CONF_GPIO_NOODSTOP";
GPIO1.interruptTrigger = "Falling Edge"; GPIO1.interruptTrigger = "Falling Edge";
GPIO1.pull = "Pull Up"; GPIO1.pull = "Pull Up";
GPIO1.mode = "Dynamic"; GPIO1.mode = "Dynamic";
GPIO1.callbackFunction = "noodstop_noodstopISR"; GPIO1.callbackFunction = "noodstopISR";
I2C1.$name = "CONFIG_I2C_0"; GPIO2.$name = "CONFIG_GPIO_INIT";
I2C1.$hardware = system.deviceData.board.components.LP_I2C; GPIO2.pull = "Pull Down";
I2C1.i2c.sdaPin.$assign = "boosterpack.10"; GPIO2.callbackFunction = "initISR";
I2C1.i2c.sclPin.$assign = "boosterpack.9"; 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.$name = "CONFIG_PWM_0";
PWM1.$hardware = system.deviceData.board.components.LED_RED; 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 * 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. * re-solve from scratch.
*/ */
GPIO1.gpioPin.$suggestSolution = "boosterpack.4"; GPIO1.gpioPin.$suggestSolution = "boosterpack.18";
I2C1.i2c.$suggestSolution = "I2C0"; GPIO4.gpioPin.$suggestSolution = "boosterpack.19";
GPIO5.gpioPin.$suggestSolution = "boosterpack.13";
PWM1.timer.$suggestSolution = "Timer2"; PWM1.timer.$suggestSolution = "Timer2";
PWM1.timer.pwmPin.$suggestSolution = "boosterpack.29"; PWM1.timer.pwmPin.$suggestSolution = "boosterpack.29";
SPI1.spi.$suggestSolution = "SPI0"; SPI1.spi.$suggestSolution = "SPI0";
SPI1.spi.sclkPin.$suggestSolution = "boosterpack.7"; SPI1.spi.sclkPin.$suggestSolution = "boosterpack.17";
SPI1.spi.misoPin.$suggestSolution = "boosterpack.14"; SPI1.spi.misoPin.$suggestSolution = "boosterpack.14";
SPI1.spi.mosiPin.$suggestSolution = "boosterpack.15"; SPI1.spi.mosiPin.$suggestSolution = "boosterpack.15";
SPI1.spi.dmaRxChannel.$suggestSolution = "UDMA_CH30"; SPI1.spi.dmaRxChannel.$suggestSolution = "UDMA_CH30";

25
pinout.md Normal file
View 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 |

View File

@ -3,11 +3,12 @@
#include "global.h" #include "global.h"
#include "MPPT.h" #include "MPPT.h"
#include "spi.h"
#define PWM_MIN 0.001 #define PWM_MIN 0.001
#define PWM_MAX 0.9 #define PWM_MAX 0.9
uint8_t mppt_setpoint, mppt_setpointOverrite; uint8_t mppt_setpoint, mppt_setpointOverrite, mppt_vermogen;
uint8_t *mppt_setpointP; uint8_t *mppt_setpointP;
PWM_Handle mppt_pwm; PWM_Handle mppt_pwm;
@ -19,6 +20,16 @@ void mppt_setSetpointOverride(uint8_t vermogen){
void mppt_setSetpoint(uint8_t vermogen){ void mppt_setSetpoint(uint8_t vermogen){
mppt_setpoint = 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(){ void mppt_init(){
PWM_init(); PWM_init();
@ -28,23 +39,23 @@ void mppt_init(){
params.dutyUnits = PWM_DUTY_FRACTION; params.dutyUnits = PWM_DUTY_FRACTION;
params.dutyValue = 0; params.dutyValue = 0;
params.periodUnits = PWM_PERIOD_US; params.periodUnits = PWM_PERIOD_US;
params.periodValue = 0; params.periodValue = 10; // 100 kHz
mppt_pwm = PWM_open(CONFIG_PWM_0, &params); mppt_pwm = PWM_open(CONFIG_PWM_0, &params);
if (mppt_pwm == NULL) { if (mppt_pwm == NULL) {
while (1); while (1);
} }
mppt_setpointP = &mppt_setpoint; mppt_setpointP = &mppt_setpoint;
mppt_start();
} }
void mppt_setPWM(double d){ void mppt_setPWM(double d){
if(d < PWM_MIN){ if(d < PWM_MIN){
PWM_setDuty(mppt_pwm, 0); PWM_setDuty(mppt_pwm, 0);
return; return;
} }
if(d > PWM_MAX){ if(d > PWM_MAX){
d = 0.9; d = PWM_MAX;
} }
PWM_setDuty(mppt_pwm, (uint32_t) ((double) PWM_DUTY_FRACTION_MAX * d)); PWM_setDuty(mppt_pwm, (uint32_t) ((double) PWM_DUTY_FRACTION_MAX * d));
} }
@ -52,13 +63,15 @@ void mppt_setPWM(double d){
void mppt_start(){ void mppt_start(){
PWM_start(mppt_pwm); PWM_start(mppt_pwm);
//TODO: implement the mppt algaritme
double duty = 0, step = 0.01; double duty = 0, step = 0.01;
while(Status == WORKING){ while(1){ //(Status == WORKING){
mppt_setPWM(duty); mppt_setPWM(duty);
duty += step; duty += step;
if(duty > 1){ if(duty > 1 || duty < 0){
step = -step; step = -step;
duty += step; duty += step;
} }
usleep(100);
} }
} }

View File

@ -1,9 +1,14 @@
#include <ti/drivers/SPI.h>
#include "debug.h"
#include "global.h" #include "global.h"
#include "communicatie.h" #include "communicatie.h"
#include "spi.h"
#define SPI_PACKET_LENGTH 4 #define SPI_PACKET_LENGTH 4
SPI_Trans_t SPI_MSPTrans;
unsigned char ReciveBuffer[SPI_PACKET_LENGTH]; unsigned char ReciveBuffer[SPI_PACKET_LENGTH];
unsigned char TransmitBuffer[SPI_PACKET_LENGTH]; unsigned char TransmitBuffer[SPI_PACKET_LENGTH];
@ -20,37 +25,28 @@ typedef enum {
SPIPARM_count SPIPARM_count
} SPI_Register_t; } SPI_Register_t;
// communicatie spi Taak #define SPI_INTERVAL (1/100) / SPIPARM_count // update all params 100 time a second
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");
}
// create transaction // communicatie spi Taak
SPI_Transaction spiTransaction; void comm_init(){
spiTransaction.count = SPI_PACKET_LENGTH; // create SPI transaction
spiTransaction.txBuf = (void *) TransmitBuffer; SPI_Params_init(&SPI_MSPTrans.params);
spiTransaction.rxBuf = (void *) ReciveBuffer; 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 // start the loop
TransmitBuffer[0] = 0; TransmitBuffer[0] = 0;
while(1){ while(1){
// zero the buffers // zero the buffers
memset((void *) TransmitBuffer+1, 0, SPI_PACKET_LENGTH-1); memset(&TransmitBuffer[0] + 1, 0, SPI_PACKET_LENGTH-1);
memset((void *) ReciveBuffer, 0, SPI_PACKET_LENGTH); // memset(&ReciveBuffer[0], 0, SPI_PACKET_LENGTH);
// set data in the transmit buffer // set data in the transmit buffer
ReciveBuffer[0] = TransmitBuffer[0];
switch(TransmitBuffer[0]){ switch(TransmitBuffer[0]){
case SPIPARM_vermogen: case SPIPARM_vermogen:
TransmitBuffer[1] = mppt_getVermogen(); TransmitBuffer[1] = mppt_getVermogen();
@ -59,27 +55,26 @@ void comm_spi(){
TransmitBuffer[1] = comm_snelheid; TransmitBuffer[1] = comm_snelheid;
break; break;
case SPIPARM_tempratuur: case SPIPARM_tempratuur:
TransmitBuffer[1] = noodstop_getTemptatuur(); TransmitBuffer[1] = noodstop_getTempratuur();
break; break;
} }
// do the transaction // do the transaction
//TODO: set the CS SPI_trans(&SPI_MSPTrans);
SPI_transaction(masterSpi, &spiTransaction);
// read the data out the recive buffer // read the data out the receive buffer
switch (ReciveBuffer[0]){ switch (ReciveBuffer[0]){
case SPIPARM_maxVermogen: case SPIPARM_maxVermogen:
noodstop_setMaxVermogen(ReciveBuffer[2]); noodstop_setMaxVermogen(ReciveBuffer[2]);
break; break;
case SPIPARM_maxSnelheid: case SPIPARM_maxSnelheid:
noodstop_setMaxSnelheid(ReciveBuffer[2] + ReciveBuffer[3]*0x100); noodstop_setMaxSnelheid(ReciveBuffer[2] + ReciveBuffer[3]*0x100); // littel endian
break; break;
case SPIPARM_maxTempratuur: case SPIPARM_maxTempratuur:
noodstop_setMaxTemptratuur(ReciveBuffer[2]); noodstop_setMaxTemptratuur(ReciveBuffer[2]);
break; break;
case SPIPARM_setpoint: case SPIPARM_setpoint:
mppt_setSsetpoint(ReciveBuffer[2]); mppt_setSetpoint(ReciveBuffer[2]);
break; break;
} }
@ -88,6 +83,6 @@ void comm_spi(){
if(TransmitBuffer[0] == SPIPARM_count) if(TransmitBuffer[0] == SPIPARM_count)
TransmitBuffer[0] = 0; TransmitBuffer[0] = 0;
usleep(5000); usleep(SPI_INTERVAL);
} }
} }

View File

@ -1,70 +1,67 @@
#ifndef COMMUNICATIE_H #ifndef COMMUNICATIE_H
#define 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 void comm_init();
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();
#endif #endif

11
src/debug.h Normal file
View 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

View File

@ -4,7 +4,7 @@
#include <pthread.h> #include <pthread.h>
#include "ti_drivers_config.h" #include "ti_drivers_config.h"
enum { typedef enum {
SLEEP, SLEEP,
INIT, INIT,
MPPT_READY, MPPT_READY,
@ -15,7 +15,9 @@ enum {
OVERLOAD, OVERLOAD,
OVERSPEED, OVERSPEED,
EXT_NOODSTOP EXT_NOODSTOP
} Status; } Status_t;
Status_t Status;
pthread_t createSimplePTread(int prio, void * fn); pthread_t createSimplePTread(int prio, void * fn);

View File

@ -1,13 +1,24 @@
#include <stdint.h> #include <stdint.h>
#include <pthread.h> #include <pthread.h>
#include <ti/drivers/GPIO.h>
#include <ti/sysbios/BIOS.h> #include <ti/sysbios/BIOS.h>
#include "debug.h"
#include "global.h" #include "global.h"
#include "communicatie.h" #include "communicatie.h"
#include "noodstop.h" #include "noodstop.h"
#include "MPPT.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: maybe detach pthread?
//TODO: add stacksize option //TODO: add stacksize option
@ -21,24 +32,84 @@ pthread_t createSimplePTread(int prio, void * fn){
pthread_t thread; pthread_t thread;
if( pthread_create(&thread, &pAttrs, fn, NULL) != 0 ){ if( pthread_create(&thread, &pAttrs, fn, NULL) != 0 ){
ERROR("could not create pthread") ERROR("could not create thread")
return 0;
} }
return thread; return thread;
} }
void startInit(){ void startInit(){
createSimplePTread(1, &comm_spi); SPI_Init();
createSimplePTread(1, &noodstop_init); treads.comm = createSimplePTread(3, &comm_init);
createSimplePTread(1, &mppt_init); treads.noodstop = createSimplePTread(1, &noodstop_init);
treads.mppt = createSimplePTread(1, &mppt_init);
//TODO: add systeembeheer //TODO: add systeembeheer
} }
void startSys(){
int main(void) treads.mppt = createSimplePTread(2, &mppt_start);
{ treads.noodstop = createSimplePTread(4, &noodstop_start);
Board_init(); // initilaze board }
void stopSys(){
//TODO: add logic // pthread_exit(treads.comm);
pthread_exit(treads.noodstop);
BIOS_start(); // start the BIOS 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);
} }

View File

@ -1,19 +1,20 @@
#include <ti/drivers/GPIO.h>
#include <ti/drivers/ADC.h>
#include <ti/drivers/SPI.h>
#include <pthread.h> #include <pthread.h>
#include <stdint.h>
#include "debug.h"
#include "global.h" #include "global.h"
#include "communicatie.h" #include "communicatie.h"
#include "MPPT.h" #include "MPPT.h"
#include "spi.h"
struct { struct {
uint8_t maxTempratuur; uint8_t maxTempratuur;
uint8_t maxVermogen; uint8_t maxVermogen;
uint16_t maxSnelheid; uint16_t maxSnelheid;
} nood_maxwaardes; } nood_maxwaardes;
pthread_t adcThread;
extern pthread_t createSimplePTread(int prio, void * fn); uint8_t temp;
void noodstop_setMaxVermogen(uint8_t value){ void noodstop_setMaxVermogen(uint8_t value){
nood_maxwaardes.maxVermogen = value; nood_maxwaardes.maxVermogen = value;
@ -28,8 +29,6 @@ void noodstop_setMaxTemptratuur(uint8_t value){
void noodstop_activeerNoodstop(){ void noodstop_activeerNoodstop(){
// zet noodstop GPIO als uitgang en laag // zet noodstop GPIO als uitgang en laag
GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_OUT_LOW); //TODO: check config GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_OUT_LOW); //TODO: check config
// set status
} }
void noodstop_snelhied(uint16_t snelhied){ 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(){ void noodstop_tempratuurHandle(){
uint8_t tempratuur; uint8_t tempB;
do{ do{
// wacht 0.1 seconde // wacht 0.1 seconde
usleep(100E3); usleep(100E3);
// lees ADC uit // read tempretures
//TODO: do it! temp = noodstop_readTemp(ADC_CH0);
tempB = noodstop_readTemp(ADC_CH1);
// bereken temperatuur if(temp < tempB)
//?? Yeti wat is die formule? temp = tempB;
tempratuur = ~0;
// controleer temperatuur // controleer temperatuur
}while(tempratuur < nood_maxwaardes.maxTempratuur); }while(temp < nood_maxwaardes.maxTempratuur);
// vermogen override = 0W // vermogen override = 0W
mppt_vermogenOverride(0); mppt_setSetpointOverride(0);
// activeer noostop // activeer noostop
Status = OVERHEAD; Status = OVERHEAD;
noodstop_activeerNoodstop(); 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 // Wacht 0.5 seconde
usleep(500000); usleep(500E3);
// activeer noostop // activeer noostop
Status = EXT_NOODSTOP; Status = EXT_NOODSTOP;
@ -81,9 +95,6 @@ void noodstop_noodstopISR(){
} }
void noodstop_init(){ void noodstop_init(){
// ADC init
//TODO: do it!
// GPIO init // GPIO init
GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_IN_PU); //TODO: check config GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_IN_PU); //TODO: check config
@ -109,24 +120,14 @@ void noodstop_init(){
}else{ }else{
ERROR("invalid Status"); ERROR("invalid Status");
} }
}
// wacht tot status == werken
while(Status != WORKING){ void noodstop_start(){
usleep(1E3); // start the treath voor het uitlezen van de temptatuur
} adcThread = createSimplePTread(2, &noodstop_tempratuurHandle);
}
// start the treath voor het uitlezen van de temptatuur
pthread_t adcThread = createSimplePTread(1, &noodstop_tempratuurHandle); void noodstop_deinit(){
// stop threads
// Maak interrupt voor noodstop signaal pthread_exit(adcThread);
//TODO: do it!
// wait until it stops
while(Status = WORKING){
usleep(5E3);
}
// stop threadhs
Task_delete(adcThread);
//TODO: deinit ADC
} }

View File

@ -6,8 +6,13 @@
void noodstop_setMaxVermogen(uint8_t value); void noodstop_setMaxVermogen(uint8_t value);
void noodstop_setMaxSnelheid(uint16_t value); void noodstop_setMaxSnelheid(uint16_t value);
void noodstop_setMaxTemptratuur(uint8_t value); void noodstop_setMaxTemptratuur(uint8_t value);
void noodstop_snelhied(uint16_t snelhied); void noodstop_snelhied(uint16_t snelhied);
void noodstop_init(); void noodstop_init();
void noodstop_start();
void noodstop_deinit();
uint8_t noodstop_getTempratuur();
void noodstop_activeerNoodstop();
#endif #endif

58
src/spi.c Normal file
View 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
View 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);