--- /dev/null
+
+#include "adc.h"
+
+int init_adc(){
+#ifndef OS_POSIX
+ // Set P0.22 and P0.23 as AIN0 -> AD0.1 and AD0.2 (pinsel value 01)
+ PINSEL1=(PINSEL1 & ~(0xF << (22*2-32))) | (1 << (22*2-32)) | (1 << (23*2-32));
+ // Set P0.24 and P0.25 as AIN1 -> AD0.1 and AD0.2 (pinsel value 01)
+ PINSEL1=(PINSEL1 & ~(0xF << (24*2-32))) | (1 << (24*2-32)) | (1 << (25*2-32));
+ // Setting of AD control register
+ AD0CR=__val2mfld(ADCR_SEL,3) | __val2mfld(ADCR_CLKDIV,255) | (ADCR_BURST*1) | (ADCR_PDN*1);
+ // Interupt eneable bit
+ AD0INTEN=0;
+#endif
+ return 0;
+}
+
+int get_adc(adc_stat_t * adcst){
+#ifndef OS_POSIX
+ // Read DATA
+ adcst->temp =__mfld2val(ADDR_RESULT, AD0DR0);
+ adcst->hum =__mfld2val(ADDR_RESULT, AD0DR1);
+#endif
+
+ return 0;
+}
+
+
-#ifndef _ADC_H
-#define _ADC_H
+#ifndef _TEMP_ADC_H
+#define _TEMP_ADC_H
-//addresses of ADC registers
+#include <stdio.h>
-//ADC Control Register
-#define ADCR 0xE0034000
-//ADC Status Register
-#define ADSTAT 0xE0034030
-//ADC Interrupt Enable Register
-#define ADINTEN 0xE003400C
+typedef struct
+{
+ int temp;
+ int hum;
+} adc_stat_t;
-#define ADDR0 0xE0034010
-#define ADDR1 0xE0034014
\ No newline at end of file
+
+typedef struct
+{
+
+} adc_cal_t;
+
+#ifndef OS_POSIX
+ #include <system_def.h>
+ #include <cpu_def.h>
+#endif
+
+ int get_adc(adc_stat_t * adcst);
+ int init_adc();
+
+#endif
#include <system_def.h>
#include <cpu_def.h>
#endif
+
// #include <lpciap.h>
// #include <keyval_id.h>
// #include <keyval_loc.h>
// #include <lpciap_kvpb.h>
//INCLUDE IN CURRENT DIRECTORY
-#include "hydroponie.h"
#include "ul_idstr.h"
+#include "hydroponie.h"
// CONSTANTS
#define UL_DEV "/dev/ulan"
ul_msginfo msginfo;
int addfilt;
+adc_stat_t adcst;
+// adc_cal_t adccal;
+
#ifndef UL_WITHOUT_HANDLE
//kvpb_block_t *kvpb_block=&kvpb_block_global;
uloi_coninfo_t *coninfo=&uloi_coninfo_global;
// OBJECT INTERFACE VARIABLES
uint16_t status_val;
-int16_t oi_temperature = 20;
+int16_t oi_temperature;
int16_t oi_cid_temp;
int16_t oi_per_temp;
-int16_t oi_humidity = 100;
+int16_t oi_humidity;
int16_t oi_cid_hum;
int16_t oi_per_hum;
}
-int send_sn(void){
- //declaration
+void send_sn(void){
int msgsend;
//.preparing of msg
}
-int heartbeat(void){
+void heartbeat(void){
//int period;
int msgsend, i;
int len = HEART_BUF_LEN;
free(buf);
}
-int send_data(void) {
+void send_data(void) {
int msgsend;
uchar *buf;
int i;
int len = DATA_BUF_LEN;
- get_data();
+ init_adc();
+ get_adc(&adcst);
+// PC_adc();
//.preparing of msg
buf = (uchar *) malloc(len*sizeof(uchar)); // NULL NULL NULL CID_TEMP len_data oi_temperature CID_HUM len_data oi_humidity
int2buf(&buf[3],CID_TEMP);
int2buf(&buf[5],2);
int2buf(&buf[7],oi_temperature);
-// int2buf(&buf[9],CID_HUM);
-// int2buf(&buf[11],2);
-// int2buf(&buf[13],oi_humidity);
+ int2buf(&buf[9],CID_HUM);
+ int2buf(&buf[11],2);
+ int2buf(&buf[13],oi_humidity);
- msgsend = ul_send_query(ul_fd, ul_dyac->ul_dysa, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, /*DATA_BUF_LEN*/9);
+ msgsend = ul_send_query(ul_fd, ul_dyac->ul_dysa, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, DATA_BUF_LEN);
printf("[I] DATA\n");
free(buf);
ul_freemsg(ul_fd);
}
-int get_data(void){
+void PC_adc(void){
#ifdef OS_POSIX
- oi_temperature = -25000;
+ oi_temperature = 25;
oi_humidity = 99;
#else
oi_temperature = AD0DR1;
#endif
}
-int accept_SDO(void) {
+void accept_SDO(void) {
// setting lan configuration
if ((ul_inepoll(ul_fd)>0) && (ul_acceptmsg(ul_fd, &msginfo)>=0)) {
}
+void blink(void){
+ #ifndef OS_POSIX
+ while(1){
+ int led1 = 200;
+ int led2 = 0;
+ mstime_t led1_time, led2_time;
+ led1_time = current_time();
+ led2_time = current_time();
+
+ if(led1 == 0) IO0SET=LED1_BIT;
+ else if(led1 == 1) IO0CLR=LED1_BIT;
+ else if((current_time()-led1_time) > led1){
+ IO0PIN=IO0PIN^LED1_BIT;
+ led1_time+=led1;
+ }
+
+ if(led2 == 0) IO0SET=LED2_BIT;
+ else if(led2 == 1) IO0CLR=LED2_BIT;
+ else if((current_time()-led2_time) > led2){
+ IO0PIN=IO0PIN^LED2_BIT;
+ led2_time+=led2;
+ }
+ }
+ #endif
+
+}
+
int main(int argc, char *argv[]) {
//opening file descriptor
uldy_init(ul_dyac,ul_fd,ul_save_sn,ul_save_adr,(char*)ul_idstr,sn);
loop();
+// blink();
ul_close(ul_fd);
+
return EXIT_SUCCESS;
}