]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
New HIS application - weather station, added infrastructure for bsp, fixed bug for
authorsmolik <smolik>
Sat, 14 Jan 2006 19:16:57 +0000 (19:16 +0000)
committersmolik <smolik>
Sat, 14 Jan 2006 19:16:57 +0000 (19:16 +0000)
msc1210 (ainterrupt) applications useing ulan (needs higher extra stack).

14 files changed:
arch/mcs51/generic/libs/misc/vect_fnc.asm
arch/mcs51/generic/libs/ulan/config-hisc.inc
arch/mcs51/mach-msc1210/libs/Makefile.omk
arch/mcs51/mach-msc1210/libs/adc/Makefile [new file with mode: 0644]
arch/mcs51/mach-msc1210/libs/adc/Makefile.omk [new file with mode: 0644]
arch/mcs51/mach-msc1210/libs/adc/msc_adc.c [new file with mode: 0644]
arch/mcs51/mach-msc1210/libs/adc/msc_adc.h [new file with mode: 0644]
board/mcs51/hisc/config/config.thermometer
board/mcs51/hisc/config/config.weather_station [new file with mode: 0644]
board/mcs51/hisc/libs/Makefile.omk
board/mcs51/hisc/libs/bspbase/Makefile [new file with mode: 0644]
board/mcs51/hisc/libs/bspbase/Makefile.omk [new file with mode: 0644]
board/mcs51/hisc/libs/bspbase/bsp0hwinit.c [new file with mode: 0644]
board/mcs51/hisc/libs/bspbase/bspbase.h [new file with mode: 0644]

index b3bedb8a0d9a741b8ce1ff2544d7931cc28ef0c2..2f34a671938b149178d23177279ec5f533ccc5f1 100644 (file)
@@ -14,6 +14,7 @@ AUXR1   DATA  0A2H
 )FI
 
 PUBLIC VEC_SET,VEC_USR,VEC_GET
