Tema SCPI Negru Rares-Razvan

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_TemperatureEx by Valentin Tanasa

Committer:
raresnegru22
Date:
Mon Oct 24 10:09:39 2016 +0000
Revision:
13:bd15c17003e7
Parent:
12:7772974713ac
Tema SCPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tanasaro10 9:303d3628986a 1 #include "ble_flash.h"
tanasaro10 9:303d3628986a 2 #include "mbed.h"
tanasaro10 9:303d3628986a 3
tanasaro10 9:303d3628986a 4 #define MAXBUFFER 99u //(((BLE_FLASH_PAGE_SIZE - 4 - sizeof(myData_t))/sizeof(myDataL_t))
tanasaro10 9:303d3628986a 5 #define MAX_WORD_PAGE_DATA 254u // to be computed as round_next_int(MAXBUFFER*sizeof(myDataL_t)+sizeof(myData_t))
tanasaro10 9:303d3628986a 6
tanasaro10 9:303d3628986a 7 #define MAX_PAGE_NUM (NRF_FICR->CODESIZE - 1) // 255
tanasaro10 12:7772974713ac 8 #define MIN_PAGE_NUM 180u
tanasaro10 8:f28ad4600b0f 9
tanasaro10 8:f28ad4600b0f 10
tanasaro10 8:f28ad4600b0f 11 typedef struct{
tanasaro10 9:303d3628986a 12 uint8_t year; // 20_XX, 2016 => 16;
tanasaro10 8:f28ad4600b0f 13 uint8_t month; // 1..12
tanasaro10 9:303d3628986a 14 uint8_t day; // 1..31
tanasaro10 11:baafa4f7a15e 15 uint8_t hours;
tanasaro10 11:baafa4f7a15e 16 uint8_t minutes;
tanasaro10 11:baafa4f7a15e 17 uint8_t seconds;
tanasaro10 11:baafa4f7a15e 18 } mdate_time_t;
tanasaro10 8:f28ad4600b0f 19
tanasaro10 8:f28ad4600b0f 20
tanasaro10 8:f28ad4600b0f 21 typedef struct{
tanasaro10 11:baafa4f7a15e 22 mdate_time_t currentDateTime;
tanasaro10 11:baafa4f7a15e 23 mdate_time_t newDateTime;
tanasaro10 11:baafa4f7a15e 24 bool updateDateTime; // true if currentTime needs to be updated with newTime;
tanasaro10 11:baafa4f7a15e 25 } mdatetime_manager_t;
tanasaro10 11:baafa4f7a15e 26
tanasaro10 8:f28ad4600b0f 27
tanasaro10 9:303d3628986a 28 typedef enum {
tanasaro10 9:303d3628986a 29 eStartAdvertising =0,
tanasaro10 9:303d3628986a 30 eStopAdvertising =1,
tanasaro10 9:303d3628986a 31 eDisconnect =2
tanasaro10 9:303d3628986a 32 } connection_update_t;
tanasaro10 8:f28ad4600b0f 33
tanasaro10 8:f28ad4600b0f 34 typedef struct {
tanasaro10 12:7772974713ac 35 int16_t x;
tanasaro10 12:7772974713ac 36 int16_t y;
tanasaro10 12:7772974713ac 37 int16_t z;
tanasaro10 9:303d3628986a 38 uint16_t temp;
tanasaro10 9:303d3628986a 39 } myPayload_t;
tanasaro10 9:303d3628986a 40
tanasaro10 9:303d3628986a 41
tanasaro10 9:303d3628986a 42 typedef struct {
tanasaro10 9:303d3628986a 43 myPayload_t data;
tanasaro10 11:baafa4f7a15e 44 uint8_t seconds;
tanasaro10 11:baafa4f7a15e 45 uint8_t minutes;
tanasaro10 9:303d3628986a 46 } myDataL_t;
tanasaro10 9:303d3628986a 47
tanasaro10 9:303d3628986a 48 typedef struct {
tanasaro10 11:baafa4f7a15e 49 mdate_time_t datetime; // 6 bytes length
tanasaro10 11:baafa4f7a15e 50 myPayload_t data; // 8 bytes lenth
tanasaro10 8:f28ad4600b0f 51 } myData_t;
tanasaro10 8:f28ad4600b0f 52
tanasaro10 9:303d3628986a 53 typedef struct {
tanasaro10 9:303d3628986a 54 myData_t startData;
tanasaro10 9:303d3628986a 55 myDataL_t myData[MAXBUFFER];
tanasaro10 9:303d3628986a 56 } myDataLog_t;
tanasaro10 9:303d3628986a 57
tanasaro10 9:303d3628986a 58 typedef struct {
tanasaro10 9:303d3628986a 59 myData_t startData;
tanasaro10 9:303d3628986a 60 myDataL_t myData;
tanasaro10 9:303d3628986a 61 } myDataLogShort_t;
tanasaro10 9:303d3628986a 62
tanasaro10 9:303d3628986a 63 /* Return current page to be written in Flash */
tanasaro10 9:303d3628986a 64 uint8_t flash_currPage();
tanasaro10 9:303d3628986a 65
tanasaro10 9:303d3628986a 66 /* Return next page to be written in Flash */
tanasaro10 9:303d3628986a 67 uint8_t flash_go_nextPage();
tanasaro10 9:303d3628986a 68
tanasaro10 9:303d3628986a 69 /* Return page-N (thas has been written in Flash) */
tanasaro10 9:303d3628986a 70 uint8_t flash_prev_N_Page(uint8_t nr_of_pages);
tanasaro10 8:f28ad4600b0f 71
tanasaro10 9:303d3628986a 72 /*search the latest page written and extract the page_nr, date, and time*/
tanasaro10 11:baafa4f7a15e 73 void search_latest_in_flash(mdate_time_t * outDateTime);
tanasaro10 9:303d3628986a 74
tanasaro10 9:303d3628986a 75 /* Update current date and time with tseconds and also if there is a new date/time given */
tanasaro10 11:baafa4f7a15e 76 void update_time(mdatetime_manager_t* myDateTimeVar, uint16_t tseconds);
tanasaro10 9:303d3628986a 77
tanasaro10 9:303d3628986a 78 /* Update buzzer with period in ms =0..9 and duty cycle = 0..9*/
tanasaro10 9:303d3628986a 79 int buzz_int(PwmOut* buzzer, uint8_t period, uint8_t duty_cycle);
tanasaro10 9:303d3628986a 80
tanasaro10 9:303d3628986a 81 /* Print on serial some error from main app*/
tanasaro10 9:303d3628986a 82 void assert_error_app(bool condition, Serial *pc, uint16_t error, uint16_t line, const char* file);