diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2016-06-29 16:37:09 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2016-06-29 16:38:18 +0900 |
commit | 41ac81a66bc48ff4d34bc5013630f90d4fa561f5 (patch) | |
tree | f7d7d8b9a7282b460b492dc95cba684ba399c26e | |
parent | 986518fba746fe50c98597665d1c4d349b631c1b (diff) |
Update example for fs-bb48
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | example-fs-bb48/Makefile | 2 | ||||
-rw-r--r-- | example-fs-bb48/command.c | 29 | ||||
-rw-r--r-- | example-fs-bb48/sample.c | 4 | ||||
-rw-r--r-- | example-fs-bb48/touch.c | 89 | ||||
-rw-r--r-- | example-fs-bb48/usb-cdc.c | 10 | ||||
-rw-r--r-- | mcu/clk_gpio_init-mkl27z.c | 44 | ||||
-rw-r--r-- | mcu/mkl27z.h | 38 |
8 files changed, 174 insertions, 45 deletions
@@ -1,5 +1,8 @@ 2016-06-29 NIIBE Yutaka <gniibe@fsij.org> + * example-fs-bb48: Update. + * example-fs-bb48/touch.c: New. + * chopstx.c (chopstx_setpriority): Fix sched_lock/unlock. 2016-06-28 NIIBE Yutaka <gniibe@fsij.org> diff --git a/example-fs-bb48/Makefile b/example-fs-bb48/Makefile index bf1fed7..e4d0c73 100644 --- a/example-fs-bb48/Makefile +++ b/example-fs-bb48/Makefile @@ -6,7 +6,7 @@ PROJECT = sample CHOPSTX = .. LDSCRIPT= sample.ld -CSRC = sample.c usb-cdc.c command.c +CSRC = sample.c usb-cdc.c command.c touch.c CHIP=mkl27z USE_SYS = yes diff --git a/example-fs-bb48/command.c b/example-fs-bb48/command.c index 791854a..f498dc7 100644 --- a/example-fs-bb48/command.c +++ b/example-fs-bb48/command.c @@ -51,7 +51,6 @@ static char hexchar (uint8_t x) return '?'; } -#ifdef ENABLE_DECIMAL_OUTPUT static char * compose_decimal (char *s, int value) { @@ -87,7 +86,7 @@ compose_decimal (char *s, int value) return s; } -#endif + static char * compose_hex (char *s, uint32_t v) @@ -144,6 +143,31 @@ get_hex (struct tty *tty, const char *s, uint32_t *v_p) static void +cmd_touch (struct tty *tty, const char *line) +{ + int i; + extern uint16_t touch_get (void); + + (void)line; + put_line (tty, "Please touch the bear, type Enter to finish.\r\n"); + + for (i = 0; i < 20; i++) + { + uint16_t v; + char output[8]; + char *s; + + chopstx_usec_wait (1000*1000); + v = touch_get (); + s = compose_decimal (output, v); + *s++ = '\r'; + *s++ = '\n'; + tty_send (tty, output, s - output); + } +} + + +static void cmd_mdw (struct tty *tty, const char *line) { int i; @@ -425,6 +449,7 @@ cmd_help (struct tty *tty, const char *line) struct command_table command_table[] = { + { "touch", cmd_touch }, { "mdw", cmd_mdw }, { "mww", cmd_mww }, { "fes", cmd_fes }, diff --git a/example-fs-bb48/sample.c b/example-fs-bb48/sample.c index 7d6a3be..1738566 100644 --- a/example-fs-bb48/sample.c +++ b/example-fs-bb48/sample.c @@ -117,6 +117,8 @@ static char hexchar (uint8_t x) } +extern void touch_init (void); + int main (int argc, const char *argv[]) { @@ -144,6 +146,8 @@ main (int argc, const char *argv[]) u = 1; + touch_init (); + tty = tty_open (); tty_wait_configured (tty); diff --git a/example-fs-bb48/touch.c b/example-fs-bb48/touch.c new file mode 100644 index 0000000..895c6bd --- /dev/null +++ b/example-fs-bb48/touch.c @@ -0,0 +1,89 @@ +#include <stdint.h> +#include <stdlib.h> +#include <chopstx.h> +#include <mcu/mkl27z.h> + +struct TPM { + volatile uint32_t SC; + volatile uint32_t CNT; + volatile uint32_t MOD; + volatile uint32_t C0SC; + volatile uint32_t C0V; + volatile uint32_t C1SC; + volatile uint32_t C1V; + uint32_t rsvd0[14]; + volatile uint32_t STATUS; + uint32_t rsvd1[7]; + volatile uint32_t POL; + uint32_t rsvd2[4]; + volatile uint32_t CONF; +}; + +static struct TPM *const TPM1 = (struct TPM *const)0x40039000; + +static chopstx_intr_t tpm1_intr; +#define INTR_REQ_TPM1 18 + +void +touch_init (void) +{ + chopstx_claim_irq (&tpm1_intr, INTR_REQ_TPM1); + + PORTB->PCR1 = (1<<3) /* TPM1_CH1 */ + | (0<<6) /* DriveStrengthEnable=0 */ + | (0<<4) /* PassiveFilterEnable=0 */ + | (1<<2) /* SlewRateEnable = slow */ + | (0<<1) /* pull enable = 0 */ + | (0<<0) /* puddselect= 0 */ + ; + + /* TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=000. */ + TPM1->SC = 0xc4; + + /* Input capture mode: MSB = 0, MSA = 0 */ + /* Rising edge: ELSB=0 ELSA=1 */ + TPM1->C1SC = 0x82; + TPM1->POL=0; + + /* Triggered by TPM1_CH1. */ + /* channel 1: TRGSEL=0010 */ + /* external: TRGSRC=0 */ + /* active low:TRGPOL=1 */ + /* stop on overflow: CSOO=1 */ + /* start on trigger: CSOT=1 */ + TPM1->CONF = 0x02c30000; + + /* Wait overflow. */ + chopstx_intr_wait (&tpm1_intr); + + /* Clear overflow. */ + TPM1->SC |= 0x80; +} + +uint16_t +touch_get (void) +{ + /* Assert LOW. */ + PORTB->PCR1 = (1<<8) /* GPIO */ + | (0<<6) /* DriveStrengthEnable=0 */ + | (0<<4) /* PassiveFilterEnable=0 */ + | (1<<2) /* SlewRateEnable = slow */ + | (0<<1) /* pull enable = 0 */ + | (0<<0) /* puddselect= 0 */ + ; + + /* Let the register to pull it up. */ + PORTB->PCR1 = (1<<3) /* TPM1_CH1 */ + | (0<<6) /* DriveStrengthEnable=0 */ + | (0<<4) /* PassiveFilterEnable=0 */ + | (1<<2) /* SlewRateEnable = slow */ + | (0<<1) /* pull enable = 0 */ + | (0<<0) /* puddselect= 0 */ + ; + + chopstx_intr_wait (&tpm1_intr); + /* Clear overflow. */ + TPM1->SC |= 0x80; + + return TPM1->C1V; +} diff --git a/example-fs-bb48/usb-cdc.c b/example-fs-bb48/usb-cdc.c index 0936a40..38b16ea 100644 --- a/example-fs-bb48/usb-cdc.c +++ b/example-fs-bb48/usb-cdc.c @@ -686,7 +686,10 @@ tty_main (void *arg) while (1) { - chopstx_poll (NULL, 1, &usb_intr); + struct chx_poll_head *pd_array[1] = { + (struct chx_poll_head *)&usb_intr + }; + chopstx_poll (NULL, 1, pd_array); if (usb_intr.ready) { uint8_t ep_num; @@ -919,7 +922,10 @@ tty_recv (struct tty *t, char *buf, uint32_t *timeout) while (1) { - chopstx_poll (timeout, 1, &poll_desc); + struct chx_poll_head *pd_array[1] = { + (struct chx_poll_head *)&poll_desc + }; + chopstx_poll (timeout, 1, pd_array); chopstx_mutex_lock (&t->mtx); r = check_rx (t); chopstx_mutex_unlock (&t->mtx); diff --git a/mcu/clk_gpio_init-mkl27z.c b/mcu/clk_gpio_init-mkl27z.c index 4040136..894a8ad 100644 --- a/mcu/clk_gpio_init-mkl27z.c +++ b/mcu/clk_gpio_init-mkl27z.c @@ -66,10 +66,12 @@ clock_init (void) while ((MCG->S & 0x0c) != 0) ; - SIM->SOPT2 = 0x00040060; /* USBSRC=IRC48, CLOKOUTSEL=LPO, RTC-clock */ + /* TPMSRC=IRC48M, USBSRC=IRC48M, CLOKOUTSEL=LPO, RTC-clock */ + SIM->SOPT2 = 0x01040060; - SIM->SCGC4 = (1 << 18); /* Enable USB FS clock */ + SIM->SCGC4 = (1 << 18); /* Enable USB FS clock */ SIM->SCGC5 = (1 << 10); /* Enable Port B clock */ + SIM->SCGC6 = (1 << 25); /* Enable TPM1 clock */ SIM->COPC = 0; /* COP disabled */ /* Crystal-less USB setup. */ @@ -78,44 +80,6 @@ clock_init (void) } -struct PORT { - volatile uint32_t PCR0; volatile uint32_t PCR1; - volatile uint32_t PCR2; volatile uint32_t PCR3; - volatile uint32_t PCR4; volatile uint32_t PCR5; - volatile uint32_t PCR6; volatile uint32_t PCR7; - volatile uint32_t PCR8; volatile uint32_t PCR9; - volatile uint32_t PCR10; volatile uint32_t PCR11; - volatile uint32_t PCR12; volatile uint32_t PCR13; - volatile uint32_t PCR14; volatile uint32_t PCR15; - volatile uint32_t PCR16; volatile uint32_t PCR17; - volatile uint32_t PCR18; volatile uint32_t PCR19; - volatile uint32_t PCR20; volatile uint32_t PCR21; - volatile uint32_t PCR22; volatile uint32_t PCR23; - volatile uint32_t PCR24; volatile uint32_t PCR25; - volatile uint32_t PCR26; volatile uint32_t PCR27; - volatile uint32_t PCR28; volatile uint32_t PCR29; - volatile uint32_t PCR30; volatile uint32_t PCR31; - volatile uint32_t GPCLR; volatile uint32_t GPCHR; - uint32_t reserved[6]; - volatile uint32_t ISFR; -}; -static struct PORT *const PORTB = (struct PORT *const)0x4004A000; -static struct PORT *const PORTD = (struct PORT *const)0x4004C000; -static struct PORT *const PORTE = (struct PORT *const)0x4004D000; - -struct GPIO { - volatile uint32_t PDOR; /* Port Data Output Register */ - volatile uint32_t PSOR; /* Port Set Output Register */ - volatile uint32_t PCOR; /* Port Clear Output Register */ - volatile uint32_t PTOR; /* Port Toggle Output Register */ - volatile uint32_t PDIR; /* Port Data Input Register */ - volatile uint32_t PDDR; /* Port Data Direction Register */ -}; -static struct GPIO *const GPIOB = (struct GPIO *const)0x400FF040; -static struct GPIO *const GPIOD = (struct GPIO *const)0x400FF0C0; -static struct GPIO *const GPIOE = (struct GPIO *const)0x400FF100; - - static void __attribute__((used)) gpio_init (void) { diff --git a/mcu/mkl27z.h b/mcu/mkl27z.h index 368ef30..ad3c54c 100644 --- a/mcu/mkl27z.h +++ b/mcu/mkl27z.h @@ -29,3 +29,41 @@ struct SIM { volatile uint32_t SRVCOP; /* Service COP */ }; static struct SIM *const SIM = (struct SIM *const)0x40047000; + +/* Port control. */ +struct PORT { + volatile uint32_t PCR0; volatile uint32_t PCR1; + volatile uint32_t PCR2; volatile uint32_t PCR3; + volatile uint32_t PCR4; volatile uint32_t PCR5; + volatile uint32_t PCR6; volatile uint32_t PCR7; + volatile uint32_t PCR8; volatile uint32_t PCR9; + volatile uint32_t PCR10; volatile uint32_t PCR11; + volatile uint32_t PCR12; volatile uint32_t PCR13; + volatile uint32_t PCR14; volatile uint32_t PCR15; + volatile uint32_t PCR16; volatile uint32_t PCR17; + volatile uint32_t PCR18; volatile uint32_t PCR19; + volatile uint32_t PCR20; volatile uint32_t PCR21; + volatile uint32_t PCR22; volatile uint32_t PCR23; + volatile uint32_t PCR24; volatile uint32_t PCR25; + volatile uint32_t PCR26; volatile uint32_t PCR27; + volatile uint32_t PCR28; volatile uint32_t PCR29; + volatile uint32_t PCR30; volatile uint32_t PCR31; + volatile uint32_t GPCLR; volatile uint32_t GPCHR; + uint32_t reserved[6]; + volatile uint32_t ISFR; +}; +static struct PORT *const PORTB = (struct PORT *const)0x4004A000; +static struct PORT *const PORTD = (struct PORT *const)0x4004C000; +static struct PORT *const PORTE = (struct PORT *const)0x4004D000; + +struct GPIO { + volatile uint32_t PDOR; /* Port Data Output Register */ + volatile uint32_t PSOR; /* Port Set Output Register */ + volatile uint32_t PCOR; /* Port Clear Output Register */ + volatile uint32_t PTOR; /* Port Toggle Output Register */ + volatile uint32_t PDIR; /* Port Data Input Register */ + volatile uint32_t PDDR; /* Port Data Direction Register */ +}; +static struct GPIO *const GPIOB = (struct GPIO *const)0x400FF040; +static struct GPIO *const GPIOD = (struct GPIO *const)0x400FF0C0; +static struct GPIO *const GPIOE = (struct GPIO *const)0x400FF100; |