From 4dfc42565c2d1f5b900d8d725126bfde886a8423 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Aug 2016 23:04:53 +0100 Subject: tidy --- app/buzzer.c | 205 ++++++++++++++++++++++++------------------------ app/cdcacm.c | 232 ++++++++++++++++++++++++++++--------------------------- app/console.c | 7 +- app/dialstr.c | 59 +++++++------- app/gpio.c | 187 +++++++++++++++++++++++++------------------- app/led.c | 20 ++--- app/main.c | 25 +++--- app/modem.c | 130 +++++++++++++++++-------------- app/prototypes.h | 131 +++++++++++++++++-------------- app/serial.c | 41 +++++----- app/ticker.c | 8 +- app/usart.c | 30 +++---- app/usb.c | 33 ++++---- 13 files changed, 598 insertions(+), 510 deletions(-) diff --git a/app/buzzer.c b/app/buzzer.c index 4c45630..d6f1eb2 100644 --- a/app/buzzer.c +++ b/app/buzzer.c @@ -8,116 +8,125 @@ int ringing; #define C6 1047 #define E6 1319 -void buzzer_on(void) +void +buzzer_on (void) { - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, - GPIO_TIM1_CH1); - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, - GPIO_TIM1_CH1N); + gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM1_CH1); + gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM1_CH1N); - timer_reset(TIM1); + timer_reset (TIM1); - timer_set_mode(TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1, TIM_CR1_DIR_UP); - timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM2); - timer_enable_oc_output(TIM1, TIM_OC1); - timer_enable_oc_output(TIM1, TIM_OC1N); - timer_enable_break_main_output(TIM1); + timer_set_mode (TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1, + TIM_CR1_DIR_UP); + timer_set_oc_mode (TIM1, TIM_OC1, TIM_OCM_PWM2); + timer_enable_oc_output (TIM1, TIM_OC1); + timer_enable_oc_output (TIM1, TIM_OC1N); + timer_enable_break_main_output (TIM1); - timer_set_oc_value(TIM1, TIM_OC1, period/2); - timer_set_period(TIM1, period); + timer_set_oc_value (TIM1, TIM_OC1, period / 2); + timer_set_period (TIM1, period); - timer_enable_counter(TIM1); + timer_enable_counter (TIM1); } -void buzzer_off(void) + +void +buzzer_off (void) { gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO8); - gpio_clear(GPIOA,GPIO8); + gpio_clear (GPIOA, GPIO8); gpio_set_mode (GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO13); - gpio_clear(GPIOB,GPIO13); - timer_disable_counter(TIM1); + gpio_clear (GPIOB, GPIO13); + timer_disable_counter (TIM1); } -void buzzer_set_freq(int hz) +void +buzzer_set_freq (int hz) { - period=(48000000/4)/hz; - timer_set_oc_value(TIM1, TIM_OC1, period/2); - timer_set_period(TIM1, period); + period = (48000000 / 4) / hz; + timer_set_oc_value (TIM1, TIM_OC1, period / 2); + timer_set_period (TIM1, period); } -void buzzer_init(void) +void +buzzer_init (void) { - /*buzzer*/ - buzzer_off(); - buzzer_set_freq(440); + /*buzzer */ + buzzer_off (); + buzzer_set_freq (440); } -void ring_tick(void) +void +ring_tick (void) { -static int t; - -if (!ringing) return; -ringing--; - -if (!ringing) { - place=0; - buzzer_off(); - return; -} - - - -t++; -if (t<50) return; -t=0; - - -switch(place){ -case 1: -case 3: -case 5: -case 7: - -case 13: -case 15: -case 17: -case 19: - place++; - buzzer_set_freq(C6); - break; - -case 0: -case 12: - place++; - buzzer_set_freq(E6); - buzzer_on(); - break; -case 2: -case 4: -case 6: -case 14: -case 16: -case 18: - place++; - buzzer_set_freq(E6); - break; - -case 8: -case 20: - place++; - buzzer_off(); - break; - -default: - place++; - break; -case 59: - place=0; -} + static int t; + + if (!ringing) + return; + ringing--; + + if (!ringing) + { + place = 0; + buzzer_off (); + return; + } + + + + t++; + if (t < 50) + return; + t = 0; + + + switch (place) + { + case 1: + case 3: + case 5: + case 7: + + case 13: + case 15: + case 17: + case 19: + place++; + buzzer_set_freq (C6); + break; + + case 0: + case 12: + place++; + buzzer_set_freq (E6); + buzzer_on (); + break; + case 2: + case 4: + case 6: + case 14: + case 16: + case 18: + place++; + buzzer_set_freq (E6); + break; + + case 8: + case 20: + place++; + buzzer_off (); + break; + + default: + place++; + break; + case 59: + place = 0; + } @@ -125,19 +134,17 @@ case 59: } -void ring_off(void) +void +ring_off (void) { -place=0; -ringing=0; -buzzer_off(); + place = 0; + ringing = 0; + buzzer_off (); } -void ring(int l) +void +ring (int l) { //mb(); -ringing=l; + ringing = l; } - - - - diff --git a/app/cdcacm.c b/app/cdcacm.c index 930d5ec..05f12b9 100644 --- a/app/cdcacm.c +++ b/app/cdcacm.c @@ -2,154 +2,156 @@ static const struct usb_endpoint_descriptor comm_endp[] = { { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x83, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 16, - .bInterval = 255, - } + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x83, + .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, + .wMaxPacketSize = 16, + .bInterval = 255, + } }; static const struct usb_endpoint_descriptor data_endp[] = { { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x01, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = 64, - .bInterval = 1, - }, + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x01, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = 64, + .bInterval = 1, + }, { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x82, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = 64, - .bInterval = 1, - } + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x82, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = 64, + .bInterval = 1, + } }; -static const struct { +static const struct +{ struct usb_cdc_header_descriptor header; struct usb_cdc_call_management_descriptor call_mgmt; struct usb_cdc_acm_descriptor acm; struct usb_cdc_union_descriptor cdc_union; -} __attribute__((packed)) cdcacm_functional_descriptors = { - .header = { - .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_HEADER, - .bcdCDC = 0x0110, - }, - .call_mgmt = { - .bFunctionLength = - sizeof(struct usb_cdc_call_management_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, - .bmCapabilities = 0, - .bDataInterface = 1, - }, - .acm = { - .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_ACM, - .bmCapabilities = 0, - }, - .cdc_union = { - .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_UNION, - .bControlInterface = 0, - .bSubordinateInterface0 = 1, - } +} __attribute__ ((packed)) cdcacm_functional_descriptors = +{ + .header = + { + .bFunctionLength = + sizeof (struct usb_cdc_header_descriptor),.bDescriptorType = + CS_INTERFACE,.bDescriptorSubtype = USB_CDC_TYPE_HEADER,.bcdCDC = + 0x0110,},.call_mgmt = + { + .bFunctionLength = + sizeof (struct usb_cdc_call_management_descriptor),.bDescriptorType = + CS_INTERFACE,.bDescriptorSubtype = + USB_CDC_TYPE_CALL_MANAGEMENT,.bmCapabilities = 0,.bDataInterface = + 1,},.acm = + { + .bFunctionLength = + sizeof (struct usb_cdc_acm_descriptor),.bDescriptorType = + CS_INTERFACE,.bDescriptorSubtype = USB_CDC_TYPE_ACM,.bmCapabilities = + 0,},.cdc_union = + { + .bFunctionLength = + sizeof (struct usb_cdc_union_descriptor),.bDescriptorType = + CS_INTERFACE,.bDescriptorSubtype = + USB_CDC_TYPE_UNION,.bControlInterface = 0,.bSubordinateInterface0 = 1,} }; const struct usb_interface_descriptor comm_iface[] = { { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_CDC, - .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, - .iInterface = 0, - .endpoint = comm_endp, - .extra = &cdcacm_functional_descriptors, - .extralen = sizeof(cdcacm_functional_descriptors) - } + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_CLASS_CDC, + .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, + .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, + .iInterface = 0, + .endpoint = comm_endp, + .extra = &cdcacm_functional_descriptors, + .extralen = sizeof (cdcacm_functional_descriptors)} }; const struct usb_interface_descriptor data_iface[] = { { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0, - .endpoint = data_endp, - } + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 1, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_DATA, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = 0, + .endpoint = data_endp, + } }; -int cdcacm_control_request(usbd_device *usbd_dev, - struct usb_setup_data *req, - uint8_t **buf, - uint16_t *len, - int (**complete)(usbd_device *usbd_dev, - struct usb_setup_data *req)) +int +cdcacm_control_request (usbd_device * usbd_dev, + struct usb_setup_data *req, + uint8_t ** buf, + uint16_t * len, + int (**complete) (usbd_device * usbd_dev, + struct usb_setup_data * req)) { - (void)complete; - (void)buf; - (void)usbd_dev; + (void) complete; + (void) buf; + (void) usbd_dev; - switch(req->bRequest) { - case USB_CDC_REQ_SET_CONTROL_LINE_STATE: { - /* - * This Linux cdc_acm driver requires this to be implemented - * even though it's optional in the CDC spec, and we don't - * advertise it in the ACM functional descriptor. - */ - char local_buf[10]; - struct usb_cdc_notification *notif = (void *)local_buf; + switch (req->bRequest) + { + case USB_CDC_REQ_SET_CONTROL_LINE_STATE: + { + /* + * This Linux cdc_acm driver requires this to be implemented + * even though it's optional in the CDC spec, and we don't + * advertise it in the ACM functional descriptor. + */ + char local_buf[10]; + struct usb_cdc_notification *notif = (void *) local_buf; - /* We echo signals back to host as notification. */ - notif->bmRequestType = 0xA1; - notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; - notif->wValue = 0; - notif->wIndex = 0; - notif->wLength = 2; - local_buf[8] = req->wValue & 3; - local_buf[9] = 0; - // usbd_ep_write_packet(0x83, buf, 10); - return 1; - } - case USB_CDC_REQ_SET_LINE_CODING: - if(*len < sizeof(struct usb_cdc_line_coding)) { - return 0; + /* We echo signals back to host as notification. */ + notif->bmRequestType = 0xA1; + notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; + notif->wValue = 0; + notif->wIndex = 0; + notif->wLength = 2; + local_buf[8] = req->wValue & 3; + local_buf[9] = 0; + // usbd_ep_write_packet(0x83, buf, 10); + return 1; + } + case USB_CDC_REQ_SET_LINE_CODING: + if (*len < sizeof (struct usb_cdc_line_coding)) + { + return 0; + } + return 1; } - return 1; - } return 0; } -void cdcacm_data_tx(void *buf,size_t len) +void +cdcacm_data_tx (void *buf, size_t len) { - usbd_ep_write_packet(usbd_dev, 0x82, buf, len); + usbd_ep_write_packet (usbd_dev, 0x82, buf, len); } -void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) +void +cdcacm_data_rx_cb (usbd_device * usbd_dev, uint8_t ep) { - (void)ep; + (void) ep; char buf[64]; - int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64); + int len = usbd_ep_read_packet (usbd_dev, 0x01, buf, 64); - if (len) - usart2_tx(buf,len); + if (len) + usart2_tx (buf, len); } diff --git a/app/console.c b/app/console.c index ae32e38..a0c6ab4 100644 --- a/app/console.c +++ b/app/console.c @@ -6,12 +6,13 @@ -int console_tx(void *buf,size_t len) +int +console_tx (void *buf, size_t len) { -usart1_tx(buf,len); + usart1_tx (buf, len); -return len; + return len; } diff --git a/app/dialstr.c b/app/dialstr.c index f75a8e4..1277a42 100644 --- a/app/dialstr.c +++ b/app/dialstr.c @@ -1,49 +1,54 @@ #include "project.h" #define DIGIT_TIMEOUT 4000 -static char dialstr[32]="ATDT"; -static unsigned dialstr_ptr=4; +static char dialstr[32] = "ATDT"; +static unsigned dialstr_ptr = 4; static int dialstr_timeout; -void dialstr_clear(void) +void +dialstr_clear (void) { -dialstr_ptr=4; -dialstr[dialstr_ptr]=';'; -dialstr[dialstr_ptr+1]=0; + dialstr_ptr = 4; + dialstr[dialstr_ptr] = ';'; + dialstr[dialstr_ptr + 1] = 0; } -void dialstr_digit(int digit) +void +dialstr_digit (int digit) { -if (!dialstr_timeout) dialstr_clear(); -if (dialstr_ptr>=(sizeof(dialstr)-2)) return; + if (!dialstr_timeout) + dialstr_clear (); + if (dialstr_ptr >= (sizeof (dialstr) - 2)) + return; -dialstr[dialstr_ptr]='0'+digit; -dialstr_ptr++; -dialstr[dialstr_ptr]=';'; -dialstr[dialstr_ptr+1]=0; + dialstr[dialstr_ptr] = '0' + digit; + dialstr_ptr++; + dialstr[dialstr_ptr] = ';'; + dialstr[dialstr_ptr + 1] = 0; -dialstr_timeout=DIGIT_TIMEOUT; -printf("Dialstr is now %s\r\n",dialstr+4); + dialstr_timeout = DIGIT_TIMEOUT; + printf ("Dialstr is now %s\r\n", dialstr + 4); } -void dialstr_dial(void) +void +dialstr_dial (void) { -printf("Dialing %s\r\n",dialstr+4); -modem_send(dialstr); + printf ("Dialing %s\r\n", dialstr + 4); + modem_send (dialstr); } -void dialstr_tick(void) +void +dialstr_tick (void) { -if (!dialstr_timeout) return; -dialstr_timeout--; -if (dialstr_timeout) return; + if (!dialstr_timeout) + return; + dialstr_timeout--; + if (dialstr_timeout) + return; -if (!hook) - dialstr_dial(); + if (!hook) + dialstr_dial (); } - - - diff --git a/app/gpio.c b/app/gpio.c index e597d16..0419cde 100644 --- a/app/gpio.c +++ b/app/gpio.c @@ -1,6 +1,6 @@ #include "project.h" #define DEBOUNCE 10 -#define DIAL_BLACKOUT 90 /* (10pps)*/ +#define DIAL_BLACKOUT 90 /* (10pps) */ static int hs_poll; int hook; @@ -12,108 +12,135 @@ static int pulse_count; static int fake_hook; -static void exti5_isr(void) +static void +exti5_isr (void) { -exti_reset_request(EXTI5); -dial_poll=DEBOUNCE; + exti_reset_request (EXTI5); + dial_poll = DEBOUNCE; } -static void exti7_isr(void) +static void +exti7_isr (void) { -exti_reset_request(EXTI7); -if (dial_pulse_blackout) return; -dial_pulse_blackout=DIAL_BLACKOUT; -pulse_count++; + exti_reset_request (EXTI7); + if (dial_pulse_blackout) + return; + dial_pulse_blackout = DIAL_BLACKOUT; + pulse_count++; } -static void exti14_isr(void) +static void +exti14_isr (void) { -exti_reset_request(EXTI14); -hs_poll=DEBOUNCE; + exti_reset_request (EXTI14); + hs_poll = DEBOUNCE; } -void exti9_5_isr(void) +void +exti9_5_isr (void) { -if (exti_get_flag_status(EXTI5)) exti5_isr(); -if (exti_get_flag_status(EXTI7)) exti7_isr(); + if (exti_get_flag_status (EXTI5)) + exti5_isr (); + if (exti_get_flag_status (EXTI7)) + exti7_isr (); } -void exti15_10_isr(void) + +void +exti15_10_isr (void) { -if (exti_get_flag_status(EXTI14)) exti14_isr(); + if (exti_get_flag_status (EXTI14)) + exti14_isr (); } -static void hs_tick(void) +static void +hs_tick (void) { -int h; + int h; -if (!hs_poll) return; -hs_poll--; + if (!hs_poll) + return; + hs_poll--; -if (hs_poll) return; + if (hs_poll) + return; -h=!gpio_get(GPIOC,GPIO14); + h = !gpio_get (GPIOC, GPIO14); -h^=fake_hook; + h ^= fake_hook; -if (hook==h) return; + if (hook == h) + return; -hook=h; + hook = h; -printf("Hook is now %d\r\n",hook); + printf ("Hook is now %d\r\n", hook); -if (!hook) { - if (ringing) { - ring_off(); - answer_call(); - } -} + if (!hook) + { + if (ringing) + { + ring_off (); + answer_call (); + } + } -if (hook) { - ring_off(); - terminate_call(); -} + if (hook) + { + ring_off (); + terminate_call (); + } } -static void dial_tick(void) { -int m; -if (dial_pulse_blackout) dial_pulse_blackout--; -if (!dial_poll) return; -dial_poll--; -if (dial_poll) return; +static void +dial_tick (void) +{ + int m; + + if (dial_pulse_blackout) + dial_pulse_blackout--; + if (!dial_poll) + return; + dial_poll--; + if (dial_poll) + return; -m=!!gpio_get(GPIOA,GPIO5); + m = ! !gpio_get (GPIOA, GPIO5); -if (m) return; -if (!pulse_count) return; + if (m) + return; + if (!pulse_count) + return; -dialstr_digit((pulse_count == 10) ? 0:pulse_count); -pulse_count=0; + dialstr_digit ((pulse_count == 10) ? 0 : pulse_count); + pulse_count = 0; } -void toggle_fake_hook(void) +void +toggle_fake_hook (void) { -fake_hook^=1; -hs_poll=DEBOUNCE; + fake_hook ^= 1; + hs_poll = DEBOUNCE; } -void gpio_tick(void) +void +gpio_tick (void) { -hs_tick(); -dial_tick(); + hs_tick (); + dial_tick (); } @@ -121,55 +148,59 @@ dial_tick(); -void gpio_init(void) +void +gpio_init (void) { - /*GSM module reset pin*/ + /*GSM module reset pin */ gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO1); - gpio_set(GPIOA,GPIO1); + gpio_set (GPIOA, GPIO1); /* Dial mute */ - gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO4); - gpio_set(GPIOA,GPIO4); + gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, + GPIO4); + gpio_set (GPIOA, GPIO4); gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO5); - gpio_clear(GPIOA,GPIO5); + gpio_clear (GPIOA, GPIO5); - exti_select_source(EXTI5, GPIOA); - exti_set_trigger(EXTI5, EXTI_TRIGGER_BOTH); - exti_enable_request(EXTI5); + exti_select_source (EXTI5, GPIOA); + exti_set_trigger (EXTI5, EXTI_TRIGGER_BOTH); + exti_enable_request (EXTI5); /*Dial contacts */ - gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO6); - gpio_set(GPIOA,GPIO6); + gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, + GPIO6); + gpio_set (GPIOA, GPIO6); gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO7); - gpio_clear(GPIOA,GPIO7); + gpio_clear (GPIOA, GPIO7); - exti_select_source(EXTI7, GPIOA); - exti_set_trigger(EXTI7, EXTI_TRIGGER_RISING); - exti_enable_request(EXTI7); + exti_select_source (EXTI7, GPIOA); + exti_set_trigger (EXTI7, EXTI_TRIGGER_RISING); + exti_enable_request (EXTI7); - nvic_enable_irq(NVIC_EXTI9_5_IRQ); + nvic_enable_irq (NVIC_EXTI9_5_IRQ); - /*hookswitch*/ - gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); - gpio_set(GPIOC,GPIO15); + /*hookswitch */ + gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, + GPIO15); + gpio_set (GPIOC, GPIO15); gpio_set_mode (GPIOC, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14); - gpio_clear(GPIOC,GPIO14); + gpio_clear (GPIOC, GPIO14); - exti_select_source(EXTI14, GPIOC); - exti_set_trigger(EXTI14, EXTI_TRIGGER_BOTH); - exti_enable_request(EXTI14); + exti_select_source (EXTI14, GPIOC); + exti_set_trigger (EXTI14, EXTI_TRIGGER_BOTH); + exti_enable_request (EXTI14); - nvic_enable_irq(NVIC_EXTI15_10_IRQ); + nvic_enable_irq (NVIC_EXTI15_10_IRQ); } diff --git a/app/led.c b/app/led.c index a6a688b..4da19ee 100644 --- a/app/led.c +++ b/app/led.c @@ -29,21 +29,21 @@ void led_tick (void) { - led_cycle++; + led_cycle++; - if (led_cycle<500) - return; + if (led_cycle < 500) + return; - led_cycle=0; + led_cycle = 0; - led_on=!led_on; + led_on = !led_on; + + if (led_on) + gpio_clear (GPIOC, GPIO13); + else + gpio_set (GPIOC, GPIO13); - if (led_on) - gpio_clear (GPIOC, GPIO13); - else - gpio_set (GPIOC, GPIO13); - } diff --git a/app/main.c b/app/main.c index 00dbc85..e225f26 100644 --- a/app/main.c +++ b/app/main.c @@ -19,7 +19,7 @@ main (void) rcc_periph_clock_enable (RCC_GPIOB); rcc_periph_clock_enable (RCC_GPIOC); rcc_periph_clock_enable (RCC_AFIO); -rcc_periph_clock_enable(RCC_TIM1); + rcc_periph_clock_enable (RCC_TIM1); nvic_set_priority (NVIC_USART1_IRQ, 0x40); nvic_set_priority (NVIC_USART2_IRQ, 0x40); @@ -28,12 +28,12 @@ rcc_periph_clock_enable(RCC_TIM1); ticker_init (); led_init (); - usart_init(); + usart_init (); - gpio_init(); - buzzer_init(); + gpio_init (); + buzzer_init (); - modem_init(); + modem_init (); @@ -44,17 +44,18 @@ rcc_periph_clock_enable(RCC_TIM1); //usb_init (); - /*Reset the GSM module*/ - gpio_clear(GPIOA,GPIO1); - delay_ms(100); - gpio_set(GPIOA,GPIO1); + /*Reset the GSM module */ + gpio_clear (GPIOA, GPIO1); + delay_ms (100); + gpio_set (GPIOA, GPIO1); //usb_run (); - for (;;) { - serial_poll(); - } + for (;;) + { + serial_poll (); + } return 0; } diff --git a/app/modem.c b/app/modem.c index fa6a57a..b531761 100644 --- a/app/modem.c +++ b/app/modem.c @@ -7,93 +7,109 @@ #define BACKOFF 200 static char modem_buf[BUFFER_SIZE]; -static unsigned modem_ptr=0; +static unsigned modem_ptr = 0; static char *modem_cmd; static int timeout; -static int sleepy=SLEEPY; +static int sleepy = SLEEPY; -void modem_send(char *buf) +void +modem_send (char *buf) { -modem_cmd=buf; - -if (sleepy>=SLEEPY) { - printf("modem is sleepy\r\n"); - usart2_queue('\r'); - sleepy=0; - timeout=BACKOFF; - return; + modem_cmd = buf; + + if (sleepy >= SLEEPY) + { + printf ("modem is sleepy\r\n"); + usart2_queue ('\r'); + sleepy = 0; + timeout = BACKOFF; + return; + } + sleepy = 0; + + printf ("(re)send\r\n"); + timeout = TIMEOUT; + usart2_queue ('\r'); + usart2_tx (modem_cmd, strlen (modem_cmd)); + usart2_queue ('\r'); } - sleepy=0; -printf("(re)send\r\n"); -timeout=TIMEOUT; -usart2_queue('\r'); -usart2_tx(modem_cmd,strlen(modem_cmd)); -usart2_queue('\r'); -} - -void modem_line() +void +modem_line () { -printf("Modem said: %s\r\n",modem_buf); + printf ("Modem said: %s\r\n", modem_buf); -sleepy=0; + sleepy = 0; -if (!strncmp(modem_buf,"RING",4)) - ring(4000); + if (!strncmp (modem_buf, "RING", 4)) + ring (4000); -if (!strncmp(modem_buf,"OK",2)) { - modem_cmd=NULL; - timeout=0; -} + if (!strncmp (modem_buf, "OK", 2)) + { + modem_cmd = NULL; + timeout = 0; + } } -void modem_byte(uint8_t b) +void +modem_byte (uint8_t b) { -if (b=='\n') return; + if (b == '\n') + return; -if (b=='\r') { - if (modem_ptr) - modem_line(); - modem_ptr=0; - modem_buf[modem_ptr]=0; - return; -} - -if (modem_ptr>=(sizeof(modem_buf)-1)) - return; + if (b == '\r') + { + if (modem_ptr) + modem_line (); + modem_ptr = 0; + modem_buf[modem_ptr] = 0; + return; + } + + if (modem_ptr >= (sizeof (modem_buf) - 1)) + return; -modem_buf[modem_ptr]=b; -modem_ptr++; -modem_buf[modem_ptr]=0; + modem_buf[modem_ptr] = b; + modem_ptr++; + modem_buf[modem_ptr] = 0; } -void answer_call(void) +void +answer_call (void) { - printf("Answering call\r\n"); - modem_send("ATA"); + printf ("Answering call\r\n"); + modem_send ("ATA"); } -void terminate_call(void) { - printf("Terminating any call\r\n"); - modem_send("ATH0"); +void +terminate_call (void) +{ + printf ("Terminating any call\r\n"); + modem_send ("ATH0"); } -void modem_tick(void) { +void +modem_tick (void) +{ -if (sleepy