Update for MKL27Z
This commit is contained in:
@@ -40,7 +40,7 @@ struct DMAMUX {
|
|||||||
volatile uint32_t CHCFG2;
|
volatile uint32_t CHCFG2;
|
||||||
volatile uint32_t CHCFG3;
|
volatile uint32_t CHCFG3;
|
||||||
};
|
};
|
||||||
static struct DMAMUX *const DMAMUX = (struct DMAMUX *const)0x40021000;
|
static struct DMAMUX *const DMAMUX = (struct DMAMUX *)0x40021000;
|
||||||
|
|
||||||
#define INTR_REQ_DMA0 0
|
#define INTR_REQ_DMA0 0
|
||||||
|
|
||||||
@@ -50,8 +50,8 @@ struct DMA {
|
|||||||
volatile uint32_t DSR_BCR;
|
volatile uint32_t DSR_BCR;
|
||||||
volatile uint32_t DCR;
|
volatile uint32_t DCR;
|
||||||
};
|
};
|
||||||
static struct DMA *const DMA0 = (struct DMA *const)0x40008100;
|
static struct DMA *const DMA0 = (struct DMA *)0x40008100;
|
||||||
static struct DMA *const DMA1 = (struct DMA *const)0x40008110;
|
static struct DMA *const DMA1 = (struct DMA *)0x40008110;
|
||||||
|
|
||||||
|
|
||||||
/* We don't use ADC interrupt. Just for reference. */
|
/* We don't use ADC interrupt. Just for reference. */
|
||||||
@@ -92,7 +92,7 @@ struct ADC {
|
|||||||
volatile uint32_t CLM1;
|
volatile uint32_t CLM1;
|
||||||
volatile uint32_t CLM0;
|
volatile uint32_t CLM0;
|
||||||
};
|
};
|
||||||
static struct ADC *const ADC0 = (struct ADC *const)0x4003B000;
|
static struct ADC *const ADC0 = (struct ADC *)0x4003B000;
|
||||||
|
|
||||||
/* SC1 */
|
/* SC1 */
|
||||||
#define ADC_SC1_DIFF (1 << 5)
|
#define ADC_SC1_DIFF (1 << 5)
|
||||||
|
|||||||
@@ -142,6 +142,43 @@ get_hex (struct tty *tty, const char *s, uint32_t *v_p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define TOUCH_VALUE_HIGH 195
|
||||||
|
#define TOUCH_VALUE_LOW 150
|
||||||
|
static void
|
||||||
|
cmd_button (struct tty *tty, const char *line)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
extern uint16_t touch_get (void);
|
||||||
|
uint16_t v0 = 0;
|
||||||
|
int touched = 0;
|
||||||
|
|
||||||
|
(void)line;
|
||||||
|
put_line (tty, "Please touch the bear.\r\n");
|
||||||
|
|
||||||
|
while (i < 16)
|
||||||
|
{
|
||||||
|
uint16_t v = touch_get ();
|
||||||
|
v0 = (v0 * 2 + v)/3;
|
||||||
|
|
||||||
|
if (touched == 0 && v0 > TOUCH_VALUE_HIGH)
|
||||||
|
{
|
||||||
|
tty_send (tty, "!", 1);
|
||||||
|
touched = 1;
|
||||||
|
}
|
||||||
|
else if (touched == 1 && v0 < TOUCH_VALUE_LOW)
|
||||||
|
{
|
||||||
|
tty_send (tty, ".", 1);
|
||||||
|
touched = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
chopstx_usec_wait (10*1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
tty_send (tty, "\r\n", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cmd_touch (struct tty *tty, const char *line)
|
cmd_touch (struct tty *tty, const char *line)
|
||||||
{
|
{
|
||||||
@@ -149,7 +186,7 @@ cmd_touch (struct tty *tty, const char *line)
|
|||||||
extern uint16_t touch_get (void);
|
extern uint16_t touch_get (void);
|
||||||
|
|
||||||
(void)line;
|
(void)line;
|
||||||
put_line (tty, "Please touch the bear, type Enter to finish.\r\n");
|
put_line (tty, "Please touch the bear.\r\n");
|
||||||
|
|
||||||
for (i = 0; i < 20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
@@ -449,6 +486,7 @@ cmd_help (struct tty *tty, const char *line)
|
|||||||
|
|
||||||
|
|
||||||
struct command_table command_table[] = {
|
struct command_table command_table[] = {
|
||||||
|
{ "button", cmd_button },
|
||||||
{ "touch", cmd_touch },
|
{ "touch", cmd_touch },
|
||||||
{ "mdw", cmd_mdw },
|
{ "mdw", cmd_mdw },
|
||||||
{ "mww", cmd_mww },
|
{ "mww", cmd_mww },
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const unsigned int *const crc32_table= (const unsigned int *const)0x00000480;
|
const unsigned int *const crc32_table= (const unsigned int *)0x00000480;
|
||||||
|
|
||||||
void
|
void
|
||||||
crc32_init (unsigned int *p)
|
crc32_init (unsigned int *p)
|
||||||
|
|||||||
@@ -7,27 +7,7 @@
|
|||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
#include <sys.h>
|
||||||
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
|
|
||||||
set_led (int on)
|
|
||||||
{
|
|
||||||
if (on)
|
|
||||||
GPIOB->PCOR = (1 << 0); /* PTB0: Clear: Light on */
|
|
||||||
else
|
|
||||||
GPIOB->PSOR = (1 << 0); /* PTB0: Set : Light off */
|
|
||||||
}
|
|
||||||
|
|
||||||
static chopstx_mutex_t mtx;
|
static chopstx_mutex_t mtx;
|
||||||
static chopstx_cond_t cnd0;
|
static chopstx_cond_t cnd0;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ struct TPM {
|
|||||||
volatile uint32_t CONF;
|
volatile uint32_t CONF;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct TPM *const TPM1 = (struct TPM *const)0x40039000;
|
static struct TPM *const TPM1 = (struct TPM *)0x40039000;
|
||||||
|
|
||||||
static chopstx_intr_t tpm1_intr;
|
static chopstx_intr_t tpm1_intr;
|
||||||
#define INTR_REQ_TPM1 18
|
#define INTR_REQ_TPM1 18
|
||||||
@@ -36,8 +36,14 @@ touch_get (void)
|
|||||||
| (0<<0) /* puddselect= 0 */
|
| (0<<0) /* puddselect= 0 */
|
||||||
;
|
;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the timer's counter.
|
||||||
|
* TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=011.
|
||||||
|
*/
|
||||||
|
TPM1->SC = 0xcb;
|
||||||
|
|
||||||
/* Let the register to pull it up. */
|
/* Let the register to pull it up. */
|
||||||
PORTB->PCR1 = (1<<3) /* TPM1_CH1 */
|
PORTB->PCR1 = (3<<8) /* TPM1_CH1 */
|
||||||
| (0<<6) /* DriveStrengthEnable=0 */
|
| (0<<6) /* DriveStrengthEnable=0 */
|
||||||
| (0<<4) /* PassiveFilterEnable=0 */
|
| (0<<4) /* PassiveFilterEnable=0 */
|
||||||
| (1<<2) /* SlewRateEnable = slow */
|
| (1<<2) /* SlewRateEnable = slow */
|
||||||
@@ -46,8 +52,10 @@ touch_get (void)
|
|||||||
;
|
;
|
||||||
|
|
||||||
chopstx_intr_wait (&tpm1_intr);
|
chopstx_intr_wait (&tpm1_intr);
|
||||||
/* Clear overflow. */
|
/* Clear overflow and CH1 capture. */
|
||||||
TPM1->SC |= 0x80;
|
TPM1->STATUS = 0x102;
|
||||||
|
/* Stop the counter. */
|
||||||
|
TPM1->SC = 0;
|
||||||
|
|
||||||
return TPM1->C1V;
|
return TPM1->C1V;
|
||||||
}
|
}
|
||||||
@@ -58,21 +66,13 @@ touch_init (void)
|
|||||||
{
|
{
|
||||||
chopstx_claim_irq (&tpm1_intr, INTR_REQ_TPM1);
|
chopstx_claim_irq (&tpm1_intr, INTR_REQ_TPM1);
|
||||||
|
|
||||||
/* TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=000. */
|
|
||||||
TPM1->SC = 0xc4;
|
|
||||||
|
|
||||||
/* Input capture mode: MSB = 0, MSA = 0 */
|
/* Input capture mode: MSB = 0, MSA = 0 */
|
||||||
/* Rising edge: ELSB=0 ELSA=1 */
|
/* Rising edge: ELSB=0 ELSA=1 */
|
||||||
TPM1->C1SC = 0x82;
|
TPM1->C1SC = 0x84;
|
||||||
TPM1->POL=0;
|
TPM1->POL=0;
|
||||||
|
|
||||||
/* Triggered by TPM1_CH1. */
|
/* No trigger. */
|
||||||
/* channel 1: TRGSEL=0010 */
|
/* Stop on overflow: CSOO=1 */
|
||||||
/* external: TRGSRC=0 */
|
/* Run the timer in the debug mode */
|
||||||
/* active low:TRGPOL=1 */
|
TPM1->CONF = 0x000200c0;
|
||||||
/* stop on overflow: CSOO=1 */
|
|
||||||
/* start on trigger: CSOT=1 */
|
|
||||||
TPM1->CONF = 0x02c30000;
|
|
||||||
|
|
||||||
touch_get ();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct MCG {
|
|||||||
uint8_t reserved2[15]; /* */
|
uint8_t reserved2[15]; /* */
|
||||||
volatile uint8_t MC; /* MCG Miscellaneous Control Register */
|
volatile uint8_t MC; /* MCG Miscellaneous Control Register */
|
||||||
};
|
};
|
||||||
static struct MCG *const MCG = (struct MCG *const)0x40064000;
|
static struct MCG *const MCG = (struct MCG *)0x40064000;
|
||||||
|
|
||||||
struct USB_CLK_RECOVER {
|
struct USB_CLK_RECOVER {
|
||||||
volatile uint8_t CTRL; /* USB Clock */
|
volatile uint8_t CTRL; /* USB Clock */
|
||||||
@@ -51,7 +51,7 @@ struct USB_CLK_RECOVER {
|
|||||||
/* interrupt status */
|
/* interrupt status */
|
||||||
};
|
};
|
||||||
static struct USB_CLK_RECOVER *const USB_CLK_RECOVER =
|
static struct USB_CLK_RECOVER *const USB_CLK_RECOVER =
|
||||||
(struct USB_CLK_RECOVER *const)0x40072140;
|
(struct USB_CLK_RECOVER *)0x40072140;
|
||||||
|
|
||||||
static void __attribute__((used))
|
static void __attribute__((used))
|
||||||
clock_init (void)
|
clock_init (void)
|
||||||
@@ -71,7 +71,7 @@ clock_init (void)
|
|||||||
|
|
||||||
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->SCGC5 = (1 << 10); /* Enable Port B clock */
|
||||||
SIM->SCGC6 = (1 << 25); /* Enable TPM1 clock */
|
SIM->SCGC6 = (1 << 25)|1; /* Enable TPM1 clock */
|
||||||
SIM->COPC = 0; /* COP disabled */
|
SIM->COPC = 0; /* COP disabled */
|
||||||
|
|
||||||
/* Crystal-less USB setup. */
|
/* Crystal-less USB setup. */
|
||||||
|
|||||||
15
mcu/mkl27z.h
15
mcu/mkl27z.h
@@ -28,7 +28,6 @@ struct SIM {
|
|||||||
volatile uint32_t COPC; /* COP Control Register */
|
volatile uint32_t COPC; /* COP Control Register */
|
||||||
volatile uint32_t SRVCOP; /* Service COP */
|
volatile uint32_t SRVCOP; /* Service COP */
|
||||||
};
|
};
|
||||||
static struct SIM *const SIM = (struct SIM *const)0x40047000;
|
|
||||||
|
|
||||||
/* Port control. */
|
/* Port control. */
|
||||||
struct PORT {
|
struct PORT {
|
||||||
@@ -52,9 +51,6 @@ struct PORT {
|
|||||||
uint32_t reserved[6];
|
uint32_t reserved[6];
|
||||||
volatile uint32_t ISFR;
|
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 {
|
struct GPIO {
|
||||||
volatile uint32_t PDOR; /* Port Data Output Register */
|
volatile uint32_t PDOR; /* Port Data Output Register */
|
||||||
@@ -64,6 +60,11 @@ struct GPIO {
|
|||||||
volatile uint32_t PDIR; /* Port Data Input Register */
|
volatile uint32_t PDIR; /* Port Data Input Register */
|
||||||
volatile uint32_t PDDR; /* Port Data Direction 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 SIM *const SIM = (struct SIM *)0x40047000;
|
||||||
static struct GPIO *const GPIOE = (struct GPIO *const)0x400FF100;
|
static struct PORT *const PORTB = (struct PORT *)0x4004A000;
|
||||||
|
static struct PORT *const PORTD = (struct PORT *)0x4004C000;
|
||||||
|
static struct PORT *const PORTE = (struct PORT *)0x4004D000;
|
||||||
|
static struct GPIO *const GPIOB = (struct GPIO *)0x400FF040;
|
||||||
|
static struct GPIO *const GPIOD = (struct GPIO *)0x400FF0C0;
|
||||||
|
static struct GPIO *const GPIOE = (struct GPIO *)0x400FF100;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ struct FTFA {
|
|||||||
/* Note: addressing (3,2,1,0). Use Bx macro. */
|
/* Note: addressing (3,2,1,0). Use Bx macro. */
|
||||||
volatile uint8_t FPROT[4];
|
volatile uint8_t FPROT[4];
|
||||||
};
|
};
|
||||||
static struct FTFA *const FTFA = (struct FTFA *const)0x40020000;
|
static struct FTFA *const FTFA = (struct FTFA *)0x40020000;
|
||||||
|
|
||||||
#define FSTAT_CCIF 0x80
|
#define FSTAT_CCIF 0x80
|
||||||
#define B3 0
|
#define B3 0
|
||||||
@@ -297,7 +297,7 @@ crc32_init (unsigned int *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ORIGINAL_IN_C
|
#ifdef ORIGINAL_IN_C
|
||||||
const unsigned int *const crc32_table= (const unsigned int *const)0x00000500;
|
const unsigned int *const crc32_table= (const unsigned int *)0x00000500;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void __attribute__ ((naked,section(".fixed_function.crc32_u8")))
|
void __attribute__ ((naked,section(".fixed_function.crc32_u8")))
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ struct USB_CONF {
|
|||||||
uint8_t rsvd2[3]; /* */
|
uint8_t rsvd2[3]; /* */
|
||||||
volatile uint8_t ADDINFO; /* Peripheral Additional Info register */
|
volatile uint8_t ADDINFO; /* Peripheral Additional Info register */
|
||||||
};
|
};
|
||||||
static struct USB_CONF *const USB_CONF = (struct USB_CONF *const) 0x40072000;
|
static struct USB_CONF *const USB_CONF = (struct USB_CONF *) 0x40072000;
|
||||||
|
|
||||||
struct USB_CTRL0 {
|
struct USB_CTRL0 {
|
||||||
volatile uint8_t OTGCTL; /* OTG Control register */
|
volatile uint8_t OTGCTL; /* OTG Control register */
|
||||||
};
|
};
|
||||||
static struct USB_CTRL0 *const USB_CTRL0 = (struct USB_CTRL0 *const)0x4007201c;
|
static struct USB_CTRL0 *const USB_CTRL0 = (struct USB_CTRL0 *)0x4007201c;
|
||||||
|
|
||||||
struct USB_CTRL1 {
|
struct USB_CTRL1 {
|
||||||
volatile uint8_t ISTAT; /* Interrupt Status register */
|
volatile uint8_t ISTAT; /* Interrupt Status register */
|
||||||
@@ -82,7 +82,7 @@ struct USB_CTRL1 {
|
|||||||
uint8_t rsvd15[3]; /* */
|
uint8_t rsvd15[3]; /* */
|
||||||
volatile uint8_t BDTPAGE3; /* BDT Page Register 3 */
|
volatile uint8_t BDTPAGE3; /* BDT Page Register 3 */
|
||||||
};
|
};
|
||||||
static struct USB_CTRL1 *const USB_CTRL1 = (struct USB_CTRL1 *const)0x40072080;
|
static struct USB_CTRL1 *const USB_CTRL1 = (struct USB_CTRL1 *)0x40072080;
|
||||||
|
|
||||||
/* Interrupt source bits */
|
/* Interrupt source bits */
|
||||||
#define USB_IS_STALL (1 << 7)
|
#define USB_IS_STALL (1 << 7)
|
||||||
@@ -98,7 +98,7 @@ struct USB_ENDPT {
|
|||||||
volatile uint8_t EP; /* Endpoint Control register */
|
volatile uint8_t EP; /* Endpoint Control register */
|
||||||
uint8_t rsvd17[3];
|
uint8_t rsvd17[3];
|
||||||
};
|
};
|
||||||
static struct USB_ENDPT *const USB_ENDPT = (struct USB_ENDPT *const)0x400720c0;
|
static struct USB_ENDPT *const USB_ENDPT = (struct USB_ENDPT *)0x400720c0;
|
||||||
|
|
||||||
struct USB_CTRL2 {
|
struct USB_CTRL2 {
|
||||||
volatile uint8_t USBCTRL; /* USB Control register */
|
volatile uint8_t USBCTRL; /* USB Control register */
|
||||||
@@ -111,7 +111,7 @@ struct USB_CTRL2 {
|
|||||||
uint8_t rsvd36[7]; /* */
|
uint8_t rsvd36[7]; /* */
|
||||||
volatile uint8_t USBFRMADJUST; /* Frame Adjut Register */
|
volatile uint8_t USBFRMADJUST; /* Frame Adjut Register */
|
||||||
};
|
};
|
||||||
static struct USB_CTRL2 *const USB_CTRL2 = (struct USB_CTRL2 *const)0x40072100;
|
static struct USB_CTRL2 *const USB_CTRL2 = (struct USB_CTRL2 *)0x40072100;
|
||||||
|
|
||||||
/* Buffer Descriptor */
|
/* Buffer Descriptor */
|
||||||
struct BD {
|
struct BD {
|
||||||
@@ -136,7 +136,7 @@ struct BD {
|
|||||||
|
|
||||||
extern uint8_t __usb_bdt__;
|
extern uint8_t __usb_bdt__;
|
||||||
|
|
||||||
static struct BD *const BD_table = (struct BD *const)&__usb_bdt__;
|
static struct BD *const BD_table = (struct BD *)&__usb_bdt__;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
kl27z_usb_init (void)
|
kl27z_usb_init (void)
|
||||||
|
|||||||
Reference in New Issue
Block a user