
Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
Revision 101:bece931236a2, committed 2016-01-26
- Comitter:
- shreeshas95
- Date:
- Tue Jan 26 13:15:01 2016 +0000
- Parent:
- 100:484a687431cc
- Child:
- 102:80c911a6e736
- Child:
- 109:78f2912e3473
- Commit message:
- Made changes in science thread, and globals for DMA
Changed in this revision
--- a/DefinitionsAndGlobals.h Tue Jan 26 12:37:17 2016 +0000 +++ b/DefinitionsAndGlobals.h Tue Jan 26 13:15:01 2016 +0000 @@ -106,8 +106,13 @@ #define OBOSC_SUB_REP_LE 0x0F #define OBOSC_SUB_RESET 0x07 -// PAYLOAD - #define PAYLOAD_BUFFER_LENGTH 2190 +// PAYLOAD or SCIENCE + #define PAYLOAD_BUFFER_LENGTH 6723 + #define PAY_SPI_MOSI D11 + #define PAY_SPI_MISO D12 + #define PAY_SPI_CLK D13 + #define PAY_SPI_CS D10 + // ****************GLOBAL VARIABLES****************** // DEBUG @@ -156,8 +161,9 @@ uint8_t gLAST_TM[TM_LONG_SIZE]; uint8_t gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE; -// SCIENCE_THREAD +// PAYLOAD OR SCIENCE_THREAD Thread* gSCIENCE_THREAD = NULL; +dmaSPISlave gPAY_SPI(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS); uint8_t gPAYLOAD_BUFFER[PAYLOAD_BUFFER_LENGTH]; // CALL SIGN TM
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SimpleDMA.lib Tue Jan 26 13:15:01 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/Sissors/code/SimpleDMA/#876f3b55e6f5
--- a/ThreadsAndFunctions.h Tue Jan 26 12:37:17 2016 +0000 +++ b/ThreadsAndFunctions.h Tue Jan 26 13:15:01 2016 +0000 @@ -271,82 +271,24 @@ } } +void payload_isr_fun(){ + gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL); +} -uint8_t payload_data[6723]; - void SCIENCE_FUN(void const *args){ - uint8_t *ptr; - //gPC.puts("haha\r\n"); - ptr = &(payload_data[3]); - //gPC.puts("haha2\r\n"); - int counter = 0; - //gPC.puts("haha3\r\n"); - payload_data[2] = 0;//for mode - for(int i = 0; i<60 ;i++){ //for mode 0.....callibra - for(int j= 0; j<48; j++){ //2 byte values - ptr[counter++] = 0; ptr[counter++] = 65; - } - for(int j=96; j <100 ; j++){ - ptr[counter++] = 0; ptr[counter++] = 0; ptr[counter++] = 0; ptr[counter++] = 65; - } - ptr = ptr+112; - counter = 0; - } - //srp(payload_data); - //gPC.puts("data given to payload"); - //gSCIENCE_THREAD->wait(2000); gSCIENCE_THREAD->terminate(); + // initialisation of payload spi + gPAY_SPI.frequency(1000000); + gPAY_SPI.format(8,0); + gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun); + gPAY_SPI.bulkRead_start(); - //while(true){ -// gSCIENCE_THREAD->wait(osWaitForever); -// gLEDR = !gLEDR; -// } while(true){ gPC.puts("entering sci\r\n"); gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL); gPC.puts("sig_set\r\n"); - srp(payload_data); + srp(gPAYLOAD_BUFFER); gPC.puts("exit_srp\r\n"); + gPAY_SPI.bulkRead_start(); } -} - - - -//void SCIENCE_FUN(void const *args){ -//// SPIpayload.format(8,0); -//// SPIpayload.frequency(1000000); -// for ( int i = 0 ; i < PAYLOAD_BUFFER_LENGTH ; i++ ){ -// gPAYLOAD_BUFFER[i] = 1; -// } -// -// // initialise the buffer for dma -// // SPIpayload.bulkRead_init(VAR_SPACE::payload_dma_buffer, PAYLOAD_DMA_SIZE, &payload_interrupt_fun); -// // start dma read -// // SPIpayload.bulkRead_start(); -// -// // attach DMA interrupt -// while(true){ -// gSCIENCE_THREAD->signal_wait(0x01); -// -////*********************************************************THE TEST -// -// //read rtc time later -// uint64_t RTC_time = 0; -// Science_Data_Compression::complete_compression( gPAYLOAD_BUFFER , RTC_time); -//// SPI_mutex.lock(); -//// disk_write(SDcard_lastWritten , 5); -//// SPI_mutex.unlock(); -// -////**********************************************THE TEST -// -//// counter_for_payload++; -//// if(counter_for_payload == 10){ -//// payload_ticker.detach(); -//// ledg = 0; -//// PC.puts("its over\r\n"); -//// } -// -//// SPIpayload.bulkRead_start(); -// -// } -//} \ No newline at end of file +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmaSPIslave.h Tue Jan 26 13:15:01 2016 +0000 @@ -0,0 +1,68 @@ +#ifdef TARGET_KL46Z +class dmaSPISlave : public SPISlave{ + public: +/* +@brief: constructor : initialise the spi slave pins +@param: mosi, miso, sclk, ssel +@return: none +*/ + dmaSPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : SPISlave(mosi, miso, sclk, ssel){ +// trigger appropriate spi for dma + if(_spi.spi == SPI0){ + read_dma.trigger(Trigger_SPI0_RX); + } + else{ + read_dma.trigger(Trigger_SPI1_RX); + } + +// set source for spi slave dma : mosi + read_dma.source(&_spi.spi->DL, false); + } + +/* +@brief: initialise the dma buffer to store the recevied data +@param: read_data : pointer to the buffer + len : length in bytes to store in the buffer + fun : address of the function to attach to the dma interrupt, interrupt is called when the len num of bytes are written to the buffer +@return: none +*/ + void bulkRead_init(uint8_t *read_data, int len, void (*fun)(void) ){ +// acquire(); + _spi.spi->C2 |= SPI_C2_RXDMAE_MASK; + +// auto increment is true + read_dma.destination(read_data, true); + +// specify length + length = len; + +// attach interrupt function + read_dma.attach(fun); + + } + +/* +@brief: start the dma read process : has to be done everytime the buffer gets filled, can be used repeatedly +@param: none +@return: none +*/ + void bulkRead_start(){ +// start the read_dma + read_dma.start(length); + } + +/* +@brief: end dma process and return back to normal spi mode +@param: none +@return: none +*/ + void bulkRead_end(){ +// turn off dma + _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK); + } + + private: + int length; + SimpleDMA read_dma; +}; +#endif \ No newline at end of file
--- a/main.cpp Tue Jan 26 12:37:17 2016 +0000 +++ b/main.cpp Tue Jan 26 13:15:01 2016 +0000 @@ -4,6 +4,8 @@ #define DEBUG 1 +#include "SimpleDMA.h" +#include "dmaSPIslave.h" #include "rtos.h" #include "mbed_debug.h" @@ -25,6 +27,9 @@ void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);} int main() { + #if DEBUG + gPC.puts("welcome to mng_tmtc\r\n"); + #endif //gLEDR = 1; // ******************INITIALISATIONS START******************