stlinky entfernt

This commit is contained in:
Rene Hopf
2014-09-21 04:29:05 +02:00
parent 51ef8fd111
commit 0cbb51e22b
2 changed files with 0 additions and 112 deletions
-59
View File
@@ -1,59 +0,0 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "stlinky.h"
volatile struct stlinky g_stlinky_term = {
.magic = STLINKY_MAGIC,
.bufsize = STLINKY_BSIZE,
.txsize = 0,
.rxsize = 0
};
int min(int a, int b){
if(a < b){
return(a);
}
return(b);
}
// returns #send bytes
int stlinky_tx(volatile struct stlinky* st, const char* buf, int siz){
if(stlinky_todo(st)){
return(0);
}
int sz = min(STLINKY_BSIZE, siz);
memcpy((char*) st->txbuf, buf, sz);
st->txsize = (unsigned char) sz;
return sz;
}
// returns #received bytes
/* TODO: We loose data here if we read less than avaliable */
int stlinky_rx(volatile struct stlinky* st, char* buf, int siz){
int sz = min(stlinky_avail(st), siz);
memcpy(buf, (char*) st->rxbuf, sz);
st->rxsize = 0;
return sz;
}
// returns #bytes in rx buffer
int stlinky_avail(volatile struct stlinky* st){
return st->rxsize;
}
// returns #bytes in tx buffer, 0 = can send
int stlinky_todo(volatile struct stlinky* st){
return(st->txsize);
}
// wait for receive
void stlinky_wait_rx(volatile struct stlinky* st){
while(!stlinky_avail(st));
}
// wait for send
void stlinky_wait_tx(volatile struct stlinky* st){
while(stlinky_todo(st));
}
-53
View File
@@ -1,53 +0,0 @@
#ifndef STLINKY_H
#define STLINKY_H
#include <stm32f4_discovery.h>
#include <stm32f4xx_conf.h>
#define STLINKY_MAGIC 0xDEADF00D
#define STLINKY_BSIZE 132
//#define STLINKY_MSIZE 16
//#define STLINKY_NSIZE 8
/* NOTE: Since rxsize/txsize will be always one
AXI transaction these will be hopefully atomic
Therefore we use them as a dumb locking mechanism
*/
struct stlinky {
uint32_t magic; /* [3:0] */
unsigned char bufsize; /* 4 */
char txsize; /* 5 */
char rxsize; /* 6 */
char reserved; /* 7 */
char txbuf[STLINKY_BSIZE];
char rxbuf[STLINKY_BSIZE];
// float monitor[STLINKY_MSIZE];
// char name[STLINKY_MSIZE][STLINKY_NSIZE];
} __attribute__ ((packed));
// send bytes
// returns #send bytes
int stlinky_tx(volatile struct stlinky* st, const char* buf, int siz);
// receive bytes
// returns #received bytes
int stlinky_rx(volatile struct stlinky* st, char* buf, int siz);
// returns #bytes in rx buffer
int stlinky_avail(volatile struct stlinky* st);
// returns #bytes in tx buffer, 0 = can send
int stlinky_todo(volatile struct stlinky* st);
// wait for receive
void stlinky_wait_rx(volatile struct stlinky* st);
// wait for send
void stlinky_wait_tx(volatile struct stlinky* st);
extern volatile struct stlinky g_stlinky_term;
#endif