+EXTRN CODE(_SETUP_BOARD)
 
 %IF(%FOR_SDCC)THEN(
 PUBLIC __SDCC_EXTERNAL_STARTUP
@@ -166,6 +167,7 @@ __SDCC_EXTERNAL_STARTUP:
         CALL    SRETI
         CALL    SRETI
         CALL    SRETI
+       CALL    _SETUP_BOARD
        MOV     DPL,#0
        RET
 SRETI:  RETI
index da53daff3519a8adde3c21acf6108fdb2dc85dc0..dee631391490c378ecccb55fdcd126e846b639dd 100644 (file)
@@ -12,7 +12,7 @@
 
 %DEFINE        (SPN)            (1)     ; Cislo serioveho portu
 
-SER_STACK_EXT  EQU   0          ; Pridavna hodnota pro stack
+SER_STACK_EXT  EQU   5+2        ; Pridavna hodnota pro stack - ainterrupts + 2 bytes extra
 
 END_RAM XDATA 08800H            ; Konec pameti
 LENG_IB EQU   1                 ; Delka vstupniho bufferu v 256 bytu
index 0d091d23b423980f69f428df0262560d8c9adca8..41332817185b94721ecd5369eddd79ca0549edad 100644 (file)
@@ -1,4 +1,4 @@
 # -*- makefile -*-
 
-SUBDIRS = flash
+SUBDIRS = flash adc
 
diff --git a/arch/mcs51/mach-msc1210/libs/adc/Makefile b/arch/mcs51/mach-msc1210/libs/adc/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/arch/mcs51/mach-msc1210/libs/adc/Makefile.omk b/arch/mcs51/mach-msc1210/libs/adc/Makefile.omk
new file mode 100644 (file)
index 0000000..8230812
--- /dev/null
@@ -0,0 +1,7 @@
+# -*- makefile -*-
+
+include_HEADERS =  msc_adc.h
+
+lib_LIBRARIES = msc_adc
+
+msc_adc_SOURCES = msc_adc.c
\ No newline at end of file
diff --git a/arch/mcs51/mach-msc1210/libs/adc/msc_adc.c b/arch/mcs51/mach-msc1210/libs/adc/msc_adc.c
new file mode 100644 (file)
index 0000000..33080b7
--- /dev/null
@@ -0,0 +1,78 @@
+#include <system_def.h>
+#include <cpu_def.h>
+
+bit 
+msc_adc_ready(void) {
+   return AIE&0x20; 
+}
+
+
+long 
+msc_adc_unipolar(void) {
+  _asm
+       mov  a,#0
+       mov  b,_ADRESH
+       mov  dph,_ADRESM
+       mov  dpl,_ADRESL
+  _endasm;
+
+/*  #pragma asm
+       mov     r4,#0
+       mov     r5,ADRESH
+       mov     r6,ADRESM
+       mov     r7,ADRESL
+  #pragma endasm*/
+}
+
+
+long 
+msc_adc_bipolar(void) {
+/*  #pragma asm
+        mov     a,ADRESH
+        mov     r5,a
+       mov     c,acc.7
+       subb    a,acc
+        mov     r4,a
+        mov     r6,ADRESM
+        mov     r7,ADRESL
+  #pragma endasm*/
+}
+
+long 
+msc_adc_summer(void) {
+/*  #pragma asm
+        mov     r4,SUMR3
+        mov     r5,SUMR2
+        mov     r6,SUMR1
+        mov     r7,SUMR0
+  #pragma endasm*/
+}
+
+
+void
+msc_adc_set_input(unsigned char admux) {
+  //         7  6   5   4   3   2    1    0
+  // ADCON1  -  POL SM1 SM0 -   CAL2 CAL1 CAL0
+  ADMUX = admux;               
+}
+
+int 
+msc_adc_init(void) {
+  PDCON &= 0xf7;       //turn on adc
+                       // ACLK min 32
+  ACLK = 15;           // ACLK = 18.432MHz/(1+1)= 0.9216MHz
+  
+  // max 2047          // Data Rate = (ACLK + 1)/64/DECIMATION
+//  DECIMATION = 1080; // Data Rate = 18.432/2/64/14400 = 10.00Hz
+  ADCON2=1080%256;
+  ADCON3=1080/256;
+
+  //         7   6    5      4     3    2    1    0
+  // ADCON0  -   BOD  EVREF  VREFH EBUF PGA2 PGA1 PGA0
+  ADCON0 = 0x30;       // Vref on 2.5V, Buff on, BOD off, PGA 1
+
+  //         7  6   5   4   3   2    1    0
+  // ADCON1  -  POL SM1 SM0 -   CAL2 CAL1 CAL0
+  ADCON1 = 0x01;       // bipolar, auto, self calibration, offset
+  return 0;
+}
diff --git a/arch/mcs51/mach-msc1210/libs/adc/msc_adc.h b/arch/mcs51/mach-msc1210/libs/adc/msc_adc.h
new file mode 100644 (file)
index 0000000..d325087
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef _MSC_ADC_H
+#define _MSC_ADC_H
+
+#include <types.h>
+
+#define MSC_ADC_LSB_BIPOLAR 298.0232e-9
+#define MSC_ADC_V2T_INTERNAL(x) (2664.7*(x)-282.14)
+
+typedef struct msc_adc_input {
+    uint8_t ain;               //input
+    float avg_value;           //avg value
+    uint8_t samples;           //period per avg value
+    uint8_t samples_cnt;       //counter period per avg value
+    uint8_t calibration;
+  } msc_adc_input_t;
+
+typedef struct msc_adc_input_list {
+    uint8_t count;
+    int8_t capacity;
+    msc_adc_input_t **inputs;
+    uint8_t input_position;
+  } msc_adc_input_list_t;
+
+bit msc_adc_ready(void);
+int msc_adc_init(void);
+void msc_adc_set_input(unsigned char admux);
+long msc_adc_unipolar(void);
+
+#endif /* _MSC_ADC_H */
index ae47be5cb0ddc2631f5332115b73e36e6fa28afa..45ca420113ccb742ed38f1acaebd7c664d59386f 100644 (file)
@@ -16,3 +16,5 @@ CONFIG_APP_HISC_THERMOMETR=y
 CONFIG_ULAN=y
 CONFIG_MISC_VECT=y
 CONFIG_ULOI_LT=y
+
+CONFIG_MSC_ADC=y
diff --git a/board/mcs51/hisc/config/config.weather_station b/board/mcs51/hisc/config/config.weather_station
new file mode 100644 (file)
index 0000000..c640a80
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- makefile -*-
+
+APP=weather-station
+
+ARCH=mcs51
+MACH=msc1210
+BOARD=hisc
+
+ULAN_ID=$(APP)-$(BOARD)
+ULAN_CFG=$(BOARD)
+
+TARGET_ARCH = -mmcs51 --model-large
+
+CONFIG_APP_HISC_WEATHER_STATION=y
+
+CONFIG_ULAN=y
+CONFIG_MISC_VECT=y
+CONFIG_ULOI_LT=y
+
+CONFIG_MSC_ADC=y
index e47cf330b81a4aa0d611f94d3a5c4caf80412b35..c9db9336c92821ee7d381c50f000b058d19775f0 100644 (file)
@@ -1,3 +1,5 @@
 # -*- makefile -*-
 
 lib_LDSCRIPTS = $(notdir $(wildcard $(SOURCES_DIR)/*.ld*))
+
+SUBDIRS = bspbase
\ No newline at end of file
diff --git a/board/mcs51/hisc/libs/bspbase/Makefile b/board/mcs51/hisc/libs/bspbase/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/board/mcs51/hisc/libs/bspbase/Makefile.omk b/board/mcs51/hisc/libs/bspbase/Makefile.omk
new file mode 100644 (file)
index 0000000..97e081d
--- /dev/null
@@ -0,0 +1,11 @@
+# -*- makefile -*-
+
+include_HEADERS =  bspbase.h
+
+lib_LIBRARIES = bspbase
+
+bspbase_SOURCES = bsp0hwinit.c
+
+ifeq ($(CONFIG_MSC_ADC),y)
+CFLAGS += -DMSC_ADC_ENABLED
+endif
\ No newline at end of file
diff --git a/board/mcs51/hisc/libs/bspbase/bsp0hwinit.c b/board/mcs51/hisc/libs/bspbase/bsp0hwinit.c
new file mode 100644 (file)
index 0000000..838b776
--- /dev/null
@@ -0,0 +1,56 @@
+#include <bspbase.h>
+#include <vect.h>
+#include <msc_adc.h>
+
+//timers
+uint8_t DATA t100ms;
+bit t100ms_flg;
+
+/****************************************************************************/
+//definice pruseni (casovac)
+
+void ainterrupts(void) interrupt {
+  uint8_t data aie=AIE;
+
+  if (aie & 0x10) {
+    uint8_t msint=MSINT;
+
+    /* timer */
+    if (t100ms==10) { 
+      t100ms=0;
+      t100ms_flg=1;
+    } else t100ms++;
+
+  #ifdef WATCHDOG_ENABLED
+    WATCHDOG_REFRESH();
+  #endif
+  }
+  AI=0; // Clear Aux INT (Bit in EICON)
+} 
+
+/****************************************************************************/
+void setup_board(void) 
+{
+  MCON|=1;              //XDATA memory map to 0x8400
+
+  his_out_putb(0xff);
+
+  MSECH=(CPU_SYS_HZ/1000-1) / 0x100;
+  MSECL=(CPU_SYS_HZ/1000-1) % 0x100;
+  PDCON&=~0x02;  // System Timer ON
+  MSINT=9|128;   //10ms
+  vec_set(ainterrupts,0x33);
+  AIE=0x10;
+
+#ifdef MSC_ADC_ENABLED
+  msc_adc_init();
+#endif
+
+  //********************
+  // watchdog
+#ifdef WATCHDOG_ENABLED
+  WATCHDOG_ON();
+  WATCHDOG_SET_MS(1000); //1s
+#endif
+  
+}
diff --git a/board/mcs51/hisc/libs/bspbase/bspbase.h b/board/mcs51/hisc/libs/bspbase/bspbase.h
new file mode 100644 (file)
index 0000000..7c288f1
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _BSPBASE_H
+#define _BSPBASE_H
+
+#include <types.h>
+#include <system_def.h>
+#include <cpu_def.h>
+
+//timers
+extern uint8_t DATA t100ms;
+extern bit t100ms_flg;
+
+#endif /* _BSPBASE_H */