masive update
This commit is contained in:
parent
a925a147f5
commit
dca0fe9bcb
@ -1,7 +1,7 @@
|
|||||||
#ifndef COMMUNICATIE_H
|
#ifndef COMMUNICATIE_H
|
||||||
#define COMMUNICATIE_H
|
#define COMMUNICATIE_H
|
||||||
|
|
||||||
#include <mqueue.h>
|
#include <ti/drivers/SPI.h>
|
||||||
|
|
||||||
// enummeration for packet IDs
|
// enummeration for packet IDs
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -65,4 +65,6 @@ union {
|
|||||||
dataAandrijving;
|
dataAandrijving;
|
||||||
} I2CPacket_t;
|
} I2CPacket_t;
|
||||||
|
|
||||||
|
void comm_spi();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1,5 +1,3 @@
|
|||||||
#include <ti/drivers/SPI.h>
|
|
||||||
|
|
||||||
#include "communicatie.h"
|
#include "communicatie.h"
|
||||||
|
|
||||||
#define SPI_PACKET_LENGTH 4
|
#define SPI_PACKET_LENGTH 4
|
||||||
@ -30,7 +28,7 @@ void comm_spi(){
|
|||||||
SPI_Params_init(&spiParams);
|
SPI_Params_init(&spiParams);
|
||||||
spiParams.frameFormat = SPI_POL0_PHA0; // mode0
|
spiParams.frameFormat = SPI_POL0_PHA0; // mode0
|
||||||
spiParams.bitRate = 1E6; // 1 MHz
|
spiParams.bitRate = 1E6; // 1 MHz
|
||||||
SPI_Handle masterSpi = SPI_open(CONFIG_SPI_MASTER, &spiParams);
|
masterSpi = SPI_open(CONFIG_SPI_MASTER, &spiParams);
|
||||||
if (masterSpi == NULL) {
|
if (masterSpi == NULL) {
|
||||||
// Display_printf(display, 0, 0, "Error initializing master SPI\n");
|
// Display_printf(display, 0, 0, "Error initializing master SPI\n");
|
||||||
while (1);
|
while (1);
|
||||||
@ -66,6 +64,7 @@ void comm_spi(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do the transaction
|
// do the transaction
|
||||||
|
//TODO: set the CS
|
||||||
SPI_transaction(masterSpi, &transaction);
|
SPI_transaction(masterSpi, &transaction);
|
||||||
|
|
||||||
// read the data out the recive buffer
|
// read the data out the recive buffer
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef GLOBALS_H
|
#ifndef GLOBALS_H
|
||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
|
|
||||||
|
#include "ti_drivers_config.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SLEEP,
|
SLEEP,
|
||||||
INIT,
|
INIT,
|
||||||
|
|||||||
14
src/main.c
14
src/main.c
@ -1,7 +1,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <ti/sysbios/BIOS.h>
|
#include <ti/sysbios/BIOS.h>
|
||||||
#include "ti_drivers_config.h"
|
|
||||||
|
#include "global.h"
|
||||||
|
#include "communicatie.h"
|
||||||
|
#include "noodstop.h"
|
||||||
|
#include "MPPT.h"
|
||||||
|
|
||||||
#define ERROR(msg) return; //TODO: create error handeler
|
#define ERROR(msg) return; //TODO: create error handeler
|
||||||
|
|
||||||
@ -23,11 +27,17 @@ pthread_t createSimplePTread(int prio, void * fn){
|
|||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startInit(){
|
||||||
|
createSimplePTread(1, &comm_spi);
|
||||||
|
createSimplePTread(1, &noodstop_init);
|
||||||
|
//TODO: add systeembeheer and mppt
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
Board_init(); // initilaze board
|
Board_init(); // initilaze board
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: add logic
|
||||||
|
|
||||||
BIOS_start(); // start the BIOS
|
BIOS_start(); // start the BIOS
|
||||||
}
|
}
|
||||||
|
|||||||
121
src/noodstop.c
121
src/noodstop.c
@ -1,79 +1,107 @@
|
|||||||
#include <mqueue.h>
|
|
||||||
#include <ti/drivers/GPIO.h>
|
#include <ti/drivers/GPIO.h>
|
||||||
#include <ti/drivers/ADC.h>
|
#include <ti/drivers/ADC.h>
|
||||||
|
#include <ti/drivers/SPI.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "communicatie.h"
|
#include "communicatie.h"
|
||||||
#include "MPPT.h"
|
#include "MPPT.h"
|
||||||
|
|
||||||
struct maxwaardes_t nood_maxwaardes;
|
struct {
|
||||||
|
uint8_t maxTempratuur;
|
||||||
|
uint8_t maxVermogen;
|
||||||
|
uint16_t maxSnelheid;
|
||||||
|
} nood_maxwaardes;
|
||||||
|
|
||||||
extern pthread_t createSimplePTread(int prio, void * fn);
|
extern pthread_t createSimplePTread(int prio, void * fn);
|
||||||
|
|
||||||
void nood_activeerNoodstop(){
|
void noodstop_setMaxVermogen(uint8_t value){
|
||||||
//BLOCK: zet noodstop GPIO als uitgang
|
nood_maxwaardes.maxVermogen = value;
|
||||||
//TODO: do it!
|
}
|
||||||
|
void noodstop_setMaxSnelheid(uint16_t value){
|
||||||
//BLOCK: noodstop GPIO = laag
|
nood_maxwaardes.maxSnelheid = value;
|
||||||
//TODO: do it!
|
}
|
||||||
|
void noodstop_setMaxTemptratuur(uint8_t value){
|
||||||
|
nood_maxwaardes.maxTempratuur = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void snelhied(uint16_t snelhied){
|
void noodstop_activeerNoodstop(){
|
||||||
//TODO: whoosh.
|
// zet noodstop GPIO als uitgang en laag
|
||||||
|
GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_OUT_LOW); //TODO: check config
|
||||||
|
|
||||||
//BLOCK: controleer snelheid
|
// set status
|
||||||
|
}
|
||||||
|
|
||||||
|
void noodstop_snelhied(uint16_t snelhied){
|
||||||
|
// controleer snelheid
|
||||||
if(snelhied > nood_maxwaardes.maxSnelheid){
|
if(snelhied > nood_maxwaardes.maxSnelheid){
|
||||||
//BLOCK: vermogen overwrite = max vermogen
|
// PANIC!!
|
||||||
mppt_vermogenOverride(nood_maxwaardes.maxVermogen);
|
mppt_vermogenOverride(nood_maxwaardes.maxVermogen);
|
||||||
|
|
||||||
//BLOCK: Wacht 0.5 seconde
|
// Wacht 0.5 seconde
|
||||||
usleep(500000);
|
usleep(500E3);
|
||||||
|
|
||||||
//BLOCK: activeer noostop
|
// activeer noostop
|
||||||
nood_activeerNoodstop();
|
Status = OVERSPEED;
|
||||||
|
noodstop_activeerNoodstop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nood_tempratuurHandle(){
|
void noodstop_tempratuurHandle(){
|
||||||
|
uint8_t tempratuur;
|
||||||
do{
|
do{
|
||||||
//BLOCK: wacht 0.1 seconde
|
// wacht 0.1 seconde
|
||||||
usleep(100000);
|
usleep(100E3);
|
||||||
|
|
||||||
//BLOCK: lees ADC uit
|
// lees ADC uit
|
||||||
//TODO: do it!
|
//TODO: do it!
|
||||||
|
|
||||||
//BLOCK: bereken temperatuur
|
// bereken temperatuur
|
||||||
//?? Yeti wat is die formule?
|
//?? Yeti wat is die formule?
|
||||||
|
tempratuur = ~0;
|
||||||
|
|
||||||
//BLOCK: controleer temperatuur
|
// controleer temperatuur
|
||||||
}while(tempratuur < nood_maxwaardes.maxTemptratuur);
|
}while(tempratuur < nood_maxwaardes.maxTempratuur);
|
||||||
|
|
||||||
//BLOCK: vermogen override = 0W
|
// vermogen override = 0W
|
||||||
mppt_vermogenOverride(0);
|
mppt_vermogenOverride(0);
|
||||||
|
|
||||||
//BLOCK: activeer noostop
|
// activeer noostop
|
||||||
nood_activeerNoodstop();
|
Status = OVERHEAD;
|
||||||
|
noodstop_activeerNoodstop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nood_noodstopISR(){
|
void noodstop_noodstopISR(){
|
||||||
//BLOCK: Wacht 0.5 seconde
|
// Wacht 0.5 seconde
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
|
|
||||||
//BLOCK: activeer noostop
|
// activeer noostop
|
||||||
nood_activeerNoodstop();
|
Status = EXT_NOODSTOP;
|
||||||
|
noodstop_activeerNoodstop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nood_init(){
|
void noodstop_init(){
|
||||||
//BLOCK: ADC init
|
// ADC init
|
||||||
//TODO: do it!
|
//TODO: do it!
|
||||||
|
|
||||||
//BLOCK: GPIO init
|
// GPIO init
|
||||||
//TODO: do it!
|
GPIO_setConfig(CONF_GPIO_NOODSTOP, GPIO_CFG_IN_PU); //TODO: check config
|
||||||
|
|
||||||
//BLOCK: wacht op Max waardes
|
memset(&nood_maxwaardes, 0xff, sizeof(nood_maxwaardes)); // set all max value to invalid ones
|
||||||
mq_receive(MaxWaardes_mq, (char*)&nood_maxwaardes, sizeof(nood_maxwaardes), NULL);
|
|
||||||
|
|
||||||
//BLOCK: Update status
|
// controleer max waardes
|
||||||
|
while(1){
|
||||||
|
if(
|
||||||
|
nood_maxwaardes.maxSnelheid <= 60000
|
||||||
|
&& nood_maxwaardes.maxTempratuur >= 60 && nood_maxwaardes.maxTempratuur <= 120
|
||||||
|
&& nood_maxwaardes.maxVermogen <= 250
|
||||||
|
){
|
||||||
|
break; // stop the loop values are valid
|
||||||
|
}
|
||||||
|
usleep(100E3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update status
|
||||||
if(Status == INIT){
|
if(Status == INIT){
|
||||||
Status = NOODSTOP_READY;
|
Status = NOODSTOP_READY;
|
||||||
}else if(Status == MPPT_READY){
|
}else if(Status == MPPT_READY){
|
||||||
@ -82,14 +110,23 @@ void nood_init(){
|
|||||||
ERROR("invalid Status");
|
ERROR("invalid Status");
|
||||||
}
|
}
|
||||||
|
|
||||||
//BLOCK: wacht tot status == werken
|
// wacht tot status == werken
|
||||||
while(Status != WORKING){
|
while(Status != WORKING){
|
||||||
usleep(1000);
|
usleep(1E3);
|
||||||
}
|
}
|
||||||
|
|
||||||
//BLOCK: maak tread voor ADC
|
// start the treath voor het uitlezen van de temptatuur
|
||||||
createSimplePTread(1, &nood_tempratuurHandle);
|
pthread_t adcThread = createSimplePTread(1, &noodstop_tempratuurHandle);
|
||||||
|
|
||||||
//BLOCK: Maak interrupt voor noodstop signaal
|
// Maak interrupt voor noodstop signaal
|
||||||
//TODO: do it!
|
//TODO: do it!
|
||||||
|
|
||||||
|
// wait until it stops
|
||||||
|
while(Status = WORKING){
|
||||||
|
usleep(5E3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop threadhs
|
||||||
|
Task_delete(adcThread);
|
||||||
|
//TODO: deinit ADC
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/noodstop.h
Normal file
13
src/noodstop.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef NOODSTOP_H
|
||||||
|
#define NOODSTOP_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user